UserController.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  43. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as aci WITH (NOLOCK)'), 'ai.SpreaderID', '=', 'aci.UserID')
  44. ->leftJoin(DB::raw('QPTreasureDB.dbo.GameScoreInfo as gi WITH (NOLOCK)'), 'ai.UserID', '=', 'gi.UserID')
  45. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountPhone as ap WITH (NOLOCK)'), 'ai.UserID', '=', 'ap.UserID')
  46. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as v WITH (NOLOCK)'), '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(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  77. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as aci WITH (NOLOCK)'), 'ai.SpreaderID', '=', 'aci.UserID')
  78. ->leftJoin(DB::raw('QPTreasureDB.dbo.GameScoreInfo as gi WITH (NOLOCK)'), 'ai.UserID', '=', 'gi.UserID')
  79. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountPhone as ap WITH (NOLOCK)'), 'ai.UserID', '=', 'ap.UserID')
  80. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as v WITH (NOLOCK)'), '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(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  123. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as aci WITH (NOLOCK)'), 'ai.SpreaderID', '=', 'aci.UserID')
  124. ->leftJoin(DB::raw('QPTreasureDB.dbo.GameScoreInfo as gi WITH (NOLOCK)'), 'ai.UserID', '=', 'gi.UserID')
  125. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as v WITH (NOLOCK)'), '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(DB::raw(TableName::QPRecordDB() . 'RecordUserGameCount WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  147. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as aci WITH (NOLOCK)'), 'ai.SpreaderID', '=', 'aci.UserID')
  148. ->leftJoin(DB::raw('QPTreasureDB.dbo.GameScoreInfo as gi WITH (NOLOCK)'), 'ai.UserID', '=', 'gi.UserID')
  149. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as v WITH (NOLOCK)'), '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(DB::raw(TableName::QPRecordDB() . 'RecordUserGameCount WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  174. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_VIPAccount as va WITH (NOLOCK)'), '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(DB::raw('[order] WITH (NOLOCK)'))
  271. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'), '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(DB::raw('QPTreasureDB.dbo.RecordDrawScore as rs WITH (NOLOCK)'))
  296. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'), 'rs.UserID', '=', 'ai.UserID')
  297. ->leftJoin(DB::raw('QPTreasureDB.dbo.RecordDrawInfo as ri WITH (NOLOCK)'), 'rs.DrawID', '=', 'ri.DrawID')
  298. ->leftJoin(DB::raw('QPPlatformDB.dbo.GameRoomInfo as gi WITH (NOLOCK)'), '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(DB::raw($table . ' as si WITH (NOLOCK)'))
  362. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'), 'si.UserID', '=', 'ai.UserID')
  363. ->leftJoin(DB::raw('QPPlatformDB.dbo.GameRoomInfo as ri WITH (NOLOCK)'), 'ri.ServerID', '=', 'si.ServerID')
  364. ->join(DB::raw('QPRecordDB.dbo.YN_RecordScoreConfig as sc WITH (NOLOCK)'), '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(DB::raw('QPRecordDB.dbo.YN_RecordRevenueInfo as si WITH (NOLOCK)'))
  412. ->leftJoin(DB::raw('QPRecordDB.dbo.YN_RecordScoreConfig as sc WITH (NOLOCK)'), '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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('agent WITH (NOLOCK)'))->Where('UserID', $user_id)->value('name');
  537. //推广总用户数
  538. $children_count = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  539. ->where($where)
  540. ->count();
  541. //活跃用户
  542. $live_users = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  543. ->where($where)
  544. ->where('LastLogonDate', '>=', date('Y-m-d', strtotime('-7 days')))
  545. ->count();
  546. //有效用户
  547. $eff_user = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  548. ->where($where)
  549. ->where('Experience', '>=', 6000)
  550. ->count();
  551. //流失用户
  552. $sleep_users = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  553. ->where($where)
  554. ->where('LastLogonDate', '<=', date('Y-m-d', strtotime('-7 days')))
  555. ->count();
  556. //已提收益
  557. $gold = DB::table(DB::raw('QPAccountsDB.dbo.YN_Withdrawal WITH (NOLOCK)'))
  558. ->selectRaw('sum(Gold) as gold')
  559. ->where('UserID', $user_id)
  560. ->value('gold');
  561. //计提收益
  562. $revenue = DB::table(DB::raw('QPAccountsDB.dbo.YN_Agent WITH (NOLOCK)'))
  563. ->where('UserID', $user_id)
  564. ->value('Revenue');
  565. //总收益
  566. $revenue_sum = DB::table(DB::raw('QPTreasureDB.dbo.YN_HistoryPerformance WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  612. ->select('NickName', 'GameID')
  613. ->where('UserID', $user_id)
  614. ->first();
  615. //每日新增
  616. $add_users_list = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPTreasureDB.dbo.YN_HistoryPerformance WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  701. ->select('NickName', 'GameID')
  702. ->where('UserID', $user_id)
  703. ->first();
  704. $add_users_list = DB::table(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'))
  705. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as ais WITH (NOLOCK)'), '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(DB::raw('QPAccountsDB.dbo.AccountsInfo WITH (NOLOCK)'))
  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(DB::raw('QPTreasureDB.dbo.YN_HistoryPerformance WITH (NOLOCK)'))
  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(DB::raw('QPAccountsDB.dbo.YN_UniqueCode as code WITH (NOLOCK)'))
  775. ->leftJoin(DB::raw('QPAccountsDB.dbo.YN_MatchProp as prop WITH (NOLOCK)'), 'code.PropID', '=', 'prop.PropID')
  776. ->leftJoin(DB::raw('QPAccountsDB.dbo.AccountsInfo as account WITH (NOLOCK)'), 'code.UserID', '=', 'account.UserID')
  777. ->leftJoin(DB::raw('agent.dbo.agent as agent WITH (NOLOCK)'), '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(DB::raw('QPAccountsDB.dbo.UserAgent as ua WITH (NOLOCK)'))
  881. ->join(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'), 'ua.UserID', 'ai.UserID')
  882. ->join(DB::raw('QPAccountsDB.dbo.AccountsInfo as ai1 WITH (NOLOCK)'), '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(DB::raw('QPRecordDB.dbo.RecordUserTotalStatistics as ru WITH (NOLOCK)'))
  897. ->leftJoin(
  898. DB::raw('QPAccountsDB.dbo.AccountsInfo as ai WITH (NOLOCK)'),
  899. 'ai.UserID',
  900. '=',
  901. 'ru.UserID'
  902. );
  903. if ($request->input('sort')) {
  904. $query->orderByRaw($request->input('sort'));
  905. }
  906. if ($request->input('GameID')) {
  907. $query->where('GameID', $request->input('GameID'));
  908. }
  909. if ($request->input('NickName')) {
  910. $query->where('NickName', $request->input('NickName'));
  911. }
  912. if ($request->input('Channel')) {
  913. $query->where('Channel', $request->input('Channel'));
  914. }
  915. if ($request->input('RegisterDateStart')) {
  916. $query->where('RegisterDate', '>=',
  917. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('RegisterDateStart')))
  918. ->format('Y-m-d H:i:00'));
  919. }
  920. if ($request->input('RegisterDateEnd')) {
  921. $query->where('RegisterDate', '<=',
  922. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('RegisterDateEnd')))
  923. ->format('Y-m-d H:i:59.999'));
  924. }
  925. if ($request->input('LastLogonDateStart')) {
  926. $query->where('LastLogonDate', '>=',
  927. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('LastLogonDateStart')))
  928. ->format('Y-m-d H:i:00'));
  929. }
  930. if ($request->input('LastLogonDateEnd')) {
  931. $query->where('LastLogonDate', '<=',
  932. \Carbon\Carbon::createFromTimestamp(strtotime($request->input('LastLogonDateEnd')))
  933. ->format('Y-m-d H:i:59.999'));
  934. }
  935. $kinds = DB::table('QPPlatformDB.dbo.GameKindItem')
  936. ->pluck('KindName', 'KindID');
  937. if ($request->input('export')) {
  938. $data = [];
  939. $query->selectRaw("ai.*, Recharge-Withdraw/100 as deviation, Recharge,
  940. Withdraw/100 as Withdraw, Handsel, DrawBase")
  941. ->orderBy('ai.UserID')
  942. ->chunk(1000, function ($items) use (&$data) {
  943. $userIDs = $items->pluck('UserID');
  944. $res = AccountsInfo::query()->with('gameScoreInfo', 'accountPhoneRelation', 'gameScoreLocker')
  945. ->whereIn('UserID', $userIDs)
  946. ->get();
  947. $userInfos = [];
  948. foreach ($res as $k => $v) {
  949. $userInfos[$v->UserID] = $v;
  950. }
  951. $res1 = DB::table(DB::raw('QPRecordDB.dbo.RecordUserDataStatisticsNew WITH (NOLOCK)'))->whereIn('UserID', $userIDs)
  952. ->where('DateID', date('Ymd'))
  953. ->get();
  954. $statNew = [];
  955. foreach ($res1 as $k => $v) {
  956. $statNew[$v->UserID] = $v;
  957. }
  958. $insert = [];
  959. foreach ($items as $k => $v) {
  960. $insert['GameID'] = $userInfos[$v->UserID]->GameID;
  961. $insert['NickName'] = $userInfos[$v->UserID]->NickName;
  962. $insert['Channel'] = $userInfos[$v->UserID]->Channel;
  963. $insert['LastLogonDate'] = $userInfos[$v->UserID]->LastLogonDate;
  964. $insert['LastLogonDateCN'] =
  965. date('Y-m-d H:i:s', strtotime($userInfos[$v->UserID]->LastLogonDate . ' +11 hours'));
  966. $insert['PhoneNum'] = $userInfos[$v->UserID]->accountPhoneRelation->PhoneNum ?? '';
  967. $insert['Score'] = $userInfos[$v->UserID]->gameScoreInfo->Score ?? '';
  968. $insert['deviation'] = $v->deviation;
  969. $insert['Recharge'] = $v->Recharge . '/' . ($statNew[$v->UserID]->Recharge ?? 0);
  970. $insert['Withdraw'] = $v->Withdraw . '/' . ($statNew[$v->UserID]->Withdraw ?? 0)/100;
  971. $insert['Handsel'] = $v->Handsel . '/' . ($statNew[$v->UserID]->Handsel ?? 0);
  972. $insert['DrawBase'] = $v->DrawBase;
  973. $insert['IP'] = $userInfos[$v->UserID]->LastLogonIP;
  974. $insert['Online'] = $kinds[$userInfos[$v->UserID]->gameScoreLocker->KindID] ?? '离线';
  975. $insert['RegisterDate'] = $userInfos[$v->UserID]->RegisterDate;
  976. $insert['RegisterDateCN'] = date(
  977. 'Y-m-d H:i:s',
  978. strtotime($userInfos[$v->UserID]->RegisterDate . ' +11 hours')
  979. );
  980. $data[] = $insert;
  981. }
  982. });
  983. downloadExcel($data, [__('auto.会员ID'), __('auto.昵称'), __('auto.最后登录时间(当地)'), __('auto.最后登录时间(中国)'), __('auto.手机号'), __('auto.余额'),
  984. __('auto.茶叶减咖啡(累计)'), __('auto.今日/历史充值'), __('auto.今日/历史茶叶'), __('auto.今日/历史彩金'), __('auto.可茶叶金额'), __('auto.IP'),
  985. __('auto.在线状态'), __('auto.注册日期(当地)'), __('auto.注册日期(中国)'),
  986. ],__('auto.提充比查询').'.xls');
  987. }
  988. $page = $query->selectRaw("ai.*, Recharge-Withdraw/100 as deviation, Recharge,
  989. Withdraw/100 as Withdraw, Handsel, DrawBase")
  990. ->whereRaw('Recharge-Withdraw/100 < 0')
  991. ->paginate(10);
  992. $userIDs = array_column($page->items(), 'UserID');
  993. if ($userIDs) {
  994. $res = AccountsInfo::query()->with('gameScoreInfo', 'accountPhoneRelation', 'gameScoreLocker')
  995. ->whereIn('UserID', $userIDs)
  996. ->get();
  997. $userInfos = [];
  998. foreach ($res as $k => $v) {
  999. $userInfos[$v->UserID] = $v;
  1000. }
  1001. $res1 = DB::table(DB::raw('QPRecordDB.dbo.RecordUserDataStatisticsNew WITH (NOLOCK)'))->whereIn('UserID', $userIDs)
  1002. ->where('DateID', date('Ymd'))
  1003. ->get();
  1004. $statNew = [];
  1005. foreach ($res1 as $k => $v) {
  1006. $statNew[$v->UserID] = $v;
  1007. }
  1008. foreach ($page as $k => $v) {
  1009. if(!(isset($userInfos[$v->UserID]) && @$userInfos[$v->UserID])){
  1010. continue;
  1011. }
  1012. $page[$k]->UserID = $v->UserID;
  1013. $page[$k]->GameID = $userInfos[$v->UserID]->GameID;
  1014. $page[$k]->NickName = $userInfos[$v->UserID]->NickName;
  1015. $page[$k]->LastLogonDate = $userInfos[$v->UserID]->LastLogonDate;
  1016. $page[$k]->LastLogonDateCN =
  1017. date('Y-m-d H:i:s', strtotime($userInfos[$v->UserID]->LastLogonDate . ' +11 hours'));
  1018. $page[$k]->PhoneNum = $userInfos[$v->UserID]->accountPhoneRelation->PhoneNum ?? '';
  1019. $page[$k]->Score = $userInfos[$v->UserID]->gameScoreInfo->Score ?? '';
  1020. $page[$k]->deviation = $v->deviation;
  1021. $page[$k]->Recharge = $v->Recharge;
  1022. $page[$k]->RechargeToday = $statNew[$v->UserID]->Recharge ?? 0;
  1023. $page[$k]->Withdraw = $v->Withdraw;
  1024. $page[$k]->WithdrawToday = ($statNew[$v->UserID]->Withdraw ?? 0)/100;
  1025. $page[$k]->Handsel = $v->Handsel;
  1026. $page[$k]->HandselToday = $statNew[$v->UserID]->Handsel ?? 0;
  1027. $page[$k]->DrawBase = $v->DrawBase;
  1028. $page[$k]->IP = $userInfos[$v->UserID]->LastLogonIP;
  1029. $page[$k]->Online = $kinds[$userInfos[$v->UserID]->gameScoreLocker->KindID] ?? '离线';
  1030. $page[$k]->RegisterDate = $userInfos[$v->UserID]->RegisterDate;
  1031. $page[$k]->RegisterDateCN = date(
  1032. 'Y-m-d H:i:s',
  1033. strtotime($userInfos[$v->UserID]->RegisterDate . ' +11 hours')
  1034. );
  1035. }
  1036. }
  1037. $channels = [0 => '全部'] + DB::connection('read')->table('QPPlatformDB.dbo.ChannelPackageName')
  1038. ->selectRaw('Channel')->groupBy('Channel')->pluck('Channel', 'Channel')
  1039. ->toArray();
  1040. $total = $query->count();
  1041. $recharge = $query->sum('Recharge');
  1042. $withdraw = $query->sum(DB::raw('Withdraw/100'));
  1043. return view('admin.user.money_deviation', [
  1044. 'list' => $page,
  1045. 'request' => $request,
  1046. 'channels' => $channels,
  1047. 'total' => $total,
  1048. 'money' => "$withdraw/$recharge",
  1049. ]);
  1050. }
  1051. }