AccountService.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Module\Fund\Services;
  3. use App\Module\Fund\Dto\AccountDto;
  4. use App\Module\Fund\Models\FundConfigModel;
  5. use App\Module\Fund\Models\FundModel;
  6. use App\Module\System\Services\ConfigService;
  7. use UCore\Helper\Cache;
  8. /**
  9. * 账户
  10. */
  11. class AccountService
  12. {
  13. /**
  14. * 检查和创建用户账户
  15. *
  16. * @param $userId
  17. * @return void
  18. * @throws \Exception
  19. */
  20. static public function check4user($userId)
  21. {
  22. TaskService::checkCreateUAccoun($userId);
  23. }
  24. /**
  25. * 用户账户
  26. *
  27. * @param int $userId 用户ID
  28. * @return AccountDto[] 账户DTO数组
  29. */
  30. static public function list4user($userId)
  31. {
  32. /**
  33. * @var FundModel[] $list
  34. */
  35. $list = FundModel::userAccount($userId);
  36. // 获取资金类型名称映射
  37. $fundNames = self::getFundsDesc();
  38. // 将模型转换为DTO
  39. $dtoList = [];
  40. foreach ($list as $model) {
  41. $dtoList[] = AccountDto::fromModel($model, $fundNames);
  42. }
  43. return $dtoList;
  44. }
  45. /**
  46. * 获取资金账户描述
  47. *
  48. * @return array
  49. */
  50. static public function getFundsDesc()
  51. {
  52. return Cache::cacheCall([ __CLASS__, __FUNCTION__ ], function () {
  53. $list = FundConfigModel::query()->pluck('name', 'id')->toArray();
  54. return $list;
  55. }, [], 100, [ ConfigService::CACHE_TAG ]);
  56. }
  57. }