40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| namespace app\traits;
 | |
| 
 | |
| use app\model\CouponMain;
 | |
| use app\model\UsingRule;
 | |
| use app\model\Coupon;
 | |
| 
 | |
| trait CouponMainTrait
 | |
| {
 | |
|     /**
 | |
|      * 检查优惠券状态是否可以领取
 | |
|      * @param CouponMain $couponMain
 | |
|      * @return bool
 | |
|      */
 | |
|     public function checkCouponMainReceiveStatus(CouponMain $couponMain){
 | |
|         if (empty($couponMain)) {
 | |
|             return $this->json(4001, "优惠券不存在");
 | |
|         }
 | |
|         if ($couponMain->status != CouponMain::status_on) {
 | |
|             return $this->json(4002, "优惠券已停用");
 | |
|         }
 | |
|         if ($couponMain->on_shelf != CouponMain::on_shelf_on) {
 | |
|             return $this->json(4003, "优惠券已下架");
 | |
|         }
 | |
|         $time = time();
 | |
|         if (strtotime($couponMain->start_time) > $time) {
 | |
|             return $this->json(4004, "优惠券还未发行");
 | |
|         }
 | |
| 
 | |
|         if (strtotime($couponMain->end_time) < $time) {
 | |
|             return $this->json(4004, "优惠券已结束使用");
 | |
|         }
 | |
| 
 | |
|         if ($couponMain->using_count <= 0) {
 | |
|             return $this->json(4004, "优惠券已经被领完了");
 | |
|         }
 | |
|         return true;
 | |
|     }
 | |
| } |