UserController.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Facade\TableName;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\helper\Helper;
  6. use App\Http\logic\admin\UserLogicController;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Carbon;
  9. use Illuminate\Support\Facades\Cache;
  10. use Illuminate\Support\Facades\DB;
  11. use App\Models\AccountsInfo;
  12. class UserController extends Controller
  13. {
  14. //用户查询
  15. public function userList(Request $request)
  16. {
  17. $excel = $request->get('excel');
  18. $user_id = $request->input('user_id');
  19. $game_id = $request->post('game_id');
  20. $nickname = $request->post('nickname');
  21. $mobile = $request->post('mobile');
  22. $page = $request->post('page');
  23. $url = $request->input('url');
  24. $start_time = $request->post('start_time');
  25. $end_time = $request->post('end_time');
  26. $goldmin = $request->post('goldmin');
  27. $goldmax = $request->post('goldmax');
  28. $cardmin = $request->post('cardmin');
  29. $cardmax = $request->post('cardmax');
  30. $where = [];
  31. !empty($start_time) ? $where[] = ['ai.RegisterDate', '>=', $start_time] : '';
  32. !empty($end_time) ? $where[] = ['ai.RegisterDate', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  33. !empty($goldmin) ? $where[] = ['gi.Score', '>=', $goldmin] : '';
  34. !empty($goldmax) ? $where[] = ['gi.Score', '<=', $goldmax] : '';
  35. !empty($cardmin) ? $where[] = ['gi.Revenue', '>=', $cardmin] : '';
  36. !empty($cardmax) ? $where[] = ['gi.Revenue', '<=', $cardmax] : '';
  37. !empty($user_id) ? $where[] = ['ai.UserID', '=', (int)$user_id] : '';
  38. !empty($game_id) ? $where[] = ['ai.GameID', '=', (int)$game_id] : '';
  39. !empty($nickname) ? $where[] = ['ai.NickName', 'like', '%' . $nickname . '%'] : '';
  40. !empty($mobile) ? $where[] = ['ap.PhoneNum', '=', $mobile] : '';
  41. if ($excel) {
  42. $cellData = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  43. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as aci', 'ai.SpreaderID', '=', 'aci.UserID')
  44. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  45. ->leftJoin('QPAccountsDB.dbo.AccountPhone as ap', 'ai.UserID', '=', 'ap.UserID')
  46. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as v', 'ai.UserID', '=', 'v.UserID')
  47. ->select('ai.NickName', 'v.Recharge', 'ai.LastLogonDate', 'ai.GameID', 'ai.MemberOrder', 'ai.RegisterDate', 'ai.UserID', 'gi.Score', 'ai.MemberOverDate', 'ap.PhoneNum', 'gi.BankScore', 'ai.Channel', 'ai.PassPortID', 'gi.InsureScore', 'aci.NickName as SpreaderName', 'ai.Compellation', 'gi.Revenue', 'aci.GameID as SpreaderGameID', 'ai.LastLogonMobile', 'ai.Experience', 'aci.UserID as SpreaderUserID')
  48. ->where($where)
  49. ->orderBy('ai.UserID', 'ASC')
  50. ->get();
  51. foreach ($cellData as $key => &$value) {
  52. $second = $value->Experience;
  53. $day = floor($second / (3600 * 24));
  54. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  55. $hour = floor($second / 3600);
  56. $second = $second % 3600;//除去整小时之后剩余的时间
  57. $minute = floor($second / 60);
  58. //返回字符串
  59. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  60. switch ($value->Channel) {
  61. case '1':
  62. $value->Channel = '联运';
  63. break;
  64. case '2':
  65. $value->Channel = '经销商';
  66. break;
  67. default:
  68. $value->Channel = '官方';
  69. break;
  70. }
  71. }
  72. $title = ['用户昵称', '充值总额', '最后登录时间', '游戏ID', 'VIP等级', '注册时间', '用户编号', '携带金豆', 'VIP过期时间', '手机号', '银行金豆', '推荐渠道', '身份证号', '房卡', '推荐人昵称', '姓名', '福卡', '推荐人ID', '操作系统', '游戏时长', '推荐人编号'];
  73. $cellData = json_decode(json_encode($cellData), true);
  74. downloadExcel($cellData, $title, '用户查询' . date('YmdHis'));
  75. } else {
  76. $list = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  77. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as aci', 'ai.SpreaderID', '=', 'aci.UserID')
  78. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  79. ->leftJoin('QPAccountsDB.dbo.AccountPhone as ap', 'ai.UserID', '=', 'ap.UserID')
  80. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as v', 'ai.UserID', '=', 'v.UserID')
  81. ->select('v.Recharge', 'ai.UserID', 'ai.GameID', 'ai.NickName', 'ai.SpreaderID', 'ai.LastLogonDate', 'ai.Nullity', 'ai.Channel', 'ai.PlayTimeCount', 'ai.RegisterDate', 'ai.MemberOrder', 'ai.MemberOverDate', 'ai.LastLogonMobile', 'ai.Experience', 'aci.NickName as SpreaderName', 'aci.GameID as SpreaderGameID', 'aci.UserID as SpreaderUserID', 'gi.InsureScore', 'gi.Score', 'gi.BankScore', 'gi.Revenue', 'ap.PhoneNum', 'ai.PassPortID', 'ai.Compellation')
  82. ->where($where)
  83. ->orderBy('ai.UserID', 'ASC')
  84. ->paginate(10);
  85. foreach ($list as $key => &$value) {
  86. $second = $value->Experience;
  87. $day = floor($second / (3600 * 24));
  88. $second = $second % (3600 * 24);//除去整天之后剩余的时间
  89. $hour = floor($second / 3600);
  90. $second = $second % 3600;//除去整小时之后剩余的时间
  91. $minute = floor($second / 60);
  92. //返回字符串
  93. $value->Experience = $day . '天' . $hour . '小时' . $minute . '分';
  94. switch ($value->Channel) {
  95. case '1':
  96. $value->Channel = '联运';
  97. break;
  98. case '2':
  99. $value->Channel = '经销商';
  100. break;
  101. default:
  102. $value->Channel = '官方';
  103. break;
  104. }
  105. }
  106. return view('admin.user.user_list', ['list' => $list, 'url' => $url, 'user_id' => $user_id, 'game_id' => $game_id, 'nickname' => $nickname, 'mobile' => $mobile, 'start_time' => $start_time, 'end_time' => $end_time, 'goldmin' => $goldmin, 'goldmax' => $goldmax, 'cardmin' => $cardmin, 'cardmax' => $cardmax, 'page' => $page]);
  107. }
  108. }
  109. //用户查询
  110. public function userLost(Request $request)
  111. {
  112. $excel = $request->get('excel',1);
  113. $page = $request->post('page');
  114. $start_time = $request->get('start_time',date('Y-m-d',strtotime("-7day")));
  115. $end_time = $request->get('end_time');
  116. $goldmin = 2500;
  117. $where = [['ai.LastLogonDate','<=',date('Y-m-d',strtotime("-4day"))]];
  118. !empty($start_time) ? $where[] = ['ai.RegisterDate', '>=', $start_time] : '';
  119. !empty($end_time) ? $where[] = ['ai.RegisterDate', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  120. !empty($goldmin) ? $where[] = ['gi.Score', '<>', $goldmin] : '';
  121. if ($excel) {
  122. $cellData = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  123. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as aci', 'ai.SpreaderID', '=', 'aci.UserID')
  124. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  125. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as v', 'ai.UserID', '=', 'v.UserID')
  126. ->select('ai.NickName', 'v.Recharge','gi.WinCount','gi.LostCount', 'ai.GameID','ai.LastLogonDate','ai.RegisterDate', 'ai.UserID','gi.Score')
  127. ->where($where)
  128. ->orderBy('ai.UserID', 'ASC')
  129. ->get();
  130. foreach ($cellData as $key => &$value) {
  131. $gameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameCount')
  132. ->where('UserID',$value->UserID)
  133. ->pluck('Cnt', 'GameID')->toArray();
  134. $value->x50 = $gameCount[3010];
  135. $value->x9 = $gameCount[3014];
  136. $value->yyl = $gameCount[3015];
  137. $value->wc = $gameCount[3016];
  138. $value->th = $gameCount[3017];
  139. $value->trea = $gameCount[3018];
  140. $value->light = $gameCount[3019];
  141. }
  142. $title = ['用户昵称', '充值总额','游戏赢的次数','游戏输的次数', '最后登录时间','注册时间', 'GameID','携带金豆','50线','9线','摇摇乐','世界杯','雷神','宝藏','闪电'];
  143. $cellData = json_decode(json_encode($cellData), true);
  144. downloadExcel($cellData, $title, '用户查询' . date('YmdHis'));
  145. } else {
  146. $list = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  147. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as aci', 'ai.SpreaderID', '=', 'aci.UserID')
  148. ->leftJoin('QPTreasureDB.dbo.GameScoreInfo as gi', 'ai.UserID', '=', 'gi.UserID')
  149. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as v', 'ai.UserID', '=', 'v.UserID')
  150. ->select('ai.NickName', 'v.Recharge','gi.WinCount','gi.LostCount', 'ai.GameID','ai.LastLogonDate','ai.RegisterDate', 'ai.UserID','gi.Score')
  151. ->where($where)
  152. ->orderBy('ai.UserID', 'ASC')
  153. ->get();
  154. foreach ($list as $key => &$value) {
  155. $gameCount = DB::table(TableName::QPRecordDB() . 'RecordUserGameCount')
  156. ->where('UserID',$value->UserID)
  157. ->pluck('Cnt', 'GameID')->toArray();
  158. $value->x50 = $gameCount[3010];
  159. $value->x9 = $gameCount[3014];
  160. $value->yyl = $gameCount[3015];
  161. $value->wc = $gameCount[3016];
  162. $value->th = $gameCount[3017];
  163. $value->trea = $gameCount[3018];
  164. $value->light = $gameCount[3019];
  165. }
  166. var_dump($list);
  167. return view('admin.user.user_lost', ['list' => $list,'start_time' => $start_time, 'end_time' => $end_time, 'page' => $page]);
  168. }
  169. }
  170. //用户分布
  171. public function userClassify(Request $request)
  172. {
  173. $player_list = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  174. ->leftJoin('QPAccountsDB.dbo.YN_VIPAccount as va', 'ai.UserID', '=', 'va.UserID')
  175. ->where('IsAndroid', 0)
  176. ->whereIn('LastLogonMobile', ['Android', 'IOS'])
  177. ->select('ai.LastLogonMobile', 'ai.UserID', 'va.Recharge', 'ai.LastLogonDate', 'ai.Gender')
  178. // ->select(DB::raw("count('ai.*') as num,ai.LastLogonMobile,sum('va.Recharge') as m"))
  179. // ->groupBy('LastLogonMobile')
  180. ->get();
  181. $nowtime = time();
  182. $android_num = $ios_num = 0;
  183. $android_lively_num = $ios_lively_num = 0;
  184. $android_recharge = $ios_recharge = 0;
  185. $android_recharge_num = $ios_recharge_num = 0;
  186. $android_man = $android_woman = $ios_man = $ios_woman = 0;
  187. $android_arppu = $ios_arppu = $ios_arpu = $android_arpu = $android_man_ratio = $android_woman_ratio
  188. = $ios_man_ratio = $ios_woman_ratio = $android_recharge_ratio = $ios_recharge_ratio = 0;
  189. foreach ($player_list as $key => $value) {
  190. if ($value->LastLogonMobile === 'Android') {
  191. $android_num += 1;//安卓用户数
  192. $time = ceil(($nowtime - strtotime($value->LastLogonDate)) / 86400);
  193. if ($time <= 7) {
  194. $android_lively_num += 1;//安卓七日活跃用户数
  195. }
  196. if (!empty($value->Recharge)) {
  197. $android_recharge += $value->Recharge;//安卓累计充值金额
  198. $android_recharge_num += 1;//安卓充值用户数
  199. }
  200. if ($value->Gender == 1) {
  201. $android_man += 1;
  202. } else {
  203. $android_woman += 1;
  204. }
  205. } else {
  206. $ios_num += 1;//IOS用户数
  207. $time = ceil(($nowtime - strtotime($value->LastLogonDate)) / 86400);
  208. if ($time <= 7) {
  209. $ios_lively_num += 1;//IOS七日活跃用户数
  210. }
  211. if (!empty($value->Recharge)) {
  212. $ios_recharge += $value->Recharge;
  213. $ios_recharge_num += 1;
  214. }
  215. if ($value->Gender == 1) {
  216. $ios_man += 1;
  217. } else {
  218. $ios_woman += 1;
  219. }
  220. }
  221. }
  222. $android_num ? $android_man_ratio = round(($android_man / $android_num) * 100, 2) . '%' : '0%';//安卓男生比例
  223. $android_num ? $android_woman_ratio = round(($android_woman / $android_num) * 100, 2) . '%' : '0%';//安卓女生比例
  224. $ios_num ? $ios_man_ratio = round(($ios_man / $ios_num) * 100, 2) . '%' : '0%';//ios男生比例
  225. $ios_num ? $ios_woman_ratio = round(($ios_woman / $ios_num) * 100, 2) . '%' : '0%';//ios女生比例
  226. $android_num ? $android_recharge_ratio = round(($android_recharge_num / $android_num) * 100, 2) . '%' : '0%';//安卓充值率
  227. $ios_num ? $ios_recharge_ratio = round(($ios_recharge_num / $ios_num) * 100, 2) . '%' : '0%';//ios充值率
  228. $android_lively_num ? $android_arpu = round(($android_recharge / $android_lively_num), 2) : 0;//安卓ARPU
  229. $ios_lively_num ? $ios_arpu = round(($ios_recharge / $ios_lively_num), 2) : 0;//ios ARPU
  230. $android_recharge_num ? $android_arppu = round(($android_recharge / $android_recharge_num), 2) : 0;//ios ARPU
  231. $ios_recharge_num ? $ios_arppu = round(($ios_recharge / $ios_recharge_num), 2) : 0;//ios ARPU
  232. $list = [
  233. [
  234. 'type' => '安卓',
  235. 'num' => $android_num,
  236. 'lively_num' => $android_lively_num,
  237. 'recharge' => number_format($android_recharge),
  238. 'recharge_num' => $android_recharge_num,
  239. 'recharge_ratio' => $android_recharge_ratio,
  240. 'arpu' => $android_arpu,
  241. 'arppu' => $android_arppu,
  242. 'ratio' => '男' . $android_man_ratio . '女' . $android_woman_ratio,
  243. ],
  244. [
  245. 'type' => '苹果',
  246. 'num' => $ios_num,
  247. 'lively_num' => $ios_lively_num,
  248. 'recharge' => number_format($ios_recharge),
  249. 'recharge_num' => $ios_recharge_num,
  250. 'recharge_ratio' => $ios_recharge_ratio,
  251. 'arpu' => $ios_arpu,
  252. 'arppu' => $ios_arppu,
  253. 'ratio' => '男' . $ios_man_ratio . '女' . $ios_woman_ratio,
  254. ]
  255. ];
  256. return view('admin.user.user_classify', ['list' => $list]);
  257. }
  258. //购买记录
  259. public function purchaseHistoryList(Request $request, $id)
  260. {
  261. $start_time = $request->post('start_time');
  262. $end_time = $request->post('end_time');
  263. $order_title = $request->post('order_title');
  264. $order_sn = $request->post('order_sn');
  265. $where[] = ['user_id', '=', $id];
  266. !empty($start_time) ? $where[] = ['order.pay_at', '>=', $start_time] : '';
  267. !empty($end_time) ? $where[] = ['order.pay_at', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  268. !empty($order_title) ? $where[] = ['order.order_title', 'like', '%' . $order_title . '%'] : '';
  269. !empty($order_sn) ? $where[] = ['order.order_sn', '=', $order_sn] : '';
  270. $list = DB::connection('write')->table('order')
  271. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'order.user_id', '=', 'ai.UserID')
  272. ->select('order.finished_at', 'order.order_sn', 'order.payment_sn', 'order.trade_sn', 'order.order_title', 'order.amount', 'ai.GameID', 'ai.NickName')
  273. ->where($where)
  274. ->orderby('order.finished_at', 'desc')
  275. ->WhereNotNull('pay_at')
  276. ->paginate(20);
  277. $nick_name = '';
  278. $game_id = '';
  279. !empty($list[0]->NickName) ? $nick_name = $list[0]->NickName : '';
  280. !empty($list[0]->GameID) ? $game_id = $list[0]->GameID : '';
  281. return view('admin.user.purchase', ['list' => $list, 'nick_name' => $nick_name, 'game_id' => $game_id, 'order_title' => $order_title, 'order_sn' => $order_sn, 'start_time' => $start_time, 'end_time' => $end_time, 'user_id' => $id]);
  282. }
  283. //游戏记录
  284. public function gameHistoryList(Request $request, $id)
  285. {
  286. $start_time = $request->post('start_time');
  287. $end_time = $request->post('end_time');
  288. $game = $request->post('game');
  289. $type = $request->post('type');
  290. $where[] = ['rs.UserID', '=', $id];
  291. !empty($start_time) ? $where[] = ['rs.InsertTime', '>=', $start_time] : '';
  292. !empty($end_time) ? $where[] = ['rs.InsertTime', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  293. !empty($game) ? $where[] = ['gi.GameID', '=', $game] : '';
  294. !empty($type) ? $where[] = ['gi.SortID', '=', $type] : '';
  295. $list = DB::table('QPTreasureDB.dbo.RecordDrawScore as rs')
  296. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'rs.UserID', '=', 'ai.UserID')
  297. ->leftJoin('QPTreasureDB.dbo.RecordDrawInfo as ri', 'rs.DrawID', '=', 'ri.DrawID')
  298. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as gi', 'ri.ServerID', '=', 'gi.ServerID')
  299. ->select('rs.DrawID', 'rs.PlayTimeCount', 'rs.Score', 'rs.Revenue', 'rs.InsertTime', 'ai.NickName', 'ai.GameID', 'ri.ServerID', 'gi.ServerName', 'gi.SortID')
  300. ->where($where)
  301. ->orderBy('rs.InsertTime', 'desc')
  302. ->paginate(20);
  303. foreach ($list as $key => &$value) {
  304. $value->Score = number_format($value->Score);
  305. if (!empty($value)) {
  306. switch ($value->SortID) {
  307. case '1':
  308. $value->SortID = '初级';
  309. break;
  310. case '2':
  311. $value->SortID = '普通';
  312. break;
  313. case '4':
  314. $value->SortID = '中级';
  315. break;
  316. case '8':
  317. $value->SortID = '高级';
  318. break;
  319. case '64':
  320. $value->SortID = '包厢';
  321. break;
  322. }
  323. }
  324. }
  325. $nick_name = '';
  326. $game_id = '';
  327. !empty($list[0]->NickName) ? $nick_name = $list[0]->NickName : '';
  328. !empty($list[0]->GameID) ? $game_id = $list[0]->GameID : '';
  329. $room_type = ['1' => '初级', '2' => '普通', '4' => '中级', '8' => '高级', '64' => '包厢'];
  330. $game_name = DB::connection('write')->table('QPPlatformDB.dbo.GameGameItem')->pluck('GameName', 'GameID');//单选框数据
  331. $level = ['1' => '初级', '2' => '普通', '4' => '中级', '8' => '高级', '64' => '包厢',];
  332. return view('admin.user.game', ['list' => $list, 'game' => $game, 'start_time' => $start_time, 'end_time' => $end_time, 'type' => $type, 'user_id' => $id, 'nick_name' => $nick_name, 'game_id' => $game_id, 'game_name' => $game_name, 'room_type' => $room_type]);
  333. }
  334. //金豆记录
  335. public function scoreHistoryList(Request $request, $id)
  336. {
  337. $start_time = $request->post('start_time');
  338. $end_time = $request->post('end_time');
  339. $describe = $request->post('describe');
  340. $game = $request->post('game');
  341. $type = $request->post('type');
  342. $where[] = ['si.UserID', '=', $id];
  343. !empty($start_time) ? $where[] = ['si.UpdateTime', '>=', $start_time . ' 00:00:00'] : '';
  344. !empty($end_time) ? $where[] = ['si.UpdateTime', '<=', $end_time . ' 23:59:59'] : '';
  345. !empty($describe) ? $where[] = ['Describe', 'like', '%' . trim($describe, " ") . '%'] : '';
  346. !empty($game) ? $where[] = ['ri.GameID', '=', $game] : '';
  347. !empty($type) ? $where[] = ['ri.SortID', '=', $type] : '';
  348. ////////////////////////
  349. // 查询范围需要在同一个月份,暂时不支持跨月份查询
  350. $from_mm = intval(date('Ym', strtotime($start_time)));
  351. $to_mm = intval(date('Ym', strtotime($end_time)));
  352. if ($from_mm != $to_mm) {
  353. throw new Exception('暂不支持跨月查询,开始时间和结束时间请选择相同月份');
  354. }
  355. //确定有效表范围,从202104月开始到当前月
  356. if ($from_mm < 202104 || $from_mm > intval(date('Ym'))) {
  357. $from_mm = date('Ym');
  358. }
  359. $table = 'QPTreasureDB.dbo.YN_RecordScoreInfo_' . $from_mm;
  360. //////////////////////
  361. $list = DB::table($table . ' as si')
  362. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ai', 'si.UserID', '=', 'ai.UserID')
  363. ->leftJoin('QPPlatformDB.dbo.GameRoomInfo as ri', 'ri.ServerID', '=', 'si.ServerID')
  364. ->join('QPRecordDB.dbo.YN_RecordScoreConfig as sc', 'sc.Reason', '=', 'si.Reason')
  365. ->select('si.UserID', 'si.BeforeScore', 'si.ChangeScore', 'si.AfterScore', 'si.UpdateTime', 'ai.NickName', 'ai.GameID', 'sc.Describe', 'ri.ServerName', 'ri.SortID')
  366. ->where($where)
  367. ->orderBy('UpdateTime', 'desc')
  368. ->paginate(10);
  369. foreach ($list as $key => &$value) {
  370. $value->BeforeScore = number_format($value->BeforeScore);
  371. $value->ChangeScore = number_format($value->ChangeScore);
  372. $value->AfterScore = number_format($value->AfterScore);
  373. if (!empty($value)) {
  374. switch ($value->SortID) {
  375. case '1':
  376. $value->SortID = '初级';
  377. break;
  378. case '2':
  379. $value->SortID = '普通';
  380. break;
  381. case '4':
  382. $value->SortID = '中级';
  383. break;
  384. case '8':
  385. $value->SortID = '高级';
  386. break;
  387. case '64':
  388. $value->SortID = '包厢';
  389. break;
  390. }
  391. }
  392. }
  393. $nick_name = '';
  394. $game_id = '';
  395. !empty($list[0]->NickName) ? $nick_name = $list[0]->NickName : '';
  396. !empty($list[0]->GameID) ? $game_id = $list[0]->GameID : '';
  397. $room_type = ['1' => '初级', '2' => '普通', '4' => '中级', '8' => '高级', '64' => '包厢'];
  398. $game_name = DB::connection('write')->table('QPPlatformDB.dbo.GameGameItem')->pluck('GameName', 'GameID');//单选框数据
  399. return view('admin.user.score', ['list' => $list, 'describe' => $describe, 'start_time' => $start_time, 'end_time' => $end_time, 'user_id' => $id, 'nick_name' => $nick_name, 'game_id' => $game_id, 'game' => $game, 'type' => $type, 'game_name' => $game_name, 'room_type' => $room_type]);
  400. }
  401. //福卡记录
  402. public function cardHistoryList(Request $request, $id)
  403. {
  404. $start_time = $request->post('start_time');
  405. $end_time = $request->post('end_time');
  406. $describe = $request->post('describe');
  407. $where[] = ['si.UserID', '=', $id];
  408. !empty($start_time) ? $where[] = ['si.UpdateTime', '>=', $start_time] : '';
  409. !empty($end_time) ? $where[] = ['si.UpdateTime', '<=', date('Y-m-d', strtotime("$end_time+1day"))] : '';
  410. !empty($describe) ? $where[] = ['Describe', 'like', '%' . trim($describe, " ") . '%'] : '';
  411. $list = DB::connection('write')->table('QPRecordDB.dbo.YN_RecordRevenueInfo as si')
  412. ->leftJoin('QPRecordDB.dbo.YN_RecordScoreConfig as sc', 'sc.Reason', '=', 'si.Reason')
  413. ->select('si.*', 'sc.Describe')
  414. ->where($where)
  415. ->orderBy('si.UpdateTime', 'desc')
  416. ->paginate(10);
  417. foreach ($list as $key => &$value) {
  418. $value->BeforeRevenue = number_format($value->BeforeRevenue);
  419. $value->ChangeRevenue = number_format($value->ChangeRevenue);
  420. $value->AfterRevenue = number_format($value->AfterRevenue);
  421. }
  422. $describe_list = DB::table('QPRecordDB.dbo.YN_RecordScoreConfig')->pluck('Describe');
  423. return view('admin.user.card', ['list' => $list, 'describe' => $describe, 'describe_list' => $describe_list, 'start_time' => $start_time, 'end_time' => $end_time, 'user_id' => $id]);
  424. }
  425. //冻结玩家
  426. public function freezeUser(Request $request, $id)
  427. {
  428. $result = DB::table('QPAccountsDB.dbo.AccountsInfo')
  429. ->where('UserID', $id)->update(['Nullity' => $request->post('nullity')]);
  430. if ($result) {
  431. return $this->json(200, "处理成功");
  432. } else {
  433. return $this->json(500, '处理失败,请重试');
  434. }
  435. }
  436. //VIP等级分布
  437. public function VipClassify(Request $request)
  438. {
  439. $all = AccountsInfo::selectRaw('MemberOrder,COUNT(*) AS VipAllCount')
  440. ->groupBy('MemberOrder')
  441. ->orderBy('MemberOrder')
  442. ->get()->toarray();
  443. $now = AccountsInfo::selectRaw('MemberOrder,COUNT(*) AS VipNowCount')
  444. ->whereRaw('MemberOverDate>GETDATE()')
  445. ->groupBy('MemberOrder')
  446. ->orderBy('MemberOrder')
  447. ->get()->toarray();
  448. foreach ($all as $key => &$value) {
  449. isset($now[$key]) ? $value['VipNowCount'] = $now[$key]['VipNowCount'] : $value['VipNowCount'] = 0;
  450. isset($now[$key]) ? $count = $now[$key]['VipNowCount'] : $count = 0;
  451. $value['VipOldCount'] = $value['VipAllCount'] - $count;
  452. }
  453. return view('admin.user.vip_classify', ['list' => $all]);
  454. }
  455. public function createHexiao(Request $request)
  456. {
  457. $params = $request->all();
  458. if ($params) {
  459. if (!$params['password'] || !$params['name'] || !$params['repwd'] || !$params['wx_account']) {
  460. return view('admin.user.create_hexiao', ['msg' => '缺少参数', 'status' => 1]);
  461. }
  462. if ($params['password'] !== $params['repwd']) {
  463. return view('admin.user.create_hexiao', ['msg' => '2次密码输入不一致', 'status' => 1]);
  464. }
  465. if (DB::table('agent.dbo.agent')->where('wx_account', $params['wx_account'])->first()) {
  466. return ['status' => false, 'message' => '登录账号不能重复'];
  467. }
  468. $password = bcrypt($params['password']);
  469. $data = [
  470. 'role_id' => 0,
  471. 'parent_id' => 0,
  472. 'name' => $params['name'],
  473. 'wx_account' => $params['wx_account'],
  474. 'mobile' => 0,
  475. 'id_card' => 0,
  476. 'status' => 1,
  477. 'password' => $password,
  478. 'num_account' => $this->get_num_account(),
  479. 'hexiao' => 1,
  480. ];
  481. if ($a = DB::table('agent.dbo.agent')->insert($data)) {
  482. //var_dump($a);
  483. $agent_id = DB::getPdo()->lastInsertId();
  484. DB::table('agent.dbo.agent_app')->insert([
  485. 'agent_id' => $agent_id,
  486. 'app_id' => 1
  487. ]);
  488. return view('admin.user.create_hexiao', ['msg' => '创建成功', 'status' => 1]);
  489. } else {
  490. return ['status' => false, 'message' => '创建失败', 'status' => 1];
  491. }
  492. }
  493. return view('admin.user.create_hexiao', ['msg' => '创建成功', 'status' => 0]);
  494. }
  495. private function get_num_account()
  496. {
  497. /* 选择一个随机的方案 */
  498. mt_srand((double)microtime() * 1000000000);
  499. $num_account = str_pad(mt_rand(1, 99999), 6, STR_PAD_LEFT);
  500. $agent = DB::table('agent.dbo.agent')->select('num_account')->where(array('num_account' => $num_account))->first();
  501. if (!$agent) {
  502. return $num_account;
  503. }
  504. /* 如果有重复的,则重新生成 */
  505. return $this->get_num_account();
  506. }
  507. //全民推广查询
  508. public function userSpreaderList(Request $request)
  509. {
  510. $game_id = $request->get('game_id');
  511. $end_time = $request->input('end_time');
  512. $start_time = $request->input('start_time');
  513. $where = [];
  514. if (empty($start_time)) {
  515. $start_time = date('Y-m-d', strtotime("-9 days"));
  516. $where[] = ['RegisterDate', '>=', $start_time];
  517. } else {
  518. $where[] = ['RegisterDate', '>=', $start_time];
  519. }
  520. if (empty($end_time)) {
  521. $where[] = ['RegisterDate', '<=', date('Y-m-d')];
  522. $end_time = date('Y-m-d');
  523. } else {
  524. $where[] = ['RegisterDate', '<=', $end_time];
  525. }
  526. $user_info = DB::table('QPAccountsDB.dbo.AccountsInfo')
  527. ->select('NickName', 'UserID')
  528. ->where('GameID', $game_id)
  529. ->first();
  530. if (empty($user_info)) {
  531. return view('admin.user.spreaders', ['list' => [], 'game_id' => $game_id, 'start_time' => $start_time, 'end_time' => $end_time]);
  532. }
  533. $user_id = $user_info->UserID;
  534. !empty($user_id) ? $where[] = ['SpreaderID', '=', $user_id] : '';
  535. //推广员姓名
  536. $name = DB::table('agent')->Where('UserID', $user_id)->value('name');
  537. //推广总用户数
  538. $children_count = DB::table('QPAccountsDB.dbo.AccountsInfo')
  539. ->where($where)
  540. ->count();
  541. //活跃用户
  542. $live_users = DB::table('QPAccountsDB.dbo.AccountsInfo')
  543. ->where($where)
  544. ->where('LastLogonDate', '>=', date('Y-m-d', strtotime('-7 days')))
  545. ->count();
  546. //有效用户
  547. $eff_user = DB::table('QPAccountsDB.dbo.AccountsInfo')
  548. ->where($where)
  549. ->where('Experience', '>=', 6000)
  550. ->count();
  551. //流失用户
  552. $sleep_users = DB::table('QPAccountsDB.dbo.AccountsInfo')
  553. ->where($where)
  554. ->where('LastLogonDate', '<=', date('Y-m-d', strtotime('-7 days')))
  555. ->count();
  556. //已提收益
  557. $gold = DB::table('QPAccountsDB.dbo.YN_Withdrawal')
  558. ->selectRaw('sum(Gold) as gold')
  559. ->where('UserID', $user_id)
  560. ->value('gold');
  561. //计提收益
  562. $revenue = DB::table('QPAccountsDB.dbo.YN_Agent')
  563. ->where('UserID', $user_id)
  564. ->value('Revenue');
  565. //总收益
  566. $revenue_sum = DB::table('QPTreasureDB.dbo.YN_HistoryPerformance')
  567. ->select(DB::raw('sum(ProfitGold0+ProfitGold1+ProfitGold2) as revenue_sum'))
  568. ->where('UserID', $user_id)
  569. ->where('BalanceDate', '>=', $start_time)
  570. ->where('BalanceDate', '<=', $end_time)
  571. ->value('revenue_sum');
  572. $result = [
  573. 'user_id' => $user_id,
  574. 'game_id' => $game_id,
  575. 'nick_name' => $user_info->NickName,
  576. 'name' => $name,
  577. 'children_count' => $children_count,
  578. 'live_users' => $live_users,
  579. 'eff_user' => $eff_user,
  580. 'sleep_users' => $sleep_users,
  581. 'gold' => $gold,
  582. 'revenue' => $revenue,
  583. 'revenue_sum' => $revenue_sum,
  584. ];
  585. return view('admin.user.spreaders', ['list' => $result, 'game_id' => $game_id, 'start_time' => $start_time, 'end_time' => $end_time]);
  586. }
  587. //每日推广数据
  588. public function everydaySpreaderList(Request $request, $user_id)
  589. {
  590. $end_time = $request->input('end_time');
  591. $start_time = $request->input('start_time');
  592. $where = [];
  593. !empty($user_id) ? $where[] = ['SpreaderID', '=', $user_id] : '';
  594. if (empty($start_time)) {
  595. $start_time = date('Y-m-d', strtotime("-50days"));
  596. $where[] = ['RegisterDate', '>=', $start_time];
  597. } else {
  598. $where[] = ['RegisterDate', '>=', $start_time];
  599. }
  600. if (empty($end_time)) {
  601. $where[] = ['RegisterDate', '<=', date('Y-m-d')];
  602. $end_time = date('Y-m-d');
  603. } else {
  604. $where[] = ['RegisterDate', '<=', $end_time];
  605. }
  606. $begintime = strtotime($start_time);
  607. $endtime = strtotime($end_time);
  608. for ($start = $begintime; $start <= $endtime; $start += 24 * 3600) {
  609. $date_arr[] = ['date' => date("Y-m-d", $start)];
  610. }
  611. $user_info = DB::table('QPAccountsDB.dbo.AccountsInfo')
  612. ->select('NickName', 'GameID')
  613. ->where('UserID', $user_id)
  614. ->first();
  615. //每日新增
  616. $add_users_list = DB::table('QPAccountsDB.dbo.AccountsInfo')
  617. ->selectRaw('CONVERT(varchar(100),RegisterDate,23) as date,count(*) as count')
  618. ->where($where)
  619. ->where('SpreaderID', $user_id)
  620. ->groupBy(DB::raw('CONVERT(varchar(100),RegisterDate,23)'))
  621. ->get();
  622. // print_r($add_users_list);exit;
  623. //每日收益
  624. $revenue_sum_list = DB::table('QPTreasureDB.dbo.YN_HistoryPerformance')
  625. ->selectRaw('BalanceDate,sum(ProfitGold0+ProfitGold1+ProfitGold2) as revenue_sum')
  626. ->where('BalanceDate', '>=', $start_time)
  627. ->where('BalanceDate', '<=', $end_time)
  628. ->where('UserID', $user_id)
  629. ->groupBy('BalanceDate')
  630. ->get();
  631. foreach ($revenue_sum_list as $key => $value) {
  632. $revenue_sum[$value->BalanceDate] = $value->revenue_sum;
  633. }
  634. $add_users = [];
  635. foreach ($add_users_list as $key => $value) {
  636. $add_users[$value->date] = $value->count;
  637. }
  638. $retain_users = DB::table('QPAccountsDB.dbo.AccountsInfo')
  639. ->select('UserID', DB::raw('CONVERT(varchar(100),RegisterDate,23) as date'))
  640. ->where('SpreaderID', $user_id)
  641. ->whereIn(DB::raw('CONVERT(varchar(100),RegisterDate,23)'), $date_arr)
  642. ->get();
  643. foreach ($date_arr as $key => &$value) {
  644. if (isset($add_users[$value['date']])) {
  645. $value['count'] = $add_users[$value['date']];
  646. } else {
  647. $value['count'] = 0;
  648. }
  649. if (isset($revenue_sum[$value['date']])) {
  650. $value['revenue_sum'] = $revenue_sum[$value['date']];
  651. } else {
  652. $value['revenue_sum'] = 0;
  653. }
  654. $date = $value['date'];
  655. $retain_users = DB::table('QPAccountsDB.dbo.AccountsInfo')
  656. ->select('UserID', DB::raw('CONVERT(varchar(100),RegisterDate,23) as date'))
  657. ->where('SpreaderID', $user_id)
  658. ->where(DB::raw('CONVERT(varchar(100),RegisterDate,23)'), date('Y-m-d', strtotime("$date-2 days")))
  659. // ->groupBy(DB::raw('CONVERT(varchar(100),RegisterDate,23)'))
  660. ->get()
  661. ->toArray();
  662. $count = 0;
  663. if ($retain_users) {
  664. foreach ($retain_users as $k => $v) {
  665. $count += DB::table('QPAccountsDB.dbo.AccountsInfo')
  666. ->where('UserID', $v->UserID)
  667. ->where(DB::raw('CONVERT(varchar(100),LastLogonDate,23)'), date('Y-m-d', strtotime("$v->date+1 days")))
  668. ->count();
  669. }
  670. }
  671. //每日流失
  672. $sleep_users = DB::table('QPAccountsDB.dbo.AccountsInfo')
  673. ->where('SpreaderID', $user_id)
  674. ->where('LastLogonDate', '<=', date('Y-m-d', strtotime("$date-7 days")))
  675. ->count();
  676. $value['sleep'] = $sleep_users;
  677. $value['retain'] = $count;
  678. }
  679. return view('admin.user.everyday_spreaders', ['list' => $date_arr, 'user_id' => $user_id, 'start_time' => $start_time, 'end_time' => $end_time, 'user_info' => $user_info]);
  680. }
  681. //下级推广数据
  682. public function subordinateList(Request $request, $user_id)
  683. {
  684. $end_time = $request->input('end_time');
  685. $start_time = $request->input('start_time');
  686. $where = [];
  687. !empty($user_id) ? $where[] = ['ai.SpreaderID', '=', $user_id] : '';
  688. if (empty($start_time)) {
  689. $start_time = date('Y-m-d', strtotime("-100days"));
  690. $where[] = ['ai.RegisterDate', '>=', $start_time];
  691. } else {
  692. $where[] = ['ai.RegisterDate', '>=', $start_time];
  693. }
  694. if (empty($end_time)) {
  695. $where[] = ['ai.RegisterDate', '<=', date('Y-m-d')];
  696. $end_time = date('Y-m-d');
  697. } else {
  698. $where[] = ['ai.RegisterDate', '<=', $end_time];
  699. }
  700. $user_info = DB::table('QPAccountsDB.dbo.AccountsInfo')
  701. ->select('NickName', 'GameID')
  702. ->where('UserID', $user_id)
  703. ->first();
  704. $add_users_list = DB::table('QPAccountsDB.dbo.AccountsInfo as ai')
  705. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as ais', 'ais.SpreaderID', '=', 'ai.UserID')
  706. ->selectRaw('ai.UserID,ai.NickName,count(ais.UserID) as count')
  707. ->where($where)
  708. ->groupBy('ai.UserID', 'ai.NickName')
  709. // ->get();
  710. ->paginate(10);
  711. $add_users_val = array_column(json_decode(json_encode($add_users_list), true)['data'], 'UserID');
  712. // $add_users_val = array_column(json_decode(json_encode($add_users_list),true),'UserID');
  713. // print_r($add_users_val);
  714. // 活跃用户
  715. $live_list = DB::table('QPAccountsDB.dbo.AccountsInfo')
  716. ->selectRaw('SpreaderID,count(*) as count')
  717. ->where('RegisterDate', '>=', $start_time)
  718. ->where('RegisterDate', '<=', $end_time)
  719. ->whereIn('SpreaderID', $add_users_val)
  720. ->where('LastLogonDate', '>=', date('Y-m-d', strtotime('-7 days')))
  721. ->groupBy('SpreaderID')
  722. ->get();
  723. $lives = [];
  724. foreach ($live_list as $key => $value) {
  725. $lives[$value->SpreaderID] = $value->count;
  726. }
  727. //收益
  728. $revenue_sum = DB::table('QPTreasureDB.dbo.YN_HistoryPerformance')
  729. ->selectRaw('UserID,sum(ProfitGold0+ProfitGold1+ProfitGold2) as revenue_sum')
  730. ->whereIn('UserID', $add_users_val)
  731. ->where('BalanceDate', '>=', $start_time)
  732. ->where('BalanceDate', '<=', $end_time)
  733. ->groupBy('UserID')
  734. ->get();
  735. $revenue = [];
  736. foreach ($revenue_sum as $key => $value) {
  737. $revenue[$value->UserID] = $value->revenue_sum;
  738. }
  739. foreach ($add_users_list as $key => &$value) {
  740. if (isset($lives[$value->UserID])) {
  741. $value->live = $lives[$value->UserID];
  742. } else {
  743. $value->live = 0;
  744. }
  745. if (isset($revenue[$value->UserID])) {
  746. $value->revenue = $revenue[$value->UserID];
  747. } else {
  748. $value->revenue = 0;
  749. }
  750. }
  751. return view('admin.user.subordinate', ['list' => $add_users_list, 'user_id' => $user_id, 'start_time' => $start_time, 'end_time' => $end_time, 'user_info' => $user_info]);
  752. }
  753. //核销查询
  754. public function verificationList(Request $request)
  755. {
  756. $end_time = $request->input('end_time');
  757. $start_time = $request->input('start_time');
  758. $user_id = $request->input('user_id');
  759. $where = [];
  760. $where[] = ['code.State', '=', 1];
  761. !empty($user_id) ? $where[] = ['code.agent_id', '=', $user_id] : '';
  762. if (empty($start_time)) {
  763. $start_time = date('Y-m-d');
  764. $where[] = ['code.UpdateTime', '>=', $start_time];
  765. } else {
  766. $where[] = ['code.UpdateTime', '>=', $start_time];
  767. }
  768. if (empty($end_time)) {
  769. $where[] = ['code.UpdateTime', '<=', date('Y-m-d', strtotime("+1 days"))];
  770. $end_time = date('Y-m-d');
  771. } else {
  772. $where[] = ['code.UpdateTime', '<=', $end_time];
  773. }
  774. $list = DB::table('QPAccountsDB.dbo.YN_UniqueCode as code')
  775. ->leftJoin('QPAccountsDB.dbo.YN_MatchProp as prop', 'code.PropID', '=', 'prop.PropID')
  776. ->leftJoin('QPAccountsDB.dbo.AccountsInfo as account', 'code.UserID', '=', 'account.UserID')
  777. ->leftJoin('agent.dbo.agent as agent', 'code.agent_id', '=', 'agent.id')
  778. ->selectRaw('account.NickName,prop.PropName,prop.Description,agent.name,code.UpdateTime,code.agent_id')
  779. ->where($where)
  780. ->orderBy('code.UpdateTime', 'desc')
  781. ->paginate(10);
  782. return view('admin.user.verification', ['list' => $list, 'user_id' => $user_id, 'start_time' => $start_time, 'end_time' => $end_time]);
  783. }
  784. // 用户金额变化明细
  785. public function scoreChange(Request $request)
  786. {
  787. $start_time = $request->get('start_time');
  788. $end_time = $request->get('end_time');
  789. $describe = (int)$request->get('describe') ?: '';
  790. $UserID = (int)$request->get('UserID') ?: '';
  791. $ChangeScoreMin = $request->ChangeScoreMin;
  792. $ChangeScoreMax = $request->ChangeScoreMax;
  793. $ChangeScoreSort = $request->ChangeScoreSort ?: '';
  794. $r = (new UserLogicController())->scoreChange($start_time, $end_time, $describe, $UserID, $ChangeScoreMin, $ChangeScoreMax, $ChangeScoreSort);
  795. return view('admin.user.score_change', $r);
  796. }
  797. // 绑定关系查询
  798. public function bind_list(Request $request)
  799. {
  800. $start_time = $request->start_time ?: '';
  801. $end_time = $request->end_time ?: '';
  802. $Higher1ID = $request->Higher1ID ?: '';
  803. $Higher2ID = $request->Higher2ID ?: '';
  804. $SpreaderID = $request->SpreaderID ?: '';
  805. // 跳转页面条件
  806. $source = $request->source ?: 1;
  807. $NickName = $request->NickName ?: '';
  808. $GameID = $request->GameID ?: '';
  809. $mobile = $request->mobile ?: '';
  810. $Type = $request->Type ?: '';
  811. $Sort = $request->Sort ?: '';
  812. $FinalScoreSort = $request->FinalScoreSort ?: '';
  813. $UserID = $request->UserID ?: '';
  814. $result = (new UserLogicController())->bind_list(
  815. $start_time,
  816. $end_time,
  817. $UserID,
  818. $Higher1ID,
  819. $Higher2ID,
  820. $SpreaderID,
  821. $request
  822. );
  823. $result['source'] = $source;
  824. $result['NickName'] = $NickName;
  825. $result['GameID'] = $GameID;
  826. $result['mobile'] = $mobile;
  827. $result['Type'] = $Type;
  828. $result['Sort'] = $Sort;
  829. $result['FinalScoreSort'] = $FinalScoreSort;
  830. $result['request'] = $request;
  831. if (empty($Higher1ID) && empty($Higher2ID)) {
  832. return view('admin.user.bind_list', $result);
  833. } else {
  834. return view('admin.user.bind_child_list', $result);
  835. }
  836. }
  837. public function user_tab($tab_id)
  838. {
  839. $explain = Cache::remember($tab_id, Carbon::tomorrow(), function () use ($tab_id) {
  840. return $explain = DB::table('QPAccountsDB.dbo.AccountsTabExplain')
  841. ->where('TabID', $tab_id)
  842. ->value('Explain');
  843. });
  844. return apiReturnSuc($explain);
  845. }
  846. // 每日绑定查询
  847. public function dailyBinding(Request $request)
  848. {
  849. $start_time = str_replace('T', ' ', $request->start_time) ?: date('Y-m-d 00:00:00');
  850. $end_time = str_replace('T', ' ', $request->end_time) ?: date('Y-m-d 23:59:59');
  851. $spreaderID = $request->SpreaderID ?: '';
  852. $GameID = $request->GameID ?: '';
  853. $date = $request->date ?: '';
  854. switch ($date) {
  855. case 1:
  856. $start_time = date('Y-m-d 00:00:00');
  857. break;
  858. case 2:
  859. $start_time = date('Y-m-d 00:00:00', strtotime('-1 day'));
  860. $end_time = date('Y-m-d 23:59:59', strtotime('-1 day'));
  861. break;
  862. case 3:
  863. //当前日期
  864. $sdefaultDate = date("Y-m-d 00:00:00");
  865. // 1表示每周星期一为开始日期 0表示每周日为开始日期
  866. $first = 1;
  867. //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
  868. $w = date('w', strtotime($sdefaultDate));
  869. $start_time = date('Y-m-d 00:00:00', strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) . ' days'));
  870. break;
  871. case 4:
  872. $start_time = date("Y-m-01 00:00:00");
  873. break;
  874. }
  875. $where = [];
  876. !empty($start_time) && $where[] = ['ai.RegisterDate', '>=', $start_time];
  877. !empty($end_time) && $where[] = ['ai.RegisterDate', '<=', $end_time];
  878. !empty($spreaderID) && $where[] = ['ai1.GameID', $spreaderID];
  879. !empty($GameID) && $where[] = ['ai.GameID', $GameID];
  880. $list = DB::connection('read')->table('QPAccountsDB.dbo.UserAgent as ua')
  881. ->join('QPAccountsDB.dbo.AccountsInfo as ai', 'ua.UserID', 'ai.UserID')
  882. ->join('QPAccountsDB.dbo.AccountsInfo as ai1', 'ua.Higher1ID', 'ai1.UserID')
  883. ->select('ai.GameID', 'ai.UserID', 'ai.RegisterDate', 'ai.LastLogonDate', 'ai1.GameID as SpreaderID', 'ai1.UserID as ai1UserID')
  884. ->where('Higher1ID', '>', 0)
  885. ->where($where)
  886. ->orderBy('ai.RegisterDate', 'desc')
  887. ->paginate(10);
  888. $start_time = Helper::timeChange($start_time);
  889. $end_time = Helper::timeChange($end_time);
  890. $dates = [1 => '今日', 2 => '昨日', 3 => '本周', 4 => '本月'];
  891. $data = compact('list', 'start_time', 'end_time', 'spreaderID', 'GameID', 'date', 'dates');
  892. return view('admin.user.daily_binding', $data);
  893. }
  894. public function moneyDeviation(Request $request)
  895. {
  896. $query = DB::table('QPRecordDB.dbo.RecordUserTotalStatistics as ru')
  897. ->leftJoin(
  898. 'QPAccountsDB.dbo.AccountsInfo as ai',
  899. 'ai.UserID',
  900. '=',
  901. 'ru.UserID'
  902. )
  903. ->lock('with(nolock)');
  904. if ($request->input('sort')) {
  905. $query->orderByRaw($request->input('sort'));
  906. }
  907. if ($request->input('GameID')) {
  908. $query->where('GameID', $request->input('GameID'));
  909. }
  910. if ($request->input('NickName')) {
  911. $query->where('NickName', $request->input('NickName'));
  912. }
  913. if ($request->input('Channel')) {
  914. $query->where('Channel', $request->input('Channel'));
  915. }
  916. if ($request->input('RegisterDateStart')) {
  917. $query->where('RegisterDate', '>=',
  918. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('RegisterDateStart')))
  919. ->format('Y-m-d H:i:00'));
  920. }
  921. if ($request->input('RegisterDateEnd')) {
  922. $query->where('RegisterDate', '<=',
  923. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('RegisterDateEnd')))
  924. ->format('Y-m-d H:i:59.999'));
  925. }
  926. if ($request->input('LastLogonDateStart')) {
  927. $query->where('LastLogonDate', '>=',
  928. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('LastLogonDateStart')))
  929. ->format('Y-m-d H:i:00'));
  930. }
  931. if ($request->input('LastLogonDateEnd')) {
  932. $query->where('LastLogonDate', '<=',
  933. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('LastLogonDateEnd')))
  934. ->format('Y-m-d H:i:59.999'));
  935. }
  936. $kinds = DB::table('QPPlatformDB.dbo.GameKindItem')
  937. ->pluck('KindName', 'KindID');
  938. if ($request->input('export')) {
  939. $data = [];
  940. $query->selectRaw("ai.*, Recharge-Withdraw/100 as deviation, Recharge,
  941. Withdraw/100 as Withdraw, Handsel, DrawBase")
  942. ->orderBy('ai.UserID')
  943. ->chunk(1000, function ($items) use (&$data) {
  944. $userIDs = $items->pluck('UserID');
  945. $res = AccountsInfo::query()->with('gameScoreInfo', 'accountPhoneRelation', 'gameScoreLocker')
  946. ->whereIn('UserID', $userIDs)
  947. ->get();
  948. $userInfos = [];
  949. foreach ($res as $k => $v) {
  950. $userInfos[$v->UserID] = $v;
  951. }
  952. $res1 = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')->whereIn('UserID', $userIDs)
  953. ->where('DateID', date('Ymd'))
  954. ->get();
  955. $statNew = [];
  956. foreach ($res1 as $k => $v) {
  957. $statNew[$v->UserID] = $v;
  958. }
  959. $insert = [];
  960. foreach ($items as $k => $v) {
  961. $insert['GameID'] = $userInfos[$v->UserID]->GameID;
  962. $insert['NickName'] = $userInfos[$v->UserID]->NickName;
  963. $insert['Channel'] = $userInfos[$v->UserID]->Channel;
  964. $insert['LastLogonDate'] = $userInfos[$v->UserID]->LastLogonDate;
  965. $insert['LastLogonDateCN'] =
  966. date('Y-m-d H:i:s', strtotime($userInfos[$v->UserID]->LastLogonDate . ' +11 hours'));
  967. $insert['PhoneNum'] = $userInfos[$v->UserID]->accountPhoneRelation->PhoneNum ?? '';
  968. $insert['Score'] = $userInfos[$v->UserID]->gameScoreInfo->Score ?? '';
  969. $insert['deviation'] = $v->deviation;
  970. $insert['Recharge'] = $v->Recharge . '/' . ($statNew[$v->UserID]->Recharge ?? 0);
  971. $insert['Withdraw'] = $v->Withdraw . '/' . ($statNew[$v->UserID]->Withdraw ?? 0)/100;
  972. $insert['Handsel'] = $v->Handsel . '/' . ($statNew[$v->UserID]->Handsel ?? 0);
  973. $insert['DrawBase'] = $v->DrawBase;
  974. $insert['IP'] = $userInfos[$v->UserID]->LastLogonIP;
  975. $insert['Online'] = $kinds[$userInfos[$v->UserID]->gameScoreLocker->KindID] ?? '离线';
  976. $insert['RegisterDate'] = $userInfos[$v->UserID]->RegisterDate;
  977. $insert['RegisterDateCN'] = date(
  978. 'Y-m-d H:i:s',
  979. strtotime($userInfos[$v->UserID]->RegisterDate . ' +11 hours')
  980. );
  981. $data[] = $insert;
  982. }
  983. });
  984. downloadExcel($data, [__('auto.会员ID'), __('auto.昵称'), __('auto.最后登录时间(当地)'), __('auto.最后登录时间(中国)'), __('auto.手机号'), __('auto.余额'),
  985. __('auto.茶叶减咖啡(累计)'), __('auto.今日/历史充值'), __('auto.今日/历史茶叶'), __('auto.今日/历史彩金'), __('auto.可茶叶金额'), __('auto.IP'),
  986. __('auto.在线状态'), __('auto.注册日期(当地)'), __('auto.注册日期(中国)'),
  987. ],__('auto.提充比查询').'.xls');
  988. }
  989. $page = $query->selectRaw("ai.*, Recharge-Withdraw/100 as deviation, Recharge,
  990. Withdraw/100 as Withdraw, Handsel, DrawBase")
  991. ->whereRaw('Recharge-Withdraw/100 < 0')
  992. ->paginate(10);
  993. $userIDs = array_column($page->items(), 'UserID');
  994. if ($userIDs) {
  995. $res = AccountsInfo::query()->with('gameScoreInfo', 'accountPhoneRelation', 'gameScoreLocker')
  996. ->whereIn('UserID', $userIDs)
  997. ->get();
  998. $userInfos = [];
  999. foreach ($res as $k => $v) {
  1000. $userInfos[$v->UserID] = $v;
  1001. }
  1002. $res1 = DB::table('QPRecordDB.dbo.RecordUserDataStatisticsNew')->whereIn('UserID', $userIDs)
  1003. ->where('DateID', date('Ymd'))
  1004. ->get();
  1005. $statNew = [];
  1006. foreach ($res1 as $k => $v) {
  1007. $statNew[$v->UserID] = $v;
  1008. }
  1009. foreach ($page as $k => $v) {
  1010. if(!(isset($userInfos[$v->UserID]) && @$userInfos[$v->UserID])){
  1011. continue;
  1012. }
  1013. $page[$k]->UserID = $v->UserID;
  1014. $page[$k]->GameID = $userInfos[$v->UserID]->GameID;
  1015. $page[$k]->NickName = $userInfos[$v->UserID]->NickName;
  1016. $page[$k]->LastLogonDate = $userInfos[$v->UserID]->LastLogonDate;
  1017. $page[$k]->LastLogonDateCN =
  1018. date('Y-m-d H:i:s', strtotime($userInfos[$v->UserID]->LastLogonDate . ' +11 hours'));
  1019. $page[$k]->PhoneNum = $userInfos[$v->UserID]->accountPhoneRelation->PhoneNum ?? '';
  1020. $page[$k]->Score = $userInfos[$v->UserID]->gameScoreInfo->Score ?? '';
  1021. $page[$k]->deviation = $v->deviation;
  1022. $page[$k]->Recharge = $v->Recharge;
  1023. $page[$k]->RechargeToday = $statNew[$v->UserID]->Recharge ?? 0;
  1024. $page[$k]->Withdraw = $v->Withdraw;
  1025. $page[$k]->WithdrawToday = ($statNew[$v->UserID]->Withdraw ?? 0)/100;
  1026. $page[$k]->Handsel = $v->Handsel;
  1027. $page[$k]->HandselToday = $statNew[$v->UserID]->Handsel ?? 0;
  1028. $page[$k]->DrawBase = $v->DrawBase;
  1029. $page[$k]->IP = $userInfos[$v->UserID]->LastLogonIP;
  1030. $page[$k]->Online = $kinds[$userInfos[$v->UserID]->gameScoreLocker->KindID] ?? '离线';
  1031. $page[$k]->RegisterDate = $userInfos[$v->UserID]->RegisterDate;
  1032. $page[$k]->RegisterDateCN = date(
  1033. 'Y-m-d H:i:s',
  1034. strtotime($userInfos[$v->UserID]->RegisterDate . ' +11 hours')
  1035. );
  1036. }
  1037. }
  1038. $channels = [0 => '全部'] + DB::connection('read')->table('QPPlatformDB.dbo.ChannelPackageName')
  1039. ->selectRaw('Channel')->groupBy('Channel')->pluck('Channel', 'Channel')
  1040. ->toArray();
  1041. $total = $query->count();
  1042. $recharge = $query->sum('Recharge');
  1043. $withdraw = $query->sum(DB::raw('Withdraw/100'));
  1044. return view('admin.user.money_deviation', [
  1045. 'list' => $page,
  1046. 'request' => $request,
  1047. 'channels' => $channels,
  1048. 'total' => $total,
  1049. 'money' => "$withdraw/$recharge",
  1050. ]);
  1051. }
  1052. }