1
This commit is contained in:
parent
ac5a629504
commit
71ad855736
244
tools/rankserver/game2003rank.py
Normal file
244
tools/rankserver/game2003rank.py
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import pymysql
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import urllib.request
|
||||||
|
import base64
|
||||||
|
import tornado.ioloop
|
||||||
|
import tornado.web
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
import redis
|
||||||
|
import os
|
||||||
|
import functools
|
||||||
|
|
||||||
|
CONFIG_DIR = ''
|
||||||
|
|
||||||
|
def IsOnlineEnv():
|
||||||
|
return os.getenv("SERVER_ENV");
|
||||||
|
|
||||||
|
if (IsOnlineEnv()):
|
||||||
|
CONFIG_DIR = '/var/data/conf_test/game2003api_rankserver/config'
|
||||||
|
else:
|
||||||
|
CONFIG_DIR = '../config'
|
||||||
|
|
||||||
|
def info(msg):
|
||||||
|
print(str(datetime.datetime.now()) + '[INFO] ' + msg)
|
||||||
|
|
||||||
|
def take_pass(elem):
|
||||||
|
return elem[3]
|
||||||
|
|
||||||
|
def take_coin_num(elem):
|
||||||
|
return elem[4]
|
||||||
|
|
||||||
|
def safeDiv(a, b):
|
||||||
|
if b == 0:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
return a / b
|
||||||
|
|
||||||
|
def getRedis():
|
||||||
|
redis_conf = json.loadsmysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.redis.cluster.json', 'r').read())
|
||||||
|
for conf in redis_conf:
|
||||||
|
r = redis.Redis(host = conf['host'],
|
||||||
|
port = conf['port'],
|
||||||
|
password = conf['passwd'],
|
||||||
|
charset = 'utf8'
|
||||||
|
)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
def getDaySeconds(time_val, incdays):
|
||||||
|
time_zone = 8
|
||||||
|
dayseconds = int((time_val + time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * time_zone;
|
||||||
|
return dayseconds
|
||||||
|
|
||||||
|
#数据去重
|
||||||
|
def delRepeatData(row, data_list):
|
||||||
|
temp_list = []
|
||||||
|
for data in data_list:
|
||||||
|
if data[0] == row[0]:
|
||||||
|
temp_list.append(data)
|
||||||
|
for temp_data in temp_list:
|
||||||
|
data_list.remove(temp_data)
|
||||||
|
|
||||||
|
#刷新通关数据
|
||||||
|
def refreshData(row, pass_list):
|
||||||
|
pass_list.append((row[0], row[1].decode('utf-8'), row[2], row[3], row[4]))
|
||||||
|
pass_list.sort(key=take_pass, reverse=True)
|
||||||
|
if (len(pass_list) > 50):
|
||||||
|
del pass_list[50:]
|
||||||
|
|
||||||
|
#刷新金币数据
|
||||||
|
def refreshCoinData(row, coin_list):
|
||||||
|
coin_list.append((row[0], row[1].decode('utf-8'), row[2], row[3], row[4]))
|
||||||
|
coin = sorted(coin_list, key=functools.cmp_to_key(customCmp), reverse = True)
|
||||||
|
if (len(coin) > 50):
|
||||||
|
del coin[50:]
|
||||||
|
|
||||||
|
#字符串排序
|
||||||
|
def customCmp(a, b):
|
||||||
|
if len(a) < len(b):
|
||||||
|
return -1
|
||||||
|
elif len(a) > len(b):
|
||||||
|
return 1
|
||||||
|
#endif
|
||||||
|
if a < b:
|
||||||
|
return -1
|
||||||
|
elif a > b:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
#更新排行榜
|
||||||
|
def updateRank(r, pass_list, coin_list):
|
||||||
|
pass_list.sort(key=take_pass, reverse=True)
|
||||||
|
pass_rank = []
|
||||||
|
for pass_index in range(min(50, len(pass_list))):
|
||||||
|
pass_rank.append(pass_list[pass_index])
|
||||||
|
r.set("game2003api:pass_rank", json.dumps(pass_rank))
|
||||||
|
|
||||||
|
coin = sorted(coin_list, key=functools.cmp_to_key(customCmp), reverse = True)
|
||||||
|
coin_rank = []
|
||||||
|
for coin_index in range(min(50, len(coin))):
|
||||||
|
coin_rank.append(coin[coin_index])
|
||||||
|
r.set("game2003api:coin_rank", json.dumps(coin_rank))
|
||||||
|
|
||||||
|
def internalDayReadMysqlData():
|
||||||
|
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||||
|
pass_list = []
|
||||||
|
coin_list = []
|
||||||
|
for conf in mysql_conf:
|
||||||
|
conn = pymysql.connect(host = conf['host'],
|
||||||
|
port = conf['port'],
|
||||||
|
user = conf['user'],
|
||||||
|
passwd = conf['passwd'],
|
||||||
|
db = 'gamedb2003_' + str(conf['instance_id']),
|
||||||
|
charset = 'utf8'
|
||||||
|
)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
last_idx = 0
|
||||||
|
temp_idx = 0
|
||||||
|
while 1:
|
||||||
|
cursor.execute('SELECT accountid, user_name, avatar_url, pass, coin_num, idx'
|
||||||
|
' FROM user WHERE idx > %s LIMIT 0, 1000' % (last_idx))
|
||||||
|
|
||||||
|
has_data = False
|
||||||
|
for row in cursor:
|
||||||
|
has_data = True
|
||||||
|
#更新通关榜
|
||||||
|
refreshData(row, pass_list)
|
||||||
|
#更新金钱榜
|
||||||
|
refreshCoinData(row, coin_list)
|
||||||
|
temp_idx = int(row[5])
|
||||||
|
if (temp_idx > last_idx) :
|
||||||
|
last_idx = int(row[5])
|
||||||
|
|
||||||
|
if not has_data:
|
||||||
|
break
|
||||||
|
|
||||||
|
r = getRedis()
|
||||||
|
updateRank(r, pass_list, coin_list)
|
||||||
|
|
||||||
|
#每日定时读取mysql里的数据生成排行榜写入redis后php读取redis返回客户端显示
|
||||||
|
def dayReadMysqlData(rushtime):
|
||||||
|
internalDayReadMysqlData()
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + rushtime,
|
||||||
|
lambda : dayReadMysqlData(rushtime)
|
||||||
|
)
|
||||||
|
|
||||||
|
#每5分钟读取mysql里发生改变过的数据更新排行榜
|
||||||
|
def readMysqlData(rushtime):
|
||||||
|
mysql_conf = json.loads(open(CONFIG_DIR + '/rankserver.mysql.cluster.json', 'r').read())
|
||||||
|
r = getRedis()
|
||||||
|
pass_list_str = r.get("game2003api:pass_rank")
|
||||||
|
if (not pass_list_str):
|
||||||
|
pass_list = []
|
||||||
|
else:
|
||||||
|
pass_list = json.loads(pass_list_str)
|
||||||
|
|
||||||
|
coin_list_str = r.get("game2003api:coin_rank")
|
||||||
|
if (not coin_list_str):
|
||||||
|
coin_list = []
|
||||||
|
else:
|
||||||
|
coin_list = json.loads(coin_list_str)
|
||||||
|
|
||||||
|
for conf in mysql_conf:
|
||||||
|
conn = pymysql.connect(host = conf['host'],
|
||||||
|
port = conf['port'],
|
||||||
|
user = conf['user'],
|
||||||
|
passwd = conf['passwd'],
|
||||||
|
db = 'gamedb2003_' + str(conf['instance_id']),
|
||||||
|
charset = 'utf8'
|
||||||
|
)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
last_idx = 0
|
||||||
|
temp_idx = 0
|
||||||
|
while 1:
|
||||||
|
cursor.execute('SELECT accountid, user_name, avatar_url, pass, coin_num, idx FROM user '
|
||||||
|
' WHERE idx > %s LIMIT 0, 1000' % (last_idx))
|
||||||
|
has_data = False
|
||||||
|
for row in cursor:
|
||||||
|
has_data = True
|
||||||
|
#更新击杀榜
|
||||||
|
delRepeatData(row, pass_list)
|
||||||
|
refreshData(row, pass_list)
|
||||||
|
temp_idx = int(row[5])
|
||||||
|
if (temp_idx > last_idx) :
|
||||||
|
last_idx = int(row[5])
|
||||||
|
if not has_data:
|
||||||
|
break
|
||||||
|
|
||||||
|
last_idx = 0
|
||||||
|
temp_idx = 0
|
||||||
|
while 1:
|
||||||
|
cursor.execute('SELECT accountid, user_name, avatar_url, pass, coin_num, idx FROM user '
|
||||||
|
' WHERE idx > %s LIMIT 0, 1000' % (last_idx))
|
||||||
|
has_data = False
|
||||||
|
for row in cursor:
|
||||||
|
has_data = True
|
||||||
|
#更新胜场榜
|
||||||
|
delRepeatData(row, coin_list)
|
||||||
|
refreshCoinData(row, coin_list)
|
||||||
|
temp_idx = int(row[5])
|
||||||
|
if (temp_idx > last_idx) :
|
||||||
|
last_idx = int(row[5])
|
||||||
|
if not has_data:
|
||||||
|
break
|
||||||
|
|
||||||
|
updateRank(r, pass_list, coin_list)
|
||||||
|
tornado.ioloop.IOLoop.current().call_later(rushtime,
|
||||||
|
lambda : readMysqlData(rushtime)
|
||||||
|
)
|
||||||
|
|
||||||
|
class SelfCheckingHandler(tornado.web.RequestHandler):
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
self.write(json.dumps({
|
||||||
|
'errcode': 0,
|
||||||
|
'errmsg': '',
|
||||||
|
'healthy': 1,
|
||||||
|
'max_rundelay': 10
|
||||||
|
}))
|
||||||
|
|
||||||
|
def make_app():
|
||||||
|
return tornado.web.Application([
|
||||||
|
(r"/webapp/index[\.]php", SelfCheckingHandler),
|
||||||
|
])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
conf = json.loads(open(CONFIG_DIR + '/rankserver.json', 'r').read())
|
||||||
|
|
||||||
|
app = make_app()
|
||||||
|
app.listen(conf['listen_port'])
|
||||||
|
conf['rushtime'] = 300
|
||||||
|
tornado.ioloop.IOLoop.current().call_later(conf['rushtime'],
|
||||||
|
lambda : readMysqlData(conf['rushtime'])
|
||||||
|
)
|
||||||
|
|
||||||
|
conf['day_rushtime'] = 5 * 3600
|
||||||
|
tornado.ioloop.IOLoop.current().call_at(getDaySeconds(time.time(), 1) + conf['day_rushtime'],
|
||||||
|
lambda : dayReadMysqlData(conf['day_rushtime'])
|
||||||
|
)
|
||||||
|
tornado.ioloop.IOLoop.current().start()
|
122
webapp/classes/AddReward.php
Normal file
122
webapp/classes/AddReward.php
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace classes;
|
||||||
|
|
||||||
|
use phpcommon;
|
||||||
|
|
||||||
|
class AddReward {
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
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'],
|
||||||
|
'type' => $item_conf['type'],
|
||||||
|
);
|
||||||
|
return $it;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function addReward($item_id, $item_num, $account_id)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$it = $this->getItem($item_id);
|
||||||
|
if (!$it) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$item_list = array();
|
||||||
|
array_push($item_list, array(
|
||||||
|
'itemid' => $item_id,
|
||||||
|
'itemnum' => $item_num,
|
||||||
|
));
|
||||||
|
foreach ($item_list as $item) {
|
||||||
|
$i = $this->getItem($item['itemid']);
|
||||||
|
switch ($i['type'])
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
//添加货币
|
||||||
|
$this->addCoin($item['itemid'], $item['itemnum'], $account_id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加货币
|
||||||
|
protected function addCoin($item_id, $item_num, $accountid)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($accountid);
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
if ($item_id == 10001) {
|
||||||
|
$row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid,
|
||||||
|
':coin_num' => $item_num + $row['coin_num'],
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
} else if ($item_id == 10003) {
|
||||||
|
$row = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid,
|
||||||
|
':diamond_num' => $item_num + $row['diamond_num'],
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
} else if ($item_id == 10002) {
|
||||||
|
$row = $conn->execQueryOne('SELECT energy FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET energy=:energy, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $accountid,
|
||||||
|
':energy' => $item_num + $row['energy'],
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
254
webapp/controller/DropBoxController.class.php
Normal file
254
webapp/controller/DropBoxController.class.php
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class DropBoxController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedis($shop_uuid)
|
||||||
|
{
|
||||||
|
$redis_conf = getRedisConfig(crc32($shop_uuid));
|
||||||
|
$r = new phpcommon\Redis(array(
|
||||||
|
'host' => $redis_conf['host'],
|
||||||
|
'port' => $redis_conf['port'],
|
||||||
|
'passwd' => $redis_conf['passwd']
|
||||||
|
|
||||||
|
));
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
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'],
|
||||||
|
'name' => $parameter_meta['param_name'],
|
||||||
|
'value' => $parameter_meta['param_value'],
|
||||||
|
);
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTank($tank_id)
|
||||||
|
{
|
||||||
|
$tank_meta_table = require('../res/tank_economy@tank_economy.php');
|
||||||
|
$tank_meta = getTankConfig($tank_meta_table, $tank_id);
|
||||||
|
$t = array(
|
||||||
|
'id' => $tank_meta['tank_id'],
|
||||||
|
'level' => $tank_meta['level'],
|
||||||
|
'coin_origin' => $tank_meta['coin_origin'],
|
||||||
|
'coin_times' => $tank_meta['coin_times'],
|
||||||
|
'coin_sell' => $tank_meta['coin_sell'],
|
||||||
|
'diamond' => $tank_meta['diamond'],
|
||||||
|
'coin_produce' => $tank_meta['coin_produce'],
|
||||||
|
'coin_lv' => $tank_meta['coin_lv'],
|
||||||
|
'diamond_lv' => $tank_meta['diamond_lv'],
|
||||||
|
'drop_level' => $tank_meta['drop_level'],
|
||||||
|
'drop_number' => $tank_meta['drop_number'],
|
||||||
|
'ad_level' => $tank_meta['ad_level'],
|
||||||
|
'buy_range1' => $tank_meta['buy_range1'],
|
||||||
|
'buy_times1' => $tank_meta['buy_times1'],
|
||||||
|
'free_lv1' => $tank_meta['free_lv1'],
|
||||||
|
'buy_range2' => $tank_meta['buy_range2'],
|
||||||
|
'buy_times2' => $tank_meta['buy_times2'],
|
||||||
|
'free_lv2' => $tank_meta['free_lv2'],
|
||||||
|
);
|
||||||
|
return $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTankuuid($accountid)
|
||||||
|
{
|
||||||
|
$mysql_conf = getMysqlConfig(crc32($accountid));
|
||||||
|
$conn = $this->getMysql($accountid);
|
||||||
|
$ret = $conn->execScript("INSERT INTO id_pool(createtime) VALUES(:createtime);",
|
||||||
|
array(
|
||||||
|
'createtime' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID();', array());
|
||||||
|
if (empty($row)) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$orderid = $this->getIdPool($mysql_conf['instance_id'] , $row[0]);
|
||||||
|
return $orderid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getIdPool($db_instance_id, $idx)
|
||||||
|
{
|
||||||
|
if ($db_instance_id >= 100 || $db_instance_id <= 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'instance_id无效');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($idx >= 4294967295 || $idx <= 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'idx无效');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$instance_id = sprintf('%02d', $db_instance_id);
|
||||||
|
$id = sprintf('%010d',$idx);
|
||||||
|
$tank_uuid = strftime('%y%m%d%H%M%S') . $instance_id . $id;
|
||||||
|
return $tank_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function airDropBoxReward()
|
||||||
|
{
|
||||||
|
$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 + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT box_num, max_level FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*if ($row['box_num'] <= 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '今日开箱子次数已用完');
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
$airReward_uuid = 'game2003api_airReward_uuid:' . md5($_REQUEST['account_id']);
|
||||||
|
$airReward_list = array();
|
||||||
|
$r = $this->getRedis($airReward_uuid);
|
||||||
|
if (!$r) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$user_db_str = $r->get($airReward_uuid);
|
||||||
|
$airReward_num = 0;
|
||||||
|
$last_time = 0;
|
||||||
|
if (empty($user_db_str)) {
|
||||||
|
$airReward_list = $this->getRandomAirReward($row['max_level']);
|
||||||
|
$airReward_db = array(
|
||||||
|
'airReward_uuid' => $airReward_uuid,
|
||||||
|
'airReward_list' => $airReward_list,
|
||||||
|
);
|
||||||
|
$r -> set($airReward_uuid, json_encode($airReward_db));
|
||||||
|
$r -> pexpire($airReward_uuid, 1000 * 7200);
|
||||||
|
} else {
|
||||||
|
$user_db = json_decode($user_db_str, true);
|
||||||
|
unset($user_db['airReward_list']);
|
||||||
|
$airReward_list = $this->getRandomAirReward($row['max_level']);
|
||||||
|
$airReward_db = array(
|
||||||
|
'airReward_uuid' => $airReward_uuid,
|
||||||
|
'airReward_list' => $airReward_list,
|
||||||
|
);
|
||||||
|
$r -> set($airReward_uuid, json_encode($airReward_db));
|
||||||
|
$r -> pexpire($airReward_uuid, 1000 * 7200);
|
||||||
|
}
|
||||||
|
/*$ret = $conn->execScript('UPDATE user SET box_num=:box_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':box_num' => $row['box_num'] - 1,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}*/
|
||||||
|
foreach ($airReward_list as $airReward) {
|
||||||
|
//添加坦克
|
||||||
|
$this->insertTank($account_id, $airReward['item_id'], $airReward['item_num']);
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg'=> '',
|
||||||
|
'item_list' => $airReward_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function airDoubleReward()
|
||||||
|
{
|
||||||
|
$account_id = $_REQUEST['account_id'];
|
||||||
|
//登录校验
|
||||||
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||||
|
if (!$login) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$airReward_uuid = 'game2003api_airReward_uuid:' . md5($_REQUEST['account_id']);
|
||||||
|
$airReward_list = array();
|
||||||
|
$r = $this->getRedis($airReward_uuid);
|
||||||
|
if (!$r) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$user_db_str = $r->get($airReward_uuid);
|
||||||
|
if (empty($user_db_str)) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2,'session失效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$user_db = json_decode($user_db_str, true);
|
||||||
|
if (empty($user_db)) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3,'session失效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$p = $this->getParameter(AIRDROPREWARD_TIMES);
|
||||||
|
$times = $p['value'] - 1;
|
||||||
|
foreach ($user_db['airReward_list'] as $airReward) {
|
||||||
|
//添加坦克
|
||||||
|
$this->insertTank($account_id, $airReward['item_id'], $airReward['item_num'] * $times);
|
||||||
|
}
|
||||||
|
$r->del($airReward_uuid, json_encode($user_db));
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg'=> '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRandomAirReward($max_level)
|
||||||
|
{
|
||||||
|
$airReward_list = array();
|
||||||
|
//随机奖励
|
||||||
|
$max_tank = $this->getTank(10000 + $max_level);
|
||||||
|
array_push($airReward_list, array(
|
||||||
|
'item_id' => $max_tank['drop_level'],
|
||||||
|
'item_num' => $max_tank['drop_number'],
|
||||||
|
));
|
||||||
|
return $airReward_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function insertTank($account_id, $level, $num)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
for ($i = 0; $i < $num; $i++) {
|
||||||
|
$curr_tank_uuid = $this->getTankuuid($account_id);
|
||||||
|
$ret = $conn->execScript('INSERT INTO tank(accountid, tank_uuid, tank_level, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :tank_uuid, :tank_level, :create_time, :modify_time)',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $curr_tank_uuid,
|
||||||
|
':tank_level' => $level,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
152
webapp/controller/HangController.class.php
Normal file
152
webapp/controller/HangController.class.php
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class HangController{
|
||||||
|
|
||||||
|
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 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 getTime()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$num = 0;
|
||||||
|
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
$ret = $conn->execScript('INSERT INTO hang(accountid, hang_time, create_time, modify_time) ' .
|
||||||
|
' VALUES(:accountid, :hang_time, :create_time, :modify_time) ' .
|
||||||
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, hang_time=:hang_time, modify_time=:modify_time;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':hang_time' => time(),
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*$p_num = $this->getParameter(GOLD);
|
||||||
|
$p_time_limit = $this->getParameter(TIME_LIMIT);
|
||||||
|
$num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']);
|
||||||
|
if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) {
|
||||||
|
$num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'time' => time(),
|
||||||
|
'num' => $num
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getHangReward()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$item_id = 0;
|
||||||
|
$num = 0;
|
||||||
|
$weight = $_REQUEST['weight'];
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT * FROM hang WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if ($row) {
|
||||||
|
$ret = $conn->execScript('UPDATE hang SET hang_time=:hang_time, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':hang_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item_id = 10001;
|
||||||
|
$p_num = $this->getParameter(GOLD);
|
||||||
|
$p_time_limit = $this->getParameter(TIME_LIMIT);
|
||||||
|
$num = floor((time() - $row['hang_time']) / 5 * $p_num['param_value']);
|
||||||
|
if ((time() - $row['hang_time']) >= $p_time_limit['param_value']) {
|
||||||
|
$num = floor($p_time_limit['param_value'] / 5 * $p_num['param_value']);
|
||||||
|
}
|
||||||
|
if ($weight != 0) {
|
||||||
|
$p = $this->getParameter(REWARD_TIMES);
|
||||||
|
$times = $p['param_value'] - 1;
|
||||||
|
$num = $num * $times;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':coin_num' => $num + $row['coin_num'],
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'num' => $num,
|
||||||
|
'time' => time()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
239
webapp/controller/QuestController.class.php
Normal file
239
webapp/controller/QuestController.class.php
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'classes/AddReward.php';
|
||||||
|
|
||||||
|
class QuestController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getQuest($quest_id)
|
||||||
|
{
|
||||||
|
$g_conf_quest_cluster = require('../res/task@task.php');
|
||||||
|
$quest_conf = getQuestConfig($g_conf_quest_cluster, $quest_id);
|
||||||
|
$q = array(
|
||||||
|
'id' => $quest_conf['id'],
|
||||||
|
'type' => $quest_conf['type'],
|
||||||
|
'condition' => $quest_conf['condition'],
|
||||||
|
'value' => $quest_conf['value'],
|
||||||
|
'jewel_reward' => $quest_conf['jewel_reward'],
|
||||||
|
);
|
||||||
|
return $q;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function questInfo()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$quest_list = array();
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$rows= $conn->execQueryRowCount('SELECT * FROM quest WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$rows) {
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'quest_list' => $quest_list,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
array_push($quest_list, array(
|
||||||
|
'quest_id' => $row['quest_id'],
|
||||||
|
'quest_num' => $row['quest_num'],
|
||||||
|
'quest_status' => $row['quest_status']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'quest_list' => $quest_list,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function triggerQuest()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$condition = $_REQUEST['type'];
|
||||||
|
$num = $_REQUEST['num'];
|
||||||
|
$g_conf_task_cluster = require('../res/task@task.php');
|
||||||
|
$quest_list = array();
|
||||||
|
$sum = 0;
|
||||||
|
$status = 0;
|
||||||
|
$rows = $conn->execQuery('SELECT quest_id, quest_num, quest_status ' .
|
||||||
|
' FROM quest WHERE accountid=:accountid AND quest_type=:quest_type;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':quest_type' => $condition,
|
||||||
|
));
|
||||||
|
if (!$rows) {
|
||||||
|
//插入任务
|
||||||
|
for ($i = 1; $i <= count($g_conf_task_cluster); $i++) {
|
||||||
|
$q = $this->getQuest($i + 71000);
|
||||||
|
if ($condition != $q['condition']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($num < $q['condition']) {
|
||||||
|
$sum = $num ;
|
||||||
|
$status = 0;
|
||||||
|
} else {
|
||||||
|
$sum = $q['condition'];
|
||||||
|
$status = 1;
|
||||||
|
array_push($quest_list, array(
|
||||||
|
'id' => $q['id'],
|
||||||
|
'num' => $num,
|
||||||
|
'status' => $status
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$this->insertQuest($q['id'], $account_id, $sum, $status, $condition);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//更新任务
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$q = $this->getQuest($row['quest_id']);
|
||||||
|
if ($row['quest_num'] + $num < $q['condition']) {
|
||||||
|
$sum = $row['quest_num'] + $num ;
|
||||||
|
$status = 0;
|
||||||
|
} else {
|
||||||
|
if ($row['quest_status'] != 0) {
|
||||||
|
$sum = $q['condition'];
|
||||||
|
$status = $row['quest_status'];
|
||||||
|
} else {
|
||||||
|
$sum = $q['condition'];
|
||||||
|
$status = 1;
|
||||||
|
array_push($quest_list, array(
|
||||||
|
'id' => $row['quest_id'],
|
||||||
|
'num' => $num,
|
||||||
|
'status' => $status
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->updateQuest($row['quest_id'], $account_id, $sum, $status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'quest_list' => $quest_list,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function submitQuest()
|
||||||
|
{
|
||||||
|
$account_id = $_REQUEST['account_id'];
|
||||||
|
//登录校验
|
||||||
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
||||||
|
if (!$login) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$quest_id = $_REQUEST['id'];
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$q = $this->getQuest($quest_id);
|
||||||
|
$row = $conn->execQueryOne('SELECT quest_status, quest_num ' .
|
||||||
|
' FROM quest WHERE accountid=:accountid AND quest_id=:quest_id;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':quest_id' => $quest_id,
|
||||||
|
));
|
||||||
|
if (!$row || !$q) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['quest_status'] == 2) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '任务奖励已领取');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row['quest_status'] == 1) {
|
||||||
|
//更新任务
|
||||||
|
$this->updateQuest($quest_id, $account_id, $row['quest_num'], 2);
|
||||||
|
//添加奖励
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward(10003, $q['jewel_reward'], $account_id);
|
||||||
|
} else {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '任务未完成');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateQuest($id, $account_id, $num, $status)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('UPDATE quest SET quest_status=:status, quest_num=:num modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid AND quest_id =:quest_id;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':quest_id' => $id,
|
||||||
|
':num' => $num,
|
||||||
|
':status' => status,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function insertQuest($id, $account_id, $num, $status, $type)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_num, quest_type, quest_status, create_time, modify_time) ' .
|
||||||
|
' VALUES(:accountid, :quest_id, :quest_num, :quest_type, :quest_status, :create_time, :modify_time) ' .
|
||||||
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_num=:quest_num, quest_type=:quest_type, quest_status=:quest_status, modify_time=:modify_time;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':quest_id' => $id,
|
||||||
|
':quest_num' => $num,
|
||||||
|
':quest_type' => $type,
|
||||||
|
':quest_status'=> $status,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
172
webapp/controller/RankController.class.php
Normal file
172
webapp/controller/RankController.class.php
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class RankController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedis()
|
||||||
|
{
|
||||||
|
$key = 'game2003api';
|
||||||
|
$redis_conf = getRedisConfig($key);
|
||||||
|
$r = new phpcommon\Redis(array(
|
||||||
|
'host' => $redis_conf['host'],
|
||||||
|
'port' => $redis_conf['port'],
|
||||||
|
'passwd' => $redis_conf['passwd'],
|
||||||
|
));
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rankInfo()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$user_list = array();
|
||||||
|
$pass_list = array();
|
||||||
|
$pass_rank = 0;
|
||||||
|
$coin_list = array();
|
||||||
|
$coin_rank = 0;
|
||||||
|
$myname = '';
|
||||||
|
$myavatar_url = '';
|
||||||
|
//个人信息
|
||||||
|
$row = $conn->execQueryOne('SELECT user_name, avatar_url, pass, coin_num FROM user ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if ($row) {
|
||||||
|
if ($row['avatar_url'] == '') {
|
||||||
|
$address = '../res/robot@robot' . 1 . '.php';
|
||||||
|
$robot_meta_cluster = require($address);
|
||||||
|
$i = Rand(1, 100);
|
||||||
|
$robot_id = 1000 + $i;
|
||||||
|
$robot_meta = getRobotConfig($robot_meta_cluster, $robot_id);
|
||||||
|
$rob = array(
|
||||||
|
'name' => $robot_meta['name'],
|
||||||
|
'avatar_url' => $robot_meta['avatar_url'],
|
||||||
|
);
|
||||||
|
$myname = $rob['name'];
|
||||||
|
$myavatar_url = $rob['avatar_url'];
|
||||||
|
} else {
|
||||||
|
$myname = $row['user_name'];
|
||||||
|
$myavatar_url = $row['avatar_url'];
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push($user_list, array(
|
||||||
|
'account_id' => $account_id,
|
||||||
|
'name' => $myname,
|
||||||
|
'avatar_url' => $myavatar_url,
|
||||||
|
'pass' => $row['pass'],
|
||||||
|
'coin_num' => $row['coin_num'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
//通关榜
|
||||||
|
$r = $this->getRedis();
|
||||||
|
$pass_rank_db = $r->get("game2003api:pass_rank");
|
||||||
|
$pass_db = json_decode($pass_rank_db);
|
||||||
|
$pass_list = $this->getRank($account_id, $pass_db);
|
||||||
|
$i = 0;
|
||||||
|
foreach ($pass_db as $pass) {
|
||||||
|
$name = '';
|
||||||
|
$avatar_url = '';
|
||||||
|
if ($i > 49) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($pass_db[$i][0] == $account_id) {
|
||||||
|
$pass_rank = $i + 1;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
//财富榜
|
||||||
|
$coin_rank_db = $r->get("game2003api:coin_rank");
|
||||||
|
$coin_db = json_decode($coin_rank_db);
|
||||||
|
$i = 0;
|
||||||
|
foreach ($coin_db as $coin) {
|
||||||
|
$name = '';
|
||||||
|
$avatar_url = '';
|
||||||
|
if ($i > 49) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($coin_db[$i][0] == $account_id) {
|
||||||
|
$coin_rank = $i + 1;
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
$coin_list = $this->getRank($account_id, $coin_db);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => "",
|
||||||
|
//'user_list' => $user_list,
|
||||||
|
'pass_rank' => $pass_rank,
|
||||||
|
'pass_list' => $pass_list,
|
||||||
|
'coin_rank' => $coin_rank,
|
||||||
|
'coin_list' => $coin_list,
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRank($account_id, $user_db)
|
||||||
|
{
|
||||||
|
$i = 0;
|
||||||
|
$user_list = array();
|
||||||
|
foreach ($user_db as $user) {
|
||||||
|
$name = '';
|
||||||
|
$avatar_url = '';
|
||||||
|
if ($i > 49) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($user_db[$i][2] == '') {
|
||||||
|
if ($user_db[$i][0] == $account_id) {
|
||||||
|
$name = $myname;
|
||||||
|
$avatar_url = $myavatar_url;
|
||||||
|
} else {
|
||||||
|
$address = '../res/robot@robot' . 1 . '.php';
|
||||||
|
$robot_meta_cluster = require($address);
|
||||||
|
$j = Rand(1, 100);
|
||||||
|
$robot_id = 1000 + $j;
|
||||||
|
$robot_meta = getRobotConfig($robot_meta_cluster, $robot_id);
|
||||||
|
$rob = array(
|
||||||
|
'name' => $robot_meta['name'],
|
||||||
|
'avatar_url' => $robot_meta['avatar_url'],
|
||||||
|
);
|
||||||
|
$name = $rob['name'];
|
||||||
|
$avatar_url = $rob['avatar_url'];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$name = $user_db[$i][1];
|
||||||
|
$avatar_url = $user_db[$i][2];
|
||||||
|
}
|
||||||
|
array_push($user_list, array(
|
||||||
|
'account_id' => $user_db[$i][0],
|
||||||
|
'name' => $name,
|
||||||
|
'avatar_url' => $avatar_url,
|
||||||
|
'pass' => $user_db[$i][3],
|
||||||
|
'coin_num'=> $user_db[$i][4],
|
||||||
|
));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
return $user_list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
123
webapp/controller/RoleController.class.php
Normal file
123
webapp/controller/RoleController.class.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class RoleController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function roleInfo()
|
||||||
|
{
|
||||||
|
$account_id = $_REQUEST['account_id'];
|
||||||
|
$user_name = $_REQUEST['name'];
|
||||||
|
$avatar_url = $_REQUEST['avatar_url'];
|
||||||
|
//登录校验
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
if (empty($_REQUEST['account_id'])) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
$ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, coin_num, create_time, modify_time, collect_status, kefu_status, sign_sum, diamond_num, pass_status, pass, energy, buy_data, tank_data, daily_reward) ' .
|
||||||
|
' VALUES(:accountid, :user_name, :avatar_url, 0, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, :buy_data, :tank_data, 0)',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':user_name' => $user_name,
|
||||||
|
':avatar_url' => $avatar_url,
|
||||||
|
':tank_data' => '',
|
||||||
|
':buy_data' => '',
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'coin_num' => 0,
|
||||||
|
'collect_status' => 0,
|
||||||
|
'energy' => 0,
|
||||||
|
'kefu_status' => 0,
|
||||||
|
'diamond_num' => 0,
|
||||||
|
'pass_status' => 0,
|
||||||
|
'pass' => 0,
|
||||||
|
'buy_list' => '',
|
||||||
|
'tank_list' => '',
|
||||||
|
'daily_reward' => 0,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'coin_num' => $row['coin_num'],
|
||||||
|
'collect_status' => $row['collect_status'],
|
||||||
|
'energy' => $row['energy'],
|
||||||
|
'kefu_status' => $row['kefu_status'],
|
||||||
|
'diamond_num' => $row['diamond_num'],
|
||||||
|
'pass_status' => $row['pass_status'],
|
||||||
|
'pass' => $row['pass'],
|
||||||
|
'buy_list' => $row['buy_data'],
|
||||||
|
'tank_list' => $row['tank_data'],
|
||||||
|
'daily_reward' => $row['daily_reward'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOfflineTime()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
if (empty($_REQUEST['account_id'])) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT modify_time FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'time' => time() - $row['modify_time'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
341
webapp/controller/ShareController.class.php
Normal file
341
webapp/controller/ShareController.class.php
Normal file
@ -0,0 +1,341 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'classes/AddReward.php';
|
||||||
|
|
||||||
|
class ShareController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getRedis($shop_uuid)
|
||||||
|
{
|
||||||
|
$redis_conf = getRedisConfig(crc32($shop_uuid));
|
||||||
|
$r = new phpcommon\Redis(array(
|
||||||
|
'host' => $redis_conf['host'],
|
||||||
|
'port' => $redis_conf['port'],
|
||||||
|
'passwd' => $redis_conf['passwd']
|
||||||
|
|
||||||
|
));
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
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'],
|
||||||
|
'name' => $parameter_meta['param_name'],
|
||||||
|
'value' => $parameter_meta['param_value'],
|
||||||
|
);
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKefuReward()
|
||||||
|
{
|
||||||
|
$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 + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$mail_id = $_REQUEST['mail_ids'];
|
||||||
|
|
||||||
|
$url = '';
|
||||||
|
if (SERVER_ENV == _ONLINE) {
|
||||||
|
$url = 'https://gamemail.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&';
|
||||||
|
} else {
|
||||||
|
$url = 'https://gamemail-test.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&';
|
||||||
|
}
|
||||||
|
$params = array(
|
||||||
|
'account_id' => $_REQUEST['account_id'],
|
||||||
|
'mail_ids' => $mail_id,
|
||||||
|
'session_id' => $_REQUEST['session_id']
|
||||||
|
);
|
||||||
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||||
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT kefu_status FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($row['kefu_status'] != 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3, '客服奖励已领取');
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$item_list = array();
|
||||||
|
$item_id = 0;
|
||||||
|
$item_num = 0;
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
$errcode = $data['errcode'];
|
||||||
|
$errmsg = $data['errmsg'];
|
||||||
|
if ($errcode == 0) {
|
||||||
|
foreach($data['attachments'] as $kefu){
|
||||||
|
$item_id = $kefu['itemid'];
|
||||||
|
$item_num = $kefu['itemnum'];
|
||||||
|
}
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $item_num, $account_id);
|
||||||
|
array_push($item_list, array(
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'item_num' => $item_num,
|
||||||
|
));
|
||||||
|
|
||||||
|
//保存客服奖励
|
||||||
|
$kefureward_uuid = 'game2003api_kefureward_uuid:' . md5($_REQUEST['account_id']);
|
||||||
|
$kefureward_list = array();
|
||||||
|
$r = $this->getRedis($kefureward_uuid);
|
||||||
|
$user_db_str = $r->get($kefureward_uuid);
|
||||||
|
if (!$r) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (empty($user_db_str)) {
|
||||||
|
$kefureward_db = array(
|
||||||
|
'kefureward_uuid' => $kefureward_uuid,
|
||||||
|
'kefureward_list' => $item_list,
|
||||||
|
);
|
||||||
|
$r -> set($kefureward_uuid, json_encode($kefureward_db));
|
||||||
|
$r -> pexpire($kefureward_uuid, 1000 * 7200);
|
||||||
|
} else {
|
||||||
|
$kefureward_db = array(
|
||||||
|
'kefureward_uuid' => $kefureward_uuid,
|
||||||
|
'kefureward_list' => $item_list,
|
||||||
|
);
|
||||||
|
$r -> set($kefureward_uuid, json_encode($kefureward_db));
|
||||||
|
$r -> pexpire($kefureward_uuid, 1000 * 7200);
|
||||||
|
}
|
||||||
|
//更新状态
|
||||||
|
$ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':modify_time' => time(),
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => $errcode,
|
||||||
|
'errmsg' => $errmsg,
|
||||||
|
'item_list' => $item_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collectReward()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$type = $_REQUEST['type'];
|
||||||
|
switch ($type)
|
||||||
|
{
|
||||||
|
case 1: //收藏
|
||||||
|
$this->updateCollectStatus($account_id);
|
||||||
|
$item_list = $this->rewardList(COLLECT_REWARDS, $account_id);
|
||||||
|
break;
|
||||||
|
case 2: //浮窗
|
||||||
|
$this->updateWindowStatus($account_id);
|
||||||
|
$item_list = $this->rewardList(WINDOWS_REWARDS, $account_id);
|
||||||
|
break;
|
||||||
|
case 3: //限时
|
||||||
|
$this->updateDailyReward($account_id);
|
||||||
|
$item_list = $this->rewardList(FREE_DIAMOND, $account_id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'item_list' => $item_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateDailyReward($account_id)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('UPDATE user SET daily_reward=daily_reward + 1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':modify_time' => time(),
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateCollectStatus($account_id)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':modify_time' => time(),
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateWindowStatus($account_id)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':modify_time' => time(),
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rewardList($key, $account_id)
|
||||||
|
{
|
||||||
|
$item_list = array();
|
||||||
|
$p = $this->getParameter($key);
|
||||||
|
$item_id = 10003;
|
||||||
|
$item_num = $p['value'];
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $item_num, $account_id);
|
||||||
|
array_push($item_list, array(
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'item_num' => $item_num
|
||||||
|
));
|
||||||
|
return $item_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tryPlayInfo()
|
||||||
|
{
|
||||||
|
$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 + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$play_list = array();
|
||||||
|
$rows = $conn->execQuery('SELECT appid, status FROM try_play WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if ($rows) {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
array_push($play_list, array(
|
||||||
|
'appid' => $row['appid'],
|
||||||
|
'status' => $row['status']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'play_list' => $play_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tryPlayReward()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$appid = $_REQUEST['appid'];
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$play_list = array();
|
||||||
|
$row = $conn->execQueryOne('SELECT status FROM try_play WHERE accountid=:accountid AND appid=:appid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':appid' => $appid
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
//插入
|
||||||
|
$ret = $conn->execScript('INSERT INTO try_play(accountid, appid, status, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :appid, :status, :create_time, :modify_time) ' .
|
||||||
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, appid=:appid, status=:status, modify_time=:modify_time;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':ach_id' => $appid,
|
||||||
|
':status' => 1,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if(!$ret){
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//更新
|
||||||
|
$ret = $conn->execScript('UPDATE try_play SET status=1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid AND appid=:ach_appid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':modify_time' => time(),
|
||||||
|
':appid' => $appid
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//获得奖励
|
||||||
|
$item_list = $this->rewardList(NEWGAME_REWARDS, $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'play_list' => $play_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
331
webapp/controller/SignController.class.php
Normal file
331
webapp/controller/SignController.class.php
Normal file
@ -0,0 +1,331 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'classes/AddReward.php';
|
||||||
|
|
||||||
|
class SignController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getSign($sign_id)
|
||||||
|
{
|
||||||
|
$g_conf_sign_cluster = require('../res/signDaily@signDaily.php');
|
||||||
|
$sign_conf = getSignConfig($g_conf_sign_cluster, $sign_id);
|
||||||
|
$s = array(
|
||||||
|
'sign_id' => $sign_conf['sign_id'],
|
||||||
|
'condition' => $sign_conf['condition'],
|
||||||
|
'item_id' => $sign_conf['item_id'],
|
||||||
|
'num' => $sign_conf['num'],
|
||||||
|
);
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function insertSign($account_id, $sign_days)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$ret = $conn->execScript('INSERT INTO sign(accountid, sign_id, signable, sign_time, create_time, modify_time) ' .
|
||||||
|
' VALUES(:accountid, :sign_id, 0, :sign_time, :create_time, :modify_time) ' .
|
||||||
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, sign_id=:sign_id, signable=0, sign_time=:sign_time, modify_time=:modify_time;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':sign_id' => $sign_days,
|
||||||
|
':sign_time' => time(),
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function signInfo()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
$last_sign_id = 0;
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows = $conn->execQuery('SELECT sign_id, sign_time FROM sign WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
$nowTime = phpcommon\getdayseconds(time());
|
||||||
|
if (!$rows) {
|
||||||
|
$last_sign_id = 1;
|
||||||
|
//插入签到列表
|
||||||
|
$this->insertSign($account_id, $last_sign_id);
|
||||||
|
//更新签到总天数
|
||||||
|
$this->updateSignSum($account_id, $last_sign_id);
|
||||||
|
} else {
|
||||||
|
$last_sign_time = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row['sign_id'] > $last_sign_id) {
|
||||||
|
$last_sign_time = $row['sign_time'];
|
||||||
|
$last_sign_id = $row['sign_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($nowTime - phpcommon\getdayseconds($last_sign_time) > 0) {
|
||||||
|
//每日刷新
|
||||||
|
//$this->updateDaily($account_id);
|
||||||
|
//$this->updateSeasonStatus($account_id);
|
||||||
|
$passed_days = floor(($nowTime - phpcommon\getdayseconds($last_sign_time)) / (3600 * 24));
|
||||||
|
if ($passed_days > 7 - $last_sign_id) {
|
||||||
|
//跨周时删除老数据
|
||||||
|
$num = 0;
|
||||||
|
$sum = 0;
|
||||||
|
$ret = $conn->execScript('DELETE from sign WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($passed_days > 7) {
|
||||||
|
$num = ($passed_days + $last_sign_id) % 7;
|
||||||
|
} else {
|
||||||
|
$num = $last_sign_id + $passed_days - 7;
|
||||||
|
}
|
||||||
|
if ($num == 0) {
|
||||||
|
$sum = 7;
|
||||||
|
} else {
|
||||||
|
$sum = $num;
|
||||||
|
}
|
||||||
|
for ($i = 1; $i < $sum + 1; $i++) {
|
||||||
|
//插入补签列表
|
||||||
|
$this->insertSign($account_id, $i);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ($i = $last_sign_id + 1; $i < $passed_days + $last_sign_id + 1; $i++) {
|
||||||
|
//插入补签列表
|
||||||
|
$this->insertSign($account_id, $i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//更新签到总天数
|
||||||
|
$this->updateSignSum($account_id, $passed_days);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sign_list = array();
|
||||||
|
$rows = $conn->execQuery('SELECT sign_id, signable FROM sign WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
array_push($sign_list, array(
|
||||||
|
'sign_id' => $row['sign_id'],
|
||||||
|
'signable' => $row['signable']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
//判断当前第几周
|
||||||
|
$item_list = array();
|
||||||
|
$week = ceil($rowUser['sign_sum'] / 7);
|
||||||
|
$dayid = ($week - 1) * 7;
|
||||||
|
//如果大于配置表最后一周,按最后一周奖励
|
||||||
|
$g_conf_sign_cluster = require('../res/signDaily@signDaily.php');
|
||||||
|
if ($dayid > count($g_conf_sign_cluster)) {
|
||||||
|
$dayid = count($g_conf_sign_cluster) - 7;
|
||||||
|
}
|
||||||
|
for ($day = $dayid + 1; $day <= $dayid + 7; $day++) {
|
||||||
|
$s = $this->getSign($day + 90000);
|
||||||
|
array_push($item_list, array(
|
||||||
|
'item_id' => $s['item_id'],
|
||||||
|
'item_num' => $s['num'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'sign_days' => $rowUser['sign_sum'],
|
||||||
|
'sign_list' => $sign_list,
|
||||||
|
'item_list' => $item_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function updateSignSum($account_id, $sign_num)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
if (!$conn) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET sign_sum=:sign_sum, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':sign_sum' => $row['sign_sum'] + $sign_num,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function signReward()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT signable FROM sign WHERE accountid=:accountid AND sign_id=:sign_id;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':sign_id' => $_REQUEST['sign_id'],
|
||||||
|
));
|
||||||
|
if (!$row || $row['signable'] == 1) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '已签到');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$ret = $conn->execScript('UPDATE sign SET sign_time=:sign_time, signable=1, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid AND sign_id=:sign_id;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':sign_id' => $_REQUEST['sign_id'],
|
||||||
|
':sign_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
//获得奖励
|
||||||
|
//判断当前第几周
|
||||||
|
$item_list = array();
|
||||||
|
$week = ceil($rowUser['sign_sum'] / 7);
|
||||||
|
$dayid = ($week - 1) * 7 + $_REQUEST['sign_id'];
|
||||||
|
//如果大于配置表最后一周,按最后一周奖励
|
||||||
|
$g_conf_sign_cluster = require('../res/signDaily@signDaily.php');
|
||||||
|
if ($dayid > count($g_conf_sign_cluster)) {
|
||||||
|
$dayid = count($g_conf_sign_cluster) - 7;
|
||||||
|
}
|
||||||
|
$s = $this->getSign($dayid + 90000);
|
||||||
|
$item_id = $s['item_id'];
|
||||||
|
$num = $s['num'];
|
||||||
|
array_push($item_list, array(
|
||||||
|
'item_id' => $s['item_id'],
|
||||||
|
'item_num' => $s['num'],
|
||||||
|
));
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $num, $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'item_list' => $item_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function signDoubleReward()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$rowUser = $conn->execQueryOne('SELECT sign_sum FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
//获得奖励
|
||||||
|
//判断当前第几周
|
||||||
|
$item_list = array();
|
||||||
|
$week = ceil($rowUser['sign_sum'] / 7);
|
||||||
|
$dayid = ($week - 1) * 7 + $_REQUEST['sign_id'];
|
||||||
|
//如果大于配置表最后一周,按最后一周奖励
|
||||||
|
$g_conf_sign_cluster = require('../res/signDaily@signDaily.php');
|
||||||
|
if ($dayid > count($g_conf_sign_cluster)) {
|
||||||
|
$dayid = count($g_conf_sign_cluster) - 7;
|
||||||
|
}
|
||||||
|
$s = $this->getSign($dayid + 90000);
|
||||||
|
$item_id = $s['item_id'];
|
||||||
|
$num = $s['num'];
|
||||||
|
$p = $this->getParameter(SIGNREWARD_TIMES);
|
||||||
|
$times = $p['param_value'] - 1;
|
||||||
|
$num = $num * $times;
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $num, $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
726
webapp/controller/TankController.class.php
Normal file
726
webapp/controller/TankController.class.php
Normal file
@ -0,0 +1,726 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TankController{
|
||||||
|
|
||||||
|
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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
||||||
|
));
|
||||||
|
return $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getTank($tank_id)
|
||||||
|
{
|
||||||
|
$tank_meta_table = require('../res/tank_economy@tank_economy.php');
|
||||||
|
$tank_meta = getTankConfig($tank_meta_table, $tank_id);
|
||||||
|
$t = array(
|
||||||
|
'id' => $tank_meta['tank_id'],
|
||||||
|
'level' => $tank_meta['level'],
|
||||||
|
'coin_origin' => $tank_meta['coin_origin'],
|
||||||
|
'coin_times' => $tank_meta['coin_times'],
|
||||||
|
'coin_sell' => $tank_meta['coin_sell'],
|
||||||
|
'diamond' => $tank_meta['diamond'],
|
||||||
|
'coin_produce' => $tank_meta['coin_produce'],
|
||||||
|
'coin_lv' => $tank_meta['coin_lv'],
|
||||||
|
'diamond_lv' => $tank_meta['diamond_lv'],
|
||||||
|
'drop_level' => $tank_meta['drop_level'],
|
||||||
|
'drop_number' => $tank_meta['drop_number'],
|
||||||
|
'ad_level' => $tank_meta['ad_level'],
|
||||||
|
'buy_range1' => $tank_meta['buy_range1'],
|
||||||
|
'buy_times1' => $tank_meta['buy_times1'],
|
||||||
|
'free_lv1' => $tank_meta['free_lv1'],
|
||||||
|
'buy_range2' => $tank_meta['buy_range2'],
|
||||||
|
'buy_times2' => $tank_meta['buy_times2'],
|
||||||
|
'free_lv2' => $tank_meta['free_lv2'],
|
||||||
|
);
|
||||||
|
return $t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendInfo()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$tankInfo = json_decode(file_get_contents('php://input'), true);
|
||||||
|
$tank_data = $tankInfo['tank'];
|
||||||
|
if ($tank_data) {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET tank_data=:tank_data, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_data' => json_encode($tank_data),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$money = $tankInfo['money'];
|
||||||
|
if ($money) {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':coin_num' => $money,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$buy_data = $tankInfo['times'];
|
||||||
|
if ($buy_data) {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET buy_data=:buy_data, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':buy_data' => json_encode($buy_data),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$pass = $tankInfo['pass'];
|
||||||
|
if ($pass) {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET pass=:pass, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':pass' => json_encode($pass),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
/* protected function getTankuuid($accountid)
|
||||||
|
{
|
||||||
|
$mysql_conf = getMysqlConfig(crc32($accountid));
|
||||||
|
$conn = $this->getMysql($accountid);
|
||||||
|
$ret = $conn->execScript("INSERT INTO id_pool(createtime) VALUES(:createtime);",
|
||||||
|
array(
|
||||||
|
'createtime' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID();', array());
|
||||||
|
if (empty($row)) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$orderid = $this->getIdPool($mysql_conf['instance_id'] , $row[0]);
|
||||||
|
return $orderid;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getIdPool($db_instance_id, $idx)
|
||||||
|
{
|
||||||
|
if ($db_instance_id >= 100 || $db_instance_id <= 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'instance_id无效');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($idx >= 4294967295 || $idx <= 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1, 'idx无效');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$instance_id = sprintf('%02d', $db_instance_id);
|
||||||
|
$id = sprintf('%010d',$idx);
|
||||||
|
$tank_uuid = strftime('%y%m%d%H%M%S') . $instance_id . $id;
|
||||||
|
return $tank_uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function tankInfo()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
//购买次数信息
|
||||||
|
$buy_list = array();
|
||||||
|
$row_times = $conn->execQueryOne('SELECT times FROM buy_times ' .
|
||||||
|
' WHERE accountid=:accountid AND level=:level;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':level' => $level,
|
||||||
|
));
|
||||||
|
if ($row_times) {
|
||||||
|
foreach ($row_times as $row_times) {
|
||||||
|
array_push($buy_list, array(
|
||||||
|
'level' => $row_times['level'],
|
||||||
|
'times' => $row_times['times'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//坦克列表
|
||||||
|
$tank_list = array();
|
||||||
|
//$curr_tank_uuid = '';
|
||||||
|
$rows_tank = $conn->execQuery('SELECT tankInfo FROM tankInfo WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
));
|
||||||
|
//新玩家默认赠送一级坦克
|
||||||
|
if ($rows_tank) {
|
||||||
|
foreach ($rows_tank as $row_tank) {
|
||||||
|
if ($row_tank['tank_level'] == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
array_push($tank_list, array(
|
||||||
|
'tank_uuid' => $row_tank['tank_uuid'],
|
||||||
|
'level' => $row_tank['tank_level'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$curr_tank_uuid = $this->getTankuuid($account_id);
|
||||||
|
$ret = $conn->execScript('INSERT INTO tank(accountid, tank_uuid, tank_level, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :tank_uuid, 1, :create_time, :modify_time)',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $curr_tank_uuid,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//更新默认上阵坦克信息
|
||||||
|
$ret = $conn->execScript('UPDATE user SET curr_tank_uuid=:tank_uuid, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $curr_tank_uuid,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
array_push($tank_list, array(
|
||||||
|
'tankInfo' => $row_tank['tankInfo'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$coin_num = $row['coin_num'];
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'buy_list' => $buy_list,
|
||||||
|
'coin_num' => $coin_num,
|
||||||
|
'tank_list' => $tank_list
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tankCompose()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$new_uuid = $_REQUEST['newtank_uuid'];
|
||||||
|
$del_uuid = $_REQUEST['deltank_uuid'];
|
||||||
|
//判断是否存在足够多的坦克
|
||||||
|
$row_new = $this->selectTank($account_id, $new_uuid);
|
||||||
|
$row_del = $this->selectTank($account_id, $del_uuid);
|
||||||
|
//坦克合成
|
||||||
|
$compose_level = $row_new['tank_level'] + 1;
|
||||||
|
$this->updateTankLevel($account_id, $new_uuid, $compose_level);
|
||||||
|
$this->updateTankLevel($account_id, $del_uuid, 0);
|
||||||
|
$compose_status = 0;
|
||||||
|
//判断是否合成新坦克
|
||||||
|
$row = $conn->execQueryOne('SELECT max_level FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if ($compose_level > $row['max_level']) {
|
||||||
|
$compose_status = 1;
|
||||||
|
//更新新坦克上阵,更新坦克最大等级
|
||||||
|
$ret = $conn->execScript('UPDATE user SET max_level=:level, curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':level' => $compose_level,
|
||||||
|
':curr_tank_uuid' => $new_uuid,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'status' => $compose_status,
|
||||||
|
'level' => $compose_level
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function selectTank($account_id, $tank_uuid)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$row = $conn->execQueryOne('SELECT tank_uuid, tank_level FROM tank ' .
|
||||||
|
' WHERE accountid=:account_id AND tank_uuid=:tank_uuid;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $tank_uuid
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2,'坦克不存在');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateTankLevel($account_id, $tank_uuid, $level)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('UPDATE tank SET tank_level=:level, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id AND tank_uuid=:tank_uuid;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $tank_uuid,
|
||||||
|
':level' => $level,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buyTank()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$level = $_REQUEST['level'];
|
||||||
|
$row = $conn->execQueryOne('SELECT max_level, coin_num, diamond_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$max_tank = $this->getTank(10000 + $row['max_level']);
|
||||||
|
$t = $this->getTank(10000 + $level);
|
||||||
|
$num = 0;
|
||||||
|
$times = 0;
|
||||||
|
$row_times = $conn->execQueryOne('SELECT times FROM buy_times ' .
|
||||||
|
' WHERE accountid=:accountid AND level=:level;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':level' => $level,
|
||||||
|
));
|
||||||
|
$this->buyLevelLimit($level, $max_tank['diamond_lv']);
|
||||||
|
if ($row['diamond_num'] < $t['diamond']) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3,'钻石不足');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$cur_num = $row['diamond_num'] - $t['diamond'];
|
||||||
|
$this->updateBuyInfo($account_id, $cur_num, 0, 0);
|
||||||
|
/*switch ($_REQUEST['type'])
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
//金币购买
|
||||||
|
$this->buyLevelLimit($level, $max_tank['coin_lv']);
|
||||||
|
if (!$row_times) {
|
||||||
|
$times = 1;
|
||||||
|
$this->insertBuyInfo($account_id, $level);
|
||||||
|
} else {
|
||||||
|
$times = $row_times['times'] + 1;
|
||||||
|
}
|
||||||
|
$num = $this->test($t['coin_origin'], $times, $t['coin_times'] * 1000);
|
||||||
|
if ($row['coin_num'] < $num) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3,'金币不足');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$cur_num = phpcommon\bnSub_s($row['coin_num'], $num);
|
||||||
|
$this->updateBuyInfo($account_id, $cur_num, $level, $times);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
//钻石购买
|
||||||
|
$this->buyLevelLimit($level, $max_tank['diamond_lv']);
|
||||||
|
if ($row['diamond_num'] < $t['diamond']) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3,'钻石不足');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$cur_num = $row['diamond_num'] - $t['diamond'];
|
||||||
|
$this->updateBuyInfo($account_id, $cur_num, 0, 0);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//金币加视频购买
|
||||||
|
$this->buyLevelLimit($level, $max_tank['buy_range2']);
|
||||||
|
if (!$row_times) {
|
||||||
|
$times = 1;
|
||||||
|
$this->insertBuyInfo($account_id, $level);
|
||||||
|
} else {
|
||||||
|
$times = $row_times['times'] + 1;
|
||||||
|
}
|
||||||
|
$num = $this->test($t['coin_origin'], $times, $t['coin_times'] * 1000);
|
||||||
|
if ($row['coin_num'] < $num) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3,'金币不足');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$cur_num = phpcommon\bnSub_s($row['coin_num'], $num);
|
||||||
|
$this->updateBuyInfo($account_id, $cur_num, $level, $times);
|
||||||
|
$level = $level + 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
//插入到坦克列表中
|
||||||
|
$curr_tank_uuid = $this->getTankuuid($account_id);
|
||||||
|
$ret = $conn->execScript('INSERT INTO tank(accountid, tank_uuid, tank_level, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :tank_uuid, :tank_level, :create_time, :modify_time)',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_uuid' => $curr_tank_uuid,
|
||||||
|
':tank_level' => $level,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'diamond_num' => $cur_num
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function buyLevelLimit($level, $t_level)
|
||||||
|
{
|
||||||
|
if ($level > $t_level) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '购买等级大于当前等级');
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function insertBuyInfo($account_id, $level)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
$ret = $conn->execScript('INSERT INTO buy_times(accountid, level, times, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :level, 0, :create_time, :modify_time)',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':level' => $level,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateBuyInfo($account_id, $num, $level, $times)
|
||||||
|
{
|
||||||
|
$conn = $this->getMysql($account_id);
|
||||||
|
if ($times != 0) {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET coin_num=:num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':num' => $num,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
$ret = $conn->execScript('UPDATE buy_times SET times=:times, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id AND level=:level;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':times' => $times,
|
||||||
|
':level' => $level,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':num' => $num,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tankListInfo()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$tank_list = $_REQUEST['tank_list'];
|
||||||
|
$ret = $conn->execScript('UPDATE user SET tank_slot_list=:tank_slot_list, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':tank_slot_list' => $tank_list,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function currentTank()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$tank_uuid = $_REQUEST['tank_uuid'];
|
||||||
|
$ret = $conn->execScript('UPDATE user SET curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':curr_tank_uuid' => $tank_uuid,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tankRecover()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$tank_uuid = $_REQUEST['tank_uuid'];
|
||||||
|
$row = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//删除坦克
|
||||||
|
$row_tank = $this->selectTank($account_id, $tank_uuid);
|
||||||
|
$this->updateTankLevel($account_id, $tank_uuid, 0);
|
||||||
|
//增加金钱
|
||||||
|
$t = $this->getTank(10000 + $row_tank['tank_level']);
|
||||||
|
$num = phpcommon\bnAdd_s($row['coin_num'], $t['coin_sell']);
|
||||||
|
$ret = $conn->execScript('UPDATE user SET coin_num=:num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':num' => $num,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sumComposeTank()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$rows = $conn->execQuery('SELECT tank_uuid, tank_level FROM tank WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$rows) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个坦克');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$tank_array = array();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$key = $row['tank_level'];
|
||||||
|
if (!array_key_exists($key, $tank_array)) {
|
||||||
|
$tank_array[$key] = array();
|
||||||
|
}
|
||||||
|
array_push($tank_array[$key], array(
|
||||||
|
'tank_uuid' => $row['tank_uuid'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$level = 1;
|
||||||
|
$max_level = 1;
|
||||||
|
$curr_tank_uuid = '';
|
||||||
|
$row_user = $conn->execQueryOne('SELECT max_level FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
));
|
||||||
|
if (!$row_user) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 1,'没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//一键合成
|
||||||
|
for (; $level <= $row_user['max_level']; $level++) {
|
||||||
|
if (!array_key_exists($level, $tank_array) || count($tank_array[$level]) < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$tank = $tank_array[$level];
|
||||||
|
$len = count($tank_array[$level]);
|
||||||
|
$new_num = floor($len / 2);
|
||||||
|
for ($i = 0; $i < $len; $i = $i + 2) {
|
||||||
|
$this->updateTankLevel($account_id, $tank[$i]['tank_uuid'], $level + 1);
|
||||||
|
$this->updateTankLevel($account_id, $tank[$i + 1]['tank_uuid'], 0);
|
||||||
|
}
|
||||||
|
$max_level = $level + 1;
|
||||||
|
$curr_tank_uuid = $tank[0]['tank_uuid'];
|
||||||
|
}
|
||||||
|
$compose_status = 0;
|
||||||
|
if ($max_level > $row_user['max_level']) {
|
||||||
|
$compose_status = 1;
|
||||||
|
//更新新坦克上阵,更新坦克最大等级
|
||||||
|
$ret = $conn->execScript('UPDATE user SET max_level=:level, curr_tank_uuid=:curr_tank_uuid, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:account_id;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':level' => $max_level,
|
||||||
|
':curr_tank_uuid' => $curr_tank_uuid,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'status' => $compose_status,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test1()
|
||||||
|
{
|
||||||
|
$this->test(310, 1, 1175);
|
||||||
|
}
|
||||||
|
public function test($base_value, $times, $multiple)
|
||||||
|
{
|
||||||
|
$v = (int)$multiple;
|
||||||
|
$value = gmp_init($base_value);
|
||||||
|
$cfg_value = gmp_init($v);
|
||||||
|
$fada_exp = gmp_init('1000');
|
||||||
|
$exp = gmp_pow($cfg_value, $times);
|
||||||
|
$exp2 = gmp_pow($fada_exp, $times);
|
||||||
|
$result = gmp_mul($value, $exp);
|
||||||
|
$real_result = gmp_div($result, $exp2);
|
||||||
|
return gmp_strval($real_result);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user