1
This commit is contained in:
parent
c4c10f0a57
commit
18f6b98e58
137
webapp/controller/DouRewardController.class.php
Normal file
137
webapp/controller/DouRewardController.class.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
require 'classes/Quest.php';
|
||||
require 'classes/AddReward.php';
|
||||
|
||||
class DouRewardController{
|
||||
|
||||
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 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)
|
||||
{
|
||||
$parameter_meta_cluster = require('../res/parameter@parameter.php');
|
||||
$parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id);
|
||||
$p = array(
|
||||
'id' => $parameter_meta['id'],
|
||||
'param_name' => $parameter_meta['param_name'],
|
||||
'param_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 getRewardTimes($coin_num)
|
||||
{
|
||||
$reward_meta_table = require('../res/rewardTimes@rewardTimes.php');
|
||||
$times = 1;
|
||||
$reward_meta = array();
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$reward_id = $i + 91000;
|
||||
$reward_meta = getRewardTimesConfig($reward_meta_table, $reward_id);
|
||||
if ((int)$coin_num >= $reward_meta['minGold'] && (int)$coin_num <= $reward_meta['maxGold']) {
|
||||
$times = $reward_meta['times'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $times;
|
||||
}
|
||||
|
||||
|
||||
public function doubleReward()
|
||||
{
|
||||
$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;
|
||||
}
|
||||
$row = $conn->execQueryOne('SELECT item_id, item_num FROM sign WHERE accountid=:accountid;',
|
||||
array(
|
||||
':accountid' => $account_id
|
||||
));
|
||||
if (!$row) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
||||
return;
|
||||
}
|
||||
$item_id = $row['item_id'];
|
||||
$num = $row['num'];
|
||||
switch ($_REQUEST['type'])
|
||||
{
|
||||
//签到双倍奖励
|
||||
case 1:
|
||||
{
|
||||
$p_gold = $this->getParameter(DOUBLE_SIGN_IN);
|
||||
$num = $num * ($p_gold['param_value'] - 1);
|
||||
break;
|
||||
}
|
||||
//挂机金币多倍奖励
|
||||
case 2:
|
||||
{
|
||||
$times = $this->getRewardTimes($num);
|
||||
$num = $num * ($times - 1);
|
||||
break;
|
||||
}
|
||||
//开宝箱双倍奖励
|
||||
case 3:
|
||||
{
|
||||
$p_gold = $this->getParameter(DOUBLE_BOX);
|
||||
$num = $num * ($p_gold['param_value'] - 1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$addreward = new classes\AddReward();
|
||||
$addreward->addReward($item_id, $num, $account_id);
|
||||
$addreward->updateReward(0, 0, $account_id);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user