Money_recharge.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. class Money_recharge extends BaseModel
  5. {
  6. protected $table = "money_recharge";
  7. public $timestamps = false;
  8. //获取充值列表
  9. function getRechargelist($value = '', $type = 1, $page = 10, $sort = 6, $ads = 'desc', $infield = '', $invalue = '', $jointable = '', $whereIn = '', $sql = '')
  10. {
  11. $key = $this->getFeild ($type);
  12. $sort = is_integer ($sort) ? $this->getFeild ($sort) : $sort;
  13. // DB::connection()->enableQueryLog();
  14. if (is_array ($value)) {
  15. $data = $this->where ($value);
  16. } else {
  17. $data = $this->where ($key, $value);
  18. }
  19. if (!empty($whereIn)) {
  20. $data = $data->whereIn ('status', $whereIn);
  21. }
  22. if (!empty($sql)) {
  23. $data = $data->whereRaw ($sql);
  24. }
  25. if (!empty($jointable) && ($jointable == 'money_recharge_remark')) {
  26. $data = $data->select ('money_recharge.*', 'account_detailed.group_name', 'money_recharge_remark.name', 'money_recharge_remark.recharge_time');
  27. $data = $data->leftJoin ('money_recharge_remark', 'money_recharge_remark.order_id', 'money_recharge.order_id');
  28. } else {
  29. $data = $data->select ('money_recharge.*', 'account_detailed.group_name');
  30. }
  31. $data = $data->join ('account_detailed', 'account_detailed.account_identity', 'money_recharge.account_identity');
  32. if (!empty($infield) && !empty($invalue)) {
  33. $data = $data->whereIn ($infield, ['汇款', '汇款赠送']);
  34. } else {
  35. $data = $data->whereNotIn ('recharge_type', ['汇款', '汇款赠送']);
  36. }
  37. $data = $data->orderby ($sort, $ads)->paginate ($page);
  38. // $queries = DB::getQueryLog();
  39. // print_r($queries);
  40. if (!$data) {
  41. return -3020000102; //没有列表数据
  42. }
  43. return $data->toArray ();
  44. }
  45. //获取充值记录条数
  46. function getCount($value = '', $type = 10)
  47. {
  48. $key = $this->getFeild ($type);
  49. //DB::connection()->enableQueryLog();
  50. if (!empty($value) && is_array ($value)) {
  51. $data = $this->where ($value);
  52. } else if (!empty($value)) {
  53. $data = $this->where ($key, $value);
  54. }
  55. $data = $data->count ();
  56. //$queries = DB::getQueryLog();
  57. //print_r($queries);
  58. return $data;
  59. }
  60. //获取充值统计
  61. function getTotal($where = '', $type = 1, $list = 10, $sort = 6, $ads = 'desc', $page = 1, $having = '', $status = '')
  62. {
  63. $data = $this->select (DB::raw ('account_name,recharge_type,money_recharge.account_identity,count("order_id") as betnum,sum("money") as betmoney,money_recharge.status,max("name") as name,max("apply_time") as end_time,min("apply_time") as star_time'))->join ('account_detailed', 'money_recharge.account_identity', 'account_detailed.account_identity')->groupBy ('account_name')->groupBy ('money_recharge.account_identity')->groupBy ('status')->groupBy ('recharge_type');
  64. if (!empty($where) && is_array ($where) && !empty($having) && is_array ($having)) {
  65. $data = $data->where ($where);
  66. foreach ($having as $v) {
  67. $data = $data->havingRaw ($v);
  68. }
  69. } elseif (!empty($having) && is_array ($having)) {
  70. foreach ($having as $v) {
  71. $data = $data->havingRaw ($v);
  72. }
  73. } elseif (!empty($where) && is_array ($where)) {
  74. $data = $data->where ($where);
  75. }
  76. if (!empty($status)) {
  77. $nstatus = ($status == 1) ? '0' : (($status == 2) ? 1 : (($status == 3) ? 2 : '0'));
  78. $status = ($status == 4) ? '0' : $status;
  79. $c1 = array(array('recharge_type', '=', '在线充值'));
  80. $c2 = array(array('status', '=', $status));
  81. $c3 = array(array('recharge_type', '<>', '在线充值'));
  82. $c4 = array(array('status', '=', $nstatus));
  83. $data = $data->where (function ($data) use ($c1, $c2, $c3, $c4) {
  84. $data->where (function ($data) use ($c1, $c2) {
  85. $data->where ($c1)->where ($c2);
  86. })->orwhere (function ($data) use ($c3, $c4) {
  87. $data->where ($c3)->where ($c4);
  88. });
  89. });
  90. }
  91. $data = $data->orderBy ('star_time', 'desc')->paginate ($list);
  92. if (!$data) {
  93. return -3020000402; //没有订单统计信息
  94. } else {
  95. $data = $data->toArray ();
  96. $status = trans ('status.money_recharge.status');
  97. $ostatus = trans ('status.money_recharge.remit_status');
  98. foreach ($data['data'] as $k => $v) {
  99. if ($v['recharge_type'] == '在线充值') {
  100. $data['data'][$k]['status'] = ($v['status'] == 0) ? $status[4] : $status[$v['status']];
  101. } else {
  102. $data['data'][$k]['status'] = ($v['status'] == 3) ? $ostatus[2] : $ostatus[$v['status']];
  103. }
  104. $data['data'][$k]['statuss'] = $v['status'];
  105. }
  106. return $data;
  107. }
  108. }
  109. //获取充值订单详情
  110. function getOrderDetails($value, $type = 1, $jointable = '', $columnn = '', $columnw = '')
  111. {
  112. $key = $this->getFeild ($type);
  113. if (is_array ($value) && !empty($value)) {
  114. $data = $this->where ($value);
  115. } else {
  116. $data = $this->where ($key, $value);
  117. }
  118. if ($jointable == 'account_bank') {
  119. $data = $data->select ('money_recharge.account_name as account', 'order_id as trade_id', 'bank_name', 'account_bank.account_name', 'bank_number', 'bank_address', 'apply_time as money_time', 'money', 'money_recharge.status', 'recharge_type as trade_type', 'reason', 'remark')->join ($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw);
  120. } elseif (!empty($jointable)) {
  121. $data = $data->join ($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw);
  122. }
  123. $data = $data->first ();
  124. if (!$data) {
  125. return -3020000302; //没有订单信息
  126. }
  127. return $data->toArray ();
  128. }
  129. //获取充值统计详情
  130. function getTotalDetails($value, $type = 1, $list = 10, $page = 1, $sort = 6, $ads = 'desc')
  131. {
  132. $key = $this->getFeild ($type);
  133. $sort = is_integer ($sort) ? $this->getFeild ($sort) : $sort;
  134. if (!is_array ($value)) {
  135. $data = $this->where ($key, $value)->paginate ($list);
  136. } else {
  137. //提现统计详情,条件会员、状态,关联用户详情表
  138. $data = $this->select ('money_recharge.account_name as account', 'order_id as trade_id', 'bank_name', 'account_bank.account_name', 'bank_number', 'bank_address', 'apply_time as money_time', 'complete_time', 'money', 'money_recharge.status', 'recharge_type as trade_type', 'reason', 'remark')->join ('account_bank', 'money_recharge.account_identity', 'account_bank.account_identity')->where ($value)->orderby ($sort, $ads)->paginate ($list);
  139. }
  140. if (!$data) {
  141. return -3020000502; //没有订单信息
  142. }
  143. return $data->toArray ();
  144. }
  145. //充值金额汇总统计
  146. function rechargeMoneyCount($where = '')
  147. {
  148. $data = array();
  149. $data['all_money'] = $this->where ('recharge_type', '<>', 1)->where ('status', '=', 2)->where ('recharge_type', '<>', '汇款')->where ('recharge_type', '<>', '汇款赠送')->sum ('money');
  150. $data['online_success'] = $this->whereIn ('recharge_type', ['在线充值'])->where ('status', 1)->sum ('money');
  151. $data['admin_success'] = $this->where ('recharge_type', '后台充值')->where ('status', 1)->sum ('money');
  152. $data['service_money'] = $this->whereIn ('recharge_type', ['后台充值赠送', '活动充值赠送'])->where ('status', 1)->sum ('money');
  153. // $data['online_fail'] = $this->where('recharge_type', 1)->where('status', 3)->sum('money');
  154. $data['admin_fail'] = $this->where ('recharge_type', '活动充值')->where ('status', 1)->sum ('money');
  155. $data['handing'] = $this->where ('recharge_type', '<>', '汇款')->where ('recharge_type', '<>', '汇款赠送')->where ('status', 1)->sum ('money');
  156. if (!empty($where) && is_array ($where)) {
  157. $data['all_money'] = $this->where ($where)->where ('recharge_type', '<>', 1)->where ('status', '<>', 3)->where ('recharge_type', '<>', '汇款')->where ('recharge_type', '<>', '汇款赠送')->sum ('money');
  158. $data['online_success'] = $this->whereIn ('recharge_type', ['在线充值'])->where ($where)->where ('status', 1)->sum ('money');
  159. $data['admin_success'] = $this->where ('recharge_type', '后台充值')->where ($where)->where ('status', 1)->sum ('money');
  160. $data['service_money'] = $this->whereIn ('recharge_type', ['后台充值赠送', '活动充值赠送'])->where ($where)->where ('status', 1)->sum ('money');
  161. // $data['online_fail'] = $this->where('recharge_type', 1)->where($where)->where('status', 3)->sum('money');
  162. $data['admin_fail'] = $this->where ('recharge_type', '活动充值')->where ($where)->where ('status', 1)->sum ('money');
  163. $data['handing'] = $this->where ($where)->where ('recharge_type', '<>', '汇款')->where ('recharge_type', '<>', '汇款赠送')->where ('status', 1)->sum ('money');
  164. }
  165. return $data;
  166. }
  167. //汇款金额汇总统计
  168. function sendMoneyCount($where = '')
  169. {
  170. $data = array();
  171. $data['all_money'] = $this->where ('status', '<>', 2)->whereIn ('recharge_type', ['汇款', '汇款赠送'])->sum ('money');
  172. $data['success_money'] = $this->whereIn ('recharge_type', ['汇款', '汇款赠送'])->where ('status', 1)->sum ('money');
  173. $data['give_money'] = $this->whereIn ('recharge_type', ['汇款赠送'])->where ('status', 1)->sum ('money');
  174. $data['fail_money'] = $this->whereIn ('recharge_type', ['汇款'])->where ('status', 0)->sum ('money');
  175. if (!empty($where) && is_array ($where)) {
  176. $data['all_money'] = $this->where ($where)->where ('status', '<>', 2)->whereIn ('recharge_type', ['汇款', '汇款赠送'])->sum ('money');
  177. $data['success_money'] = $this->where ($where)->whereIn ('recharge_type', ['汇款', '汇款赠送'])->where ('status', 1)->sum ('money');
  178. $data['give_money'] = $this->where ($where)->whereIn ('recharge_type', ['汇款赠送'])->where ('status', 1)->sum ('money');
  179. $data['fail_money'] = $this->where ($where)->whereIn ('recharge_type', ['汇款'])->where ('status', 0)->sum ('money');
  180. }
  181. return $data;
  182. }
  183. //字段对应值
  184. private function getFeild($num)
  185. {
  186. $data = array(
  187. '1' => 'id',
  188. '2' => 'info_identity',
  189. '3' => 'order_id',
  190. '4' => 'account_name',
  191. '5' => 'account_identity',
  192. '6' => 'apply_time',
  193. '7' => 'completetime',
  194. '8' => 'recharge_type',
  195. '9' => 'sysetem_user',
  196. '10' => 'status',
  197. '11' => 'name',
  198. '12' => 'recharge_time',
  199. '13' => 'remark',
  200. );
  201. return $data[$num];
  202. }
  203. //最后一个存款时间
  204. function getLast($account_id)
  205. {
  206. $time = $this->select ('apply_time', 'money', 'recharge_type', 'account_name')->where ('account_identity', $account_id)->orderBy ('apply_time', 'desc')->first ();
  207. if (!$time) {
  208. return array();
  209. }
  210. return $time->toArray ();
  211. }
  212. /**
  213. * 添加充值数据
  214. * @param $data
  215. * @return int
  216. */
  217. function addMoney($data)
  218. {
  219. if (!$this->checkOrderID ($data['order_id'])) {
  220. return -3010126022; //订单号已存在
  221. }
  222. $this->account_name = $data['account_name'];
  223. $this->account_identity = $data['account_identity'];
  224. $this->money = $data['money'];
  225. $this->reason = $data['reason'];
  226. $this->sysetem_user = $data['sysetem_user'];
  227. $this->money_cash = $data['money_cash'];
  228. $this->recharge_type = $data['recharge_type'];
  229. $this->status = $data['status'];
  230. $this->info_identity = UUID ();
  231. $this->order_id = $data['order_id'];
  232. $this->apply_time = $data['apply_time'];
  233. $this->complete_time = $data['complete_time'];
  234. $this->remark = $data['remark'] ?? '后台充值';
  235. $this->rate = $data['rate'] ?? 1;
  236. $res = $this->save ();
  237. if (!$res) {
  238. return -3020011322; //加款失败
  239. }
  240. return $this->order_id;
  241. }
  242. //修改信息
  243. function updateInfo($data, $field, $value)
  244. {
  245. $res = $this->where ($field, $value)->update ($data);
  246. if ($res < 0) {
  247. return -3020100102; //操作失败
  248. }
  249. return 1;
  250. }
  251. //检测订单号
  252. function checkOrderID($order_id)
  253. {
  254. $res = $this->where ('order_id', $order_id)->first ();
  255. if (!$res) {
  256. return true;
  257. }
  258. return false;
  259. }
  260. //充值统计
  261. function totalRecharge($whereTime = '', $type)
  262. {
  263. if (is_array ($whereTime) && count ($whereTime) > 0) {
  264. $this->where ($whereTime)->where ('recharge_type', $type)->sum ('momney');
  265. }
  266. }
  267. //更新状态
  268. function updateStatus($order_id, $status)
  269. {
  270. $data = [
  271. 'status' => $status,
  272. 'complete_time' => date ('Y-m-d H:i:s'),
  273. 'sysetem_user' => session ('adminInfo.admin_name'),
  274. ];
  275. $res = $this->where ('order_id', $order_id)->update ($data);
  276. if (!$res) {
  277. return -5010050022; //状态更新失败
  278. }
  279. return 1;
  280. }
  281. function text()
  282. {
  283. $data = $this->select (DB::raw ('recharge_type'))->groupBy ('recharge_type')->get ();
  284. return $data->toArray ();
  285. }
  286. //获取待处理汇款详情
  287. function getRimitDetails($order_id)
  288. {
  289. $data = $this->where ('order_id', $order_id)->where ('status', 0)->first ();
  290. if (!$data) {
  291. return -3020035022; //汇款待审订单不存在或已处理
  292. }
  293. return $data->toArray ();
  294. }
  295. //汇款
  296. function countRimitUser($timearea)
  297. {
  298. $data = $this->select ('account_identity')->whereBetween ('apply_time', $timearea)->where ('recharge_type', '汇款')->groupBy ('account_identity')->get ();
  299. if (!$data) {
  300. return 0;
  301. }
  302. $data = $data->toArray ();
  303. return count ($data);
  304. }
  305. //加款检测
  306. function checkAdd($account_id, $money, $time)
  307. {
  308. $res = $this->where ('account_identity', $account_id)->where ('money', $money)
  309. ->where ('apply_time', '>', $time)->first ();
  310. if (!$res) {
  311. return 1;
  312. }
  313. return -5023809122;
  314. }
  315. }