Game_diceone.php 18 KB

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