69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace App\Admin\Forms;
|
||
|
||
use App\Models\ProductSku;
|
||
use App\Models\ProductSkuVerify;
|
||
use Dcat\Admin\Contracts\LazyRenderable;
|
||
use Dcat\Admin\Traits\LazyWidget;
|
||
use Dcat\Admin\Widgets\Form;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Throwable;
|
||
|
||
class SkuVerifyBatch extends Form implements LazyRenderable
|
||
{
|
||
use LazyWidget;
|
||
|
||
/**
|
||
* 是否有权限判断.
|
||
*
|
||
* @param Model|Authenticatable|HasPermissions|null $user
|
||
* @return bool
|
||
*/
|
||
protected function authorize($user): bool
|
||
{
|
||
return $user->can('dcat.admin.product_sku_verifies.batch_verify');
|
||
}
|
||
|
||
/**
|
||
* Handle the form request.
|
||
*
|
||
* @param array $input
|
||
*
|
||
* @return mixed
|
||
*/
|
||
public function handle(array $input)
|
||
{
|
||
$ids = explode(',', $input['id'] ?? null);
|
||
$skuIds = ProductSkuVerify::find($ids)->pluck('sku_id')->toArray();
|
||
try {
|
||
DB::beginTransaction();
|
||
ProductSku::skuVerify($skuIds, (int) $input['status'], $input['remarks']);
|
||
DB::commit();
|
||
} catch (Throwable $th) {
|
||
DB::rollBack();
|
||
report($th);
|
||
return $this->response()->error('操作失败:'.$th->getMessage());
|
||
}
|
||
|
||
return $this->response()
|
||
->success(__('admin.update_succeeded'))
|
||
->refresh();
|
||
}
|
||
|
||
/**
|
||
* Build a form here.
|
||
*/
|
||
public function form()
|
||
{
|
||
$this->radio('status')->options([
|
||
1 => '成功',
|
||
2 => '拒绝',
|
||
])->default(1);
|
||
$this->text('remarks');
|
||
|
||
// 设置隐藏表单,传递用户id
|
||
$this->hidden('id')->attribute('id', 'verify-sku-id');
|
||
}
|
||
}
|