| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace ThirdParty\Urs\Services;
- use ThirdParty\Urs\Request\UrsGetUserInfoRequest;
- use ThirdParty\Urs\Request\UrsGetUserTeamRequest;
- use ThirdParty\Urs\Request\UrsGetUserLevelCountRequest;
- use ThirdParty\Urs\Request\UrsRegisterRequest;
- use ThirdParty\Urs\Request\UrsDepositRequest;
- use ThirdParty\Urs\Request\UrsWithdrawRequest;
- use ThirdParty\Urs\Request\UrsCheckBalanceRequest;
- /**
- * URS服务类
- *
- * 统一管理所有URS相关的请求操作,提供简洁的API接口
- * 每个方法对应一个专用的Request类,遵循单一职责原则
- */
- class UrsService
- {
- /**
- * 获取用户信息
- *
- * @param string $userKey 用户密钥
- * @return array
- * @throws \Exception
- */
- public static function getUserInfo(string $userKey): array
- {
- $request = new UrsGetUserInfoRequest();
- return $request->request(['userKey' => $userKey]);
- }
- /**
- * 获取用户团队关系
- *
- * @param int $userId 用户ID
- * @return array
- * @throws \Exception
- */
- public static function getUserTeam(int $userId): array
- {
- $request = new UrsGetUserTeamRequest();
- return $request->request(['userId' => $userId]);
- }
- /**
- * 获取用户下级统计
- *
- * @param int $userId 用户ID
- * @param int $level 统计级别(1或3)
- * @return array
- * @throws \Exception
- */
- public static function getUserLevelCount(int $userId, int $level): array
- {
- if (!in_array($level, [1, 3])) {
- throw new \InvalidArgumentException('level参数必须是1或3');
- }
- $request = new UrsGetUserLevelCountRequest();
- return $request->request([
- 'userId' => $userId,
- 'level' => $level
- ]);
- }
- /**
- * 用户注册
- *
- * @param int $userId 用户ID
- * @param string $username 用户名
- * @return array
- * @throws \Exception
- */
- public static function registerUser(int $userId, string $username): array
- {
- $request = new UrsRegisterRequest();
- return $request->request([
- 'user_id' => $userId,
- 'username' => $username
- ]);
- }
- /**
- * 充值操作
- *
- * @param int $userId 用户ID
- * @param float $amount 充值金额
- * @param string $orderId 订单ID
- * @return array
- * @throws \Exception
- */
- public static function deposit(int $userId, float $amount, string $orderId): array
- {
- $request = new UrsDepositRequest();
- return $request->request([
- 'user_id' => $userId,
- 'amount' => $amount,
- 'order_id' => $orderId
- ]);
- }
- /**
- * 提取操作
- *
- * @param int $userId 用户ID
- * @param float $amount 提取金额
- * @param string $orderId 订单ID
- * @return array
- * @throws \Exception
- */
- public static function withdraw(int $userId, float $amount, string $orderId): array
- {
- $request = new UrsWithdrawRequest();
- return $request->request([
- 'user_id' => $userId,
- 'amount' => $amount,
- 'order_id' => $orderId
- ]);
- }
- /**
- * 检查余额
- *
- * @param int $userId 用户ID
- * @return array
- * @throws \Exception
- */
- public static function checkBalance(int $userId): array
- {
- $request = new UrsCheckBalanceRequest();
- return $request->request(['user_id' => $userId]);
- }
- }
|