| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\traits; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use think\Model; | 
					
						
							|  |  |  | use app\model\Coupon; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | trait CouponTrait | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /**消费者持有优惠券总数 | 
					
						
							|  |  |  |      * @param string $userCode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function consumerTotalCoupon($userCode) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Coupon::where("consumer_code", $userCode)->count("id"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**消费者已使用优惠券总数 | 
					
						
							|  |  |  |      * @param string $userCode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function consumerUsedTotalCoupon($userCode) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Coupon::where("consumer_code", $userCode)->where("is_verificated", Coupon::is_verificated_on)->count("id"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**消费者已使用优惠券总数 | 
					
						
							|  |  |  |      * @param string $userCode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function consumerNotUsedTotalCoupon($userCode) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return Coupon::where("consumer_code", $userCode)->where("is_verificated", Coupon::is_verificated_off)->count("id"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /**消费者已使用优惠券总数 | 
					
						
							|  |  |  |      * @param string $userCode | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array | 
					
						
							|  |  |  |      * @throws \Exception | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |     public function consumerCouponList($where, $page, $size) | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-11-23 17:13:55 +08:00
										 |  |  |         return Coupon::findList($where, [], $page, $size, function ($q){ | 
					
						
							|  |  |  |             return $q->with("couponBill"); | 
					
						
							|  |  |  |         }, ["id" => "desc"]); | 
					
						
							| 
									
										
										
										
											2021-11-19 19:06:22 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |