| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace App\Module\Fund\Services;
- use App\Module\Fund\Dto\AccountDto;
- use App\Module\Fund\Models\FundConfigModel;
- use App\Module\Fund\Models\FundModel;
- use App\Module\System\Services\ConfigService;
- use UCore\Helper\Cache;
- /**
- * 账户
- */
- class AccountService
- {
- /**
- * 检查和创建用户账户
- *
- * @param $userId
- * @return void
- * @throws \Exception
- */
- static public function check4user($userId)
- {
- TaskService::checkCreateUAccoun($userId);
- }
- /**
- * 用户账户
- *
- * @param int $userId 用户ID
- * @return AccountDto[] 账户DTO数组
- */
- static public function list4user($userId)
- {
- /**
- * @var FundModel[] $list
- */
- $list = FundModel::userAccount($userId);
- // 获取资金类型名称映射
- $fundNames = self::getFundsDesc();
- // 将模型转换为DTO
- $dtoList = [];
- foreach ($list as $model) {
- $dtoList[] = AccountDto::fromModel($model, $fundNames);
- }
- return $dtoList;
- }
- /**
- * 获取资金账户描述
- *
- * @return array
- */
- static public function getFundsDesc()
- {
- return Cache::cacheCall([ __CLASS__, __FUNCTION__ ], function () {
- $list = FundConfigModel::query()->pluck('name', 'id')->toArray();
- return $list;
- }, [], 100, [ ConfigService::CACHE_TAG ]);
- }
- }
|