| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- use Laravel\Sanctum\HasApiTokens;
- /**
- * @mixin Builder
- * @method static Builder|static where($column, $operator = null, $value = null, $boolean = 'and')
- */
- class Rebate extends Authenticatable
- {
- use HasApiTokens, Notifiable;
- protected $table = 'rebates';
- // protected $hidden = ['created_at', 'updated_at'];
- protected $fillable = ['date', 'member_id', 'betting_amount', 'rebate_ratio',
- 'amount', 'status', 'first_name', 'username', 'audited_by',
- 'profit', 'huishui_percentage', 'huishui_restriction', 'huishui_amount',
- ];
- static function updateProfit($data)
- {
- $data['date'] = Carbon::now('America/New_York')->format('Y-m-d');
- $rebate = static::where('date', $data['date'])
- ->where('member_id', $data['member_id'])->first();
- $rebate->increment('profit', $data['profit']);
- return $rebate;
- }
- static function addOrUpdate($data)
- {
- $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 getHuishuiRestrictionAttribute($value)
- {
- $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val;
- return $huishui_restriction;
- }
- protected function getHuishuiPercentageAttribute($value)
- {
- $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val;
- return $huishui_percentage;
- }
- protected function getHuishuiAmountAttribute($value)
- {
- $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;
- }
- protected function getCreatedAtAttribute($value)
- {
- return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
- }
- protected function getUpdatedAtAttribute($value)
- {
- return \Carbon\Carbon::parse($value)->setTimezone('Asia/Shanghai')->format('Y-m-d H:i:s');
- }
- }
|