| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace App\Module\UrsPromotion\Repositories;
- use App\Module\UrsPromotion\Models\UrsTransferFeeConfig;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * URS转出手续费配置仓库
- *
- * 提供URS转出手续费配置数据的访问和操作功能。
- * 该类是URS转出手续费配置模块与后台管理系统的桥梁,用于处理手续费配置数据的CRUD操作。
- */
- class UrsTransferFeeConfigRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = UrsTransferFeeConfig::class;
- /**
- * 根据房屋等级和达人等级查找配置
- *
- * @param int $houseLevel 房屋等级
- * @param int $talentLevel 达人等级
- * @return UrsTransferFeeConfig|null
- */
- public function findByLevels(int $houseLevel, int $talentLevel): ?UrsTransferFeeConfig
- {
- return UrsTransferFeeConfig::where('house_level', $houseLevel)
- ->where('talent_level', $talentLevel)
- ->where('status', UrsTransferFeeConfig::STATUS_ENABLED)
- ->first();
- }
- /**
- * 获取所有启用的配置,按优先级排序
- *
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function getEnabledConfigs()
- {
- return UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED)
- ->orderBy('priority', 'desc')
- ->orderBy('house_level')
- ->orderBy('talent_level')
- ->get();
- }
- /**
- * 获取匹配指定条件的配置
- *
- * @param int $houseLevel 房屋等级
- * @param int $talentLevel 达人等级
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function getMatchingConfigs(int $houseLevel, int $talentLevel)
- {
- return UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED)
- ->where(function ($query) use ($houseLevel) {
- $query->where('house_level', 0)
- ->orWhere('house_level', $houseLevel);
- })
- ->where(function ($query) use ($talentLevel) {
- $query->where('talent_level', 0)
- ->orWhere('talent_level', $talentLevel);
- })
- ->orderBy('priority', 'desc')
- ->get();
- }
- /**
- * 检查是否存在重复的配置
- *
- * @param int $houseLevel 房屋等级
- * @param int $talentLevel 达人等级
- * @param int|null $excludeId 排除的配置ID
- * @return bool
- */
- public function hasDuplicateConfig(int $houseLevel, int $talentLevel, ?int $excludeId = null): bool
- {
- $query = UrsTransferFeeConfig::where('house_level', $houseLevel)
- ->where('talent_level', $talentLevel);
- if ($excludeId) {
- $query->where('id', '!=', $excludeId);
- }
- return $query->exists();
- }
- /**
- * 获取最高优先级
- *
- * @return int
- */
- public function getMaxPriority(): int
- {
- return UrsTransferFeeConfig::max('priority') ?? 0;
- }
- /**
- * 批量更新状态
- *
- * @param array $ids 配置ID数组
- * @param int $status 状态值
- * @return int 更新的记录数
- */
- public function batchUpdateStatus(array $ids, int $status): int
- {
- return UrsTransferFeeConfig::whereIn('id', $ids)
- ->update(['status' => $status]);
- }
- /**
- * 获取统计信息
- *
- * @return array
- */
- public function getStatistics(): array
- {
- $total = UrsTransferFeeConfig::count();
- $enabled = UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_ENABLED)->count();
- $disabled = UrsTransferFeeConfig::where('status', UrsTransferFeeConfig::STATUS_DISABLED)->count();
- return [
- 'total' => $total,
- 'enabled' => $enabled,
- 'disabled' => $disabled,
- 'enabled_percentage' => $total > 0 ? round(($enabled / $total) * 100, 2) : 0,
- ];
- }
- }
|