|
|
@@ -76,10 +76,9 @@ class GoodsClass extends BaseClass
|
|
|
$addCategory[] = ['gId' => $id, 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
}
|
|
|
GoodsCategoryClass::batchAdd($addCategory);
|
|
|
-
|
|
|
//处理款式
|
|
|
if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
- $goodsStyleList = [['id' => 0, 'styleName' => '红色', 'price' => 0.1, 'picture' => '']];
|
|
|
+ $goodsStyleList = [['styleName' => '红色', 'price' => 0.1, 'picture' => '']];
|
|
|
$addStyle = [];
|
|
|
foreach ($goodsStyleList as $style) {
|
|
|
$addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
@@ -88,5 +87,46 @@ class GoodsClass extends BaseClass
|
|
|
}
|
|
|
return $goodsInfo;
|
|
|
}
|
|
|
+
|
|
|
+ //更新商品 shish 2019.12.7
|
|
|
+ public static function updateGoods($id, $data)
|
|
|
+ {
|
|
|
+ $categoryIdList = isset($data['categoryIdList']) && !empty($data['categoryIdList']) ? $data['categoryIdList'] : [];
|
|
|
+ unset($data['categoryIdList']);
|
|
|
+ if (empty($categoryIdList)) {
|
|
|
+ util::fail('没有选择分类');
|
|
|
+ }
|
|
|
+ $goodsStyleList = isset($data['goodsStyleList']) && !empty($data['goodsStyleList']) ? $data['goodsStyleList'] : [];
|
|
|
+ unset($data['goodsStyleList']);
|
|
|
+
|
|
|
+ //处理分类
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $merchantHasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
|
|
|
+ $diff = array_diff($categoryIdList, $merchantHasCategoryIdList);
|
|
|
+ if (!empty($diff)) {
|
|
|
+ util::fail('您使用了别人的分类');
|
|
|
+ }
|
|
|
|
|
|
+ //先删除分类
|
|
|
+ GoodsCategoryClass::delGoodsCategory($id);
|
|
|
+ $addCategory = [];
|
|
|
+ foreach ($categoryIdList as $categoryId) {
|
|
|
+ $addCategory[] = ['gId' => $id, 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
+ }
|
|
|
+ //再添加分类
|
|
|
+ GoodsCategoryClass::batchAdd($addCategory);
|
|
|
+
|
|
|
+ //处理款式
|
|
|
+ if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
+ $goodsStyleList = [['id' => 0, 'styleName' => '红色', 'price' => 0.1, 'picture' => '','act'=>'']];
|
|
|
+ $addStyle = [];
|
|
|
+ foreach ($goodsStyleList as $style) {
|
|
|
+ $addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
+ }
|
|
|
+ GoodsStyleClass::batchAdd($addStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ self::updateById($id, $data);
|
|
|
+ }
|
|
|
+
|
|
|
}
|