Rebate.php 3.2 KB

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