Rebate.php 3.2 KB

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