* @version : HUOSDK 8.0 */ namespace huo\controller\wallet; use huo\controller\agent\AgentWallet; use huo\controller\common\Base; use huo\controller\finance\Income; use huo\controller\member\MemWallet; use huo\model\finance\GmChargeModel; use huo\model\finance\PtbAgentChargeModel; use huo\model\finance\PtbChargeModel; use huoAccountDeal\controller\AccountOrder; use huolib\constant\OrderConst; use huolib\constant\SettleConst; use huolib\constant\WalletConst; use huolib\pay\Pay; use huolib\status\OrderStatus; use think\Exception; use think\Log; class Notify extends Base { /** * @param $payway * * @return bool */ public function notifyUrl($payway) { try { $_pay_class = Pay::ins()->get($payway); } catch (Exception $e) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&payway=".$payway.'&data='.json_encode($_REQUEST), LOG::ERROR ); exit('fail'); } $_order_class = '\\huo\\controller\\wallet\\Notify'; $_func = 'payNotify'; $_pay_class->setOrderClass($_order_class); $_pay_class->setFunc($_func); return $_pay_class->notifyUrl(); } /** * @param string $product_id * @param string $order_id * @param string $trade_no * @param float $amount * @param string $payway * * @return bool */ public function payNotify($product_id, $order_id, $trade_no, $amount, $payway) { switch ($product_id) { case WalletConst::WALLET_PRODUCT_MEM_PTB: return $this->payNotifyPtbCharge($order_id, $trade_no, $amount, $payway); case WalletConst::WALLET_PRODUCT_AGENT_PTB: return $this->payNotifyAgentPtbCharge($order_id, $trade_no, $amount, $payway); case WalletConst::WALLET_PRODUCT_MEM_GM: return $this->payNotifyGmCharge($order_id, $trade_no, $amount, $payway); case WalletConst::WALLET_PRODUCT_ACCOUNT: return $this->payNotifyByAccount($order_id, $trade_no, $amount, $payway); default: return false; } } /** * @param string $order_id * @param string $trade_no * @param float $amount * @param string $payway * * @return bool */ public function payNotifyPtbCharge($order_id, $trade_no, $amount, $payway) { $_notify_data['order_id'] = $order_id; $_notify_data['trade_no'] = $trade_no; $_notify_data['amount'] = $amount; $_notify_data['payway'] = $payway; if (empty($order_id)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step1&code=".OrderStatus::ORDER_ID_EMPTY.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } if (empty($amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step2&code=".OrderStatus::ORDER_AMOUNT_IS_ZERO .'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_pc_model = new PtbChargeModel(); $_order_data = $_pc_model->getDetail($order_id); if (false == $_order_data) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step3&code=".OrderStatus::ORDER_NOT_EXISTS.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_amount = number_format($amount, 2, '.', ''); $_order_amount = number_format($_order_data['real_amount'], 2, '.', ''); if (($_amount < $_order_amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step4&code=".OrderStatus::NOTIFY_AMOUNT_ERROR.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::ERROR ); return false; } if (OrderConst::PAY_STATUS_SUC == $_order_data['status']) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step5&code=".OrderStatus::ORDER_HAS_PAY.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::LOG ); return true; } /* 更新订单支付状态 */ $_order_data['status'] = OrderConst::PAY_STATUS_SUC; $_order_data['remark'] = $trade_no; $_rs = $_pc_model->updateOrder($_order_data, $_order_data['id']); if (false == $_rs) { return false; } $_wr_class = new WalletRequest(); $_wr_class->setPtbChargeData($_order_data); $this->doAfterPtbCharge($_wr_class); return true; } /** * @param WalletRequest $wr */ public function doAfterPtbCharge(WalletRequest $wr) { (new MemWallet())->updatePtb($wr->getMemId(), $wr->getPtbCnt(), SettleConst::SETTLE_WALLET_ADD); // TODO: wuyonghong 2018/5/16 平台币充值成功后需要做的操作 (new Income())->incomeFromPmc($wr->getOrderId()); } public function payNotifyAgentPtbCharge($order_id, $trade_no, $amount, $payway) { $_notify_data['order_id'] = $order_id; $_notify_data['trade_no'] = $trade_no; $_notify_data['amount'] = $amount; $_notify_data['payway'] = $payway; if (empty($order_id)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step1&code=".OrderStatus::ORDER_ID_EMPTY.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } if (empty($amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step2&code=".OrderStatus::ORDER_AMOUNT_IS_ZERO .'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_pc_model = new PtbAgentChargeModel(); $_order_data = $_pc_model->getDetail($order_id); if (false == $_order_data) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step3&code=".OrderStatus::ORDER_NOT_EXISTS.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_amount = number_format($amount, 2, '.', ''); $_order_amount = number_format($_order_data['real_amount'], 2, '.', ''); if (($_amount < $_order_amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step4&code=".OrderStatus::NOTIFY_AMOUNT_ERROR.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::ERROR ); return false; } if (OrderConst::PAY_STATUS_SUC == $_order_data['status']) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step5&code=".OrderStatus::ORDER_HAS_PAY.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::LOG ); return false; } /* 更新订单支付状态 */ $_order_data['status'] = OrderConst::PAY_STATUS_SUC; $_order_data['remark'] = $trade_no; $_rs = $_pc_model->updateOrder($_order_data, $_order_data['id']); if (false == $_rs) { return false; } $_wr_class = new WalletRequest(); $_wr_class->setPtbAgentChargeData($_order_data); $this->doAfterAgentPtbCharge($_wr_class); return true; } /** * @param WalletRequest $wr */ public function doAfterAgentPtbCharge(WalletRequest $wr) { (new AgentWallet())->updatePtb($wr->getAgentId(), $wr->getPtbCnt(), SettleConst::SETTLE_WALLET_ADD); /* 计算收益 */ (new Income())->incomeFromPac($wr->getOrderId()); } /** * @param string $order_id * @param string $trade_no * @param float $amount * @param string $payway * * @return bool */ public function payNotifyGmCharge($order_id, $trade_no, $amount, $payway) { $_notify_data['order_id'] = $order_id; $_notify_data['trade_no'] = $trade_no; $_notify_data['amount'] = $amount; $_notify_data['payway'] = $payway; if (empty($order_id)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step1&code=".OrderStatus::ORDER_ID_EMPTY.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } if (empty($amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step2&code=".OrderStatus::ORDER_AMOUNT_IS_ZERO .'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_pc_model = new GmChargeModel(); $_order_data = $_pc_model->getDetail($order_id); if (false == $_order_data) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step3&code=".OrderStatus::ORDER_NOT_EXISTS.'¬ify_data.' .http_build_query($_notify_data), LOG::ERROR ); return false; } $_amount = number_format($amount, 2, '.', ''); $_order_amount = number_format($_order_data['real_amount'], 2, '.', ''); if (($_amount < $_order_amount)) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step4&code=".OrderStatus::NOTIFY_AMOUNT_ERROR.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::ERROR ); return false; } if (OrderConst::PAY_STATUS_SUC == $_order_data['status']) { Log::write( "func=".__FUNCTION__."&class=".__CLASS__."&step5&code=".OrderStatus::ORDER_HAS_PAY.'¬ify_data.' .http_build_query($_notify_data).'&order_data='.http_build_query($_order_data), LOG::LOG ); return true; } /* 更新订单支付状态 */ $_order_data['status'] = OrderConst::PAY_STATUS_SUC; $_order_data['remark'] = $trade_no; $_rs = $_pc_model->updateOrder($_order_data, $_order_data['id']); if (false == $_rs) { return false; } $_wr_class = new WalletRequest(); $_wr_class->setGmChargeData($_order_data); $this->doAfterGmCharge($_wr_class); return true; } /** * @param WalletRequest $wr */ public function doAfterGmCharge(WalletRequest $wr) { //修改玩家游戏币余额 (new MemWallet())->updateGm($wr->getMemId(), $wr->getAppId(), $wr->getGmCnt(), SettleConst::SETTLE_WALLET_ADD); } /** * 玩家购买小号 * * @param $order_id * @param $trade_no * @param $amount * @param $payway * * @return bool */ private function payNotifyByAccount($order_id, $trade_no, $amount, $payway) { return (new AccountOrder())->payNotifyByAccount($order_id, $trade_no, $amount, $payway); } }