Kaynağa Gözat

优化:订单详情页商品封面显示SKU图

萤火科技 4 yıl önce
ebeveyn
işleme
7969ff027d
1 değiştirilmiş dosya ile 11 ekleme ve 1 silme
  1. 11 1
      app/api/service/order/Checkout.php

+ 11 - 1
app/api/service/order/Checkout.php

@@ -793,7 +793,7 @@ class Checkout extends BaseService
                 'goods_id' => $goods['goods_id'],
                 'goods_name' => $goods['goods_name'],
                 'goods_no' => $goods['goods_no'] ?: '',
-                'image_id' => (int)current($goods['goods_images'])['file_id'],
+                'image_id' => $this->getGoodsImageId($goods),
                 'deduct_stock_type' => $goods['deduct_stock_type'],
                 'spec_type' => $goods['spec_type'],
                 'goods_sku_id' => $goods['skuInfo']['goods_sku_id'],
@@ -822,6 +822,16 @@ class Checkout extends BaseService
         $this->model->goods()->saveAll($goodsList) !== false;
     }
 
+    /**
+     * 获取订单商品的封面图(优先sku封面图)
+     * @param $goods
+     * @return int
+     */
+    private function getGoodsImageId($goods): int
+    {
+        return $goods['skuInfo']['image_id'] ?: (int)current($goods['goods_images'])['file_id'];
+    }
+
     /**
      * 更新商品库存 (针对下单减库存的商品)
      * @param $order