示例#1
0
 public function register()
 {
     if ($this->provinceId == "" || $this->majorJobId == "") {
         CommonFunctions::createAlertMessage("省份或者专业类型不能为空", "error");
         return false;
     }
     $majorJob = MajorJob::findOne($this->majorJobId);
     if ($this->provinceId != $majorJob['provinceId']) {
         CommonFunctions::createAlertMessage("专业类型与所处省份不一致,请重新选择", "error");
         return false;
     }
     $openId = Yii::$app->session->get('openId');
     $user = Users::findByWeiXin($openId);
     if (!$user) {
         //如果用户不存在,即关注的时候没有把微信的相关信息存入
         $user = new Users();
         $user->weixin = $openId;
     }
     if (!$user->registerDate || $user->registerDate == 0) {
         //如果用户注册日期不存在或为0,表明用户第一次实名认证
         $user->bitcoin = 0;
         $user->registerDate = DateFunctions::getCurrentDate();
         $user->role = Users::ROLE_A;
         $user->state = Users::STATE_NORMAL;
         do {
             //保证生成的推荐码的唯一
             $recommendCode = CommonFunctions::createCommonRecommendCode();
         } while (Users::findUserByRecommendCode($recommendCode));
         $user->recommendCode = $recommendCode;
         if ($this->tjm) {
             //推荐码绑定推荐人
             $this->recommendUser = Users::findUserByRecommendCode($this->tjm);
             if ($this->recommendUser) {
                 if ($this->recommendUser['userId'] != $user['userId']) {
                     //推荐人不是自己
                     $user->recommendUserID = $this->recommendUser['userId'];
                 }
             }
         }
     }
     $user->nickname = $this->nickname;
     $user->realname = $this->realname;
     $user->provinceId = $this->provinceId;
     $user->majorJobId = $this->majorJobId;
     $user->cellphone = $this->cellphone;
     $user->company = $this->company;
     $user->address = $this->address;
     if (!$user->save()) {
         throw new Exception("RegisterForm register Save Error");
     }
     Yii::$app->cache->delete($user->cellphone);
     //注册成功后将验证码缓存清除
     Yii::$app->session->set('user', $user);
     return true;
 }