64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Forms;
|
|
|
|
use App\Models\AfterSale;
|
|
use Dcat\Admin\Contracts\LazyRenderable;
|
|
use Dcat\Admin\Traits\LazyWidget;
|
|
use Dcat\Admin\Widgets\Form;
|
|
|
|
class AfterSaleRevoke extends Form implements LazyRenderable
|
|
{
|
|
use LazyWidget;
|
|
|
|
/**
|
|
* 权限判断,如不需要可以删除此方法
|
|
*
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.after_sales.revoke');
|
|
}
|
|
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
$afterSale = AfterSale::findOrFail($this->payload['id']);
|
|
|
|
if ($afterSale->isCancelled()) {
|
|
return $this->response()->error('售后单已取消');
|
|
}
|
|
|
|
if ($afterSale->isFinished()) {
|
|
return $this->response()->error('售后单已完成');
|
|
}
|
|
|
|
$afterSale->update([
|
|
'state' => AfterSale::STATE_CANCEL,
|
|
'remarks' => $input['remarks'] ?? null,
|
|
]);
|
|
|
|
return $this->response()
|
|
->success(__('admin.update_succeeded'))
|
|
->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$this->text('remarks', '备注');
|
|
$this->confirm('是否关闭售后单?', '该操作不可逆,确认后将取消售后单。');
|
|
}
|
|
}
|