From b8e8982832a14b830f4d0f0be537261774ee477c Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Fri, 10 May 2019 10:31:08 +0800 Subject: [PATCH] 1 --- webapp/controller/EquipController.class.php | 59 +++++++++++-------- .../controller/SupplyBoxController.class.php | 5 +- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php index 40625b5..bb53921 100644 --- a/webapp/controller/EquipController.class.php +++ b/webapp/controller/EquipController.class.php @@ -36,6 +36,35 @@ class EquipController{ return $e; } + protected function subCoin($account_id, $equip_id) + { + $e = $this->getEquip($equip_id); + if (!$e) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); + return; + } + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); + return; + } + $rowCoin = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', + array( + ':accountid' => $account_id + )); + if ($rowCoin['coin_num'] < $e['equip_cost']) { + phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); + return; + } + $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num ' . + ' WHERE accountid=:accountid;', + array( + ':accountid' => $account_id, + ':coin_num' => $rowCoin['coin_num'] - $e['equip_cost'] + )); + return $e; + } + public function equipInfo() { $account_id = $_REQUEST['account_id']; @@ -105,36 +134,15 @@ class EquipController{ $equip_id = $_REQUEST['equip_id']; $coin_num = $_REQUEST['coin_num']; $equip_level = $_REQUEST['equip_level']; - if ($equip_level >= 10) { - phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); - return; - } - $e = $this->getEquip($equip_id * 10 + $equip_level); - if (!$e) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); - return; - } - $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if ($row['coin_num'] < $e['equip_cost']) { - phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); - return; - } - $ret = $conn->execScript('UPDATE user SET coin_num=:coin_num ' . - ' WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':coin_num' => $row['coin_num'] - $e['equip_cost'] - )); $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', array( ':account_id' => $account_id, ':equip_id' => $equip_id )); + if (!$row) { + $e = $this->subCoin($account_id, $equip_id * 10 + 1); $ret = $conn->execScript('INSERT INTO equip(accountid, equip_id, equip_level, equip_experience_level, active_time) ' . ' VALUES(:accountid, :equip_id, :equip_level, :equip_experience_level, :active_time);', array( @@ -149,6 +157,11 @@ class EquipController{ return; } } else { + if ($row['equip_level'] >= 10) { + phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); + return; + } + $e = $this->subCoin($account_id, $equip_id * 10 + $row['equip_level']); $ret = $conn->execScript('UPDATE equip SET equip_level=:equip_level ' . ' WHERE accountid=:account_id AND equip_id=:equip_id;', array( diff --git a/webapp/controller/SupplyBoxController.class.php b/webapp/controller/SupplyBoxController.class.php index cf72c78..64b9016 100644 --- a/webapp/controller/SupplyBoxController.class.php +++ b/webapp/controller/SupplyBoxController.class.php @@ -278,10 +278,7 @@ class SupplyBoxController{ array( ':accountid' => $account_id )); - var_dump($s['price']); - var_dump($s['parameter']); - var_dump($row['buy_times']); - var_dump($s['price'] * pow($s['parameter'], ($row['buy_times']))); + if ($row1['coin_num'] < $s['price'] * pow($s['parameter'], ($row['buy_times']))) { phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); return;