From 59996cc33e0282e39f59d1c0c5888ffbd1580092 Mon Sep 17 00:00:00 2001 From: yangduo Date: Tue, 18 Feb 2025 10:16:54 +0800 Subject: [PATCH] js api pay --- .../controller/RechargeController.class.php | 110 +++++++++++++++++- 1 file changed, 104 insertions(+), 6 deletions(-) diff --git a/webapp/controller/RechargeController.class.php b/webapp/controller/RechargeController.class.php index 99c5378..1ef61c8 100644 --- a/webapp/controller/RechargeController.class.php +++ b/webapp/controller/RechargeController.class.php @@ -52,6 +52,10 @@ class RechargeController } $goods_id = $_REQUEST['goods_id']; + if (!$this->checkPurchaseLimit($conn, $account_id, $goods_id)) { + phpcommon\sendError(ERR_USER_BASE + 2, '不能购买'); + return; + } $url = ''; if (SERVER_ENV == _ONLINE) { @@ -247,6 +251,14 @@ class RechargeController )); } + public function preparePay() { + $this->prePay(); + } + + public function preparePayDone() { + $this->purchaseDone(); + } + public function prePurchase() { $account_id = $_REQUEST['account_id']; @@ -453,7 +465,8 @@ class RechargeController 'orderid' => $_REQUEST['orderid'], 'amount' => $_REQUEST['amount'], ); - $oristr = 'account_id=' . $_REQUEST['account_id'] . '&goodsid=' . $_REQUEST['goodsid'] . '&orderid=' . $_REQUEST['orderid'] . '&amount=' . $_REQUEST['amount'] . ':' . $_REQUEST['timestamp'] . 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD'; + $goodsid = $_REQUEST['goodsid']; + $oristr = 'account_id=' . $_REQUEST['account_id'] . '&goodsid=' . $goodsid . '&orderid=' . $_REQUEST['orderid'] . '&amount=' . $_REQUEST['amount'] . ':' . $_REQUEST['timestamp'] . 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD'; // $sign = phpcommon\md5Sign($params, 'NrN3zkVOzXF1vRzUc9eJM9ZKRO5eLooD', $_REQUEST['timestamp']); $sign = md5($oristr); error_log('src:' . $oristr . '|' . $sign . '|' . $_REQUEST['sign']); @@ -466,7 +479,7 @@ class RechargeController die(); } - $shopgoods = metatable\getShopGoodsById($_REQUEST['goodsid']); + $shopgoods = metatable\getShopGoodsById($goodsid); if (!$shopgoods) { error_log('game2004api payNotify goods error:' + json_encode($_REQUEST)); echo json_encode(array( @@ -477,6 +490,7 @@ class RechargeController } if ( + $shopgoods['type'] != 1 && //钻石 $shopgoods['type'] != 2 && //特惠礼包 $shopgoods['type'] != 3 //月卡 ) { @@ -490,7 +504,7 @@ class RechargeController $privilegecard_conf = null; if ($shopgoods['type'] == 3) { - $privilegecard_conf = metatable\getPrivilegeCardById($_REQUEST['goodsid']); + $privilegecard_conf = metatable\getPrivilegeCardById($goodsid); if (!$privilegecard_conf) { error_log('game2004api payNotify privilege card goods config error:' + json_encode($_REQUEST)); echo json_encode(array( @@ -502,6 +516,10 @@ class RechargeController } $conn = $this->getMysql($_REQUEST['account_id']); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } $orderRow = $conn->execQueryOne( 'SELECT * FROM orderinfo WHERE orderid=:orderid', @@ -532,7 +550,7 @@ class RechargeController $all_item_list = array(); $item_list = array(); $addreward = new classes\AddReward(); - if ($shopgoods['first_present'] > 0) { + if ($shopgoods['type'] != 1 && $shopgoods['first_present'] > 0) { array_push($item_list, array( 'item_id' => 10003, 'item_num' => $shopgoods['first_present'], @@ -548,7 +566,86 @@ class RechargeController } $rechargeactivity->updateActivityCur($activity, $shopgoods['price'] * 10, true); - if ($shopgoods['type'] == 3) { + $diamond_present = 0; + if ($shopgoods['type'] == 1) { + $diamonds = $shopgoods['item_num']; + $userrow = $conn->execQueryOne( + 'SELECT diamond_num, free_diamond FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + ) + ); + if (!$userrow) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + + $diamond_present = $shopgoods['first_present']; + if (!$rechargerow) { + $ret = $conn->execScript( + 'INSERT INTO recharge(accountid, first_data, recharge_diamond, present_diamond, activity, create_time, modify_time) ' . + ' VALUES(:account_id, :first_data, :recharge_diamond, :present_diamond, :activity, :create_time, :modify_time) ' . + ' ON DUPLICATE KEY UPDATE accountid=:account_id, first_data=:first_data, recharge_diamond=:recharge_diamond, present_diamond=:present_diamond, activity=:activity, modify_time=:modify_time;', + array( + ':account_id' => $account_id, + ':first_data' => $goodsid, + ':recharge_diamond' => $diamonds, + ':present_diamond' => $diamond_present, + ':activity' => json_encode($activity), + ':create_time' => time(), + ':modify_time' => time() + ) + ); + } else { + $firstlist = explode(',', $rechargerow['first_data']); + $firstrecharge = true; + for ($i = 0; $i < count($firstlist); $i++) { + if ($firstlist[$i] == $goodsid) { + $firstrecharge = false; + } + } + + $firstdata = $rechargerow['first_data']; + if ($firstrecharge) { + if ($firstdata == NULL || $firstdata == '') { + $firstdata = $goodsid; + } else { + $firstdata = $rechargerow['first_data'] . ',' . $goodsid; + } + } else { + $diamond_present = 0; + } + + $ret = $conn->execScript( + 'UPDATE recharge SET first_data=:first_data, recharge_diamond=:recharge_diamond, present_diamond=:present_diamond, activity=:activity, modify_time=:modify_time' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':first_data' => $firstdata, + ':recharge_diamond' => $rechargerow['recharge_diamond'] + $diamonds, + ':present_diamond' => $rechargerow['present_diamond'] + $diamond_present, + ':activity' => json_encode($activity), + ':modify_time' => time() + ) + ); + } + + $diamond_num = $userrow['diamond_num'] + $diamonds + $diamond_present; + + $ret = $conn->execScript( + 'UPDATE user SET diamond_num=:diamond_num' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':diamond_num' => $diamond_num + ) + ); + array_push($item_list, array( + 'item_id' => 10003, + 'item_num' => $diamonds + $diamond_present, + 'time' => 0, + )); + } else if ($shopgoods['type'] == 3) { $nowtime = time(); // update vip_info if (!$rechargerow) { @@ -720,7 +817,7 @@ class RechargeController if ($r) { $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); - $adfree = $addreward->getAdfree($account_id); + $adfree = $addreward->getAdfree($account_id); $privilege = new classes\Privilege(); $plustimes = $privilege->getCoinTimesPlus($account_id); $user_purchase = array( @@ -730,6 +827,7 @@ class RechargeController 'status' => 1, 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, + 'diamond_present' => $diamond_present, 'adfree' => $adfree, 'vip_plustime' => $plustimes, 'item_list' => $item_list,