wesmiler 2 سال پیش
والد
کامیت
fee8236cf0
2فایلهای تغییر یافته به همراه30 افزوده شده و 12 حذف شده
  1. 28 11
      app/Services/Api/GoodsService.php
  2. 2 1
      app/Services/Api/MemberService.php

+ 28 - 11
app/Services/Api/GoodsService.php

@@ -232,11 +232,32 @@ class GoodsService extends BaseService
         }
 
         $goods = [];
+        $skuList = [];
+        $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
+        if($usdtPrice<=0){
+            $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
+            $usdtPrice = $usdtCnyPrice>0 && $usdtCnyPrice< 100? $usdtCnyPrice : 0;
+        }
+        $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
+        $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
+
         if($goodsId){
             $info = $this->getInfo($goodsId, $userId, false);
             if($info){
+
                 $info['num'] = $num;
-                $info['sku'] = GoodsSkuModel::where(['goods_id'=> $goodsId,'sku_id'=> $skuId,'mark'=>1])->first();
+                $info['sku_id'] = $skuId;
+                $skuInfo = GoodsSkuModel::where(['goods_id'=> $goodsId,'sku_id'=> $skuId,'mark'=>1])->first();
+                $costPrice = isset($skuInfo['retail_price'])? $skuInfo['retail_price'] : 0;
+                if($costPrice){
+                    $info['cost_price'] = $usdtPrice > 0 ? moneyFormat($costPrice / $usdtPrice * $xdPrice, 2) : $costPrice;
+                }
+
+                $skuList[$goodsId] = [
+                    'sku_id'=> $skuId,
+                    'num'=> $num
+                ];
+                $info['sku'] = $skuInfo;
                 $goods[] = $info;
             }
         }else {
@@ -246,7 +267,7 @@ class GoodsService extends BaseService
                 ->whereIn('a.id', $cartIds)
                 ->where(['a.status' => 1, 'a.mark' => 1,'b.status'=>1,'b.mark'=>1])
                 ->where('b.cost_price', '>', 0)
-                ->select(['b.goods_id','b.merch_id','b.goods_name','b.supply_type','b.main_img','b.cost_price','b.retail_price','b.limit_num','b.lowest_num','b.brand_name','a.num','a.sku_id'])
+                ->select(['b.goods_id','b.merch_id','b.goods_name','b.supply_type','b.main_img','b.retail_price','b.limit_num','b.lowest_num','b.brand_name','a.num','a.sku_id','a.retail_price as cost_price'])
                 ->get();
             if($goods){
 
@@ -256,14 +277,6 @@ class GoodsService extends BaseService
                 $locale = $locale ? $locale : 'zh-cn';
                 $supplyList = config('goods.supplyList');
 
-                $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
-                if($usdtPrice<=0){
-                    $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
-                    $usdtPrice = $usdtCnyPrice>0 && $usdtCnyPrice< 100? $usdtCnyPrice : 0;
-                }
-                $xdPrice = ConfigService::make()->getConfigByCode('xd_price', 100);
-                $xdPrice = $xdPrice > 0 && $xdPrice <= 10000 ? $xdPrice : 100;
-
                 foreach ($goods as &$item) {
                     $item['detail_img'] = isset($item['detail_img']) && $item['detail_img'] ? json_decode($item['detail_img'], true) : [];
                     $item['supply_name'] = isset($supplyList[$item['supply_type']]) ? $supplyList[$item['supply_type']] : '';
@@ -271,6 +284,10 @@ class GoodsService extends BaseService
                     $item['xd_price_rate'] = $xdPrice;
                     $item['original_price'] = $item['cost_price'];
                     $item['cost_price'] = $usdtPrice > 0 ? moneyFormat($item['cost_price'] / $usdtPrice * $xdPrice, 2) : $item['cost_price'];
+                    $skuList[$item['goods_id']] = [
+                        'sku_id'=> $item['sku_id'],
+                        'num'=> $item['num']
+                    ];
                 }
                 unset($item);
             }
@@ -281,7 +298,7 @@ class GoodsService extends BaseService
             return false;
         }
 
-        return $goods;
+        return ['sku_list'=> $skuList, 'goods'=> $goods];
     }
 
     /**

+ 2 - 1
app/Services/Api/MemberService.php

@@ -139,7 +139,8 @@ class MemberService extends BaseService
             }else if($type == 'buy'){
                 $address = MemberAddressService::make()->getBindInfo($userId);
                 $info['address'] = $address;
-                $info['address_id'] = isset($address['district_code'])? $address['district_code'] : '';
+                $info['freight_address_id'] = isset($address['district_code'])? $address['district_code'] : '';
+                $info['address_id'] = isset($address['id'])? $address['id'] : 0;
                 $info['cart_num'] = GoodsService::make()->getCartCount($info['id']);
             }else if($type == 'upgrade'){
                 $level = isset($info['level'])? $info['level'] : [];