Sfoglia il codice sorgente

活动商品详情显示问题

whitefang 1 anno fa
parent
commit
04a8a38d3c
2 ha cambiato i file con 14 aggiunte e 5 eliminazioni
  1. 2 2
      app/api/controller/GoodsController.php
  2. 12 3
      app/api/logic/GoodsLogic.php

+ 2 - 2
app/api/controller/GoodsController.php

@@ -30,7 +30,7 @@ class GoodsController extends BaseApiController
     public function categoryDetail()
     {
         $params = (new GoodsValidate())->goCheck('category');
-        $result = GoodsLogic::detail($params['goods_category_id'],'category');
+        $result = GoodsLogic::detail($params['goods_category_id'],'category',$this->userId);
         return $this->data($result);
     }
 
@@ -44,7 +44,7 @@ class GoodsController extends BaseApiController
     public function eventGoodsDetail()
     {
         $params = (new GoodsValidate())->goCheck('goods');
-        $result = GoodsLogic::eventDetail($params['id']);
+        $result = GoodsLogic::eventDetail($params['id'],$this->userId);
         return $this->data($result);
     }
 

+ 12 - 3
app/api/logic/GoodsLogic.php

@@ -16,7 +16,7 @@ class GoodsLogic extends BaseLogic
 {
 
     /**
-     * @notes 文章详情
+     * @notes 商品详情
      * @param $goods_id
      * @param $userId
      * @return array
@@ -71,11 +71,20 @@ class GoodsLogic extends BaseLogic
         return $goods;
     }
 
-    public static function eventDetail($id){
+    public static function eventDetail($id,$userId){
         $goods = Goods::where(['id'=>$id])->visible([
                 'id','goods_image','goods_name','goods_banners','good_unit','sell_num','base_service_fee',
                 'service_total','service_fee','service_image','fee_schedule','warranty_period','goods_payment_type','goods_category_id'
-            ])->select()->toArray();
+            ])->select()
+            ->each(function (&$item, $key) use ($userId){
+                //判定是否存在可使用的用户优惠券,存在的话直接更新展示价格
+                if($userId!=0){
+                    $result = UserCouponLogic::categoryWithAmountLists(['user_id'=>$userId,'amount'=>$item['service_fee'],'goods_category_id'=>$item['goods_category_id'],'goods_id'=>$item['id']]);
+                    if(!empty($result[0]['amount'])){
+                        $item['base_service_fee'] = '券后'.($item['base_service_fee'] - $result[0]['amount']);
+                    }
+                }
+            })->toArray();
 
         if(!empty($goods)){
             $data = [];