AgentIncome.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * AgentIncome.php UTF-8
  4. * 渠道收益表
  5. *
  6. * @date : 2018/5/14 15:11
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\finance;
  13. use huo\controller\agent\AgentOrder;
  14. use huolib\constant\CommonConst;
  15. use huolib\tool\StrUtils;
  16. class AgentIncome {
  17. private $default_gain = 0.00;
  18. /**
  19. * 计算渠道收益
  20. *
  21. * @param AoRequest $aor 订单信息
  22. * @param bool $is_parent
  23. * @param float $deduct_fee 扣除金额
  24. *
  25. * @return float
  26. */
  27. public function getAgentGain(AoRequest $aor, $is_parent = false, $deduct_fee = 0.00) {
  28. if (empty($aor->getOrderId())) {
  29. return $this->default_gain;
  30. }
  31. $_real_fee = $aor->getRealAmount();
  32. $_no_coin_fee = $aor->getNoCoinFee();
  33. if (StrUtils::compareNumber($_real_fee - $deduct_fee, CommonConst::CONST_ZERO_COMPARE) < 0) {
  34. return $this->default_gain;
  35. }
  36. if (!$is_parent) {
  37. $_gain = StrUtils::formatNumber(
  38. $_real_fee - $_no_coin_fee * $aor->getAgentRate() + $_no_coin_fee * $aor->getAgentRebate()
  39. - $deduct_fee, 2
  40. );
  41. } else {
  42. $_gain = StrUtils::formatNumber(
  43. $_real_fee - $_no_coin_fee * $aor->getParentRate() + $_no_coin_fee * $aor->getParentRebate()
  44. - $deduct_fee
  45. - $aor->getAgentGain(), 2
  46. );
  47. }
  48. if (StrUtils::compareNumber($_gain, CommonConst::CONST_ZERO_COMPARE) < 0) {
  49. return $this->default_gain;
  50. }
  51. return $_gain;
  52. }
  53. /**
  54. * 设置渠道收益
  55. *
  56. * @param AoRequest $aor 收益表
  57. * @param float $deduct_fee 扣除费用
  58. *
  59. * @return bool
  60. */
  61. public function setLevelOne(AoRequest $aor, $deduct_fee = 0.00) {
  62. $aor->setAgentId(0);
  63. $aor->setParentGain($this->getAgentGain($aor, true, $deduct_fee));
  64. return (new AgentOrder())->createAoOrder($aor);
  65. }
  66. /**
  67. * 设置一级二级收益
  68. *
  69. * @param AoRequest $aor 订单
  70. * @param float $deduct_fee 扣除费用
  71. *
  72. * @return bool
  73. */
  74. public function setLevelTwo(AoRequest $aor, $deduct_fee = 0.00) {
  75. $aor->setAgentGain($this->getAgentGain($aor, false, $deduct_fee));
  76. $aor->setParentGain($this->getAgentGain($aor, true, $deduct_fee));
  77. return (new AgentOrder())->createAoOrder($aor);
  78. }
  79. /**
  80. * 设置父渠道收益
  81. *
  82. * @param AoRequest $aor 订单
  83. *
  84. * @return bool
  85. */
  86. public function setParent(AoRequest $aor) {
  87. $aor->setAgentId(0);
  88. return (new AgentOrder())->createAoOrder($aor);
  89. }
  90. }