From 92ce24b773ec737480ac128ed5ed5d894538a667 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 25 Sep 2024 11:48:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E5=85=85=E5=80=BC=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/controller/ShopController.class.php | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 1f054cfd..6cc46eb8 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -196,6 +196,105 @@ class ShopController extends BaseAuthedController { ); } + +public function inappPurchase() + { + $goodsId = getReqVal('goods_id', 0); + $goodsNum = getReqVal('goods_num', 0); + $platform = getReqVal('platform', 0); + $balance = $this->getInAppBalance(); + + if ($balance <= 0) { + $this->_rspErr(2, "insufficient available balance"); + return; + } + $goodsMeta = mt\ShopGoods::getByGoodsUuid($goodsId); + if (!$goodsMeta) { + $this->_rspErr(2, "inapp purchase failed"); + return; + } + if (!in_array($goodsMeta['shop_id'], + array( + mt\Shop::INAPP_SHOP_DIAMOND + ) + )) { + $this->_rspErr(3, "inapp purchase failed"); + return; + } + if ($goodsNum != 1) { + $this->_rspErr(3, "goods_num error"); + return; + } + if ($goodsMeta['token_type'] != mt\Shop::TOKEN_TYPE_USD) { + $this->_rspErr(3, "token_type config error"); + return; + } + if (!InAppOrder::isValidPlatform($platform)) { + $this->_rspErr(1, "error paramater platform"); + return; + } + $price = $goodsMeta['price']; + if (empty($price) || $price < 0.001) { + $this->_rspErr(1, "config error"); + return; + } + + $orderId = OrderId::genInappOrderId(); + InAppOrder::add( + $orderId, + $platform, + $goodsId, + $price + ); + InAppRecord::addAmount($price); + $this->_rspData(array( + 'order_id' => $orderId, + )); + } + + public function queryInAppPurchase() + { + $orderId = getReqVal('order_id', ''); + $orderDb = InAppOrder::find($orderId); + if (!$orderDb) { + myself()->_rspErr(1, 'order not found'); + return; + } + $goodsMeta = mt\ShopGoods::get($orderDb['goods_id']); + error_log(json_encode($orderDb)); + error_log(json_encode($goodsMeta)); + $this->_rspData(array( + 'order_id' => $orderDb['order_id'], + 'item_id' => $goodsMeta['item_id'], + 'item_num' => $goodsMeta['item_num'], + 'status' => $orderDb['status'], + )); + } + + public function queryInAppBalance() + { + myself()->_rspData( + array( + 'balance' => $this->getInAppBalance() + ) + ); + } + + private function getInAppBalance() + { + $totalAmount = InAppRecord::getTotalAmount(); + $recordDb = InAppRecord::get(); + $upLimit = mt\Parameter::getVal('inapp_daily_up_limit', 0); + $totalUpLimit = mt\Parameter::getVal('inapp_total_up_limit', 0); + $todayAmount = 0; + if ($recordDb) { + $todayAmount = max($recordDb['amount'], $recordDb['amount_ok']); + } + $dailyBalance = max(0, $upLimit - $todayAmount); + $totalBalance = max(0, $totalUpLimit - $totalAmount); + return min($dailyBalance, $totalBalance); + } + private function internalAddItem($awardService, $propertyChgService, $itemMeta, @@ -213,4 +312,5 @@ class ShopController extends BaseAuthedController { $propertyChgService); } + }