| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- use Illuminate\Support\Facades\Log;
- /**
- * @property $id
- * @property $effective_betting_amount
- * @property $date
- * @property $rebate_ratio
- * @property $member_id
- * @property $status
- * @property $amount
- * @property $audited_by
- * @property $grant_time
- */
- class Rebate extends BaseModel
- {
- protected $table = 'rebates';
- protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio',
- 'amount', 'status', 'first_name', 'username', 'audited_by',
- 'profit', 'huishui_percentage', 'huishui_restriction', 'huishui_amount',
- 'effective_betting_amount', 'grant_time'
- ];
- const STATUS_WEI_FAN_YONG = 0;//未返佣
- const STATUS_FAN_YONG = 1; //已返佣
- static function updateProfit($data)
- {
- $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
- Log::error('错误测试');
- Log::error(json_encode($data));
- $rebate = static::where('date', $data['date'])
- ->where('member_id', $data['member_id'])->first();
- if ($rebate) {
- $profit = bcadd($rebate->profit, $data['profit'], 2);
- $rebate->profit = $profit;
- $rebate->save();
- }
- return $rebate;
- }
- static function addOrUpdate($data)
- {
- $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
- $data['rebate_ratio'] = Config::where('field', 'rebate')->first()->val;
- $data['huishui_restriction'] = Config::where('field', 'huishui_restriction')->first()->val;
- $data['huishui_percentage'] = Config::where('field', 'huishui_percentage')->first()->val;
- $rebate = static::where('date', $data['date'])
- ->where('member_id', $data['member_id'])->first();
- if ($rebate) {
- $rebate->rebate_ratio = $data['rebate_ratio'];
- $rebate->first_name = $data['first_name'];
- $rebate->username = $data['username'];
- $rebate->save();
- $rebate->increment("betting_amount", $data['betting_amount']);
- } else {
- $rebate = static::create($data);
- }
- return $rebate;
- }
- protected function getGrantTimeAttribute($value): string
- {
- if ($value > 0) return date('Y-m-d H:i', $value);
- return "";
- }
- protected function getHuishuiRestrictionAttribute($value)
- {
- if ($this->status == static::STATUS_WEI_FAN_YONG) {
- $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
- return $huishui_restriction;
- }
- return $value;
- }
- protected function getHuishuiPercentageAttribute($value)
- {
- if ($this->status == static::STATUS_WEI_FAN_YONG) {
- $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
- return $huishui_percentage;
- }
- return $value;
- }
- protected function getHuishuiAmountAttribute($value)
- {
- if ($this->status == static::STATUS_WEI_FAN_YONG) {
- $value = 0;
- $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
- $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
- $lose = $this->profit * -1;
- if ($lose >= $huishui_restriction) {
- $value = bcmul($lose, $huishui_percentage, 2); // 返利金额
- }
- }
- return $value;
- }
- }
|