privilege
This commit is contained in:
parent
2105b305b0
commit
9a149a1950
@ -344,6 +344,7 @@ CREATE TABLE `recharge` (
|
||||
`accountid` varchar(60) COLLATE utf8_bin NOT NULL DEFAULT '' COMMENT '账号id',
|
||||
`first_data` mediumblob COMMENT '首充数据',
|
||||
`daily_purchase` mediumblob COMMENT '每日特惠礼包',
|
||||
`vip_info` mediumblob COMMENT '月卡信息',
|
||||
`recharge_diamond` int(11) NOT NULL DEFAULT '0' COMMENT '累计充值钻石',
|
||||
`present_diamond` int(11) NOT NULL DEFAULT '0' COMMENT '充值赠送钻石总量',
|
||||
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
@ -364,8 +365,8 @@ CREATE TABLE `orderinfo` (
|
||||
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
UNIQUE KEY `idx_orderid` (`orderid`),
|
||||
KEY `idx_accountid` (`accountid`),
|
||||
KEY `idx_orderid` (`orderid`),
|
||||
KEY `idx_goodsid` (`goodsid`),
|
||||
KEY `idx_time` (`create_time`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
64
webapp/classes/Privilege.php
Normal file
64
webapp/classes/Privilege.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace classes;
|
||||
|
||||
use phpcommon;
|
||||
use metatable;
|
||||
require_once 'metatable/privilegecard.php';
|
||||
|
||||
class Privilege
|
||||
{
|
||||
|
||||
protected function getMysql($account_id)
|
||||
{
|
||||
$mysql_conf = getMysqlConfig(crc32($account_id));
|
||||
$conn = new phpcommon\Mysql(array(
|
||||
'host' => $mysql_conf['host'],
|
||||
'port' => $mysql_conf['port'],
|
||||
'user' => $mysql_conf['user'],
|
||||
'passwd' => $mysql_conf['passwd'],
|
||||
'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id']
|
||||
));
|
||||
return $conn;
|
||||
}
|
||||
|
||||
public function getBattlePlus($account_id)
|
||||
{
|
||||
return $this->getPrivilegePlus($account_id, 'battleplus');
|
||||
}
|
||||
|
||||
public function getCoinTimesPlus($account_id)
|
||||
{
|
||||
return $this->getPrivilegePlus($account_id, 'dailycoin_times');
|
||||
}
|
||||
|
||||
protected function getPrivilegePlus($account_id, $name)
|
||||
{
|
||||
$conn = $this->getMysql($account_id);
|
||||
if (!$conn) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$row = $conn->execQueryOne(
|
||||
'SELECT * FROM recharge WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
)
|
||||
);
|
||||
$plus = 0;
|
||||
if ($row) {
|
||||
$nowtime = time();
|
||||
$vip_info = json_decode($row['vip_info']);
|
||||
foreach ($vip_info as $key => $carditem) {
|
||||
if ($vip_info[$key]['expire'] == 0 || $vip_info[$key]['expire'] > $nowtime) {
|
||||
$privilegecard_conf = metatable\getPrivilegeCardById($key);
|
||||
if (!$privilegecard_conf) {
|
||||
$plus += $privilegecard_conf[$name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $plus;
|
||||
}
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
require 'classes/Quest.php';
|
||||
require 'classes/AddReward.php';
|
||||
|
||||
class GameOverController{
|
||||
class GameOverController
|
||||
{
|
||||
|
||||
protected function getMysql($account_id)
|
||||
{
|
||||
@ -74,7 +75,7 @@ class GameOverController{
|
||||
'equip_upgradetime' => $equip_conf['equip_upgradetime'],
|
||||
'diamond_cost' => $equip_conf['diamond_cost'],
|
||||
'drop_id' => $equip_conf['drop_id']
|
||||
);
|
||||
);
|
||||
return $e;
|
||||
}
|
||||
|
||||
@ -164,10 +165,12 @@ class GameOverController{
|
||||
}
|
||||
//道具物品
|
||||
$first_list = array();
|
||||
if (phpcommon\extractChannel($account_id) == 6001 ||
|
||||
if (
|
||||
phpcommon\extractChannel($account_id) == 6001 ||
|
||||
phpcommon\extractChannel($account_id) == 6007 ||
|
||||
phpcommon\extractChannel($account_id) == 6008 ||
|
||||
phpcommon\extractChannel($account_id) == 6000) {
|
||||
phpcommon\extractChannel($account_id) == 6000
|
||||
) {
|
||||
array_push($first_list, array(
|
||||
'item_id' => 18006,
|
||||
'item_num' => $num,
|
||||
@ -182,12 +185,12 @@ class GameOverController{
|
||||
'first_uuid' => $first_uuid,
|
||||
'first_list' => $first_list,
|
||||
);
|
||||
$r -> set($first_uuid, json_encode($first_db));
|
||||
$r -> pexpire($first_uuid, 1000 * 3600 * 2);
|
||||
$r->set($first_uuid, json_encode($first_db));
|
||||
$r->pexpire($first_uuid, 1000 * 3600 * 2);
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'first_uuid' => $first_uuid,
|
||||
'item_list' => $first_list,
|
||||
'coin' => $coin,
|
||||
@ -214,16 +217,25 @@ class GameOverController{
|
||||
$all_item_list = array();
|
||||
if ($type == 0) {
|
||||
$item_list = $this->fixReward($item_list, 5);
|
||||
$privilege = new classes\Privilege();
|
||||
$coinplus = $privilege->getBattlePlus($account_id);
|
||||
if ($coinplus > 0) {
|
||||
foreach ($item_list as $key => $val) {
|
||||
if ($val['item_id'] == 10001) {
|
||||
$item_list[$key]['item_num'] = $val['item_num'] * (100 + $coinplus) / 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$r = $this->getRedis($first_uuid);
|
||||
$user_db_str = $r->get($first_uuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session失效');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session失效');
|
||||
return;
|
||||
}
|
||||
$item_list = $user_db['first_list'];
|
||||
@ -241,9 +253,9 @@ class GameOverController{
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($item_list as $it) {
|
||||
foreach ($item_list as $it) {
|
||||
$items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0);
|
||||
foreach($items as $j) {
|
||||
foreach ($items as $j) {
|
||||
array_push($all_item_list, array(
|
||||
'item_id' => $j['item_id'],
|
||||
'item_num' => $j['item_num'],
|
||||
@ -255,7 +267,7 @@ class GameOverController{
|
||||
$diamond_num = $addreward->getDiamondNum($account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'coin_nums' => $coin_num,
|
||||
'diamond_nums' => $diamond_num,
|
||||
'item_list' => $item_list,
|
||||
@ -275,7 +287,7 @@ class GameOverController{
|
||||
$fixed_num = $this->getExplode($b1['num']);
|
||||
$fixed_array = $this->getExplode($b1['weight']);
|
||||
|
||||
for($i = 0; $i < count($fixed_id); $i++) {
|
||||
for ($i = 0; $i < count($fixed_id); $i++) {
|
||||
$random = Rand(0, 10000);
|
||||
if ($fixed_array[$i][0] >= $random) {
|
||||
array_push($item_list, array(
|
||||
@ -288,7 +300,8 @@ class GameOverController{
|
||||
return $item_list;
|
||||
}
|
||||
|
||||
protected function randomBox($item_list, $type) {
|
||||
protected function randomBox($item_list, $type)
|
||||
{
|
||||
$b1 = $this->getbox($type);
|
||||
if (!$b1) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
||||
@ -299,13 +312,13 @@ class GameOverController{
|
||||
$fixed_num = $this->getExplode($b1['num']);
|
||||
$fixed_array = $this->getExplode($b1['weight']);
|
||||
$sum = 0;
|
||||
for($i = 0; $i < count($fixed_array); $i++) {
|
||||
for ($i = 0; $i < count($fixed_array); $i++) {
|
||||
$sum = $fixed_array[$i][0] + $sum;
|
||||
}
|
||||
|
||||
$rm = Rand(0, $sum);
|
||||
$key = 0;
|
||||
for($j = 0; $j < count($fixed_array); $j++) {
|
||||
for ($j = 0; $j < count($fixed_array); $j++) {
|
||||
$key = $fixed_array[$j][0] + $key;
|
||||
if ($key >= $rm) {
|
||||
array_push($item_list, array(
|
||||
@ -319,14 +332,13 @@ class GameOverController{
|
||||
'item_num' => $fixed_num[$j][0],
|
||||
'time' => $fixed_time[$j][0]
|
||||
));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $item_list;
|
||||
}
|
||||
protected function randomReward($rank,$type)
|
||||
protected function randomReward($rank, $type)
|
||||
{
|
||||
//随机奖励
|
||||
$r = $this->getRankReward($rank);
|
||||
@ -408,9 +420,9 @@ class GameOverController{
|
||||
$all_item_list = array();
|
||||
$item_list = $this->randomBoxNew($id);
|
||||
$addreward = new classes\AddReward();
|
||||
foreach($item_list as $it) {
|
||||
foreach ($item_list as $it) {
|
||||
$items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0);
|
||||
foreach($items as $j) {
|
||||
foreach ($items as $j) {
|
||||
array_push($all_item_list, array(
|
||||
'item_id' => $j['item_id'],
|
||||
'item_num' => $j['item_num'],
|
||||
@ -422,7 +434,7 @@ class GameOverController{
|
||||
$diamond_num = $addreward->getDiamondNum($account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'coin_nums' => $coin_num,
|
||||
'diamond_nums' => $diamond_num,
|
||||
'item_list' => $item_list,
|
||||
@ -495,7 +507,7 @@ class GameOverController{
|
||||
$diamond_num = $addreward->getDiamondNum($account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'diamond_nums' => $diamond_num,
|
||||
));
|
||||
}
|
||||
@ -514,10 +526,12 @@ class GameOverController{
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
$rowUser = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
));
|
||||
$rowUser = $conn->execQueryOne(
|
||||
'SELECT diamond_num FROM user WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
)
|
||||
);
|
||||
if (!$rowUser) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||
return;
|
||||
@ -532,7 +546,7 @@ class GameOverController{
|
||||
$diamond_num = $addreward->getDiamondNum($account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'diamond_nums' => $diamond_num,
|
||||
));
|
||||
}
|
||||
@ -567,7 +581,7 @@ class GameOverController{
|
||||
'time' => 0,
|
||||
));
|
||||
$items = $addreward->addReward($val[0], $val[1], $account_id, 0, 0);
|
||||
foreach($items as $it) {
|
||||
foreach ($items as $it) {
|
||||
array_push($all_item_list, array(
|
||||
'item_id' => $it['item_id'],
|
||||
'item_num' => $it['item_num'],
|
||||
@ -579,7 +593,7 @@ class GameOverController{
|
||||
$diamond_num = $addreward->getDiamondNum($account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'errmsg' => '',
|
||||
'coin_nums' => $coin_num,
|
||||
'diamond_nums' => $diamond_num,
|
||||
'item_list' => $item_list,
|
||||
|
@ -3,6 +3,7 @@
|
||||
require 'classes/Quest.php';
|
||||
require 'classes/AddReward.php';
|
||||
require_once 'metatable/shopGoods.php';
|
||||
require_once 'metatable/privilegecard.php';
|
||||
|
||||
class RechargeController
|
||||
{
|
||||
@ -255,31 +256,110 @@ class RechargeController
|
||||
die();
|
||||
}
|
||||
|
||||
$privilegecard_conf = null;
|
||||
if ($shopgoods['type'] == 3) {
|
||||
$privilegecard_conf = metatable\getPrivilegeCardById($_REQUEST['goodsid']);
|
||||
if (!$privilegecard_conf) {
|
||||
error_log('game2004api payNotify privilege card goods config error:' + json_encode($_REQUEST));
|
||||
echo json_encode(array(
|
||||
'errcode' => 4,
|
||||
'errmsg' => 'privilege card error'
|
||||
));
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$nowtime = time();
|
||||
$conn = $this->getMysql($_REQUEST['account_id']);
|
||||
$this->insertNewOrder($conn, $nowtime);
|
||||
$this->updateUserTable($conn);
|
||||
$this->addToBuyHis($conn, $nowtime);
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$rechargerow = $conn->execQueryOne(
|
||||
'SELECT * FROM recharge WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
)
|
||||
);
|
||||
|
||||
$addreward = new classes\AddReward();
|
||||
if ($shopgoods['first_present'] > 0) {
|
||||
$addreward->addReward(10003, $shopgoods['first_present'], $account_id, 0, 0);
|
||||
}
|
||||
|
||||
if ($shopgoods['type'] == 3) {
|
||||
$nowtime = time();
|
||||
$conn = $this->getMysql($_REQUEST['account_id']);
|
||||
$this->insertNewOrder($conn, $nowtime);
|
||||
$addreward = new classes\AddReward();
|
||||
// update vip_info
|
||||
if (!$rechargerow) {
|
||||
$vip_info = array();
|
||||
$expire = 0;
|
||||
if ($privilegecard_conf['time'] > 0) {
|
||||
$expire = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1;
|
||||
}
|
||||
array_push($vip_info, array(
|
||||
'id' => $_REQUEST['goodsid'],
|
||||
'expire' => $expire,
|
||||
'daily_time' => 0,
|
||||
));
|
||||
|
||||
$ret = $conn->execScript(
|
||||
'INSERT INTO recharge(accountid, vip_info, create_time, modify_time) ' .
|
||||
' VALUES(:account_id, :vip_info, :create_time, :modify_time) ' .
|
||||
' ON DUPLICATE KEY UPDATE accountid=:account_id, vip_info=:vip_info, modify_time=:modify_time;',
|
||||
array(
|
||||
':account_id' => $account_id,
|
||||
':vip_info' => json_encode($vip_info),
|
||||
':create_time' => $nowtime,
|
||||
':modify_time' => $nowtime,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$vip_info = json_decode($rechargerow['vip_info']);
|
||||
$found = false;
|
||||
foreach ($vip_info as $key => $carditem) {
|
||||
if ($carditem['id'] == $_REQUEST['goodsid']) {
|
||||
$found = true;
|
||||
if ($vip_info[$key]['expire'] > $nowtime) {
|
||||
$vip_info[$key]['expire'] += $privilegecard_conf['time'] * 3600 * 24;
|
||||
} else {
|
||||
if ($privilegecard_conf['time'] > 0) {
|
||||
$vip_info[$key]['expire'] = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
$expire = 0;
|
||||
if ($privilegecard_conf['time'] > 0) {
|
||||
$expire = phpcommon\getdayseconds($nowtime) + $privilegecard_conf['time'] * 3600 * 24 + 3600 * 24 - 1;
|
||||
}
|
||||
array_push($vip_info, array(
|
||||
'id' => $_REQUEST['goodsid'],
|
||||
'expire' => $expire,
|
||||
'daily_time' => 0,
|
||||
));
|
||||
}
|
||||
|
||||
$ret = $conn->execScript(
|
||||
'UPDATE recharge SET daily_purchase=:daily_purchase, modify_time=:modify_time' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
':vip_info' => json_encode($vip_info),
|
||||
':modify_time' => time(),
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$item_list = $addreward->addReward($shopgoods['item_id'], 1, $_REQUEST['account_id'], 0, 0);
|
||||
|
||||
foreach ($item_list as &$value) {
|
||||
$value['itemnum'] = (float)$value['itemnum'];
|
||||
}
|
||||
error_log(json_encode($item_list));
|
||||
|
||||
$this->updateUserTable($conn);
|
||||
$this->addToBuyHis($conn, $nowtime);
|
||||
|
||||
|
||||
//update daily purchase
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$rechargerow = $conn->execQueryOne(
|
||||
'SELECT * FROM recharge WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
)
|
||||
);
|
||||
|
||||
if (!$rechargerow) {
|
||||
$daily_purchase = array();
|
||||
array_push($daily_purchase, array(
|
||||
@ -299,11 +379,11 @@ class RechargeController
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$daily_purchase = json_decode($rechargerow['first_data']);
|
||||
$daily_purchase = json_decode($rechargerow['daily_purchase']);
|
||||
$found = false;
|
||||
foreach ($daily_purchase as $key => $dailyitem) {
|
||||
if ($dailyitem['id'] == $_REQUEST['goodsid']) {
|
||||
$firstrecharge = true;
|
||||
$found = true;
|
||||
$daily_purchase[$key]['time'] = $_REQUEST['timestamp'];
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
require 'classes/Quest.php';
|
||||
require 'classes/AddReward.php';
|
||||
require 'classes/Privilege.php';
|
||||
require_once 'metatable/parameter.php';
|
||||
class RoleController
|
||||
{
|
||||
@ -1614,7 +1615,8 @@ class RoleController
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$privilege = new classes\Privilege();
|
||||
$plustimes = $privilege->getCoinTimesPlus($account_id);
|
||||
$coin_times = $rowUser['coin_times'];
|
||||
$p1 = $this->getParameter(DAILYCOIN_TIMES);
|
||||
$max_times = $p1['param_value'];
|
||||
@ -1636,7 +1638,7 @@ class RoleController
|
||||
$coin_arr = $this->getExplode($eg['promote_gold']);
|
||||
$coin_num = $coin_list[$rowEquip['lv']][0] * $coin_arr[$rowEquip['lv']][0];
|
||||
}
|
||||
if ($coin_times >= $max_times) {
|
||||
if ($coin_times >= $max_times + $plustimes) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 2, '今日次数达到上限');
|
||||
return;
|
||||
}
|
||||
|
36
webapp/metatable/privilegecard.php
Normal file
36
webapp/metatable/privilegecard.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace metatable;
|
||||
|
||||
/*
|
||||
配置表规范
|
||||
getXXXConf:获取表所有数据
|
||||
getXxxById():通过id获取单个数据
|
||||
_internalGetXXXConf:获取表所有数据内部实现不对外开放
|
||||
|
||||
使用方式
|
||||
require_once 'metatable/XXXX.php';
|
||||
|
||||
!!!注意必须使用require_once
|
||||
*/
|
||||
|
||||
function getPrivilegeCardConf()
|
||||
{
|
||||
return _internalGetPrivilegeCardConf();
|
||||
}
|
||||
|
||||
function getPrivilegeCardById($shop_id)
|
||||
{
|
||||
$conf = getPrivilegeCardConf();
|
||||
$shop_id = (int)$shop_id;
|
||||
return array_key_exists($shop_id, $conf) ? $conf[$shop_id] : null;
|
||||
}
|
||||
|
||||
function _internalGetPrivilegeCardConf()
|
||||
{
|
||||
global $g_privilegeCard_table;
|
||||
if (!$g_privilegeCard_table) {
|
||||
$g_privilegeCard_table = require(getConfigBaseDir() . 'privilegecard@privilegecard.php');
|
||||
}
|
||||
return $g_privilegeCard_table;
|
||||
}
|
@ -32,7 +32,7 @@ function _internalGetShopGoodsConf()
|
||||
{
|
||||
global $g_shopGoods_table;
|
||||
if (!$g_shopGoods_table) {
|
||||
$g_shopG_table = require(getConfigBaseDir() . 'shopGoods@shopGoods.php');
|
||||
$g_shopGoods_table = require(getConfigBaseDir() . 'shopGoods@shopGoods.php');
|
||||
}
|
||||
return $g_shopG_table;
|
||||
return $g_shopGoods_table;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user