Rebate.php 3.2 KB

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