Money_take.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class Money_take extends BaseModel {
  5. protected $table = "money_take";
  6. public $timestamps = false;
  7. //获取提现列表
  8. function getTakelist($value = '', $type = 1, $limit = 10, $sort = 6, $ads = 'desc',$jointable,$grade='') {
  9. //DB::connection()->enableQueryLog();
  10. $key = $this->getFeild($type);
  11. $sort = is_integer($sort) ? 'money_take.'.$this->getFeild($sort) : 'money_take.'.$sort;
  12. $data = $this->orderby($sort, $ads);
  13. if (!empty($value)) {
  14. if (is_array($value)) {
  15. $data = $data->where($value);
  16. } else {
  17. $data = $data->where($key, $value);
  18. }
  19. }
  20. if (!empty($jointable) && ($jointable == 'account_detailed')) {
  21. $data->join('account_detailed', 'account_detailed.account_identity', 'money_take.account_identity');
  22. $data->where('grade',$grade);
  23. }
  24. $data = $data->paginate($limit);
  25. //$queries = DB::getQueryLog();
  26. //print_r($queries);
  27. if (!$data) {
  28. return -3020100102; //没有列表数据
  29. }
  30. return $data->toArray();
  31. }
  32. //获取提现订单详情
  33. function getOrderDetails($value, $type = 1, $jointable = '', $columnn = '', $columnw = '', $clumn = 1) {
  34. $key = $this->getFeild($type);
  35. if ($clumn == 1) {
  36. $data = $this->where($key, $value);
  37. } elseif ($clumn == 2) {
  38. $data = $this->select('account_name as account', 'order_id as trade_id', 'bank_info as bank_name', 'bank_user as account_name', 'bank_no as bank_number', 'bank_address', 'apply_time as money_time', 'money', 'status', 'reason')->where($key, $value);
  39. }
  40. $data = $data->first();
  41. if (!$data) {
  42. return -3020100302; //没有订单信息
  43. }
  44. return $data->toArray();
  45. }
  46. //获取提现记录条数
  47. function getCountnum($value = '', $type = 10) {
  48. $key = $this->getFeild($type);
  49. if (!empty($value) && is_array($value)) {
  50. $data = $this->where($value);
  51. } else if (!empty($value)) {
  52. $data = $this->where($key, $value);
  53. }
  54. $data = $data->count();
  55. return $data;
  56. }
  57. //获取提现统计
  58. function getTotal($where = '', $type = 1, $list = 10, $sort = 6, $ads = 'desc', $page = 1, $having = '') {
  59. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  60. $data = $this->select(DB::raw('account_name,money_take.account_identity,count("order_id") as betnum,sum("money") as betmoney,money_take.status,max("name") as name,max("apply_time") as end_time,min("apply_time") as star_time'))->join('account_detailed', 'money_take.account_identity', 'account_detailed.account_identity')->groupBy('account_name')->groupBy('money_take.account_identity')->groupBy('status');
  61. if (!empty($where) && is_array($where) && !empty($having) && is_array($having)) {
  62. $data = $data->where($where);
  63. foreach ($having as $v) {
  64. $data = $data->havingRaw($v);
  65. }
  66. } elseif (!empty($having) && is_array($having)) {
  67. foreach ($having as $v) {
  68. $data = $data->havingRaw($v);
  69. }
  70. } elseif (!empty($where) && is_array($where)) {
  71. $data = $data->where($where);
  72. }
  73. $data = $data->orderby('star_time', 'desc')->paginate($list);
  74. if (!$data) {
  75. return -3020100402; //没有订单统计信息
  76. } else {
  77. $data = $data->toArray();
  78. $status = trans('status.money_take.status');
  79. foreach ($data['data'] as $k => $v) {
  80. if ($v['status'] == 1 || $v['status'] == 2) {
  81. $data['data'][$k]['status'] = $status[$v['status']];
  82. } else {
  83. $data['data'][$k]['status'] = $status[3];
  84. }
  85. $data['data'][$k]['statuss'] = $v['status'];
  86. }
  87. return $data;
  88. }
  89. }
  90. //获取提现统计详情
  91. function getTotalDetails($value, $type = 1, $list = 10, $page = 1, $sort = 6, $ads = 'desc') {
  92. $key = $this->getFeild($type);
  93. $sort = is_integer($sort) ? $this->getFeild($sort) : $sort;
  94. $data = $this->orderby($sort, $ads);
  95. if (!empty($value) && is_array($value)) {
  96. //提现统计详情,条件会员、状态,关联用户详情表
  97. $data = $data->select('account_name as account', 'order_id as trade_id', 'bank_info as bank_name', 'bank_user as account_name', 'bank_no as bank_number', 'bank_address', 'apply_time as money_time', 'money', 'money_cash', 'money_cash', 'money_take.status', 'reason', 'name', 'money_cash as old_money')->join('account_detailed', 'money_take.account_identity', 'account_detailed.account_identity')->join('money_details', 'money_take.order_id', 'money_details.trade_id')->where($value);
  98. } else {
  99. $data = $data->where($key, $value);
  100. }
  101. $data = $data->paginate($list);
  102. if (!$data) {
  103. return -3020100502; //没有订单信息
  104. }
  105. $data = $data->toArray();
  106. return $data;
  107. }
  108. //字段对应值
  109. private function getFeild($num) {
  110. $data = array(
  111. '1' => 'id',
  112. '2' => 'info_identity',
  113. '3' => 'order_id',
  114. '4' => 'account_name',
  115. '5' => 'account_identity',
  116. '6' => 'apply_time',
  117. '7' => 'pass_time',
  118. '8' => 'apply_date',
  119. '9' => 'sysetem_user',
  120. '10' => 'status',
  121. );
  122. return $data[$num];
  123. }
  124. //总提现数
  125. function getCount($account_id) {
  126. $count = $this->where('account_identity', $account_id)->where('status',1)->count();
  127. return $count;
  128. }
  129. //今日提现总数
  130. function gettoDayCount($account_id) {
  131. $today = date('Y-m-d', time());
  132. $count = $this->where('account_identity', $account_id)->where('apply_date', $today)->where('status', 1)->count();
  133. return $count;
  134. }
  135. //修改更新数据
  136. function updateInfo($data, $oid) {
  137. $res = $this->where('order_id', $oid)->update($data);
  138. if (!$res) {
  139. return -3020102202;
  140. }
  141. return 1;
  142. }
  143. //提现金额汇总统计
  144. function takeMoneyCount($where = '') {
  145. $data = array();
  146. $data['all_money'] = $this->where('status', '<>', 2)->sum('money');
  147. $data['success_money'] = $this->where('status', 1)->sum('money');
  148. // $data['fail_money'] = $this->where('status',2)->sum('money');
  149. $data['service_money'] = 0;
  150. $data['handing'] = $this->where('status', '0')->sum('money');
  151. if (!empty($where) && is_array($where)) {
  152. $data['all_money'] = $this->where($where)->where('status', '<>', 2)->sum('money');
  153. $data['success_money'] = $this->where($where)->where('status', 1)->sum('money');
  154. // $data['fail_money'] = $this->where($where)->where('status',2)->sum('money');
  155. $data['handing'] = $this->where($where)->where('status', '0')->sum('money');
  156. }
  157. return $data;
  158. }
  159. //最后一个提款
  160. function getLast($account_id) {
  161. $time = $this->where('account_identity', $account_id)->where('status', 1)->first();
  162. if (!$time) {
  163. return -3020102302;
  164. }
  165. return $time->toArray();
  166. }
  167. //一段时间内的提现人数
  168. function countUser($timearea){
  169. $data=$this->select('account_name')->whereBetween('apply_time', $timearea)->groupBy('account_name')->get();
  170. if(!$data){
  171. return 0;
  172. }
  173. $data=$data->toArray();
  174. return count($data);
  175. }
  176. //检测订单是否已经操作
  177. function checkInfo($order_id){
  178. $data=$this->where('order_id',$order_id)->where('status',0)->first();
  179. if(!$data){
  180. return -5051272522;
  181. }
  182. return 1;
  183. }
  184. //获取历史成功提现
  185. protected function getTakeHistory($limit){
  186. $data=$this->where('status',1)->paginate($limit);
  187. return $data->toArray();
  188. }
  189. }