user = User::find($user_id); //用户模型 $this->profit = $profit; //分红记录模型 $this->allPoint = [ '3' => $profit->portion(3), '4' => $profit->portion(4), '5' => $profit->portion(5), '6' => $profit->portion(6), ]; //每一份金额 $this->selfPoint = [ '3' => $profit->portion(3, $this->user->id), '4' => $profit->portion(4, $this->user->id), '5' => $profit->portion(5, $this->user->id), '6' => $profit->portion(6, $this->user->id), ]; //参与分红身份ID $this->proportion = [ '3' => 0.2, '4' => 0.2, '5' => 0.2, '6' => 0.2, ]; //分红比例 } public function handle() { foreach ($this->allPoint as $key => $all) { $self = $this->selfPoint[$key]; if ($self <= 0 || $all <= 0) { continue; } $share = round($this->profit->price * $this->proportion[$key] / $all, 2); $cash = $self * (int) $share; if ($cash > 0) { $this->user->rule('profit' . $key, $cash, false, ['allPoint' => $all, 'selfPoint' => $self, 'identity_id' => $key, 'no' => $this->profit->end_at->format('Ymd')]); } } } }