1
This commit is contained in:
parent
cafaf7d3ec
commit
42915d43f3
@ -26,7 +26,7 @@ class AddReward {
|
|||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
if ($item_id == 10001) {
|
if ($item_id == 10001) {
|
||||||
$row1 = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;',
|
$row1 = $conn->execQueryOne('SELECT coin_num FROM user WHERE accountid=:accountid;',
|
||||||
array(
|
array(
|
||||||
':accountid' => $account_id
|
':accountid' => $account_id
|
||||||
));
|
));
|
||||||
@ -41,7 +41,7 @@ class AddReward {
|
|||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
} else if ($item_id > 13000 && $item_id < 14000) {
|
} else if ($item_id > 13000 && $item_id < 14000) {
|
||||||
$rowSkin = $conn->execQueryOne('SELECT * FROM skin WHERE accountid=:accountid AND fragment_id=:fragment_id;',
|
$rowSkin = $conn->execQueryOne('SELECT fragment_num FROM skin WHERE accountid=:accountid AND fragment_id=:fragment_id;',
|
||||||
array(
|
array(
|
||||||
':accountid' => $account_id,
|
':accountid' => $account_id,
|
||||||
':fragment_id' => $item_id
|
':fragment_id' => $item_id
|
||||||
@ -57,6 +57,21 @@ class AddReward {
|
|||||||
if (!$ret) {
|
if (!$ret) {
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
} else if ($item_id == 10002) {
|
||||||
|
$rowkey = $conn->execQueryOne('SELECT keys_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
$ret = $conn->execScript('UPDATE user SET keys_num=:keys_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':coin_num' => $item_num + $rowkey['keys_num'],
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
345
webapp/controller/ShareController.class.php
Normal file
345
webapp/controller/ShareController.class.php
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require 'classes/AddReward.php';
|
||||||
|
require 'classes/Quest.php';
|
||||||
|
|
||||||
|
class ShareController{
|
||||||
|
|
||||||
|
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 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 getShare($share_id)
|
||||||
|
{
|
||||||
|
$g_conf_share_cluster = require('../res/share@share.php');
|
||||||
|
$share_conf = getShareConfig($g_conf_share_cluster, $share_id);
|
||||||
|
$sh = array(
|
||||||
|
'id' => $share_conf['id'],
|
||||||
|
'rewards' => $share_conf['rewards'],
|
||||||
|
'people' => $share_conf['people'],
|
||||||
|
);
|
||||||
|
return $sh;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 getParameter($para_id)
|
||||||
|
{
|
||||||
|
$g_conf_para_cluster = require('../res/parameter@parameter.php');
|
||||||
|
$para_conf = getParameterConfig($g_conf_para_cluster, $para_id);
|
||||||
|
$p = array(
|
||||||
|
'id' => $para_conf['id'],
|
||||||
|
'param_name' => $para_conf['param_name'],
|
||||||
|
'param_value' => $para_conf['param_value'],
|
||||||
|
);
|
||||||
|
return $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function keyBoxInfo()
|
||||||
|
{
|
||||||
|
$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 keys_num FROM user WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
/*if ($row['keys_num'] < 1) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3, '钥匙不足');
|
||||||
|
die();
|
||||||
|
}*/
|
||||||
|
$ret = $conn->execScript('UPDATE user SET keys_num=:keys_num, modify_time=:modify_time ' .
|
||||||
|
' WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':keys_num' => $row['keys_num'] - 1,
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if (!$ret) {
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//随机奖励
|
||||||
|
$free = $_REQUEST['free'];
|
||||||
|
$drop_id = 0;
|
||||||
|
if ($free != 0) {
|
||||||
|
$drop_id = 24002;
|
||||||
|
} else {
|
||||||
|
$drop_id = 24001;
|
||||||
|
}
|
||||||
|
$d = $this->getDrop($drop_id);
|
||||||
|
if (!$d) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$item_id_array = $this->getExplode($d['item_id']);
|
||||||
|
$weight_sum = 0;
|
||||||
|
$keys = 0;
|
||||||
|
$item_num_array = $this->getExplode($d['num']);
|
||||||
|
$weight_array = $this->getExplode($d['weight']);
|
||||||
|
for ($i = 0; $i < count($weight_array); $i++) {
|
||||||
|
$weight_sum += $weight_array[$i][0];
|
||||||
|
}
|
||||||
|
srand(crc32($account_id));
|
||||||
|
$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];
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $item_num, $account_id);
|
||||||
|
$item_list = array();
|
||||||
|
array_push($item_list, array(
|
||||||
|
'item_id' => $item_id,
|
||||||
|
'item_num' => $item_num,
|
||||||
|
));
|
||||||
|
$quest = new classes\Quest();
|
||||||
|
$quest->triggerQuest(71004, 1, 1, $account_id);
|
||||||
|
$quest->triggerQuest(72004, 2, 1, $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'item_list' => $item_list,
|
||||||
|
'keys_num' => $row['keys_num'] - 1
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function keyBoxReward()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
//随机奖励
|
||||||
|
$free = $_REQUEST['free'];
|
||||||
|
$drop_id = 0;
|
||||||
|
if ($free != 0) {
|
||||||
|
$drop_id = 24002;
|
||||||
|
} else {
|
||||||
|
$drop_id = 24001;
|
||||||
|
}
|
||||||
|
$d = $this->getDrop($drop_id);
|
||||||
|
if (!$d) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$item_id_array = $this->getExplode($d['item_id']);
|
||||||
|
$weight_sum = 0;
|
||||||
|
$keys = 0;
|
||||||
|
$item_num_array = $this->getExplode($d['num']);
|
||||||
|
$weight_array = $this->getExplode($d['weight']);
|
||||||
|
for ($i = 0; $i < count($weight_array); $i++) {
|
||||||
|
$weight_sum += $weight_array[$i][0];
|
||||||
|
}
|
||||||
|
srand($account_id);
|
||||||
|
$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];
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($item_id, $item_num, $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shareFriendInfo()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$info_list = array();
|
||||||
|
$rows = $conn->execQuery('SELECT ach_id, status FROM share_achievement WHERE accountid=:accountid;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id
|
||||||
|
));
|
||||||
|
if (count($rows) == 0) {
|
||||||
|
$share_meta_table = require('../res/share@share.php');
|
||||||
|
for ($i = 1; $i <= count($share_meta_table); $i++) {
|
||||||
|
error_log($i);
|
||||||
|
$ret = $conn->execScript('INSERT INTO share_achievement(accountid, ach_id, status, create_time, modify_time) ' .
|
||||||
|
' VALUES(:account_id, :ach_id, :status, :create_time, :modify_time) ' .
|
||||||
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, ach_id=:ach_id, status=:status, modify_time=:modify_time;',
|
||||||
|
array(
|
||||||
|
':account_id' => $account_id,
|
||||||
|
':ach_id' => $i,
|
||||||
|
':status' => 0,
|
||||||
|
':create_time' => time(),
|
||||||
|
':modify_time' => time()
|
||||||
|
));
|
||||||
|
if(!$ret){
|
||||||
|
die();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
array_push($info_list, array(
|
||||||
|
'achivement_id' => $i,
|
||||||
|
'status' => 0
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
array_push($info_list, array(
|
||||||
|
'achivement_id' => $row['ach_id'],
|
||||||
|
'status' => $row['status']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
'info_list' => $info_list
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shareFriendReward()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
$ach_id = $_REQUEST['ach_id'];
|
||||||
|
$row = $conn->execQueryOne('SELECT status FROM share_achievement WHERE accountid=:accountid AND ach_id=:ach_id;',
|
||||||
|
array(
|
||||||
|
':accountid' => $account_id,
|
||||||
|
':ach_id' => $ach_id,
|
||||||
|
));
|
||||||
|
if (!$row) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($row['status'] != 0) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 3, '奖励已领取');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$url = '';
|
||||||
|
if (SERVER_ENV == _ONLINE) {
|
||||||
|
$url = 'https://service.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNumSvr&';
|
||||||
|
} else {
|
||||||
|
$url = 'https://service-test.kingsome.cn/webapp/index.php?c=AchievementShare&a=getInviteeNumSvr&';
|
||||||
|
}
|
||||||
|
$timestamp = time();
|
||||||
|
$params = array(
|
||||||
|
'account_id' => $REQUEST['account_id'],
|
||||||
|
'achievement_ids' => $ach_id,
|
||||||
|
);
|
||||||
|
$sign = phpcommon\md5Sign($params,
|
||||||
|
'70e32abc60367adccaa9eb7b56ed821b',
|
||||||
|
$timestamp);
|
||||||
|
$params['sign'] = $sign;
|
||||||
|
$params['timestamp'] = $timestamp;
|
||||||
|
$response = '';
|
||||||
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
||||||
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
$ach_list = $data['invitee_nums'];
|
||||||
|
$peo_num = 0;
|
||||||
|
$sh = $this->getShare($ach_id);
|
||||||
|
for ($i = 0; $i < count($ach_list); $i++) {
|
||||||
|
$arr = $this->getExplode($ach_list[$i]);
|
||||||
|
if ($ach_id == $arr[0][0]) {
|
||||||
|
$peo_num = $arr[0][1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($peo_num < $sh['people']) {
|
||||||
|
phpcommon\sendError(ERR_USER_BASE + 4, '未达到人数要求');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$array = $this->getExplode($sh['rewards']);
|
||||||
|
$addreward = new classes\AddReward();
|
||||||
|
$addreward->addReward($array[0][0], $array[0][1], $account_id);
|
||||||
|
echo json_encode(array(
|
||||||
|
'errcode' => 0,
|
||||||
|
'errmsg' => '',
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user