action refund
parent
68161a1e55
commit
2d3defd12f
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Order\Action\Refund;
|
||||
|
||||
use Dcat\Admin\Grid\RowAction;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
use Peidikeji\Order\Form\Refund\CheckForm;
|
||||
|
||||
class RowCheck extends RowAction
|
||||
{
|
||||
protected $title = '审核';
|
||||
|
||||
public function html()
|
||||
{
|
||||
$model = $this->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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Order\Action\Refund;
|
||||
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Peidikeji\Order\Enums\RefundStatus;
|
||||
use Peidikeji\Order\Form\Refund\CheckForm;
|
||||
|
||||
class ShowCheck extends AbstractTool
|
||||
{
|
||||
protected $style = 'btn btn-sm btn-danger';
|
||||
|
||||
protected $title = '审核';
|
||||
|
||||
public function html()
|
||||
{
|
||||
$model = $this->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('<button type="button" class="'.$this->style.'">'.$this->title.'</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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Order\Form\Refund;
|
||||
|
||||
use Dcat\Admin\Admin;
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Dcat\Admin\Contracts\LazyRenderable;
|
||||
use Dcat\Admin\Traits\LazyWidget;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Peidikeji\Order\Enums\RefundWay;
|
||||
use Peidikeji\Order\Models\OrderRefund;
|
||||
use Peidikeji\Order\RefundService;
|
||||
|
||||
class CheckForm extends Form implements LazyRenderable
|
||||
{
|
||||
use LazyWidget;
|
||||
|
||||
protected $buttons = ['reset' => 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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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' => [
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue