创建修改商品的时候的商户代码迁移
This commit is contained in:
parent
62bd597ac5
commit
8bddb832cc
@ -66,6 +66,23 @@ class ProductRepository extends BaseRepository
|
||||
public $saleType;
|
||||
protected $dao;
|
||||
const CREATE_PARAMS = [
|
||||
"is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort", "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free', 'param_temp_id', 'extend', 'mer_form_id',
|
||||
["mer_cate_id", []],
|
||||
['refund_switch', 1],
|
||||
["brand_id", 0],
|
||||
['once_max_count', 0],
|
||||
['once_min_count', 0],
|
||||
['pay_limit', 0],
|
||||
["attrValue", []],
|
||||
['give_coupon_ids', []],
|
||||
['type', 0],
|
||||
['svip_price', 0],
|
||||
['svip_price_type', 0],
|
||||
['params', []],
|
||||
['product_type', 0],
|
||||
['good_ids', []],
|
||||
];
|
||||
const UPDATE_PARAMS = [
|
||||
"is_copy", "image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "unit_name", "sort", "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free', 'param_temp_id', 'extend', 'mer_form_id','wholesale_price',
|
||||
["mer_cate_id", []],
|
||||
['refund_switch', 1],
|
||||
@ -235,15 +252,12 @@ class ProductRepository extends BaseRepository
|
||||
$admin_info = $data['admin_info'] ?? [];
|
||||
unset($data['admin_info']);
|
||||
}
|
||||
// dump($data);
|
||||
$product = $this->setProduct($data);
|
||||
$product['wholesale_price'] = 11;
|
||||
// halt($product);
|
||||
event('product.create.before', compact('data', 'productType', 'conType'));
|
||||
return Db::transaction(function () use ($data, $productType, $conType, $content, $product, $admin_info) {
|
||||
$activity_id = 0;
|
||||
$result = $this->dao->create($product);
|
||||
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0);
|
||||
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']);
|
||||
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']);
|
||||
$settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id);
|
||||
if ($productType == 0) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [], $data['mer_id']);
|
||||
@ -293,7 +307,9 @@ class ProductRepository extends BaseRepository
|
||||
}
|
||||
event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType'));
|
||||
$spuData = $product = $this->setProduct($data);//商品主表
|
||||
$settleParams = $this->setAttrValue($data, $id, $productType, 1);
|
||||
$settleParams = $this->setAttrValue($data, $id, $productType, 1,$merId);
|
||||
|
||||
|
||||
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
|
||||
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
|
||||
$content = [
|
||||
@ -405,7 +421,6 @@ class ProductRepository extends BaseRepository
|
||||
unset($data['admin_info']);
|
||||
}
|
||||
$update_infos = $settleParams['update_infos'] ?? [];
|
||||
|
||||
if (isset($settleParams['data'])) $data = array_merge($data, $settleParams['data']);
|
||||
$this->dao->update($id, $data);
|
||||
if (isset($data['status']) && $data['status'] !== 1) {
|
||||
@ -531,7 +546,7 @@ class ProductRepository extends BaseRepository
|
||||
'refund_switch' => $data['refund_switch'] ?? 0,
|
||||
'mer_form_id' => $data['mer_form_id'] ?? 0,
|
||||
'rate' => $data['rate'] ?? 5.0,
|
||||
'wholesale_price'=>$data['wholesale_price'] ??0
|
||||
'wholesale_price'=> min($data['attrValue'][0]['ot_price'],$data['attrValue'][0]['price'])
|
||||
];
|
||||
if (isset($data['extend']))
|
||||
$result['extend'] = $data['extend'] ? json_encode($data['extend'], JSON_UNESCAPED_UNICODE) : '';
|
||||
@ -606,8 +621,11 @@ class ProductRepository extends BaseRepository
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0)
|
||||
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0, int $merId = 0)
|
||||
{
|
||||
if ($merId <= 0) {
|
||||
throw new ValidateException('添加商品商户id不能为0');
|
||||
}
|
||||
$extension_status = systemConfig('extension_status');
|
||||
if ($isUpdate) {
|
||||
$productAttrValue = app()->make(ProductAttrValueRepository::class)->search(['product_id' => $productId])->select()->toArray();
|
||||
@ -653,8 +671,13 @@ class ProductRepository extends BaseRepository
|
||||
!$cdkeey_stock ?: $value['stock'] = $cdkeey_stock;
|
||||
}
|
||||
$new_price = $value['price'] ? (($value['price'] < 0) ? 0 : $value['price']) : 0;
|
||||
$otPrice = $value['ot_price'] ? (($value['ot_price'] < 0) ? 0 : $value['ot_price']) : 0;
|
||||
if(isset($value['wholesale_price'])){
|
||||
$wholesale_price = $value['wholesale_price'] ? (($value['wholesale_price'] < 0) ? 0 : $value['wholesale_price']) : 0;
|
||||
}else{
|
||||
$wholesale_price = min($new_price,$otPrice);
|
||||
}
|
||||
|
||||
$wholesale_price = $value['wholesale_price'] ? (($value['wholesale_price'] < 0) ? 0 : $value['wholesale_price']) : 0;
|
||||
$new_stock = $value['stock'] ? (($value['stock'] < 0) ? 0 : $value['stock']) : 0;
|
||||
$array = [
|
||||
'detail' => json_encode($value['detail'] ?? ''),
|
||||
@ -666,10 +689,11 @@ class ProductRepository extends BaseRepository
|
||||
"volume" => isset($value['volume']) ? ($value['volume'] ? (($value['volume'] < 0) ? 0 : $value['volume']) : 0) : 0,
|
||||
"weight" => isset($value['weight']) ? ($value['weight'] ? (($value['weight'] < 0) ? 0 : $value['weight']) : 0) : 0,
|
||||
"stock" => $new_stock,
|
||||
"ot_price" => $value['ot_price'] ? (($value['ot_price'] < 0) ? 0 : $value['ot_price']) : 0,
|
||||
"ot_price" =>$otPrice,
|
||||
"extension_one" => $extension_status ? ($value['extension_one'] ?? 0) : 0,
|
||||
"extension_two" => $extension_status ? ($value['extension_two'] ?? 0) : 0,
|
||||
"product_id" => $productId,
|
||||
'mer_id' => $merId,
|
||||
"type" => 0,
|
||||
"sku" => $sku,
|
||||
"unique" => $unique,
|
||||
|
@ -135,7 +135,7 @@ class Product extends BaseController
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$params = $this->request->params($this->repository::CREATE_PARAMS);
|
||||
$params = $this->request->params($this->repository::UPDATE_PARAMS);
|
||||
$data = $this->repository->checkParams($params, $this->request->merId(), $id);
|
||||
if (!$this->repository->merExists($this->request->merId(), $id))
|
||||
return app('json')->fail('数据不存在');
|
||||
|
Loading…
x
Reference in New Issue
Block a user