Parcourir la source

修复SPU中单个商品库存不足,搜索出来的就显示为库存不足的问题

stanley-king il y a 8 ans
Parent
commit
3e618692ba
2 fichiers modifiés avec 41 ajouts et 4 suppressions
  1. 40 3
      data/model/goods.model.php
  2. 1 1
      mobile/control/search.php

+ 40 - 3
data/model/goods.model.php

@@ -98,13 +98,50 @@ class goodsModel extends Model
         //去掉多规格颜色显示 好商城V3-B11
 //        $field = "CONCAT(goods_commonid,',',color_id) as nc_distinct ," . $field;
 //        $count = $this->getGoodsOnlineCount($condition, "distinct CONCAT(goods_commonid,',',color_id)");
-        $field = "CONCAT(goods_commonid) as nc_distinct ," . $field;
+        $fieldex = "CONCAT(goods_commonid) as nc_distinct, max(goods_storage) as max_goods_storage, " . $field;
         $count = $this->getGoodsOnlineCount($condition, "distinct CONCAT(goods_commonid)");
         $goods_list = array();
         if ($count != 0) {
-            $goods_list = $this->getGoodsOnlineList($condition, $field, $page, $order, 0, 'nc_distinct', false, $count);
+            $goods_list = $this->getGoodsOnlineList($condition, $fieldex, $page, $order, 0, 'nc_distinct', false, $count);
         }
-        return $goods_list;
+
+        $goods_ret = array();
+        $goods_cids = array();
+        foreach($goods_list as $goods)
+        {
+            $g_storage = intval($goods['goods_storage']);
+            if($g_storage > 0 || $g_storage == intval($goods['max_goods_storage'])) {
+                array_push($goods_ret,$goods);
+            } else {
+                array_push($goods_cids,intval($goods['goods_commonid']));
+            }
+        }
+
+        if(!empty($goods_cids))
+        {
+            arsort($goods_cids);
+            $condition['goods_commonid'] = array('in', $goods_cids);
+            $items = $this->cls()->table('goods')->field($field)->where($condition)->order('goods_commonid desc,goods_storage desc')->limit(false)->select();
+
+            foreach($goods_cids as $commonid)
+            {
+                $fAdd = true;
+                foreach($items as $key => $goods)
+                {
+                    if($commonid == intval($goods['goods_commonid'])) {
+                        if($fAdd) {
+                            array_push($goods_ret,$goods);
+                            $fAdd = false;
+                        }
+                        unset($items[$key]);
+                    }
+                    else {
+                        break;
+                    }
+                }
+            }
+        }
+        return $goods_ret;
     }
 
     /**

+ 1 - 1
mobile/control/search.php

@@ -93,7 +93,7 @@ class searchControl extends mobileHomeControl
         }
 
         $helper = new goods_helper();
-        $goods_list = $helper->get_infos($goods_ids,$fieldstr);
+        $goods_list = $helper->get_infos($goods_ids);
 
 //        //处理商品列表(抢购、限时折扣、商品图片)
 //        $goods_list = $this->_goods_list_extend($goods_list);