| 
					
				 | 
			
			
				@@ -425,19 +425,24 @@ class CouponController extends Curd 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             if ($chooseCoupon['nbr'] > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 // 有发行数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 if ($coupon['coupon_number'] != 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    // 查询共发行了多少张了 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    $count = CouponDetail::where('join_detail_coupon_id', $coupon['coupon_id'])->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    // 查询还有多少张没领的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    $count = CouponDetail::where('join_detail_coupon_id', $coupon['coupon_id']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        ->whereIn('coupon_detail_status',['INIT','PENDING']) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        ->count(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     if (!isset($couponNbr[$coupon['coupon_id']])) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                         $couponNbr[$coupon['coupon_id']] = $count; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    if ($couponNbr[$coupon['coupon_id']] + $chooseCoupon['nbr'] > $coupon['coupon_number']) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    if ($couponNbr[$coupon['coupon_id']] - $chooseCoupon['nbr'] < 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                         throw new BusinessException($coupon['coupon_name'] . "超出发行数量"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    $couponNbr[$coupon['coupon_id']] = $couponNbr[$coupon['coupon_id']] + $chooseCoupon['nbr']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                for ($i = 0; $i < $chooseCoupon['nbr']; $i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    CouponDetailService::customSendCoupon($params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    $couponNbr[$coupon['coupon_id']] = $couponNbr[$coupon['coupon_id']] - $chooseCoupon['nbr']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    $params['chooseCouponNbr'] = $chooseCoupon['nbr']; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    // 匹配已发行的优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    CouponDetailService::customSendCouponHave($params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    for ($i = 0; $i < $chooseCoupon['nbr']; $i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                        CouponDetailService::customSendCoupon($params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 |