Withdrawal.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\TableName;
  4. use App\Http\helper\NumConfig;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Log;
  7. use Illuminate\Support\Facades\Redis;
  8. class Withdrawal
  9. {
  10. public function OrderServe(SerPay $serPay, $PixType, $accountName, $phone, $email, $PixNum)
  11. {
  12. // 1:CPF/CNPJ 2:Email 3:PhoneNumber
  13. if ($PixType == 1) {
  14. strlen($PixNum) == 11 ? $serPay->setCardType('CPF') : $serPay->setCardType('CNPJ');
  15. $serPay->setPanNum($PixNum);
  16. }
  17. }
  18. // 免审配置验证 -- false人工审。true免审
  19. public function configVerify($UserID, $Withdraw, $OrderID)
  20. {
  21. $UserInfo = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->select('Recharge', 'Withdraw')->first();
  22. // 读取免审配置
  23. $getConfig = DB::table(TableName::agent() . 'withdrawal_position_config')
  24. ->where('status', 1)
  25. ->first();
  26. // 配置没开启,返回
  27. if (!$getConfig) return false;
  28. // 提现值除100
  29. $Withdraw /= NumConfig::NUM_VALUE;
  30. // 设置默认值
  31. $UserWithdraw = $UserInfo->Withdraw ?? 0;
  32. $UserRecharge = $UserInfo->Recharge ?? 0;
  33. // 用户已经提现值除100
  34. $UserWithdraw /= NumConfig::NUM_VALUE;
  35. if($UserWithdraw==0) return 9;
  36. //0
  37. if($Withdraw<3000&&$Withdraw<=$UserRecharge-$UserWithdraw){
  38. Log::info("{$OrderID}:自动免审:级别5:{$UserRecharge}-{$UserWithdraw}");
  39. return 5;
  40. }else if($UserRecharge>=1000&&$Withdraw<$UserRecharge-$UserWithdraw+100){
  41. Log::info("{$OrderID}:自动免审:级别3:{$UserRecharge}-{$UserWithdraw}");
  42. return 3;
  43. }else if($UserRecharge>=100&&$Withdraw<$UserRecharge-$UserWithdraw+100){
  44. Log::info("{$OrderID}:自动免审:级别2:{$UserRecharge}-{$UserWithdraw}");
  45. return 2;
  46. }else if($UserRecharge>10&&$Withdraw<$UserRecharge-$UserWithdraw+100){
  47. Log::info("{$OrderID}:自动免审:级别4:{$UserRecharge}-{$UserWithdraw}");
  48. return 4;
  49. }else if($UserRecharge>0&&$Withdraw<$UserRecharge-$UserWithdraw+100){
  50. Log::info("{$OrderID}:自动免审:级别1:{$UserRecharge}-{$UserWithdraw}");
  51. return 1;
  52. }
  53. ///
  54. /// ================================ 配置判断 ====================================
  55. ///
  56. // 1、 充值额度配置开启
  57. if ($getConfig->recharge_checkbox) {
  58. if ($UserRecharge < $getConfig->recharge_min || $UserRecharge > $getConfig->recharge_max) {
  59. Log::info("{$OrderID}:自动免审:充值额度不符合,已充值金额:{$UserRecharge}");
  60. return false;
  61. }
  62. }
  63. // 2、提现大于充值某个值 -- 人工审核 【反之,提现+要提现金额小于充值+配置值免审】
  64. if ($getConfig->draw_gt_recharge > 0) {
  65. // 已经提现的金额 + 要提现金额 小于 充值 + 设置值
  66. if (($UserWithdraw + $Withdraw) >= $UserRecharge + $getConfig->draw_gt_recharge) {
  67. Log::info("{$OrderID}:自动免审:提现大于充值,已提现金额:{$UserWithdraw}");
  68. return false;
  69. }
  70. }
  71. // 3、提现总额度超过值 -- 人工审 【反之,提现小于配置设置额度免审】
  72. if ($getConfig->draw_total > 0) {
  73. if (($UserWithdraw + $Withdraw) > $getConfig->draw_total) {
  74. Log::info("{$OrderID}:自动免审:提现总额度超过值:{$UserWithdraw}");
  75. return false;
  76. }
  77. }
  78. //4、提现笔数超过 -- 人工审 【反之,提现笔数小于设置值免审】
  79. if ($getConfig->draw_bi > 0) {
  80. $redis = Redis::connection();
  81. $drawBi = $redis->get('draw_' . date('Ymd') . $UserID);
  82. if ($drawBi > $getConfig->draw_bi) {
  83. Log::info("{$OrderID}:自动免审:提现笔数超出设置值:{$drawBi}");
  84. return false;
  85. }
  86. }
  87. // 5、游戏时长小于配置值 -- 人工审 【反之,游戏时间大于配置值免审】
  88. if ($getConfig->game_time > 0) {
  89. // 查用户游戏时长 -- 秒
  90. $PlayTimeCount = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)->value('PlayTimeCount');
  91. if (($PlayTimeCount / 60) < $getConfig->game_time) {
  92. Log::info("{$OrderID}:自动免审:游戏时长小于配置值:{$PlayTimeCount}");
  93. return false;
  94. }
  95. }
  96. // 6、固定额度/倍数
  97. if ($getConfig->type > 0 && $getConfig->quota > 0) {
  98. if ($getConfig->type == 2) { // 倍数 -- 充值额度 * 倍数
  99. $getConfig->quota = (int)($UserRecharge * $getConfig->quota);
  100. }
  101. // 该用户已经消耗的额度 -- 免审提现额度 -- (申请提现额度额外加)
  102. $use_quota = DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  103. ->where('user_id', $UserID)
  104. ->whereDate('create_at', date('Y-m-d'))
  105. ->selectRaw('IsNull(sum(use_quota),0) use_quota')
  106. ->first()->use_quota;
  107. // 该配置已经消耗的全部额度 -- (申请提现额度额外加)
  108. $all_use_quota = DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  109. ->selectRaw('IsNull(sum(use_quota),0) use_quota')
  110. ->where('config_id', $getConfig->id)
  111. ->whereDate('create_at', date('Y-m-d'))
  112. ->first()->use_quota;
  113. // 用户消耗额度 + 要提现额度
  114. $use_quota_after = ($use_quota / NumConfig::NUM_VALUE) + $Withdraw;
  115. $all_use_quota_after = ($all_use_quota / NumConfig::NUM_VALUE) + $Withdraw;
  116. if ((int)$use_quota_after > $getConfig->quota && (int)$all_use_quota_after > $getConfig->total_quota) {
  117. Log::info("{$OrderID}:自动免审:用户提现超出额度:{$use_quota_after},配置总额度消耗:{$all_use_quota_after}");
  118. return false;
  119. }
  120. }
  121. return true;
  122. }
  123. // 免审配置验证
  124. public function configVerifyCopy($UserID, $Withdraw)
  125. {
  126. $UserInfo = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')->where('UserID', $UserID)->select('Recharge', 'Withdraw')->first();
  127. // 读取免审配置
  128. $getConfig = DB::table(TableName::agent() . 'withdrawal_position_config')
  129. ->where('status', 1)
  130. ->first();
  131. // 配置没开启,返回
  132. if (!$getConfig) return false;
  133. // 提现值除100
  134. $Withdraw /= NumConfig::NUM_VALUE;
  135. // 设置默认值
  136. $UserWithdraw = $UserInfo->Withdraw ?? 0;
  137. $UserRecharge = $UserInfo->Recharge ?? 0;
  138. // 用户已经提现值除100
  139. $UserWithdraw /= NumConfig::NUM_VALUE;
  140. ///
  141. /// ================================ 配置判断 ====================================
  142. ///
  143. $flag = false;
  144. // 1、 充值额度配置开启
  145. if ($getConfig->recharge_checkbox) {
  146. if ($UserRecharge >= $getConfig->recharge_min && $UserRecharge <= $getConfig->recharge_max) {
  147. $flag = true;
  148. } else {
  149. $flag = false;
  150. }
  151. }
  152. // 2、提现大于充值某个值 -- 人工审核 【反之,提现+要提现金额小于充值+配置值免审】
  153. if ($getConfig->draw_gt_recharge > 0) {
  154. // 已经提现的金额 + 要提现金额 小于 充值 + 设置值
  155. if (($UserWithdraw + $Withdraw) < $UserRecharge + $getConfig->draw_gt_recharge) {
  156. $flag = true;
  157. } else {
  158. $flag = false;
  159. }
  160. }
  161. // 3、提现总额度超过值 -- 人工审 【反之,提现小于配置设置额度免审】
  162. if ($getConfig->draw_total > 0) {
  163. if ((($UserWithdraw + $Withdraw)) < $getConfig->draw_total) {
  164. $flag = true;
  165. } else {
  166. $flag = false;
  167. }
  168. }
  169. //4、提现笔数超过 -- 人工审 【反之,提现笔数小于设置值免审】
  170. if ($getConfig->draw_bi > 0) {
  171. $redis = Redis::connection();
  172. $drawBi = $redis->get('draw_' . date('Ymd') . $UserID);
  173. if ($drawBi < $getConfig->draw_bi) {
  174. $flag = true;
  175. } else {
  176. $flag = false;
  177. }
  178. }
  179. // 5、游戏时长小于配置值 -- 人工审 【反之,游戏时间大于配置值免审】
  180. if ($getConfig->game_time > 0) {
  181. // 查用户游戏时长 -- 秒
  182. $PlayTimeCount = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)->value('PlayTimeCount');
  183. if (($PlayTimeCount / 60) > $getConfig->game_time) {
  184. $flag = true;
  185. } else {
  186. $flag = false;
  187. }
  188. }
  189. // 6、固定额度/倍数
  190. if ($getConfig->type > 0 && $getConfig->quota > 0) {
  191. if ($getConfig->type == 2) { // 倍数 -- 充值额度 * 倍数
  192. $getConfig->quota = (int)($UserRecharge * $getConfig->quota);
  193. }
  194. // 该用户已经消耗的额度 -- 免审提现额度 -- (申请提现额度额外加)
  195. $use_quota = DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  196. ->where('user_id', $UserID)
  197. ->whereDate('create_at', date('Y-m-d'))
  198. ->selectRaw('IsNull(sum(use_quota),0) use_quota')
  199. ->first()->use_quota;
  200. // 该配置已经消耗的全部额度 -- (申请提现额度额外加)
  201. $all_use_quota = DB::connection('write')->table('agent.dbo.withdrawal_position_log')
  202. ->selectRaw('IsNull(sum(use_quota),0) use_quota')
  203. ->where('config_id', $getConfig->id)
  204. ->whereDate('create_at', date('Y-m-d'))
  205. ->first()->use_quota;
  206. // 用户消耗额度 + 要提现额度
  207. $use_quota_after = ($use_quota / NumConfig::NUM_VALUE) + $Withdraw;
  208. $all_use_quota_after = ($all_use_quota / NumConfig::NUM_VALUE) + $Withdraw;
  209. if ((int)$use_quota_after < $getConfig->quota && (int)$all_use_quota_after < $getConfig->total_quota) {
  210. $flag = true;
  211. } else {
  212. $flag = false;
  213. }
  214. }
  215. return $flag;
  216. }
  217. }