FundConfigRepository.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Module\Fund\Repositorys;
  3. use App\Module\Fund\Models\FundConfigModel;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. /**
  6. * 账户种类配置仓库
  7. *
  8. * 提供账户种类配置数据的访问和操作功能。
  9. * 该类是账户种类配置模块与后台管理系统的桥梁,用于处理账户种类配置数据的CRUD操作。
  10. */
  11. class FundConfigRepository extends EloquentRepository
  12. {
  13. /**
  14. * 关联的模型类
  15. *
  16. * @var string
  17. */
  18. protected $eloquentClass = FundConfigModel::class;
  19. /**
  20. * 根据币种ID获取账户种类列表
  21. *
  22. * @param int $currencyId
  23. * @return \Illuminate\Database\Eloquent\Collection
  24. */
  25. public function findByCurrencyId(int $currencyId)
  26. {
  27. return FundConfigModel::where('currency_id', $currencyId)->get();
  28. }
  29. /**
  30. * 获取所有账户种类,按币种分组
  31. *
  32. * @return array
  33. */
  34. public function getGroupedByFundCurrency()
  35. {
  36. $result = [];
  37. $configs = FundConfigModel::with('currency')->get();
  38. foreach ($configs as $config) {
  39. $currencyId = $config->currency_id ?? 0;
  40. $currencyName = $config->currency ? $config->currency->name : '未分类';
  41. if (!isset($result[$currencyId])) {
  42. $result[$currencyId] = [
  43. 'currency_name' => $currencyName,
  44. 'configs' => []
  45. ];
  46. }
  47. $result[$currencyId]['configs'][] = $config;
  48. }
  49. return $result;
  50. }
  51. }