| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace app\model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use think\Collection; | 
					
						
							|  |  |  | use think\db\exception\DataNotFoundException; | 
					
						
							|  |  |  | use think\db\exception\DbException; | 
					
						
							|  |  |  | use think\db\exception\ModelNotFoundException; | 
					
						
							| 
									
										
										
										
											2021-11-30 15:26:38 +08:00
										 |  |  | use think\Model; | 
					
						
							| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 优惠券主表 | 
					
						
							|  |  |  |  * Class CouponMain | 
					
						
							|  |  |  |  * @package app\model | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class CouponMain extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |         const status_on     = 0;//进行中
 | 
					
						
							|  |  |  |         const status_off    = 1;//停止
 | 
					
						
							|  |  |  |         const on_shelf_on   = 0;//上架状态
 | 
					
						
							|  |  |  |         const on_shelf_off  = 1;//下架状态
 | 
					
						
							| 
									
										
										
										
											2021-11-24 14:41:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function business() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(Business::class, 'code',"business_code"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-24 16:34:56 +08:00
										 |  |  |     public function couponType() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(CouponType::class, 'id',"type_id"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     public function usingRule() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return $this->hasOne(UsingRule::class, 'coupon_id',"id"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-14 17:34:27 +08:00
										 |  |  |     //创建完成之后
 | 
					
						
							| 
									
										
										
										
											2021-11-30 15:26:38 +08:00
										 |  |  |     public static function onAfterInsert( $obj) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-12-14 17:34:27 +08:00
										 |  |  |         $obj->sort                  = $obj->id; | 
					
						
							|  |  |  |         $obj->using_count           = $obj->count; | 
					
						
							|  |  |  |         $obj->received_count        = 0; | 
					
						
							|  |  |  |         $obj->verification_count    = 0; | 
					
						
							| 
									
										
										
										
											2021-11-30 15:26:38 +08:00
										 |  |  |         $obj->save(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-18 17:57:04 +08:00
										 |  |  | } |