123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- <?php
- /**
- * Notify.php UTF-8
- *
- *
- * @date : 2018/5/16 23:21
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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);
- }
- }
|