UserLogicController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace App\Http\logic\admin;
  3. use App\Http\helper\NumConfig;
  4. use Illuminate\Support\Facades\DB;
  5. class UserLogicController extends BaseLogicController
  6. {
  7. protected $switch = 1; // 控制变化原因开关 1开启 -1关闭
  8. protected $ids = [15, 39, 37, 33, 1, 46, 47, 48, 50, 53, 54, 21, 36, 42, 44, 45, 49, 51, 52, 58, 59, 70, 72]; // 总得变化原因
  9. //全部彩金-- 21:绑定手机赠送 36:推广赚金(彩金) 42:邮件附件(彩金) 44:签到奖励 45:充值金额(彩金) 49:月卡(彩金) 51:首充礼包(彩金) 52:邮件附件(群发彩金)70:反水活动彩金
  10. protected $LotteryMoney = [21, 33, 36, 37, 42, 44, 45, 49, 51, 52, 59, 70, 72];
  11. public function scoreChange($start_time, $end_time, $describe, $UserID, $ChangeScoreMin, $ChangeScoreMax, $ChangeScoreSort)
  12. {
  13. $where = [];
  14. !empty($ChangeScoreMax) && $ChangeScoreMax = (int)$ChangeScoreMax * NumConfig::NUM_VALUE;
  15. !empty($ChangeScoreMin) && $ChangeScoreMin = (int)$ChangeScoreMin * NumConfig::NUM_VALUE;
  16. if ((!empty($ChangeScoreMax) || $ChangeScoreMax === '0') && (!empty($ChangeScoreMin) || $ChangeScoreMin === '0')) {
  17. $where[] = [function ($obj) use ($ChangeScoreMin, $ChangeScoreMax) {
  18. $obj->whereBetween('ChangeScore', [$ChangeScoreMin, $ChangeScoreMax]);
  19. }];
  20. } elseif (!empty($ChangeScoreMin) || $ChangeScoreMin === '0') {
  21. $where[] = ['ChangeScore', '>=', $ChangeScoreMin];
  22. } elseif (!empty($ChangeScoreMax) || $ChangeScoreMax === '0') {
  23. $where[] = ['ChangeScore', '<=', $ChangeScoreMax];
  24. }
  25. !empty($UserID) && $where[] = ['ai.GameID', 'like', '%' . $UserID . '%'];
  26. if ($describe == -1) {
  27. $where[] = [function ($where) {
  28. $where->whereIn('sc.Reason', $this->LotteryMoney);
  29. }];
  30. } else {
  31. !empty($describe) && $where[] = ['sc.Reason', '=', $describe];
  32. }
  33. $Reason = [];
  34. if ($this->switch == 1) {
  35. $Reason = DB::connection('read')->table('QPRecordDB.dbo.YN_RecordScoreConfig')->whereIn('Reason', $this->ids)->get();
  36. }
  37. // 默认查询近一天的数据
  38. $start_time = $start_time ?: date("Y-m-d");
  39. $end_time = $end_time ?: date("Y-m-d");
  40. $where[] = ['si.UpdateTime', '>=', $start_time . ' 00:00:00'];
  41. $where[] = ['si.UpdateTime', '<=', $end_time . ' 23:59:59'];
  42. if (!empty($ChangeScoreSort)) {
  43. $sort = "si.ChangeScore $ChangeScoreSort";
  44. } else {
  45. $sort = 'UpdateTime desc';
  46. }
  47. ////////////////////////
  48. // 查询范围需要在同一个月份,暂时不支持跨月份查询
  49. // $from_mm = intval(date('Ym', strtotime($start_time)));
  50. // $to_mm = intval(date('Ym', strtotime($end_time)));
  51. // if ($from_mm != $to_mm) {
  52. // throw new Exception('暂不支持跨月查询,开始时间和结束时间请选择相同月份');
  53. // }
  54. //确定有效表范围,从202104月开始到当前月
  55. // if ($from_mm < 202104 || $from_mm > intval(date('Ym'))) {
  56. // throw new Exception('超出时间范围,开始时间应大于等于2021年4月,小于等于当前月');
  57. // }
  58. $table = 'QPRecordDB.dbo.RecordUserScoreChange';
  59. //////////////////////
  60. $list = DB::connection('read')->table($table . ' as si')
  61. ->join('QPRecordDB.dbo.YN_RecordScoreConfig as sc', 'sc.Reason', '=', 'si.Reason')
  62. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'si.UserID', '=', 'ai.UserID')
  63. //->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi', 'gi.ServerID', 'si.ServerID')
  64. ->select('si.UserID', 'ai.GameID', 'si.BeforeScore', 'si.ChangeScore', 'si.AfterScore', 'si.UpdateTime', 'sc.Describe')
  65. ->where($where)
  66. ->orderByRaw($sort)
  67. ->paginate(10);
  68. foreach ($list as $key => &$value) {
  69. $value->BeforeScore = number_float($value->BeforeScore / 100);
  70. $value->ChangeScore = number_float($value->ChangeScore / 100);
  71. $value->AfterScore = number_float($value->AfterScore / 100);
  72. $value->ServerName = '';
  73. }
  74. !empty($ChangeScoreMax) && $ChangeScoreMax /= NumConfig::NUM_VALUE;
  75. !empty($ChangeScoreMin) && $ChangeScoreMin /= NumConfig::NUM_VALUE;
  76. return ['list' => $list,
  77. 'describe' => $describe,
  78. 'start_time' => $start_time,
  79. 'end_time' => $end_time,
  80. 'UserID' => $UserID,
  81. 'Reason' => $Reason,
  82. 'ChangeScoreMax' => $ChangeScoreMax,
  83. 'ChangeScoreMin' => $ChangeScoreMin,
  84. 'ChangeScoreSort' => $ChangeScoreSort
  85. ];
  86. }
  87. public function bind_list($start_time, $end_time, $UserID, $Higher1ID, $Higher2ID, $SpreaderID, $request)
  88. {
  89. $where = [];
  90. !empty($start_time) && $where[] = ['ai1.RegisterDate', '>=', $start_time];
  91. !empty($end_time) && $where[] = ['ai1.RegisterDate', '<=', $end_time];
  92. !empty($UserID) && $where[] = ['ai1.GameID', '=', $UserID];
  93. !empty($Higher1ID) && $where[] = ['Higher1ID', '=', $Higher1ID];
  94. !empty($Higher2ID) && $where[] = ['Higher2ID', '=', $Higher2ID];
  95. if (empty($Higher1ID) && empty($Higher2ID)) {
  96. $where[] = ['downCount1', '>', 0];
  97. }
  98. if (!empty($SpreaderID)) {
  99. $spreader_id = DB::connection('read')->table('QPAccountsDB.dbo.AccountsInfo')
  100. ->where('GameID', $SpreaderID)
  101. ->value('UserID');
  102. $where[] = ['Higher1ID', '=', $spreader_id];
  103. }
  104. $field = ['ua.UserID', 'Higher1ID', 'Higher2ID', 'downCount1', 'downCount2', 'ai1.GameID', 'ai2.GameID as SpreaderID', 'ai1.RegisterDate', 'ai1.LastLogonDate'];
  105. $list = DB::connection('read')->table('QPAccountsDB.dbo.UserAgent as ua')
  106. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai1', 'ua.UserID', 'ai1.UserID')
  107. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai2', 'ua.Higher1ID', 'ai2.UserID')
  108. ->where($where)
  109. ->select($field)
  110. ->when($request->input('sort'), function ($q) use ($request) {
  111. $q->orderBy(DB::raw($request->input('sort')), 'desc');
  112. })
  113. ->paginate(10);
  114. $userIDs = array_column($list->items(), 'UserID');
  115. if ($userIDs) {
  116. $ID1 = DB::table('QPAccountsDB.dbo.UserAgent')->whereIn('Higher1ID', $userIDs)
  117. ->selectRaw('Higher1ID as UserID, sum(TotalReward1) as TotalReward')
  118. ->groupBy('Higher1ID')
  119. ->pluck('TotalReward', 'UserID');
  120. $ID2 = DB::table('QPAccountsDB.dbo.UserAgent')->whereIn('Higher2ID', $userIDs)
  121. ->selectRaw('Higher2ID as UserID, sum(TotalReward2) as TotalReward')
  122. ->groupBy('Higher2ID')
  123. ->pluck('TotalReward', 'UserID');
  124. foreach ($list as $k => $v) {
  125. $list[$k]->Rewards = ($ID1[$v->UserID] ?? 0) + ($ID2[$v->UserID] ?? 0);
  126. $list[$k]->Rewards = round($list[$k]->Rewards/100, 2);
  127. }
  128. }
  129. return compact('list', 'start_time', 'end_time', 'UserID', 'SpreaderID', 'Higher1ID', 'Higher2ID');
  130. }
  131. }