1036 lines
36 KiB
PHP
1036 lines
36 KiB
PHP
<?php
|
|
|
|
require 'classes/AddReward.php';
|
|
require 'classes/Quest.php';
|
|
require 'classes/RechargeActInfo.php';
|
|
require_once 'metatable/item.php';
|
|
require_once 'metatable/drop.php';
|
|
require_once 'metatable/parameter.php';
|
|
require_once 'metatable/activityplus.php';
|
|
require_once 'metatable/parameter.php';
|
|
|
|
class NewPayActivityController extends BaseAuthedController {
|
|
|
|
private $data = null;
|
|
|
|
public function handlePre()
|
|
{
|
|
parent::handlePre();
|
|
$this->readData();
|
|
}
|
|
|
|
private function readData()
|
|
{
|
|
$conn = $this->getSelfMysql();
|
|
$rows = phpcommon\SqlHelper::select
|
|
(
|
|
$this->getSelfMysql(),
|
|
'recharge_activity',
|
|
array(
|
|
'blobdata'
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
)
|
|
);
|
|
foreach ($rows as $row) {
|
|
$rec_db_str = $row['blobdata'];
|
|
$this->data= json_decode($rec_db_str, true);
|
|
}
|
|
if (empty($this->data)) {
|
|
$this->data = array(
|
|
'single_list' => array(),
|
|
'sum_list' => array(),
|
|
'quest_list' => array(),
|
|
'shop_list' => array(),
|
|
'dress_list' => array(),
|
|
'discount_list' => array(),
|
|
'draw_list' => array(),
|
|
'table_list' => array(),
|
|
'daily_list' => array(),
|
|
);
|
|
}
|
|
}
|
|
|
|
private function saveData()
|
|
{
|
|
phpcommon\SqlHelper::insertOrUpdate
|
|
($this->getSelfMysql(),
|
|
'recharge_activity',
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId(),
|
|
'blobdata' => json_encode($this->data),
|
|
'create_time' => $this->getNowTime(),
|
|
'modify_time' => $this->getNowTime()
|
|
),
|
|
array(
|
|
'blobdata' => json_encode($this->data),
|
|
'modify_time' => $this->getNowTime()
|
|
));
|
|
}
|
|
|
|
protected function recSingleRmb($num, $account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT accountid, daily_max_single FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($row['daily_max_single'] == 0) {
|
|
foreach ($this->data['single_list'] as &$us) {
|
|
if ($us['status'] != 1) {
|
|
continue;
|
|
}
|
|
for ($i = count($us['reward']) - 1; $i > 0; $i--) {
|
|
if ($num >= $us['reward'][$i]['condition']) {
|
|
$us['reward'][$i]['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
$us['status'] = 2;
|
|
$us['time'] = phpcommon\getNowTime();
|
|
break;
|
|
}
|
|
$this->saveData();
|
|
}
|
|
}
|
|
|
|
public function rechargeRmb()
|
|
{
|
|
$num = $_REQUEST['num'];
|
|
$addreward = new classes\AddReward();
|
|
$now_lv = $addreward->getVipLevel($account_id);
|
|
$this->recSingleRmb($num, $account_id);
|
|
$locket = $this->addRmb($num, $account_id);
|
|
$quest = new classes\Quest();
|
|
$quest->flushActQuest(71014, $num, $account_id);
|
|
$new_lv = $addreward->getVipLevel($account_id);
|
|
$isUp = false;
|
|
if ($new_lv > $now_lv) {
|
|
$isUp = true;
|
|
$addreward->insertMailEvent($account_id, $now_lv, $new_lv);
|
|
$addreward->updaterechargelv($account_id, $new_lv, 0);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'isUp' => $isUp,
|
|
'lv' => $new_lv,
|
|
'locket' => $locket,
|
|
));
|
|
}
|
|
|
|
protected function addRmb($num, $account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT accountid, sum_coin, recharge_times_total, max_single_recharge, daily_max_single, rmb_lot_ticket, sumlot_coin FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
$sum_coin = $row['sum_coin'] + $num;
|
|
$rmb_lot_ticket = floor(($num + $row['sumlot_coin']) / 10) + $row['rmb_lot_ticket'];
|
|
$sumlot_coin = floor(($num + $row['sumlot_coin']) % 10);
|
|
$recharge_times_total = $row['recharge_times_total'] + 1;
|
|
$max_single_recharge = $row['max_single_recharge'];
|
|
if ($max_single_recharge < $num) {
|
|
$max_single_recharge = $num;
|
|
}
|
|
$daily_max_single = $row['daily_max_single'];
|
|
if ($daily_max_single < $num) {
|
|
$daily_max_single = $num;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET sum_coin=:sum_coin, recharge_times_total=:recharge_times_total, max_single_recharge=:max_single_recharge, daily_max_single=:daily_max_single, modify_time=:modify_time, rmb_lot_ticket=:rmb_lot_ticket, sumlot_coin=:sumlot_coin WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => phpcommon\getNowTime(),
|
|
':sum_coin' => $sum_coin,
|
|
':recharge_times_total' => $recharge_times_total,
|
|
':max_single_recharge' => $max_single_recharge,
|
|
':daily_max_single' => $daily_max_single,
|
|
':rmb_lot_ticket' => $rmb_lot_ticket,
|
|
':sumlot_coin' => $sumlot_coin,
|
|
));
|
|
return $rmb_lot_ticket;
|
|
}
|
|
|
|
public function rechargeBuy()
|
|
{
|
|
$id = $_REQUEST['id'];
|
|
$item_conf = metatable\getItemById($id);
|
|
if (!$item_conf) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
$item_list = metatable\getDropListById($item_conf['fuctionindex']);
|
|
if (!$item_list) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
return;
|
|
}
|
|
if ($item_conf['buy_reward'] && $item_conf['buy_reward'] != '') {
|
|
$item_arr = $this->getExplode($item_conf['buy_reward']);
|
|
array_push($item_list, array(
|
|
'item_id' => $item_arr[0][0],
|
|
'item_num' => $item_arr[0][1],
|
|
'time' => $item_arr[0][2],
|
|
));
|
|
}
|
|
$all_item_list = array();
|
|
$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);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
public function unlockPassCard()
|
|
{
|
|
$row = phpcommon\SqlHelper::selectOne
|
|
($this->getSelfMysql(),
|
|
'user',
|
|
array(
|
|
'rmb_num',
|
|
'rmb_lot_ticket'
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
)
|
|
);
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
|
|
return;
|
|
}
|
|
$cost = metatable\getParameterByName('season_card_cost');
|
|
if (!$cost) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
//扣除点券
|
|
// $rmb_lot_ticket = floor($cost / 10) + $row['rmb_lot_ticket'];
|
|
// // if ($row['rmb_num'] < $cost) {
|
|
// // phpcommon\sendError(ERR_USER_BASE + 3, '点券不足');
|
|
// // return;
|
|
// // }
|
|
$ret = phpcommon\SqlHelper::update
|
|
($this->getSelfMysql(),
|
|
'user',
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
),
|
|
array(
|
|
'passcard' => 1,
|
|
'modify_time' => $this->getNowTime()
|
|
)
|
|
);
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
// $now_lv = $addreward->getVipLevel($account_id);
|
|
// $this->recSingleRmb($cost, $account_id);
|
|
// $this->addRmb($cost, $account_id);
|
|
|
|
// $new_lv = $addreward->getVipLevel($account_id);
|
|
// $isUp = false;
|
|
// if ($new_lv > $now_lv) {
|
|
// $isUp = true;
|
|
// $addreward->insertMailEvent($account_id, $now_lv, $new_lv);
|
|
// $addreward->updaterechargelv($account_id, $new_lv, 0);
|
|
// }
|
|
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'status' => 1,
|
|
// 'isUp' => $isUp,
|
|
// 'lv' => $new_lv,
|
|
'rmb_nums' => $rmb_num,
|
|
));
|
|
}
|
|
|
|
//充值活动
|
|
public function recAcitivityInfo()
|
|
{
|
|
$userInfo = $this->getUserInfo(
|
|
array(
|
|
'rmb_num',
|
|
'score'
|
|
));
|
|
//充值活动信息
|
|
$user_db = $this->getRecActInfo($userInfo['rmb_num']);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg'=> '',
|
|
'single_list' => $user_db['single_list'],
|
|
'sum_list' => $user_db['sum_list'],
|
|
'quest_list' => $user_db['quest_list'],
|
|
'shop_list' => $user_db['shop_list'],
|
|
'dress_list' => $user_db['dress_list'],
|
|
'discount_list' => $user_db['discount_list'],
|
|
'draw_list' => $user_db['draw_list'],
|
|
'table_list' => $user_db['table_list'],
|
|
'daily_list' => $user_db['daily_list'],
|
|
));
|
|
}
|
|
|
|
protected function getRecActInfo($rmb_num)
|
|
{
|
|
$recharge = new classes\RechargeActInfo();
|
|
$single_list = $recharge->getActSingleInfo(1, $this->data['single_list'], $rmb_num, $this->getAccountId());
|
|
$sum_list = $recharge->getActSumInfo(2, $this->data['sum_list'], $rmb_num, $this->getAccountId());
|
|
$quest_list = $recharge->getActQuestInfo(3, $this->data['quest_list'], $rmb_num, $this->getAccountId());
|
|
$shop_list = $recharge->getActShopInfo(4, $this->data['shop_list'], $rmb_num, $this->getAccountId());
|
|
$dress_list = $recharge->getActDressInfo(5, $this->data['dress_list'], $rmb_num, $this->getAccountId());
|
|
$discount_list = $recharge->getActDiscountInfo(6, $this->data['discount_list'], $rmb_num, $this->getAccountId());
|
|
$draw_list = $recharge->getActDrawInfo(7, $this->data['draw_list'], $rmb_num,$this->getAccountId());
|
|
$table_list = $recharge->getActTableInfo(8, $this->data['table_list'], $rmb_num, $this->getAccountId());
|
|
$daily_list = $recharge->getActDailyInfo(9, $this->data['daily_list'], $rmb_num, $this->getAccountId());
|
|
$act_db = array(
|
|
'single_list' => $single_list,
|
|
'sum_list' => $sum_list,
|
|
'quest_list' => $quest_list,
|
|
'shop_list' => $shop_list,
|
|
'dress_list' => $dress_list,
|
|
'discount_list' => $discount_list,
|
|
'draw_list' => $draw_list,
|
|
'table_list' => $table_list,
|
|
'daily_list' => $daily_list,
|
|
);
|
|
return $act_db;
|
|
}
|
|
|
|
protected function getDailyExtraReward($type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
foreach ($this->data['daily_list'] as &$us) {
|
|
if ($us['id'] != $id) {
|
|
continue;
|
|
}
|
|
foreach ($us['daily_list'] as &$key) {
|
|
if ($idx != $key['condition']) {
|
|
continue;
|
|
}
|
|
$item_list = $key['extra'];
|
|
$key['time'] = phpcommon\getNowTime();
|
|
$key['extra_status'] = 2;
|
|
}
|
|
}
|
|
$this->saveData($this->getAccountId(), $this->data);
|
|
return $item_list;
|
|
}
|
|
|
|
//充值活动奖励
|
|
public function recAcitivityReward()
|
|
{
|
|
$type = $_REQUEST['type'];
|
|
$id = $_REQUEST['id'];
|
|
$idx = $_REQUEST['idx'];
|
|
//十连抽特殊字段
|
|
$draw_type = 0;
|
|
if (isset($_REQUEST['draw_type'])) {
|
|
$draw_type = $_REQUEST['draw_type'];
|
|
}
|
|
$isUp = false;
|
|
$addreward = new classes\AddReward();
|
|
$new_lv = $addreward->getVipLevel($this->getAccountId());
|
|
$item_list = $this->getActRewardList($type, $id, $idx, $draw_type);
|
|
if (!$item_list || empty($item_list)) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励');
|
|
return;
|
|
}
|
|
$all_item_list = array();
|
|
foreach ($item_list as $item) {
|
|
$items = $addreward->addReward($item['item_id'], $item['item_num'], $this->getAccountId(), $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($this->getAccountId());
|
|
$rmb_num = $addreward->getRmbNum($this->getAccountId());
|
|
$rmb_ticket = $addreward->getRmbTicketNum($this->getAccountId());
|
|
$row = phpcommon\SqlHelper::selectOne
|
|
($this->getSelfMysql(),
|
|
'user',
|
|
array(
|
|
'free_box',
|
|
),
|
|
array(
|
|
'accountid' => $this->getAccountId()
|
|
)
|
|
);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'coin_nums' => $coin_num,
|
|
'rmb_nums' => $rmb_num,
|
|
'all_item_list' => $all_item_list,
|
|
'rmb_lot_ticket' => $rmb_ticket,
|
|
'free_box' => $row['free_box'],
|
|
// 'isUp' => $isUp,
|
|
// 'lv' => $new_lv,
|
|
));
|
|
}
|
|
|
|
protected function getActRewardList($type, $id, $idx, $draw_type)
|
|
{
|
|
$item_list = array();
|
|
if ($type == 1) {
|
|
$item_list = $this->getSingleReward($type, $id, $idx);
|
|
} else if ($type == 2) {
|
|
$item_list = $this->getSumReward($id, $draw_type);
|
|
} else if ($type == 3) {
|
|
$item_list = $this->getQuestReward($type, $id, $idx, $draw_type);
|
|
} else if ($type == 4) {
|
|
$item_list = $this->getShopReward($type, $id, $idx);
|
|
} else if ($type == 5) {
|
|
$item_list = $this->getDressReward($type, $id, $idx);
|
|
} else if ($type == 6) {
|
|
$item_list = $this->getDiscountReward($type, $id, $idx);
|
|
} else if ($type == 7) {
|
|
$item_list = $this->getDrawReward($type, $id, $idx, $user_db);
|
|
} else if ($type == 8) {
|
|
$item_list = $this->getTableReward($type, $id, $idx, $draw_type);
|
|
} else if ($type == 9) {
|
|
if ($draw_type == 0) {
|
|
$item_list = $this->getDailyReward($type, $id, $idx);
|
|
} else {
|
|
$item_list = $this->getDailyExtraReward($type, $id, $idx);
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
private function getDailyActCond($actdb, $cond)
|
|
{
|
|
return isset($actdb[$cond]) ? $actdb[$cond] : null;
|
|
}
|
|
|
|
private function getDailyActCondIdx($actdb, $cond)
|
|
{
|
|
return isset($actdb[$cond]) ? $actdb[$cond] : null;
|
|
}
|
|
|
|
private function calcDailyActRemainDay($actdb)
|
|
{
|
|
$pass_day = phpcommon\between_days($this->getNowTime(), $actdb['last_buytime']);
|
|
$real_remain_day = max($actdb['remain_day'] - $pass_day, 0);
|
|
return $real_remain_day;
|
|
}
|
|
|
|
/*
|
|
id: 活动id
|
|
cond: 活动目标条件
|
|
*/
|
|
protected function getDailyReward($type, $id, $cond)
|
|
{
|
|
$actMeta = metatable\getActPlusById($id);
|
|
|
|
$item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
$actdb = isset($this->data['daily_list'][$id]) ? $this->data['daily_list'][$id] : null;
|
|
if ($actdb == null) {
|
|
$actdb = array();
|
|
$cond_conf = explode('|', $actMeta['condition']);
|
|
foreach ($cond_conf as $c) {
|
|
$actdb[$c] = array(
|
|
'act_cond' => $c, //活动目标条件
|
|
'buytimes' => 0, //购买次数
|
|
'last_buytime' => 0, //最后一次购买时间,0就表示未购买过
|
|
'last_receive_time' => 0, //最后领取时间如果等于当天表示今天已1领取
|
|
);
|
|
}
|
|
$actdb['remain_day'] = 0;
|
|
$actdb['last_buytime'] = 0;
|
|
$this->data['daily_list'][$id] = $actdb;
|
|
}
|
|
$cond_idx = metatable\ActivityPlus::getCondIdx($actMeta, $cond);
|
|
if (!$this->getDailyActCond($actdb, $cond) ||
|
|
$cond_idx < 0) {
|
|
phpcommon\sendError(500, '配置表错误');
|
|
error_log('不存在的daily act cond');
|
|
die();
|
|
}
|
|
$cond_actdb = $actdb[$cond];
|
|
{
|
|
//计算价格
|
|
$decPrice = 0;
|
|
foreach ($actdb as $c) {
|
|
if ($this->calcDailyActRemainDay($actdb) > 0 && $c['act_cond'] < $cond) {
|
|
$decPrice += $c['act_cond'];
|
|
}
|
|
}
|
|
$finallyPrice = max($cond - $decPrice, 0);
|
|
}
|
|
{
|
|
//计算剩余天数
|
|
$new_remain_day = $this->calcDailyActRemainDay($actdb) + $cond;
|
|
$actdb['remain_day'] = $new_remain_day;
|
|
$actdb['last_buytime'] = $this->getNowTime();
|
|
$cond_actdb['last_buytime'] = $this->getNowTime();
|
|
}
|
|
{
|
|
//给奖励
|
|
$item_conf = metatable\getItemById(metatable\ActivityPlus::getReward($actMeta, $cond_idx));
|
|
if (!$item_conf) {
|
|
return null;
|
|
}
|
|
$item_list = metatable\getDropListById($item_conf['fuctionindex']);
|
|
$item_str = $item_conf['buy_reward'];
|
|
$it_arr = $this->getExplode($item_str);
|
|
foreach ($it_arr as $it) {
|
|
array_push($item_list, array(
|
|
'item_id' => $it[0],
|
|
'item_num' => $it[1],
|
|
'time' => $it[2],
|
|
));
|
|
}
|
|
for ($i = 1; $i < $cond_idx + 1; $i++) {
|
|
$addreward->addReward($i + 19000, 1, $this->getAccountId(), 0, 0);
|
|
}
|
|
$addreward->updaterechargelv($this->getAccountId(), $cond_idx + 1, 1);
|
|
}
|
|
$cond_actdb['buytimes']++;
|
|
|
|
$this->saveData();
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getSingleReward($type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
foreach ($this->data['single_list'] as &$us) {
|
|
if ($us['id'] != $id) {
|
|
continue;
|
|
}
|
|
foreach ($us['reward'] as &$r) {
|
|
if ($idx != $r['condition']) {
|
|
continue;
|
|
}
|
|
$item_conf = metatable\getItemById($r['reward_id']);
|
|
if (!$item_conf) {
|
|
return null;
|
|
}
|
|
$item_list = metatable\getDropListById($item_conf['fuctionindex']);
|
|
$r['status'] = 2;
|
|
break;
|
|
}
|
|
$us['status'] = 3;
|
|
$us['time'] = phpcommon\getNowTime();
|
|
break;
|
|
}
|
|
foreach ($this->data['single_list'] as &$us) {
|
|
$us['time'] = phpcommon\getNowTime();
|
|
}
|
|
$this->saveData($this->getAccountId(), $this->data);
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getSumReward($id, $draw_type)
|
|
{
|
|
$act = metatable\getActPlusById($id);
|
|
$item_conf = metatable\getItemById($act['reward']);
|
|
$item_list = array();
|
|
if (!$item_conf) {
|
|
return null;
|
|
}
|
|
$num = 1;
|
|
if ($draw_type == 1) {
|
|
$num = 10;
|
|
}
|
|
$re = $this->subCoin($this->getAccountId(), 99999, $num);
|
|
if (!$re) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '货币不足');
|
|
die();
|
|
return;
|
|
}
|
|
$item_list = array();
|
|
for ($i = 0; $i < $num; $i++) {
|
|
$items = metatable\getDropListById($item_conf['fuctionindex']);
|
|
if (!$items) {
|
|
return null;
|
|
}
|
|
foreach ($items as $it) {
|
|
array_push($item_list, array(
|
|
'item_id' => $it['item_id'],
|
|
'item_num' => $it['item_num'],
|
|
'time' => $it['time'],
|
|
));
|
|
}
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getQuestReward($account_id, $user_db, $type, $id, $idx, $condition)
|
|
{
|
|
$item_list = array();
|
|
foreach ($user_db['quest_list'] as &$us) {
|
|
if (!isset($us['id']) || $us['id'] != $id) {
|
|
continue;
|
|
}
|
|
$num = 0;
|
|
foreach ($us['quest_list'] as &$q) {
|
|
if ($q['id'] != $idx) {
|
|
$num++;
|
|
continue;
|
|
}
|
|
|
|
if ($q['condition'] != $condition) {
|
|
$num++;
|
|
continue;
|
|
}
|
|
|
|
if ($q['status'] != 1) {
|
|
$num++;
|
|
continue;
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $us['reward'][$num]['item_id'],
|
|
'item_num' => $us['reward'][$num]['item_num'],
|
|
'time' => $us['reward'][$num]['time'],
|
|
));
|
|
$q['status'] = 2;
|
|
$num++;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
$this->saveData();
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getShopReward($account_id, $user_db, $type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
foreach ($user_db['shop_list'] as &$us) {
|
|
if (empty($us['id']) || $us['id'] != $id) {
|
|
continue;
|
|
}
|
|
foreach ($us['reward']['shop_list'] as &$s) {
|
|
if ($s['id'] != $idx) {
|
|
continue;
|
|
}
|
|
$price_id = 10003;
|
|
if ($s['buy'] == 2) {
|
|
$price_id = 10003;
|
|
} else if ($s['buy'] == 1) {
|
|
$price_id = 10001;
|
|
}
|
|
$re = $this->subCoin($account_id, $price_id, $s['price']);
|
|
if (!$re || ($s['status'] >= $s['limit_val'] && $s['limit_val'] != 0)) {
|
|
return null;
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $s['id'],
|
|
'item_num' => 1,
|
|
'time' => 0,
|
|
));
|
|
$s['status']++;
|
|
break;
|
|
}
|
|
}
|
|
$this->saveData();
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getDressReward($type, $id, $idx)
|
|
{
|
|
|
|
}
|
|
|
|
protected function getDiscountReward($account_id, $user_db, $type, $id, $idx)
|
|
{
|
|
$item_list = array();
|
|
$item_id = 0;
|
|
foreach ($user_db['discount_list'] as &$us) {
|
|
if ($id != $us['id']) {
|
|
continue;
|
|
}
|
|
foreach ($us['reward'] as &$r) {
|
|
$re = $this->subCoin($account_id, 10003, $r['price']);
|
|
if (!$re || $r['status'] == 1) {
|
|
return null;
|
|
}
|
|
$item_id = $r['id'];
|
|
array_push($item_list, array(
|
|
'item_id' => $r['id'],
|
|
'item_num' => 1,
|
|
'time' => 0,
|
|
));
|
|
$r['status'] = 1;
|
|
break;
|
|
}
|
|
}
|
|
$rec = $this->flushItem($account_id, $user_db, $id, $item_id, 1);
|
|
if (!$rec) {
|
|
return null;
|
|
}
|
|
//$this->saveData();
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getDrawReward($type, $id, $idx, $user_db)
|
|
{
|
|
$item_list = array();
|
|
$keys = 0;
|
|
for ($i = 0; $i < count($this->data['draw_list']); $i++) {
|
|
if ($this->data['draw_list'][$i]['id'] == $id) {
|
|
$reward = $this->data['draw_list'][$i]['reward'];
|
|
break;
|
|
}
|
|
}
|
|
if (empty($reward) || !$reward) {
|
|
return $item_list;
|
|
}
|
|
$weight_sum = 0;
|
|
for ($j = 0; $j < count($reward); $j++) {
|
|
$weight_sum += $reward[$j]['weight'];
|
|
}
|
|
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($j = 0; $j < count($reward); $j++) {
|
|
$weight += $reward[$j]['weight'];
|
|
if ($weight > $random) {
|
|
$keys = $j;
|
|
break;
|
|
}
|
|
}
|
|
$item_id = $reward[$keys]['item_id'];
|
|
$item_num = $reward[$keys]['item_num'];
|
|
$time = $reward[$keys]['time'];
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'time' => $time,
|
|
));
|
|
if ($item_list) {
|
|
$re = $this->subCoin($this->getAccountId(), $this->data['draw_list'][$idx]['conditionid'], $this->data['draw_list'][$idx]['condition']);
|
|
if (!$re) {
|
|
return null;
|
|
}
|
|
}
|
|
unset($reward[$keys]);
|
|
$user_db['draw_list'][$idx]['reward'] = array_values($reward);
|
|
$this->saveData($this->getAccountId(), $user_db);
|
|
return $item_list;
|
|
}
|
|
|
|
protected function getTableReward($type, $id, $idx, $draw_type)
|
|
{
|
|
$act = metatable\getActPlusById($id);
|
|
$item_conf = metatable\getItemById($act['reward']);
|
|
$item_list = array();
|
|
if (!$item_conf) {
|
|
return null;
|
|
}
|
|
$num = 1;
|
|
if ($draw_type == 1) {
|
|
$num = 10;
|
|
}
|
|
for ($i = 0; $i < $num; $i++) {
|
|
$items = metatable\getDropListById($item_conf['fuctionindex']);
|
|
if (!$items) {
|
|
return null;
|
|
}
|
|
foreach ($items as $it) {
|
|
array_push($item_list, array(
|
|
'item_id' => $it['item_id'],
|
|
'item_num' => $it['item_num'],
|
|
'time' => $it['time'],
|
|
));
|
|
}
|
|
}
|
|
if ($draw_type != 2) {
|
|
$re = $this->subCoin($this->getAccountId(), $this->data['table_list'][$idx]['conditionid'], $this->data['table_list'][$idx]['condition'] * $num);
|
|
if (!$re) {
|
|
phpcommon\sendError(ERR_USER_BASE + 4, '货币不足');
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
$conn = $this->getMysql($this->getAccountId());
|
|
$row = $conn->execQueryOne('SELECT free_box FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $this->getAccountId(),
|
|
));
|
|
if (!$row || $row['free_box'] >= metatable\getParameterByName('activit_draw_times')) {
|
|
phpcommon\sendError(ERR_USER_BASE + 5, '今日次数已达上限');
|
|
die();
|
|
return;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET free_box=:free_box, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $this->getAccountId(),
|
|
':free_box' => $row['free_box'] + 1,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
}
|
|
return $item_list;
|
|
}
|
|
|
|
protected function subCoin($account_id, $id, $num)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$row = $conn->execQueryOne('SELECT rmb_num, coin_num, rmb_lot_ticket FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
));
|
|
if (!$row) {
|
|
return false;
|
|
}
|
|
if ($id == 10001) {
|
|
if ($row['coin_num'] < $num) {
|
|
return false;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':coin_num' => $row['coin_num'] - $num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
} else if ($id == 10003 || $id == 10007) {
|
|
if ($row['rmb_num'] < $num) {
|
|
return false;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':rmb_num' => $row['rmb_num'] - $num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
} else if ($id == 99999) {
|
|
if ($row['rmb_lot_ticket'] < $num) {
|
|
return false;
|
|
}
|
|
$ret = $conn->execScript('UPDATE user SET rmb_lot_ticket=:rmb_lot_ticket, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':rmb_lot_ticket' => $row['rmb_lot_ticket'] - $num,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
}
|
|
if (!$ret) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
protected function itemlistinfo($reward)
|
|
{
|
|
$item_list = array();
|
|
$weight_sum = 0;
|
|
$keys = 0;
|
|
for ($j = 0; $j < count($reward); $j++) {
|
|
$weight_sum += $reward[$j]['weight'];
|
|
}
|
|
|
|
$random = Rand(0, $weight_sum);
|
|
$weight = 0;
|
|
for ($j = 0; $j < count($reward); $j++) {
|
|
$weight += $reward[$j]['weight'];
|
|
if ($weight > $random) {
|
|
$keys = $j;
|
|
break;
|
|
}
|
|
}
|
|
$item_id = $reward[$keys]['item_id'];
|
|
$item_num = $reward[$keys]['item_num'];
|
|
$time = $reward[$keys]['time'];
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
'time' => $time,
|
|
));
|
|
return $item_list;
|
|
}
|
|
|
|
//好友砍价
|
|
public function shareDiscount()
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
if (!$this->data || empty($this->data) || empty($this->data['discount_list'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$id = $_REQUEST['id'];
|
|
$item_id = $_REQUEST['item_id'];
|
|
$price = 0;
|
|
$flag = false;
|
|
foreach ($this->data['discount_list'] as &$us) {
|
|
if ($id != $us['id']) {
|
|
continue;
|
|
}
|
|
foreach ($us['reward'] as &$r) {
|
|
if ($r['id'] != $item_id) {
|
|
continue;
|
|
}
|
|
$r['price'] = floor($r['price'] * $r['dis_num'] / 100);
|
|
if ($r['price'] <= 5) {
|
|
$r['price'] = 0;
|
|
}
|
|
$price = $r['price'];
|
|
$flag = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!$flag) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具');
|
|
return;
|
|
}
|
|
$this->saveData();
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'price' => $price,
|
|
));
|
|
}
|
|
|
|
//好友砍价刷新
|
|
public function flushDiscountShop()
|
|
{
|
|
if (!$this->data || empty($this->data) || empty($this->data['discount_list'])) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$id = $_REQUEST['id'];
|
|
$flag = false;
|
|
$item_id = $_REQUEST['item_id'];
|
|
$rec = $this->flushItem($this->getAccountId(), $this->data, $id, $item_id, 0);
|
|
if (!$rec) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具');
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
protected function flushItem($account_id, $user_db, $id, $item_id, $type)
|
|
{
|
|
$flag = false;
|
|
foreach ($user_db['discount_list'] as &$us) {
|
|
if ($id != $us['id']) {
|
|
continue;
|
|
}
|
|
$num = 0;
|
|
foreach ($us['sum_list'] as $s) {
|
|
if ($s['id'] == $item_id) {
|
|
$flag = true;
|
|
break;
|
|
}
|
|
$num++;
|
|
}
|
|
if (!$flag) {
|
|
//phpcommon\sendError(ERR_USER_BASE + 3, '没有这个道具');
|
|
return null;
|
|
}
|
|
if ($type == 1) {
|
|
array_splice($us['sum_list'], $num, 1);
|
|
}
|
|
$sum_list = $us['sum_list'];
|
|
$recharge = new classes\RechargeActInfo();
|
|
$reward = $recharge->randDiscount($sum_list, $us['reward'][0]['id']);
|
|
$us['reward'] = $reward;
|
|
break;
|
|
}
|
|
$this->saveData();
|
|
return true;
|
|
}
|
|
|
|
public function changeHeadKuang()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->getMysql($account_id);
|
|
$id = $_REQUEST['id'];
|
|
$ret = $conn->execScript('UPDATE user SET head_kuang_id=:head_kuang_id, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':head_kuang_id' => $id,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'head_kuang_id' => $id,
|
|
));
|
|
}
|
|
|
|
public function addmailReward()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$attachment = $_REQUEST['attachment'];
|
|
$item_list = array();
|
|
$all_item_list = array();
|
|
$arr = json_decode($attachment, true);
|
|
foreach ($arr as $a) {
|
|
$time = 0;
|
|
if (isset($a['time'])){
|
|
$time = $a['time'];
|
|
}
|
|
array_push($item_list, array(
|
|
'item_id' => $a['itemid'],
|
|
'item_num' => $a['itemnum'],
|
|
'time' => $time,
|
|
));
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
foreach ($item_list as $i) {
|
|
$items = $addreward->addReward($i['item_id'], $i['item_num'], $account_id, $i['time'], 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);
|
|
$rmb_num = $addreward->getRmbNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'all_item_list' => $all_item_list,
|
|
'coin_num' => $coin_num,
|
|
'rmb_num' => $rmb_num,
|
|
));
|
|
}
|
|
|
|
|
|
}
|