ExemptDraw.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\TableName;
  4. use App\Http\helper\NumConfig;
  5. use App\Http\logic\api\BaseApiLogic;
  6. use Carbon\Carbon;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Log;
  9. use Illuminate\Support\Facades\Redis;
  10. class ExemptDraw extends BaseApiLogic
  11. {
  12. /**
  13. * 验证是否符合免审条件
  14. * @param $UserID // 用户ID
  15. * @param $WithDraw // 要提现的金额
  16. * @return array|bool
  17. */
  18. public function verify($UserID, $WithDraw)
  19. {
  20. // 查询用户信息
  21. $GameTime = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  22. ->where('UserID', $UserID)
  23. ->value('PlayTimeCount');
  24. // 充值金额,提现金额
  25. $UserRecord = DB::table(TableName::QPRecordDB() . 'RecordUserTotalStatistics')
  26. ->where('UserID', $UserID)
  27. ->select('Withdraw', 'Recharge')
  28. ->first();
  29. $HistoryWithdraw = (int)$UserRecord->Withdraw ?? 0;
  30. $HistoryRecharge = (int)$UserRecord->Recharge ?? 0;
  31. // 用户提现笔数
  32. $redis = Redis::connection();
  33. $TodayDrawBi = $redis->get('draw_' . date('Ymd') . $UserID);
  34. if (empty($HistoryRecharge)) {
  35. $config = DB::table(TableName::agent() . 'withdrawal_position_config')
  36. ->where('status', 1)
  37. ->where('recharge_checkbox', 1)
  38. ->where('recharge_min', 0)
  39. ->where('recharge_max', 0)
  40. ->first();
  41. } else {
  42. $config = DB::table(TableName::agent() . 'withdrawal_position_config')
  43. ->where('status', 1)
  44. ->where('recharge_min', '<=', $HistoryRecharge)
  45. ->where('recharge_max', '>=', $HistoryRecharge)
  46. ->first();
  47. }
  48. if (!$config) {
  49. Log::info('免审配置没获取到' . $UserID);
  50. $this->error = '免审配置没获取到';
  51. return false;
  52. }
  53. // 验证免审提现类型
  54. $verifyType = $this->checkType($config->type, $UserID, $config->quota, $WithDraw, $HistoryWithdraw);
  55. if (!$verifyType) {
  56. $this->error = '固定额度已超出,或倍数已超出';
  57. return false;
  58. }
  59. // 提现大于充值验证
  60. if ($config->draw_gt_recharge > 0) {
  61. if (($HistoryWithdraw / NumConfig::NUM_VALUE) > $HistoryRecharge) {
  62. $this->error = '提现大于充值';
  63. return false;
  64. }
  65. }
  66. // 提现总额度验证 [历史提现 + 要提现的这笔 大于设置值。不允许免审]
  67. if ($config->draw_total > 0) {
  68. if (($HistoryWithdraw / NumConfig::NUM_VALUE) + $WithDraw > $config->draw_total) {
  69. $this->error = '提现总额度验证 [历史提现 + 要提现的这笔 大于设置值。不允许免审]';
  70. return false;
  71. }
  72. }
  73. // 提现笔数 [单日提现笔数大于设置值。不允许免审]
  74. if ($config->draw_bi > 0) {
  75. if ($TodayDrawBi > $config->draw_bi) {
  76. $this->error = '提现笔数 [单日提现笔数大于设置值。不允许免审]';
  77. return false;
  78. }
  79. }
  80. // 游戏时长验证[总游戏时长大于设置值。不允许免审]
  81. if ($config->game_time > 0) {
  82. if ($GameTime > $config->game_time) {
  83. $this->error = '游戏时长验证[总游戏时长大于设置值。不允许免审]';
  84. return false;
  85. }
  86. }
  87. // 总额度验证
  88. $checkTotalScore = $this->checkTotalScore($config->id, $config->total_quota);
  89. if (!$checkTotalScore) {
  90. $this->error = '总额度已超出';
  91. return false;
  92. }
  93. // 返回信息
  94. return [true, $config->id];
  95. }
  96. // 检查免审提现类型
  97. /**
  98. * @param $Type // 1 固定额度 2 倍数
  99. * @param $UserID // 用户ID
  100. * @param $quota // 平台设置的提现额度【根据type变化】
  101. * @param $WithDraw // 要提现的值
  102. * @param $HistoryRecharge // 历史充值
  103. * @return bool
  104. */
  105. public function checkType($Type, $UserID, $quota, $WithDraw, $HistoryRecharge)
  106. {
  107. if ($Type == 0) return true;
  108. // 查询用户今日免审消耗的额度
  109. $UseAmount = DB::table(TableName::agent() . 'withdrawal_position_log')
  110. ->where('take_effect', 2)
  111. ->where('user_id', $UserID)
  112. ->sum('use_quota');
  113. if ($Type == 1) {
  114. if ($quota < $UseAmount + $WithDraw) { // 提现固定额度 小于 要提现的额度 + 今天已经提现的额度,不允许免审
  115. $this->error = '提现固定额度 小于 要提现的额度 + 今天已经提现的额度,不允许免审';
  116. return false;
  117. }
  118. } elseif ($Type == 2) {
  119. if ($UseAmount + $WithDraw > $HistoryRecharge * $quota) { // 要提现的金额 + 今天已经提现的额度 大于 历史充值的n倍。不允许免审
  120. $this->error = '要提现的金额 + 今天已经提现的额度 大于 历史充值的n倍。不允许免审';
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. // 总额度验证
  127. public function checkTotalScore($ConfigId, $TotalScore)
  128. {
  129. // 查该配置的所有已使用额度
  130. $UseQuoTa = DB::table(TableName::agent() . 'withdrawal_position_log')
  131. ->where('config_id', $ConfigId)
  132. ->where('take_effect', 2)
  133. ->sum('use_quota');
  134. // 使用额度,大于设置值,不允许免审
  135. if ($UseQuoTa > ($TotalScore * NumConfig::NUM_VALUE)) {
  136. $this->error = '使用额度,大于设置值,不允许免审';
  137. return false;
  138. }
  139. return true;
  140. }
  141. }