263 lines
11 KiB
PHP
263 lines
11 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' => 'gamedb2001_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getSkin($skin_id)
|
|
{
|
|
$g_conf_skin_cluster = require('../config/game2001api.dress.cluster.php');
|
|
|
|
$skin_conf = getSkinConfig($g_conf_skin_cluster, $skin_id);
|
|
$s = array(
|
|
'skin_id' => $skin_conf['id'],
|
|
'skin_name' => $skin_conf['name'],
|
|
'skin_skillid' => $skin_conf['skill_id'],
|
|
'skin_compose' => $skin_conf['compose'],
|
|
'skin_experience' => $skin_conf['is_experience'],
|
|
'skin_price' => $skin_conf['price']
|
|
);
|
|
return $s;
|
|
}
|
|
|
|
public function skinInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$skin_list = array();
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
|
return;
|
|
}
|
|
$rowCount = $conn->execQueryRowCount('SELECT accountid, skin_id, skin_status, frgment_num, active_time ' .
|
|
' FROM skin WHERE accountid = :account_id;',
|
|
array(
|
|
':account_id' => $account_id
|
|
));
|
|
if ($rowCount == 0) {
|
|
for ($i = 14001; $i < 14010; $i++) {
|
|
if ($i == 14001) {
|
|
$skin_status = 0;
|
|
} else {
|
|
$skin_status = 2;
|
|
}
|
|
$ret = $conn->execScript('INSERT INTO skin(accountid, skin_id, skin_status, frgment_num, active_time) ' .
|
|
' VALUES(:account_id, :skin_id, :skin_status, :fragment_num, :active_time);',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $i,
|
|
':skin_status' => $skin_status,
|
|
':fragment_num' => 0,
|
|
':active_time' => 0,
|
|
));
|
|
}
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
$time = 0;
|
|
$rows = $conn->execQuery('SELECT accountid, skin_id, skin_status, frgment_num, active_time ' .
|
|
' FROM skin WHERE accountid = :account_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
));
|
|
|
|
foreach ($rows as $row) {
|
|
if(time() - $row['active_time'] >= 7200 && $row['active_time'] != 0){
|
|
if($row['skin_status'] == 0){
|
|
$ret = $conn->execScript('UPDATE skin SET active_time=0, skin_status=:skin_status ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $row['skin_id'],
|
|
':skin_status' => 2
|
|
));
|
|
$ret = $conn->execScript('UPDATE skin SET skin_status=0 ' .
|
|
' WHERE accountid = :account_id AND skin_id = 14001;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
));
|
|
}else{
|
|
$ret = $conn->execScript('UPDATE skin SET active_time=0, skin_status=:skin_status ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $row['skin_id'],
|
|
':skin_status' => 2
|
|
));
|
|
}
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if($row['active_time'] != 0){
|
|
$time = 2;
|
|
}else{
|
|
$time = 0;
|
|
}
|
|
array_push($skin_list, array(
|
|
'skin_id' => $row['skin_id'],
|
|
'skin_status' => $row['skin_status'],
|
|
'fragment_num' => $row['frgment_num'],
|
|
'active_time' => $time,
|
|
));
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'skin_list' => $skin_list
|
|
));
|
|
}
|
|
|
|
|
|
public function unlockSkin()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$skin_id = $_REQUEST['skin_id'];
|
|
$coin_num = $_REQUEST['coin_num'];
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
|
return;
|
|
}
|
|
$s = $this->getSkin($skin_id);
|
|
if(!$s){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤1');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT accountid, skin_id, skin_status, frgment_num, active_time ' .
|
|
' FROM skin WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id
|
|
));
|
|
if(!$row){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个皮肤');
|
|
return;
|
|
}
|
|
$fragment_num = 0;
|
|
if($row['frgment_num'] >= $s['skin_compose']){
|
|
$fragment_num = $row['frgment_num'] - $s['skin_compose'];
|
|
}else{
|
|
$coin = $s['skin_price'] * 1.0 / $s['skin_compose'] * ($s['skin_compose'] - $row['frgment_num']);
|
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($row['coin_num'] < $coin) {
|
|
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'] - $coin
|
|
));
|
|
|
|
$fragment_num = 0;
|
|
}
|
|
$ret = $conn->execScript('UPDATE skin SET frgment_num=:frgment_num ,skin_status=1 ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id,
|
|
':frgment_num' => $fragment_num
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function exchangeSkin()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$usingskin_id = $_REQUEST['usingskin_id'];
|
|
$exchangeskin_id = $_REQUEST['exchangeskin_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$using_ret = $conn->execScript('UPDATE skin SET skin_status=1 ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $usingskin_id
|
|
));
|
|
|
|
if(!$using_ret){
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有皮肤');
|
|
return;
|
|
}
|
|
$exchange_ret = $conn->execScript('UPDATE skin SET skin_status=0 ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $exchangeskin_id
|
|
));
|
|
if(!$exchange_ret){
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有皮肤');
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function freetryskin()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$skin_id = $_REQUEST['skin_id'];
|
|
if(!$conn){
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个角色');
|
|
return;
|
|
}
|
|
$s = $this->getSkin($skin_id);
|
|
if(!$s){
|
|
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个皮肤');
|
|
return;
|
|
}
|
|
if($s['skin_experience'] == 0){
|
|
phpcommon\sendError(ERR_USER_BASE + 3,'皮肤不可以体验');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE skin SET active_time=:active_time, skin_status=1 ' .
|
|
' WHERE accountid = :account_id AND skin_id = :skin_id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':skin_id' => $skin_id,
|
|
':active_time' => time()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
}
|
|
?>
|