Explorar o código

更新:商品列表查询修改

shizhongqi hai 1 ano
pai
achega
2ba109b92a
Modificáronse 2 ficheiros con 12 adicións e 11 borrados
  1. 2 1
      app-hd/controllers/GoodsController.php
  2. 10 10
      biz-hd/goods/services/GoodsService.php

+ 2 - 1
app-hd/controllers/GoodsController.php

@@ -113,11 +113,12 @@ class GoodsController extends BaseController
     {
         $get = Yii::$app->request->get();
         $status = isset($get['status']) && is_numeric($get['status']) ? $get['status'] : -1;
-        $cId = isset($get['cId']) && !empty($get['cId']) ? $get['cId'] : 0;
+        $cId = isset($get['cId']) ? intval($get['cId']) : 0;
         $name = isset($get['name']) && !empty($get['name']) ? $get['name'] : '';
         $flowerNum = isset($get['flowerNum']) && $get['flowerNum'] > 0 ? $get['flowerNum'] : 0;
         $flower = isset($get['flower']) ? $get['flower'] : '';
         $hasStock = isset($get['hasStock']) ? $get['hasStock'] : 0;
+
         $where = [];
         if ($status != -1) {
             $where['status'] = $status;

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

@@ -29,7 +29,7 @@ class GoodsService extends BaseService
             // 使用新的分类商品查询方法
             return self::getCategoryGoodsList($where, $page, $pageSize);
         } else {
-            $data = GoodsClass::getList('*', $where, 'updateTime DESC');
+            $data = GoodsClass::getList('*', $where, 'inTurn DESC, sold DESC');
             $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
             if (empty($list)) {
                 return $data;
@@ -127,32 +127,32 @@ class GoodsService extends BaseService
             ->joinWith(['goods' => function($query) use ($where) {
                 // 商品表的筛选条件
                 if (isset($where['mainId'])) {
-                    $query->andWhere(['goods.mainId' => $where['mainId']]);
+                    $query->andWhere(['xhGoods.mainId' => $where['mainId']]);
                 }
                 if (isset($where['delStatus'])) {
-                    $query->andWhere(['goods.delStatus' => $where['delStatus']]);
+                    $query->andWhere(['xhGoods.delStatus' => $where['delStatus']]);
                 }
                 if (isset($where['status'])) {
-                    $query->andWhere(['goods.status' => $where['status']]);
+                    $query->andWhere(['xhGoods.status' => $where['status']]);
                 }
                 if (isset($where['name'])) {
-                    $query->andWhere(['like', 'goods.name', $where['name']]);
+                    $query->andWhere(['like', 'xhGoods.name', $where['name']]);
                 }
                 // 如果需要筛选有库存的商品
                 if (isset($where['hasStock']) && $where['hasStock'] == 1) {
-                    $query->andWhere(['>', 'goods.stock', 0]);
+                    $query->andWhere(['>', 'xhGoods.stock', 0]);
                 }
             }]);
 
         // 分类表的筛选条件
         if (isset($where['cId'])) {
-            $query->andWhere(['goodsCategory.cId' => $where['cId']]);
+            $query->andWhere(['cId' => $where['cId']]);
         }
         if (isset($where['flower'])) {
-            $query->andWhere(['goodsCategory.flower' => $where['flower']]);
+            $query->andWhere(['xhGoodsCategory.flower' => $where['flower']]);
         }
         if (isset($where['flowerNum'])) {
-            $query->andWhere(['goodsCategory.flowerNum' => $where['flowerNum']]);
+            $query->andWhere(['xhGoodsCategory.flowerNum' => $where['flowerNum']]);
         }
 
         // 计算总数
@@ -163,7 +163,7 @@ class GoodsService extends BaseService
         $query->offset($offset)->limit($pageSize);
 
         // 排序
-        $query->orderBy(['goodsCategory.inTurn' => SORT_DESC]);
+        $query->orderBy(['xhGoods.inTurn' => SORT_DESC, 'xhGoods.sold' => SORT_DESC]);
 
         // 获取数据
         $list = $query->all();