452 lines
17 KiB
PHP
452 lines
17 KiB
PHP
<?php
|
|
|
|
trait RechargeActivity
|
|
{
|
|
public function activityInfo()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$rechargerow = $conn->execQueryOne(
|
|
'SELECT * FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
)
|
|
);
|
|
|
|
$firstrecharge = '';
|
|
$vipinfo = array();
|
|
$dailypurchase = array();
|
|
$daysecs = phpcommon\getdayseconds(time());
|
|
if ($rechargerow) {
|
|
if ($rechargerow['first_data'] != null) {
|
|
$firstrecharge = $rechargerow['first_data'];
|
|
}
|
|
if ($rechargerow['vip_info'] != null && $rechargerow['vip_info'] != '') {
|
|
$vipinfo = json_decode($rechargerow['vip_info'], true);
|
|
foreach ($vipinfo as $key => $val) {
|
|
$vipinfo[$key]['award'] = $val['daily_time'] < $daysecs ? 0 : 1;
|
|
unset($vipinfo[$key]['daily_time']);
|
|
}
|
|
}
|
|
|
|
if ($rechargerow['daily_purchase'] != null && $rechargerow['daily_purchase'] != '') {
|
|
$dailypurchase = json_decode($rechargerow['daily_purchase'], true);
|
|
$packtime = 0;
|
|
foreach ($dailypurchase as $key => $val) {
|
|
if ($val['id'] == 10 && $val['time'] > $daysecs) {
|
|
$packtime = $val['time'];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($packtime > 0) {
|
|
$shopconf = metatable\getShopGoodsConf();
|
|
foreach ($shopconf as $itemconf) {
|
|
if ($itemconf['type'] != 2) {
|
|
continue;
|
|
}
|
|
|
|
if ($itemconf['shop_id'] == 10) {
|
|
continue;
|
|
}
|
|
|
|
$found = false;
|
|
foreach ($dailypurchase as $key => $val) {
|
|
if ($val['id'] == $itemconf['shop_id']) {
|
|
$found = true;
|
|
$dailypurchase[$key]['time'] = $packtime;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$found) {
|
|
array_push($dailypurchase, array(
|
|
'id' => $itemconf['shop_id'],
|
|
'time' => $packtime,
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
$daily = array();
|
|
foreach ($dailypurchase as $key => $val) {
|
|
if ($val['time'] < $daysecs) {
|
|
unset($dailypurchase[$key]);
|
|
} else {
|
|
array_push($daily, $val);
|
|
}
|
|
}
|
|
$dailypurchase = $daily;
|
|
}
|
|
}
|
|
|
|
$activityconf = metatable\getRechargeActivityConf();
|
|
$recharge_activity = array();
|
|
$activity = array();
|
|
if ($rechargerow['activity'] != null && $rechargerow['activity'] != '') {
|
|
$activity = json_decode($rechargerow['activity'], true);
|
|
}
|
|
$needupdate = false;
|
|
$time1 = '';
|
|
$time2 = '';
|
|
foreach ($activityconf as $key => $itemconf) {
|
|
$time1 = $itemconf['time1'];
|
|
$time2 = $itemconf['time2'];
|
|
if (time() < strtotime($itemconf['time1']) || time() > strtotime($itemconf['time2'])) {
|
|
continue;
|
|
}
|
|
|
|
$found = false;
|
|
$itemarray = array();
|
|
foreach ($activity as $itemkey => $item) {
|
|
if ($itemconf['shop_id'] == $item['id']) {
|
|
$found = true;
|
|
|
|
switch ($itemconf['type']) {
|
|
case 1: //累积充值
|
|
case 2: //累计消耗
|
|
$itemarray = array(
|
|
'id' => $item['id'],
|
|
'cur' => $item['cur'],
|
|
'target' => $item['target'],
|
|
'award' => $item['time'] > 0 ? 1 : 0,
|
|
);
|
|
break;
|
|
case 3: //每日累积充值
|
|
$itemarray['id'] = $item['id'];
|
|
$itemarray['target'] = $item['target'];
|
|
if ($item['time'] < $daysecs) {
|
|
$itemarray['cur'] = 0;
|
|
$itemarray['award'] = 0;
|
|
$needupdate = true;
|
|
$activity[$itemkey]['cur'] = 0;
|
|
$activity[$itemkey]['award'] = 0;
|
|
} else {
|
|
$itemarray['cur'] = $item['cur'];
|
|
$itemarray['award'] = $item['award'];
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!$found) {
|
|
$itemarray = array(
|
|
'id' => $itemconf['shop_id'],
|
|
'cur' => 0,
|
|
'target' => $itemconf['target'],
|
|
'award' => 0,
|
|
);
|
|
}
|
|
if (
|
|
$itemconf['type'] == 1 ||
|
|
$itemconf['type'] == 3
|
|
) {
|
|
$itemarray['cur'] /= 10;
|
|
$itemarray['target'] /= 10;
|
|
}
|
|
array_push($recharge_activity, $itemarray);
|
|
}
|
|
|
|
if ($needupdate) {
|
|
$conn->execScript(
|
|
'UPDATE recharge SET activity=:activity, modify_time=:modify_time' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':activity' => json_encode($activity),
|
|
':modify_time' => time(),
|
|
)
|
|
);
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'first_recharge' => $firstrecharge,
|
|
'vip_info' => $vipinfo,
|
|
'daily_purchase' => $dailypurchase,
|
|
'recharge_activity' => $recharge_activity,
|
|
'time1' => $time1,
|
|
'time2' => $time2,
|
|
));
|
|
}
|
|
|
|
public function getVipDailyAward()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$rechargerow = $conn->execQueryOne(
|
|
'SELECT vip_info FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
)
|
|
);
|
|
|
|
if ($rechargerow['vip_info'] == null || $rechargerow['vip_info'] == '') {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没月卡');
|
|
return;
|
|
}
|
|
|
|
$vipinfo = json_decode($rechargerow['vip_info'], true);
|
|
$item_list = array();
|
|
$found = false;
|
|
$nowTime = time();
|
|
foreach ($vipinfo as $key => $val) {
|
|
if ($val['id'] == $_REQUEST['id']) {
|
|
if ($val['expire'] > 0 && $val['expire'] < $nowTime) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '月卡过期');
|
|
return;
|
|
}
|
|
|
|
if (phpcommon\getdayseconds($val['daily_time']) >= phpcommon\getdayseconds($nowTime)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '月卡奖励已领');
|
|
return;
|
|
}
|
|
|
|
$privilegecard_conf = metatable\getPrivilegeCardById($_REQUEST['id']);
|
|
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();
|
|
}
|
|
|
|
$itemconf = metatable\getItemById($privilegecard_conf['item_id']);
|
|
if (!$itemconf) {
|
|
error_log('game2004api payNotify privilege card goods config error 2:' + json_encode($_REQUEST));
|
|
echo json_encode(array(
|
|
'errcode' => 4,
|
|
'errmsg' => 'privilege card error 2'
|
|
));
|
|
die();
|
|
}
|
|
|
|
$dropconf = $this->getDrop($itemconf['fuctionindex']);
|
|
if (!$dropconf) {
|
|
error_log('game2004api payNotify privilege card goods config error 3:' + json_encode($_REQUEST));
|
|
echo json_encode(array(
|
|
'errcode' => 4,
|
|
'errmsg' => 'privilege card error 3'
|
|
));
|
|
die();
|
|
}
|
|
|
|
$vipinfo[$key]['daily_time'] = $nowTime;
|
|
$ret = $conn->execScript(
|
|
'UPDATE recharge SET vip_info=:vip_info, modify_time=:modify_time' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':vip_info' => json_encode($vipinfo),
|
|
':modify_time' => time(),
|
|
)
|
|
);
|
|
|
|
if (!$ret) {
|
|
echo json_encode(array(
|
|
'errcode' => 2,
|
|
'errmsg' => '服务器内部错误'
|
|
));
|
|
die();
|
|
}
|
|
|
|
$itemidlist = explode('|', $dropconf['item_id']);
|
|
$itemnumlist = explode('|', $dropconf['num']);
|
|
$addreward = new classes\AddReward();
|
|
$all_item_list = array();
|
|
foreach ($itemidlist as $key => $itemid) {
|
|
array_push($item_list, array(
|
|
'item_id' => $itemid,
|
|
'item_num' => $itemnumlist[$key],
|
|
'time' => 0,
|
|
));
|
|
$items = $addreward->addReward($itemid, $itemnumlist[$key], $account_id, 0, 0);
|
|
foreach ($items as $i) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $i['item_id'],
|
|
'item_num' => $i['item_num'],
|
|
'time' => $i['time'],
|
|
));
|
|
}
|
|
}
|
|
|
|
$found = true;
|
|
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
$adfree = $addreward->getAdfree($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'adfree' => $adfree,
|
|
'id' => $_REQUEST['id'],
|
|
'item_list' => $item_list,
|
|
'vip_info' => json_encode($vipinfo),
|
|
'all_item_list' => $all_item_list,
|
|
));
|
|
}
|
|
}
|
|
|
|
if (!$found) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没月卡 2');
|
|
return;
|
|
}
|
|
}
|
|
|
|
public function getActivityAward()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$rechargerow = $conn->execQueryOne(
|
|
'SELECT activity FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
)
|
|
);
|
|
|
|
if ($rechargerow['activity'] == null || $rechargerow['activity'] == '') {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没参与活动');
|
|
return;
|
|
}
|
|
|
|
$activity = json_decode($rechargerow['activity'], true);
|
|
$item_list = array();
|
|
$found = false;
|
|
$nowTime = time();
|
|
foreach ($activity as $key => $val) {
|
|
if ($val['id'] == $_REQUEST['id']) {
|
|
if ($val['cur'] < $val['target']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没完成');
|
|
return;
|
|
}
|
|
|
|
$activity_conf = metatable\getRechargeActivityById($_REQUEST['id']);
|
|
if (!$activity_conf) {
|
|
error_log('game2004api payNotify recharge activity config error:' + json_encode($_REQUEST));
|
|
echo json_encode(array(
|
|
'errcode' => 4,
|
|
'errmsg' => 'activity error'
|
|
));
|
|
die();
|
|
}
|
|
|
|
if ($activity_conf['type'] == 3) { //每日充值活动
|
|
if ($val['time'] < phpcommon\getdayseconds($nowTime) || $val['award'] != 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '已领');
|
|
return;
|
|
}
|
|
$activity[$key]['award'] = 1;
|
|
} else {
|
|
if ($val['time'] > 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '已领');
|
|
return;
|
|
}
|
|
$activity[$key]['time'] = $nowTime;
|
|
}
|
|
|
|
$ret = $conn->execScript(
|
|
'UPDATE recharge SET activity=:activity, modify_time=:modify_time' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':activity' => json_encode($activity),
|
|
':modify_time' => $nowTime,
|
|
)
|
|
);
|
|
|
|
if (!$ret) {
|
|
echo json_encode(array(
|
|
'errcode' => 2,
|
|
'errmsg' => '服务器内部错误'
|
|
));
|
|
die();
|
|
}
|
|
|
|
$itemidlist = explode('|', $activity_conf['item_id']);
|
|
$itemnumlist = explode('|', $activity_conf['item_num']);
|
|
$addreward = new classes\AddReward();
|
|
$all_item_list = array();
|
|
foreach ($itemidlist as $itemkey => $itemid) {
|
|
array_push($item_list, array(
|
|
'item_id' => $itemid,
|
|
'item_num' => $itemnumlist[$itemkey],
|
|
'time' => 0,
|
|
));
|
|
$items = $addreward->addReward($itemid, $itemnumlist[$itemkey], $account_id, 0, 0);
|
|
foreach ($items as $i) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $i['item_id'],
|
|
'item_num' => $i['item_num'],
|
|
'time' => $i['time'],
|
|
));
|
|
}
|
|
}
|
|
|
|
foreach ($activity as $key => $val) {
|
|
$activity[$key]['award'] = $val['time'] > 0 ? 1 : 0;
|
|
unset($activity[$key]['time']);
|
|
}
|
|
|
|
$found = true;
|
|
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
$adfree = $addreward->getAdfree($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'adfree' => $adfree,
|
|
'id' => $_REQUEST['id'],
|
|
'item_list' => $item_list,
|
|
'recharge_activity' => json_encode($activity),
|
|
'all_item_list' => $all_item_list,
|
|
));
|
|
}
|
|
}
|
|
|
|
if (!$found) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没活动 2');
|
|
return;
|
|
}
|
|
}
|
|
} |