setter
							parent
							
								
									c445c5fcc2
								
							
						
					
					
						commit
						4f75f51d50
					
				|  | @ -188,12 +188,14 @@ class Coupon extends Base | ||||||
|             return $q->with("business")->lock(true); |             return $q->with("business")->lock(true); | ||||||
|         }); |         }); | ||||||
| 
 | 
 | ||||||
|  |         try { | ||||||
|             //检查优惠券状态
 |             //检查优惠券状态
 | ||||||
|         $checkCouponMainReceiveStatus = CouponRepository::getInstance()->checkCouponMainReceiveStatus($couponMain); |            CouponRepository::getInstance()->checkCouponMainReceiveStatus($couponMain); | ||||||
|         if( $checkCouponMainReceiveStatus !== true ){ |         }catch (RepositoryException $e){ | ||||||
|             return $checkCouponMainReceiveStatus; |             return $this->json(4001,$e->getMessage()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|         try { |         try { | ||||||
|             //检查是否可以领取  0可领取 1已领取
 |             //检查是否可以领取  0可领取 1已领取
 | ||||||
|            AccountRepository::getInstance()->getCouponReceiveStatusText($account,$couponMain);//领取状态
 |            AccountRepository::getInstance()->getCouponReceiveStatusText($account,$couponMain);//领取状态
 | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| namespace app\traits; | namespace app\traits; | ||||||
| 
 | 
 | ||||||
|  | use app\exception\RepositoryException; | ||||||
| use app\model\CouponMain; | use app\model\CouponMain; | ||||||
| use app\model\UsingRule; | use app\model\UsingRule; | ||||||
| use app\model\Coupon; | use app\model\Coupon; | ||||||
|  | @ -15,25 +16,25 @@ trait CouponMainTrait | ||||||
|      */ |      */ | ||||||
|     public function checkCouponMainReceiveStatus(CouponMain $couponMain){ |     public function checkCouponMainReceiveStatus(CouponMain $couponMain){ | ||||||
|         if (empty($couponMain)) { |         if (empty($couponMain)) { | ||||||
|             return $this->json(4001, "优惠券不存在"); |             throw  new  RepositoryException("优惠券不存在"); | ||||||
|         } |         } | ||||||
|         if ($couponMain->status != CouponMain::status_on) { |         if ($couponMain->status != CouponMain::status_on) { | ||||||
|             return $this->json(4002, "优惠券已停用"); |             throw  new  RepositoryException("优惠券已停用"); | ||||||
|         } |         } | ||||||
|         if ($couponMain->on_shelf != CouponMain::on_shelf_on) { |         if ($couponMain->on_shelf != CouponMain::on_shelf_on) { | ||||||
|             return $this->json(4003, "优惠券已下架"); |             throw  new  RepositoryException("优惠券已下架"); | ||||||
|         } |         } | ||||||
|         $time = time(); |         $time = time(); | ||||||
|         if (strtotime($couponMain->start_time) > $time) { |         if (strtotime($couponMain->start_time) > $time) { | ||||||
|             return $this->json(4004, "优惠券还未发行"); |             throw  new  RepositoryException("优惠券还未到开始使用时间"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (strtotime($couponMain->end_time) < $time) { |         if (strtotime($couponMain->end_time) < $time) { | ||||||
|             return $this->json(4004, "优惠券已结束使用"); |             throw  new  RepositoryException("优惠券已结束使用"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if ($couponMain->using_count <= 0) { |         if ($couponMain->using_count <= 0) { | ||||||
|             return $this->json(4004, "优惠券已经被领完了"); |             throw  new  RepositoryException("优惠券已经被领完了"); | ||||||
|         } |         } | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue