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['phone'], '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 cancelTrade(ProductTeac $productTeac, TeacLogin $teacLogin) { $id = $this->request->post('teac_id/d', 0); $row = $productTeac::where(['id' => $id, 'user_id' => $this->auth->id])->find(); if(empty($row)) $this->error('订单不存在'); if($row['status'] != ProductTeac::Normal) $this->error('订单已完成'); Db::startTrans(); try { //返回相应茶宝Teac $teacLogin::setUserReturnOrder($this->auth->id, $row['type_id'], $row['frozen']); $row->frozen = 0; $row->status = ProductTeac::Closure; $row->save(); // 提交事务 Db::commit(); } catch (Exception $e) { // 回滚事务 Db::rollback(); return $e->getMessage(); } $this->success('ok'); } }