RebateService.php 3.4 KB

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