66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Extensions\Grid\Tools\Product;
|
|
|
|
use App\Models\ProductSku;
|
|
use Dcat\Admin\Grid\BatchAction;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class BatchReleaseCancel extends BatchAction
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected $title = '<i class="feather icon-corner-up-left grid-action-icon"></i>';
|
|
|
|
public function title()
|
|
{
|
|
if ($this->title) {
|
|
return $this->title.' '.__('admin_message.extensions.grid.batch.release_cancel');
|
|
}
|
|
|
|
return __('admin_message.extensions.grid.batch.release_cancel');
|
|
}
|
|
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.product_skus.batch_release_cancel');
|
|
}
|
|
|
|
// 确认弹窗信息
|
|
public function confirm()
|
|
{
|
|
return '您确定操作已选中的商品吗?';
|
|
}
|
|
|
|
// 处理请求
|
|
public function handle(Request $request)
|
|
{
|
|
// 获取选中的skuID数组
|
|
$keys = $this->getKey();
|
|
$query = ProductSku::query()->whereIn('id', $keys)->where('verify_state', 1)->whereNull('release_at');
|
|
|
|
$list = $query->get();
|
|
if ($list->count() != count($keys)) {
|
|
return $this->response()->error('操作失败,所选商品含有不能操作项')->refresh();
|
|
}
|
|
|
|
$message = '操作成功';
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
ProductSku::releaseCancel($keys);
|
|
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
return $this->response()->error('操作失败,'.$th->getMessage())->refresh();
|
|
}
|
|
|
|
return $this->response()->success($message)->refresh();
|
|
}
|
|
}
|