'满减券', 2=>'无门槛券' ]; const T_FULL=1; const T_WU=2; /** * @return string[] */ public static function getTypes(): array { return self::$types; } public function bindGoods(){ return $this->hasMany(CouponGoods::class); } protected static function init() { self::beforeWrite(function (self $coupon){ if($coupon['type']==2){ unset($coupon['amount_full']); } }); } public function sendToUser($users,$num){ $users=array_unique($users); $users=array_filter($users); $this['num_send']=$this['num_send']+$num*count($users); if($this['num_send']>$this['num']){ throw_user("[{$this['id']}]券数量不足"); } $this->save(); foreach ($users as $userId){ $user=User::find($userId); if($user){ for ($i=0;$i<$num;$i++) { UserCoupon::toUser($user, $this); } SiteMsg::sendMsg(SiteMsg::TYPE_COUPON,$user); } } } }