* @version : HUOSDK 8.0 */ namespace huo\controller\finance; use huo\controller\agent\AgentOrder; use huolib\constant\CommonConst; use huolib\tool\StrUtils; class AgentIncome { private $default_gain = 0.00; /** * 计算渠道收益 * * @param AoRequest $aor 订单信息 * @param bool $is_parent * @param float $deduct_fee 扣除金额 * * @return float */ public function getAgentGain(AoRequest $aor, $is_parent = false, $deduct_fee = 0.00) { if (empty($aor->getOrderId())) { return $this->default_gain; } $_real_fee = $aor->getRealAmount(); $_no_coin_fee = $aor->getNoCoinFee(); if (StrUtils::compareNumber($_real_fee - $deduct_fee, CommonConst::CONST_ZERO_COMPARE) < 0) { return $this->default_gain; } if (!$is_parent) { $_gain = StrUtils::formatNumber( $_real_fee - $_no_coin_fee * $aor->getAgentRate() + $_no_coin_fee * $aor->getAgentRebate() - $deduct_fee, 2 ); } else { $_gain = StrUtils::formatNumber( $_real_fee - $_no_coin_fee * $aor->getParentRate() + $_no_coin_fee * $aor->getParentRebate() - $deduct_fee - $aor->getAgentGain(), 2 ); } if (StrUtils::compareNumber($_gain, CommonConst::CONST_ZERO_COMPARE) < 0) { return $this->default_gain; } return $_gain; } /** * 设置渠道收益 * * @param AoRequest $aor 收益表 * @param float $deduct_fee 扣除费用 * * @return bool */ public function setLevelOne(AoRequest $aor, $deduct_fee = 0.00) { $aor->setAgentId(0); $aor->setParentGain($this->getAgentGain($aor, true, $deduct_fee)); return (new AgentOrder())->createAoOrder($aor); } /** * 设置一级二级收益 * * @param AoRequest $aor 订单 * @param float $deduct_fee 扣除费用 * * @return bool */ public function setLevelTwo(AoRequest $aor, $deduct_fee = 0.00) { $aor->setAgentGain($this->getAgentGain($aor, false, $deduct_fee)); $aor->setParentGain($this->getAgentGain($aor, true, $deduct_fee)); return (new AgentOrder())->createAoOrder($aor); } /** * 设置父渠道收益 * * @param AoRequest $aor 订单 * * @return bool */ public function setParent(AoRequest $aor) { $aor->setAgentId(0); return (new AgentOrder())->createAoOrder($aor); } }