This commit is contained in:
yangduo 2025-02-13 14:42:17 +08:00
parent 20776fcb3f
commit 6b7002e0f9

View File

@ -3,7 +3,8 @@
require 'classes/Quest.php'; require 'classes/Quest.php';
require 'classes/AddReward.php'; require 'classes/AddReward.php';
class BagController{ class BagController
{
protected function getMysql($account_id) protected function getMysql($account_id)
{ {
@ -71,23 +72,27 @@ class BagController{
return; return;
} }
$bag_list = array(); $bag_list = array();
$rows = $conn->execQuery('SELECT * FROM bag WHERE accountid=:account_id;', $rows = $conn->execQuery(
'SELECT * FROM bag WHERE accountid=:account_id;',
array( array(
':account_id' => $account_id ':account_id' => $account_id
)); )
);
if ($rows) { if ($rows) {
foreach ($rows as $row){ foreach ($rows as $row) {
$active_time = 0; $active_time = 0;
$color_id = 0; $color_id = 0;
$status = $row['status']; $status = $row['status'];
if (time() >= $row['active_time'] && $row['active_time'] != 0) { if (time() >= $row['active_time'] && $row['active_time'] != 0) {
$ret = $conn->execScript('UPDATE bag SET active_time=0, color_id=0, status=2, modify_time=:modify_time ' . $ret = $conn->execScript(
'UPDATE bag SET active_time=0, color_id=0, status=2, modify_time=:modify_time ' .
' WHERE accountid=:account_id AND id=:id;', ' WHERE accountid=:account_id AND id=:id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $row['id'], ':id' => $row['id'],
':modify_time' => time() ':modify_time' => time()
)); )
);
if (!$ret) { if (!$ret) {
die(); die();
return; return;
@ -118,7 +123,8 @@ class BagController{
)); ));
} }
public function exchangeBagItem() { public function exchangeBagItem()
{
$account_id = $_REQUEST['account_id']; $account_id = $_REQUEST['account_id'];
//登录校验 //登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']); $login = loginVerify($account_id, $_REQUEST['session_id']);
@ -129,12 +135,18 @@ class BagController{
$item_id = $_REQUEST['item_id']; $item_id = $_REQUEST['item_id'];
$color_id = $_REQUEST['color_id']; $color_id = $_REQUEST['color_id'];
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
if(!$conn){ if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return; return;
} }
$b = $this->getBag($item_id); $b = $this->getBag($item_id);
$bag_meta_table = require('../res/bag@bag.php'); $bag_meta_table = require('../res/bag@bag.php');
$rsp = array(
'errcode' => 0,
'errmsg' => '',
'item_id' => $item_id,
'color_id' => $color_id
);
//正在装备的道具 //正在装备的道具
if ($b['fuction'] != 5 && $b['fuction'] != 6) { if ($b['fuction'] != 5 && $b['fuction'] != 6) {
foreach ($bag_meta_table as $bag_info) { foreach ($bag_meta_table as $bag_info) {
@ -146,11 +158,13 @@ class BagController{
if ($bag['fuction'] != $b['fuction']) { if ($bag['fuction'] != $b['fuction']) {
continue; continue;
} }
$row = $conn->execQueryOne('SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;', $row = $conn->execQueryOne(
'SELECT status, active_time, color_id FROM bag WHERE accountid=:accountid AND id=:id;',
array( array(
':accountid' => $account_id, ':accountid' => $account_id,
':id' => $id, ':id' => $id,
)); )
);
if (!$row || $row['status'] != 0) { if (!$row || $row['status'] != 0) {
continue; continue;
} }
@ -158,50 +172,68 @@ class BagController{
if ($row['active_time'] == 0 || $row['active_time'] > time()) { if ($row['active_time'] == 0 || $row['active_time'] > time()) {
$status = 1; $status = 1;
} }
$using_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' . $altercolor = false;
$colorid = 0;
if ($id == $item_id) {
$altercolor = true;
//仅改变颜色
if ($color_id == $row['color_id']) {
echo json_encode($rsp);
return;
}
$status = 0;
$colorid = $color_id;
}
$using_ret = $conn->execScript(
'UPDATE bag SET status=:status, color_id=:colorid, modify_time=:modify_time ' .
' WHERE accountid = :account_id AND id = :id;', ' WHERE accountid = :account_id AND id = :id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $id, ':id' => $id,
':status' => $status, ':status' => $status,
':colorid' => $colorid,
':modify_time' => time() ':modify_time' => time()
)); )
if(!$using_ret){ );
if (!$using_ret) {
die(); die();
return; return;
} }
if ($altercolor) {
echo json_encode($rsp);
return;
}
} }
} }
//要装备的道具 //要装备的道具
$row = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:accountid AND id=:id;', $row = $conn->execQueryOne(
'SELECT status FROM bag WHERE accountid=:accountid AND id=:id;',
array( array(
':accountid' => $account_id, ':accountid' => $account_id,
':id' => $item_id, ':id' => $item_id,
)); )
);
if (!$row || $row['status'] != 1 || ($row['active_time'] > 0 && $row['active_time'] < time())) { if (!$row || $row['status'] != 1 || ($row['active_time'] > 0 && $row['active_time'] < time())) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
return; return;
} }
$exchange_ret = $conn->execScript('UPDATE bag SET status=0, color_id=:color_id, modify_time=:modify_time ' . $exchange_ret = $conn->execScript(
'UPDATE bag SET status=0, color_id=:color_id, modify_time=:modify_time ' .
' WHERE accountid = :account_id AND id = :id;', ' WHERE accountid = :account_id AND id = :id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $item_id, ':id' => $item_id,
':color_id' => $color_id, ':color_id' => $color_id,
':modify_time' => time() ':modify_time' => time()
)); )
if(!$exchange_ret){ );
if (!$exchange_ret) {
die(); die();
return; return;
} }
echo json_encode(array( echo json_encode($rsp);
'errcode' => 0,
'errmsg' => '',
'item_id' => $item_id,
'color_id' => $color_id
));
} }
public function downItem() public function downItem()
@ -215,17 +247,19 @@ class BagController{
} }
$item_id = $_REQUEST['item_id']; $item_id = $_REQUEST['item_id'];
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
if(!$conn){ if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return; return;
} }
$b = $this->getBag($item_id); $b = $this->getBag($item_id);
$row = $conn->execQueryOne('SELECT status,active_time FROM bag WHERE accountid=:accountid AND id=:id;', $row = $conn->execQueryOne(
'SELECT status,active_time FROM bag WHERE accountid=:accountid AND id=:id;',
array( array(
':accountid' => $account_id, ':accountid' => $account_id,
':id' => $item_id, ':id' => $item_id,
)); )
);
if (!$row || $row['status'] != 0) { if (!$row || $row['status'] != 0) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具'); phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
return; return;
@ -234,15 +268,17 @@ class BagController{
if ($row['active_time'] == 0 || $row['active_time'] > time()) { if ($row['active_time'] == 0 || $row['active_time'] > time()) {
$status = 1; $status = 1;
} }
$exchange_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' . $exchange_ret = $conn->execScript(
'UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' .
' WHERE accountid = :account_id AND id = :id;', ' WHERE accountid = :account_id AND id = :id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $item_id, ':id' => $item_id,
':status' => $status, ':status' => $status,
':modify_time' => time() ':modify_time' => time()
)); )
if(!$exchange_ret){ );
if (!$exchange_ret) {
die(); die();
return; return;
} }
@ -266,19 +302,21 @@ class BagController{
} }
$item_id = $_REQUEST['item_id']; $item_id = $_REQUEST['item_id'];
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
if(!$conn){ if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return; return;
} }
$exchange_ret = $conn->execScript('UPDATE bag SET color_id=0, modify_time=:modify_time ' . $exchange_ret = $conn->execScript(
'UPDATE bag SET color_id=0, modify_time=:modify_time ' .
' WHERE accountid = :account_id AND id = :id;', ' WHERE accountid = :account_id AND id = :id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $item_id, ':id' => $item_id,
':modify_time' => time() ':modify_time' => time()
)); )
if(!$exchange_ret){ );
if (!$exchange_ret) {
die(); die();
return; return;
} }
@ -302,7 +340,7 @@ class BagController{
} }
$item_id = $_REQUEST['item_id']; $item_id = $_REQUEST['item_id'];
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
if(!$conn){ if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return; return;
} }
@ -348,7 +386,7 @@ class BagController{
'time' => 1, 'time' => 1,
)); ));
$items = $addreward->addReward($i, 1, $account_id, $time, 1); $items = $addreward->addReward($i, 1, $account_id, $time, 1);
foreach($items as $it) { foreach ($items as $it) {
array_push($all_item_list, array( array_push($all_item_list, array(
'item_id' => $it['item_id'], 'item_id' => $it['item_id'],
'item_num' => $it['item_num'], 'item_num' => $it['item_num'],
@ -376,17 +414,19 @@ class BagController{
return; return;
} }
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
if(!$conn){ if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return; return;
} }
$arr = json_decode($_REQUEST['arr'], true); $arr = json_decode($_REQUEST['arr'], true);
foreach ($arr as $a) { foreach ($arr as $a) {
$row = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:account_id AND id=:id;', $row = $conn->execQueryOne(
'SELECT status FROM bag WHERE accountid=:account_id AND id=:id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
':id' => $a['id'] ':id' => $a['id']
)); )
);
if (!$row) { if (!$row) {
continue; continue;
} }
@ -394,7 +434,8 @@ class BagController{
if ($a['count'] == 0) { if ($a['count'] == 0) {
$status = 2; $status = 2;
} }
$ret = $conn->execScript('UPDATE bag SET status=:status, num=:num, modify_time=:modify_time ' . $ret = $conn->execScript(
'UPDATE bag SET status=:status, num=:num, modify_time=:modify_time ' .
' WHERE accountid = :account_id AND id = :id;', ' WHERE accountid = :account_id AND id = :id;',
array( array(
':account_id' => $account_id, ':account_id' => $account_id,
@ -402,8 +443,9 @@ class BagController{
':status' => $status, ':status' => $status,
':num' => $a['count'], ':num' => $a['count'],
':modify_time' => time() ':modify_time' => time()
)); )
if(!$ret){ );
if (!$ret) {
die(); die();
return; return;
} }
@ -414,4 +456,3 @@ class BagController{
)); ));
} }
} }
?>