ソースを参照

我的优惠券列表-订单可用优惠券

whitefang 1 年間 前
コミット
ad88c82ccc
1 ファイル変更9 行追加5 行削除
  1. 9 5
      app/api/logic/UserCouponLogic.php

+ 9 - 5
app/api/logic/UserCouponLogic.php

@@ -162,14 +162,18 @@ class UserCouponLogic extends BaseLogic
     public static function categoryWithAmountLists($params)
     {
         try{
-            $data = UserCoupon::with(['couponCategory'=>function ($query) use ($params) {
-                $query->where('goods_category_id',$params['goods_category_id']);
-            }])->where('user_id',$params['user_id'])
+            $coupon_all_ids =UserCoupon::where('user_id',$params['user_id'])
                 ->where('voucher_count','>',0)
                 ->where('voucher_status',0)
-                ->append(['discount_ratio_text'])
                 ->where('amount_require','<=',$params['amount'])
-                ->visible(['id','amount','amount_require','begin_use','discount_ratio','event_name','expire_time','max_deductible_price','server_category_name','mold_type'])
+                ->column('coupon_id');
+
+            $coupon_ids = CouponCategory::where('goods_category_id',$params['goods_category_id'])->whereIn('coupon_id',$coupon_all_ids)->column('coupon_id');
+
+            $data = UserCoupon::where('user_id',$params['user_id'])
+                ->whereIn('coupon_id',$coupon_ids)
+                ->append(['discount_ratio_text'])
+                ->visible(['id','coupon_id','amount','amount_require','begin_use','discount_ratio','event_name','expire_time','max_deductible_price','server_category_name','mold_type'])
                 ->select()->toArray();
             foreach($data as $k => $v){
                 $data[$k]['begin_use'] = date("Y-m-d H:i:s",$v['begin_use'] );