833 lines
32 KiB
PHP
833 lines
32 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
|
|
class PayController{
|
|
|
|
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 getItem($item_id)
|
|
{
|
|
$item_meta_table = require('../res/item@item.php');
|
|
$item_meta = getItemConfig($item_meta_table, $item_id);
|
|
$item = array(
|
|
'id' => $item_meta['id'],
|
|
'name' => $item_meta['name'],
|
|
'price' => $item_meta['price'],
|
|
'icon' => $item_meta['icon'],
|
|
'fuction' => $item_meta['fuction'],
|
|
'fuctionindex' => $item_meta['fuctionindex'],
|
|
'dprice' => $item_meta['dprice'],
|
|
);
|
|
return $item;
|
|
}
|
|
|
|
protected function getVip($vip_id)
|
|
{
|
|
$vip_meta_table = require('../res/vip@vip.php');
|
|
$vip_meta = getVipConfig($vip_meta_table, $vip_id);
|
|
$vip = array(
|
|
'level' => $vip_meta['level'],
|
|
'require' => $vip_meta['require'],
|
|
'reward' => $vip_meta['reward'],
|
|
'dailyreward' => $vip_meta['dailyreward'],
|
|
'vipicon' => $vip_meta['vipicon']
|
|
);
|
|
return $vip;
|
|
}
|
|
|
|
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 getDiamondShop($diamond_id)
|
|
{
|
|
$diamond_meta_table = require('../res/diamondshop@diamondshop.php');
|
|
$diamond_meta = getDiamondShopConfig($diamond_meta_table, $diamond_id);
|
|
$diamond = array(
|
|
'shop_id' => $diamond_meta['shop_id'],
|
|
'shop_type' => $diamond_meta['shop_type'],
|
|
'item_id' => $diamond_meta['item_id'],
|
|
'coin_type' => $diamond_meta['coin_type'],
|
|
'coin_num' => $diamond_meta['coin_num'],
|
|
'open_time' => $diamond_meta['open_time'],
|
|
'continue_time' => $diamond_meta['continute_time'],
|
|
'limit_num' => $diamond_meta['limit_num'],
|
|
'limit_type' => $diamond_meta['limit_type'],
|
|
'sort' => $diamond_meta['sort'],
|
|
);
|
|
return $diamond;
|
|
}
|
|
|
|
|
|
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 getItemInfo($itemid)
|
|
{
|
|
$d = $this->getDrop($itemid);
|
|
if (!$d) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
|
die();
|
|
}
|
|
$item_list = array();
|
|
$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++) {
|
|
$random = Rand(0, 10000);
|
|
if ($weight_array[$i][0] > $random) {
|
|
$item_id = $item_id_array[$i][0];
|
|
$item_num = $item_num_array[$i][0];
|
|
array_push($item_list, array(
|
|
'itemid' => $item_id,
|
|
'itemnum' => $item_num,
|
|
));
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
public function getPayInfo()
|
|
{
|
|
$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;
|
|
}
|
|
$rowUser = $conn->execQueryOne('SELECT create_time, free_coin, free_diamond FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$rowUser) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$times = 0;
|
|
$info_list = array();
|
|
$diamond_meta_table = require('../res/diamondshop@diamondshop.php');
|
|
for ($i = 1; $i <= count($diamond_meta_table); $i++) {
|
|
$diamond = $this->getDiamondShop($i);
|
|
$item = $this->getItem($diamond['item_id']);
|
|
$item_list = $this->getItemInfo($item['fuctionindex']);
|
|
if (!$item || !$diamond) {
|
|
continue;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT today_times FROM buy_his ' .
|
|
' WHERE accountid=:accountid AND itemid=:itemid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':itemid' => $diamond['item_id']
|
|
));
|
|
if (!$row) {
|
|
$times = $diamond['limit_num'];
|
|
} else {
|
|
//无限次数
|
|
if ($diamond['limit_num'] == -1) {
|
|
$times = $diamond['limit_num'];
|
|
} else {
|
|
//限定次数
|
|
$times = $diamond['limit_num'] - $row['today_times'];
|
|
if ($times < 0) {
|
|
$times = 0;
|
|
}
|
|
}
|
|
}
|
|
//开启结束时间
|
|
$sub_item = array();
|
|
$coin_icon = '';
|
|
$open_time = '-1';
|
|
$end_time = '-1';
|
|
if ($diamond['coin_type'] != 0) {
|
|
$sub_item = $this->getItem($diamond['coin_type']);
|
|
$coin_icon = $sub_item['icon'];
|
|
} else {
|
|
//免费金币钻石领取次数及有效时间
|
|
if ($diamond['shop_type'] == 2) {
|
|
$times = $diamond['limit_num'] - $rowUser['free_coin'];
|
|
}
|
|
if ($diamond['shop_type'] == 1) {
|
|
$times = $diamond['limit_num'] - $rowUser['free_diamond'];
|
|
}
|
|
if ($times == 0) {
|
|
$end_time = phpcommon\getdayseconds(time()) + 24 * 3600;
|
|
}
|
|
}
|
|
if ($diamond['open_time'] != '-1') {
|
|
if ($diamond['open_time'] != '1') {
|
|
$open_time = strtotime($diamond['open_time']);
|
|
}else {
|
|
$open_time = $rowUser['create_time'];
|
|
}
|
|
$end_time = $open_time + $diamond['continue_time'];
|
|
if (time() > $end_time || time() < $open_time) {
|
|
$end_time = '-1';
|
|
}
|
|
}
|
|
array_push($info_list, array(
|
|
'shop_type' => $diamond['shop_type'],
|
|
'item_id' => $diamond['item_id'],
|
|
'item_icon' => $item['icon'],
|
|
'coin_type' => $diamond['coin_type'],
|
|
'coin_num' => $diamond['coin_num'],
|
|
'coin_icon' => $coin_icon,
|
|
'open_time' => $open_time,
|
|
'end_time' => $end_time,
|
|
'buy_num' => $times,
|
|
'sort' => $diamond['sort'],
|
|
'item_list' => $item_list,
|
|
));
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'info_list' => $info_list
|
|
));
|
|
}
|
|
|
|
public function getVipInfo()
|
|
{
|
|
$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 vip_score FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$vip_list = array();
|
|
$vip_level = 0;
|
|
$vip_icon = '';
|
|
$vip_item_list = array();
|
|
$vip_today_item_list = array();
|
|
$vip_meta_table = require('../res/vip@vip.php');
|
|
for ($i = 0; $i < count($vip_meta_table); $i++) {
|
|
$vip_status = 0;
|
|
$vip_today_status = 0;
|
|
$vip = $this->getVip($i);
|
|
if ($row['vip_score'] >= $vip['require']) {
|
|
$vip_level = $vip['level'];
|
|
$vip_icon = $vip['vipicon'];
|
|
}
|
|
$rowVip = $conn->execQueryOne('SELECT reward_id, vipid, reward_status, today_reward_id, today_reward_status ' .
|
|
' FROM vipinfo WHERE accountid=:accountid AND vipid=:vipid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':vipid' => $vip['level']
|
|
));
|
|
if ($rowVip) {
|
|
$vip_status = $rowVip['reward_status'];
|
|
$vip_today_status = $rowVip['today_reward_status'];
|
|
}
|
|
$vip_item_list = $this->getVipItemInfo($vip['reward']);
|
|
$vip_today_item_list = $this->getVipItemInfo($vip['dailyreward']);
|
|
array_push($vip_list, array(
|
|
'vip_id' => $vip['level'],
|
|
'require' => $vip['require'],
|
|
'vip_status' => $vip_status,
|
|
'vip_item_list' => $vip_item_list,
|
|
'vip_today_status' => $vip_today_status,
|
|
'vip_today_item_list' => $vip_today_item_list,
|
|
));
|
|
}
|
|
$v = $this->getVip($vip_level + 1);
|
|
$sum = $v['require'];
|
|
$coin_num = $sum - $row['vip_score'];
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'vip_level' => $vip_level,
|
|
'vip_icon' => $vip_icon,
|
|
'coin_num' => $coin_num,
|
|
'sum' => $sum,
|
|
'vip_list' => $vip_list
|
|
));
|
|
}
|
|
|
|
protected function getVipItemInfo($id)
|
|
{
|
|
$item = $this->getItem($id);
|
|
if (!$item) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
die();
|
|
}
|
|
$d = $this->getDrop($item['fuctionindex']);
|
|
if (!$d) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
die();
|
|
}
|
|
$item_list = array();
|
|
$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++) {
|
|
$random = Rand(0, 10000);
|
|
if ($weight_array[$i][0] > $random) {
|
|
$item_id = $item_id_array[$i][0];
|
|
$item_num = $item_num_array[$i][0];
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
));
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
public function getVipReward()
|
|
{
|
|
$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;
|
|
}
|
|
$vip_id = $_REQUEST['vip_id'];
|
|
$type = $_REQUEST['reward_type'];
|
|
$status = 0;
|
|
$vip = $this->getVip($vip_id);
|
|
if (!$vip) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
return;
|
|
}
|
|
$rowVip = $conn->execQueryOne('SELECT reward_status, today_reward_status ' .
|
|
' FROM vipinfo WHERE accountid=:accountid AND vipid=:vipid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':vipid' => $vip['level']
|
|
));
|
|
if ($rowVip) {
|
|
if ($type == 1) {
|
|
$status = $rowVip['today_reward_status'];
|
|
}
|
|
if ($type == 2) {
|
|
$status = $rowVip['reward_status'];
|
|
}
|
|
if ($status == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '该奖励已领取');
|
|
return;
|
|
}
|
|
}
|
|
$row = $conn->execQueryOne('SELECT vip_score FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
|
|
if ($vip['require'] > $row['vip_score']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '没有达到vip要求');
|
|
return;
|
|
}
|
|
|
|
if (!$rowVip) {
|
|
$ret = $conn->execScript('INSERT INTO vipinfo(accountid, vipid, reward_id, reward_status, today_reward_id, today_reward_status, create_time, modify_time) ' .
|
|
' VALUES(:accountid, :vipid, :reward_id, 0, :today_reward_id, 0, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:accountid, vipid=0, reward_id=0, reward_status=0, today_reward_id=0, today_reward_status=0, modify_time=:modify_time;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':vipid' => $vip['level'],
|
|
':reward_id' => $vip['reward'],
|
|
':today_reward_id' => $vip['dailyreward'],
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
$this->updateStatus($account_id, $vip_id, $type);
|
|
//发送奖励
|
|
$item_list = array();
|
|
if ($type == 2) {
|
|
$item_list = $this->getVipItemInfo($vip['reward']);
|
|
}
|
|
if ($type == 1) {
|
|
$item_list = $this->getVipItemInfo($vip['dailyreward']);
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
foreach ($item_list as $item) {
|
|
//增加奖励
|
|
$addreward->addReward($item['item_id'], $item['item_num'], $account_id);
|
|
}
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num,
|
|
'item_list' => $item_list
|
|
));
|
|
}
|
|
|
|
protected function updateStatus($accountid, $vipid, $type)
|
|
{
|
|
$conn = $this->getMysql($accountid);
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$vip = $this->getVip($vipid);
|
|
if (!$vip) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
return;
|
|
}
|
|
if ($type == 1) {
|
|
$ret = $conn->execScript('UPDATE vipinfo SET today_reward_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND vipid=:vipid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':vipid' => $vipid,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if ($type == 2) {
|
|
$ret = $conn->execScript('UPDATE vipinfo SET reward_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND vipid=:vipid;',
|
|
array(
|
|
':accountid' => $accountid,
|
|
':vipid' => $vipid,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function buyItem()
|
|
{
|
|
//登录校验
|
|
$login = loginVerify($_REQUEST['account_id'], $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$itemid = $_REQUEST['itemid'];
|
|
$itemnum = $_REQUEST['itemnum'];
|
|
|
|
$item_meta_table = require('../res/item@item.php');
|
|
$item_meta = getItemConfig($item_meta_table, $itemid);
|
|
if (!$item_meta || $item_meta['rmbprice'] < 0.001) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '参数错误');
|
|
die();
|
|
}
|
|
|
|
$params = array(
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'itemid' => $itemid,
|
|
'itemnum' => 1,
|
|
'price' => (float)$item_meta['rmbprice']
|
|
);
|
|
$timestamp = time();
|
|
$params['sign'] = phpcommon\md5Sign($params, '06ba97e28ea905b0b7ed5477746b07f1', $timestamp);
|
|
$params['timestamp'] = $timestamp;
|
|
$iv = '1dd2f605f4f8496b';
|
|
$key = 'c868a478c81ff3c168b35d703f787d3c';
|
|
$str_encoded = '2004_' . base64_encode(phpcommon\aesEncrypt(json_encode($params), $iv, $key));
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'data' => $str_encoded
|
|
));
|
|
}
|
|
|
|
public function getOrderInfo()
|
|
{
|
|
if (!loginVerify($_REQUEST['account_id'],
|
|
$_REQUEST['session_id'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
|
|
$conn = $this->getMysql($_REQUEST['account_id']);
|
|
$row = $conn->execQueryOne('SELECT orderid, status, item_list, itemid ' .
|
|
'FROM orderinfo WHERE orderid=:orderid;',
|
|
array(
|
|
':orderid' => $_REQUEST['orderid']
|
|
));
|
|
if (!$row || $row['status'] == 0) {
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'order_state' => 1,
|
|
));
|
|
die();
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'order_state' => 0,
|
|
'buy_itemid' => $row[3],
|
|
'buy_itemnum' => 1,
|
|
'item_list' => json_decode($row[2], true)
|
|
));
|
|
}
|
|
|
|
public function buyPayItem()
|
|
{
|
|
$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 diamond_num, first_gift, free_coin, free_diamond FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_list = array();
|
|
$diamond_meta_table = require('../res/diamondshop@diamondshop.php');
|
|
for ($i = 1; $i <= count($diamond_meta_table); $i++) {
|
|
$diamond = $this->getDiamondShop($i);
|
|
if ($item_id != $diamond['item_id']) {
|
|
continue;
|
|
}
|
|
$item = $this->getItem($diamond['item_id']);
|
|
$item_list = $this->getItemInfo($item['fuctionindex']);
|
|
if (!$item_list) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
|
return;
|
|
}
|
|
if ($diamond['coin_type'] == 10003) {
|
|
//扣除钻石
|
|
if ($row['diamond_num'] < $diamond['coin_num']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '钻石不足');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':diamond_num' => $row['diamond_num'] - $diamond['coin_num'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
//首充礼包奖励
|
|
if ($diamond['shop_type'] == 4) {
|
|
if ($row['first_gift'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '首充礼包已领取');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET first_gift=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
//每日免费金币钻石
|
|
if ($diamond['coin_type'] == 0) {
|
|
if ($diamond['shop_type'] == 2) {
|
|
if ($row['free_coin'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '每日免费金币已领取');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET free_coin=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
if ($diamond['shop_type'] == 1) {
|
|
if ($row['free_diamond'] == 1) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '每日免费钻石已领取');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET free_diamond=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//添加道具
|
|
foreach ($item_list as $item) {
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item['itemid'], $item['itemnum'], $account_id);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
public function getDoubleCoin()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
//登录校验
|
|
$login = loginVerify($account_id, $_REQUEST['session_id']);
|
|
if (!$login) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
|
|
return;
|
|
}
|
|
$item_id = $_REQUEST['item_id'];
|
|
$item_list = array();
|
|
$diamond_meta_table = require('../res/diamondshop@diamondshop.php');
|
|
for ($i = 1; $i <= count($diamond_meta_table); $i++) {
|
|
$diamond = $this->getDiamondShop($i);
|
|
if ($item_id != $diamond['item_id']) {
|
|
continue;
|
|
}
|
|
$item = $this->getItem($diamond['item_id']);
|
|
$item_list = $this->getItemInfo($item['fuctionindex']);
|
|
if (!$item_list) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
|
|
return;
|
|
}
|
|
}
|
|
//添加道具
|
|
$p = $this->getParameter(REWARD_TIMES);
|
|
$times = $p['value'] - 1;
|
|
foreach ($item_list as $item) {
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item['itemid'], $item['itemnum'] * $times, $account_id);
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
public function addADtimes()
|
|
{
|
|
$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 vip_score, shop_view_times, game_times, newhand, newhand2, view_times2, act_ad_status, game_times2, first_day_ad FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$newhand = $row['newhand'];
|
|
$newhand2 = $row['newhand2'];
|
|
$rview_times2 = $row['view_times2'];
|
|
$p1 = $this->getParameter(NEWHAND_NUM1);
|
|
$fight_times = $p1['value'];
|
|
$p2 = $this->getParameter(NEWHAND_NUM2);
|
|
$view_times = $p2['value'];
|
|
$p3 = $this->getParameter(CREAM_TASK_01);
|
|
$fight_times2 = $p3['value'];
|
|
$p4 = $this->getParameter(CREAM_TASK_02);
|
|
$view_times2 = $p4['value'];
|
|
if ($row['game_times'] >= $fight_times && $row['vip_score'] + 1 == $view_times && $newhand == 0) {
|
|
$newhand = 1;
|
|
}
|
|
if ($newhand == 2) {
|
|
if ($row['game_times2'] >= $fight_times2 && $row['view_times2'] + 1 == $view_times2 && $newhand2 == 0) {
|
|
$newhand = 1;
|
|
}
|
|
$rview_times2++;
|
|
}
|
|
$status = $row['act_ad_status'];
|
|
if ($row['vip_score'] + 1 >= 5 && $row['act_ad_status'] < 1){
|
|
$status = 1;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET vip_score=:vip_score, shop_view_times=:shop_view_times, modify_time=:modify_time, newhand=:newhand, act_ad_status=:act_ad_status, newhand2=:newhand2, view_times2=:view_times2, first_day_ad=:first_day_ad ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time(),
|
|
':vip_score' => $row['vip_score'] + 1,
|
|
':newhand' => $newhand,
|
|
':act_ad_status' => $status,
|
|
':shop_view_times' => $row['shop_view_times'] + 1,
|
|
':newhand2' => $newhand2,
|
|
':view_times2' => $rview_times2,
|
|
':first_day_ad' => $row['first_day_ad'] + 1
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
));
|
|
}
|
|
|
|
public function buyPassBook()
|
|
{
|
|
$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 diamond_num FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$item = $this->getItem(10005);
|
|
if (!$item) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
//扣除钻石
|
|
if ($row['diamond_num'] < $item['dprice']) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '钻石不足');
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':diamond_num' => $row['diamond_num'] - $item['dprice'],
|
|
':modify_time' => time()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
//添加通行证
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward(10005, 1, $account_id);
|
|
$coin_num = $addreward->getCoinNum($account_id);
|
|
$diamond_num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'status' => 1,
|
|
'coin_nums' => $coin_num,
|
|
'diamond_nums' => $diamond_num
|
|
));
|
|
}
|
|
}
|
|
?>
|