IndexController.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Support\Facades\App;
  5. use Illuminate\Support\Facades\DB;
  6. /**
  7. *
  8. */
  9. class IndexController extends Controller
  10. {
  11. function welcome()
  12. {
  13. $total = array(
  14. 'total_user' => $this->countTodayUser(),
  15. 'total_bet' => $this->countBet(),
  16. 'today_take' => $this->countTodayTake(),
  17. 'today_recharge' => $this->countTodayRecharge(),
  18. 'today_return' => $this->countTodayReturn(),
  19. 'today_rimit' => $this->countTodayRimt(),
  20. );
  21. if (\App\Models\Role::hasRoot('/enable/show/get_money_count') < 0) {
  22. $get_money_count = "*****";
  23. } else {
  24. $get_money_count = $total['today_recharge']['count'];
  25. }
  26. $notice = $this->getNotice();
  27. $message = $this->Message();
  28. return view('admin/welcome', ['total' => $total, 'notice' => $notice, 'message' => $message, 'get_money_count' => $get_money_count]);
  29. }
  30. //返回用户数量
  31. function countUser()
  32. {
  33. return \App\Models\Account_detailed::count();
  34. }
  35. //今日注册用户数量
  36. function countTodayUser()
  37. {
  38. $time1 = date('Y-m-d 00:00:00'); //今日0时
  39. $time2 = date('Y-m-d 23:59:59'); //
  40. $timearea = [$time1, $time2];
  41. if (\App\Models\Role::hasRoot('/enable/show/today_user') < 0) {
  42. $user_data['today_user'] = "*****";
  43. } else {
  44. $user_data['today_user'] = \App\Models\Account_detailed::whereBetween('register_time', $timearea)->join('account', 'account_detailed.account_identity', '=', 'account.identity')->where('status', '1')->count();
  45. }
  46. if (\App\Models\Role::hasRoot('/enable/show/last_online') < 0) {
  47. $user_data['last_online'] = "*****";
  48. } else {
  49. $user_data['last_online'] = \App\Models\Account_Token::whereBetween('last_time', $timearea)->count();
  50. }
  51. if (\App\Models\Role::hasRoot('/enable/show/user_count') < 0) {
  52. $user_data['user_count'] = "*****";
  53. } else {
  54. $user_data['user_count'] = \App\Models\Account_detailed::count();
  55. }
  56. return $user_data;
  57. }
  58. //注单总数量
  59. function countBet()
  60. {
  61. $time1 = date('Y-m-d 00:00:00'); //今日0时
  62. $time2 = date('Y-m-d 23:59:59'); //
  63. $timearea = [$time1, $time2];
  64. if (\App\Models\Role::hasRoot('/enable/show/bet_count') < 0) {
  65. $bet_count['count'] = "*****";
  66. } else {
  67. $bet_count['count'] = \App\Models\MoneyBuy::where('money_buy.status', '<>', 4)->join('account', 'money_buy.account_identity', '=', 'account.identity')->where('account.status', '<>', '4')->where('account.user_type', '1')->whereBetween('money_time', $timearea)->count();
  68. }
  69. if (\App\Models\Role::hasRoot('/enable/show/bet_money') < 0) {
  70. $bet_money = \App\Models\MoneyBuy::where('money_buy.status', '<>', 4)->join('account', 'money_buy.account_identity', '=', 'account.identity')->where('account.status', '<>', '4')->where('account.user_type', '1')->whereBetween('money_time', $timearea)->sum('money');
  71. $bet_count['money_count'] = "*****";
  72. } else {
  73. $bet_money = \App\Models\MoneyBuy::where('money_buy.status', '<>', 4)->join('account', 'money_buy.account_identity', '=', 'account.identity')->where('account.status', '<>', '4')->where('account.user_type', '1')->whereBetween('money_time', $timearea)->sum('money');
  74. $bet_count['money_count'] = round($bet_money, 2);
  75. }
  76. // DB::connection()->enableQueryLog();
  77. if (\App\Models\Role::hasRoot('/enable/show/countBet') < 0) {
  78. $db = new \App\Models\MoneyBuy;
  79. $bet_count['user_count'] = "*****";
  80. } else {
  81. $db = new \App\Models\MoneyBuy;
  82. $bet_count['user_count'] = $db->countUser($timearea);
  83. }
  84. // $queries = DB::getQueryLog();
  85. // print_r($queries);
  86. return $bet_count;
  87. }
  88. //今日提现
  89. function countTodayTake()
  90. {
  91. $time1 = date('Y-m-d 00:00:00'); //今日0时
  92. $time2 = date('Y-m-d 23:59:59'); //
  93. $timearea = [$time1, $time2];
  94. if (\App\Models\Role::hasRoot('/enable/show/count') < 0) {
  95. $take_count['count'] = "*****";
  96. } else {
  97. $take_count['count'] = \App\Models\Money_take::whereBetween('apply_time', $timearea)->where('status', 1)->count();
  98. }
  99. if (\App\Models\Role::hasRoot('/enable/show/money_count') < 0) {
  100. $take_count['money_count'] = "*****";
  101. } else {
  102. $take_count['money_count'] = \App\Models\Money_take::whereBetween('apply_time', $timearea)->where('status', 1)->sum('money');
  103. }
  104. // DB::connection()->enableQueryLog();
  105. if (\App\Models\Role::hasRoot('/enable/show/user_count') < 0) {
  106. $db = new \App\Models\Money_take;
  107. $take_count['user_count'] = "*****";
  108. } else {
  109. $db = new \App\Models\Money_take;
  110. $take_count['user_count'] = $db->countUser($timearea);
  111. }
  112. // $queries = DB::getQueryLog();
  113. // dump($queries);
  114. // dump($take_count);
  115. return $take_count;
  116. }
  117. //今日充值笔数
  118. function countTodayRecharge()
  119. {
  120. $time1 = date('Y-m-d 00:00:00'); //今日0时
  121. $time2 = date('Y-m-d 23:59:59'); //
  122. $timearea = [$time1, $time2];
  123. // DB::connection()->enableQueryLog();
  124. if (\App\Models\Role::hasRoot('/enable/show/countTodayRecharge') < 0) {
  125. $rech_data['count'] = "*****";
  126. } else {
  127. $rech_data['count'] = \App\Models\Money_details::whereBetween('money_time', $timearea)->whereIn('trade_type', array(6, 11))->where('status', 1)->count();
  128. }
  129. // $queries = DB::getQueryLog();
  130. // print_r($queries);
  131. if (\App\Models\Role::hasRoot('/enable/show/countTodayRecharge_money') < 0) {
  132. $money_count = \App\Models\Money_details::whereBetween('money_time', $timearea)->whereIn('trade_type', array(6, 11))->where('status', 1)->sum('money');
  133. $rech_data['money_count'] = "*****";
  134. } else {
  135. $money_count = \App\Models\Money_details::whereBetween('money_time', $timearea)->whereIn('trade_type', array(6, 11))->where('status', 1)->sum('money');
  136. $rech_data['money_count'] = round($money_count, 2);
  137. }
  138. // DB::connection()->enableQueryLog();
  139. if (\App\Models\Role::hasRoot('/enable/show/countTodayRecharge_user') < 0) {
  140. $db = new \App\Models\Money_details;
  141. $count = $db->countUser($timearea, array(6, 11));
  142. $rech_data['user_count'] = "*****";
  143. } else {
  144. $db = new \App\Models\Money_details;
  145. $count = $db->countUser($timearea, array(6, 11));
  146. $rech_data['user_count'] = $count;
  147. }
  148. // $queries = DB::getQueryLog();
  149. // dump($queries);
  150. return $rech_data;
  151. }
  152. // 今日回水笔数
  153. function countTodayReturn()
  154. {
  155. $time1 = date('Y-m-d 00:00:00'); //今日0时
  156. $time2 = date('Y-m-d 23:59:59'); //
  157. $timearea = [$time1, $time2];
  158. if (\App\Models\Role::hasRoot('/enable/show/countTodayReturn') < 0) {
  159. $return['count'] = "*****";
  160. } else {
  161. $return['count'] = \App\Models\Money_return::whereBetween('processing_time', $timearea)->count();
  162. }
  163. if (\App\Models\Role::hasRoot('/enable/show/countTodayReturn_money') < 0) {
  164. $return['money_count'] = "*****";
  165. } else {
  166. $return['money_count'] = \App\Models\Money_return::whereBetween('processing_time', $timearea)->sum('money');
  167. }
  168. // $return['user_count'] = \App\Model\Money_return::whereBetween('processing_time', $timearea)->groupBy('account_identity')->count();
  169. if (\App\Models\Role::hasRoot('/enable/show/countTodayReturn_user') < 0) {
  170. $db = new \App\Models\Money_return;
  171. $return['user_count'] = "*****";
  172. } else {
  173. $db = new \App\Models\Money_return;
  174. $return['user_count'] = $db->countUser($timearea);
  175. }
  176. return $return;
  177. }
  178. // 今日反水笔数
  179. function countTodayBack()
  180. {
  181. $time1 = date('Y-m-d 00:00:00'); //今日0时
  182. $time2 = date('Y-m-d 23:59:59'); //
  183. $timearea = [$time1, $time2];
  184. if (\App\Models\Role::hasRoot('/enable/show/countTodayBack') < 0) {
  185. $return['count'] = "*****";
  186. } else {
  187. $return['count'] = \App\Models\Money_back::whereBetween('processing_time', $timearea)->count();
  188. }
  189. if (\App\Models\Role::hasRoot('/enable/show/countTodayBack_money') < 0) {
  190. $return['money_count'] = "*****";
  191. } else {
  192. $return['money_count'] = \App\Models\Money_back::whereBetween('processing_time', $timearea)->sum('money');
  193. }
  194. if (\App\Models\Role::hasRoot('/enable/show/countTodayBack_user') < 0) {
  195. $return['user_count'] = "*****";
  196. } else {
  197. $return['user_count'] = \App\Models\Money_back::whereBetween('processing_time', $timearea)->groupBy('account_identity')->count();
  198. }
  199. return $return;
  200. }
  201. //今日汇款
  202. function countTodayRimt()
  203. {
  204. $time1 = date('Y-m-d 00:00:00'); //今日0时
  205. $time2 = date('Y-m-d 23:59:59'); //
  206. $timearea = [$time1, $time2];
  207. if (\App\Models\Role::hasRoot('/enable/show/countTodayRimt') < 0) {
  208. $rimit['count'] = "*****";
  209. } else {
  210. $rimit['count'] = \App\Models\Money_recharge::whereBetween('apply_time', $timearea)->where('recharge_type', '汇款')->where('status', 1)->count();
  211. }
  212. if (\App\Models\Role::hasRoot('/enable/show/countTodayRimt_money') < 0) {
  213. $rimit['money_count'] = "*****";
  214. } else {
  215. $rimit['money_count'] = \App\Models\Money_recharge::whereBetween('apply_time', $timearea)->where('recharge_type', '汇款')->where('status', 1)->sum('money');
  216. }
  217. if (\App\Models\Role::hasRoot('/enable/show/countTodayRimt_user') < 0) {
  218. $db = new \App\Models\Money_recharge;
  219. $rimit['user_count'] = "*****";
  220. } else {
  221. $db = new \App\Models\Money_recharge;
  222. $rimit['user_count'] = $db->countRimitUser($timearea);
  223. }
  224. return $rimit;
  225. }
  226. //公告信息
  227. function getNotice()
  228. {
  229. $db = new \App\Models\Article();
  230. $data = $db->getMsg(2, 2);
  231. return $data;
  232. }
  233. //当前在线用户饼状图
  234. function onlineUser()
  235. {
  236. // $db = new \App\Model\Logfile;
  237. // $db=new \App\Model\Account_Token;
  238. $db = new \App\Models\Account_detailed;
  239. $data_log = $db->getOnlineUser();
  240. // $data_log = $db->getUser();
  241. $array['data'] = $data_log;
  242. if (empty($data_log)) {
  243. $array['data'][0]['name'] = '没有';
  244. $array['data'][0]['value'] = 0;
  245. }
  246. //组装标
  247. $count = 0;
  248. foreach ($array['data'] as $k => $v) {
  249. $array['title'][$k] = trim($v['name']);
  250. $array['data'][$k]['name'] = trim($v['name']);
  251. $count += $v['value'];
  252. }
  253. //总在线数量、
  254. $array['text'] = date('Y-m-d') . trans('common.today_user_num') . $count;
  255. return responseToJson($array);
  256. // dump($array);
  257. }
  258. //今日投注统计饼状图
  259. function getBetUrl()
  260. {
  261. $db = new \App\Models\OrderUrl;
  262. $data = $db->getUrlBet();
  263. $array['data'] = $data;
  264. if (empty($data)) {
  265. $array['data'][0]['name'] = '没有';
  266. $array['data'][0]['value'] = 0;
  267. }
  268. //组装标
  269. foreach ($array['data'] as $k => $v) {
  270. $array['title'][$k] = $v['name'];
  271. }
  272. //添加标题
  273. //总投注数量
  274. $count = $db->gettotal();
  275. $array['text'] = date('Y-m-d') . trans('common.today_bet_num') . $count;
  276. // dump($array);
  277. return responseToJson($array);
  278. }
  279. //时间区
  280. function getTime()
  281. {
  282. $time = array(
  283. 'addrss' => date_default_timezone_get(),
  284. 'time' => date("Y-m-d H:i:s", time() + 3600 * 8),
  285. );
  286. // print_r($time['time']);die;
  287. return responseToJson($time);
  288. }
  289. //最近7天会员注册情况
  290. function regUser()
  291. {
  292. /*
  293. $time2 = date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 30);
  294. $time1 = date('Y-m-d H:i:s', time());
  295. $timearea = [$time2, $time1];
  296. $rech_data['money_with'] = DB::table('account_detailed')->join('account', 'account.identity', '=', 'money_details.account_identity')->select(DB::Raw('sum(money) as with'))->whereBetween('money_time', $timearea)->groupBy('account')->where('trade_type', 5)->get();
  297. $rimit = \App\Models\Account_list::where('account_status', 1)
  298. ->select(DB::Raw('date(register_time) as name, count(identity) as value'))
  299. ->whereBetween('register_time', $timearea)->orderBy(DB::Raw('date(register_time)'))->groupBy(DB::Raw('date(register_time)'))->get();
  300. $data = $rimit->toArray();
  301. */
  302. //统计七天内注册用户数量按天进行分组
  303. $start_time = date('Y-m-d', strtotime('-7 days'));
  304. $end_time = date('Y-m-d', time());
  305. $user = DB::select('select rtime as name ,count(rtime) as value from (SELECT to_char( "register_time",\'YYYY-MM-DD\') as rtime FROM "account_detailed" where "register_time">=CURRENT_DATE-7) as tmp group by rtime order by name asc');
  306. if (!empty($user)) {
  307. $userData = [];
  308. foreach ($user as $k => $v) {
  309. $userData[$k]['name'] = $v->name;
  310. $userData[$k]['value'] = $v->value;
  311. }
  312. }
  313. //计算日期内天数
  314. $stimestamp = strtotime($start_time);
  315. $etimestamp = strtotime($end_time);
  316. //计算日期段内有多少天
  317. $days = ($etimestamp - $stimestamp) / 86400;
  318. //保存每天日期
  319. $date = array();
  320. for ($i = 0; $i < $days; $i++) {
  321. $date[] = date('Y-m-d', $stimestamp + (86400 * $i));
  322. }
  323. //循环补全日期
  324. foreach ($date as $key => $val) {
  325. $data[$key] = [
  326. 'name' => $val,
  327. 'value' => 0
  328. ];
  329. foreach ($userData as $item => $value) {
  330. if ($val == $value['name']) {
  331. $data[$key] = $value;
  332. }
  333. }
  334. }
  335. foreach ($data as $k => $v) {
  336. $array['title'][$k] = $v['name'];
  337. $array['data']['num'][$k] = $v['value'];
  338. }
  339. $array['legend'][] = '最近7天注册用户记录';
  340. return responseToJson($array);
  341. }
  342. //最近7天财务情况
  343. function money()
  344. {
  345. $res_array = array();
  346. for ($i = 6; $i >= 0; $i--) {
  347. $secondes = $i * 24 * 60 * 60;
  348. $res_array['title'][] = date('Y-m-d', (time() - $secondes));
  349. $res_array['data']['money_with'][] = 0;
  350. $res_array['data']['money_recharge'][] = 0;
  351. $res_array['data']['money_remittance'][] = 0;
  352. $res_array['data']['money_trans'][] = 0;
  353. $res_array['data']['profit'][] = 0;
  354. }
  355. $res_array['legend']['money_with'] = trans('user.money_with');
  356. $res_array['legend']['money_recharge'] = trans('user.money_recharge');
  357. $res_array['legend']['money_remittance'] = trans('user.money_remittance');
  358. $res_array['legend']['money_trans'] = trans('user.money_trans');
  359. $res_array['legend']['profit'] = '盈利';
  360. $db = new \App\Models\Money_details;
  361. $data = $db->getBet();
  362. if ($data < 0) {
  363. return responseToJson($res_array);
  364. }
  365. $trade_type = $this->getTradetype();
  366. foreach ($data as $k => $v) {
  367. foreach ($res_array['title'] as $tk => $tv) {
  368. if ($v['date'] == $tv) {
  369. $res_array['data'][$trade_type[$v['trade_type']]][$tk] += $v['value'];
  370. $res_array['data'][$trade_type[1]][$tk] += ($v['trade_type'] == 5) ? -$v['value'] : +$v['value'];
  371. break;
  372. }
  373. }
  374. }
  375. return responseToJson($res_array);
  376. /*print_r($data);exit;
  377. $i = 0;
  378. $array['title']=array();
  379. foreach ($data as $k => $v) {
  380. if (is_array($v) && count($v) > 0) {
  381. foreach ($v as $ka => $va) {
  382. $array['title'][$i] = $va['date'];
  383. $temp[$k][$va['date']] = $va['value'];
  384. $i++;
  385. }
  386. } else {
  387. $temp[$k] = array();
  388. }
  389. $array['legend'][$k] = trans('user.' . $k);
  390. }
  391. $array['title']=array_unique($array['title']);
  392. asort($array['title']);
  393. $tem=array();
  394. foreach($array['title'] as $v){
  395. $tem[]=$v;
  396. }
  397. $array['title']=$tem;
  398. $te = array();
  399. foreach ($array['title'] as $k => $v) {
  400. if (array_key_exists($v, $temp['money_with'])) {
  401. $te['money_with'][] = $temp['money_with'][$v];
  402. $money_with=$temp['money_with'][$v];
  403. } else {
  404. $te['money_with'][] = 0;
  405. $money_with=0;
  406. }
  407. if (array_key_exists($v, $temp['money_recharge'])) {
  408. $te['money_recharge'][] = $temp['money_recharge'][$v];
  409. $money_recharge=$temp['money_recharge'][$v];
  410. } else {
  411. $te['money_recharge'][] = 0;
  412. $money_recharge=0;
  413. }
  414. if (array_key_exists($v, $temp['money_remittance'])) {
  415. $te['money_remittance'][] = $temp['money_remittance'][$v];
  416. $money_remittance=$temp['money_remittance'][$v];
  417. } else {
  418. $te['money_remittance'][] = 0;
  419. $money_remittance=0;
  420. }
  421. if (array_key_exists($v, $temp['money_trans'])) {
  422. $te['money_trans'][] = $temp['money_trans'][$v];
  423. $money_trans=$temp['money_trans'][$v];
  424. } else {
  425. $te['money_trans'][] = 0;
  426. $money_trans=0;
  427. }
  428. $te['profit'][]=$money_trans+$money_remittance+$money_recharge-$money_with;
  429. }
  430. $array['legend']['profit']='盈利';
  431. $array['data'] = $te;
  432. return responseToJson($array);*/
  433. }
  434. private function getTradetype()
  435. {
  436. $tradetype = array(
  437. '5' => 'money_with',
  438. '6' => 'money_recharge',
  439. '11' => 'money_trans',
  440. '14' => 'money_remittance',
  441. '1' => 'profit',
  442. );
  443. return $tradetype;
  444. }
  445. //每天每个游戏注单数
  446. function TodayGameNote()
  447. {
  448. $time1 = date('Y-m-d 00:00:00');//今日零时
  449. $time2 = date('Y-m-d 23:59:59');//今日末时
  450. // $time1='2017-09-14 00:00:00';
  451. // $time2='2017-09-14 23:59:59';
  452. $timearea = [$time1, $time2];
  453. $data = \App\Models\MoneyBuy::select('game_name as name', DB::Raw('count(id) as value'))->whereBetween('money_time', $timearea)->groupBy('game_name')->get();
  454. $data = $data->toArray();
  455. if (count($data) == 0) {
  456. $data = array(array('name' => 'no_bet', 'value' => 0));
  457. }
  458. $array = array();
  459. foreach ($data as $k => $v) {
  460. $data[$k]['name'] = trans('common.' . $v['name']);
  461. $array['title'][$k] = trans('common.' . $v['name']);
  462. }
  463. $array['data'] = $data;
  464. $array['text'] = '今日游戏注单数量:' . date('Y-m-d');
  465. return responseToJson($array);
  466. }
  467. //拉时间
  468. function pullTime()
  469. {
  470. //获取前台域名
  471. $setInfo = new \App\Models\Setinfo();
  472. $info = $setInfo->getInfo(18);
  473. if ($info < 0) {
  474. return responseToJson($info);
  475. }
  476. //$a=file_get_contents($info['infocontent'].'api-common/getTime');
  477. $url = $info['infocontent'] . 'api-common/getTime';
  478. $timeout = 30;
  479. $ch = curl_init();
  480. curl_setopt($ch, CURLOPT_URL, $url);
  481. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  482. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 2);
  483. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  484. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  485. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); //避免data数据过长问题
  486. curl_setopt($ch, CURLOPT_POST, true);
  487. curl_setopt($ch, CURLOPT_POSTFIELDS, array());
  488. $a = curl_exec($ch);
  489. curl_close($ch);
  490. echo $a;
  491. }
  492. //通知消息
  493. function Message()
  494. {
  495. $admin_id = session('adminInfo.admin_id');
  496. $db = new \App\Models\MessageRead;
  497. $dbs = new \App\Models\Manager;
  498. $where = [
  499. 'type',
  500. '4'
  501. ];
  502. $datas = $dbs->getlistd($where);
  503. $data = $db->getlist($admin_id);
  504. if (!empty($data)) {
  505. foreach ($datas as $k => $v) {
  506. foreach ($data as $val) {
  507. if ($v['id'] == $val['message_id']) {
  508. $datas[$k]['status'] = '1';
  509. }
  510. }
  511. }
  512. }
  513. return $datas;
  514. }
  515. //刷新缓存
  516. public function refresh()
  517. {
  518. return view('admin.refresh');
  519. }
  520. }