|
|
|
@ -5,7 +5,6 @@ namespace App\AdminAgent\Controllers; |
|
|
|
use App\AdminAgent\Renderable\SelectProduct; |
|
|
|
use App\AdminAgent\Repositories\AgentProduct; |
|
|
|
use App\Common\ProductStatus; |
|
|
|
use App\Common\Settlement; |
|
|
|
use App\Models\Category; |
|
|
|
use App\Models\Channel; |
|
|
|
use App\Models\Product; |
|
|
|
@ -113,7 +112,7 @@ class AgentProductController extends AdminController |
|
|
|
$show->field('sale'); |
|
|
|
$show->field('channel_id'); |
|
|
|
$show->field('category_id'); |
|
|
|
$show->field('status'); |
|
|
|
$show->field('status')->using(ProductStatus::array()); |
|
|
|
$show->field('created_at'); |
|
|
|
$show->field('updated_at'); |
|
|
|
|
|
|
|
@ -151,7 +150,15 @@ class AgentProductController extends AdminController |
|
|
|
$form->hidden('agent_id')->value($agent_id); |
|
|
|
$form->hidden('status')->value(ProductStatus::UNAUDITED); |
|
|
|
$form->hidden('product_id'); |
|
|
|
$form->multipleSelectTable('product_ids', '供应商产品') |
|
|
|
$form->multipleSelectTable('product_ids', '选择产品') |
|
|
|
->help('可多选组合销售') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
->model(Product::class) |
|
|
|
->required(); |
|
|
|
$form->selectTable('product_id', '封面产品') |
|
|
|
->help('当多选产品时,产品列表显示的是该产品的标题和图片') |
|
|
|
->title('选择产品') |
|
|
|
->dialogWidth('80%;min-width:825px;') |
|
|
|
->from(SelectProduct::make()) |
|
|
|
@ -169,9 +176,12 @@ class AgentProductController extends AdminController |
|
|
|
->options(array_slice($options, 1)) |
|
|
|
->required(); |
|
|
|
|
|
|
|
$form->radio('settlement') |
|
|
|
->options(Settlement::array()) |
|
|
|
->default(settlement::INSTANT) |
|
|
|
$form->radio('status') |
|
|
|
->default(ProductStatus::ON_SALE) |
|
|
|
->options([ |
|
|
|
ProductStatus::ON_SALE => '上架', |
|
|
|
ProductStatus::SOLD_OUT => '下架', |
|
|
|
]) |
|
|
|
->required(); |
|
|
|
})->saving(function (Form $form) { |
|
|
|
//不允许修改非自己的数据
|
|
|
|
@ -181,18 +191,27 @@ class AgentProductController extends AdminController |
|
|
|
|
|
|
|
$agent_id = Admin::user()->id; |
|
|
|
|
|
|
|
//判断供应商产品是否存在或下架
|
|
|
|
if (!Product::where(['id' => $form->product_id, 'status' => ProductStatus::ON_SALE])->exists()) { |
|
|
|
return $form->response()->error('供应商不存在该产品或已下架,不可销售'); |
|
|
|
} |
|
|
|
|
|
|
|
//不允许编辑的字段
|
|
|
|
$form->ignore(['id', 'agent_id', 'created_at', 'updated_at', 'deleted_at']); |
|
|
|
|
|
|
|
$product_ids = explode(',', $form->product_ids); |
|
|
|
if (empty($product_ids)) { |
|
|
|
return $form->response()->error('请选择产品'); |
|
|
|
} |
|
|
|
|
|
|
|
//判断供应商产品是否存在或下架
|
|
|
|
$not_in_id = Product::query() |
|
|
|
->whereIn('id', $product_ids) |
|
|
|
->where('status', '<>', ProductStatus::ON_SALE) |
|
|
|
->pluck('id') |
|
|
|
->toArray(); |
|
|
|
if ($not_in_id) { |
|
|
|
return $form->response()->error('产品ID'. join(',', $not_in_id) .'不存在或已下架,请重新选择'); |
|
|
|
} |
|
|
|
|
|
|
|
//处理特殊字段
|
|
|
|
$form->agent_id = $agent_id; |
|
|
|
$form->status = ProductStatus::UNAUDITED; |
|
|
|
$form->product_id = $form->product_ids[0]; |
|
|
|
$form->status = $form->status == ProductStatus::ON_SALE ? ProductStatus::ON_SALE : ProductStatus::SOLD_OUT; |
|
|
|
|
|
|
|
//判断是否重复发布产品
|
|
|
|
$where = [ |
|
|
|
|