1
This commit is contained in:
parent
ec9f18839f
commit
812ff5af90
262
webapp/controller/SkinController.class.php
Normal file
262
webapp/controller/SkinController.class.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?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.skin.cluster.php');
|
||||
|
||||
$skin_conf = getSkinConfig($g_conf_skin_cluster, $skin_id);
|
||||
$s = array(
|
||||
'skin_id' => $skin_conf['skin_id'],
|
||||
'skin_name' => $skin_conf['skin_name'],
|
||||
'skin_skillid' => $skin_conf['skin_skillid'],
|
||||
'skin_compose' => $skin_conf['skin_compose'],
|
||||
'skin_experience' => $skin_conf['skin_experience'],
|
||||
'skin_price' => $skin_conf['skin_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) {
|
||||
$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' => 14001,
|
||||
':skin_status' => 0,
|
||||
':fragment_num' => 0,
|
||||
':active_time' => 0,
|
||||
));
|
||||
$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' => 14002,
|
||||
':skin_status' => 2,
|
||||
':fragment_num' => 0,
|
||||
':active_time' => 0,
|
||||
));
|
||||
$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' => 14003,
|
||||
':skin_status' => 2,
|
||||
':fragment_num' => 100,
|
||||
':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']);
|
||||
if($coin_num < $coin){
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '金币不足');
|
||||
return;
|
||||
}
|
||||
$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' => '',
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user