From 6e2f156145ebd054a09d5b0e716a79b19ee46016 Mon Sep 17 00:00:00 2001 From: lemon <15040771@qq.com> Date: Mon, 13 Sep 2021 01:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=BB=E5=90=8E=E5=8F=B0=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WithdrawalController.php | 63 ++++++++++ app/Admin/Extensions/Grid/Withdrawal.php | 113 ++++++++++++++++++ app/Admin/Repositories/Withdrawal.php | 16 +++ app/Admin/routes.php | 2 + app/Models/Agent.php | 5 + app/Models/Guide.php | 5 + app/Models/Supplier.php | 5 + app/Models/Withdrawal.php | 5 + 8 files changed, 214 insertions(+) create mode 100755 app/Admin/Controllers/WithdrawalController.php create mode 100644 app/Admin/Extensions/Grid/Withdrawal.php create mode 100755 app/Admin/Repositories/Withdrawal.php diff --git a/app/Admin/Controllers/WithdrawalController.php b/app/Admin/Controllers/WithdrawalController.php new file mode 100755 index 0000000..2bf5810 --- /dev/null +++ b/app/Admin/Controllers/WithdrawalController.php @@ -0,0 +1,63 @@ +disableActions(); + //$grid->disable(); + $grid->column('id')->sortable(); + $grid->column('price','提现金额'); + $grid->column('user.name','用户名称'); + $grid->column('pay_type','提现方式')->using(WithdrawalTraits::$userTypeText); + $grid->column('status','状态') + ->if(fn() => $this->status == WithdrawalTraits::$state[0]) + ->display('') + ->then(function ($column) { + $column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 1))->setKey($this->id))->append(' '); + $column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 2))->setKey($this->id)); + }) + ->if(fn() => $this->status == WithdrawalTraits::$state[2]) + ->display('') + ->then(function ($column) { + $column->append((new \App\Admin\Extensions\Grid\Withdrawal(null, 3))->setKey($this->id))->append(' '); + }) + ->if(fn() => $this->status == WithdrawalTraits::$state[1] || $this->status == WithdrawalTraits::$state[3]) + ->then(function ($column) { + $column->using(WithdrawalTraits::$stateText)->dot([ + + 1 => Admin::color()->yellow(), + 2 => 'danger', + 3 => Admin::color()->info(), + 4 => 'success', + + ]); + }); + $grid->column('created_at'); + $grid->column('updated_at')->sortable(); + $grid->disableCreateButton(); + $grid->disableRowSelector(); + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id')->width(3); + $filter->equal('status','状态')->select(WithdrawalTraits::$stateTextSelect)->width(2); + }); + }); + } + +} diff --git a/app/Admin/Extensions/Grid/Withdrawal.php b/app/Admin/Extensions/Grid/Withdrawal.php new file mode 100644 index 0000000..7381250 --- /dev/null +++ b/app/Admin/Extensions/Grid/Withdrawal.php @@ -0,0 +1,113 @@ +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) + { + 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,$withdrawal->price,6); + $user->save(); + } elseif ($request->action == 3) { + //确认打款 + $withdrawal = \App\Models\Withdrawal::find($this->getKey()); + $withdrawal->status = WithdrawalTraits::$state[3]; + } + + $withdrawal->save(); + + 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]; + } +} diff --git a/app/Admin/Repositories/Withdrawal.php b/app/Admin/Repositories/Withdrawal.php new file mode 100755 index 0000000..9550a35 --- /dev/null +++ b/app/Admin/Repositories/Withdrawal.php @@ -0,0 +1,16 @@ +resource('mini_program/draft', 'MiniProgramDraftController'); $router->resource('mini_program/template', 'MiniProgramTemplateController'); $router->resource('mini_program/list', 'MiniProgramListController'); + + $router->resource('withdrawal', 'WithdrawalController'); }); diff --git a/app/Models/Agent.php b/app/Models/Agent.php index ab8a6ed..457873d 100644 --- a/app/Models/Agent.php +++ b/app/Models/Agent.php @@ -59,4 +59,9 @@ class Agent extends BaseModel { return $this->morphMany('App\Models\Statement', 'user'); } + + public function withdrawal() + { + return $this->morphOne('App\Models\Withdrawal', 'user'); + } } diff --git a/app/Models/Guide.php b/app/Models/Guide.php index bd41196..308681d 100644 --- a/app/Models/Guide.php +++ b/app/Models/Guide.php @@ -48,4 +48,9 @@ class Guide extends BaseModel return $this->morphMany('App\Models\Statement', 'user'); } + + public function withdrawal() + { + return $this->morphOne('App\Models\Withdrawal', 'user'); + } } diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 21375cf..3aded00 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -59,4 +59,9 @@ class Supplier extends BaseModel { return $this->morphMany('App\Models\Statement', 'user'); } + + public function withdrawal() + { + return $this->morphOne('App\Models\Withdrawal', 'user'); + } } diff --git a/app/Models/Withdrawal.php b/app/Models/Withdrawal.php index a294cad..60aa45c 100755 --- a/app/Models/Withdrawal.php +++ b/app/Models/Withdrawal.php @@ -17,4 +17,9 @@ class Withdrawal extends Model { return $this->morphTo(); } + + public function user() + { + return $this->morphTo(); + } }