| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- /**
- * This is the model class for table "{{useradmin}}".
- *
- * The followings are the available columns in table '{{useradmin}}':
- * @property integer $id
- * @property string $username
- * @property string $password
- * @property string $email
- * @property string $status
- * @property string $role_id
- * @property string $avatar
- * @property string $descr
- * @property string $create_date
- * @property string $update_date
- */
- class Useradmin extends CActiveRecord
- {
- public $verifypassword; //注册中的重复密码
- public $verifyCode; //注册中的验证码
- public $phoneCode; //手机验证码
- /**
- * @return string the associated database table name
- */
- public function tableName()
- {
- return '{{useradmin}}';
- }
- /**
- * @return array validation rules for model attributes.
- */
- public function rules()
- {
- // NOTE: you should only define rules for those attributes that
- // will receive user inputs.
- return array(
- array('username, password, phone', 'required'),
- array('username', 'length', 'max'=>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);
- }
- }
|