profit = $profit->fresh(); } /** * 购卡佣金 * @return [type] [description] */ public function fire() { if ($this->profit && $this->profit->sett === 0) { $users = User::when($this->profit->identity_id, function ($query) { $query->whereHas('identity', function ($q) { $q->where('identity_id', $this->profit->identity_id); }); })->get(); $this->profit->num = $users->count(); if ($this->profit->num == 0) { $this->profit->single = 0; } else { $this->profit->single = bcadd($this->profit->price / $users->count(), 0, 2); } $this->profit->realPrice = $this->profit->single * $this->profit->num; $this->profit->sett = 1; $this->profit->setted_at = now(); if ($this->profit->save()) { $source = [ 'profit_id' => $this->profit->id, ]; foreach ($users as $key => $user) { $user->rule('profit', $this->profit->single, false, $source); ProfitLog::create([ 'profit_id' => $this->profit->id, 'user_id' => $user->id, 'price' => $this->profit->single, ]); } } } else { \Log::channel('bonus')->error('全球分红不正确(ID:' . ($this->profit->id ?? '无') . ')'); } } }