Update
parent
2f723013c8
commit
b0fc336fa0
|
|
@ -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();
|
||||
// 颁发新的商户端令牌
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace App\Endpoint\Api\Http\Resources\Merchant;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserInfoResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'nickname' => (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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue