Browse Source

fix goods main image

stanley-king 7 years ago
parent
commit
49bee8f4b0

+ 3 - 2
helper/goods/commonid_helper.php

@@ -45,12 +45,13 @@ class commonid_helper
             else
             {
                 $mod_goods = Model('goods');
-                $goods = $mod_goods->getGoodsCommonList(['goods_commonid' => $commonid],'store_id,goods_image');
-                if(empty($goods)) {
+                $items = $mod_goods->getGoodsCommonList(['goods_commonid' => $commonid],'store_id,goods_image');
+                if(empty($items)) {
                     return false;
                 }
                 else
                 {
+                    $goods = $items[0];
                     $storeid = intval($goods['store_id']);
                     $image = $goods['goods_image'];
                     if($storeid > 0 && !empty($image)) {

+ 4 - 3
helper/goods_helper.php

@@ -21,8 +21,9 @@ class goods_helper
                   is_fcode,have_gift,goods_mobile_name,goods_spec,goods_collect,
                   goods_addtime,goods_edittime';
 
-    public function __construct() {
-
+    private $mUseMainPage;
+    public function __construct($main_page = true) {
+        $this->mUseMainPage = $main_page;
     }
 
     public function get_distinct($goods_commonids)
@@ -134,7 +135,7 @@ class goods_helper
         foreach ($goods_list as $goods)
         {
             $summary = new goods_summary($goods);
-            $info = $summary->format($act_type,$act_id,$favorate,$anotice);
+            $info = $summary->format($act_type,$act_id,$favorate,$anotice,$this->mUseMainPage);
             $goods_id = intval($goods['goods_id']);
             $sort_summarys[$goods_id] = $info;
 

+ 13 - 3
helper/model/goods_summary.php

@@ -79,7 +79,7 @@ class goods_summary
         return ($add_time > $start || $edit_time > $start);
     }
 
-    public function format(&$act_type, &$act_id,user_session\favorite $favorate,user_session\anotice $anotice)
+    public function format(&$act_type, &$act_id,user_session\favorite $favorate,user_session\anotice $anotice,$main_page)
     {
         $summary = [];
 
@@ -100,8 +100,18 @@ class goods_summary
         $summary['goods_marketprice'] = $this->goods_info['goods_marketprice'];
         $summary['goods_promotion_price'] = $this->goods_info['goods_promotion_price'];
 
-        $summary['goods_image_url'] = self::img_url($this->goods_info['goods_image'],$this->goods_info['store_id']);
-        //$summary['goods_main_image'] = commonid_helper::instance()->main_image($summary['goods_id']);
+        if($main_page)
+        {
+            $image = commonid_helper::instance()->main_image($summary['goods_id']);
+            if(empty($image)) {
+                $summary['goods_image_url'] = self::img_url($this->goods_info['goods_image'],$this->goods_info['store_id']);
+            } else {
+                $summary['goods_image_url'] = $image;
+            }
+        }
+        else {
+            $summary['goods_image_url'] = self::img_url($this->goods_info['goods_image'],$this->goods_info['store_id']);
+        }
 
         $summary['goods_state'] = intval($this->goods_info['goods_state']);
         $summary['goods_salenum'] = intval($this->goods_info['goods_salenum']) + 19;

+ 3 - 3
mobile/control/cart.php

@@ -142,7 +142,7 @@ class cartControl extends mobileControl
             $cart_infos[] = $cart_item;
         }
 
-        $helper = new goods_helper();
+        $helper = new goods_helper(false);
         $summaries = $helper->cart_summary($goods_ids,$related_goods);
         $summary_list = $summaries['summary'];
         if(!empty($related_goods)) {
@@ -234,7 +234,7 @@ class cartControl extends mobileControl
                 $blocks = $this->format($fcodes);
             }
 
-            $helper = new goods_helper();
+            $helper = new goods_helper(false);
             $ret = $helper->cart_summary($gids,$related_goods);
 
             return self::outsuccess(array('special_list' => $blocks,
@@ -354,7 +354,7 @@ class cartControl extends mobileControl
             }
             else
             {
-                $helper = new goods_helper();
+                $helper = new goods_helper(false);
                 $summaries = $helper->cart_summary($gids,$related_goods);
                 $summary_list = $summaries['summary'];
                 if(!empty($related_goods)) {

+ 1 - 1
mobile/control/goods_common.php

@@ -37,7 +37,7 @@ class goods_commonControl extends mobileControl
                 Model('goods_browse')->addViewedGoods($goods_id,$_SESSION['member_id'],$_SESSION['store_id']);
             }
 
-            $helper = new goods_helper();
+            $helper = new goods_helper(false);
             $ret = $helper->get_spu($common_id,$goods_id,$err);
             if($ret == false) {
                 return self::outerr($err['code'],$err['msg']);

+ 1 - 1
mobile/control/member_fcode.php

@@ -69,7 +69,7 @@ class member_fcodeControl extends mbMemberControl
                 $blocks = $this->format($fcodes);
             }
 
-            $helper = new goods_helper();
+            $helper = new goods_helper(false);
             $ret = $helper->cart_summary($gids,$related_goods);
 
             return self::outsuccess(array('special_list' => $blocks,