ExtensionCopy.php 7.5 KB

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