| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\admin\controller\store;
- use app\common\controller\AdminController;
- use app\common\model\Users;
- use app\http\IResponse;
- use EasyWeChat\Factory;
- use GuzzleHttp\Exception\GuzzleException;
- use think\Db;
- class TaxiUserWithdraw extends AdminController
- {
- /**
- * 提现列表
- *
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = [];
- //组合搜索
- !empty(input('name')) && $where[]
- = ['name', 'like', '%' . input('name') . '%'];
- !empty(input('keyword')) && $where[]
- = ['mobile', 'like', '%'.input('keyword').'%'];
- $withdraw = model('common/TaxiUsersWithdraw');
- return IResponse::paginate($withdraw->where($where)->order(['created_at'=>'desc'])->with(['user','taxiUser'])
- ->paginate(input('limit'),false));
- }
- /**
- * 更新数据
- *
- * @param $id
- * @return \think\response\Json
- */
- public function update($id)
- {
- // 接收数据
- $params = $this->request->param();
- // 查询用户
- $withdraw = model('common/TaxiUsersWithdraw')->findBy($id);
- // 状态操作
- $valid = $this->validate($params, [
- 'status|配置参数' => 'require|integer'
- ]);
- // 错误返回
- (true !== $valid) && IResponse::failure($valid);
- // 更新信息
- $withdraw->updateBy($id, $params);
- Db::startTrans();
- try {
- // 通过
- $withdraw->status = $params['status'];
- $withdraw->remittance_time = $params['status'] ==20? time() : 0;
- $withdraw-> arrival_amount = $params['status'] ==20? $withdraw['amount'] : 0;
- if(!$withdraw->save()){
- Db::rollback();
- IResponse::failure('提现审核失败');
- }
- // 拒绝退款
- if($params['status'] == 30){
- // 查用户
- $user = model('common/Users')->getBy($withdraw['user_id']);
- if(empty($user)){
- Db::rollback();
- IResponse::failure('司机账户错误,请联系管理员处理');
- }
- // 写入资金记录
- $Users = new Users();
- $Users->changePartnership($user['id'], $withdraw['amount'], '资产提现失败退还', 20,true);
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollback();
- IResponse::failure('审核错误');
- }
- return IResponse::success('审核成功');
- }
- /**
- * 删除
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:26
- *
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- model('common/UsersWithdraw')->deleteBy($id);
- return IResponse::success([],'删除提现申请单成功');
- }
- /**
- * 用户批量操作
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/11 14:34
- *
- * @return mixed
- */
- public function plectron(){
- // 收参数
- $params = $this->request->param();
- foreach (str2arr($params['ids']) as $id){
- $withdraw = model('common/UsersWithdraw')->getBy($id);
- if ($this->request->isDelete()){
- $withdraw->deleteBy($id);
- }else
- // 等待审核状态下才做更新
- if ($withdraw['status'] == 1){
- $withdraw->allowField(true)->updateBy($id, $params);
- Db::startTrans();
- try {
- if ($params['status'] == 2){
- // 查用户
- $user = model('common/Users')->getBy($withdraw['user_id']);
- // 更新资金
- $user->where(['id' => $withdraw['user_id']])->setDec('balance', $withdraw['amount']);
- // 写入资金记录
- model('common/UsersBalanceRecord')::create([
- 'user_id' => $withdraw['user_id'],
- 'dec_amount' => $withdraw['amount'],
- 'aft_amount' => round($user['balance'] - $withdraw['amount']),
- 'remark' => '主动提现,¥' . $withdraw['amount'] . ',单号;' . $withdraw['draw_no']
- ], true);
- }
- Db::commit();
- }catch (\Exception $e){
- Db::rollback();
- }
- }
- }
- return IResponse::success([],'操作成功');
- }
- }
|