Browse Source

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

shish 11 months ago
parent
commit
31c7b0fb04

+ 24 - 3
app-hd/controllers/CategoryController.php

@@ -120,6 +120,7 @@ class CategoryController extends BaseController
         $get = Yii::$app->request->get();
         $catId = $get['catId'] ?? 0;
         $where = [];
+        $goodsCond = [];
         $where['mainId'] = $this->mainId;
         if (!empty($catId)) {
             $where['cId'] = $catId;
@@ -128,15 +129,35 @@ class CategoryController extends BaseController
         if (is_numeric($flower)) {
             $where['flower'] = $flower;
         }
+        // flowerNum 是针对 xhGoods 表的条件查询
         $flowerNum = $get['flowerNum'] ?? 0;
-        if (!empty($flowerNum)) {
-            $where['flowerNum'] = $flowerNum;
+        if ($flowerNum > 0) {
+            $goodsCond['flowerNum'] = $flowerNum;
         }
+        if (isset($get['lookPrice'])) { // 1:有价格 2:无价格 -- 根据前端的传值
+            $lookPrice = intval($get['lookPrice']);
+            if ($lookPrice == 1) {
+                $goodsCond['priceType'] = 1;
+            }
+            if ($lookPrice == 2) {
+                $goodsCond['priceType'] = 0;
+            }
+        }
+        if (isset($get['lookStock'])) { // 1:有库存 2:无库存 -- 根据前端的传值
+            $lookStock = intval($get['lookStock']);
+            if ($lookStock == 1) {
+                $goodsCond['stock>'] = 0;
+            }
+            if ($lookStock == 2) {
+                $goodsCond['stock'] = 0;
+            }
+        }
+
         $searchText = $get['searchText'] ?? '';
         if (!empty($searchText)) {
             $where['name'] = ['like', $searchText];
         }
-        $data = GoodsCategoryService::getGoodsList($where);
+        $data = GoodsCategoryService::getGoodsList($where, $goodsCond);
         util::success($data);
     }
 

+ 1 - 3
app-mall/controllers/CategoryController.php

@@ -5,15 +5,13 @@ namespace mall\controllers;
 use bizHd\custom\classes\CustomClass;
 use bizMall\goods\services\CategoryService;
 use bizMall\goods\services\GoodsCategoryService;
-use bizMall\user\classes\UserClass;
 use Yii;
-use yii\web\Controller;
 use common\components\util;
 
 class CategoryController extends BaseController
 {
 
-    public $guestAccess = ['list', 'goods-list'];
+    public $guestAccess = ['list']; // 'goods-list' ---- 为什么不用认证
 
     //获取分类 ssh 2019.12.2
     public function actionList()

+ 3 - 11
biz-hd/goods/classes/GoodsClass.php

@@ -344,7 +344,7 @@ class GoodsClass extends BaseClass
 
     /**
      * 组装商品基本信息
-     * @param $list goods商品数组
+     * @param $list  "goods商品数组"
      * @param bool $getItem 是否获取"成品的花材"
      * @param array $sortIds 按商品分类的inTurn 进行排序的商品id数组
      * @return mixed
@@ -409,18 +409,10 @@ class GoodsClass extends BaseClass
             $val['belongCategory'] = $belongCategory;
 
             $shortCover = $val['cover'] ?? '';
-            // 兼容 cover 保存的是数字(表示第几张图片)
-            if (intval($shortCover) > 0) {
-                $shopImg = isset($val['shortImgList']) ? $val['shortImgList'] : [];
-                $idx = intval($shortCover) - 1;
-                if (isset($shopImg[$idx])) {
-                    $shortCover = $shopImg[$idx];
-                }
-            }
             $val['shortCover'] = $shortCover;
             $val['cover'] = imgUtil::groupImg($shortCover);
-            $val['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
-            $val['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $val['smallCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $val['bigCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_700,w_700";
 
             if ($getItem) {
                 $currentItems = isset($groupedItems[$id]) ? $groupedItems[$id] : [];

+ 13 - 4
biz-hd/goods/services/GoodsCategoryService.php

@@ -8,11 +8,15 @@ use bizHd\goods\classes\GoodsClass;
 
 class GoodsCategoryService extends BaseService
 {
-    const OFTEN_CLASS_ID = '-2'; //常用分类
     public static $baseFile = '\bizHd\goods\classes\GoodsCategoryClass';
 
-    //查询一个分类下的商品,有分页 ssh 2019.12.2
-    public static function getGoodsList($where)
+    /**
+     * 查询一个分类下的商品,有分页
+     * @param array $where 分类的查询条件
+     * @param array $goodsCondition 商品的查询条件
+     * @return mixed
+     */
+    public static function getGoodsList($where, $goodsCondition = [])
     {
         $where['delStatus'] = 0; // 排除已删除
         $data = GoodsCategoryClass::getList('*', $where, 'inTurn DESC');
@@ -20,8 +24,13 @@ class GoodsCategoryService extends BaseService
         if (empty($list)) {
             return $data;
         }
+
         $ids = array_column($list, 'gId');
-        $goodsList = GoodsClass::getAllByCondition(['id' => ['in', $ids]], null, '*');
+        $goodsWhere = ['id' => ['in', $ids]];
+        if (count($goodsCondition) > 0) {
+            $goodsWhere = array_merge($goodsWhere, $goodsCondition);
+        }
+        $goodsList = GoodsClass::getAllByCondition($goodsWhere, null, '*');
         $data['list'] = GoodsClass::groupGoodsBaseInfo($goodsList, false, $ids);
         return $data;
     }

+ 30 - 6
biz-mall/goods/classes/GoodsClass.php

@@ -30,17 +30,26 @@ class GoodsClass extends BaseClass
         return $info;
     }
 
-    //组装商品基本信息 ssh 2019.12.2
-    public static function groupGoodsBaseInfo($list)
+    /**
+     * 组装商品基本信息
+     * @param $list
+     * @param array $sortIds
+     * @return mixed
+     */
+    public static function groupGoodsBaseInfo($list, $sortIds = [])
     {
+        if (empty($list)) {
+            return [];
+        }
+        $arrNotEmpty = is_array($sortIds) && !empty($sortIds);
 
         //注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!
-
         $currentData = current($list);
         $sjId = $currentData['sjId'];
         $rise = GoodsSettingClass::getRise($sjId);
 
         foreach ($list as $key => $val) {
+            $id = $val['id'];
             //大中小图片转化
             $val = business::formatGoodsImg($val);
             //免费配送范围
@@ -59,14 +68,29 @@ class GoodsClass extends BaseClass
                     $val['price'] = $price + $rise['riseAmount'];
                 }
             }
-            //临时加100块
-            //$price = $val['price'];
-            //$val['price'] = $price + 100;
             $shortCover = $val['cover'] ?? '';
             $val['cover'] = imgUtil::groupImg($shortCover);
             $val['shortCover'] = $shortCover;
+            $val['smallCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_130,w_130";
+            $val['bigCover'] = $val['cover'] . "?x-oss-process=image/resize,m_fill,h_700,w_700";
+
+            if ($arrNotEmpty) {
+                $sortIndex = array_search($id, $sortIds);
+                // $newList[$sortIndex] = $val;
+                $val['sortWeight'] = $sortIndex !== false ? $sortIndex : count($sortIds);
+            }
+
             $list[$key] = $val;
         }
+
+        if ($arrNotEmpty) {
+            usort($list, function($a, $b) {
+                return $a['sortWeight'] - $b['sortWeight'];
+            });
+            //return $newList;
+            // return array_values($newList);
+        }
+
         return $list;
     }
 

+ 2 - 3
biz-mall/goods/services/GoodsCategoryService.php

@@ -5,8 +5,7 @@ namespace bizMall\goods\services;
 use bizMall\base\services\BaseService;
 use bizMall\goods\classes\GoodsCategoryClass;
 use bizMall\goods\classes\GoodsClass;
-use Yii;
-use linslin\yii2\curl;
+
 
 class GoodsCategoryService extends BaseService
 {
@@ -24,7 +23,7 @@ class GoodsCategoryService extends BaseService
         }
         $ids = array_column($list, 'gId');
         $list = GoodsService::getAllByCondition(['id' => ['in', $ids]], null, '*');
-        $data['list'] = GoodsClass::groupGoodsBaseInfo($list);
+        $data['list'] = GoodsClass::groupGoodsBaseInfo($list, $ids);
         return $data;
     }
 

+ 4 - 11
common/components/imgUtil.php

@@ -1,11 +1,4 @@
 <?php
-/**
- * Created by PhpStorm.
- * User: ssh <ssh@zhhinc.com>
- * Date: 2019/11/22 0022
- * Time: 9:46
- */
-
 namespace common\components;
 
 use Yii;
@@ -29,14 +22,14 @@ class imgUtil
         }
     }
 
-    //组合出头像 ssh 2021.4.9
-    public static function groupImg($avatar)
+    //组合出图片路径 ssh 2021.4.9
+    public static function groupImg($pic)
     {
         $prefix = self::getPrefix();
-        if (empty($avatar)) {
+        if (empty($pic)) {
             return $prefix . 'hhb_small.png';
         }
-        return $prefix . $avatar;
+        return $prefix . $pic;
     }
 
 }