|
|
@ -196,8 +196,8 @@ class AgentProductController extends AdminController |
|
|
$form->editor('know'); |
|
|
$form->editor('know'); |
|
|
$form->editor('content'); |
|
|
$form->editor('content'); |
|
|
} else { |
|
|
} else { |
|
|
if ($form->isCreating()) { |
|
|
|
|
|
$form->hidden('type')->value(0); |
|
|
$form->hidden('type')->value(0); |
|
|
|
|
|
if ($form->isCreating()) { |
|
|
$js = file_get_contents(resource_path('js/select-supplier-product-change.js')); |
|
|
$js = file_get_contents(resource_path('js/select-supplier-product-change.js')); |
|
|
$class = str_replace('\\', '\\\\', LoadSupplierSpec::class); |
|
|
$class = str_replace('\\', '\\\\', LoadSupplierSpec::class); |
|
|
$js = str_replace( |
|
|
$js = str_replace( |
|
|
@ -225,9 +225,11 @@ class AgentProductController extends AdminController |
|
|
$form->date('supplier_date', '日期')->disable()->customFormat(fn() => $this->product_spec['date'] ?? '供应商已删除规格'); |
|
|
$form->date('supplier_date', '日期')->disable()->customFormat(fn() => $this->product_spec['date'] ?? '供应商已删除规格'); |
|
|
$form->text('supplier_stock', '供应商库存')->disable()->customFormat(fn() => $this->product_spec['stock'] ?? 0); |
|
|
$form->text('supplier_stock', '供应商库存')->disable()->customFormat(fn() => $this->product_spec['stock'] ?? 0); |
|
|
$form->text('supplier_price', '供应商价')->disable()->customFormat(fn() => $this->product_spec['price'] ?? 0); |
|
|
$form->text('supplier_price', '供应商价')->disable()->customFormat(fn() => $this->product_spec['price'] ?? 0); |
|
|
$form->text('stock', '您的库存')->customFormat(fn() => isset($this->product_spec['stock'], $this->stock) && $this->stock > $this->product_spec['stock'] ? $this->product_spec['stock'] : $this->stock); |
|
|
|
|
|
$form->text('original_price', '您的原价'); |
|
|
|
|
|
$form->text('price', '您的售价'); |
|
|
|
|
|
|
|
|
$form->text('stock', '您的库存')->required() |
|
|
|
|
|
//如果库存大于供应商库存,则取供应商库存
|
|
|
|
|
|
->customFormat(fn() => isset($this->product_spec['stock'], $this->stock) && $this->stock > $this->product_spec['stock'] ? $this->product_spec['stock'] : $this->stock); |
|
|
|
|
|
$form->text('original_price', '您的原价')->required(); |
|
|
|
|
|
$form->text('price', '您的售价')->required(); |
|
|
Admin::style('.has-many-spec .add.btn{display:none;} |
|
|
Admin::style('.has-many-spec .add.btn{display:none;} |
|
|
.has-many-spec .field_date{width:100px!important;} |
|
|
.has-many-spec .field_date{width:100px!important;} |
|
|
.has-many-spec .col-md-12{padding:0;} |
|
|
.has-many-spec .col-md-12{padding:0;} |
|
|
@ -238,8 +240,8 @@ class AgentProductController extends AdminController |
|
|
$js = file_get_contents(resource_path('js/agent-spec-edit.js')); |
|
|
$js = file_get_contents(resource_path('js/agent-spec-edit.js')); |
|
|
$class = str_replace('\\', '\\\\', LoadSupplierSpec::class); |
|
|
$class = str_replace('\\', '\\\\', LoadSupplierSpec::class); |
|
|
$js = str_replace( |
|
|
$js = str_replace( |
|
|
['`{{url}}`', '`{{class}}`'], |
|
|
|
|
|
[route(admin_api_route_name('form')), $class], |
|
|
|
|
|
|
|
|
['`{{url}}`', '`{{class}}`', '`{{product_id}}`', '`{{agent_product_id}}`'], |
|
|
|
|
|
[route(admin_api_route_name('form')), $class, $form->model()->product_id, $form->model()->id], |
|
|
$js |
|
|
$js |
|
|
); |
|
|
); |
|
|
Admin::script($js); |
|
|
Admin::script($js); |
|
|
@ -373,12 +375,11 @@ class AgentProductController extends AdminController |
|
|
|
|
|
|
|
|
if ($form->stock !== null || $form->status !== null) { |
|
|
if ($form->stock !== null || $form->status !== null) { |
|
|
$ids = explode(',', $form->model()->product_ids); |
|
|
$ids = explode(',', $form->model()->product_ids); |
|
|
$count = Product::where([ |
|
|
|
|
|
['status', '=', ProductStatus::ON_SALE], |
|
|
|
|
|
['stock', '>=', $form->stock ?? $form->model()->stock], |
|
|
|
|
|
])->whereIn('id', $ids)->count(); |
|
|
|
|
|
if (count($ids) != $count) { |
|
|
|
|
|
return $form->response()->error('供应商产品已下架或库存小于你设置的库存' . $form->stock)->refresh(); |
|
|
|
|
|
|
|
|
$exists = Product::where([ |
|
|
|
|
|
['status', '<>', ProductStatus::ON_SALE], |
|
|
|
|
|
])->whereIn('id', $ids)->exists(); |
|
|
|
|
|
if ($exists) { |
|
|
|
|
|
return $form->response()->error('供应商产品已下架')->refresh(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//修改库存
|
|
|
//修改库存
|
|
|
@ -439,7 +440,7 @@ class AgentProductController extends AdminController |
|
|
//将供应商产品写入title,pictures,know,content
|
|
|
//将供应商产品写入title,pictures,know,content
|
|
|
$product = Product::find($form->product_id); |
|
|
$product = Product::find($form->product_id); |
|
|
if ($product->status != ProductStatus::ON_SALE) { |
|
|
if ($product->status != ProductStatus::ON_SALE) { |
|
|
return $form->response()->error('产品ID '. $form->product_id .' 已下架'); |
|
|
|
|
|
|
|
|
return $form->response()->error('供应商产品 '. $product->title .' 已下架'); |
|
|
/*} else if ($product->stock < $form->stock) { |
|
|
/*} else if ($product->stock < $form->stock) { |
|
|
return $form->response()->error("供应商当前库存为{$product->stock},你设置的库存不能超过该数值");*/ |
|
|
return $form->response()->error("供应商当前库存为{$product->stock},你设置的库存不能超过该数值");*/ |
|
|
} else if ($form->price < $product->price) { |
|
|
} else if ($form->price < $product->price) { |
|
|
|