58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Grid;
|
|
|
|
use App\Admin\Forms\OrderClose as OrderCloseForm;
|
|
use App\Exceptions\BizException;
|
|
use App\Models\OfflineOrder;
|
|
use App\Services\OfflineOrderService;
|
|
use Dcat\Admin\Grid\RowAction;
|
|
use Dcat\Admin\Widgets\Modal;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class OfflineOrderRevoke extends RowAction
|
|
{
|
|
public function title()
|
|
{
|
|
return '<i class="feather icon-x grid-action-icon"></i> 取消订单';
|
|
}
|
|
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.offline_orders.revoke');
|
|
}
|
|
|
|
public function handle(Request $request)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
$order = OfflineOrder::lockForUpdate()->findOrFail($this->getKey());
|
|
|
|
if (! $order->isPending()) {
|
|
throw new BizException('订单状态已更新');
|
|
}
|
|
|
|
(new OfflineOrderService())->revoke($order);
|
|
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
|
}
|
|
|
|
return $this->response()->success('操作成功')->refresh();
|
|
}
|
|
|
|
/**
|
|
* @return string|array|void
|
|
*/
|
|
public function confirm()
|
|
{
|
|
return ['是否取消选中订单?'];
|
|
}
|
|
}
|