|
|
|
@ -59,6 +59,7 @@ class AgentProductController extends AdminController |
|
|
|
$grid->column('price'); |
|
|
|
$grid->column('original_price'); |
|
|
|
$grid->column('sale'); |
|
|
|
$grid->column('stock'); |
|
|
|
|
|
|
|
$channels = Channel::where('agent_id', $agent_id)->pluck('name', 'id')->toArray(); |
|
|
|
$grid->column('channel_id', '频道') |
|
|
|
@ -115,6 +116,7 @@ class AgentProductController extends AdminController |
|
|
|
$show->field('price'); |
|
|
|
$show->field('original_price'); |
|
|
|
$show->field('sale'); |
|
|
|
$show->field('stock'); |
|
|
|
$show->field('channel_id'); |
|
|
|
$show->field('category_id'); |
|
|
|
$show->field('status')->using(ProductStatus::array()); |
|
|
|
@ -158,7 +160,7 @@ class AgentProductController extends AdminController |
|
|
|
$form->display('id'); |
|
|
|
$form->hidden('product_id'); |
|
|
|
$form->selectTable('product_id', '封面产品') |
|
|
|
->help('当多选产品时,产品列表显示的是该产品的标题和图片') |
|
|
|
->help('产品列表显示的是该产品的标题和图片') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
@ -174,6 +176,7 @@ class AgentProductController extends AdminController |
|
|
|
$form->text('price')->required(); |
|
|
|
$form->text('original_price')->required(); |
|
|
|
$form->text('sale')->default(0); |
|
|
|
$form->text('stock')->default(9999); |
|
|
|
|
|
|
|
$options = Channel::selectOptions(fn($query) => $query->where('agent_id', $agent_id)); |
|
|
|
$form->multipleSelect('channel_id')->options(array_slice($options, 1)); |
|
|
|
@ -214,7 +217,7 @@ class AgentProductController extends AdminController |
|
|
|
$agent_id = Admin::user()->id; |
|
|
|
|
|
|
|
//不允许编辑的字段
|
|
|
|
$form->ignore(['id', 'agent_id', 'created_at', 'updated_at', 'deleted_at']); |
|
|
|
$form->ignore(['id', 'agent_id', 'status', 'created_at', 'updated_at', 'deleted_at']); |
|
|
|
|
|
|
|
$product_ids = explode(',', $form->product_ids); |
|
|
|
if (empty($product_ids)) { |
|
|
|
@ -224,11 +227,14 @@ class AgentProductController extends AdminController |
|
|
|
//判断供应商产品是否存在或下架
|
|
|
|
$not_in_id = Product::query() |
|
|
|
->whereIn('id', $product_ids) |
|
|
|
->where('status', '<>', ProductStatus::ON_SALE) |
|
|
|
->where(function ($query) use ($form) { |
|
|
|
$query->where('status', '<>', ProductStatus::ON_SALE) |
|
|
|
->orWhere('stock', '<', $form->stock); |
|
|
|
}) |
|
|
|
->pluck('id') |
|
|
|
->toArray(); |
|
|
|
if ($not_in_id) { |
|
|
|
return $form->response()->error('产品ID'. join(',', $not_in_id) .'不存在或已下架,请重新选择'); |
|
|
|
return $form->response()->error('产品ID'. join(',', $not_in_id) .'不存在或已下架,或库存小于你设置的库存' . $form->stock); |
|
|
|
} |
|
|
|
|
|
|
|
//处理特殊字段
|
|
|
|
|