83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Show;
|
|
|
|
use App\Models\AfterSale;
|
|
use App\Services\AfterSaleService;
|
|
use Dcat\Admin\Show\AbstractTool;
|
|
use Illuminate\Contracts\Auth\Authenticatable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class AfterSaleFinanceShipping extends AbstractTool
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected $title = '<i class="fa fa-exclamation-triangle icon-shuffle"></i> 确认发货';
|
|
|
|
/**
|
|
* 按钮样式定义,默认 btn btn-white waves-effect
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $style = 'btn btn-sm btn-danger';
|
|
|
|
/**
|
|
* 权限判断,如不需要可以删除此方法
|
|
*
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.after_sales.finance');
|
|
}
|
|
|
|
/**
|
|
* 处理请求,如果不需要接口处理,请直接删除这个方法
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
// 获取主键
|
|
$key = $this->getKey();
|
|
|
|
$afterSaleService = new AfterSaleService();
|
|
try {
|
|
DB::beginTransaction();
|
|
$afterSale = AfterSale::where('state', AfterSale::STATE_FINANCE)->findOrFail($key);
|
|
$afterSaleService->finance($afterSale, '同意换货');
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
return $this->response()->error('操作失败:'.$th->getMessage());
|
|
}
|
|
|
|
return $this->response()
|
|
->success(__('admin.update_succeeded'))
|
|
->refresh();
|
|
}
|
|
|
|
public function html()
|
|
{
|
|
return parent::html().' ';
|
|
}
|
|
|
|
/**
|
|
* 确认弹窗信息,如不需要可以删除此方法
|
|
*
|
|
* @return string|array|void
|
|
*/
|
|
public function confirm()
|
|
{
|
|
return ['是否确认发货?', '该操作不可逆,确认后将产生新的订单以及发货包裹单。'];
|
|
}
|
|
}
|