前台部分接口

This commit is contained in:
2025-05-07 14:48:34 +08:00
parent 6e963b23b0
commit d3bb8380e2
19 changed files with 575 additions and 62 deletions

View File

@@ -4,7 +4,10 @@ namespace App\Service;
use App\BaseApp\BaseService;
use App\Enum\UserStatusEnum;
use App\Models\CollectionModel;
use App\Models\RoleModel;
use App\Models\UserModel;
use App\Models\UserPayModel;
use Exception;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
@@ -160,4 +163,48 @@ class UserService extends BaseService
}
return $result;
}
/**
* 获取用户信息
* @return mixed
* @throws Exception
*/
public function myInfo(): mixed
{
$this->with = [
'roles'
];
$result = $this->getDetail($this->userId);
$result['created_day_at'] = format_time(strtotime($result['created_at']), 'Y-m-d');
$result['account'] = desensitization($result['account']);
return $result;
}
/**
* 用户统计
* @return array[]
*/
public function userStats()
{
$payProject = UserPayModel::where('user_id', $this->userId)->count();
$collection = CollectionModel::where('user_id', $this->userId)->count();
$role = $this->userInfo['role_name'];
return [
'pay_project' => [
'label' => '已购项目',
'value' => $payProject,
'icon' => 'shopping-bag'
],
'collection' => [
'label' => '我的收藏',
'value' => $collection,
'icon' => 'heart'
],
'role' => [
'label' => '用户类型',
'value' => $role,
'icon' => 'user'
],
];
}
}