123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace huo\controller\finance;
- use huo\controller\agent\AgentOrder;
- use huolib\constant\CommonConst;
- use huolib\tool\StrUtils;
- class AgentIncome {
- private $default_gain = 0.00;
-
- 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;
- }
-
- 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);
- }
-
- 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);
- }
-
- public function setParent(AoRequest $aor) {
- $aor->setAgentId(0);
- return (new AgentOrder())->createAoOrder($aor);
- }
- }
|