wesmiler 1 سال پیش
والد
کامیت
fbcf5b97ce
2فایلهای تغییر یافته به همراه22 افزوده شده و 18 حذف شده
  1. 20 13
      app/Services/Api/GoodsService.php
  2. 2 5
      app/Services/Api/OrderService.php

+ 20 - 13
app/Services/Api/GoodsService.php

@@ -363,7 +363,7 @@ class GoodsService extends BaseService
             return $datas;
         }
 
-        $goods = $this->model->with(['skuList'])->from('goods as a')
+        $goods = $this->model->from('goods as a')
             ->whereIn('a.goods_id',$ids)
             ->where(['a.status' => 1, 'a.mark' => 1])
             ->where('a.retail_price', '>', 0)
@@ -371,18 +371,6 @@ class GoodsService extends BaseService
             ->get();
         $goods = $goods? $goods->toArray() : [];
         if($goods){
-            foreach ($goods as &$item){
-                $skuList = isset($item['sku_list'])? $item['sku_list'] : [];
-                if($skuList){
-                    $skus = [];
-                    foreach ($skuList as $v){
-                        $v['retail_price'] = $this->getRealSalePrice($v['plat_price']);
-                        $skus[$v['sku_id']] = $v;
-                    }
-
-                    $item['sku_list'] = $skus;
-                }
-            }
             RedisService::set($cacheKey, $goods, rand(5,10));
         }
         return $goods;
@@ -579,6 +567,25 @@ class GoodsService extends BaseService
         }
     }
 
+    public function getSkuInfo($sakuId)
+    {
+        $cacheKey = "caches:goodsSku:{$sakuId}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $data = GoodsSkuModel::where(['sku_id'=> $sakuId,'status'=>1,'mark'=>1])
+            ->select(['id','sku_id','goods_id','retail_price','plat_price','sku_sn','sku_name','main_img','attr'])
+            ->first();
+        $data = $data? $data->toArray() : [];
+        if($data){
+            RedisService::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
     /**
      * 更新浏览量
      * @param $userId

+ 2 - 5
app/Services/Api/OrderService.php

@@ -212,8 +212,6 @@ class OrderService extends BaseService
         $merchId = 0;
         $orderNo = get_order_num('XS');
 
-        var_dump($skuList);
-        return false;
         // 价格参数
         $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
         if($usdtPrice<=0){
@@ -228,9 +226,8 @@ class OrderService extends BaseService
             $num = isset($skuList[$goodsId]['num'])? intval($skuList[$goodsId]['num']) : 0;
             $skuId = isset($skuList[$goodsId]['sku_id'])? intval($skuList[$goodsId]['sku_id']) : 0;
 
-            $goodsSkuList = isset($item['sku_list'])? $item['sku_list'] : [];
-            $skuInfo = isset($goodsSkuList[$skuId])? $goodsSkuList[$skuId] : [];
-            $price = isset($skuInfo['retail_price'])? $skuInfo['retail_price'] : 0;
+            $skuInfo = GoodsService::make()->getSkuInfo($skuId);
+            $price = isset($skuInfo['plat_price'])? $skuInfo['plat_price'] : 0;
             $attr = isset($skuAttr[$goodsId])? $skuAttr[$goodsId] : [];
             if($num>0 && $skuId >0 && $price>0){
                 $item['price'] = GoodsService::make()->getRealSalePrice($price); // 浮动后星豆价