Rebate.php 2.8 KB

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