PointsLog.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model\user;
  13. use app\common\model\user\PointsLog as PointsLogModel;
  14. /**
  15. * 用户余额变动明细模型
  16. * Class PointsLog
  17. * @package app\store\model\user
  18. */
  19. class PointsLog extends PointsLogModel
  20. {
  21. /**
  22. * 获取积分明细列表
  23. * @param array $param
  24. * @return \think\Paginator
  25. */
  26. public function getList(array $param = []): \think\Paginator
  27. {
  28. // 设置查询条件
  29. $filter = $this->getFilter($param);
  30. // 获取列表数据
  31. return $this->with(['user.avatar'])
  32. ->alias('m')
  33. ->field('m.*')
  34. ->where($filter)
  35. ->join('user', 'user.user_id = m.user_id')
  36. ->order(['m.create_time' => 'desc', $this->getPk()])
  37. ->paginate(15);
  38. }
  39. /**
  40. * 设置查询条件
  41. * @param array $param
  42. * @return array
  43. */
  44. private function getFilter(array $param): array
  45. {
  46. // 设置默认的检索数据
  47. $params = $this->setQueryDefaultValue($param, [
  48. 'userId' => 0, // 会员ID
  49. 'search' => '', // 搜索内容
  50. 'betweenTime' => [], // 起止时间
  51. ]);
  52. // 检索查询条件
  53. $filter = [];
  54. // 用户ID
  55. $params['userId'] > 0 && $filter[] = ['m.user_id', '=', $params['userId']];
  56. // 搜索内容: 用户昵称
  57. !empty($params['search']) && $filter[] = ['user.nick_name', 'like', "%{$params['search']}%"];
  58. // 起止时间
  59. if (!empty($params['betweenTime'])) {
  60. $times = between_time($params['betweenTime']);
  61. $filter[] = ['m.create_time', '>=', $times['start_time']];
  62. $filter[] = ['m.create_time', '<', $times['end_time'] + 86400];
  63. }
  64. return $filter;
  65. }
  66. }