LogService.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Module\Fund\Services;
  3. use App\Module\Fund\Dto\FundLogDto;
  4. use App\Module\Fund\Logic\Log;
  5. use Illuminate\Pagination\LengthAwarePaginator;
  6. /**
  7. * 日志服务
  8. *
  9. */
  10. class LogService
  11. {
  12. /**
  13. * 日志记录
  14. *
  15. * @param array $where 查询条件
  16. * @param int $page 页码
  17. * @param int $rows 每页行数
  18. * @return LengthAwarePaginator 分页结果,包含FundLogDto对象
  19. */
  20. public function log_list(array $where, int $page, int $rows = 5)
  21. {
  22. $log = new Log();
  23. $paginator = $log->lists($where, $page, $rows);
  24. // 获取资金类型名称映射
  25. $fundNames = AccountService::getFundsDesc();
  26. // 获取操作类型名称映射
  27. $operateTypeNames = [
  28. 1 => '充值',
  29. 2 => '提现',
  30. 3 => '转账',
  31. 4 => '系统操作',
  32. 5 => '管理员操作',
  33. 6 => '交易',
  34. 7 => '流转',
  35. ];
  36. // 将模型转换为DTO
  37. $items = $paginator->getCollection()->map(function ($model) use ($fundNames, $operateTypeNames) {
  38. return FundLogDto::fromModel($model, $fundNames, $operateTypeNames);
  39. });
  40. // 创建新的分页器,使用DTO集合
  41. return new LengthAwarePaginator(
  42. $items,
  43. $paginator->total(),
  44. $paginator->perPage(),
  45. $paginator->currentPage(),
  46. ['path' => request()->url(), 'query' => request()->query()]
  47. );
  48. }
  49. /**
  50. * 统计资金日志
  51. *
  52. * @param array $where 查询条件
  53. * @return array 统计结果
  54. */
  55. public function statistical(array $where)
  56. {
  57. $log = new Log();
  58. $result = $log->statistical($where);
  59. return $result;
  60. }
  61. }