撤销售后单
parent
17caae4370
commit
d59468ee70
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Actions\Show;
|
||||
|
||||
use App\Admin\Forms\AfterSaleRevoke as AfterSaleRevokeForm;
|
||||
use Dcat\Admin\Show\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
|
||||
class AfterSaleRevoke extends AbstractTool
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected $title = '<i class="feather icon-x-circle"></i> 撤销';
|
||||
|
||||
/**
|
||||
* 按钮样式定义,默认 btn btn-white waves-effect
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $style = 'btn-danger';
|
||||
|
||||
public function render()
|
||||
{
|
||||
$form = AfterSaleRevokeForm::make()->payload(['id'=>$this->getKey()]);
|
||||
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->title($this->title)
|
||||
->body($form)
|
||||
->button("<a href=\"javascript:void(0)\" class=\"btn btn-sm {$this->style}\">{$this->title}</a> ");
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Admin\Controllers;
|
|||
use App\Admin\Actions\Grid\AfterSaleSetTag;
|
||||
use App\Admin\Actions\Show\AfterSaleFinance;
|
||||
use App\Admin\Actions\Show\AfterSaleFinanceShipping;
|
||||
use App\Admin\Actions\Show\AfterSaleRevoke;
|
||||
use App\Admin\Actions\Show\AfterSaleShipping;
|
||||
use App\Admin\Actions\Show\AfterSaleShippingFail;
|
||||
use App\Admin\Actions\Show\AfterSaleShippingFill;
|
||||
|
|
@ -221,6 +222,11 @@ class AfterSaleController extends AdminController
|
|||
$tools->append(new AfterSaleFinanceShipping());
|
||||
}
|
||||
}
|
||||
|
||||
if (! in_array($show->model()->state, [AfterSaleModel::STATE_FINISH, AfterSaleModel::STATE_CANCEL]) &&
|
||||
Admin::user()->can('dcat.admin.after_sales.revoke')) {
|
||||
$tools->append(new AfterSaleRevoke());
|
||||
}
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
<?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('是否关闭售后单?', '该操作不可逆,确认后将取消售后单。');
|
||||
}
|
||||
}
|
||||
|
|
@ -146,7 +146,17 @@ class AfterSale extends Model
|
|||
*/
|
||||
public function isCancelled(): bool
|
||||
{
|
||||
return $this->status === static::STATE_CANCEL;
|
||||
return $this->state === static::STATE_CANCEL;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认此售后单是否已完成
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFinished(): bool
|
||||
{
|
||||
return $this->state === static::STATE_FINISH;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -180,20 +190,6 @@ class AfterSale extends Model
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消售后订单日志
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createCancelLog()
|
||||
{
|
||||
$this->logs()->create([
|
||||
'after_sale_id' => $this->id,
|
||||
'name' => '取消申请',
|
||||
'desc' => '用户取消售后申请',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成售后订单日志
|
||||
*
|
||||
|
|
@ -222,7 +218,11 @@ class AfterSale extends Model
|
|||
parent::saved(function ($afterSale) {
|
||||
//如果取消订单
|
||||
if ($afterSale->state == self::STATE_CANCEL) {
|
||||
$afterSale->createCancelLog();
|
||||
$afterSale->logs()->create([
|
||||
'after_sale_id' => $afterSale->id,
|
||||
'name' => '取消申请',
|
||||
'desc' => $afterSale->remarks,
|
||||
]);
|
||||
$afterSale->orderProduct->update([
|
||||
'after_sale_state'=>0,
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'shipping'=>['name' =>'确认收货'],
|
||||
'finances'=>['name' =>'售后打款'],
|
||||
'finance'=>['name' =>'确认打款'],
|
||||
'revoke'=>['name' =>'撤销'],
|
||||
'tags'=>['name' =>'标签设置'],
|
||||
],
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue