AgentOrder.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * AgentOrder.php UTF-8
  4. * 渠道收益订单
  5. *
  6. * @date : 2018/5/18 14:12
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\controller\agent;
  13. use huo\controller\common\Base;
  14. use huo\controller\finance\AoRequest;
  15. use huo\model\agent\AgentOrderModel;
  16. use huolib\constant\CommonConst;
  17. use huolib\constant\SettleConst;
  18. use huolib\status\SettleStatus;
  19. use huolib\tool\StrUtils;
  20. use think\Log;
  21. class AgentOrder extends Base {
  22. /**
  23. * 创建渠道收益订单
  24. *
  25. * @param AoRequest $aor
  26. *
  27. * @return int
  28. */
  29. public function createAoOrder(AoRequest $aor) {
  30. /* 查询次订单是否获取过收益 */
  31. $_ao_model = new AgentOrderModel();
  32. $_ao_info = $_ao_model->getInfoByOrderId($aor->getOrderId());
  33. if (!empty($_ao_info)) {
  34. $_code = SettleStatus::ORDER_HAS_SHARE;
  35. Log::write(
  36. "func=".__FUNCTION__."&class=".__CLASS__."&code=".$_code.'&msg='.SettleStatus::getMsg($_code)."&order="
  37. .http_build_query($aor->toArray()),
  38. LOG::ERROR
  39. );
  40. return $_code;
  41. }
  42. $_aw_class = new AgentWallet();
  43. if (!empty($aor->getAgentId())
  44. && StrUtils::compareNumber($aor->getAgentGain(), CommonConst::CONST_ZERO_COMPARE) > 0) {
  45. /* 添加余额 */
  46. $_rs = $_aw_class->updateWallet($aor->getAgentId(), $aor->getAgentGain(), SettleConst::SETTLE_WALLET_ADD);
  47. if (SettleStatus::NO_ERROR != $_rs) {
  48. return $_rs;
  49. }
  50. }
  51. if (!empty($aor->getParentId())
  52. && StrUtils::compareNumber(
  53. $aor->getParentGain(), CommonConst::CONST_ZERO_COMPARE
  54. ) > 0) {
  55. /* 添加余额 */
  56. $_rs = $_aw_class->updateWallet($aor->getParentId(), $aor->getParentGain(), SettleConst::SETTLE_WALLET_ADD);
  57. if (SettleStatus::NO_ERROR != $_rs) {
  58. return $_rs;
  59. }
  60. }
  61. /* 插入渠道消费订单 */
  62. $_ao_data = $aor->toArray();
  63. $_rs = (new AgentOrderModel())->createOrder($_ao_data);
  64. if (false == $_rs) {
  65. return SettleStatus::ORDER_CREATE_FAIL;
  66. }
  67. return SettleStatus::NO_ERROR;
  68. }
  69. }