6
0
Fork 0
jiqu-library-server/app/Admin/Forms/SkuVerify.php

70 lines
1.6 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 SkuVerify 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.verify');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
try {
DB::beginTransaction();
ProductSku::skuVerify([$input['sku_id']], (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()
{
$id = $this->payload['id'] ?? 0;
$verify = ProductSkuVerify::with('sku')->findOrFail($id);
$this->text('name')->value($verify->sku->name)->disable();
$this->radio('status')->options([
1 => '成功',
2 => '拒绝',
])->default(1);
$this->text('remarks');
$this->hidden('sku_id')->value($verify->sku_id);
}
}