RebateService.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Rebate;
  4. use App\Models\User;
  5. use Carbon\Carbon;
  6. class RebateService extends BaseService
  7. {
  8. /**
  9. * @description: 模型
  10. * @return {string}
  11. */
  12. public static function model(): string
  13. {
  14. return Rebate::class;
  15. }
  16. /**
  17. * @description: 枚举
  18. * @return {*}
  19. */
  20. public static function enum(): string
  21. {
  22. return '';
  23. }
  24. /**
  25. * @description: 获取查询条件
  26. * @param {array} $search 查询内容
  27. * @return {array}
  28. */
  29. public static function getWhere(array $search = []): array
  30. {
  31. $where = [];
  32. if (isset($search['id']) && !empty($search['id'])) {
  33. $where[] = ['id', '=', $search['id']];
  34. }
  35. if (isset($search['member_id']) && !empty($search['member_id'])) {
  36. $where[] = ['member_id', '=', $search['member_id']];
  37. }
  38. if (isset($search['status']) && !empty($search['status'])) {
  39. $where[] = ['status', '=', $search['status']];
  40. }
  41. if (isset($search['date']) && !empty($search['date'])) {
  42. $where[] = ['date', '=', $search['date']];
  43. }
  44. return $where;
  45. }
  46. /**
  47. * @description: 查询单条数据
  48. * @param array $search
  49. * @return \App\Models\Rebate|null
  50. */
  51. public static function findOne(array $search): ?Rebate
  52. {
  53. return self::model()::where(self::getWhere($search))->first();
  54. }
  55. /**
  56. * @description: 查询所有数据
  57. * @param array $search
  58. * @return \Illuminate\Database\Eloquent\Collection
  59. */
  60. public static function findAll(array $search = [])
  61. {
  62. return self::model()::where(self::getWhere($search))->get();
  63. }
  64. /**
  65. * @description: 分页查询
  66. * @param array $search
  67. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  68. */
  69. public static function paginate(array $search = [])
  70. {
  71. $limit = isset($search['limit']) ? $search['limit'] : 15;
  72. $date = Carbon::now('America/New_York')->format('Y-m-d');
  73. $paginator = self::model()::where(self::getWhere($search))
  74. ->where('date', '<', $date)
  75. ->with('wallet:user_id,member_id,address,available_balance')->paginate($limit);
  76. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  77. }
  78. }