startTrans(); try { $percent = sys_config('agent_share', 'agent'); $motorAgent = $MotorAgent->with([ 'user' ]) ->where('area_id', $order['area_id']) ->find(); if ($motorAgent && $motorAgent->user) { $money = bcmul($order['price'], $percent/100, 2); $motorAgent->user->motor_agent_money += $money; $motorAgent->user->save(); $MotorRecord->setMoneyLog($motorAgent->user, 'motor_agent_money', $money, 0, '摩的代理分红'); $result = $MotorRecord->saveMoneyLog(); } $this->commit(); } catch(Exception $e) { $this->rollback(); throw new Exception($e->getMessage()); } return $result; } }