4
0
Fork 0
dcat-admin-order/src/Form/Refund/CheckForm.php

66 lines
2.2 KiB
PHP

<?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'],
];
}
}