Rebate.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. if(!$rebate){
  20. $profit = bcadd($rebate->profit, $data['profit'], 2);
  21. $rebate->profit = $profit;
  22. $rebate->save();
  23. }
  24. return $rebate;
  25. }
  26. static function addOrUpdate($data)
  27. {
  28. $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
  29. $data['rebate_ratio'] = Config::where('field', 'rebate')->first()->val;
  30. $data['huishui_restriction'] = Config::where('field', 'huishui_restriction')->first()->val;
  31. $data['huishui_percentage'] = Config::where('field', 'huishui_percentage')->first()->val;
  32. $rebate = static::where('date', $data['date'])
  33. ->where('member_id', $data['member_id'])->first();
  34. if ($rebate) {
  35. $rebate->rebate_ratio = $data['rebate_ratio'];
  36. $rebate->first_name = $data['first_name'];
  37. $rebate->username = $data['username'];
  38. $rebate->save();
  39. $rebate->increment("betting_amount", $data['betting_amount']);
  40. } else {
  41. $rebate = static::create($data);
  42. }
  43. return $rebate;
  44. }
  45. protected function getHuishuiRestrictionAttribute($value)
  46. {
  47. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  48. $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
  49. return $huishui_restriction;
  50. }
  51. return $value;
  52. }
  53. protected function getHuishuiPercentageAttribute($value)
  54. {
  55. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  56. $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
  57. return $huishui_percentage;
  58. }
  59. return $value;
  60. }
  61. protected function getHuishuiAmountAttribute($value)
  62. {
  63. if ($this->status == static::STATUS_WEI_FAN_YONG) {
  64. $value = 0;
  65. $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
  66. $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
  67. $lose = $this->profit * -1;
  68. if ($lose >= $huishui_restriction) {
  69. $value = bcmul($lose, $huishui_percentage, 2); // 返利金额
  70. }
  71. }
  72. return $value;
  73. }
  74. }