IndexController.php 21 KB

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