Esempio n. 1
0
 /**
  * 生成用户标识
  * @param int $number 生成数量
  * @return bool
  */
 public function generate($number = 10)
 {
     $info = $this->getMaxInfo();
     $maxNickId = isset($info['nick_id']) ? $info['nick_id'] : '';
     $maxOrderNo = $info['order_no'];
     $count = 0;
     while ($count < $number) {
         //计算下一级标识
         if ($maxNickId == '') {
             $nextNickId = 'aaa00';
         } else {
             $nextNickId = ++$maxNickId;
         }
         $nextOrderNo = ++$maxOrderNo;
         //入库
         $nickList = new NickList();
         $nickList->attributes = ['nick_id' => $nextNickId, 'order_no' => $nextOrderNo, 'create_at' => time()];
         if (!$nickList->save()) {
             return false;
         }
         $count++;
     }
     return true;
 }
Esempio n. 2
0
 /**
  * 用户注册
  * @param $nation_code
  * @param $phone
  * @param $sms_code
  * @param $password
  */
 public function actionUserRegister($nation_code = '86', $phone, $sms_code, $password)
 {
     try {
         //验证码正确性
         $sms = new SmsRegisterBinding();
         $result = $sms->validateSmsCode($nation_code, $phone, $sms_code, 1800);
         if (!$result) {
             $this->code(450, '验证码不存在或已过期');
         }
         //验证用户是否已存在
         $user = new User();
         $result = $user->isExists($nation_code, $phone);
         if ($result) {
             $this->code(452, '已经注册');
         }
         //同步账号到腾讯云
         $result = yii::$app->tencent->accountImport(sprintf('%s-%s', $nation_code, $phone));
         if (0 != $result['ErrorCode']) {
             throw new Exception('腾讯云同步错误');
         }
         //开启事务
         $trans = yii::$app->db->beginTransaction();
         //添加新用户
         $userId = $user->add(['nation_code' => $nation_code, 'username' => $phone, 'password' => $password, 'created_at' => time(), 'updated_at' => time()]);
         if (!$userId) {
             $trans->rollBack();
             throw new Exception('用户入库失败');
         }
         //选择用户标识入库
         $nickListObj = new NickList();
         $nickInfo = $nickListObj->getInfoByOrderNo($userId);
         if (!$nickInfo) {
             $trans->rollBack();
             throw new Exception('未找到用户标识');
         }
         $userNickObj = new UserNickBinding();
         $result = $userNickObj->add(['user_id' => $userId, 'nick_list_id' => $nickInfo['id'], 'create_at' => time()]);
         if (!$result) {
             $trans->rollBack();
             throw new Exception('nick_id入库失败');
         }
         $trans->commit();
         $this->code(200, 'ok', ['user_id' => $userId, 'nation_code' => $nation_code, 'avatar' => '', 'phone' => $phone, 'nick_name' => '', 'nick_id' => $nickInfo['nick_id'], 'gender' => 0, 'birthday' => '', 'believe_date' => '', 'province_id' => 0, 'city_id' => 0, 'province_name' => '', 'city_name' => '']);
     } catch (Exception $e) {
         $this->code(500, $e->getMessage());
     }
 }
Esempio n. 3
0
 public function getNickList()
 {
     return $this->hasOne(NickList::className(), ['id' => 'nick_list_id']);
 }
Esempio n. 4
0
 /**
  * 批量生成用户标识
  * @param integer $number 生成数量
  * @return bool
  */
 public function actionGenerateNick($number)
 {
     $nick = new NickList();
     return $nick->generate($number);
 }