Exemplo n.º 1
0
 /**
  * 判定用户session 是否失效
  * @param $sessionkey
  * @return bool
  */
 public static function sessionkey_istimeout($sessionkey)
 {
     $is_timeout = Sessionkey::find()->where(['sessionkey' => $sessionkey, 'status' => Sessionkey::STATUS_DELETED])->asArray()->one();
     if ($is_timeout) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  *以后做推广活动进行的注册操作
  * @param $phone 手机号
  * @param $pwd  密码
  * @param $phone_code 手机验证码
  * @param $from 用户来源
  * @param string  $userIp 注册ip
  * @param string  $from  注册来源
  * @return array
  */
 public static function the_promotion_register($phone, $pwd, $phone_code, $from)
 {
     //注册来源
     $from = $from;
     //判定手机号是否注册
     $flag = self::phoneIsRegister($phone);
     if ($flag) {
         $return = array('errorNum' => '1', 'errorMsg' => '此手机号已注册,请直接登录', 'data' => null);
         return $return;
     } elseif (!preg_match('/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)[0-9a-zA-Z]{6,16}$/', $pwd)) {
         $return = array('errorNum' => '1', 'errorMsg' => '密码应该是数字、字母组成的6到16位字符', 'data' => null);
         return $return;
     }
     //手机短息验证码验证
     $check = Port::checkPhnoe($phone, $phone_code);
     $session_key = "";
     //生成app的密码
     $app_pwd = md5(sha1($pwd) . time());
     // 根据ip获取地区---Yii::$app->request->userIp
     $userIp = Yii::$app->request->userIp;
     $area = self::get_area($userIp);
     $area = $area ? $area : '地球';
     if (!$check['errorNum']) {
         //事物回滚
         $transaction = \Yii::$app->db->beginTransaction();
         try {
             $user = new UcenterMember();
             $user->username = $phone;
             $user->phone = $phone;
             $user->setPassword(trim($pwd));
             $user->create_ip = $userIp;
             $user->create_area = $area;
             $user->create_channel = (int) $from;
             $user->status = UcenterMember::STATUS_ACTIVE;
             $user->lock = UcenterMember::TYPE_UNLOCK;
             //app密码设定
             $user->app_pwd = $app_pwd;
             ///
             $user->generateAuthKey();
             if ($user->save()) {
                 //生成邀请码
                 $new_uid = $user->id;
                 $invitation_code = 'v' . $new_uid * 99;
                 $user->invitation_code = $invitation_code;
                 $user->save();
                 //初始换用户账户
                 $asset_info = new Info();
                 $asset_info->member_id = $user['id'];
                 $asset_info->balance = 0;
                 $asset_info->freeze = 0;
                 if ($asset_info->save()) {
                     $uid = $user['id'];
                     //注册动作完成---进行登录操作
                     $log = new Log();
                     $log->member_id = $uid;
                     $log->login_ip = Yii::$app->request->userIp;
                     $log->login_time = time();
                     $log->login_area = $area;
                     $log->status = self::LOG_CONFIM;
                     $res = $log->save();
                     if ($res) {
                         $session_key = self::verification($uid) . '--' . $from;
                         $session = new Sessionkey();
                         $session->uid = $uid;
                         $session->sessionkey = $session_key;
                         $session->status = self::STATUS_ACTIVE;
                         $res = $session->save();
                         if ($res) {
                             $log->status = self::LOG_SUSSESS;
                             $log->save();
                             //新用户注册送体验金---6666
                             self::give_experience_gold(1, $user['id']);
                         } else {
                             $return = array('errorNum' => '1', 'errorMsg' => '登陆失败', 'data' => null);
                             return $return;
                         }
                     } else {
                         $return = array('errorNum' => '1', 'errorMsg' => '登陆记录失败', 'data' => null);
                         return $return;
                     }
                 } else {
                     $return = array('errorNum' => '1', 'errorMsg' => '账户初始化失败', 'data' => null);
                     return $return;
                 }
             } else {
                 $return = array('errorNum' => '1', 'errorMsg' => '注册失败', 'data' => null);
                 return $return;
             }
             $transaction->commit();
             //事务成功提交后返回数据
             $data = array('sessionkey' => $session_key, 'balance' => 0, 'phone' => $phone, 'app_pwd' => $app_pwd);
             $return = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => $data);
             return $return;
         } catch (\Exception $e) {
             $transaction->rollBack();
             $remark = $e->getMessage();
             $result = array('errorNum' => '1', 'errorMsg' => $remark, 'data' => null);
             return $result;
         }
     } else {
         $return = array('errorNum' => '1', 'errorMsg' => $check['errorMsg'], 'data' => null);
         return $return;
     }
 }