game2004api/webapp/controller/ActivityController.class.php

1541 lines
56 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' => DBNAME_PREFIX . $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 getBox($box_id)
{
$box_meta_table = require('../res/box@box.php');
$box_meta = getBoxConfig($box_meta_table, $box_id);
$b = array(
'box_id' => $box_meta['box_type'],
'item_id' => $box_meta['item_id'],
'num' => $box_meta['num'],
'weight' => $box_meta['weight'],
'type' => $box_meta['type'],
'time' => $box_meta['time'],
);
return $b;
}
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'],
'time' => $lot_conf['time'],
'day' => $lot_conf['day'],
);
return $l;
}
protected function getItem($item_id)
{
$g_conf_item_cluster = require('../res/item@item.php');
$item_conf = getItemConfig($g_conf_item_cluster, $item_id);
$it = array(
'id' => $item_conf['id'],
'diamond' => $item_conf['diamond'],
'type' => $item_conf['fuction'],
'diamond_hour' => $item_conf['diamond_hour'],
'pool_weight' => $item_conf['pool_weight'],
);
return $it;
}
protected function getDrawTableConfig($id)
{
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
$lot_conf = getLotteryConfig($g_conf_lot_cluster, $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'],
'time' => $lot_conf['time'],
);
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;
}
protected function getRecommend($rec_id)
{
$g_conf_rec_cluster = require('../res/recommend@recommend.php');
$rec_conf = getRecommendConfig($g_conf_rec_cluster, $rec_id);
$rec = array(
'pool' => $rec_conf['pool'],
'rank' => $rec_conf['rank'],
'time' => $rec_conf['time'],
'reward' => $rec_conf['reward'],
're_reward' => $rec_conf['regular_reward'],
'huge_reward' => $rec_conf['huge_reward'],
);
return $rec;
}
public function newLuckDrawInfo()
{
$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 = 'game2004api_newlot_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'];
$flush_flag = 0;
$now_days = 1;
$row = $conn->execQueryOne('SELECT free_times, video_times, now_days, modify_time 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, now_days) ' .
' VALUES(:accountid, 0, 0, 0, 0, :create_time, :modify_time, 1) ' .
' ON DUPLICATE KEY UPDATE accountid=:accountid, free_times=0, video_times=0, item_id=0, item_num=0, modify_time=:modify_time, now_days=1;',
array(
':accountid' => $account_id,
':create_time' => time(),
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
$now_days = 1;
$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'];
$now_days = $row['now_days'];
//刷新抽奖活动奖励
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['modify_time']) > 0) {
$flush_flag = 1;
$lottery_ret = $conn->execScript('UPDATE activity SET free_times=0, video_times=0, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
));
if (!$lottery_ret) {
die();
return;
}
$free_times = $p_free['value'];
$video_times = $p_video['value'];
}
}
//道具物品
$user_db_str = $r->get($draw_uuid);
if (empty($user_db_str)) {
$draw_list = $this->randomNewReward(1,$account_id,$now_days);
$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);
if ($flush_flag == 1) {
$user_db_str = $r->get($draw_uuid);
$draw_list = $this->randomNewReward(1,$account_id,$now_days);
$draw_db = json_decode($user_db_str, true);
$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_str = $r->get($draw_uuid);
$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) {
$status = 0;
if (isset($draw['status'])) {
$status = $draw['status'];
}
array_push($draw_list, array(
'item_id' => $draw['item_id'],
'item_num' => $draw['item_num'],
'quailty' => $draw['quailty'],
'time' => $draw['time'],
'status' => $status,
));
}
}
}
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 getNewLuckDraw()
{
$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, now_days 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');
$lot_array = array();
$draw_uuid = $_REQUEST['draw_uuid'];
$item_id = 0;
$item_num = 0;
$flag = 0;
$weight = 0;
$key = 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;
}
if ($row['free_times'] + $row['video_times'] + 1 == 5) {
$day = 1;
if (phpcommon\extractChannel($account_id) == 6001 ||
phpcommon\extractChannel($account_id) == 6000) {
$day = $row['now_days'];
}
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
for($g = 1; $g <= count($g_conf_lot_cluster); $g++) {
$l = $this->getLottery($g);
if ($l['jilv'] == 0 && $l['day'] == $day) {
array_push($lot_array, array(
'key' => $g
));
}
}
for ($i1 = 0; $i1 < count($lot_array); $i1++) {
$l = $this->getLottery($lot_array[$i1]['key']);
$weight_sum += $l['jilv'];
}
$random = Rand(0, 100);
if ($random >= 50) {
$key = $lot_array[0]['key'];
} else {
$key = $lot_array[1]['key'];
}
} else if ($row['free_times'] + $row['video_times'] + 1 == 6) {
foreach ($user_db['draw_list'] as $draw) {
if (isset($draw['status']) && $draw['status'] != 0) {
continue;
}
$key = $draw['key'] + 1;
}
} else {
foreach ($user_db['draw_list'] as $draw) {
if (isset($draw['status']) && $draw['status'] != 0) {
continue;
}
array_push($lot_array,array(
'key' => $draw['key'] + 1,
));
}
for ($i = 0; $i < count($lot_array); $i++) {
$l = $this->getLottery($lot_array[$i]['key']);
$weight_sum += $l['jilv'];
}
$random = Rand(1, $weight_sum);
// error_log($random);
for ($ii = 0; $ii < count($lot_array); $ii++) {
$l = $this->getLottery($lot_array[$ii]['key']);
$weight += $l['jilv'];
if ($weight >= $random) {
$key = $lot_array[$ii]['key'];
break;
}
}
}
foreach ($user_db['draw_list'] as &$draw) {
if ($draw['key'] + 1 == $key) {
$item_id = $draw['item_id'];
$item_num = $draw['item_num'];
$time = $draw['time'];
$flag = 1;
$status = 1;
if (isset($draw['status'])) {
$draw['status'] = 1;
} else {
array_push($draw, array(
'status' => 1,
));
}
break;
}
}
$r->set($draw_uuid, json_encode($user_db));
$r -> pexpire($draw_uuid, 1000 * 3600 * 24);
if ($flag == 0) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品');
return;
}
//增加奖励
$addreward = new classes\AddReward();
$all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time, 0);
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$item_list = array();
$quest = new classes\Quest();
$quest->triggerQuest(71004, 1, 1, $account_id);
array_push($item_list,array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time
));
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);
$now_days = $row['now_days'];
if ($p_flush['value'] <= $row['video_times']) {
phpcommon\sendError(ERR_USER_BASE + 3, '今日刷新次数已满');
return;
}
if ($p_flush['value'] == $row['video_times'] + 1) {
$last_conf = $this->getLottery(count($g_conf_lot_cluster));
$now_days++;
if ($last_conf && $now_days >= $last_conf['day']) {
$now_days = $last_conf['day'];
}
}
$ret = $conn->execScript('UPDATE activity SET video_times=:video_times,item_id=:item_id, item_num=:item_num, modify_time=:modify_time, now_days=:now_days ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':video_times' => $row['video_times'] + 1,
':item_id' => $item_id,
':item_num' => $item_num,
':modify_time' => time(),
':now_days' => $now_days
));
if (!$ret) {
die();
return;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_id' => $item_id,
'item_num' => $item_num,
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list,
'status' => $status
));
}
public function drawTableInfo()
{
$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;
}
$drawtable_uuid = 'game2004api_drawtable_uuid:' . md5($_REQUEST['account_id']);
$drawtable_list = array();
$r = $this->getRedis($drawtable_uuid);
if (!$r) {
die();
return;
}
//道具物品
//$user_db_str = $r->get($drawtable_uuid);
$drawtable_list = $this->randomReward(2,$account_id);
$drawtable_db = array(
'drawtable_uuid' => $drawtable_uuid,
'drawtable_list' => $drawtable_list,
);
$r -> set($drawtable_uuid, json_encode($drawtable_db));
$r -> pexpire($drawtable_uuid, 1000 * 3600 * 24);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'drawtable_uuid' => $drawtable_uuid,
'item_list' => $drawtable_list,
));
}
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 = 'game2004api_lot_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'];
$flush_flag = 0;
$row = $conn->execQueryOne('SELECT free_times, video_times, modify_time 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'];
//刷新抽奖活动奖励
if (phpcommon\getdayseconds(time()) - phpcommon\getdayseconds($row['modify_time']) > 0) {
$flush_flag = 1;
$lottery_ret = $conn->execScript('UPDATE activity SET free_times=0, video_times=0, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':modify_time' => time(),
));
if (!$lottery_ret) {
die();
return;
}
$free_times = $p_free['value'];
$video_times = $p_video['value'];
}
}
//道具物品
$user_db_str = $r->get($draw_uuid);
if (empty($user_db_str)) {
$draw_list = $this->randomReward(1,$account_id);
$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);
if ($flush_flag == 1) {
$user_db_str = $r->get($draw_uuid);
$draw_list = $this->randomReward(1,$account_id);
$draw_db = json_decode($user_db_str, true);
$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_str = $r->get($draw_uuid);
$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) {
$status = 0;
if (isset($draw['status'])) {
$status = $draw['status'];
}
array_push($draw_list, array(
'item_id' => $draw['item_id'],
'item_num' => $draw['item_num'],
'quailty' => $draw['quailty'],
'time' => $draw['time'],
'status' => $status,
));
}
}
}
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 getDrawTable()
{
$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;
}
//随机确认奖励
$weight_sum = 0;
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
$l = $this->getDrawTableConfig($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->getDrawTableConfig($ii);
$weight += $l['jilv'];
if ($weight >= $random) {
$key = $ii;
break;
}
}
$drawtable_uuid = $_REQUEST['drawtable_uuid'];
$item_id = 0;
$item_num = 0;
$flag = 0;
$r = $this->getRedis($drawtable_uuid);
$user_db_str = $r->get($drawtable_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;
}
$quest = new classes\Quest();
$quest->triggerQuest(71004, 1, 1, $account_id);
foreach ($user_db['drawtable_list'] as $draw) {
if ($draw['key'] == $key - 1) {
$item_id = $draw['item_id'];
$item_num = $draw['item_num'];
$time = $draw['time'];
$flag = 1;
break;
}
}
if ($flag == 0) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品');
return;
}
$ret = $conn->execScript('UPDATE activity SET item_id=:item_id, item_num=:item_num ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':item_id' => $item_id,
':item_num' => $item_num,
));
if (!$ret) {
die();
return;
}
//增加奖励
$addreward = new classes\AddReward();
$all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time,0);
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$item_list = array();
array_push($item_list,array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time,
));
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_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');
$lot_array = array();
$draw_uuid = $_REQUEST['draw_uuid'];
$item_id = 0;
$item_num = 0;
$flag = 0;
$weight = 0;
$key = 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;
}
if ($row['free_times'] + $row['video_times'] + 1 == 5) {
$day = 1;
if (phpcommon\extractChannel($account_id) == DOUYIN_CHANNEL ||
phpcommon\extractChannel($account_id) == 6001 ||
phpcommon\extractChannel($account_id) == 6000) {
$day = date('w', time());
if ($day == 0) {
$day = 7;
}
}
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
for($g = 1; $g <= count($g_conf_lot_cluster); $g++) {
$l = $this->getLottery($g);
if ($l['jilv'] == 0 && $l['day'] == $day) {
array_push($lot_array, array(
'key' => $g
));
}
}
for ($i1 = 0; $i1 < count($lot_array); $i1++) {
$l = $this->getLottery($lot_array[$i1]['key']);
$weight_sum += $l['jilv'];
}
$random = Rand(0, 100);
if ($random >= 50) {
$key = $lot_array[0]['key'];
} else {
$key = $lot_array[1]['key'];
}
} else if ($row['free_times'] + $row['video_times'] + 1 == 6) {
foreach ($user_db['draw_list'] as $draw) {
if (isset($draw['status']) && $draw['status'] != 0) {
continue;
}
$key = $draw['key'] + 1;
}
} else {
foreach ($user_db['draw_list'] as $draw) {
if (isset($draw['status']) && $draw['status'] != 0) {
continue;
}
array_push($lot_array,array(
'key' => $draw['key'] + 1,
));
}
for ($i = 0; $i < count($lot_array); $i++) {
$l = $this->getLottery($lot_array[$i]['key']);
$weight_sum += $l['jilv'];
}
$random = Rand(1, $weight_sum);
// error_log($random);
for ($ii = 0; $ii < count($lot_array); $ii++) {
$l = $this->getLottery($lot_array[$ii]['key']);
$weight += $l['jilv'];
if ($weight >= $random) {
$key = $lot_array[$ii]['key'];
break;
}
}
}
foreach ($user_db['draw_list'] as &$draw) {
if ($draw['key'] + 1 == $key) {
$item_id = $draw['item_id'];
$item_num = $draw['item_num'];
$time = $draw['time'];
$flag = 1;
$status = 1;
if (isset($draw['status'])) {
$draw['status'] = 1;
} else {
array_push($draw, array(
'status' => 1,
));
}
break;
}
}
$r->set($draw_uuid, json_encode($user_db));
$r -> pexpire($draw_uuid, 1000 * 3600 * 24);
if ($flag == 0) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个物品');
return;
}
//增加奖励
$addreward = new classes\AddReward();
$all_item_list = $addreward->addReward($item_id, $item_num, $account_id, $time, 0);
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$item_list = array();
$quest = new classes\Quest();
$quest->triggerQuest(71004, 1, 1, $account_id);
array_push($item_list,array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time
));
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;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_id' => $item_id,
'item_num' => $item_num,
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list,
'status' => $status
));
}
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,0,0);
$coin_num = $addreward->getCoinNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
));
}
protected function randomNewReward($type,$accountid,$days)
{
$draw_list = array();
$g_conf_lot_cluster = array();
if ($type == 1) {
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
} else {
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
}
$day = 1;
if ($type == 1) {
if (phpcommon\extractChannel($accountid) == 6001 ||
phpcommon\extractChannel($accountid) == 6000) {
$day = $days;
}
}
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
$item_id = 0;
$item_num = 0;
$key = 0;
$l = array();
if ($type == 1) {
$l = $this->getLottery($i);
} else {
$l = $this->getDrawTableConfig($i);
}
//确定商品id和数量
$weight_sum = 0;
$weight_array = $this->getExplode($l['weight']);
if ($type == 1) {
if ($l['day'] != $day) {
continue;
}
}
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']);
$time_array = $this->getExplode($l['time']);
$item_id = $item_id_array[$key][0];
$item_num = $num_array[$key][0];
$quailty = $quailty_array[$key][0];
$time = $time_array[$key][0];
array_push($draw_list, array(
'key' => $i - 1,
'item_id' => $item_id,
'item_num' => $item_num,
'quailty' => $quailty,
'time' => $time,
'status' => 0,
));
}
return $draw_list;
}
protected function randomReward($type,$accountid)
{
$draw_list = array();
$g_conf_lot_cluster = array();
if ($type == 1) {
$g_conf_lot_cluster = require('../res/lottery@lottery.php');
} else {
$g_conf_lot_cluster = require('../res/lotterydraw@lotterydraw.php');
}
$day = 1;
if ($type == 1) {
if (phpcommon\extractChannel($accountid) == 6001 ||
phpcommon\extractChannel($accountid) == 6006 ||
phpcommon\extractChannel($accountid) == 6000) {
$day = date('w', time());
if ($day == 0) {
$day = 7;
}
}
}
for ($i = 1; $i <= count($g_conf_lot_cluster); $i++) {
$item_id = 0;
$item_num = 0;
$key = 0;
$l = array();
if ($type == 1) {
$l = $this->getLottery($i);
} else {
$l = $this->getDrawTableConfig($i);
}
//确定商品id和数量
$weight_sum = 0;
$weight_array = $this->getExplode($l['weight']);
if ($type == 1) {
if ($l['day'] != $day) {
continue;
}
}
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']);
$time_array = $this->getExplode($l['time']);
$item_id = $item_id_array[$key][0];
$item_num = $num_array[$key][0];
$quailty = $quailty_array[$key][0];
$time = $time_array[$key][0];
array_push($draw_list, array(
'key' => $i - 1,
'item_id' => $item_id,
'item_num' => $item_num,
'quailty' => $quailty,
'time' => $time,
'status' => 0,
));
}
return $draw_list;
}
public function lotteryReward()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$pool = $_REQUEST['pool'];
$rec = $this->getRecommend($pool);
$reward_id = 0;
$item_list = array();
$all_item_list = array();
$reward_array = array();
$addreward = new classes\AddReward();
$delim = "|";
$num_multiply = explode($delim, $rec['huge_reward']);
//随机奖励
for($i = 0; $i < $rec['reward']; $i++) {
$item_num = 1;
$time = $this->randtime($rec['time']);
$reward_id = $this->randlottery($reward_array, $pool);
array_push($reward_array, array(
'id' => $reward_id
));
if ($reward_id == 10001) {
$item_num = $num_multiply[0];
$time = 0;
} else if ($reward_id == 10003) {
$item_num = $num_multiply[1];
$time = 0;
}
array_push($item_list, array(
'item_id' => $reward_id,
'item_num' => $item_num,
'time' => $time,
));
$items = $addreward->addReward($reward_id, $item_num, $account_id, $time, 0);
foreach($items as $j) {
array_push($all_item_list, array(
'item_id' => $j['item_id'],
'item_num' => $j['item_num'],
'time' => $j['time'],
));
}
}
//固定奖励
$delim2 = ":";
$re_multiply = explode($delim2, $rec['re_reward']);;
array_push($item_list, array(
'item_id' => $re_multiply[0],
'item_num' => $re_multiply[1],
'time' => 0,
));
$items = $addreward->addReward($re_multiply[0], $re_multiply[1], $account_id, 0, 0);
foreach($items as $s) {
array_push($all_item_list, array(
'item_id' => $s['item_id'],
'item_num' => $s['item_num'],
'time' => $s['time'],
));
}
$coin_num = $addreward->getCoinNum($account_id);
$diamond_num = $addreward->getDiamondNum($account_id);
$quest = new classes\Quest();
$quest->triggerQuest(71004, 1, 1, $account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'coin_nums' => $coin_num,
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list
));
}
protected function randtime($str_time)
{
$weight_sum = 0;
$weight_array = $this->getExplode($str_time);
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight_sum += $weight_array[$ii][1];
}
$random = Rand(0, $weight_sum);
$weight = 0;
$key = 0;
for ($ii = 0; $ii < count($weight_array); $ii++) {
$weight += $weight_array[$ii][1];
if ($weight > $random) {
$key = $weight_array[$ii][0];
break;
}
}
return $key;
}
protected function randlottery($id, $pool)
{
$weight_sum = 0;
$rand_array = array();
$po = $pool - 1;
$g_conf_item_cluster = require('../res/item@item.php');
foreach($g_conf_item_cluster as $items) {
$flag = 0;
$it = $this->getItem($items['id']);
if ($it['id'] != 0) {
foreach ($id as $ids) {
if ($it['id'] == $ids['id']) {
$flag = 1;
break;
}
}
if ($flag == 1) {
continue;
}
$weight_array = $this->getExplode($it['pool_weight']);
$weight_sum += $weight_array[$po][0];
array_push($rand_array, array(
'id' => $it['id'],
'weight' => $weight_array[$po][0]
));
}
}
$random = Rand(0, $weight_sum);
$weight = 0;
$key = 0;
foreach ($rand_array as $r) {
$weight += $r['weight'];
if ($weight > $random) {
$key = $r['id'];
break;
}
}
return $key;
}
public function getBoxOrder()
{
$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 daily_order1, daily_order2, daily_order3 FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
}
$item_list = array();
$daily_order1 = $row['daily_order1'];
$daily_order2 = $row['daily_order2'];
$daily_order3 = $row['daily_order3'];
$p1 = $this->getParameter(LOGINBOX_TIME1);
$p2 = $this->getParameter(LOGINBOX_TIME2);
$p3 = $this->getParameter(LOGINBOX_TIME3);
$p = $this->getParameter(LOGINBOX_TIME);
$pt1 = $p1['value'];
$pt2 = $p2['value'];
$pt3 = $p3['value'];
$pt = $p['value'];
$nowTime = floor((time() - phpcommon\getdayseconds(time())) / 3600);
if ($nowTime < $pt1) {
$daily_order1 = 0;
$daily_order2 = 0;
$daily_order3 = 0;
} else if ($nowTime >= $pt1 && $nowTime < $pt1 + $pt) {
if ($daily_order1 == 0) {
$daily_order1 = 1;
} else {
$daily_order1 = $row['daily_order1'];
}
$daily_order2 = 0;
$daily_order3 = 0;
} else if ($nowTime >= $pt1 + $pt && $nowTime < $pt2) {
if ($daily_order1 <= 1) {
$daily_order1 = 3;
} else {
$daily_order1 = $row['daily_order1'];
}
$daily_order2 = 0;
$daily_order3 = 0;
} else if ($nowTime >= $pt2 && $nowTime < $pt2 + $pt) {
if ($daily_order1 <= 1) {
$daily_order1 = 3;
} else {
$daily_order1 = $row['daily_order1'];
}
if ($daily_order2 == 0) {
$daily_order2 = 1;
} else {
$daily_order2 = $row['daily_order2'];
}
$daily_order3 = 0;
} else if ($nowTime >= $pt2 + $pt && $nowTime < $pt3) {
if ($daily_order1 <= 1) {
$daily_order1 = 3;
} else {
$daily_order1 = $row['daily_order1'];
}
if ($daily_order2 <= 1) {
$daily_order2 = 3;
} else {
$daily_order2 = $row['daily_order2'];
}
$daily_order3 = 0;
} else if ($nowTime >= $pt3 && $nowTime < $pt3 + $pt) {
if ($daily_order1 <= 1) {
$daily_order1 = 3;
} else {
$daily_order1 = $row['daily_order1'];
}
if ($daily_order2 <= 1) {
$daily_order2 = 3;
} else {
$daily_order2 = $row['daily_order2'];
}
if ($daily_order3 == 0) {
$daily_order3 = 1;
} else {
$daily_order3 = $row['daily_order3'];
}
} else if ($nowTime >= $pt3 + $pt) {
if ($daily_order1 <= 1) {
$daily_order1 = 3;
} else {
$daily_order1 = $row['daily_order1'];
}
if ($daily_order2 <= 1) {
$daily_order2 = 3;
} else {
$daily_order2 = $row['daily_order2'];
}
if ($daily_order3 <= 1) {
$daily_order3 = 3;
} else {
$daily_order3 = $row['daily_order3'];
}
}
$stauts = 0;
for ($i = 0; $i < 3; $i++) {
if ($i == 0) {
$status = $daily_order1;
} else if ($i == 1) {
$status = $daily_order2;
} else if ($i == 2) {
$status = $daily_order3;
}
array_push($item_list, array(
'status' => $status
));
}
$ret = $conn->execScript('UPDATE user SET daily_order1=:daily_order1, daily_order2=:daily_order2, daily_order3=:daily_order3 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
':daily_order1' => $daily_order1,
':daily_order2' => $daily_order2,
':daily_order3' => $daily_order3
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'item_list' => $item_list,
));
}
public function getOrderReward()
{
$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;
}
$id = $_REQUEST['id'];
$row = $conn->execQueryOne('SELECT daily_order1, daily_order2, daily_order3 FROM user WHERE accountid=:accountid;',
array(
':accountid' => $account_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
}
if ($id == 1) {
if ($row['daily_order1'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领');
return;
}
$ret = $conn->execScript('UPDATE user SET daily_order1=2 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$ret) {
die();
return;
}
} else if ($id == 2) {
if ($row['daily_order2'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领');
return;
}
$ret = $conn->execScript('UPDATE user SET daily_order2=2 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$ret) {
die();
return;
}
} else if ($id == 3) {
if ($row['daily_order3'] != 1) {
phpcommon\sendError(ERR_USER_BASE + 3, '奖励不可领');
return;
}
$ret = $conn->execScript('UPDATE user SET daily_order3=2 ' .
' WHERE accountid=:accountid;',
array(
':accountid' => $account_id,
));
if (!$ret) {
die();
return;
}
}
$all_item_list = array();
$item_list = $this->randBoxReward(3);
$addreward = new classes\AddReward();
foreach ($item_list as $item) {
$items = $addreward->addReward($item['item_id'], $item['item_num'], $account_id, $item['time'], 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);
$num = $addreward->getDiamondNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'item_list' => $item_list,
'diamond_nums' => $num,
'all_item_list' => $all_item_list
));
}
protected function randBoxReward($drop_id)
{
//随机奖励
$item_list = array();
$b = $this->getbox($drop_id);
if (!$b) {
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
die();
}
$item_id_array = $this->getExplode($b['item_id']);
$weight_sum = 0;
$keys = 0;
$item_num_array = $this->getExplode($b['num']);
$weight_array = $this->getExplode($b['weight']);
$time_array = $this->getExplode($b['time']);
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];
$time = $time_array[$keys][0];
array_push($item_list, array(
'item_id' => $item_id,
'item_num' => $item_num,
'time' => $time
));
return $item_list;
}
}
?>