MoneyBuy.php 26 KB

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