TaxiUserWithdraw.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace app\admin\controller\store;
  3. use app\common\controller\AdminController;
  4. use app\common\model\Users;
  5. use app\http\IResponse;
  6. use EasyWeChat\Factory;
  7. use GuzzleHttp\Exception\GuzzleException;
  8. use think\Db;
  9. class TaxiUserWithdraw extends AdminController
  10. {
  11. /**
  12. * 提现列表
  13. *
  14. * @return mixed
  15. * @throws \think\exception\DbException
  16. */
  17. public function index()
  18. {
  19. $where = [];
  20. //组合搜索
  21. !empty(input('name')) && $where[]
  22. = ['name', 'like', '%' . input('name') . '%'];
  23. !empty(input('keyword')) && $where[]
  24. = ['mobile', 'like', '%'.input('keyword').'%'];
  25. $withdraw = model('common/TaxiUsersWithdraw');
  26. $list = $withdraw->where($where)->order(['created_at'=>'desc'])->with(['user','taxiUser'])
  27. ->paginate(input('limit'),false);
  28. //return IResponse::paginate();
  29. return IResponse::success([
  30. 'total' => $list->total(),
  31. 'counts' => [
  32. 'wait'=>$withdraw->where($where)->where(['status'=>10])->order(['created_at'=>'desc'])->sum('amount'),
  33. 'success'=>$withdraw->where($where)->where(['status'=>20])->order(['created_at'=>'desc'])->sum('amount')
  34. ],
  35. 'list' => $list->getCollection(),
  36. ]);
  37. }
  38. /**
  39. * 更新数据
  40. *
  41. * @param $id
  42. * @return \think\response\Json
  43. */
  44. public function update($id)
  45. {
  46. // 接收数据
  47. $params = $this->request->param();
  48. // 查询用户
  49. $withdraw = model('common/TaxiUsersWithdraw')->findBy($id);
  50. // 状态操作
  51. $valid = $this->validate($params, [
  52. 'status|配置参数' => 'require|integer'
  53. ]);
  54. // 错误返回
  55. (true !== $valid) && IResponse::failure($valid);
  56. // 更新信息
  57. $withdraw->updateBy($id, $params);
  58. Db::startTrans();
  59. try {
  60. // 通过
  61. $withdraw->status = $params['status'];
  62. $withdraw->remittance_time = $params['status'] ==20? time() : 0;
  63. $withdraw-> arrival_amount = $params['status'] ==20? $withdraw['amount'] : 0;
  64. if(!$withdraw->save()){
  65. Db::rollback();
  66. IResponse::failure('提现审核失败');
  67. }
  68. // 拒绝退款
  69. if($params['status'] == 30){
  70. // 查用户
  71. $user = model('common/Users')->getBy($withdraw['user_id']);
  72. if(empty($user)){
  73. Db::rollback();
  74. IResponse::failure('司机账户错误,请联系管理员处理');
  75. }
  76. // 写入资金记录
  77. $Users = new Users();
  78. $Users->changePartnership($user['id'], $withdraw['amount'], '资产提现失败退还', 20,true);
  79. }
  80. Db::commit();
  81. } catch (\Exception $e) {
  82. Db::rollback();
  83. IResponse::failure('审核错误');
  84. }
  85. return IResponse::success('审核成功');
  86. }
  87. /**
  88. * 删除
  89. *
  90. * @author 许祖兴 < zuxing.xu@lettered.cn>
  91. * @date 2020/6/11 14:26
  92. *
  93. * @param $id
  94. * @return \think\response\Json
  95. */
  96. public function delete($id)
  97. {
  98. model('common/UsersWithdraw')->deleteBy($id);
  99. return IResponse::success([],'删除提现申请单成功');
  100. }
  101. /**
  102. * 用户批量操作
  103. *
  104. * @author 许祖兴 < zuxing.xu@lettered.cn>
  105. * @date 2020/6/11 14:34
  106. *
  107. * @return mixed
  108. */
  109. public function plectron(){
  110. // 收参数
  111. $params = $this->request->param();
  112. foreach (str2arr($params['ids']) as $id){
  113. $withdraw = model('common/UsersWithdraw')->getBy($id);
  114. if ($this->request->isDelete()){
  115. $withdraw->deleteBy($id);
  116. }else
  117. // 等待审核状态下才做更新
  118. if ($withdraw['status'] == 1){
  119. $withdraw->allowField(true)->updateBy($id, $params);
  120. Db::startTrans();
  121. try {
  122. if ($params['status'] == 2){
  123. // 查用户
  124. $user = model('common/Users')->getBy($withdraw['user_id']);
  125. // 更新资金
  126. $user->where(['id' => $withdraw['user_id']])->setDec('balance', $withdraw['amount']);
  127. // 写入资金记录
  128. model('common/UsersBalanceRecord')::create([
  129. 'user_id' => $withdraw['user_id'],
  130. 'dec_amount' => $withdraw['amount'],
  131. 'aft_amount' => round($user['balance'] - $withdraw['amount']),
  132. 'remark' => '主动提现,¥' . $withdraw['amount'] . ',单号;' . $withdraw['draw_no']
  133. ], true);
  134. }
  135. Db::commit();
  136. }catch (\Exception $e){
  137. Db::rollback();
  138. }
  139. }
  140. }
  141. return IResponse::success([],'操作成功');
  142. }
  143. }