get activity award & vip daily award
This commit is contained in:
parent
9a149a1950
commit
527571146c
@ -4,6 +4,8 @@ require 'classes/Quest.php';
|
||||
require 'classes/AddReward.php';
|
||||
require_once 'metatable/shopGoods.php';
|
||||
require_once 'metatable/privilegecard.php';
|
||||
require_once 'metatable/rechargeActivity.php';
|
||||
require_once 'metatable/item.php';
|
||||
|
||||
class RechargeController
|
||||
{
|
||||
@ -342,7 +344,7 @@ class RechargeController
|
||||
}
|
||||
|
||||
$ret = $conn->execScript(
|
||||
'UPDATE recharge SET daily_purchase=:daily_purchase, modify_time=:modify_time' .
|
||||
'UPDATE recharge SET vip_info=:vip_info, modify_time=:modify_time' .
|
||||
' WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id,
|
||||
@ -358,7 +360,7 @@ class RechargeController
|
||||
$value['itemnum'] = (float)$value['itemnum'];
|
||||
}
|
||||
error_log(json_encode($item_list));
|
||||
|
||||
|
||||
//update daily purchase
|
||||
if (!$rechargerow) {
|
||||
$daily_purchase = array();
|
||||
@ -494,19 +496,329 @@ class RechargeController
|
||||
);
|
||||
|
||||
$firstrecharge = '';
|
||||
$vipinfo = array();
|
||||
$dailypurchase = array();
|
||||
if ($rechargerow) {
|
||||
$firstrecharge = $rechargerow['first_data'];
|
||||
if ($rechargerow['vip_info'] != null && $rechargerow['vip_info'] != '') {
|
||||
$vipinfo = json_encode($rechargerow['vip_info']);
|
||||
}
|
||||
|
||||
if ($rechargerow['daily_purchase'] != null && $rechargerow['daily_purchase'] != '') {
|
||||
$dailypurchase = json_encode($rechargerow['daily_purchase']);
|
||||
}
|
||||
}
|
||||
|
||||
$activityconf = metatable\getRechargeActivityConf();
|
||||
$recharge_activity = array();
|
||||
if ($rechargerow['activity'] != null && $rechargerow['activity'] != '') {
|
||||
$activity = json_decode($rechargerow['activity']);
|
||||
$needupdate = false;
|
||||
foreach ($activity as $key => $item) {
|
||||
$itemconf = $activityconf[$item['id']];
|
||||
if (time() < strtotime($itemconf['time1']) || time() > strtotime($itemconf['time2'])) {
|
||||
continue;
|
||||
}
|
||||
$itemarray = array(
|
||||
'id' => $item['id'],
|
||||
'cur' => $item['cur'],
|
||||
'target' => $item['target'],
|
||||
'award' => ($item['time'] > 0 ? 1 : 0),
|
||||
);
|
||||
|
||||
switch ($itemconf['type']) {
|
||||
case 1: //累积充值
|
||||
case 2: //累计消耗
|
||||
array_push($recharge_activity, $itemarray);
|
||||
break;
|
||||
case 3: //每日累积充值
|
||||
$daysecs = phpcommon\getdayseconds(time());
|
||||
if ($item['time'] < $daysecs) {
|
||||
$itemarray['cur'] = 0;
|
||||
$itemarray['award'] = 0;
|
||||
$needupdate = true;
|
||||
$activity[$key]['cur'] = 0;
|
||||
$activity[$key]['award'] = 0;
|
||||
} else {
|
||||
$itemarray['award'] = $item['award'];
|
||||
}
|
||||
array_push($recharge_activity, $itemarray);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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' => array(),
|
||||
'daily_purchase' => array(),
|
||||
'daily_recharge' => array(),
|
||||
'total_recharge' => array(),
|
||||
'total_consume' => array(),
|
||||
'vip_info' => $vipinfo,
|
||||
'daily_purchase' => $dailypurchase,
|
||||
'recharge_activity' => $recharge_activity,
|
||||
));
|
||||
}
|
||||
|
||||
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']);
|
||||
$item_list = array();
|
||||
$found = false;
|
||||
$nowTime = time();
|
||||
foreach ($vipinfo as $key => $val) {
|
||||
if ($val['id'] == $_REQUEST['id']) {
|
||||
if ($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();
|
||||
foreach ($itemidlist as $index => $itemid) {
|
||||
array_push($item_list, array(
|
||||
'item_id' => $itemid,
|
||||
'item_num' => $itemnumlist[$key],
|
||||
'time' => 0,
|
||||
));
|
||||
$addreward->addReward($itemid, $itemnumlist[$key], $account_id, 0, 0);
|
||||
}
|
||||
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没月卡 2');
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
'coin_nums' => 0,
|
||||
'diamond_nums' => 0,
|
||||
'item_list' => $item_list,
|
||||
'vip_info' => json_encode($vipinfo),
|
||||
));
|
||||
}
|
||||
|
||||
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']);
|
||||
$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();
|
||||
foreach ($itemidlist as $index => $itemid) {
|
||||
array_push($item_list, array(
|
||||
'item_id' => $itemid,
|
||||
'item_num' => $itemnumlist[$key],
|
||||
'time' => 0,
|
||||
));
|
||||
$addreward->addReward($itemid, $itemnumlist[$key], $account_id, 0, 0);
|
||||
}
|
||||
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$found) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没活动 2');
|
||||
return;
|
||||
}
|
||||
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
'coin_nums' => 0,
|
||||
'diamond_nums' => 0,
|
||||
'item_list' => $item_list,
|
||||
'recharge_activity' => json_encode($activity),
|
||||
));
|
||||
}
|
||||
|
||||
protected function getDrop($drop_id)
|
||||
{
|
||||
$drop_meta_table = require('../res/drop@drop.php');
|
||||
$drop_meta = getDropConfig($drop_meta_table, $drop_id);
|
||||
if (!$drop_meta) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$d = array(
|
||||
'drop_id' => $drop_meta['drop_id'],
|
||||
'item_id' => $drop_meta['item_id'],
|
||||
'num' => $drop_meta['num'],
|
||||
'weight' => $drop_meta['weight'],
|
||||
'type' => $drop_meta['type']
|
||||
);
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ function getItemConf()
|
||||
return _internalGetItemConf();
|
||||
}
|
||||
|
||||
function getItemById($param_id)
|
||||
function getItemById($item_id)
|
||||
{
|
||||
$conf = getItemConf();
|
||||
$item_id = (int)$item_id;
|
||||
|
36
webapp/metatable/rechargeActivity.php
Normal file
36
webapp/metatable/rechargeActivity.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace metatable;
|
||||
|
||||
/*
|
||||
配置表规范
|
||||
getXXXConf:获取表所有数据
|
||||
getXxxById():通过id获取单个数据
|
||||
_internalGetXXXConf:获取表所有数据内部实现不对外开放
|
||||
|
||||
使用方式
|
||||
require_once 'metatable/XXXX.php';
|
||||
|
||||
!!!注意必须使用require_once
|
||||
*/
|
||||
|
||||
function getRechargeActivityConf()
|
||||
{
|
||||
return _internalGetRechargeActivityConf();
|
||||
}
|
||||
|
||||
function getRechargeActivityById($shop_id)
|
||||
{
|
||||
$conf = getRechargeActivityConf();
|
||||
$shop_id = (int)$shop_id;
|
||||
return array_key_exists($shop_id, $conf) ? $conf[$shop_id] : null;
|
||||
}
|
||||
|
||||
function _internalGetRechargeActivityConf()
|
||||
{
|
||||
global $g_rechargeActivity_table;
|
||||
if (!$g_rechargeActivity_table) {
|
||||
$g_rechargeActivity_table = require(getConfigBaseDir() . 'rechargeactivity@rechargeactivity.php');
|
||||
}
|
||||
return $g_rechargeActivity_table;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user