SixMoneyBuy.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class SixMoneyBuy extends BaseModel {
  5. protected $table = "sixmoney_buy";
  6. public $timestamps = false;
  7. protected function getType() {
  8. return array(
  9. 'all' => trans('user_buy.all'), 'unclear' => trans('user_buy.unclear'), 'cleared' => trans('user_buy.cleared'),
  10. // 'rubish' => trans('user_buy.rubish'),
  11. );
  12. }
  13. function getAllBetAccount($where) {
  14. $model = $this->select('account_name');
  15. if (isset($where['in'])) {
  16. $model->whereIn('status', $where['in']);
  17. unset($where['in']);
  18. }
  19. if (!empty($where)) {
  20. $model->where($where);
  21. }
  22. $data = $model->groupBy('account_name')->get();
  23. if (!$data) {
  24. return -7010100202;
  25. }
  26. return $data->toArray();
  27. }
  28. function getTakelist($list = 20) {
  29. $data = $this->select('account_name', 'order_id', 'game_name', 'game_no', 'prize_note', 'money', 'prize_money', 'status', 'codes', 'water_status', 'money_time', 'get_money', 'prize', 'game_status')->orderBy('money_time', 'desc')->groupBy('account_name')->paginate($list);
  30. if (!$data) {
  31. return -7010100102; //没有列表数据
  32. }
  33. return $data->toArray();
  34. }
  35. //获取注单信息
  36. function getBuyInfo($game, $list = 20, $fild = 'money_time', $order = 'desc', $where = '',$page=1) {
  37. $frist=($page-1)*$list;
  38. // DB::connection()->enableQueryLog();
  39. if (!empty($where)&&count($where)>0) {
  40. $model = $this->select($this->table . '.id',$this->table . '.info_identity', 'account_name', 'order_id', 'game_name', 'game_no', 'money_time', 'money', 'get_money', $this->table . '.codes', $this->table . '.status', 'game_status', 'extra', 'prizes', 'game_' . $game . '.codes as prizes_code', 'game_' . $game . '.status as code_status','prize')
  41. ->join('game_' . $game, DB::raw("cast(info_no as VARCHAR)"), 'game_no')
  42. ->where($where)
  43. ->orderBy('money_time', $order)
  44. ->orderBy('game_no', $order);
  45. }else{
  46. $model = $this->select($this->table . '.id', 'account_name', 'order_id', 'game_name', 'game_no', 'money_time', 'money', 'get_money', $this->table . '.codes', $this->table . '.status', 'game_status', 'extra', 'prizes', 'game_' . $game . '.codes as prizes_code', 'game_' . $game . '.status as code_status')
  47. ->join('game_' . $game, DB::raw("cast(info_no as VARCHAR)"), 'game_no')
  48. ->where('game_name', $game)
  49. ->orderBy('money_time', $order)
  50. ->orderBy('game_no', $order);
  51. }
  52. if(!empty($list)){
  53. $model=$model->paginate($list);
  54. }else{
  55. $model=$model->get();
  56. }
  57. if (!$model) {
  58. return -5030000122; //没有数据
  59. }
  60. return $model->toArray();
  61. }
  62. //获取异常注意信息
  63. function getBtrecordBuyInfo($game, $list = 20, $fild = 'money_time', $order = 'desc', $where = '',$page=1) {
  64. $frist=($page-1)*$list;
  65. // DB::connection()->enableQueryLog();
  66. if (!empty($where)&&count($where)>0) {
  67. $model = $this->select($this->table . '.id', 'account_name', 'order_id', 'game_name', 'game_no', 'money_time', 'money', 'get_money', $this->table . '.codes', $this->table . '.status', 'game_status', 'extra', 'prizes', 'game_' . $game . '.codes as prizes_code','prize','type')
  68. ->join('game_' . $game, 'info_no', 'game_no')
  69. ->join('btrecord', 'btrecord.identity', 'sixmoney_buy.info_identity')
  70. ->where($where)
  71. ->orderBy('money_time', $order);
  72. }else{
  73. $model = $this->select($this->table . '.id', 'account_name', 'order_id', 'game_name', 'game_no', 'money_time', 'money', 'get_money', $this->table . '.codes', $this->table . '.status', 'game_status', 'extra', 'prizes', 'game_' . $game . '.codes as prizes_code','type')
  74. ->join('game_' . $game, 'info_no', 'game_no')
  75. ->join('btrecord', 'btrecord.identity', 'sixmoney_buy.info_identity')
  76. ->where('game_name', $game)
  77. ->orderBy('money_time', $order);
  78. }
  79. if(!empty($list)){
  80. $model=$model->paginate($list);
  81. }else{
  82. $model=$model->get();
  83. }
  84. if (!$model) {
  85. return -5030000122; //没有数据
  86. }
  87. return $model->toArray();
  88. }
  89. //根据订单号获取订单信息
  90. function getInfoByOrderID($order_id) {
  91. $data = $this->where('order_id', $order_id)->first();
  92. if (!$data) {
  93. return -5030001022; //没有订单数据
  94. }
  95. return $data->toArray();
  96. }
  97. //获取注单信息
  98. function getBetInfo($where) {
  99. $data = $this->select('codes')->where($where)->get();
  100. if (!$data) {
  101. return -503000102; //没有订单数据
  102. }
  103. return $data->toArray();
  104. }
  105. //根据id获取订单信息
  106. function getInfoByID($id) {
  107. $data = $this->where('id', $id)->first();
  108. if (!$data) {
  109. return -5030001022; //没有订单数据
  110. }
  111. return $data->toArray();
  112. }
  113. //根据info_identity获取订单信息
  114. function getInfoByIdentity($id) {
  115. $data = $this->where('info_identity', $id)->first();
  116. if (!$data) {
  117. return -5030001022; //没有订单数据
  118. }
  119. return $data->toArray();
  120. }
  121. function getTotal($list = 10, $page, $where = '', $having = '') {
  122. // DB::connection()->enableQueryLog();
  123. if (!empty($where) && is_array($where) && !empty($having) && is_array($having)) {
  124. $data = $this->where($where)->select(DB::raw('sum("get_money") as winmoney,sum("prize_money") as prizemoney,sum("money") as betmoney,game_name,count("order_id") as munBet,max("money_time") as end_time,min("money_time") as star_time,game_status'))
  125. ->join('account','sixmoney_buy.account_identity', '=', 'account.identity')
  126. ->where('account.status','<>','4')
  127. ->where('account.user_type','1')
  128. ->groupBy('game_name')
  129. ->groupBy('game_status');
  130. foreach ($having as $v) {
  131. $data = $data->havingRaw($v);
  132. }
  133. $data = $data->orderby('star_time','desc')->paginate($list);
  134. } elseif (!empty($having) && is_array($having)) {
  135. $data = $this->select(DB::raw('sum("get_money") as winmoney,sum("prize_money") as prizemoney,sum("money") as betmoney,game_name,count("order_id") as munbet,max("money_time") as end_time,min("money_time") as star_time,game_status'))
  136. ->join('account','sixmoney_buy.account_identity', '=', 'account.identity')
  137. ->where('account.status','<>','4')
  138. ->where('account.user_type','1')
  139. ->groupBy('game_name')
  140. ->groupBy('game_status');
  141. foreach ($having as $v) {
  142. $data = $data->havingRaw($v);
  143. }
  144. $data = $data->orderby('star_time','desc')->paginate($list);
  145. } elseif (!empty($where) && is_array($where)) {
  146. $data = $this->where($where)->select(DB::raw('sum("get_money") as winmoney,sum("prize_money") as prizemoney,sum("money") as betmoney,game_name,count("order_id") as munBet,max("money_time") as end_time,min("money_time") as star_time,game_status'))
  147. ->join('account','sixmoney_buy.account_identity', '=', 'account.identity')
  148. ->where('account.status','<>','4')
  149. ->where('account.user_type','1')
  150. ->groupBy('game_name')
  151. ->groupBy('game_status')->orderby('star_time','desc')->paginate($list);
  152. }
  153. if (!isset($data) || !$data) {
  154. } else {
  155. $data = $data->toArray();
  156. $gamename = trans('report');
  157. foreach ($data['data'] as $k => $v) {
  158. $data['data'][$k]['name'] = $gamename[$v['game_name']];
  159. $data['data'][$k]['munBet'] = $v['munbet'];
  160. }
  161. return $data['data'];
  162. }
  163. $fs = ($page - 1) * $list;
  164. $array = array();
  165. $data = DB::select('select sum("get_money") as "winmoney",sum("money") as "betmoney","game_name",count("order_id") as "munBet",max("money_time") as end_time,min("money_time") as star_time from sixmoney_buy inner join account on account.identity=account_identity where sixmoney_buy.status != 4 and account.user_type=1 group by game_name ');
  166. foreach ($data as $k => $v) {
  167. $array[$k]['winmoney'] = $v->winmoney;
  168. $array[$k]['betmoney'] = $v->betmoney;
  169. $array[$k]['game_name'] = $v->game_name;
  170. $array[$k]['munBet'] = $v->munBet;
  171. $array[$k]['star_time'] = $v->star_time;
  172. $array[$k]['end_time'] = $v->end_time;
  173. $array[$k]['prizemoney'] = $v->winmoney + $v->betmoney;
  174. $array[$k]['name'] = trans('report.' . $v->game_name);
  175. }
  176. // $count = DB::select('select sum("get_money") as "winmoney",sum("money") as "betmoney","game_name",count("order_id") as "munBet" from money_buy where status != 4 group by game_name');
  177. // $array['total']=count($count);
  178. return $array;
  179. }
  180. //有效金额统计
  181. function getEffective($where = '',$subwhere='',$game='sixlottery') {
  182. // DB::connection()->enableQueryLog();
  183. $sql = 'select sum("money") as betmoney,max("money_time") as end_time,min("money_time") as star_time from sixmoney_buy inner join account on account.identity=account_identity where sixmoney_buy.status != 4 and game_status <> 0 and account.user_type=1';
  184. if (!empty($where) && !empty($subwhere)) {
  185. $sql .= ' and '.$where;
  186. $sql .= ' and game_identity in (select identity from game_' . $game . ' where '.$subwhere.')';
  187. }elseif (!empty($where)) {
  188. $sql .= ' and '.$where;
  189. }elseif (!empty($subwhere)) {
  190. $sql .= ' and game_identity in (select identity from game_' . $game . ' where '.$subwhere.')';
  191. }
  192. $data = DB::select($sql);
  193. if (!isset($data) || !$data) {
  194. return -1;
  195. } else {
  196. $data = json_encode($data);
  197. $data = json_decode($data,1);
  198. return current($data);
  199. }
  200. }
  201. //获取回水列表
  202. function getMoneyReturn($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '',$having='') {
  203. DB::connection()->enableQueryLog();
  204. $key = $this->getFeild($type);
  205. // $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  206. $data = $this->select(DB::raw('sum("get_money") as total_money,account_name,max("account_identity") as account_identity'))->groupBy('account_name');
  207. if(!empty($having)){
  208. $data = $data->havingRaw($having);
  209. }
  210. if (!empty($wheregame)) {
  211. // $data = $data->where(function ($data) use ($wheregame, $orwhere) {
  212. // $data->where($orwhere)->orwhere($wheregame);
  213. // });
  214. $data->whereIn('game_name',$wheregame);
  215. }
  216. if (empty($value) || is_array($value)) {
  217. $where = $value;
  218. } else {
  219. $where[] = array($key, '=', $value);
  220. }
  221. // $where[] = array('get_money', '<', '0');
  222. $where[] = array('water_status', '=', 1);
  223. $where[] = array('member_type', '!=', 4);
  224. // $where[] = array('total_money', '<', '0');
  225. //print_r($where);
  226. $data = $data->where($where);
  227. $data = $data->whereIn('status', [1, 2])->paginate($limit);
  228. // $queries = DB::getQueryLog();
  229. // print_r($queries);
  230. if (!$data) {
  231. return -5030001202; //没有列表数据
  232. }
  233. return $data->toArray();
  234. }
  235. //获取用户回水详情列表
  236. function getUserReturndetail($value = '', $type = 1, $limit = 10, $sort = 13, $ads = 'desc') {
  237. $key = $this->getFeild($type);
  238. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  239. $data = $this->orderby($sort, $ads);
  240. if (empty($value) || is_array($value)) {
  241. $value[] = array('water_status', '=', 1);
  242. $data = $data->where($value);
  243. } else {
  244. $data = $data->where($key, $value);
  245. }
  246. $data = $data->whereIn('status', [1, 2])->paginate($limit);
  247. if (!$data) {
  248. return -5030001402; //没有列表数据
  249. }
  250. $data = $data->toArray();
  251. foreach ($data['data'] as $k => $v) {
  252. $data['data'][$k]['game_name'] = trans('money.gametype.' . $v['game_name']);
  253. $data['data'][$k]['returnstatus'] = trans('status.sixmoney_buy.status')[$v['status']];
  254. }
  255. return $data;
  256. }
  257. //字段对应值
  258. private function getFeild($num) {
  259. $data = array(
  260. '1' => 'id',
  261. '2' => 'info_identity',
  262. '3' => 'order_id',
  263. '4' => 'account_name',
  264. '5' => 'account_identity',
  265. '6' => 'game_name',
  266. '7' => 'game_no',
  267. '8' => 'prize_note',
  268. '9' => 'money',
  269. '10' => 'prize_money',
  270. '11' => 'status',
  271. '12' => 'water_status',
  272. '13' => 'money_time',
  273. '14' => 'get_money',
  274. '15' => 'settle_status',
  275. '16' => 'game_status',
  276. '17' => 'member_type',
  277. );
  278. return $data[$num];
  279. }
  280. public static function getBetMoney($time,$id) {
  281. // DB::connection()->enableQueryLog();
  282. $sum = self::where('money_time', '>=', $time)->whereIn('status',['1','2'])->where('game_status','<>',0)->where('account_identity',$id)->sum('money');
  283. // $queries = DB::getQueryLog();
  284. // print_r($queries);
  285. return $sum;
  286. }
  287. function getTotalByUser($game, $page, $list, $where = '') {
  288. if (!empty($where) && is_array($where)) {
  289. $where[] = array('sixmoney_buy.status', '<>', 4);
  290. $where[] = array('game_status', '<>', '0');
  291. $where[] = array('game_name', '=', $game);
  292. $data = $this->select(DB::raw('sum("get_money") as "winmoney",sum("money") as "betmoney","account_name",count("money") as "munbet" ,max("money_time") as end_time,min("money_time") as star_time'))
  293. ->join('account','sixmoney_buy.account_identity', '=', 'account.identity')
  294. ->where('account.status','<>','4')->where($where)->groupBy('account_name')->paginate($list);
  295. if (!$data) {
  296. return -5030001302; //没有列表数据
  297. }
  298. $data = $data->toArray();
  299. foreach ($data['data'] as $k => $v) {
  300. $data['data'][$k]['game_name'] = $game;
  301. $data['data'][$k]['munBet'] = $v['munbet'];
  302. $data['data'][$k]['name'] = trans('report.' . $game);
  303. }
  304. return $data;
  305. }
  306. $start = ($page - 1) * $list;
  307. $data = DB::select('select sum("get_money") as "winmoney",sum("money") as "betmoney","account_name",count("money") as "munBet" ,max("money_time") as end_time,min("money_time") as star_time
  308. from sixmoney_buy inner join account on sixmoney_buy.account_identity=account.identity where sixmoney_buy.status != 4 AND account.status != 4 AND game_status <> 0 AND game_name=:game
  309. group by account_name offset :start limit :list', ['game' => $game, 'start' => $start, 'list' => $list]);
  310. // $data=$this->where('game_name',$game)->groupBy('account_identity')->sum('get_money')->sum('money')->count('id');
  311. $count = $this->where('game_name', $game)->where('sixmoney_buy.status', '<>', 4)
  312. ->join('account','sixmoney_buy.account_identity', '=', 'account.identity')
  313. ->where('account.status','<>','4')->where('game_status', '<>', 0)->groupBy('account_name')->count();
  314. $array = array();
  315. foreach ($data as $k => $v) {
  316. $array[$k]['winmoney'] = $v->winmoney;
  317. $array[$k]['betmoney'] = $v->betmoney;
  318. // $array[$k]['game_name'] = $v->game_name;
  319. $array[$k]['munBet'] = $v->munBet;
  320. $array[$k]['star_time'] = $v->star_time;
  321. $array[$k]['end_time'] = $v->end_time;
  322. $array[$k]['name'] = trans('report.' . $game);
  323. $array[$k]['account_name'] = $v->account_name;
  324. }
  325. $datas['data'] = $array;
  326. $datas['total'] = $count;
  327. return $datas;
  328. }
  329. //获取投注失败的订单
  330. function getNotBet($list = 50, $field = 'money_time', $order = 'desc') {
  331. $data = $this->where('status', 4)->orderBy($field, $order)->paginate($list);
  332. if (!$data) {
  333. return -5030000122; //没有数据
  334. }
  335. return $data->toArray();
  336. }
  337. //获取全部注单信息
  338. function getBuy($where = '', $list = 20, $page = 1, $field = 'money_time', $order = 'desc') {
  339. if (is_array($where) && count($where)) {
  340. $data = $this->where($where)->orderBy($field, $order);
  341. } else {
  342. $data = $this->orderBy($field, $order);
  343. }
  344. $data = $data->orderBy('game_no', $order);
  345. if(!empty($list)){
  346. $data=$data->paginate($list);
  347. }else{
  348. $data=$data->get();
  349. }
  350. if (!$data) {
  351. return -5030000222; //没有数据
  352. };
  353. return $data->toArray();
  354. }
  355. //获取用户打码量
  356. function getHitcode($where) {
  357. //DB::connection()->enableQueryLog();
  358. $data = $this->select(DB::raw('sum("money") as "hitcode_count",account_identity,account_name'))->where($where)->groupBy('account_identity')->groupBy('account_name')->first();
  359. //$queries = DB::getQueryLog();
  360. //print_r($queries);
  361. if (!$data) {
  362. return -5030000402; //没有数据
  363. }
  364. return $data->toArray();
  365. }
  366. //反水状态
  367. function updateWater($name,$timearea,$game_name='') {
  368. $res = $this->where('account_name', $name)
  369. ->where($timearea);
  370. if(empty($game_name)){
  371. $res->whereIn('game_name',array('xy28','jnd28'));
  372. }else{
  373. $res->where('game_name',$game_name);
  374. }
  375. $res=$res->update(['water_status' => '2']);
  376. if (!$res) {
  377. return -3012564406; //反水失败
  378. }
  379. return 1;
  380. }
  381. //总投注
  382. function totalBet($where) {
  383. if (count($where)>0) {
  384. return $this->where($where)->join('account','sixmoney_buy.account_identity', '=', 'account.identity')->where('account.status','<>','4')->where('account.user_type','1')->sum('money');
  385. } else {
  386. return $this->join('account','sixmoney_buy.account_identity', '=', 'account.identity')->where('account.status','<>','4')->where('account.user_type','1')->sum('money');
  387. }
  388. }
  389. //总赢取
  390. function totalGetMoney($where) {
  391. if (count($where)>0) {
  392. $res = $this->where($where)->join('account','sixmoney_buy.account_identity', '=', 'account.identity')->where('account.status','<>','4')->where('account.user_type','1')->sum('get_money');
  393. } else {
  394. $res = $this->join('account','sixmoney_buy.account_identity', '=', 'account.identity')->where('account.status','<>','4')->where('account.user_type','1')->sum('money');
  395. }
  396. return -$res;
  397. }
  398. //异常总投注
  399. function totalBtBet($where) {
  400. if (count($where)>0) {
  401. return $this->where($where)
  402. ->join('btrecord', 'btrecord.identity', 'sixmoney_buy.info_identity')->sum('money');
  403. } else {
  404. return $this->sum('money');
  405. }
  406. }
  407. //异常总赢取
  408. function totalBtGetMoney($where) {
  409. if (count($where)>0) {
  410. $res = $this->where($where)
  411. ->join('btrecord', 'btrecord.identity', 'sixmoney_buy.info_identity')->sum('get_money');
  412. } else {
  413. $res = $this->sum('money');
  414. }
  415. return -$res;
  416. }
  417. //撤单
  418. function Cancel($where) {
  419. $res = $this->where($where)->where('game_status', 0)->update(['status' => 4]);
  420. if (!$res) {
  421. return -5051262522;
  422. }
  423. return 1;
  424. }
  425. //由id数组撤单
  426. function CancelByids($ids) {
  427. $res = $this->whereIn('id', $ids)->update(['status' => 4]);
  428. if (!$res) {
  429. return -5051262522;
  430. }
  431. return 1;
  432. }
  433. //统计每个游戏今日总投注金额
  434. function countTodayMoney() {
  435. $where = array(
  436. array('money_time', '>=', date('Y-m-d 00:00:00', time())),
  437. array('money_time', '<=', date('Y-m-d 23:59:59', time())),
  438. );
  439. $data = $this->select(DB::raw('sum("money") as "betmoney",game_name'))->where($where)->groupBy('game_name')->get();
  440. if (!$data) {
  441. return -5000100102;
  442. }
  443. return $data->toArray();
  444. }
  445. //统计7日总投注金额趋势
  446. function countSevendayMoney($where) {
  447. $data = DB::select("select sum(money) as betmoney, sum(get_money) as winfail_money, to_char(money_time, 'YYYY-MM-DD') as money_date from sixmoney_buy where (to_char(money_time, 'YYYY-MM-DD') >= '".$where."') group by money_date");
  448. if (!$data) {
  449. return -5000100202;
  450. }
  451. $data = json_encode($data);
  452. $data = json_decode($data,1);
  453. return $data;
  454. }
  455. //更新结算状态
  456. function updateSettle($account_arr,$start_time,$end_time){
  457. $model=$this->whereIn('account_name',$account_arr)
  458. ->where('game_status','!=',0);
  459. if(!empty($start_time)){
  460. $model->where('money_time','>=',$start_time);
  461. }
  462. if(!empty($end_time)){
  463. $model->where('money_time','<=',$end_time);
  464. }
  465. $res=$model->update(['settle_status'=>2]);
  466. if(!$res){
  467. return -8005476322;
  468. }
  469. return 1;
  470. }
  471. //管理员作废更新
  472. function updateStatus($order_id){
  473. $res=$this->where('order_id',$order_id)->update(['status'=>4,'prize_money'=>0,'get_money'=>0]);
  474. if(!$res){
  475. return -7021021122;
  476. }
  477. return 1;
  478. }
  479. //统计回水亏损金额用于计算
  480. function countReturn($accountIDs){
  481. $data = $this->select(DB::raw('sum("get_money") as total_money,account_name,max("account_identity") as account_identity'))
  482. ->whereIn('status', [1, 2])
  483. ->whereIn('game_name',array('xy28','jnd28'))
  484. ->whereIn('account_identity',$accountIDs)
  485. ->groupBy('account_name')
  486. ->get();
  487. if (!$data) {
  488. return -5030001202; //没有列表数据
  489. }
  490. return $data->toArray();
  491. }
  492. //代理下级用户投注金额,盈利统计统计
  493. protected function getChildMoneyTotal($child_arr,$timeArea,$type=''){
  494. // echo '<pre>';
  495. //DB::connection()->enableQueryLog();
  496. $data=$this->select(DB::raw('sum(money) as money,sum(get_money) as get_money,account_name'))->whereIn('account_name',$child_arr);
  497. $data=$data->whereIn('status',array(1,2));
  498. $data=$data->where('game_status','<>','0');
  499. if($type==1){//未结算金额
  500. $data=$data->where('settle_status',1);
  501. }
  502. //print_r($timeArea);
  503. if(!empty($timeArea)&&count($timeArea)>0){
  504. $data=$data->where($timeArea);
  505. }
  506. $data=$data->groupBy('account_name');
  507. $data=$data->get();
  508. $queries = DB::getQueryLog();
  509. //print_r($queries);exit;
  510. if(!$data){
  511. return -8040410022;//没有统计数据
  512. }
  513. return $data->toArray();
  514. }
  515. //一段时间内的提现人数
  516. function countUser($timearea){
  517. $data=$this->select('account_name')->where('status', '<>', 4)->whereBetween('money_time', $timearea)->groupBy('account_name')->get();
  518. if(!$data){
  519. return 0;
  520. }
  521. $data=$data->toArray();
  522. return count($data);
  523. }
  524. //获取下级流水键代理id对流水金额
  525. function getChildSumMoney($agent_identity_arr,$time1,$time2,$type=1){
  526. $data=$this->select(DB::raw('"sum"(money) as money,agent_identity'))
  527. ->leftJoin('agent_child','agent_child.account_identity','sixmoney_buy.account_identity')
  528. ->whereIn('agent_identity',$agent_identity_arr)
  529. ->whereIn('status',[1,2])
  530. ->where('game_status','<>',0);
  531. if($type!=1){
  532. //已结算投注金额
  533. $data=$data->where('settle_status',2);
  534. }
  535. if(!empty($time1)){
  536. // $sql.='and money_time >= '.$time1;
  537. $data=$data->where('money_time','>=',$time1);
  538. }
  539. if(!empty($time2)){
  540. // $sql.=' and money_time <= '.$time2;
  541. $data=$data->where('money_time','<=',$time2);
  542. }
  543. // $sql.=' GROUP BY agent_identity';
  544. $data=$data->groupBy('agent_identity')->get();
  545. // $data = DB::select($sql);
  546. if (!$data) {
  547. return -5000100202;
  548. }
  549. // print_r($data);
  550. if (empty($data)) {
  551. return -5000100202;
  552. }
  553. // $data = json_encode($data);
  554. // $data = json_decode($data,1);
  555. $data=$data->toArray();
  556. $return_data=array();
  557. foreach ($data as $k=>$v){
  558. $return_data[$v['agent_identity']]=$v['money'];
  559. }
  560. return $return_data;
  561. }
  562. //统计用户当前期投注总金额
  563. function countNoBetMoney($account_identity,$game_no,$game_name){
  564. return $this->where('account_identity',$account_identity)->where('game_no',$game_no)
  565. ->where('status','<',4)->where('game_name',$game_name)->sum('money');
  566. }
  567. //更新为不中奖
  568. protected function updateDatas($no){
  569. $res=$this->where('game_no',$no)->where('game_status',0)->update(['game_status'=>2]);
  570. if(!$res){
  571. return -504123102;
  572. }
  573. return 1;
  574. }
  575. protected function reSet($no){
  576. $res=$this->where('game_no',$no)->update(['game_status'=>0]);
  577. if(!$res){
  578. return -30081;
  579. }
  580. return 1;
  581. }
  582. /**
  583. *查询历史数据
  584. */
  585. protected function getHistoryBet($limit){
  586. $data=$this->where('status','<>',4)->where('game_status','<>',0)->paginate($limit);
  587. return $data->toArray();
  588. }
  589. protected function BetList($game,$no,$list){
  590. DB::connection()->enableQueryLog();
  591. $data = $this->join('game_'.$game.'_buy',$this->table.'.info_identity','game_'.$game.'_buy.identity')
  592. ->leftJoin('money_back',function ($join){
  593. $join->on('money_back.buy_identity','=',$this->table.'.order_id')
  594. ->where('money_back.status','<>',3);
  595. })
  596. ->where('game_no',$no)
  597. ->where('game_'.$game.'_buy.delstatus',1)
  598. // ->where('money_back.status','<>',3)
  599. ->orderBy('game_'.$game.'_buy.account_identity')
  600. ->select('game_'.$game.'_buy.*',$this->table.'.account_name','money_back.order_id as back_orderid','money_back.money as back_money')
  601. ->paginate($list);
  602. /*$queries = DB::getQueryLog();
  603. echo '<pre>';
  604. print_r($queries);exit;*/
  605. return $data->toArray();
  606. }
  607. }