action = $action; //$action:1=通过;2=拒绝 switch ($action) { case 1: $this->title = '通过'; break; case 2: $this->title = '拒绝'; break; case 3: $this->title = '确认打款'; break; default: $this->title = '通过'; } } protected function html() { switch ($this->action) { case 1: $class = 'btn btn-sm btn-success'; break; case 2: $class = 'btn btn-sm btn-danger'; break; case 3: $class = 'btn btn-sm btn-info'; break; default: $class = 'btn btn-sm btn-success'; } $this->appendHtmlAttribute('class', $class); $this->defaultHtmlAttribute('href', 'javascript:;'); return "formatHtmlAttributes()}>{$this->title}"; } public function handle(Request $request) { DB::beginTransaction(); try { if ($request->action == 1) { //同意打款 $withdrawal = \App\Models\Withdrawal::find($this->getKey()); $withdrawal->status = WithdrawalTraits::$state[2]; } elseif ($request->action == 2) { //拒绝打款 $withdrawal = \App\Models\Withdrawal::find($this->getKey()); $withdrawal->status = WithdrawalTraits::$state[1]; //退回余额 if ($withdrawal->user_type == DemandTraits::$col[0]) { $user = Agent::query(); } elseif($withdrawal->user_type == DemandTraits::$col[1]) { $user = Supplier::query(); } elseif($withdrawal->user_type == DemandTraits::$col[2]) { $user = Guide::query(); } $user = $user->where('id', $withdrawal->user_id)->lockForUpdate()->first(); //退回提现的钱和手续费 $user->balance = bcadd($user->balance,bcadd($withdrawal->cut_price,$withdrawal->price,6),6); $user->save(); //流水 $service = new WithdrawalService(); //退余额 $service->create( $withdrawal->price, StatementType::REFUND, Admin::user()->id, $withdrawal->user_type, $withdrawal->id, StatementTraits::$type[1] ); //退手续费 $service->create( $withdrawal->cut_price, StatementType::REFUND, Admin::user()->id, $withdrawal->user_type, $withdrawal->id, StatementTraits::$type[1] ); } elseif ($request->action == 3) { //确认打款 $withdrawal = \App\Models\Withdrawal::find($this->getKey()); $withdrawal->status = WithdrawalTraits::$state[3]; } $withdrawal->save(); DB::commit(); return $this->response()->success("操作成功")->refresh(); } catch (\Exception $e) { return $this->response()->error($e->getMessage()); } } public function confirm() { return ['确定要'.$this->title.'本次提现吗?', '']; } public function parameters() { return ['action' => $this->action]; } }