diff --git a/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php b/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php index e5ce4837..daea5dd4 100644 --- a/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php +++ b/app/Endpoint/Api/Http/Controllers/Auth/LoginController.php @@ -6,6 +6,7 @@ use App\Constants\Device; use App\Endpoint\Api\Http\Controllers\Controller; use App\Exceptions\BizException; use App\Models\User; +use App\Models\UserInfo; use Illuminate\Http\Request; class LoginController extends Controller @@ -42,6 +43,10 @@ class LoginController extends Controller switch ($device) { case Device::MERCHANT: + if ($user->userInfo?->agent_level < UserInfo::AGENT_LEVEL_VIP) { + throw new BizException('用户未找到'); + } + // 清理此用户的商户端令牌 $user->tokens()->where('name', $device)->delete(); // 颁发新的商户端令牌 diff --git a/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php b/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php index b28c4ff2..cf7e87a9 100644 --- a/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php +++ b/app/Endpoint/Api/Http/Controllers/Merchant/UserController.php @@ -3,10 +3,30 @@ namespace App\Endpoint\Api\Http\Controllers\Merchant; use App\Endpoint\Api\Http\Controllers\Controller; +use App\Endpoint\Api\Http\Resources\Merchant\UserInfoResource; +use App\Endpoint\Api\Http\Resources\UserBalanceResource; +use App\Endpoint\Api\Http\Resources\UserWalletResource; use Illuminate\Http\Request; class UserController extends Controller { + /** + * 个人信息 + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function show(Request $request) + { + $user = $request->user(); + + return response()->json([ + 'phone' => $user->phone, + 'user_info' => UserInfoResource::make($user->userInfo), + 'balance' => bcdiv($user->balance?->balance, '100', 2), + ]); + } + /** * 个人账户信息 * @@ -18,12 +38,12 @@ class UserController extends Controller $user = $request->user(); return response()->json([ + // 余额 + 'balance' => UserBalanceResource::make($user->balance), + // 可提 + 'wallet' => UserWalletResource::make($user->wallet), // 销售值 'sales_value' => $user->userInfo->growth_value, - // 余额 - 'balance' => bcdiv($user->balance?->balance, 100, 2), - // 可提 - 'wallet_balance' => bcdiv($user->wallet?->balance, 100, 2), // 总预收益 'total_pre_revenue' => $user->getTotalPreRevenue(), ]); diff --git a/app/Endpoint/Api/Http/Resources/Merchant/UserInfoResource.php b/app/Endpoint/Api/Http/Resources/Merchant/UserInfoResource.php new file mode 100644 index 00000000..8eff3b9d --- /dev/null +++ b/app/Endpoint/Api/Http/Resources/Merchant/UserInfoResource.php @@ -0,0 +1,29 @@ + (string) $this->nickname, + 'avatar' => (string) $this->avatar, + 'gender' => (string) $this->gender, + 'birthday' => (string) $this->birthday?->toDateString(), + 'code' => (string) $this->code, + 'points' => (int) $this->points, + 'quota_v2' => $this->quota_v2, + 'quota_v1' => $this->quota_v1, + 'agent_level_name' => $this->agent_level_name, + ]; + } +} diff --git a/app/Endpoint/Api/Http/Resources/UserBalanceResource.php b/app/Endpoint/Api/Http/Resources/UserBalanceResource.php index d2a036fe..d3af15d9 100644 --- a/app/Endpoint/Api/Http/Resources/UserBalanceResource.php +++ b/app/Endpoint/Api/Http/Resources/UserBalanceResource.php @@ -14,21 +14,10 @@ class UserBalanceResource extends JsonResource */ public function toArray($request) { - if (is_null($this->resource)) {//没有钱包数据时默认数据 - return [ - 'balance'=> '0.00', - // 'total_expenses'=> $this->total_expenses, - // 'total_revenue' => $this->total_revenue, - 'transferable' => true, - 'is_frozen' => false, - ]; - } return [ - 'balance'=>$this->balance_format, - // 'total_expenses'=> $this->total_expenses, - // 'total_revenue' => $this->total_revenue, - 'transferable' => (bool) $this->transferable, - 'is_frozen' => (bool) $this->is_frozen, + 'balance' => $this->resource?->balance_format ?: '0.00', + 'transferable' => (bool) $this->resource?->transferable ?: true, + 'is_frozen' => (bool) $this->resource?->is_frozen, ]; } } diff --git a/app/Endpoint/Api/Http/Resources/UserWalletResource.php b/app/Endpoint/Api/Http/Resources/UserWalletResource.php index ff9ab026..35f3b7ea 100644 --- a/app/Endpoint/Api/Http/Resources/UserWalletResource.php +++ b/app/Endpoint/Api/Http/Resources/UserWalletResource.php @@ -14,23 +14,11 @@ class UserWalletResource extends JsonResource */ public function toArray($request) { - if (is_null($this->resource)) {//没有钱包数据时默认数据 - return [ - 'balance'=> '0.00', - // 'total_expenses'=> $this->total_expenses, - // 'total_revenue' => $this->total_revenue, - 'withdrawable' => true, - 'has_password' => false, - 'is_frozen' => false, - ]; - } return [ - 'balance'=> $this->balance_format, - // 'total_expenses'=> $this->total_expenses, - // 'total_revenue' => $this->total_revenue, - 'withdrawable' => (bool) $this->withdrawable, - 'is_frozen' => (bool) $this->is_frozen, - 'has_password' => (bool) $this->password??false, + 'balance'=> $this->resource?->balance_format ?: '0.00', + 'withdrawable' => (bool) $this->resource?->withdrawable ?: true, + 'is_frozen' => (bool) $this->resource?->is_frozen, + 'has_password' => (bool) $this->resource?->password, ]; } } diff --git a/app/Endpoint/Api/routes.php b/app/Endpoint/Api/routes.php index 1a71919c..20d529d2 100644 --- a/app/Endpoint/Api/routes.php +++ b/app/Endpoint/Api/routes.php @@ -182,6 +182,9 @@ Route::group([ 'ability:merchant', ], ], function () { + // 个人信息 + Route::get('me', [Merchant\UserController::class, 'show']); + // 个人账户 Route::get('account', [Merchant\UserController::class, 'account']); // 粉丝列表 Route::get('fans', [Merchant\FanController::class, 'index']);