|
|
@@ -12,129 +12,130 @@ use biz\base\classes\BaseClass;
|
|
|
|
|
|
class GoodsClass extends BaseClass
|
|
|
{
|
|
|
-
|
|
|
- public static $baseFile = '\biz\goods\models\Goods';
|
|
|
-
|
|
|
- //获取商品完整详情,包括商品的分类 shish 2019.12.3
|
|
|
- public static function getGoodsInfo($id)
|
|
|
- {
|
|
|
- $info = self::getById($id);
|
|
|
- if (empty($info)) {
|
|
|
- return [];
|
|
|
- }
|
|
|
- $list = self::groupGoodsBaseInfo([$info]);
|
|
|
- $info = current($list);
|
|
|
- //商品的分类
|
|
|
- $category = GoodsCategoryService::getGoodsHasCategoryIdList($id);
|
|
|
- $info['categoryIdList'] = $category;
|
|
|
- return $info;
|
|
|
- }
|
|
|
-
|
|
|
- //组装商品基本信息 shish 2019.12.2
|
|
|
- public static function groupGoodsBaseInfo($list)
|
|
|
- {
|
|
|
- $merchantIdList = array_column($list, 'merchantId');
|
|
|
- $merchantIdList = array_unique(array_filter($merchantIdList));
|
|
|
- $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
|
|
|
- foreach ($list as $key => $val) {
|
|
|
- $id = $val['id'];
|
|
|
- //大中小图片转化
|
|
|
- $val = business::formatGoodsImg($val);
|
|
|
- //免费配送范围
|
|
|
- $val['freeSendDist'] = 5;
|
|
|
- //多款式
|
|
|
- $val['goodsStyleList'] = isset($val['goodsStyle']) && $val['goodsStyle'] == 1 ? GoodsStyleClass::getStyleList($id) : [];
|
|
|
- $val['createDate'] = date("Y-m-d", strtotime($val['createTime']));
|
|
|
- $merchantId = $val['merchantId'];
|
|
|
- $val['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
|
|
|
- $list[$key] = $val;
|
|
|
- //涨价
|
|
|
- }
|
|
|
- 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'] : [];
|
|
|
-
|
|
|
- //用商户id生成商品的编号
|
|
|
- $merchantId = $data['merchantId'];
|
|
|
- $data['itemNumber'] = stringUtil::buildRandNo($merchantId);
|
|
|
- $data['createTime'] = date("Y-m-d H:i:s");
|
|
|
- $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
- $data['briefContent'] = isset($data['briefContent']) ? $data['briefContent'] : '';
|
|
|
- $data['content'] = isset($data['content']) ? $data['content'] : '';
|
|
|
- $goodsInfo = self::add($data);
|
|
|
- $id = $goodsInfo['id'];
|
|
|
- $goodsName = $goodsInfo['goodsName'];
|
|
|
-
|
|
|
- //处理分类
|
|
|
- $hasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
|
|
|
- $diff = array_diff($categoryIdList, $hasCategoryIdList);
|
|
|
- if (!empty($diff)) {
|
|
|
- util::fail('您使用了别人的分类');
|
|
|
- }
|
|
|
- $addCategory = [];
|
|
|
- foreach ($categoryIdList as $categoryId) {
|
|
|
- $addCategory[] = ['gId' => $id, 'goodsName' => $goodsName, 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
- }
|
|
|
- GoodsCategoryClass::batchAdd($addCategory);
|
|
|
- //处理款式
|
|
|
- if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
- $addStyle = [];
|
|
|
- foreach ($goodsStyleList as $goodsStyle) {
|
|
|
- $addStyle[] = ['styleName' => $goodsStyle['styleName'], 'goodsId' => $id, 'picture' => $goodsStyle['picture'], 'price' => $goodsStyle['price']];
|
|
|
- }
|
|
|
- GoodsStyleClass::batchAdd($addStyle);
|
|
|
- }
|
|
|
- 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, 'goodsName' => $data['goodsName'], 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
- }
|
|
|
- GoodsCategoryClass::batchAdd($addCategory);
|
|
|
|
|
|
- //处理款式
|
|
|
- if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
- GoodsStyleClass::updateGoodsStyle($goodsStyleList, $id);
|
|
|
- }
|
|
|
-
|
|
|
- $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
- self::updateById($id, $data);
|
|
|
- }
|
|
|
-
|
|
|
- //产品上下架 shish 2019.12.8
|
|
|
- public static function changeStatus($id, $status)
|
|
|
- {
|
|
|
- self::updateById($id, ['status' => $status]);
|
|
|
- GoodsCategoryClass::updateByCondition(['gId' => $id], ['status' => $status]);
|
|
|
- }
|
|
|
-
|
|
|
+ public static $baseFile = '\biz\goods\models\Goods';
|
|
|
+
|
|
|
+ //获取商品完整详情,包括商品的分类 shish 2019.12.3
|
|
|
+ public static function getGoodsInfo($id)
|
|
|
+ {
|
|
|
+ $info = self::getById($id);
|
|
|
+ if (empty($info)) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $list = self::groupGoodsBaseInfo([$info]);
|
|
|
+ $info = current($list);
|
|
|
+ //商品的分类
|
|
|
+ $category = GoodsCategoryService::getGoodsHasCategoryIdList($id);
|
|
|
+ $info['categoryIdList'] = $category;
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ //组装商品基本信息 shish 2019.12.2
|
|
|
+ public static function groupGoodsBaseInfo($list)
|
|
|
+ {
|
|
|
+ $merchantIdList = array_column($list, 'merchantId');
|
|
|
+ $merchantIdList = array_unique(array_filter($merchantIdList));
|
|
|
+ $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
|
|
|
+ foreach ($list as $key => $val) {
|
|
|
+ $id = $val['id'];
|
|
|
+ //大中小图片转化
|
|
|
+ $val = business::formatGoodsImg($val);
|
|
|
+ //免费配送范围
|
|
|
+ $val['freeSendDist'] = 5;
|
|
|
+ //多款式
|
|
|
+ $val['goodsStyleList'] = isset($val['goodsStyle']) && $val['goodsStyle'] == 1 ? GoodsStyleClass::getStyleList($id) : [];
|
|
|
+ $val['createDate'] = date("Y-m-d", strtotime($val['createTime']));
|
|
|
+ $merchantId = $val['merchantId'];
|
|
|
+ $val['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
|
|
|
+ $list[$key] = $val;
|
|
|
+ //涨价
|
|
|
+ }
|
|
|
+ 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'] : [];
|
|
|
+
|
|
|
+ //用商户id生成商品的编号
|
|
|
+ $merchantId = $data['merchantId'];
|
|
|
+ $data['itemNumber'] = stringUtil::buildRandNo($merchantId);
|
|
|
+ $data['createTime'] = date("Y-m-d H:i:s");
|
|
|
+ $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
+ $data['briefContent'] = isset($data['briefContent']) ? $data['briefContent'] : '';
|
|
|
+ $data['content'] = isset($data['content']) ? $data['content'] : '';
|
|
|
+ $data['stock'] = isset($data['stock']) && is_numeric($data['stock']) && $data['stock'] >= 0 ? $data['stock'] : -1;
|
|
|
+ $goodsInfo = self::add($data);
|
|
|
+ $id = $goodsInfo['id'];
|
|
|
+ $goodsName = $goodsInfo['goodsName'];
|
|
|
+
|
|
|
+ //处理分类
|
|
|
+ $hasCategoryIdList = CategoryClass::getCategoryIdList($merchantId);
|
|
|
+ $diff = array_diff($categoryIdList, $hasCategoryIdList);
|
|
|
+ if (!empty($diff)) {
|
|
|
+ util::fail('您使用了别人的分类');
|
|
|
+ }
|
|
|
+ $addCategory = [];
|
|
|
+ foreach ($categoryIdList as $categoryId) {
|
|
|
+ $addCategory[] = ['gId' => $id, 'goodsName' => $goodsName, 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
+ }
|
|
|
+ GoodsCategoryClass::batchAdd($addCategory);
|
|
|
+ //处理款式
|
|
|
+ if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
+ $addStyle = [];
|
|
|
+ foreach ($goodsStyleList as $goodsStyle) {
|
|
|
+ $addStyle[] = ['styleName' => $goodsStyle['styleName'], 'goodsId' => $id, 'picture' => $goodsStyle['picture'], 'price' => $goodsStyle['price']];
|
|
|
+ }
|
|
|
+ GoodsStyleClass::batchAdd($addStyle);
|
|
|
+ }
|
|
|
+ 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, 'goodsName' => $data['goodsName'], 'cId' => $categoryId, 'merchantId' => $data['merchantId']];
|
|
|
+ }
|
|
|
+ GoodsCategoryClass::batchAdd($addCategory);
|
|
|
+
|
|
|
+ //处理款式
|
|
|
+ if (!empty($goodsStyleList) && $data['goodsStyle'] == 1) {
|
|
|
+ GoodsStyleClass::updateGoodsStyle($goodsStyleList, $id);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['shopImg'] = json_encode($data['shopImg']);
|
|
|
+ self::updateById($id, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ //产品上下架 shish 2019.12.8
|
|
|
+ public static function changeStatus($id, $status)
|
|
|
+ {
|
|
|
+ self::updateById($id, ['status' => $status]);
|
|
|
+ GoodsCategoryClass::updateByCondition(['gId' => $id], ['status' => $status]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|