934 lines
35 KiB
PHP
934 lines
35 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
|
|
class ActivityController{
|
|
|
|
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' => 'gamedb2001_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getRedis($shop_uuid)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($shop_uuid));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
protected function getParameter($para_id)
|
|
{
|
|
$parameter_meta_cluster = require('../res/parameter@parameter.php');
|
|
$parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id);
|
|
$p = array(
|
|
'id' => $parameter_meta['id'],
|
|
'name' => $parameter_meta['param_name'],
|
|
'value' => $parameter_meta['param_value'],
|
|
);
|
|
return $p;
|
|
}
|
|
|
|
protected function getDrop($drop_id)
|
|
{
|
|
$drop_meta_table = require('../res/drop@drop.php');
|
|
$drop_meta = getDropConfig($drop_meta_table, $drop_id);
|
|
$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;
|
|
}
|
|
|
|
|
|
protected function getExplode($string)
|
|
{
|
|
$delim = "|";
|
|
$drop_multiply = explode($delim, $string);
|
|
$delim1 = ":";
|
|
$arr = array();
|
|
for ($i = 0; $i < count($drop_multiply); $i++) {
|
|
$mul = explode($delim1, $drop_multiply[$i]);
|
|
array_push($arr, $mul);
|
|
}
|
|
return $arr;
|
|
}
|
|
|
|
protected function getLottery($lot_id)
|
|
{
|
|
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
|
|
$lot_conf = getLotteryConfig($g_conf_lot_cluster, $lot_id);
|
|
$l = array(
|
|
'id' => $lot_conf['id'],
|
|
'item_id' => $lot_conf['item_id'],
|
|
'num' => $lot_conf['num'],
|
|
'weight' => $lot_conf['weight'],
|
|
'quailty' => $lot_conf['quailty'],
|
|
'jilv' => $lot_conf['jilv'],
|
|
);
|
|
return $l;
|
|
}
|
|
|
|
protected function getreward($re_id)
|
|
{
|
|
$g_conf_re_cluster = require('../res/randreward@randreward.php');
|
|
$re_conf = getRandrewardConfig($g_conf_re_cluster, $re_id);
|
|
$re = array(
|
|
'id' => $re_conf['id'],
|
|
'reward' => $re_conf['reward'],
|
|
'number' => $re_conf['number'],
|
|
'weight' => $re_conf['weight'],
|
|
);
|
|
return $re;
|
|
}
|
|
|
|
public function luckDrawInfo()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$draw_uuid = 'game2001api_draw_uuid:' . md5($_REQUEST['account_id']);
|
|
$draw_list = array();
|
|
$r = $this->getRedis($draw_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
//刷新次数
|
|
$p_free = $this->getParameter(FREELOTTERY_TIME);
|
|
$p_video = $this->getParameter(VIDEOLOTTERY_TIME);
|
|
$free_times = $p_free['value'];
|
|
$video_times = $p_video['value'];
|
|
$row = $conn->execQueryOne('SELECT free_times, video_times FROM activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
$ret = $conn->execScript('INSERT INTO activity(accountid, free_times, video_times, item_id, item_num, create_time, modify_time) ' .
|
|
' VALUES(:accountid, 0, 0, 0, 0, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, free_times=0, video_times=0, item_id=0, item_num=0, modify_time=:modify_time;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$free_times = $p_free['value'];
|
|
$video_times = $p_video['value'];
|
|
} else {
|
|
$free_times = $p_free['value'] - $row['free_times'];
|
|
$video_times = $p_video['value'] - $row['video_times'];
|
|
}
|
|
|
|
//道具物品
|
|
$user_db_str = $r->get($draw_uuid);
|
|
if (empty($user_db_str)) {
|
|
$draw_list = $this->randomReward();
|
|
$draw_db = array(
|
|
'draw_uuid' => $draw_uuid,
|
|
'draw_list' => $draw_list,
|
|
);
|
|
$r -> set($draw_uuid, json_encode($draw_db));
|
|
$r -> pexpire($draw_uuid, 1000 * 3600 * 24);
|
|
} else {
|
|
$draw_db = json_decode($user_db_str, true);
|
|
$rowTime = $conn->execQueryOne('SELECT modify_time FROM activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($rowTime['modify_time']) > 0) {
|
|
$draw_list = $this->randomReward();
|
|
$draw_db = array(
|
|
'draw_uuid' => $draw_uuid,
|
|
'draw_list' => $draw_list,
|
|
);
|
|
$r -> set($draw_uuid, json_encode($draw_db));
|
|
$r -> pexpire($draw_uuid, 1000 * 3600 * 24);
|
|
} else {
|
|
$user_db = json_decode($user_db_str, true);
|
|
if (empty($user_db)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
|
|
return;
|
|
}
|
|
foreach ($user_db['draw_list'] as $draw) {
|
|
array_push($draw_list, array(
|
|
'item_id' => $draw['item_id'],
|
|
'item_num' => $draw['item_num'],
|
|
'quailty' => $draw['quailty'],
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'draw_uuid' => $draw_uuid,
|
|
'free_times' => $free_times,
|
|
'video_times' => $video_times,
|
|
'item_list' => $draw_list,
|
|
));
|
|
|
|
}
|
|
|
|
public function getLuckDraw()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT free_times, video_times FROM activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
//随机确认奖励
|
|
$weight_sum = 0;
|
|
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
|
|
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
|
|
$l = $this->getLottery($i);
|
|
$weight_sum += $l['jilv'];
|
|
}
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
$key = 0;
|
|
for ($ii = 1; $ii <= count($g_conf_lot_cluster); $ii++) {
|
|
$l = $this->getLottery($ii);
|
|
$weight += $l['jilv'];
|
|
if ($weight > $random) {
|
|
$key = $ii;
|
|
break;
|
|
}
|
|
}
|
|
$draw_uuid = $_REQUEST['draw_uuid'];
|
|
$item_id = 0;
|
|
$item_num = 0;
|
|
$flag = 0;
|
|
$r = $this->getRedis($draw_uuid);
|
|
$user_db_str = $r->get($draw_uuid);
|
|
if (empty($user_db_str)) {
|
|
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失效');
|
|
return;
|
|
}
|
|
foreach ($user_db['draw_list'] as $draw) {
|
|
if ($draw['key'] == $key - 1) {
|
|
$item_id = $draw['item_id'];
|
|
$item_num = $draw['item_num'];
|
|
$flag = 1;
|
|
break;
|
|
}
|
|
}
|
|
if ($flag == 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品');
|
|
return;
|
|
}
|
|
|
|
if ($_REQUEST['type'] == 0) {
|
|
$p_flush = $this->getParameter(FREELOTTERY_TIME);
|
|
if ($p_flush['value'] <= $row['free_times']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE activity SET free_times=:free_times, item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':free_times' => $row['free_times'] + 1,
|
|
':item_id' => $item_id,
|
|
':item_num' => $item_num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if ($_REQUEST['type'] == 1) {
|
|
$p_flush = $this->getParameter(VIDEOLOTTERY_TIME);
|
|
if ($p_flush['value'] <= $row['video_times']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE activity SET video_times=:video_times,item_id=:item_id, item_num=:item_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':video_times' => $row['video_times'] + 1,
|
|
':item_id' => $item_id,
|
|
':item_num' => $item_num,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item_id, $item_num, $account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
));
|
|
}
|
|
|
|
public function doubleLuckDraw()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT item_id, item_num FROM activity WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
//增加奖励
|
|
$p = $this->getParameter(REWARD_TIMES);
|
|
$times = $p['value'] - 1;
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($row['item_id'], $row['item_num'] * $times, $account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
protected function randomReward()
|
|
{
|
|
$draw_list = array();
|
|
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
|
|
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
|
|
$item_id = 0;
|
|
$item_num = 0;
|
|
$key = 0;
|
|
$l = $this->getLottery($i);
|
|
//确定商品id和数量
|
|
$weight_sum = 0;
|
|
$weight_array = $this->getExplode($l['weight']);
|
|
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
|
$weight_sum += $weight_array[$ii][0];
|
|
}
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
|
$weight += $weight_array[$ii][0];
|
|
if ($weight > $random) {
|
|
$key = $ii;
|
|
break;
|
|
}
|
|
}
|
|
$item_id_array = $this->getExplode($l['item_id']);
|
|
$num_array = $this->getExplode($l['num']);
|
|
$quailty_array = $this->getExplode($l['quailty']);
|
|
$item_id = $item_id_array[$key][0];
|
|
$item_num = $num_array[$key][0];
|
|
$quailty = $quailty_array[$key][0];
|
|
array_push($draw_list, array(
|
|
'key' => $i - 1,
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'quailty' => $quailty,
|
|
));
|
|
}
|
|
return $draw_list;
|
|
}
|
|
|
|
public function randRewardInfo()
|
|
{
|
|
$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;
|
|
}
|
|
|
|
$randreward_uuid = 'game2001api_randreward_uuid:' . md5($_REQUEST['account_id']);
|
|
$randreward_list = array();
|
|
$r = $this->getRedis($randreward_uuid);
|
|
$user_db_str = $r->get($randreward_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
if (empty($user_db_str)) {
|
|
$randreward_list = $this->getRandomReward();
|
|
$randreward_db = array(
|
|
'randreward_uuid' => $randreward_uuid,
|
|
'randreward_list' => $randreward_list,
|
|
);
|
|
$r -> set($randreward_uuid, json_encode($randreward_db));
|
|
$r -> pexpire($randreward_uuid, 1000 * 7200);
|
|
} else {
|
|
$randreward_list = $this->getRandomReward();
|
|
$randreward_db = array(
|
|
'randreward_uuid' => $randreward_uuid,
|
|
'randreward_list' => $randreward_list,
|
|
);
|
|
$r -> set($randreward_uuid, json_encode($randreward_db));
|
|
$r -> pexpire($randreward_uuid, 1000 * 7200);
|
|
}
|
|
$r = $this->getRedis($randreward_uuid);
|
|
$user_db_str = $r->get($randreward_uuid);
|
|
$user_db = json_decode($user_db_str, true);
|
|
foreach ($user_db['randreward_list'] as $randreward) {
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($randreward['item_id'], $randreward['item_num'], $account_id);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'randreward_uuid' => $randreward_uuid,
|
|
'item_list' => $randreward_list,
|
|
));
|
|
}
|
|
|
|
public function doubleRandReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$randreward_uuid = $_REQUEST['randreward_uuid'];
|
|
$r = $this->getRedis($randreward_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
$user_db_str = $r->get($randreward_uuid);
|
|
if (empty($user_db_str)) {
|
|
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失效');
|
|
return;
|
|
}
|
|
$p = $this->getParameter(REWARD_TIMES);
|
|
$times = $p['value'] - 1;
|
|
foreach ($user_db['randreward_list'] as $randreward) {
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($randreward['item_id'], $randreward['item_num'] * $times, $account_id);
|
|
}
|
|
$r->del($randreward_uuid, json_encode($user_db));
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
protected function getRandomReward()
|
|
{
|
|
$randreward_list = array();
|
|
$g_conf_re_cluster = require('../res/randreward@randreward.php');
|
|
for ($i = 1; $i <= count($g_conf_re_cluster); $i++) {
|
|
$item_id = 0;
|
|
$item_num = 0;
|
|
$key = 0;
|
|
$re = $this->getreward($i);
|
|
//确定商品id和数量
|
|
$weight_sum = 0;
|
|
$weight_array = $this->getExplode($re['weight']);
|
|
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
|
$weight_sum += $weight_array[$ii][0];
|
|
}
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($ii = 0; $ii < count($weight_array); $ii++) {
|
|
$weight += $weight_array[$ii][0];
|
|
if ($weight > $random) {
|
|
$key = $ii;
|
|
break;
|
|
}
|
|
}
|
|
$item_id_array = $this->getExplode($re['reward']);
|
|
$num_array = $this->getExplode($re['number']);
|
|
$item_id = $item_id_array[$key][0];
|
|
$item_num = $num_array[$key][0];
|
|
array_push($randreward_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
));
|
|
}
|
|
return $randreward_list;
|
|
}
|
|
|
|
public function airDropBoxReward()
|
|
{
|
|
$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 + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT box_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
if ($row['box_num'] <= 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '今日开箱子次数已用完');
|
|
return;
|
|
}
|
|
$airReward_uuid = 'game2001api_airReward_uuid:' . md5($_REQUEST['account_id']);
|
|
$airReward_list = array();
|
|
$r = $this->getRedis($airReward_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
$user_db_str = $r->get($airReward_uuid);
|
|
$airReward_num = 0;
|
|
$last_time = 0;
|
|
if (empty($user_db_str)) {
|
|
$airReward_list = $this->getRandomAirReward(24106);
|
|
$airReward_db = array(
|
|
'airReward_uuid' => $airReward_uuid,
|
|
'airReward_list' => $airReward_list,
|
|
);
|
|
$r -> set($airReward_uuid, json_encode($airReward_db));
|
|
$r -> pexpire($airReward_uuid, 1000 * 7200);
|
|
} else {
|
|
$user_db = json_decode($user_db_str, true);
|
|
unset($user_db['airReward_list']);
|
|
$airReward_list = $this->getRandomAirReward(24106);
|
|
$airReward_db = array(
|
|
'airReward_uuid' => $airReward_uuid,
|
|
'airReward_list' => $airReward_list,
|
|
);
|
|
$r -> set($airReward_uuid, json_encode($airReward_db));
|
|
$r -> pexpire($airReward_uuid, 1000 * 7200);
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET box_num=:box_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':box_num' => $row['box_num'] - 1,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
foreach ($airReward_list as $airReward) {
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($airReward['item_id'], $airReward['item_num'], $account_id);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'item_list' => $airReward_list
|
|
));
|
|
}
|
|
|
|
|
|
public function airDoubleReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$airReward_uuid = 'game2001api_airReward_uuid:' . md5($_REQUEST['account_id']);
|
|
$airReward_list = array();
|
|
$r = $this->getRedis($airReward_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
$user_db_str = $r->get($airReward_uuid);
|
|
if (empty($user_db_str)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2,'session失效');
|
|
return;
|
|
}
|
|
$user_db = json_decode($user_db_str, true);
|
|
if (empty($user_db)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3,'session失效');
|
|
return;
|
|
}
|
|
$p = $this->getParameter(REWARD_TIMES);
|
|
$times = $p['value'] - 1;
|
|
foreach ($user_db['airReward_list'] as $airReward) {
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($airReward['item_id'], $airReward['item_num'] * $times, $account_id);
|
|
}
|
|
$r->del($airReward_uuid, json_encode($user_db));
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
|
|
protected function getRandomAirReward($drop_id)
|
|
{
|
|
$airReward_list = array();
|
|
//随机奖励
|
|
$d = $this->getDrop($drop_id);
|
|
if (!$d) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
die();
|
|
}
|
|
$item_id_array = $this->getExplode($d['item_id']);
|
|
$item_num_array = $this->getExplode($d['num']);
|
|
$weight_array = $this->getExplode($d['weight']);
|
|
if ($d['type'] == 2) {
|
|
$weight_sum = 0;
|
|
$keys = 0;
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$weight_sum += $weight_array[$i][0];
|
|
}
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$weight += $weight_array[$i][0];
|
|
if ($weight > $random) {
|
|
$keys = $i;
|
|
break;
|
|
}
|
|
}
|
|
$item_id = $item_id_array[$keys][0];
|
|
$item_num = $item_num_array[$keys][0];
|
|
array_push($airReward_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
));
|
|
}
|
|
if ($d['type'] == 1) {
|
|
for ($i = 0; $i < count($weight_array); $i++) {
|
|
$random = Rand(0, 10000);
|
|
if ($weight_array[$i][0] < $random) {
|
|
continue;
|
|
}
|
|
array_push($airReward_list, array(
|
|
'item_id' => $item_id_array[$keys][0],
|
|
'item_num' => $item_num_array[$keys][0],
|
|
));
|
|
}
|
|
}
|
|
return $airReward_list;
|
|
}
|
|
|
|
public function getRedBag()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$p = array();
|
|
$type = $_REQUEST['type'];
|
|
$item_list = array();
|
|
//随机奖励
|
|
if ($type == 1) {
|
|
$item_list = $this->getRandomAirReward(24006);
|
|
$p = $this->getParameter(REDLIMIT);
|
|
}
|
|
if ($type == 2) {
|
|
$item_list = $this->getRandomAirReward(24007);
|
|
$p = $this->getParameter(73);
|
|
}
|
|
$limit = $p['value'];
|
|
foreach ($item_list as $item) {
|
|
if ($item['item_id'] != 10004 ) {
|
|
//增加奖励
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item['item_id'], $item['item_num'], $account_id);
|
|
} else {
|
|
//判断今日红包是否领完
|
|
$red_conn = $this->getRedMysql();
|
|
$row = $red_conn->execQueryOne('SELECT red_sum FROM redpack ' .
|
|
' WHERE red_type=:red_type AND red_date=:red_date;',
|
|
array(
|
|
':red_type' => $type,
|
|
':red_date' => phpcommon\getdayseconds(time())
|
|
));
|
|
if ($row['red_sum'] + $item['item_num'] > $limit) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '今日红包已领完');
|
|
return;
|
|
}
|
|
//红包领取现金
|
|
$this->getRedPack($item['item_num'] * 100, $account_id);
|
|
//更新红包数据
|
|
$this->updateRedPack($item['item_num'], $type);
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list
|
|
));
|
|
}
|
|
|
|
protected function getRedMysql()
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32(''));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => 'gamedb2001_' . 1
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getPayMysql($accountid)
|
|
{
|
|
$mysql_conf = getMysqlConfig(crc32($accountid));
|
|
$conn = new phpcommon\Mysql(array(
|
|
'host' => $mysql_conf['host'],
|
|
'port' => $mysql_conf['port'],
|
|
'user' => $mysql_conf['user'],
|
|
'passwd' => $mysql_conf['passwd'],
|
|
'dbname' => 'paydb'
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
//redpack201908191405_xxxxx
|
|
protected function getOrderId($accountid)
|
|
{
|
|
$conn = $this->getPayMysql($accountid);
|
|
$orderid_pre = 'redpack' . strftime('%y%m%d%H%M%S');
|
|
$ret = $conn->execScript("INSERT INTO orderidx(createtime) VALUES(:createtime);",
|
|
array(
|
|
'createtime' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne('SELECT LAST_INSERT_ID();', array());
|
|
if (empty($row)) {
|
|
die();
|
|
}
|
|
$orderid = $orderid_pre . 'idx' . $row[0];
|
|
return $orderid;
|
|
}
|
|
|
|
//红包提现
|
|
protected function getRedPack($amount, $account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$row = $conn->execQueryOne('SELECT user_name FROM user ' .
|
|
' WHERE accountid=:accountid ;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
die();
|
|
}
|
|
$mch_appid = '';
|
|
$appid_url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$appid_url = 'https://login.kingsome.cn/webapp/index.php?c=SdkService&a=getAppId&';
|
|
} else {
|
|
$appid_url = 'https://login-test.kingsome.cn/webapp/index.php?c=SdkService&a=getAppId&';
|
|
}
|
|
$params['account_id'] = $account_id;
|
|
$app_response = '';
|
|
if (!phpcommon\HttpClient::get($appid_url, $params, $app_response)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
die();
|
|
}
|
|
$app_data = json_decode($app_response, true);
|
|
$mch_appid = $app_data['appid'];
|
|
$openid = phpcommon\extractOpenId($account_id);
|
|
$re_user_name = $row['user_name'];
|
|
$url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$url = 'https://cloud.kingsome.cn/webapp/index.php?c=Config&a=read&';
|
|
} else {
|
|
$url = 'https://cloud-test.kingsome.cn/webapp/index.php?c=Config&a=read&';
|
|
}
|
|
|
|
$params['gameid'] = phpcommon\extractGameId($account_id);
|
|
$params['channel'] = phpcommon\extractChannel($account_id);
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
die();
|
|
}
|
|
$desc = '';
|
|
$data = json_decode($response, true);
|
|
$data_list = json_decode($data['KVList'], true);
|
|
foreach ($data_list as $d) {
|
|
if ($d['key'] == 'red_env_tip') {
|
|
$desc = $d['value'];
|
|
break;
|
|
}
|
|
}
|
|
$partner_trade_no = $this->getOrderId($account_id);
|
|
$url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$url = 'https://service.kingsome.cn/webapp/index.php?c=RedPack&a=sendRedPack&';
|
|
} else {
|
|
$url = 'https://service-test.kingsome.cn/webapp/index.php?c=RedPack&a=sendRedPack&';
|
|
}
|
|
|
|
$param['mch_appid'] = $mch_appid;
|
|
$param['partner_trade_no'] = $partner_trade_no;
|
|
$param['openid'] = $openid;
|
|
$param['re_user_name'] = $re_user_name;
|
|
$param['amount'] = $amount;
|
|
$param['desc'] = $desc;
|
|
$param['account_id'] = $account_id;
|
|
$res = '';
|
|
if (!phpcommon\HttpClient::get($url, $param, $res)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
die();
|
|
}
|
|
$data = json_decode($res, true);
|
|
if ($data['errcode'] != 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '领取失败');
|
|
die();
|
|
}
|
|
//插入日志信息
|
|
$ret = $conn->execScript('INSERT INTO redpack_log(accountid, order_id, get_time, custom_data, createtime, modifytime, coin_num) ' .
|
|
' VALUES(:accountid, :order_id, :get_time, :custom_data, :createtime, :modifytime, :coin_num);',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':order_id' => $partner_trade_no,
|
|
':get_time' => time(),
|
|
':custom_data' => $res,
|
|
':coin_num' => $amount,
|
|
':createtime' => time(),
|
|
':modifytime' => time()
|
|
));
|
|
}
|
|
|
|
//更新今日红包数据
|
|
protected function updateRedPack($item_num, $type)
|
|
{
|
|
$sum = 0;
|
|
$red_conn = $this->getRedMysql();
|
|
$row = $red_conn->execQueryOne('SELECT red_sum FROM redpack ' .
|
|
' WHERE red_type=:red_type AND red_date=:red_date;',
|
|
array(
|
|
':red_type' => $type,
|
|
':red_date' => phpcommon\getdayseconds(time())
|
|
));
|
|
if (!$row) {
|
|
$ret = $red_conn->execScript('INSERT INTO redpack(red_type, red_sum, red_date, create_time, modify_time) ' .
|
|
' VALUES(:red_type, :red_sum, :red_date, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE red_type=1, red_sum=:red_sum, red_date=:red_date, modify_time=:modify_time;',
|
|
array(
|
|
':red_sum' => $item_num,
|
|
':create_time' => time(),
|
|
':red_type' => $type,
|
|
':red_date' => phpcommon\getdayseconds(time()),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
} else {
|
|
$sum = $row['red_sum'] + $item_num;
|
|
$ret = $red_conn->execScript('UPDATE redpack set red_sum=:red_sum, modify_time=:modify_time ' .
|
|
' WHERE red_type=:red_type AND red_date=:red_date;',
|
|
array(
|
|
':red_sum' => $sum,
|
|
':red_type' => $type,
|
|
':red_date' => phpcommon\getdayseconds(time()),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|