575 lines
21 KiB
PHP
575 lines
21 KiB
PHP
<?php
|
|
|
|
trait RechargeActivity
|
|
{
|
|
protected function getFirstPurchaseActivity($shopid)
|
|
{
|
|
$conf = require('../res/firstchargeactivity@firstchargeactivity.php');
|
|
return array_key_exists($shopid, $conf) ? $conf[$shopid] : null;
|
|
}
|
|
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());
|
|
$firstpurchase = (object)array();
|
|
if ($rechargerow) {
|
|
if (!is_null($rechargerow['first_data'])) {
|
|
$firstrecharge = $rechargerow['first_data'];
|
|
}
|
|
if (!is_null($rechargerow['vip_info']) && !empty($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 (!is_null($rechargerow['daily_purchase']) && !empty($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;
|
|
}
|
|
|
|
if (!is_null($rechargerow['first_purchase']) && !empty($rechargerow['first_purchase'])) {
|
|
$firstpurchase = json_decode($rechargerow['first_purchase']);
|
|
}
|
|
}
|
|
|
|
$activityconf = metatable\getRechargeActivityConf();
|
|
$recharge_activity = array();
|
|
$activity = array();
|
|
if (!is_null($rechargerow['activity']) && $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: //累计消耗
|
|
case 4: //充值达标天数
|
|
$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,
|
|
'first_purchase' => $firstpurchase,
|
|
));
|
|
}
|
|
|
|
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 (is_null($rechargerow['vip_info']) || empty($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 (is_null($rechargerow['activity']) || empty($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;
|
|
}
|
|
}
|
|
|
|
public function getFirstPurchaseAward()
|
|
{
|
|
$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 first_purchase FROM recharge WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
)
|
|
);
|
|
|
|
if (is_null($rechargerow['first_purchase']) || empty($rechargerow['first_purchase'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没购买');
|
|
return;
|
|
}
|
|
|
|
$activitycfg = $this->getFirstPurchaseActivity($_REQUEST['id']);
|
|
if (!$activitycfg) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没购买 1');
|
|
return;
|
|
}
|
|
|
|
$firstpurchaseinfo = json_decode($rechargerow['first_purchase'], true);
|
|
$infokey = 'shop_' . $_REQUEST['id'];
|
|
if (!array_key_exists($infokey, $firstpurchaseinfo)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没购买 2');
|
|
return;
|
|
}
|
|
|
|
$getcount = $firstpurchaseinfo[$infokey]['count'] + 1;
|
|
$awardkey = 'item_' . $getcount;
|
|
if (!array_key_exists($awardkey, $activitycfg)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '已领完');
|
|
return;
|
|
}
|
|
|
|
$nowtime = time();
|
|
if (phpcommon\getdayseconds($nowtime) == phpcommon\getdayseconds($firstpurchaseinfo[$infokey]['time'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '今日已领');
|
|
return;
|
|
}
|
|
|
|
$firstpurchaseinfo[$infokey]['time'] = $nowtime;
|
|
$firstpurchaseinfo[$infokey]['count'] = $getcount;
|
|
$ret = $conn->execScript(
|
|
'UPDATE recharge SET first_purchase=:first_purchase, modify_time=:modify_time' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':first_purchase' => json_encode($firstpurchaseinfo),
|
|
':modify_time' => $nowtime
|
|
)
|
|
);
|
|
|
|
if (!$ret) {
|
|
phpcommon\sendError(ERR_RETRY + 1, '系统繁忙');
|
|
return;
|
|
}
|
|
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
$firstpurchaseawards = explode('|', $activitycfg[$awardkey]);
|
|
$addreward = new classes\AddReward();
|
|
foreach ($firstpurchaseawards as $awarditem) {
|
|
$itemstrs = explode(':', $awarditem);
|
|
if (count($itemstrs) < 2) {
|
|
continue;
|
|
}
|
|
$item_list[] = array(
|
|
"item_id" => $itemstrs[0],
|
|
"item_num" => $itemstrs[1],
|
|
"time" => 0,
|
|
);
|
|
$items = $addreward->addReward($itemstrs[0], $itemstrs[1], $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'],
|
|
));
|
|
}
|
|
}
|
|
|
|
$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,
|
|
'all_item_list' => $all_item_list,
|
|
'first_purchase' => $firstpurchaseinfo,
|
|
));
|
|
}
|
|
}
|