| | |
| | | } |
| | | } |
| | | $data['content'] = isset($data['content']) ? $data['content'] : ''; |
| | | $data['open_coupons'] = isset($data['open_coupons']) ? $data['open_coupons'] : []; |
| | | $data['app_id'] = $data['sku']['app_id'] = self::$app_id; |
| | | // 设置商品重量默认值 |
| | | $data['product_weight'] = isset($data['product_weight']) ? $data['product_weight'] : 0; |
| | | // 单规格商品,将规格重量赋值给商品重量 |
| | | if (isset($data['spec_type']) && $data['spec_type'] == '10' && isset($data['sku']['weight'])) { |
| | | $data['product_weight'] = $data['sku']['weight']; |
| | | } |
| | | // 获取分类 by lyzflash 2023.06.15 |
| | | if ($data['category_ids']) { |
| | | $data['category_id'] = $data['category_ids'][0]; // 从商品多分类中获取第一个作为主分类 by lyzflash |
| | | } |
| | | |
| | | $this->processContent($data); |
| | | // 开启事务 |
| | |
| | | if($data['is_picture'] == 1){ |
| | | $this->addProductContentImages($data['contentImage']); |
| | | } |
| | | // 保存商品多分类 |
| | | $data['category_ids'] && $this->saveProductCategorys($data['category_ids']); |
| | | $this->commit(); |
| | | return true; |
| | | } catch (\Exception $e) { |
| | |
| | | $this->rollback(); |
| | | return false; |
| | | } |
| | | } |
| | | /** |
| | | * 添加商品多分类 by lzyflash 2023.06.15 |
| | | */ |
| | | private function saveProductCategorys($data) |
| | | { |
| | | // 先删除所有分类 |
| | | $model = new ProductCategory; |
| | | $model->removeAll($this['product_id']); |
| | | $model->addCategoryList($this['product_id'], $data); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | $data['spec_type'] = isset($data['spec_type']) ? $data['spec_type'] : $this['spec_type']; |
| | | $data['content'] = isset($data['content']) ? $data['content'] : ''; |
| | | $data['open_coupons'] = isset($data['open_coupons']) ? $data['open_coupons'] : []; |
| | | $data['app_id'] = $data['sku']['app_id'] = self::$app_id; |
| | | // 设置商品重量默认值 |
| | | $data['product_weight'] = isset($data['product_weight']) ? $data['product_weight'] : 0; |
| | | // 单规格商品,将规格重量赋值给商品重量 |
| | | if (isset($data['spec_type']) && $data['spec_type'] == '10' && isset($data['sku']['weight'])) { |
| | | $data['product_weight'] = $data['sku']['weight']; |
| | | } |
| | | // 获取分类 by lyzflash 2023.06.15 |
| | | if ($data['category_ids']) { |
| | | $data['category_id'] = $data['category_ids'][0]; // 从商品多分类中获取第一个作为主分类 by lyzflash |
| | | } |
| | | $productSkuIdList = helper::getArrayColumn(($this['sku']), 'product_sku_id'); |
| | | return $this->transaction(function () use ($data, $productSkuIdList) { |
| | | // 商品状态,如果已审核过的,看平台配置是否需要再次审核 |
| | |
| | | if($data['is_picture'] == 1){ |
| | | $this->addProductContentImages($data['contentImage']); |
| | | } |
| | | // 保存商品多分类 |
| | | $data['category_ids'] && $this->saveProductCategorys($data['category_ids']); |
| | | return true; |
| | | }); |
| | | } |