From 76b1da090706ce718f76bf7f77a731bfe3bb3666 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Thu, 20 Jan 2022 14:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0=E6=89=93?= =?UTF-8?q?=E6=AC=BE=E5=8A=A8=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Actions/Show/DealerEarningPay.php | 32 +++++++++ .../Controllers/DealerEarningController.php | 9 ++- app/Admin/Forms/DealerEarningPay.php | 71 +++++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 app/Admin/Actions/Show/DealerEarningPay.php create mode 100644 app/Admin/Forms/DealerEarningPay.php diff --git a/app/Admin/Actions/Show/DealerEarningPay.php b/app/Admin/Actions/Show/DealerEarningPay.php new file mode 100644 index 00000000..8250a1fb --- /dev/null +++ b/app/Admin/Actions/Show/DealerEarningPay.php @@ -0,0 +1,32 @@ + 打款'; + + /** + * 按钮样式定义,默认 btn btn-white waves-effect + * + * @var string + */ + protected $style = 'btn-danger'; + + public function render() + { + $form = DealerEarningPayForm::make()->payload(['id'=>$this->getKey()]); + return Modal::make() + ->lg() + ->title($this->title) + ->body($form) + ->button("style}\">{$this->title}  "); + } +} diff --git a/app/Admin/Controllers/DealerEarningController.php b/app/Admin/Controllers/DealerEarningController.php index b7e0152f..6124c04b 100644 --- a/app/Admin/Controllers/DealerEarningController.php +++ b/app/Admin/Controllers/DealerEarningController.php @@ -2,7 +2,9 @@ namespace App\Admin\Controllers; +use App\Admin\Actions\Show\DealerEarningPay; use App\Admin\Repositories\DealerEarning; +use App\Enums\DealerEarningStatus; use App\Models\DealerChannelSubsidyLog; use App\Models\DealerEarning as DealerEarningModel; use App\Models\DealerManagerSalesLog; @@ -120,7 +122,7 @@ class DealerEarningController extends AdminController $show->field('payer.phone', '打款人')->as(function () { return $this->payer_id ? $this->payer?->phone : '公司'; }); - $show->field('pay_image'); + $show->field('pay_image')->image(); // $show->field('pay_info'); $show->field('pay_at'); $show->field('settle_at'); @@ -178,6 +180,11 @@ class DealerEarningController extends AdminController ->tools(function (Show\Tools $tools) use ($show) { $tools->disableEdit(); $tools->disableDelete(); + if ($show->model()->status == DealerEarningStatus::Pending) { + if (!$show->model()->payer_id || $show->model()->payer_id == 1) { + $tools->append(new DealerEarningPay()); + } + } }); })); }); diff --git a/app/Admin/Forms/DealerEarningPay.php b/app/Admin/Forms/DealerEarningPay.php new file mode 100644 index 00000000..ea3371f2 --- /dev/null +++ b/app/Admin/Forms/DealerEarningPay.php @@ -0,0 +1,71 @@ +can('dcat.admin.dealer_earnings.pay'); + } + + /** + * Handle the form request. + * + * @param array $input + * + * @return mixed + */ + public function handle(array $input) + { + $id = $this->payload['id'] ?? 0; + + try { + DB::beginTransaction(); + $earning = DealerEarning::findOrFail($id); + $earning->update([ + 'pay_info' => $earning->getPayInfo(), + 'pay_image' => $input['pay_image']??null, + 'pay_at' => now(), + 'status' => DealerEarningStatus::Completed, + ]); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + return $this->response()->error('操作失败:'.$th->getMessage()); + } + + return $this->response() + ->success(__('admin.update_succeeded')) + ->refresh(); + } + + /** + * Build a form here. + */ + public function form() + { + $this->image('pay_image') + ->move('dealer-pay/'.Carbon::now()->toDateString()) + ->saveFullUrl() + ->removable(false) + ->autoUpload(); + } +}