first purchase

This commit is contained in:
yangduo 2025-03-16 22:49:29 +08:00
parent fdc7b7f814
commit 40d4bfb057
4 changed files with 180 additions and 13 deletions

View File

@ -349,6 +349,7 @@ CREATE TABLE `recharge` (
`adfree` int(11) NOT NULL DEFAULT '0' COMMENT '免广告券',
`recharge_diamond` int(11) NOT NULL DEFAULT '0' COMMENT '累计充值钻石',
`present_diamond` int(11) NOT NULL DEFAULT '0' COMMENT '充值赠送钻石总量',
`first_purchase` mediumblob COMMENT '首充活动信息',
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),

View File

@ -2,6 +2,11 @@
trait RechargeActivity
{
protected function getFirstPurchaseActivity($shopid)
{
$conf = require('../res/firstchargeactivity@firstchargeactivity.php');
return array_key_exists($level, $conf) ? $conf[$level] : null;
}
public function activityInfo()
{
$account_id = $_REQUEST['account_id'];
@ -28,11 +33,12 @@ trait RechargeActivity
$vipinfo = array();
$dailypurchase = array();
$daysecs = phpcommon\getdayseconds(time());
$firstpurchase = array();
if ($rechargerow) {
if ($rechargerow['first_data'] != null) {
if (!is_null($rechargerow['first_data'])) {
$firstrecharge = $rechargerow['first_data'];
}
if ($rechargerow['vip_info'] != null && $rechargerow['vip_info'] != '') {
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;
@ -40,7 +46,7 @@ trait RechargeActivity
}
}
if ($rechargerow['daily_purchase'] != null && $rechargerow['daily_purchase'] != '') {
if (!is_null($rechargerow['daily_purchase']) && !empty($rechargerow['daily_purchase'])) {
$dailypurchase = json_decode($rechargerow['daily_purchase'], true);
$packtime = 0;
foreach ($dailypurchase as $key => $val) {
@ -89,12 +95,16 @@ trait RechargeActivity
}
$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 ($rechargerow['activity'] != null && $rechargerow['activity'] != '') {
if (!is_null($rechargerow['activity']) && $rechargerow['activity'] != '') {
$activity = json_decode($rechargerow['activity'], true);
}
$needupdate = false;
@ -180,6 +190,7 @@ trait RechargeActivity
'recharge_activity' => $recharge_activity,
'time1' => $time1,
'time2' => $time2,
'first_purchase' => $firstpurchase,
));
}
@ -449,4 +460,114 @@ trait RechargeActivity
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' => json_encode($firstpurchaseinfo),
));
}
}

View File

@ -57,7 +57,7 @@ class RechargeController
if (!$this->checkPurchaseLimit($conn, $account_id, $goods_id)) {
phpcommon\sendError(ERR_USER_BASE + 2, '不能购买');
return;
}
}
$url = '';
if (SERVER_ENV == _ONLINE) {
@ -253,11 +253,13 @@ class RechargeController
));
}
public function preparePay() {
public function preparePay()
{
$this->prePay();
}
public function preparePayDone() {
public function preparePayDone()
{
$this->purchaseDone();
}
@ -494,7 +496,11 @@ class RechargeController
if (
$shopgoods['type'] != 1 && //钻石
$shopgoods['type'] != 2 && //特惠礼包
$shopgoods['type'] != 3 //月卡
$shopgoods['type'] != 3 && //月卡
$shopgoods['type'] != 5 && //等级基金
$shopgoods['type'] != 6 && //首充
$shopgoods['type'] != 7 && //关卡基金
$shopgoods['type'] != 8 //体力基金
) {
error_log('game2004api payNotify goods type error:' + json_encode($_REQUEST));
echo json_encode(array(
@ -563,7 +569,7 @@ class RechargeController
$rechargeactivity = new classes\RechargeActivity();
$activity = array();
if ($rechargerow && $rechargerow['activity'] != null && $rechargerow['activity'] != '') {
if ($rechargerow && !is_null($rechargerow['activity']) && !empty($rechargerow['activity'])) {
$activity = json_decode($rechargerow['activity'], true);
}
$rechargeactivity->updateActivityCur($activity, $shopgoods['price'] * 10, true);
@ -716,7 +722,7 @@ class RechargeController
)
);
}
} else {
} else if ($shopgoods['type'] == 2) {
$itemconf = metatable\getItemById($shopgoods['item_id']);
if (!$itemconf) {
error_log('game2004api purchaseNotify daily goods config error:' . json_encode($_REQUEST));
@ -807,6 +813,45 @@ class RechargeController
)
);
}
} else if ($shopgoods['type'] == 6) {
$purchasekey = 'shop_' . $goodsid;
$purchaseinfo = array(
'count' => 0,
'time' => 0,
);
if (!$rechargerow) {
$first_purchase = array(
$purchasekey => $purchaseinfo,
);
$conn->execScript(
'INSERT INTO recharge(accountid, first_purchase, activity, create_time, modify_time) ' .
' VALUES(:account_id, :first_purchase, :activity, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:account_id, first_purchase=:first_purchase, activity=:activity, modify_time=:modify_time;',
array(
':account_id' => $account_id,
':first_purchase' => json_encode($first_purchase),
':activity' => json_encode($activity),
':create_time' => time(),
':modify_time' => time()
)
);
} else {
$first_purchase = array();
if (!is_null($rechargerow['first_purchase']) && !empty($rechargerow['first_purchase'])) {
$first_purchase = json_decode($rechargerow['first_purchase'], true);
}
$first_purchase[$purchasekey] = $purchaseinfo;
$conn->execScript(
'UPDATE recharge SET first_purchase=:first_purchase, activity=:activity, modify_time=:modify_time' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':first_purchase' => json_encode($first_purchase),
':activity' => json_encode($activity),
':modify_time' => time()
)
);
}
}
echo json_encode(array(

View File

@ -535,7 +535,7 @@ class SoloController
if ($reqfinished) {
$finishedawards = explode($reqlevelcfg['winreward'], '|');
foreach ($finishedawards as $finishitem) {
$itemstrs = explode($finishitem, '|');
$itemstrs = explode($finishitem, ':');
if (count($itemstrs) < 2) {
continue;
}
@ -588,7 +588,7 @@ class SoloController
if ($curlvcfg) {
$uplvawards = explode($curlvcfg['level_reward'], '|');
foreach ($uplvawards as $uplvitem) {
$itemstrs = explode($uplvitem, '|');
$itemstrs = explode($uplvitem, ':');
if (count($itemstrs) < 2) {
continue;
}