Pārlūkot izejas kodu

用户端使用优惠券

whitefang 1 gadu atpakaļ
vecāks
revīzija
b6e5adf022

+ 4 - 3
app/api/controller/UserCouponController.php

@@ -35,10 +35,11 @@ class UserCouponController extends BaseApiController
             'user_id'=>$this->userId
         ]);
         $result = UserCouponLogic::add($params);
-        if (false !== $result) {
-            return $this->success('领取成功'.implode('\n',$result), [], 1, 1);
+        if(!empty($result)){
+            return $this->fail(implode('\n',$result));
+        }else{
+            return $this->success('领取成功', [], 1, 1);
         }
-        return $this->fail(UserCouponLogic::getError());
     }
 
 

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

@@ -6,6 +6,7 @@ use app\common\model\coupon\CouponRules;
 use app\common\model\coupon\UserCoupon;
 use think\db\Query;
 use think\db\Where;
+use think\Exception;
 use think\facade\Db;
 
 /**
@@ -33,6 +34,7 @@ class UserCouponLogic extends BaseLogic
                 }
                 if($v->remaining_count <= 0 ){
                     $errMsgArr[] = $v->event_name .'数量不足';
+                    continue;
                 }
                 if($userCoupon->where('coupon_id',$v->id)->count()){
                     $errMsgArr[] = $v->event_name . '已领取';
@@ -56,7 +58,9 @@ class UserCouponLogic extends BaseLogic
                     'server_category_name' => $v->server_category_name
                 ];
             }
-            CouponRules::updateWhenCase($updateData);
+            if(!empty($updateData)){
+                CouponRules::updateWhenCase($updateData);
+            }
             if(!empty($createData)){
                 (new UserCoupon())->saveAll($createData);
             }