306 lines
12 KiB
PHP
306 lines
12 KiB
PHP
<?php
|
|
|
|
class SkinController{
|
|
|
|
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' => 'gamedb2002_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getTankSkin($skin_id)
|
|
{
|
|
$skin_meta_table = require('../res/tankSkin@tankSkin.php');
|
|
$skin_meta = getCommanderConfig($skin_meta_table, $skin_id);
|
|
$s = array(
|
|
'id' => $skin_meta['id'],
|
|
'name' => $skin_meta['name'],
|
|
'price' => $skin_meta['price'],
|
|
);
|
|
return $s;
|
|
}
|
|
|
|
protected function getExplode($string)
|
|
{
|
|
$delim = "|";
|
|
$drop_multiply = explode($delim, $string);
|
|
$delim1 = ":";
|
|
$arr = array();
|
|
for ($i = 0; $i < count($drop_multiply); $i++) {
|
|
$mul = explode($delim1, $drop_multiply[$i]);
|
|
array_push($arr, $mul);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
protected function getTank($tank_id)
|
|
{
|
|
$tank_meta_table = require('../res/tank@tank.php');
|
|
$tank_meta = getTankConfig($tank_meta_table, $tank_id);
|
|
$t = array(
|
|
'id' => $tank_meta['id'],
|
|
'name' => $tank_meta['name'],
|
|
'cost' => $tank_meta['cost'],
|
|
'cost_int' => $tank_meta['cost_int'],
|
|
'max_lv' => $tank_meta['max_lv'],
|
|
'compose' => $tank_meta['compose'],
|
|
'debris' => $tank_meta['debris'],
|
|
'origin_skin' => $tank_meta['origin_skin']
|
|
);
|
|
return $t;
|
|
}
|
|
|
|
protected function getParameter($para_id)
|
|
{
|
|
$parameter_meta_cluster = require('../res/parameter@parameter.php');
|
|
$parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id);
|
|
$p = array(
|
|
'id' => $parameter_meta['id'],
|
|
'param_name' => $parameter_meta['param_name'],
|
|
'param_value' => $parameter_meta['param_value'],
|
|
);
|
|
return $p;
|
|
}
|
|
|
|
public function skinInfo()
|
|
{
|
|
$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);
|
|
$skin_list = array();
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
|
return;
|
|
}
|
|
$rowCount = $conn->execQueryRowCount('SELECT skin_id FROM skin WHERE accountid = :account_id;',
|
|
array(
|
|
':account_id' => $account_id
|
|
));
|
|
$status = 0;
|
|
$tank_meta_table = require('../res/tank@tank.php');
|
|
if ($rowCount == 0) {
|
|
for ($i = 15001; $i <= count($tank_meta_table) + 15000; $i++) {
|
|
$t = $this->getTank($i);
|
|
if (!$t) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤');
|
|
return;
|
|
}
|
|
$s = $this->getTankSkin($t['origin_skin']);
|
|
$status = 0;
|
|
$ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, skin_status, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :skin_id, :skin_status, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, skin_id=:skin_id, skin_status=:skin_status, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $t['origin_skin'],
|
|
':skin_status' => $status,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
$rows = $conn->execQuery('SELECT skin_id, skin_status FROM skin WHERE accountid = :account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
));
|
|
$skin_id = 0;
|
|
foreach ($rows as $row) {
|
|
if ($skin_id == $row['skin_id']) {
|
|
continue;
|
|
}
|
|
$skin_id = $row['skin_id'];
|
|
array_push($skin_list, array(
|
|
'skin_id' => $skin_id,
|
|
'skin_status' => $row['skin_status'],
|
|
));
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'skin_list' => $skin_list
|
|
));
|
|
}
|
|
|
|
|
|
public function unlockSkin()
|
|
{
|
|
$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);
|
|
$skin_id = $_REQUEST['skin_id'];
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
|
return;
|
|
}
|
|
$s = $this->getTankSkin($skin_id);
|
|
if(!$s){
|
|
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤');
|
|
return;
|
|
}
|
|
$num = $s['price'];
|
|
$rowDiamond = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
));
|
|
if (!$rowDiamond) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
if ($num > $rowDiamond['diamond_num']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 6, '钻石不足');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT skin_status FROM skin WHERE accountid=:account_id AND skin_id=:skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id
|
|
));
|
|
if (!$row) {
|
|
$ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, skin_status, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :skin_id, :skin_status, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, skin_id=:skin_id, skin_status=:skin_status, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id,
|
|
':skin_status' => 1,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
if ($row['skin_status'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3,'皮肤已解锁');
|
|
return;
|
|
}
|
|
|
|
$ret = $conn->execScript('UPDATE skin SET skin_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
$retDiamond = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':diamond_num' => $rowDiamond['diamond_num'] - $num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$retDiamond) {
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
"skin_id" => $skin_id,
|
|
"skin_status" => 1,
|
|
));
|
|
}
|
|
|
|
public function exchangeSkin()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$usingskin_id = $_REQUEST['usingskin_id'];
|
|
$exchangeskin_id = $_REQUEST['exchangeskin_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
//正在上阵的皮肤
|
|
$row = $conn->execQueryOne('SELECT skin_status FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':skin_id' => $usingskin_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个指挥官');
|
|
return;
|
|
}
|
|
$status = 1;
|
|
$using_ret = $conn->execScript('UPDATE skin SET skin_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $usingskin_id,
|
|
':modify_time' => time()
|
|
));
|
|
|
|
if(!$using_ret){
|
|
die();
|
|
return;
|
|
}
|
|
$skin_list = array();
|
|
array_push($skin_list, array(
|
|
'skin_id' => $usingskin_id,
|
|
'skin_status' => 1,
|
|
));
|
|
//准备上阵的皮肤
|
|
$row_exchange = $conn->execQueryOne('SELECT skin_status FROM skin WHERE accountid=:accountid AND skin_id=:skin_id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':skin_id' => $exchangeskin_id,
|
|
));
|
|
$exchange_ret = $conn->execScript('UPDATE skin SET skin_status=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $exchangeskin_id,
|
|
':modify_time' => time()
|
|
));
|
|
if(!$exchange_ret){
|
|
die();
|
|
return;
|
|
}
|
|
array_push($skin_list, array(
|
|
'skin_id' => $exchangeskin_id,
|
|
'skin_status' => 0,
|
|
));
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
"skin_list" => $skin_list,
|
|
));
|
|
}
|
|
}
|
|
?>
|