|
|
@@ -5,6 +5,7 @@ namespace biz\goods\classes;
|
|
|
use biz\goods\services\GoodsCategoryService;
|
|
|
use biz\goods\services\GoodsStyleService;
|
|
|
use common\components\business;
|
|
|
+use common\components\stringUtil;
|
|
|
use Yii;
|
|
|
use biz\base\classes\BaseClass;
|
|
|
|
|
|
@@ -47,4 +48,45 @@ class GoodsClass extends BaseClass
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
|
+ public static function addGoods($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']);
|
|
|
+
|
|
|
+ //用商户id生成商品的编号
|
|
|
+ $data['itemNumber'] = stringUtil::buildRandNo($merchantId);
|
|
|
+ $data['createTime'] = date("Y-m-d H:i:s");
|
|
|
+ $goodsInfo = self::add($data);
|
|
|
+ $id = $goodsInfo['id'];
|
|
|
+
|
|
|
+ //处理分类
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $hasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
|
|
|
+ $diff = array_diff($categoryIdList, $hasCategoryIdList);
|
|
|
+ if (!empty($diff)) {
|
|
|
+ util::fail('您使用了别人的分类');
|
|
|
+ }
|
|
|
+ $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' => '']];
|
|
|
+ $addStyle = [];
|
|
|
+ foreach ($goodsStyleList as $style) {
|
|
|
+ $addStyle[] = ['styleName' => $style['styleName'], 'goodsId' => $id, 'picture' => $style['picture'], 'price' => $style['price']];
|
|
|
+ }
|
|
|
+ GoodsStyleClass::batchAdd($addStyle);
|
|
|
+ }
|
|
|
+ return $goodsInfo;
|
|
|
+ }
|
|
|
+
|
|
|
}
|