Rebate.php 2.4 KB

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