Rebate.php 3.0 KB

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