public function register() { $request = Request::capture(); $username = $request->input('username'); $password = $request->input('password'); $nickname = $request->input('nickname'); $age = $request->input('age'); $information = $request->input('information'); $location = $request->input('location'); $headPic = $request->input('headPicture'); $homePic = $request->input('homePicture'); if ($username == null || $password == null) { // 账号 密码 不能为空 return Utility::response_format(Utility::RESPONSE_CODE_Error, '', '账号密码不能为空'); } else { if (UserAccount::where('username', $username)->first() != null) { return Utility::response_format(Utility::RESPONSE_CODE_Error, '', '账号已存在'); } else { if (Utility::isValidateUsername($username) == false) { // 用户名无效 } else { if (Utility::isValidatePassword($password) == false) { // 密码无效 } } } } $token = Utility::genToken(); DB::beginTransaction(); try { $user = UserAccount::create(['username' => $username, 'password' => $password, 'token' => $token]); $userInfo = UserInfo::create(['user_name' => $nickname, 'user_age' => $age, 'user_information' => $information, 'user_location' => $location, 'user_id' => $user->id, 'head_pic' => $headPic, 'home_pic' => $homePic]); DB::commit(); $userInfo['token'] = $user->token; $userInfo['tags'] = $user->userTags; return $userInfo; } catch (Exception $e) { DB::rollBack(); return Utility::response_format(Utility::RESPONSE_CODE_DB_ERROR, '', $e->getMessage()); } }