453 lines
15 KiB
PHP
453 lines
15 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
|
|
class BagController
|
|
{
|
|
|
|
protected function getMysql($account_id)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($account_id));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getBag($bag_id)
|
|
{
|
|
$g_conf_bag_cluster = require('../res/bag@bag.php');
|
|
$bag_conf = getBagConfig($g_conf_bag_cluster, $bag_id);
|
|
$b = array(
|
|
'id' => $bag_conf['id'],
|
|
'name' => $bag_conf['name'],
|
|
'fuction' => $bag_conf['fuction'],
|
|
);
|
|
return $b;
|
|
}
|
|
|
|
protected function getItem($item_id)
|
|
{
|
|
$g_conf_item_cluster = require('../res/item@item.php');
|
|
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
|
|
$it = array(
|
|
'id' => $item_conf['id'],
|
|
'diamond' => $item_conf['diamond'],
|
|
'dprice' => $item_conf['dprice'],
|
|
'type' => $item_conf['fuction'],
|
|
'diamond_hour' => $item_conf['diamond_hour']
|
|
);
|
|
return $it;
|
|
}
|
|
|
|
protected function getParameter($para_id)
|
|
{
|
|
$g_conf_para_cluster = require('../res/parameter@parameter.php');
|
|
$para_conf = getParameterConfig($g_conf_para_cluster, $para_id);
|
|
$p = array(
|
|
'id' => $para_conf['id'],
|
|
'param_name' => $para_conf['param_name'],
|
|
'param_value' => $para_conf['param_value'],
|
|
);
|
|
return $p;
|
|
}
|
|
|
|
public function getBagInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$bag_list = array();
|
|
$rows = $conn->execQuery(
|
|
'SELECT * FROM bag WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id
|
|
)
|
|
);
|
|
if ($rows) {
|
|
foreach ($rows as $row) {
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = $row['status'];
|
|
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 ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $row['id'],
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = 2;
|
|
} else {
|
|
if ($row['active_time'] != 0) {
|
|
$active_time = $row['active_time'];
|
|
}
|
|
$color_id = $row['color_id'];
|
|
$status = $row['status'];
|
|
}
|
|
array_push($bag_list, array(
|
|
'id' => $row['id'],
|
|
'active_time' => $active_time,
|
|
'status' => $status,
|
|
'color_id' => $color_id,
|
|
'num' => $row['num'],
|
|
));
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'bag_list' => $bag_list
|
|
));
|
|
}
|
|
|
|
public function exchangeBagItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$color_id = $_REQUEST['color_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$b = $this->getBag($item_id);
|
|
$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) {
|
|
foreach ($bag_meta_table as $bag_info) {
|
|
if ($bag_info['fuction'] != $b['fuction']) {
|
|
continue;
|
|
}
|
|
$id = $bag_info['id'];
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status, active_time, color_id FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id,
|
|
)
|
|
);
|
|
if (!$row || $row['status'] != 0) {
|
|
continue;
|
|
}
|
|
$status = 2;
|
|
if ($row['active_time'] == 0 || $row['active_time'] > time()) {
|
|
$status = 1;
|
|
}
|
|
$colorid = 0;
|
|
if ($id == $item_id) {
|
|
//仅改变颜色
|
|
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;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $id,
|
|
':status' => $status,
|
|
':colorid' => $colorid,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$using_ret) {
|
|
die();
|
|
return;
|
|
}
|
|
if ($id == $item_id) {
|
|
echo json_encode($rsp);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//要装备的道具
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $item_id,
|
|
)
|
|
);
|
|
if (!$row || $row['status'] != 1 || ($row['active_time'] > 0 && $row['active_time'] < time())) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
|
|
$exchange_ret = $conn->execScript(
|
|
'UPDATE bag SET status=0, color_id=:color_id, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':color_id' => $color_id,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$exchange_ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode($rsp);
|
|
}
|
|
|
|
public function downItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$b = $this->getBag($item_id);
|
|
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status,active_time FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $item_id,
|
|
)
|
|
);
|
|
if (!$row || $row['status'] != 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
$status = 2;
|
|
if ($row['active_time'] == 0 || $row['active_time'] > time()) {
|
|
$status = 1;
|
|
}
|
|
$exchange_ret = $conn->execScript(
|
|
'UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':status' => $status,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$exchange_ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function downItemColor()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
$exchange_ret = $conn->execScript(
|
|
'UPDATE bag SET color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$exchange_ret) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function tryItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$ptime = $this->getParameter(RECOMMEND_TIME);
|
|
$addreward->addReward($item_id, 1, $account_id, $ptime['param_value'], 0);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function freeGetItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$arr = $_REQUEST['arr'];
|
|
$delim = ',';
|
|
$item_multiply = explode($delim, $arr);
|
|
$all_item_list = array();
|
|
$item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
$random = Rand(0, 10000);
|
|
$time = 1;
|
|
$p = $this->getParameter(RECOMMEND_FOREVER_WEIGHT);
|
|
$ptime = $this->getParameter(RECOMMEND_TIME);
|
|
if ($random < $p['param_value']) {
|
|
$time = 0;
|
|
} else {
|
|
$time = $ptime['param_value'];
|
|
}
|
|
foreach ($item_multiply as $i) {
|
|
array_push($item_list, array(
|
|
'item_id' => $i,
|
|
'item_num' => 1,
|
|
'time' => 1,
|
|
));
|
|
$items = $addreward->addReward($i, 1, $account_id, $time, 1);
|
|
foreach ($items as $it) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $it['item_id'],
|
|
'item_num' => $it['item_num'],
|
|
'time' => $it['time'],
|
|
));
|
|
}
|
|
}
|
|
$num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'diamond_nums' => $num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
public function updateWeizhuang()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$arr = json_decode($_REQUEST['arr'], true);
|
|
foreach ($arr as $a) {
|
|
$row = $conn->execQueryOne(
|
|
'SELECT status FROM bag WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $a['id']
|
|
)
|
|
);
|
|
if (!$row) {
|
|
continue;
|
|
}
|
|
$status = $row['status'];
|
|
if ($a['count'] == 0) {
|
|
$status = 2;
|
|
}
|
|
$ret = $conn->execScript(
|
|
'UPDATE bag SET status=:status, num=:num, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $a['id'],
|
|
':status' => $status,
|
|
':num' => $a['count'],
|
|
':modify_time' => time()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
}
|