RebateService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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['first_name']) && !empty($search['first_name'])) {
  39. $where[] = ['first_name', '=', $search['first_name']];
  40. }
  41. if (isset($search['username']) && !empty($search['username'])) {
  42. $where[] = ['username', '=', $search['username']];
  43. }
  44. if (isset($search['status']) && !empty($search['status'])) {
  45. $where[] = ['status', '=', $search['status']];
  46. }
  47. if (isset($search['date']) && !empty($search['date'])) {
  48. $where[] = ['date', '=', $search['date']];
  49. }
  50. return $where;
  51. }
  52. /**
  53. * @description: 查询单条数据
  54. * @param array $search
  55. * @return \App\Models\Rebate|null
  56. */
  57. public static function findOne(array $search): ?Rebate
  58. {
  59. return self::model()::where(self::getWhere($search))->first();
  60. }
  61. /**
  62. * @description: 查询所有数据
  63. * @param array $search
  64. * @return \Illuminate\Database\Eloquent\Collection
  65. */
  66. public static function findAll(array $search = [])
  67. {
  68. return self::model()::where(self::getWhere($search))->get();
  69. }
  70. /**
  71. * @description: 分页查询
  72. * @param array $search
  73. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  74. */
  75. public static function paginate(array $search = [])
  76. {
  77. $limit = isset($search['limit']) ? $search['limit'] : 15;
  78. $date = Carbon::now('America/New_York')->format('Y-m-d');
  79. $paginator = self::model()::where(self::getWhere($search))
  80. // ->where('date', '<', $date)
  81. ->with('wallet:user_id,member_id,address,available_balance')->paginate($limit);
  82. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  83. }
  84. }