123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * AgentIncome.php UTF-8
- * 渠道收益表
- *
- * @date : 2018/5/14 15:11
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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);
- }
- }
|