123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- namespace App\Http\Controllers\Client;
- use App\Http\Controllers\Controller;
- use App\Http\Requests\Client\Account\LoginRequest;
- use App\Http\Requests\Client\Account\SendVerifyCodeRequest;
- use App\Http\Requests\Client\Account\WxLoginRequest;
- use App\Services\Client\AccountService;
- use Illuminate\Support\Facades\Auth;
- /**
- * @group 用户端
- *
- * 包含登录、注册、账户管理等基础功能
- */
- class AccountController extends Controller
- {
- protected AccountService $service;
- public function __construct(AccountService $service)
- {
- $this->service = $service;
- }
- /**
- * 发送验证码
- *
- * 向指定手机号发送验证码
- *
- * @queryParam mobile string required 手机号码. Example: 13800138000
- *
- * @response {
- * "code": 200,
- * "message": "验证码发送成功",
- * "data": null
- * }
- */
- public function sendVerifyCode(SendVerifyCodeRequest $request)
- {
- $validated = $request->validated();
- return $this->success(
- $this->service->sendVerifyCode($validated['mobile'])
- );
- }
- /**
- * 用户登录
- *
- * 使用手机号和验证码登录账户
- *
- * @bodyParam mobile string required 手机号码. Example: 13800138000
- * @bodyParam code string required 验证码. Example: 123456
- * @bodyParam invite_code string optional 邀请码. Example: user_1
- *
- * @response {
- * "code": 200,
- * "message": "登录成功",
- * "data": {
- * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
- * "user": {
- * "id": 1,
- * "mobile": "13800138000",
- * "nickname": "用户昵称"
- * }
- * }
- * }
- */
- public function login(LoginRequest $request)
- {
- $validated = $request->validated();
- return $this->success(
- $this->service->login(
- $validated['mobile'],
- $validated['code'],
- $validated['invite_code'] ?? null
- )
- );
- }
- /**
- * 微信登录
- *
- * 使用微信openid登录账户
- *
- * @bodyParam openid string required 微信openid. Example: wx_123456789
- * @bodyParam userInfo object optional 微信用户信息.
- * @bodyParam userInfo.nickname string optional 用户昵称. Example: 张三
- * @bodyParam userInfo.avatar string optional 头像URL. Example: https://xxx.com/avatar.jpg
- * @bodyParam userInfo.gender int optional 性别(1男2女0未知). Example: 1
- * @bodyParam userInfo.invite_code string optional 邀请码. Example: user_1
- *
- * @response {
- * "code": 200,
- * "message": "登录成功",
- * "data": {
- * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
- * "user": {
- * "id": 1,
- * "openid": "wx_123456789",
- * "nickname": "微信昵称"
- * }
- * }
- * }
- */
- public function wxLogin(WxLoginRequest $request)
- {
- $validated = $request->validated();
- return $this->success(
- $this->service->wxLogin($validated['openid'], $validated['userInfo'] ?? [])
- );
- }
- /**
- * 用户退出
- *
- * 退出当前账户登录状态
- *
- * @authenticated
- *
- * @response {
- * "code": 200,
- * "message": "退出成功",
- * "data": null
- * }
- */
- public function logout()
- {
- return $this->success(
- $this->service->logout(Auth::user()->id)
- );
- }
- /**
- * 用户注销
- *
- * 永久注销当前账户
- *
- * @authenticated
- *
- * @response {
- * "code": 200,
- * "message": "注销成功",
- * "data": null
- * }
- */
- public function destroy()
- {
- return $this->success(
- $this->service->deleteAccount()
- );
- }
- }
|