Extensions.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\TableName;
  4. use App\Http\logic\api\BaseApiLogic;
  5. use App\Models\RecordScoreInfo;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Redis;
  8. // 裂变逻辑
  9. class Extensions extends BaseApiLogic
  10. {
  11. // 领取充值额度
  12. public function receiveRechargeScore($UserID, $Type = 1)
  13. {
  14. $redis = Redis::connection();
  15. $register_invite_switches = $redis->get('register_invite_switches_' . $UserID);
  16. if ($register_invite_switches == 1) {
  17. // 您的推广赚金额度被冻结,请联系客服
  18. $this->error = 'O valor dos ganhos da sua promoção foi congelado, entre em contato com o atendimento ao cliente';
  19. return false;
  20. }
  21. $addScore = $this->recharge($UserID);
  22. if ($addScore == 0) {
  23. $this->error = 'No collectable limit';
  24. return false;
  25. }
  26. StoredProcedure::receiveRecharge($UserID, 1);
  27. StoredProcedure::receiveRecharge($UserID, 2);
  28. $Surplus = 0;
  29. $data = compact('addScore', 'Type', 'Surplus');
  30. return $data;
  31. }
  32. // 领取注册额度
  33. public function receiveRegisterScore($UserID, $clientType = 2, $type = 1)
  34. {
  35. $Type = $clientType;
  36. $redis = Redis::connection();
  37. $register_invite_switches = $redis->get('register_invite_switches_' . $UserID);
  38. // 自动审核开关是否开启。
  39. $AutoVerify = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  40. ->where('StatusName', 'AutoVerify')
  41. ->value('StatusValue');
  42. if (empty($AutoVerify) || $register_invite_switches == 1) {
  43. // 您的推广赚金额度被冻结,请联系客服
  44. $this->error = 'O valor dos ganhos da sua promoção foi congelado, entre em contato com o atendimento ao cliente';
  45. return false;
  46. }
  47. // 可领取额度
  48. $addScore = $this->register($UserID)['Register'] ?: 0;
  49. // 剩余额度
  50. $Surplus = 0;
  51. $Score = $addScore;
  52. $data = compact('addScore', 'Type', 'Surplus', 'Score');
  53. if ($addScore == 0) {
  54. $this->data = $data;
  55. $this->error = 'Quantidade insuficiente recebida';
  56. return false;
  57. }
  58. $this->addLog($UserID, $addScore, '', $type);
  59. return $data;
  60. }
  61. // 添加领取的记录,改变用户余额--可提现额度
  62. public function addLog($UserID, $addScore, $orderIds, $Type)
  63. {
  64. // 增加用户余额
  65. DB::connection('write')->table('QPTreasureDB.dbo.GameScoreInfo')
  66. ->where('UserID', $UserID)
  67. ->increment('Score', $addScore);
  68. // 减少自己身上的余额
  69. DB::table(TableName::agent() . 'register_invite')
  70. ->where('user_id', $UserID)
  71. ->decrement('score', $addScore);
  72. // 添加金币变化记录
  73. RecordScoreInfo::addScore($UserID, $addScore, 72);
  74. return true;
  75. }
  76. // 获取充值可领额度
  77. public function recharge($UserID)
  78. {
  79. $xiaji = StoredProcedure::recharge($UserID, 1);
  80. $xiaxiaji = StoredProcedure::recharge($UserID, 2);
  81. $TotalBalance1 = $xiaji[0]->TotalBalance ?? 0;
  82. $TotalBalance2 = $xiaxiaji[0]->TotalBalance ?? 0;
  83. $TotalBalance = $TotalBalance1 + $TotalBalance2;
  84. return $TotalBalance;
  85. }
  86. // 获取可提现额度
  87. public function remainingBalance($UserID)
  88. {
  89. $AccountWithDrawInfo = DB::connection('read')->table('QPAccountsDB.dbo.AccountWithDrawInfo')
  90. ->where('UserID', $UserID)
  91. ->selectRaw('Win,Lost')
  92. ->first();
  93. if (!$AccountWithDrawInfo) {
  94. $remainingBalance = 0;
  95. } else {
  96. # 可提现余额逻辑:win > 保底值 win + lost 取和,小于保底值 取win 第二步,跟用户余额比较,取小值
  97. $Score = DB::connection('read')->table('QPTreasureDB.dbo.GameScoreInfo')
  98. ->where('UserID', $UserID)
  99. ->selectRaw('Score')
  100. ->first()->Score ?? 0;
  101. # win
  102. $r = $AccountWithDrawInfo->Win;
  103. # 保底值
  104. $StatusValue = DB::connection('read')->table('QPAccountsDB.dbo.SystemStatusInfo')
  105. ->where('StatusName', 'WithDrawPoint')
  106. ->select('StatusValue')
  107. ->first()->StatusValue ?? 0;
  108. # win + lost 和
  109. if ($r > $StatusValue) {
  110. $r = $AccountWithDrawInfo->Win + $AccountWithDrawInfo->Lost;
  111. }
  112. // 可提现余额大于用户总余额 默认 用户总余额
  113. if ($AccountWithDrawInfo->Win <= 0 || $r <= 0) {
  114. $remainingBalance = 0;
  115. } elseif ($Score < $r) {
  116. $remainingBalance = number_float($Score);
  117. } else {
  118. $remainingBalance = number_float($r);
  119. }
  120. }
  121. return $remainingBalance;
  122. }
  123. // 获取注册可领额度
  124. public function register($UserID, $Type = 1)
  125. {
  126. $Register = DB::table(TableName::agent() . 'register_invite')
  127. ->where('user_id', $UserID)
  128. ->value('score');
  129. // 自动审核开关
  130. $AutoVerify = DB::connection('write')->table('QPAccountsDB.dbo.SystemStatusInfo')
  131. ->where('StatusName', 'AutoVerify')
  132. ->value('StatusValue');
  133. $redis = Redis::connection();
  134. $register_invite_switches = $redis->get('register_invite_switches_' . $UserID);
  135. $Flag = false;
  136. if ($register_invite_switches == 1 || empty($AutoVerify) || $Register == 0) {
  137. $Flag = true;
  138. }
  139. $Register = empty($Register) ? 0 : $Register;
  140. return compact('Register', 'Flag');
  141. }
  142. // 来源玩家
  143. public function sourcePlayer($user_profit_log, &$value)
  144. {
  145. $UserID = $value->UserID;
  146. $Type = $value->Type;
  147. if ($Type == 1) {
  148. foreach ($user_profit_log as $val) {
  149. if ($val->UserID == $UserID && $val->Type == $Type) {
  150. $value->count = $val->NoteCount;
  151. $userArr = explode(',', trim($val->InvitationUserIDs));
  152. }
  153. }
  154. } else {
  155. $array = DB::connection('write')->table('agent.dbo.extension_user_profit_log')
  156. ->where('OrderID', 0)
  157. ->where('UserID', $UserID)
  158. ->where('Type', $Type)
  159. ->where('Status', 1)
  160. ->selectRaw('distinct(InvitationUserIDs)')
  161. ->get()->map(function ($val) {
  162. return (array)$val;
  163. })->toArray();
  164. $userArr = array_column($array, 'InvitationUserIDs');
  165. $value->count = count($userArr);
  166. }
  167. if (!empty($userArr)) {
  168. $userTotalRecharge = DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  169. ->whereIn('UserID', $userArr)
  170. ->where('Recharge', '>', 0)
  171. ->selectRaw('count(UserID) userCount,sum(Recharge) RechargeSum')
  172. ->first();
  173. $value->rechargeCount = $userTotalRecharge->userCount;
  174. $value->RechargeSum = number_float($userTotalRecharge->RechargeSum);
  175. }
  176. return $value;
  177. }
  178. }