diff --git a/src/Action/Refund/RowCheck.php b/src/Action/Refund/RowCheck.php new file mode 100644 index 0000000..6b83468 --- /dev/null +++ b/src/Action/Refund/RowCheck.php @@ -0,0 +1,23 @@ +row; + + return Modal::make() + ->lg() + ->title($this->title) + ->body(CheckForm::make()->payload(['id' => $model->id, 'refund_reason' => $model->refund_reason, 'refund_money' => $model->refund_money, 'refund_way' => $model->refund_way])) + ->button($this->title); + } +} diff --git a/src/Action/Refund/ShowCheck.php b/src/Action/Refund/ShowCheck.php new file mode 100644 index 0000000..b73e0ff --- /dev/null +++ b/src/Action/Refund/ShowCheck.php @@ -0,0 +1,36 @@ +parent->model(); + return Modal::make() + ->lg() + ->title($this->title) + ->body(CheckForm::make()->payload(['id' => $model->id, 'refund_reason' => $model->refund_reason, 'refund_money' => $model->refund_money, 'refund_way' => $model->refund_way])) + ->button(''); + } + + protected function authorize($user): bool + { + return $user->can('dcat.admin.order_refunds.check'); + } + + public function allowed() + { + $model = $this->parent->model(); + return $model->refund_status === RefundStatus::Apply; + } +} diff --git a/src/Form/PayForm.php b/src/Form/PayForm.php index 0391034..b87de6c 100644 --- a/src/Form/PayForm.php +++ b/src/Form/PayForm.php @@ -38,7 +38,7 @@ class PayForm extends Form implements LazyRenderable $admin = Admin::user(); $order->options()->create([ - 'user_type' => Administrator::class, + 'user_type' => $admin->getMorphClass(), 'user_id' => $admin->id, 'description' => '管理员: ' . $admin->name . ' 支付订单', 'attribute' => $input, diff --git a/src/Form/Refund/CheckForm.php b/src/Form/Refund/CheckForm.php new file mode 100644 index 0000000..5e7e785 --- /dev/null +++ b/src/Form/Refund/CheckForm.php @@ -0,0 +1,65 @@ + false, 'submit' => true]; + + public function handle(array $input) + { + try { + DB::beginTransaction(); + $info = OrderRefund::findOrFail($this->payload['id']); + $order = $info->order; + + $status = !!$input['status']; + RefundService::make()->handle($info, $status, $input['reason']); + + $admin = Admin::user(); + $order->options()->create([ + 'user_type' => $admin->getMorphClass(), + 'user_id' => $admin->id, + 'description' => '管理员: ' . $admin->name . ($status ? '同意' : '拒绝了') . ' 了订单的退款申请', + 'attribute' => $input, + ]); + DB::commit(); + return $this->response()->success('操作成功')->refresh(); + } catch (\Exception $e) { + DB::rollBack(); + return $this->response()->error($e->getMessage()); + } + } + + public function form() + { + $this->display('refund_reason', __('dcat-admin-order::refund.fields.refund_reason')); + $this->display('refund_money', __('dcat-admin-order::refund.fields.refund_money')); + $this->display('refund_way', __('dcat-admin-order::refund.fields.refund_way'))->with(function ($v) { + return RefundWay::from(intval($v))->label(); + }); + $this->radio('status', '结果')->options(['1' => '通过', '0' => '不通过']); + $this->text('reason', __('dcat-admin-order::refund.fields.refund_reason'))->help('未通过审核的原因'); + } + + public function default() + { + return [ + 'status' => '1', + 'refund_money' => $this->payload['refund_money'], + 'refund_reason' => $this->payload['refund_reason'], + 'refund_way' => $this->payload['refund_way'], + ]; + } +} diff --git a/src/Form/RemarksForm.php b/src/Form/RemarksForm.php index 2171774..9911967 100644 --- a/src/Form/RemarksForm.php +++ b/src/Form/RemarksForm.php @@ -24,7 +24,7 @@ class RemarksForm extends Form implements LazyRenderable $admin = Admin::user(); $order->options()->create([ - 'user_type' => get_class($admin), + 'user_type' => $admin->getMorphClass(), 'user_id' => $admin->id, 'description' => '管理员: ' . $admin->name . ' 修改系统备注', 'attribute' => [ diff --git a/src/Form/ShipForm.php b/src/Form/ShipForm.php index ffba9fc..bd60f03 100644 --- a/src/Form/ShipForm.php +++ b/src/Form/ShipForm.php @@ -41,7 +41,7 @@ class ShipForm extends Form implements LazyRenderable $admin = Admin::user(); $order->options()->create([ - 'user_type' => get_class($admin), + 'user_type' => $admin->getMorphClass(), 'user_id' => $admin->id, 'description' => '管理员: ' . $admin->name . ' 发货', 'attribute' => $input, diff --git a/src/Http/Admin/RefundController.php b/src/Http/Admin/RefundController.php index 01454c7..c81a031 100644 --- a/src/Http/Admin/RefundController.php +++ b/src/Http/Admin/RefundController.php @@ -13,6 +13,8 @@ use Dcat\Admin\Grid\Displayers\Actions; use Peidikeji\Order\Enums\RefundStatus; use Peidikeji\Order\Enums\RefundWay; use Peidikeji\Order\Models\OrderRefund; +use Peidikeji\Order\Action\Refund\RowCheck; +use Peidikeji\Order\Action\Refund\ShowCheck; class RefundController extends AdminController { @@ -59,6 +61,9 @@ class RefundController extends AdminController $grid->actions(function (Actions $actions) use ($user) { $row = $actions->row; $actions->edit($row->refund_status === RefundStatus::Apply && $user->can('dcat.admin.order_refunds.edit')); + if ($user->can('dcat.admin.order_refunds.check') && $row->refund_status === RefundStatus::Apply) { + $actions->append(new RowCheck()); + } }); }); } @@ -78,6 +83,8 @@ class RefundController extends AdminController $show->disableDeleteButton(); $show->disableEditButton(); + + $show->tools(new ShowCheck()); }); } diff --git a/src/Models/Order.php b/src/Models/Order.php index ea7f097..e299a00 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -129,6 +129,13 @@ class Order extends Model return false; } + if ($this->refund_status !== RefundStatus::None) { + if ($throw) { + throw new OrderException('订单退款处理中, 无法取消'); + } + return false; + } + return true; } diff --git a/src/RefundService.php b/src/RefundService.php index 91ee461..9eadf9d 100644 --- a/src/RefundService.php +++ b/src/RefundService.php @@ -97,7 +97,8 @@ class RefundService $order = $info->order; if ($order) { - $order->increment('refund_money', $info->refund_money, ['refund_status' => RefundStatus::Success]); + $attributes = ['refund_status' => RefundStatus::Success]; + $order->increment('refund_money', $info->refund_money, $attributes); } }