| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Module\Fund\Repositorys;
- use App\Module\Fund\Models\FundConfigModel;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 账户种类配置仓库
- *
- * 提供账户种类配置数据的访问和操作功能。
- * 该类是账户种类配置模块与后台管理系统的桥梁,用于处理账户种类配置数据的CRUD操作。
- */
- class FundConfigRepository extends EloquentRepository
- {
- /**
- * 关联的模型类
- *
- * @var string
- */
- protected $eloquentClass = FundConfigModel::class;
- /**
- * 根据币种ID获取账户种类列表
- *
- * @param int $currencyId
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function findByCurrencyId(int $currencyId)
- {
- return FundConfigModel::where('currency_id', $currencyId)->get();
- }
- /**
- * 获取所有账户种类,按币种分组
- *
- * @return array
- */
- public function getGroupedByFundCurrency()
- {
- $result = [];
- $configs = FundConfigModel::with('currency')->get();
-
- foreach ($configs as $config) {
- $currencyId = $config->currency_id ?? 0;
- $currencyName = $config->currency ? $config->currency->name : '未分类';
-
- if (!isset($result[$currencyId])) {
- $result[$currencyId] = [
- 'currency_name' => $currencyName,
- 'configs' => []
- ];
- }
-
- $result[$currencyId]['configs'][] = $config;
- }
-
- return $result;
- }
- }
|