Rebate.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Models;
  3. use Carbon\Carbon;
  4. class Rebate extends BaseModel
  5. {
  6. protected $table = 'rebates';
  7. protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio',
  8. 'amount', 'status', 'first_name', 'username', 'audited_by',
  9. 'profit', 'huishui_percentage', 'huishui_restriction', 'huishui_amount',
  10. 'effective_betting_amount'
  11. ];
  12. const STATUS_WEI_FAN_YONG = 0;//未返佣
  13. const STATUS_FAN_YONG = 1; //已返佣
  14. static function updateProfit($data)
  15. {
  16. $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
  17. $rebate = static::where('date', $data['date'])
  18. ->where('member_id', $data['member_id'])->first();
  19. $profit = bcadd($rebate->profit, $data['profit'], 2);
  20. $rebate->profit = $profit;
  21. $rebate->save();
  22. return $rebate;
  23. }
  24. static function addOrUpdate($data)
  25. {
  26. $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
  27. $data['rebate_ratio'] = Config::where('field', 'rebate')->first()->val;
  28. $data['huishui_restriction'] = Config::where('field', 'huishui_restriction')->first()->val;
  29. $data['huishui_percentage'] = Config::where('field', 'huishui_percentage')->first()->val;
  30. $rebate = static::where('date', $data['date'])
  31. ->where('member_id', $data['member_id'])->first();
  32. if ($rebate) {
  33. $rebate->rebate_ratio = $data['rebate_ratio'];
  34. $rebate->first_name = $data['first_name'];
  35. $rebate->username = $data['username'];
  36. $rebate->save();
  37. $rebate->increment("betting_amount", $data['betting_amount']);
  38. } else {
  39. $rebate = static::create($data);
  40. }
  41. return $rebate;
  42. }
  43. protected function getHuishuiRestrictionAttribute($value)
  44. {
  45. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  46. $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
  47. return $huishui_restriction;
  48. }
  49. return $value;
  50. }
  51. protected function getHuishuiPercentageAttribute($value)
  52. {
  53. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  54. $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
  55. return $huishui_percentage;
  56. }
  57. return $value;
  58. }
  59. protected function getHuishuiAmountAttribute($value)
  60. {
  61. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  62. $value = 0;
  63. $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
  64. $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
  65. $lose = $this->profit * -1;
  66. if ($lose >= $huishui_restriction) {
  67. $value = bcmul($lose, $huishui_percentage, 2); // 返利金额
  68. }
  69. }
  70. return $value;
  71. }
  72. }