68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Actions\Grid;
|
|
|
|
use App\Models\ProductSku;
|
|
use Dcat\Admin\Actions\Response;
|
|
use Dcat\Admin\Grid\RowAction;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Throwable;
|
|
|
|
class SkuSyncSpu extends RowAction
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
protected $title = '<i class="feather icon-rotate-cw grid-action-icon"></i>';
|
|
|
|
public function title()
|
|
{
|
|
if ($this->title) {
|
|
return $this->title.' '.__('admin_message.actions.grid.sku_sync_spu');
|
|
}
|
|
|
|
return __('admin_message.actions.grid.sku_sync_spu');
|
|
}
|
|
|
|
/**
|
|
* @param Model|Authenticatable|HasPermissions|null $user
|
|
*
|
|
* @return bool
|
|
*/
|
|
protected function authorize($user): bool
|
|
{
|
|
return $user->can('dcat.admin.product_skus.sku_sync_spu');
|
|
}
|
|
|
|
/**
|
|
* Handle the action request.
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
ProductSku::syncSpuById($this->getKey());
|
|
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 ['确认当前商品同步主商品信息?'];
|
|
}
|
|
}
|