payment = $payment->fresh(); } /** * 购卡佣金 * @return [type] [description] */ public function fire() { if ($this->payment && $this->payment->state == 'SUCCESS') { //判断订单状态 $order = $this->payment->order; //获取订单 $user = $order->user; //获取会员 if ($order && $user) { //基础判断 $parent = $user->parent; //获取推荐人 $eventName = 'team_card'; //默认直推 $lastPrice = 0; //默认直推 while ($parent) { $price = $parent->identity->info->configs[$eventName] ?? 0; //结算单价 if ($price) { $amount = $this->payment->amount; //代理金额 $num = $order->num; //代理金额 $cash = $price * $num; //实际佣金 $cash -= $lastPrice; $lastPrice += $cash; $log = $parent->accountLogs()->where('rule_id', 9)->where('source->order_id', $order->id)->first(); //查看是否结算过佣金 if ($cash > 0 && !$log) { $source = [ 'user_id' => $user->id, //会员ID 'payment_id' => $this->payment->id, //升级订单ID 'order_id' => $order->id, //升级订单ID 'price' => $price, //结算比例 'num' => $num, //结算数量 ]; $parent->rule($eventName, $cash, false, $source); //执行立即到账 } } $parent = $parent->parent; } } else { \Log::channel('bonus')->error('购卡订单或会员不存在' . $this->payment->order_id); } } else { \Log::channel('bonus')->error('购卡订单状态不正确(ID:' . ($this->payment->id ?? '无') . ')'); } } }