Rebate.php 2.8 KB

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