* @version : HUOSDK 8.0 */ namespace huo\controller\agent; use huo\controller\common\Base; use huo\controller\finance\AoRequest; use huo\model\agent\AgentOrderModel; use huolib\constant\CommonConst; use huolib\constant\SettleConst; use huolib\status\SettleStatus; use huolib\tool\StrUtils; use think\Log; class AgentOrder extends Base { /** * 创建渠道收益订单 * * @param AoRequest $aor * * @return int */ public function createAoOrder(AoRequest $aor) { /* 查询次订单是否获取过收益 */ $_ao_model = new AgentOrderModel(); $_ao_info = $_ao_model->getInfoByOrderId($aor->getOrderId()); if (!empty($_ao_info)) { $_code = SettleStatus::ORDER_HAS_SHARE; Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&code=".$_code.'&msg='.SettleStatus::getMsg($_code)."&order=" .http_build_query($aor->toArray()), LOG::ERROR ); return $_code; } $_aw_class = new AgentWallet(); if (!empty($aor->getAgentId()) && StrUtils::compareNumber($aor->getAgentGain(), CommonConst::CONST_ZERO_COMPARE) > 0) { /* 添加余额 */ $_rs = $_aw_class->updateWallet($aor->getAgentId(), $aor->getAgentGain(), SettleConst::SETTLE_WALLET_ADD); if (SettleStatus::NO_ERROR != $_rs) { return $_rs; } } if (!empty($aor->getParentId()) && StrUtils::compareNumber( $aor->getParentGain(), CommonConst::CONST_ZERO_COMPARE ) > 0) { /* 添加余额 */ $_rs = $_aw_class->updateWallet($aor->getParentId(), $aor->getParentGain(), SettleConst::SETTLE_WALLET_ADD); if (SettleStatus::NO_ERROR != $_rs) { return $_rs; } } /* 插入渠道消费订单 */ $_ao_data = $aor->toArray(); $_rs = (new AgentOrderModel())->createOrder($_ao_data); if (false == $_rs) { return SettleStatus::ORDER_CREATE_FAIL; } return SettleStatus::NO_ERROR; } }