20), array('username','unique','message'=>'用户名已被占用'), array('password', 'length', 'max'=>50), array('verifypassword', 'length', 'max'=>50), array('verifypassword', 'compare', 'compareAttribute'=>'password', 'message'=>'请再输入确认密码', 'on'=>'register'), array('auth, status', 'safe'), // The following rule is used by search(). // @todo Please remove those attributes that should not be searched. array('id, username, password, auth, status, verifypassword, phone,email', 'safe', 'on'=>'search'), //找回密码相关 // array('username', 'safe', 'on'=>'findpassword'), array('username', 'exist', 'on'=>'findpassword', 'message'=>'{attribute}{value}不存在!'), array('password', 'required', 'on'=>'changepassword'), array('verifypassword', 'compare', 'compareAttribute'=>'password', 'on'=>'changepassword'), // 检查手机验证码 array('phoneCode', 'required', 'on'=>'register'), array('phoneCode', 'regVerifyCodeCheck', 'on'=>'register'), array('phone', 'checkPhoneRegNum', 'on'=>'register'), ); } public function usernameCheck($attribute,$params) { if(!$this->hasErrors()) { if (strpos($this->username, ':') || strpos($this->username, ':')) { $this->addError('username', '用户名不能包含冒号!'); } } } /** * 检查手机验证码 * @param unknown $attribute * @param unknown $params */ public function regVerifyCodeCheck($attribute,$params) { if(!$this->hasErrors()) { $result = CheckVerifyCode($this->phoneCode); if(isset($result['errmsg'])) { $this->addError("phoneCode", $result['errmsg']); return false; } } } /** * 检查手机验证码 * @param unknown $attribute * @param unknown $params */ public function checkPhoneRegNum($attribute,$params) { if(!$this->hasErrors()) { $result = self::getPhoneRegNum($this->phone); if($result >= 3) { $this->addError("phone", '一个手机号码最多只能注册3个乐外卖账号!'); return false; } } } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'username' => '账号', 'password' => '密码', 'verifypassword' => '确认密码', 'phone' =>'手机号码', 'email' =>'邮箱地址', ); } /** * Retrieves a list of models based on the current search/filter conditions. * * Typical usecase: * - Initialize the model fields with values from filter form. * - Execute this method to get CActiveDataProvider instance which will filter * models according to data in model fields. * - Pass data provider to CGridView, CListView or any similar widget. * * @return CActiveDataProvider the data provider that can return the models * based on the search/filter conditions. */ public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $criteria->compare('username',$this->username,true); $criteria->compare('password',$this->password,true); $criteria->compare('verifypassword',$this->verifypassword,true); $criteria->compare('phone',$this->phone,true); $criteria->compare('email',$this->email,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); } /** * Returns the static model of the specified AR class. * Please note that you should have this exact method in all your CActiveRecord descendants! * @param string $className active record class name. * @return Useradmin the static model class */ public static function model($className=__CLASS__) { return parent::model($className); } public function searchusing() { $criteria=new CDbCriteria; $criteria->addCondition('status=1'); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, 'pagination'=>['pageSize'=>20] )); } public function extendDueDate($days) { $oldDueDate = $this->due_date > date("Y-m-d H:i:s") ? $this->due_date : date("Y-m-d H:i:s"); $year = (int) substr($oldDueDate, 0, 4); $mon = (int) substr($oldDueDate, 5, 2); $mday = (int) substr($oldDueDate, 8, 2); $hour = (int) substr($oldDueDate, 11, 2); $minute = (int) substr($oldDueDate, 14, 2); $second = (int) substr($oldDueDate, 17, 2); $this->due_date = date("Y-m-d H:i:s", mktime($hour, $minute, $second, $mon, $mday+$days, $year)); } /** * 取出手机号码的注册次数 * @param unknown $phone */ public static function getPhoneRegNum($phone) { if(empty($phone)) { return false; } $result = self::model()->count('phone=:phone', array(':phone'=>$phone)); return intval($result); } }