Compare commits

...

2 Commits

  1. 8
      app/store/controller/sharp/Goods.php
  2. 2
      app/store/model/sharp/Goods.php
  3. 8
      app/store/model/sharp/GoodsSku.php

@ -68,7 +68,9 @@ class Goods extends Controller
{ {
// 验证商品ID能否被添加 // 验证商品ID能否被添加
$model = new SharpGoodsModel; $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->renderError($model->getError());
} }
return $this->renderSuccess('添加成功,请在编辑页设置秒杀价格'); return $this->renderSuccess('添加成功,请在编辑页设置秒杀价格');
@ -86,8 +88,10 @@ class Goods extends Controller
{ {
// 秒杀商品详情 // 秒杀商品详情
$model = SharpGoodsModel::detail($sharpGoodsId); $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->renderSuccess('更新成功');
} }
return $this->renderError($model->getError() ?: '更新失败'); return $this->renderError($model->getError() ?: '更新失败');

@ -165,7 +165,7 @@ class Goods extends SharpGoodsModel
// 默认数据 // 默认数据
$data = array_merge($data, [ $data = array_merge($data, [
'newSkuList' => [], 'newSkuList' => [],
'store_id' => self::$storeId, 'store_id' => $data['store_id'] ?? self::$storeId,
]); ]);
// 规格和sku数据处理 // 规格和sku数据处理
$data['newSkuList'] = $this->getNewSkuList($data, $event); $data['newSkuList'] = $this->getNewSkuList($data, $event);

@ -138,14 +138,14 @@ class GoodsSku extends SharpGoodsSkuModel
* @param int $specType * @param int $specType
* @return array|bool|false * @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) { if ($specType === SpecTypeEnum::SINGLE) {
return (new static)->save(array_merge($newSkuList, [ return (new static)->save(array_merge($newSkuList, [
'sharp_goods_id' => $sharpGoodsId, 'sharp_goods_id' => $sharpGoodsId,
'goods_sku_id' => 0, 'goods_sku_id' => 0,
'store_id' => self::$storeId 'store_id' => $storeId ? $storeId : self::$storeId
])); ]));
} // 多规格模式 } // 多规格模式
elseif ($specType === SpecTypeEnum::MULTI) { elseif ($specType === SpecTypeEnum::MULTI) {
@ -162,12 +162,12 @@ class GoodsSku extends SharpGoodsSkuModel
* @param array $skuList * @param array $skuList
* @return array|bool|false * @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记录 // 删除所有的sku记录
static::deleteAll(['sharp_goods_id' => $sharpGoodsId]); static::deleteAll(['sharp_goods_id' => $sharpGoodsId]);
// 新增商品sku记录 // 新增商品sku记录
return static::add($sharpGoodsId, $specType, $skuList); return static::add($sharpGoodsId, $specType, $skuList, $storeId);
} }
/** /**

Loading…
Cancel
Save