Withdrawal.php 11 KB

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