RebateService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Config;
  4. use App\Models\Rebate;
  5. use App\Models\User;
  6. use Carbon\Carbon;
  7. class RebateService extends BaseService
  8. {
  9. /**
  10. * @description: 模型
  11. * @return {string}
  12. */
  13. public static function model(): string
  14. {
  15. return Rebate::class;
  16. }
  17. /**
  18. * @description: 枚举
  19. * @return {*}
  20. */
  21. public static function enum(): string
  22. {
  23. return '';
  24. }
  25. /**
  26. * @description: 获取查询条件
  27. * @param {array} $search 查询内容
  28. * @return {array}
  29. */
  30. public static function getWhere(array $search = []): array
  31. {
  32. $where = [];
  33. if (isset($search['id']) && !empty($search['id'])) {
  34. $where[] = ['id', '=', $search['id']];
  35. }
  36. if (isset($search['member_id']) && !empty($search['member_id'])) {
  37. $where[] = ['member_id', '=', $search['member_id']];
  38. }
  39. if (isset($search['first_name']) && !empty($search['first_name'])) {
  40. $where[] = ['first_name', '=', $search['first_name']];
  41. }
  42. if (isset($search['username']) && !empty($search['username'])) {
  43. $where[] = ['username', '=', $search['username']];
  44. }
  45. if (isset($search['status']) && !empty($search['status'])) {
  46. $where[] = ['status', '=', $search['status']];
  47. }
  48. if (isset($search['date']) && !empty($search['date'])) {
  49. $where[] = ['date', '=', $search['date']];
  50. }
  51. return $where;
  52. }
  53. /**
  54. * @description: 查询单条数据
  55. * @param array $search
  56. * @return \App\Models\Rebate|null
  57. */
  58. public static function findOne(array $search): ?Rebate
  59. {
  60. return self::model()::where(self::getWhere($search))->first();
  61. }
  62. /**
  63. * @description: 查询所有数据
  64. * @param array $search
  65. * @return \Illuminate\Database\Eloquent\Collection
  66. */
  67. public static function findAll(array $search = [])
  68. {
  69. return self::model()::where(self::getWhere($search))->get();
  70. }
  71. /**
  72. * @description: 分页查询
  73. * @param array $search
  74. * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  75. */
  76. public static function paginate(array $search = [])
  77. {
  78. $limit = isset($search['limit']) ? $search['limit'] : 15;
  79. $date = Carbon::now('America/New_York')->format('Y-m-d');
  80. $paginator = self::model()::where(self::getWhere($search))
  81. ->where('date', '<', $date)
  82. ->orderByDesc('date')
  83. ->orderBy('status')
  84. ->orderByDesc('betting_amount')
  85. ->paginate($limit);
  86. return ['total' => $paginator->total(), 'data' => $paginator->items()];
  87. }
  88. //比比返水
  89. public static function BibiReturn($rebate)
  90. {
  91. $rebate_ratio = Config::where('field', 'rebate')->first()->val;
  92. $rebateAmount = bcmul($rebate->betting_amount, $rebate_ratio, 2); // 返利金额
  93. if ($rebateAmount > 0) {
  94. $res = WalletService::updateBalance($rebate->member_id, $rebateAmount);
  95. BalanceLogService::addLog(
  96. $rebate->member_id,
  97. $rebateAmount,
  98. $res['before_balance'],
  99. $res['after_balance'],
  100. '返水',
  101. $rebate->id,
  102. '');
  103. }
  104. return true;
  105. }
  106. }