params = $this->request->post(); if(empty($this->params) || !array_filter($this->params)) $this->error('参数错误'); $sign = ''; foreach ($this->params as $key => $value) { if($key != 'sign') $sign .= $value; } $sign .= Env::get('rwa.AppID'); $sign = md5($sign); if($this->params['sign'] != $sign) $this->error('签名验签错误'); } /* * 判断登录 */ public function login(UserModel $userModel) { $user = $userModel::where('phone', $this->params['mobile'])->find(); if(!$user) $this->error('账号不存在', [], 4000); Token::marshal($user['id'], $user['address']); $user['token'] = Token::getEncryptedToken($user['id']); $this->success('ok', $user); } /* * 注册 */ public function register(UserModel $userModel) { //手机号存在 if($userModel::where('phone', $this->params['mobile'])->find()) $this->error('账号已存在'); $newUserID = 0; Db::startTrans(); try { //注册 $time = time(); $data = [ 'phone' => $this->params['mobile'], 'nickname' => "188" . substr((string)$time, 2) . rand(10, 99),//188开头,时间戳去掉开头两位,再后面再加两位随机数 'avatar' => $this->request->domain().'/assets/img/logo.png', 'create_time' => $time, 'team_level_id' => 0, ]; // 创建用户 $newUserID = $userModel->insertGetId($data); // 创建钱包 (new LedgerWalletModel())->insertGetId(['user_id' => $newUserID]); Token::marshal($newUserID); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); $this->error($e->getMessage()); } if($newUserID == 0) $this->error('注册失败'); $this->success('ok', ['token' => Token::getEncryptedToken($newUserID)]); } //绑定地址 public function bindAddress(UserModel $userModel) { $user = $userModel->getByAddress($this->params['address']); if(!$user) $this->error('钱包地址不存在'); if($user->phone) $this->error('钱包地址已被绑定'); //修改手机号 $user->phone = $this->params['mobile']; $user->save(); $this->success('ok'); } //转让茶宝 public function chalink(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if(!$user) $this->error('钱包地址不存在'); //添加茶宝 $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TOKEN, $this->params['chalink'], LedgerTokenChangeModel::ChaLink); $this->success('ok'); } //转入Teac public function teac(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if(!$user) $this->error('钱包地址不存在'); //添加Teac $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC_ANGEL, $this->params['teac'], LedgerTeacAngelChangeModel::TransferIn); $this->success('ok'); } //转入TeaC生态发展 public function teacecology(UserModel $userModel, LedgerWalletModel $ledgerWalletModel) { $user = $userModel->getByPhone($this->params['mobile']); if(!$user) $this->error('钱包地址不存在'); //添加Teac $ledgerWalletModel->changeWalletAccount($user['id'], Asset::TEAC_ECOLY, $this->params['teacecology'], LedgerTeacEcolyChangeModel::TransferIn); $this->success('ok'); } }