TaxiUserWithdraw.php 4.9 KB

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