From 8dc4e103c229c61e9fc3d5c7a70dadac7905c240 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 9 Nov 2020 13:19:05 +0800 Subject: [PATCH] 1 --- webapp/classes/OrderCtrl.php | 56 +++++++++++++++++++++++ webapp/controller/PayController.class.php | 24 ++++++++++ webapp/sdkwarpper/GoogleAndroid.php | 30 ++++++++++++ 3 files changed, 110 insertions(+) diff --git a/webapp/classes/OrderCtrl.php b/webapp/classes/OrderCtrl.php index 912cc91..6b7add1 100644 --- a/webapp/classes/OrderCtrl.php +++ b/webapp/classes/OrderCtrl.php @@ -65,6 +65,20 @@ class OrderCtrl { return $row; } + public function getOrderBySpOrderId($account_id, $channel, $sp_orderid) + { + $conn = $this->getMysql($this->getStrDNA($account_id)); + $row = $conn->execQueryOne('SELECT * FROM orderinfo ' . + 'WHERE account_id=:account_id AND channel=:channel AND sp_orderid=:sp_orderid;', + array( + ':account_id' => $account_id, + ':channel' => $channel, + ':sp_orderid' => $sp_orderid, + ) + ); + return $row; + } + public function getReceipt($receipt_id) { $conn = $this->getMysql($this->getStrDNA($receipt_id)); @@ -110,6 +124,11 @@ class OrderCtrl { return $this->internalAddOrder($pre_order_info); } + public function addComplateOrder($order_info) + { + return $this->internalAddOrder($order_info); + } + private function internalAddOrder($order_info) { $gameid = phpcommon\extractGameId($order_info['account_id']); @@ -177,4 +196,41 @@ class OrderCtrl { return $ret; } + public function getPendingOrderList($account_id) + { + $conn = $this->getMysql($this->getStrDNA($account_id)); + $rows = $conn->execQuery('SELECT orderid, sp_orderid, itemid, status FROM orderinfo ' . + 'WHERE account_id=:account_id AND status != 2;', + array( + ':account_id' => $account_id + ) + ); + $data = array(); + foreach ($rows as $row ) { + array_push($data, array( + 'cp_orderid' => $row['orderid'], + 'sp_orderid' => $row['sp_orderid'], + 'itemid' => $row['itemid'], + 'status' => $row['status'], + )); + } + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + 'order_list' => $data + )); + } + + public function deliver($account_id, $cp_orderid) + { + $conn = $this->getMysql($this->getStrDNA($account_id)); + $row = $conn->execQueryOne('SELECT orderid, sp_orderid, itemid, status FROM orderinfo ' . + 'WHERE account_id=:account_id AND orderid=:orderid;', + array( + ':account_id' => $account_id, + ':orderid' => $cp_orderid + ) + ); + } + } diff --git a/webapp/controller/PayController.class.php b/webapp/controller/PayController.class.php index b1180ad..174b6c2 100644 --- a/webapp/controller/PayController.class.php +++ b/webapp/controller/PayController.class.php @@ -1,5 +1,7 @@ getPendingOrderList($_REQUEST['account_id']); + } + + public function deliver() + { + if (!phpcommon\isValidSessionId($_REQUEST['account_id'], $_REQUEST['session_id'])) { + phpcommon\sendError(1, 'session无效'); + return; + } + require 'classes/OrderCtrl.php'; + $order_ctrl = new classes\OrderCtrl(); + $order_ctrl->deliver($_REQUEST['account_id'], $_REQUEST['cp_orderid']); + } + public function payNotify() { error_log(json_encode($_REQUEST)); diff --git a/webapp/sdkwarpper/GoogleAndroid.php b/webapp/sdkwarpper/GoogleAndroid.php index b577d6f..1597243 100644 --- a/webapp/sdkwarpper/GoogleAndroid.php +++ b/webapp/sdkwarpper/GoogleAndroid.php @@ -56,9 +56,39 @@ class GoogleAndroid extends BaseSdk { $response, $proxy)) { phpcommon\sendError(2, '服务器内部错误'); + return; } error_log($response); echo $response; + + $receipt_info = array(); + $receipt_db = $this->order_ctrl->getReceipt($receipt_info['purchaseToken']); + $order_db = $this->order_ctrl->getOrderBySpOrderId( + $_REQUEST['account_id'], + $this->real_channel, + $receipt_info['purchaseToken'] + ); + if ($receipt_db) { + if ($receipt_db['account_id'] != $_REQUEST['account_id']) { + phpcommon\sendError(2, '账号id不匹配'); + return; + } + if ($order_db) { + echo json_encode(array( + 'errcode' => 0, + 'errmsg' => '', + + 'cp_orderid' => $order_db['orderid'], + 'status' => $order_db['status'], + )); + return; + } else { + phpcommon\sendError(2, '订单不存在'); + return; + } + } else { + $cp_orderid = $this->genOrderId($_REQUEST['account_id']); + } } }