Money_details.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. class Money_details extends BaseModel {
  5. protected $table = "money_details";
  6. public $timestamps = false;
  7. //获取存取反水列表
  8. function getPartlist($value = '', $type = 1, $page = 10, $sort = 1, $ads = 'desc') {
  9. // DB::connection()->enableQueryLog();
  10. $key = $this->getFeild($type);
  11. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  12. $data = $this->select('money_details.id', 'money_details.trade_id', 'money_details.account_name', 'money_details.account_identity', 'money_details.money', 'money_details.money_time', 'money_details.money_type', 'money_details.money_cash', 'money_details.trade_type', 'money_details.trade_desc', 'money_details.reason', 'money_details.sysetem_user','money_details.status','money_recharge.remark')->leftJoin('money_recharge', 'money_recharge.order_id', '=', 'money_details.trade_id')->whereIn('trade_type', [5, 6, 7, 8, 9, 11, 12, 13, 14, 15,16,19,22]);
  13. if (is_array($value)) {
  14. $data = $data->where($value);
  15. } else {
  16. $data = $data->where($key, $value);
  17. }
  18. $data = $data->orderby($sort, $ads)->paginate($page);
  19. // $queries = DB::getQueryLog();
  20. // print_r($queries);
  21. if (!$data) {
  22. return -3021000102; //没有列表数据
  23. }
  24. return $data->toArray();
  25. }
  26. //获取资金流水列表
  27. function getMoneylist($value = '', $type = 1, $page = 10, $sort = 6, $ads = 'desc') {
  28. $key = $this->getFeild($type);
  29. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  30. //DB::connection()->enableQueryLog();
  31. if (is_array($value)) {
  32. $data = $this->where($value);
  33. } else {
  34. $data = $this->where($key, $value);
  35. }
  36. $data = $data->select('money_details.id', 'money_details.trade_id', 'money_details.account_name', 'money_details.account_identity', 'money_details.money', 'money_details.money_time', 'money_details.money_type', 'money_details.money_cash', 'money_details.trade_type', 'money_details.trade_desc', 'money_details.reason', 'money_details.sysetem_user','money_details.status','money_recharge.remark')->leftJoin('money_recharge', 'money_recharge.order_id', '=', 'money_details.trade_id')->orderby($sort, $ads)->orderby('money_details.id',$ads)->paginate($page);
  37. //$queries = DB::getQueryLog();
  38. //print_r($queries);
  39. if (!$data) {
  40. return -3021000102; //没有列表数据
  41. }
  42. return $data->toArray();
  43. }
  44. //用户提现笔数区间筛选
  45. function getTakenumArea($where = '', $type = 1, $list = 10, $sort = 6, $ads = 'desc', $page = 1, $having = '', $whereIn = '') {
  46. //DB::connection()->enableQueryLog();
  47. $data = $this->select(DB::raw('max(account.id) as id, max(account.identity) as identity, max(account) as account, max(grade) as grade, max(cash) as cash, max(name) as name, max(register_time) as register_time, max(register_ip) as register_ip, max(last_ip) as last_ip, max(phone) as phone, max(email) as email, max(statuss) as statuss,max(last_time) as last_time,count("trade_id") as betnum'))->join('account_detailed', 'money_details.account_identity', '=', 'account_detailed.account_identity')->join('account', 'money_details.account_identity', 'account.identity')->groupBy('money_details.account_identity')->whereIn('trade_type', $whereIn)->where('money_details.status', 1);
  48. if (!empty($where) && is_array($where) && !empty($having) && is_array($having)) {
  49. $data = $data->where($where);
  50. foreach ($having as $v) {
  51. $data = $data->havingRaw($v);
  52. }
  53. } elseif (!empty($having) && is_array($having)) {
  54. foreach ($having as $v) {
  55. $data = $data->havingRaw($v);
  56. }
  57. } elseif (!empty($where) && is_array($where)) {
  58. $data = $data->where($where);
  59. }
  60. $data = $data->paginate($list);
  61. //$queries = DB::getQueryLog();
  62. //print_r($queries);
  63. if (!$data) {
  64. return -3020100402; //没有订单统计信息
  65. }
  66. $data = $data->toArray();
  67. return $data;
  68. }
  69. //统计会员财务日志
  70. function getFundlog($value = '', $type = 1, $limit = 10, $sort = 6, $ads = 'desc',$page=1) {
  71. $key = $this->getFeild($type);
  72. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  73. //DB::connection()->enableQueryLog();
  74. $value .= empty($value)?' where ':' and ';
  75. $value .= 'status=1 ';
  76. $offset = ($page-1)*$limit;
  77. $sql = 'SELECT main.account_name,SUM(CASE WHEN trade_type=14 THEN money ELSE 0 END) as sendmoney,
  78. SUM(CASE WHEN trade_type=6 OR trade_type=11 THEN money ELSE 0 END) as savemoney,
  79. SUM(CASE WHEN trade_type=5 OR trade_type=9 THEN money ELSE 0 END) as getmoney,
  80. SUM(CASE WHEN trade_type=12 AND money_type=1 THEN money ELSE 0 END) as adminadd,
  81. SUM(CASE WHEN trade_type=12 AND trade_type=2 THEN money ELSE 0 END) as adminpull,
  82. SUM(CASE WHEN trade_type=13 THEN money ELSE 0 END) as recharge_send,
  83. SUM(CASE WHEN trade_type=7 OR trade_type=8 THEN money ELSE 0 END) as back_return,
  84. (SUM(CASE WHEN trade_type=14 OR trade_type=6 OR trade_type=11 THEN money ELSE 0 END)-
  85. SUM(CASE WHEN trade_type=5 OR trade_type=9 THEN money ELSE 0 END)) as winmoney
  86. from money_details as main '.$value.' GROUP BY main.account_name LIMIT '.$limit.' OFFSET '.$offset;
  87. $countsql = 'SELECT COUNT(account_name) from (SELECT account_name from money_details '.$value.' GROUP BY account_name) as a';
  88. $data = DB::select($sql);
  89. $count = DB::select($countsql);
  90. //$queries = DB::getQueryLog();
  91. //print_r($queries);
  92. if (!$data) {
  93. return -3021000502; //没有列表数据
  94. }
  95. $data = json_encode($data);
  96. $data = json_decode($data,1);
  97. $resdata['data'] = $data;
  98. $resdata['total'] = $count[0]->count;
  99. return $resdata;
  100. /*$data = $this->select(DB::raw('account_name,MAX("account_identity") as account_identity'))->groupBy('account_name');
  101. if (is_array($value)) {
  102. $data = $data->where($value);
  103. } else if (!empty($value)) {
  104. $data = $data->where($key, $value);
  105. }
  106. if (!empty($whereIn) && is_array($whereIn)) {
  107. foreach ($whereIn as $k => $v) {
  108. $data = $data->whereIn($v[0], $v[1]);
  109. }
  110. }
  111. if (!empty($whereNotin) && is_array($whereNotin)) {
  112. foreach ($whereNotin as $k => $v) {
  113. $data = $data->whereNotIn($v[0], $v[1]);
  114. }
  115. }
  116. $data = $data->paginate($page);
  117. //$queries = DB::getQueryLog();
  118. //print_r($queries);
  119. if (!$data) {
  120. return -3021000102; //没有列表数据
  121. }
  122. return $data->toArray();*/
  123. }
  124. //分类统计会员财务
  125. function getPartlog($value = '', $type = 1) {
  126. $key = $this->getFeild($type);
  127. $data = $this->select(DB::raw('trade_type,SUM("money") as summoney,money_type'))->groupBy('trade_type')->groupBy('money_type');
  128. if (is_array($value)) {
  129. $data = $data->where($value);
  130. } else if (!empty($value)) {
  131. $data = $data->where($key, $value);
  132. }
  133. $data = $data->get();
  134. //$queries = DB::getQueryLog();
  135. //print_r($queries);
  136. if (!$data) {
  137. return -3021000102; //没有列表数据
  138. }
  139. return $data->toArray();
  140. }
  141. //分类统计会员财务改
  142. function getPatlog($where){
  143. $data = $this->select(DB::raw('trade_type,sum("money") as summoney,money_type,account_name'))
  144. ->where($where)
  145. ->groupBy('trade_type')
  146. ->groupBy('money_type')
  147. ->groupBy('account_name')
  148. ->get();
  149. if (!$data) {
  150. return -3021000102; //没有列表数据
  151. }
  152. return $data->toArray();
  153. }
  154. //获取账务订单详情
  155. function getOrderDetails($value, $type = 1, $jointable = '', $columnn = '', $columnw = '') {
  156. $key = $this->getFeild($type);
  157. if (empty($jointable)) {
  158. $data = $this->where($key, $value)->first();
  159. } elseif ($jointable == 'account_bank') {
  160. $data = $this->select('money_details.account_name as account', 'trade_id', 'bank_name', 'account_bank.account_name', 'bank_number', 'bank_address', 'money_time', 'money', 'money_details.status', 'trade_type', 'reason')->where($key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
  161. } else {
  162. $data = $this->where($key, $value)->join($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw)->first();
  163. }
  164. if (!$data) {
  165. return -3021000402; //没有订单信息
  166. }
  167. return $data->toArray();
  168. }
  169. //获取游戏倍率
  170. function getOddsBy($game_code) {
  171. $data = $this->select('odds')->where('game_code', $game_code)->where('type', 2)->where('isparent_node', 1)->get();
  172. $data = $data->toArray();
  173. if (!$data) {
  174. return -8010011001; //没有倍率
  175. }
  176. $redata = array();
  177. //组合游戏项的倍率
  178. foreach ($data as $k => $v) {
  179. $redata = array_merge($redata, json_decode($v['odds'], 1));
  180. }
  181. return $redata;
  182. }
  183. //获取号码信息
  184. function getInfoByCode($code) {
  185. $data = $this->where('parent', $code)->get();
  186. if (!$data) {
  187. return -8020000501; //没有游戏玩法的号码
  188. }
  189. return $data->toArray();
  190. }
  191. //字段对应值
  192. private function getFeild($num) {
  193. $data = array(
  194. '1' => 'id',
  195. '2' => 'info_identity',
  196. '3' => 'trade_id',
  197. '4' => 'account_name',
  198. '5' => 'account_identity',
  199. '6' => 'money_time',
  200. '7' => 'money_type',
  201. '8' => 'trade_type',
  202. '9' => 'sysetem_user',
  203. '10' => 'status',
  204. );
  205. return $data[$num];
  206. }
  207. function updateInfo($data,$value,$field=1){
  208. $key = $this->getFeild($field);
  209. $res = $this->where($key,$value)->update($data);
  210. if($res<0){
  211. return -3021010102; //更新失败
  212. }
  213. return 1;
  214. }
  215. function money($page, $identity, $status) {
  216. $data = $this->select('account_identity', 'money_type', 'money_time', 'trade_id', 'trade_type', 'money', 'money_cash', 'trade_desc', 'status')
  217. ->orderBy('money_time', 'desc')
  218. ->where('account_identity', $identity)
  219. ->limit($page)
  220. ->get();
  221. foreach ($data as $k => $v) {
  222. if ($v['money_type'] == 1 && $v['status'] == $status) {
  223. $data[$k]['old_money'] = sprintf("%.1f", $v['money_cash'] - $v['money']);
  224. } elseif ($v->money_type == 2 && $v['status'] == $status) {
  225. $data[$k]['old_money'] = sprintf("%.1f", $v['money_cash'] + $v['money']);
  226. }
  227. }
  228. if (!$data) {
  229. return -2020062003; //用户没有数据
  230. }
  231. return $data->toArray();
  232. }
  233. //插入数据
  234. function insertData($data) {
  235. if ($this->checkTrade_id($data['trade_id'])) {
  236. return -3010026022; //订单号已存在。
  237. }
  238. $data['info_identity'] = UUID();
  239. $res = $this->insert($data);
  240. if (!$res) {
  241. return -2020072022; //插入资金详情失败
  242. }
  243. return 1;
  244. }
  245. //获取用户的流水记录
  246. function getUserWater($account_id, $list = 10, $where = '') {
  247. $data = $this->where('account_identity', $account_id);
  248. if (!empty($where) && is_array($where)) {
  249. $data = $data->where($where);
  250. }
  251. $data = $data->orderBy('money_time', 'desc')->paginate($list);
  252. if (!$data) {
  253. return -8020010522; //没有数据
  254. }
  255. $datas = $data->toArray();
  256. if (is_array($datas['data']) && count($datas['data'])) {
  257. foreach ($datas['data'] as $k => $v) {
  258. if ($v['money_type'] == 1) {
  259. $datas['data'][$k]['old_money'] = $v['money_cash'] - $v['money'];
  260. } else {
  261. $datas['data'][$k]['old_money'] = $v['money_cash'] + $v['money'];
  262. }
  263. }
  264. }
  265. return $datas;
  266. }
  267. //检测交易订单号
  268. function checkTrade_id($order_id) {
  269. $res = $this->where('trade_id', $order_id)->first();
  270. if ($res) {
  271. return true;
  272. }
  273. return false;
  274. }
  275. //统计总金额
  276. function sumMoney($where) {
  277. $res = $this->where($where)->sum('money');
  278. return $res;
  279. }
  280. //获取存取反水总金额含活动赠送
  281. function getTotal($time) {
  282. $array = array(5, 6, 7, 8, 9, 11, 12, 13, 14);
  283. $res = $this->where($time)->whereIn('trade_type', $array)->sum('money');
  284. return $res;
  285. }
  286. //入款总额汇总
  287. function getIntoTotal($where) {
  288. $array = array(6, 11, 14);
  289. $res = $this->where($where)->whereIn('trade_type', $array)->sum('money');
  290. return $res;
  291. }
  292. //统计各项入款金额
  293. function sumIntoMoney($where) {
  294. $res = $this->where($where)->sum('money');
  295. return $res;
  296. }
  297. //测试统计
  298. function totalTypeMoney($where){
  299. $type=array(5,6,7,8,9,12,11,13,14,16,19,10,22);
  300. $data=$this->select(DB::raw('sum(money) as money,trade_type,money_type'))
  301. ->whereIn('trade_type',$type)
  302. ->where($where)
  303. ->groupBy('trade_type')
  304. ->groupBy('money_type')
  305. ->get();
  306. return $data->toArray();
  307. }
  308. function getActiveMoney($where, $type) {
  309. $res = $this->where('money_type', $type)->where($where)->where('trade_type', 12)->sum('money');
  310. return $res;
  311. }
  312. //汇款金额汇总统计
  313. function sendMoneyCount($where = '') {
  314. $data = array();
  315. $data['all_money'] = $this->whereIn('trade_type', [13, 14])->sum('money');
  316. $data['success_money'] = $this->whereIn('trade_type', [13])->sum('money');
  317. $data['give_money'] = $this->whereIn('trade_type', [13, 14])->where('status', 1)->sum('money');
  318. $data['fail_money'] = $this->whereIn('trade_type', [13, 14])->where('status', 2)->sum('money');
  319. if (!empty($where) && is_array($where)) {
  320. $data['all_money'] = $this->where($where)->whereIn('trade_type', [13, 14])->sum('money');
  321. $data['success_money'] = $this->where($where)->whereIn('trade_type', [13])->sum('money');
  322. $data['give_money'] = $this->where($where)->whereIn('trade_type', [13, 14])->where('status', 1)->sum('money');
  323. $data['fail_money'] = $this->where($where)->whereIn('trade_type', [13, 14])->where('status', 2)->sum('money');
  324. }
  325. return $data;
  326. }
  327. //反水插入
  328. function returnData($data) {
  329. $res = $this->insert($data);
  330. if (!$res) {
  331. return -5020034002; //反水失败
  332. }
  333. return 1;
  334. }
  335. function getBet() {
  336. $time2 = date("Y-m-d H:i:s", time() - 60 * 60 * 24 * 7);
  337. $type=array(5,6,11,14);
  338. //提现
  339. $rech_data= $this->select(DB::Raw('date(money_time)'), DB::Raw('sum(money) as value'),'trade_type')->where('money_time', '>=', $time2)
  340. ->where('status',1)
  341. ->whereIn('trade_type',$type)
  342. ->orderBy(DB::Raw('date(money_time)'), 'asc')->groupBy(DB::Raw('date(money_time)'))->groupBy('trade_type')->get();
  343. if (!$rech_data) {
  344. return -3021010102; //没有列表数据
  345. }
  346. return $rech_data->toArray();
  347. //判断数据是否存在
  348. /*$rech_data['money_with'] = $rech_data['money_with']->toArray();
  349. $rech_data['money_recharge'] = $this->join('account', 'account.identity', '=', 'money_details.account_identity')->select(DB::Raw('date(money_time)'), DB::Raw('sum(money) as value'))->whereBetween('money_time', $timearea)->orderBy(DB::Raw('date(money_time)'), 'asc')->groupBy(DB::Raw('date(money_time)'))->where('trade_type', 6)->get();
  350. $rech_data['money_recharge'] = $rech_data['money_recharge']->toArray();
  351. $rech_data['money_remittance'] = $this->join('account', 'account.identity', '=', 'money_details.account_identity')->select(DB::Raw('date(money_time)'), DB::Raw('sum(money) as value'))->whereBetween('money_time', $timearea)->orderBy(DB::Raw('date(money_time)'), 'asc')->groupBy(DB::Raw('date(money_time)'))->where('trade_type', 11)->get();
  352. $rech_data['money_remittance'] = $rech_data['money_remittance']->toArray();
  353. $rech_data['money_trans'] = $this->join('account', 'account.identity', '=', 'money_details.account_identity')->select(DB::Raw('date(money_time)'), DB::Raw('sum(money) as value'))->whereBetween('money_time', $timearea)->orderBy(DB::Raw('date(money_time)'), 'asc')->groupBy(DB::Raw('date(money_time)'))->where('trade_type', 14)->get();
  354. $rech_data['money_trans'] = $rech_data['money_trans']->toArray();
  355. return $rech_data;*/
  356. }
  357. function countUser($timearea, $array) {
  358. $data = $this->select('account_name')->whereBetween('money_time', $timearea)->whereIn('trade_type', $array)->groupBy('account_name')->get();
  359. if (!$data) {
  360. return 0;
  361. }
  362. $data = $data->toArray();
  363. return count($data);
  364. }
  365. //下级会员资金列表
  366. function getChildMoneyList($childs,$list){
  367. $data=$this->whereIn('account_name',$childs)->orderBy('money_time','desc')->paginate($list);
  368. if (!$data) {
  369. return -3021000102; //没有列表数据
  370. }
  371. return $data->toArray();
  372. }
  373. //获取用户存取款笔数
  374. function getUserMoneynum($aid){
  375. $rechargenum=$this->whereIn('trade_type',array(6,12,11,14))->where('account_identity',$aid)->count();
  376. $takenum=$this->whereIn('trade_type',array(5))->where('account_identity',$aid)->count();
  377. $data = array(
  378. 'recharge_num' => !$rechargenum?0:$rechargenum,
  379. 'take_num' => !$takenum?0:$takenum,
  380. );
  381. return $data;
  382. }
  383. //批量插入数据
  384. function insertAllData($data) {
  385. $res = $this->insert($data);
  386. if (!$res) {
  387. return -2020072022; //插入资金详情失败
  388. }
  389. return 1;
  390. }
  391. //根据用户名统计该用户提款,充值成功次数
  392. function countUserNum($account_name){
  393. $data=$this->select(DB::raw('count(id) as num,trade_type'))->where('status',1)->where('account_name',$account_name)->whereIn('trade_type',array(5,6,11,14))->groupBy('trade_type')->get();
  394. if(!$data){
  395. return array();
  396. }
  397. return $data->toArray();
  398. }
  399. //获取用户充值总金额
  400. function sumRecharge($account_name){
  401. return $this->where('account_name',$account_name)->where('status',1)->whereIn('trade_type',array(6,11,14))->sum('money');
  402. }
  403. protected function getBetMoney($time,$id) {
  404. // DB::connection()->enableQueryLog();
  405. $sum = $this->where('money_time', '>', $time)->whereIn('status',['1','2'])->where('account_identity',$id)->sum('money');
  406. // $queries = DB::getQueryLog();
  407. // print_r($queries);
  408. return $sum;
  409. }
  410. /** 获取一种类型得数据
  411. * @param $type 交易类型
  412. * @param $limit 条数
  413. * @param $otherWhere 其他条件
  414. */
  415. protected function getTypeData($type,$limit,$otherwhere=array()){
  416. $data=$this->where('trade_type',$type);
  417. if(is_array($otherwhere)&&count($otherwhere)>0){
  418. $data=$data->where($otherwhere);
  419. }
  420. $data=$data->orderBy('id','asc');
  421. $data=$data->paginate($limit);
  422. return $data->toArray();
  423. }
  424. protected function getTypesData($typearray=array(),$limit){
  425. $data=$this->whereIn('trade_type',$typearray)->paginate($limit);
  426. return $data->toArray();
  427. }
  428. }