From 8bddb832cc20dd8aa4828a6081e8f850e2dbc3e2 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Tue, 19 Mar 2024 11:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BF=AE=E6=94=B9=E5=95=86?= =?UTF-8?q?=E5=93=81=E7=9A=84=E6=97=B6=E5=80=99=E7=9A=84=E5=95=86=E6=88=B7?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/product/ProductRepository.php | 44 ++++++++++++++----- .../merchant/store/product/Product.php | 2 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index 91b671fb..2ff383d5 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -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, diff --git a/app/controller/merchant/store/product/Product.php b/app/controller/merchant/store/product/Product.php index 464a8d8e..700d6295 100644 --- a/app/controller/merchant/store/product/Product.php +++ b/app/controller/merchant/store/product/Product.php @@ -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('数据不存在');