From 23e72e36fc98591f41f497aa629ccfe25e9d197e Mon Sep 17 00:00:00 2001 From: lqmac Date: Tue, 5 Nov 2024 22:59:38 +0800 Subject: [PATCH] 1 --- app/store/controller/sharp/Goods.php | 8 ++++++-- app/store/model/sharp/Goods.php | 2 +- app/store/model/sharp/GoodsSku.php | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/store/controller/sharp/Goods.php b/app/store/controller/sharp/Goods.php index 9c5163d8..49189f45 100644 --- a/app/store/controller/sharp/Goods.php +++ b/app/store/controller/sharp/Goods.php @@ -68,7 +68,9 @@ class Goods extends Controller { // 验证商品ID能否被添加 $model = new SharpGoodsModel; - if (!$model->add($this->postForm())) { + $data = $this->postForm(); + $data['store_id'] = $this->storeId; + if (!$model->add($data)) { return $this->renderError($model->getError()); } return $this->renderSuccess('添加成功,请在编辑页设置秒杀价格'); @@ -86,8 +88,10 @@ class Goods extends Controller { // 秒杀商品详情 $model = SharpGoodsModel::detail($sharpGoodsId); + $data = $this->postForm(); + $data['store_id'] = $this->storeId; // 更新记录 - if ($model->edit($this->postForm())) { + if ($model->edit($data)) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); diff --git a/app/store/model/sharp/Goods.php b/app/store/model/sharp/Goods.php index a9dcea5f..82f26a00 100644 --- a/app/store/model/sharp/Goods.php +++ b/app/store/model/sharp/Goods.php @@ -165,7 +165,7 @@ class Goods extends SharpGoodsModel // 默认数据 $data = array_merge($data, [ 'newSkuList' => [], - 'store_id' => self::$storeId, + 'store_id' => $data['store_id'] ?? self::$storeId, ]); // 规格和sku数据处理 $data['newSkuList'] = $this->getNewSkuList($data, $event); diff --git a/app/store/model/sharp/GoodsSku.php b/app/store/model/sharp/GoodsSku.php index 90132170..db3a2ee8 100644 --- a/app/store/model/sharp/GoodsSku.php +++ b/app/store/model/sharp/GoodsSku.php @@ -138,14 +138,14 @@ class GoodsSku extends SharpGoodsSkuModel * @param int $specType * @return array|bool|false */ - public static function add(int $sharpGoodsId, int $specType = SpecTypeEnum::SINGLE, array $newSkuList = []) + public static function add(int $sharpGoodsId, int $specType = SpecTypeEnum::SINGLE, array $newSkuList = [], $storeId = 0) { // 单规格模式 if ($specType === SpecTypeEnum::SINGLE) { return (new static)->save(array_merge($newSkuList, [ 'sharp_goods_id' => $sharpGoodsId, 'goods_sku_id' => 0, - 'store_id' => self::$storeId + 'store_id' => $storeId ? $storeId : self::$storeId ])); } // 多规格模式 elseif ($specType === SpecTypeEnum::MULTI) { @@ -162,12 +162,12 @@ class GoodsSku extends SharpGoodsSkuModel * @param array $skuList * @return array|bool|false */ - public static function edit(int $sharpGoodsId, int $specType = SpecTypeEnum::SINGLE, array $skuList = []) + public static function edit(int $sharpGoodsId, int $specType = SpecTypeEnum::SINGLE, array $skuList = [], $storeId = 0) { // 删除所有的sku记录 static::deleteAll(['sharp_goods_id' => $sharpGoodsId]); // 新增商品sku记录 - return static::add($sharpGoodsId, $specType, $skuList); + return static::add($sharpGoodsId, $specType, $skuList, $storeId); } /**