Custom.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace App\Services;
  3. use App\Facade\Redis;
  4. use App\Facade\TableName;
  5. use App\Http\helper\HttpCurl;
  6. use App\Http\helper\NumConfig;
  7. use App\Http\logic\admin\GlobalLogicController;
  8. use App\Http\logic\api\BaseApiLogic;
  9. use App\Models\AccountsInfo;
  10. use App\Models\Control;
  11. use App\Models\Order;
  12. use App\Models\RecordPlatformData;
  13. use App\Models\Withdrawal;
  14. use Illuminate\Support\Arr;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. class Custom extends BaseApiLogic
  18. {
  19. public function needCallUser($lastDay=7,$limit=5, $minRecharge='', $maxRecharge='')
  20. {
  21. $field = ['ai.GameID','ai.UserID', 'ai.NickName','ai.LastLogonDate', 'ai.RegisterDate', 'ap.PhoneNum'];
  22. $Sql = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  23. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ai.UserID', 'gi.UserID')
  24. ->leftJoin(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  25. ->leftJoin(TableName::QPRecordDB().'RecordUserTotalStatistics as rut','ai.UserID', 'rut.UserID')
  26. ->select($field);
  27. $where = [];
  28. $where[] = ['ai.Present','=',0];
  29. if (!empty($lastDay))
  30. $where[] = ['ai.LastLogonDate', '<=', date('Y-m-d H:i:s',strtotime("-{$lastDay} days"))];
  31. if (!empty($minRecharge))
  32. $where[] = ['rut.Recharge', '>=', $minRecharge];
  33. if (!empty($maxRecharge))
  34. $where[] = ['rut.Recharge', '<=', $maxRecharge];
  35. $orderBy = 'ai.LastLogonDate desc';
  36. $list = $Sql->where($where)->orderByRaw($orderBy)->take($limit)->get()->toArray();
  37. return $list;
  38. }
  39. public function myCallUser($lastDay=7,$state=-1,$admin=0){
  40. }
  41. public function userNewList($admin_id,$gameID,$cstartTime, $cendTime, $startTime, $endTime, $lstartTime, $lendTime,$state)
  42. {
  43. $field = ['ai.GameID','ai.Channel','ai.UserID', 'ai.NickName','gi.Score', 'ai.LastLogonDate','ub.call_state','ub.Email','ub.CallbackDate','ub.AddDate', 'ai.RegisterDate', 'ub.PhoneNum','ub.recharge','ub.withdraw','admin_id'];
  44. $Sql = DB::connection('read')->table('agent.dbo.UserCallBack as ub')
  45. ->leftJoin(TableName::QPAccountsDB() . 'AccountsInfo as ai','ai.UserID', 'ub.UserID')
  46. ->leftJoin(TableName::QPTreasureDB() . 'GameScoreInfo as gi', 'ub.UserID', 'gi.UserID')
  47. ->leftJoin(TableName::QPRecordDB().'RecordUserTotalStatistics as rut','ub.UserID', 'rut.UserID')
  48. ->select($field);
  49. // return DB::connection('read')->table('QPRecordDB.dbo.RecordUserTotalStatistics')
  50. // ->selectRaw('Recharge,Withdraw,Handsel,(WinScore + LostScore) Score,ServiceFee,UserID,Revenue')
  51. // ->whereIn('UserID', $UserIDs)
  52. // ->get();
  53. $where = [];
  54. if ($admin_id)
  55. $where[] = ['admin_id', $admin_id];
  56. if ($state!=-1)
  57. $where[] = ['call_state', $state];
  58. if (!empty($gameID))
  59. $where[] = ['ai.GameID', $gameID];
  60. if (!empty($startTime))
  61. $where[] = ['ub.CallbackDate', '>=', $startTime];
  62. if (!empty($endTime))
  63. $where[] = ['ub.CallbackDate', '<=', $endTime];
  64. if (!empty($cstartTime))
  65. $where[] = ['ub.AddDate', '>=', $cstartTime];
  66. if (!empty($cendTime))
  67. $where[] = ['ub.AddDate', '<=', $cendTime];
  68. if (!empty($lstartTime))
  69. $where[] = ['ai.LastLogonDate', '>=', $lstartTime];
  70. if (!empty($lendTime))
  71. $where[] = ['ai.LastLogonDate', '<=', $lendTime];
  72. $orderBy = 'AddDate desc';
  73. $list = $Sql->where($where)->orderByRaw($orderBy)->paginate(10);
  74. foreach ($list as &$value) {
  75. $value->Score = $value->Score / NumConfig::NUM_VALUE;
  76. }
  77. return $list;
  78. }
  79. public function userCallCount($admin_id,$start,$end,$state=2)
  80. {
  81. $Sql = DB::connection('read')->table('agent.dbo.UserCallBack');
  82. $where = [];
  83. $where[] = ['call_state', $state];
  84. if($admin_id){
  85. $where[] = ['admin_id', $admin_id];
  86. }
  87. if ($start)
  88. $where[] = ['AddDate', '>=', $start];
  89. if ($end)
  90. $where[] = ['AddDate', '<=', $end];
  91. return $Sql->where($where)->count();
  92. }
  93. public function userCallProfit($admin_id,$start,$end)
  94. {
  95. $Sql = DB::connection('read')->table('agent.dbo.UserCallBack');
  96. $where = [];
  97. if($admin_id){
  98. $where[] = ['admin_id', $admin_id];
  99. }
  100. if ($start)
  101. $where[] = ['AddDate', '>=', $start];
  102. if ($end)
  103. $where[] = ['AddDate', '<=', $end];
  104. return $Sql->where($where)->selectRaw('sum(recharge) as total_recharge,sum(withdraw) as total_withdraw')
  105. ->first();
  106. }
  107. public function checkSend($UserID){
  108. $mail = DB::connection('read')->table(TableName::QPAccountsDB() . 'PrivateMail')
  109. ->where('UserID', $UserID)
  110. //->where('MailStatus', 1)
  111. ->where('admin_type', 1)
  112. ->first();
  113. return $mail?1:0;
  114. }
  115. public function clearUnBackUser(){
  116. $data = DB::connection('write')->table('agent.dbo.UserCallBack')
  117. ->where('call_state',0)
  118. ->where('AddDate','<=', date('Y-m-d H:i:s',time()-86400*2))
  119. //->select('ServerName', 'UserID')
  120. ->pluck('UserID', 'UserID')->toArray();
  121. $userId = [];
  122. if($data){
  123. $userId = array_values($data);
  124. }
  125. if($userId){
  126. //删除 分配记录
  127. DB::connection('write')->table('agent.dbo.UserCallBack')
  128. ->where('call_state',0)
  129. ->whereIn('UserID',$userId)
  130. ->delete();
  131. // 删除标记
  132. DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  133. ->whereIn('UserID',$userId)
  134. ->update(['Present' => 0]);
  135. DB::connection('write')->table(TableName::QPAccountsDB() . 'PrivateMail')
  136. ->whereIn('UserID',$userId)
  137. ->where('admin_type', 1)
  138. ->delete();
  139. }
  140. Log::info('【用户召回清理】' .count($userId));
  141. //return count($userId);
  142. //TODO 明天开启
  143. $activeLost = DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  144. ->join('agent.dbo.UserCallBack as au', 'ai.UserID', 'au.UserID')
  145. ->where('call_state','>', 0)
  146. ->where('ai.LastLogonDate','<', date('Y-m-d H:i:s',strtotime("-7 days")))
  147. ->pluck('au.UserID', 'au.UserID')->toArray();
  148. $lostID = [];
  149. if($activeLost){
  150. $lostID = array_values($activeLost);
  151. }
  152. if($lostID){
  153. //删除 分配记录
  154. DB::connection('write')->table('agent.dbo.UserCallBack')
  155. //->where('call_state',0)
  156. ->whereIn('UserID',$lostID)
  157. ->delete();
  158. // 删除标记
  159. DB::connection('write')->table(TableName::QPAccountsDB() . 'AccountsInfo')
  160. ->whereIn('UserID',$lostID)
  161. ->update(['Present' => 0]);
  162. DB::connection('write')->table(TableName::QPAccountsDB() . 'PrivateMail')
  163. ->whereIn('UserID',$lostID)
  164. ->where('admin_type', 1)
  165. ->delete();
  166. }
  167. Log::info('【用户召回后再次流失清理】' .count($lostID));
  168. return count($userId);
  169. }
  170. public function checkPhoneUnique($phone){
  171. return DB::connection('read')->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
  172. ->where('ai.IsAndroid', 0)
  173. ->join(TableName::QPAccountsDB() . 'AccountPhone as ap', 'ai.UserID', 'ap.UserID')
  174. ->where('ap.PhoneNum', $phone)
  175. ->where('ai.LastLogonDate','>', date('Y-m-d H:i:s',strtotime("-7 days")))
  176. ->count();
  177. }
  178. public static function updateAdminBonus($admin_id,$bonus,$type=1){
  179. // if(date('Ym')<202403){
  180. // return false;
  181. // }
  182. $adminBonus = DB::connection('read')->table('agent.dbo.CallBackBonus')
  183. ->where('Admin_ID', $admin_id)
  184. ->where('Month', date('Ym'))
  185. ->first();
  186. if($adminBonus){
  187. Log::info('【更新奖励】' .$admin_id.'-'.$bonus);
  188. $update = [
  189. 'Bonus' => $adminBonus->Bonus+$bonus,
  190. ];
  191. if($type==1){
  192. $update['CallBackCount'] = $adminBonus->CallBackCount+1;
  193. }
  194. if($type==2){
  195. $update['ActiveCount'] = $adminBonus->ActiveCount+1;
  196. }
  197. DB::connection('read')->table('agent.dbo.CallBackBonus')
  198. ->where('Admin_ID', $admin_id)
  199. ->where('Month', date('Ym'))
  200. ->update($update);
  201. }else{
  202. Log::info('【新增奖励】' .$admin_id.'-'.$bonus);
  203. $insert = [
  204. 'Admin_ID' => $admin_id,
  205. 'Month' => date('Ym'),
  206. 'Bonus' => $bonus,
  207. ];
  208. if($type==1){
  209. $insert['CallBackCount'] = 1;
  210. }
  211. if($type==2){
  212. $insert['ActiveCount'] = 1;
  213. }
  214. DB::connection('read')->table('agent.dbo.CallBackBonus')->insert($insert);
  215. }
  216. return true;
  217. }
  218. }