shish 4 лет назад
Родитель
Сommit
9472fe6f3a

+ 7 - 9
app-hd/controllers/GoodsController.php

@@ -169,18 +169,16 @@ class GoodsController extends BaseController
 
     public function actionIndex()
     {
-        $classIds = CategoryService::getCategoryClassAll($this->mainId);
-        $where['sjId'] = $this->sjId;
-        $where['delStatus'] = 0;
-        $goodsData = GoodsCategoryService::getGoodsAll($where);
-
-        //常用的GoodsId
-        $oftenIds = GoodsCategoryService::getOftenIds($this->mainId);
+        $catWhere = ['mainId' => $this->mainId];
+        $goodsWhere['mainId'] = $this->mainId;
+        $goodsWhere['delStatus'] = 0;
+        $classIds = CategoryService::getCategoryClassAll($catWhere);
+        $goodsData = GoodsCategoryService::getGoodsAll($goodsWhere);
 
         $goodsCateData = GoodsCategoryService::getEnableGoodsCategory($this->mainId);
 
-        //组装数据 [{classId:'','className:'',child:[{itemInfoData}]}]
-        $data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData, $oftenIds);
+        //组装数据 [{classId:'','className:'',child:[{itemInfoData}]}]
+        $data = GoodsCategoryService::assembleData($classIds, $goodsCateData, $goodsData);
 
         util::success($data);
     }

+ 2 - 8
biz-hd/goods/services/CategoryService.php

@@ -124,16 +124,10 @@ class CategoryService extends BaseService
         return CategoryClass::deleteCategory($id);
     }
 
-    //获取开单页所有的分类:包括、常用
-    public static function getCategoryClassAll($mainId)
+    //获取开单页所有的分类
+    public static function getCategoryClassAll($where)
     {
-        $where = ['mainId' => $mainId];
         $data = self::getAllList('id,categoryName as name', $where, 'inTurn desc');
-        $use = [
-            'id' => -2,
-            'name' => '常用'
-        ];
-        array_unshift($data, $use);
         return $data;
     }
 

+ 91 - 131
biz-hd/goods/services/GoodsCategoryService.php

@@ -11,187 +11,147 @@ use linslin\yii2\curl;
 class GoodsCategoryService extends BaseService
 {
     const OFTEN_CLASS_ID = '-2'; //常用分类
-	public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
+    public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
 
-	//查询一个分类下的商品,有分页 ssh 2019.12.2
-	public static function getGoodsList($where)
-	{
-		$data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
-		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-		if (empty($list)) {
-			return $data;
-		}
-		$ids = array_column($list, 'gId');
-		$list = GoodsService::getAllByCondition(['id' => ['in', $ids]], 'inTurn DESC', '*');
-		$data['list'] = GoodsClass::groupGoodsBaseInfo($list);
-		return $data;
-	}
-
-	//查询指定分类下的商品,没有分页,首页使用 ssh 2019.12.2
-	public static function getAppointCategoryList($category)
-	{
-		$ids = array_column($category, 'id');
-		//取出分类下的商品id
-		$list = GoodsCategoryClass::getAllByCondition(['cId' => ['in', $ids]], 'inTurn DESC,addTime DESC', '*');
-		if (empty($list)) {
-			foreach ($category as $key => $val) {
-				$category[$key]['goodsInfoList'] = [];
-			}
-			return $category;
-		}
-		$goodsList = [];
-		$categoryGoods = [];
-		foreach ($list as $val) {
-			$goodsList[] = $val['gId'];
-			$cId = $val['cId'];
-			$categoryGoods[$cId][] = $val['gId'];
-		}
-		//查出商品信息
-		$goodsInfoList = GoodsService::getAllByCondition(['id' => ['in', $goodsList]], 'inTurn DESC', '*', 'id');
-		$goodsInfoList = GoodsClass::groupGoodsBaseInfo($goodsInfoList);
-
-		//每个分类取的商品数
-		$getNum = [6, 2, 4];
-		$showRowNum = [2, 1, 2];
+    //查询一个分类下的商品,有分页 ssh 2019.12.2
+    public static function getGoodsList($where)
+    {
+        $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $ids = array_column($list, 'gId');
+        $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], 'inTurn DESC', '*');
+        $data['list'] = GoodsClass::groupGoodsBaseInfo($list);
+        return $data;
+    }
 
-		foreach ($category as $key => $val) {
-			$id = $val['id'];
-			//当前分类下有哪些商品id,并组合商品信息
-			$categoryGoodsIdList = isset($categoryGoods[$id]) ? $categoryGoods[$id] : [];
-			$info = [];
-			if (!empty($categoryGoodsIdList)) {
-				$currentGetNum = isset($getNum[$key]) ? $getNum[$key] : 2;
-				$categoryGoodsIdList = array_slice($categoryGoodsIdList, 0, $currentGetNum);
-				foreach ($categoryGoodsIdList as $currentGoodsId) {
-					if (isset($goodsInfoList[$currentGoodsId])) {
-						$info[] = $goodsInfoList[$currentGoodsId];
-					}
-				}
-			}
-			$category[$key]['goodsInfoList'] = $info;
-			$category[$key]['showRow'] = isset($showRowNum[$key]) ? $showRowNum[$key] : 2;
-		}
-		return $category;
-	}
+    //查询指定分类下的商品,没有分页,首页使用 ssh 2019.12.2
+    public static function getAppointCategoryList($category)
+    {
+        $ids = array_column($category, 'id');
+        //取出分类下的商品id
+        $list = GoodsCategoryClass::getAllByCondition(['cId' => ['in', $ids]], 'inTurn DESC,addTime DESC', '*');
+        if (empty($list)) {
+            foreach ($category as $key => $val) {
+                $category[$key]['goodsInfoList'] = [];
+            }
+            return $category;
+        }
+        $goodsList = [];
+        $categoryGoods = [];
+        foreach ($list as $val) {
+            $goodsList[] = $val['gId'];
+            $cId = $val['cId'];
+            $categoryGoods[$cId][] = $val['gId'];
+        }
+        //查出商品信息
+        $goodsInfoList = GoodsService::getAllByCondition(['id' => ['in', $goodsList]], 'inTurn DESC', '*', 'id');
+        $goodsInfoList = GoodsClass::groupGoodsBaseInfo($goodsInfoList);
+
+        //每个分类取的商品数
+        $getNum = [6, 2, 4];
+        $showRowNum = [2, 1, 2];
+
+        foreach ($category as $key => $val) {
+            $id = $val['id'];
+            //当前分类下有哪些商品id,并组合商品信息
+            $categoryGoodsIdList = isset($categoryGoods[$id]) ? $categoryGoods[$id] : [];
+            $info = [];
+            if (!empty($categoryGoodsIdList)) {
+                $currentGetNum = isset($getNum[$key]) ? $getNum[$key] : 2;
+                $categoryGoodsIdList = array_slice($categoryGoodsIdList, 0, $currentGetNum);
+                foreach ($categoryGoodsIdList as $currentGoodsId) {
+                    if (isset($goodsInfoList[$currentGoodsId])) {
+                        $info[] = $goodsInfoList[$currentGoodsId];
+                    }
+                }
+            }
+            $category[$key]['goodsInfoList'] = $info;
+            $category[$key]['showRow'] = isset($showRowNum[$key]) ? $showRowNum[$key] : 2;
+        }
+        return $category;
+    }
 
-	//获取商品所属的分类id  ssh 201917
-	public static function getGoodsHasCategoryIds($goodsId)
-	{
-		$categoryIdList = GoodsCategoryClass::getAllByCondition(['gId' => $goodsId], null, 'cId', 'cId');
-		if (empty($categoryIdList)) {
-			return [];
-		}
-		$ids = array_keys($categoryIdList);
-		return $ids;
-	}
+    //获取商品所属的分类id  ssh 201917
+    public static function getGoodsHasCategoryIds($goodsId)
+    {
+        $categoryIdList = GoodsCategoryClass::getAllByCondition(['gId' => $goodsId], null, 'cId', 'cId');
+        if (empty($categoryIdList)) {
+            return [];
+        }
+        $ids = array_keys($categoryIdList);
+        return $ids;
+    }
 
-	//所有商品
+    //所有商品
     public static function getGoodsAll($where)
     {
         $list = GoodsCategoryClass::getAllList('*', $where, 'inTurn DESC');
-
         $ids = array_column($list, 'gId');
         $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], 'inTurn DESC', '*');
         $data = GoodsClass::groupGoodsBaseInfo($list);
         return $data;
     }
 
-    //获取商家下 所有商品的分类
-    public static function getGoodsCategory($sjId)
-    {
-        $where = [
-            'sjId' => $sjId
-        ];
-        $data = self::getAllList('cId as classId,gId', $where);
-        return $data;
-    }
-
-    //获取商家下 所有启用的商品分类
+    //获取商家下所有启用的商品分类
     public static function getEnableGoodsCategory($mainId)
     {
         $cat = CategoryService::getEnableList($mainId);
-        $where = ['mainId' => $mainId,'cId' => ['in', array_column($cat, 'id')]];
+        $where = ['mainId' => $mainId, 'cId' => ['in', array_column($cat, 'id')]];
         $data = self::getAllList('cId as classId,gId', $where);
         return $data;
     }
 
-	//获取常用分类的 goods id  lqh 2021.04.09
+    //获取常用分类的 goods id  lqh 2021.04.09
     public static function getOftenIds($mainId)
     {
-        $data = GoodsClass::getLimitList("id", ['mainId' => $mainId], 10,'actualSold desc');
+        $data = GoodsClass::getLimitList("id", ['mainId' => $mainId], 10, 'actualSold desc');
         if ($data) {
             $data = array_column($data, 'id');
         }
         return $data;
     }
 
-    //
-    public static function assembleData($classIds,$goodsCateData,$goodsData, $oftenIds)
+    public static function assembleData($classIds, $goodsCateData, $goodsData)
     {
-        $oftenItemInfoData = [];
-        if($goodsData){
-            foreach ($goodsData as $v){
-                if(in_array($v['id'],$oftenIds)){
-                    $v['classId'] = self::OFTEN_CLASS_ID;
-                    $oftenItemInfoData[] = $v;
-                }
-            }
-        }
-
-        //classId=>itemId
         $classMapItem = [];
-        if($goodsData){
-            foreach ($goodsCateData as $v){
+        if ($goodsData) {
+            foreach ($goodsCateData as $v) {
                 $classMapItem[$v['classId']][] = $v['gId'];
             }
         }
-
-        //常用
-        $oftenData = [
-            [
-                'classId'=> self::OFTEN_CLASS_ID,
-                'className'=>'常用',
-                'child'=>$oftenItemInfoData,
-            ]
-        ];
-
         $classData = [];
-
-
-        foreach ($classIds as $v){
+        foreach ($classIds as $v) {
             $classId = $v['id'];
-            if($classId > 0 ){
-                $tmp =[];
+            if ($classId > 0) {
+                $tmp = [];
                 $tmp['classId'] = $classId;
                 $tmp['className'] = $v['name'];
-                $items = $classMapItem[$classId]??[];
-                if($items){
-                    if($goodsData){
-                        foreach ($goodsData as $v){
-                            if(in_array($v['id'],$items)){
+                $items = $classMapItem[$classId] ?? [];
+                if ($items) {
+                    if ($goodsData) {
+                        foreach ($goodsData as $v) {
+                            if (in_array($v['id'], $items)) {
                                 $v['classId'] = $classId; //前端要求增加classId 2021.1.31 lqh
                                 $tmp['child'][] = $v;
                             }
                         }
-                    }else{
+                    } else {
                         $tmp['child'] = [];
                     }
-                }else{
+                } else {
                     $tmp['child'] = [];
                 }
                 //去除空分类
-                if(empty($tmp['child'])){
+                if (empty($tmp['child'])) {
                     continue;
                 }
                 $classData[] = $tmp;
             }
-
         }
-
-        //$data = array_merge($oftenData,$allData,$classData);
-        //去除全部
-        $data = array_merge($oftenData,$classData);
-
-        return $data;
+        return $classData;
     }
+
 }

+ 6 - 6
biz-hd/goods/services/GoodsService.php

@@ -85,12 +85,12 @@ class GoodsService extends BaseService
             //新增goods  todo  还有很多字段待确定
             $goodsData = [
                 'name'=>$name,
-                'shopImg'=>'',//?待确定
+                'shopImg'=>'',//待确定
                 'price'=>$order['actPrice'],//实际支付价格
-                'adminId'=>$adminId,//
-                'sjId'=>$order['sjId'],//
-                'status'=>0,//
-                'content'=>'',//
+                'adminId'=>$adminId,
+                'sjId'=>$order['sjId'],
+                'status'=>0,
+                'content'=>'',
                 'createTime'=>$now,
                 'updateTime'=>$now,
             ];
@@ -111,7 +111,7 @@ class GoodsService extends BaseService
                     'productId'=>$v['productId'],
                     'itemId'=>$v['itemId'],
                 ];
-                GoodsItemClass::add($itemData);
+                GoodsItemClass::addData($itemData);
             }
         }catch (\Exception $exception){
             $transaction->rollBack();

+ 2 - 0
sql.txt

@@ -740,4 +740,6 @@ ALTER TABLE xhWork ADD smallNum SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单
 ALTER TABLE xhGoods ADD bigNum SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单位数量' AFTER `flower`;
 ALTER TABLE xhGoods ADD smallNum SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单位数量' AFTER `bigNum`;
 
+ALTER TABLE xhGoodsCategory ADD flower TINYINT NOT NULL DEFAULT 1 COMMENT '商品属性 0绿植盆栽资材 1鲜花成品' AFTER `sjId`;
+
 ====预订单 ssh 20220402