|
|
@@ -59,13 +59,14 @@ class GoodsClass extends BaseClass
|
|
|
unset($data['goodsStyleList']);
|
|
|
|
|
|
//用商户id生成商品的编号
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
$data['itemNumber'] = stringUtil::buildRandNo($merchantId);
|
|
|
$data['createTime'] = date("Y-m-d H:i:s");
|
|
|
+ $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
$goodsInfo = self::add($data);
|
|
|
$id = $goodsInfo['id'];
|
|
|
|
|
|
//处理分类
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
$hasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
|
|
|
$diff = array_diff($categoryIdList, $hasCategoryIdList);
|
|
|
if (!empty($diff)) {
|
|
|
@@ -78,9 +79,10 @@ class GoodsClass extends BaseClass
|
|
|
GoodsCategoryClass::batchAdd($addCategory);
|
|
|
//处理款式
|
|
|
if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
- $goodsStyleList = [['styleName' => '红色', 'price' => 0.1, 'picture' => '']];
|
|
|
+ $goodsStyleList = ['add' => [['styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '']]];
|
|
|
+ $addGoodsStyle = $goodsStyleList['add'];
|
|
|
$addStyle = [];
|
|
|
- foreach ($goodsStyleList as $style) {
|
|
|
+ foreach ($addGoodsStyle as $style) {
|
|
|
$addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
}
|
|
|
GoodsStyleClass::batchAdd($addStyle);
|
|
|
@@ -106,7 +108,6 @@ class GoodsClass extends BaseClass
|
|
|
if (!empty($diff)) {
|
|
|
util::fail('您使用了别人的分类');
|
|
|
}
|
|
|
-
|
|
|
//先删除分类
|
|
|
GoodsCategoryClass::delGoodsCategory($id);
|
|
|
$addCategory = [];
|
|
|
@@ -115,17 +116,36 @@ class GoodsClass extends BaseClass
|
|
|
}
|
|
|
//再添加分类
|
|
|
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']];
|
|
|
+ $goodsStyleList = [
|
|
|
+ 'add' => [['styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['styleName' => '蓝色', 'price' => 0.1, 'picture' => '']],
|
|
|
+ 'delete' => [1, 2, 3],
|
|
|
+ 'update' => [['id' => 4, 'styleName' => '红色', 'price' => 0.1, 'picture' => ''], ['id' => 5, 'styleName' => '蓝色', 'price' => 0.1, 'picture' => '']],
|
|
|
+ ];
|
|
|
+ if (isset($goodsStyleList['add']) && !empty($goodsStyleList['add'])) {
|
|
|
+ $addStyleList = $goodsStyleList['add'];
|
|
|
+ $addStyle = [];
|
|
|
+ foreach ($addStyleList as $style) {
|
|
|
+ $addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
+ }
|
|
|
+ GoodsStyleClass::batchAdd($addStyle);
|
|
|
+ }
|
|
|
+ if (isset($goodsStyleList['delete']) && !empty($goodsStyleList['delete'])) {
|
|
|
+ GoodsStyleClass::deleteByIds($goodsStyleList['delete']);
|
|
|
+ }
|
|
|
+ if (isset($goodsStyleList['update']) && !empty($goodsStyleList['update'])) {
|
|
|
+ $update = $goodsStyleList['update'];
|
|
|
+ foreach ($update as $up) {
|
|
|
+ $currentId = $up['id'];
|
|
|
+ unset($up['id']);
|
|
|
+ GoodsStyleClass::updateById($currentId, $up);
|
|
|
+ }
|
|
|
}
|
|
|
- GoodsStyleClass::batchAdd($addStyle);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
self::updateById($id, $data);
|
|
|
}
|
|
|
|