1
This commit is contained in:
parent
b5b4e5da08
commit
7035c8309b
@ -1,254 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require 'classes/AddReward.php';
|
|
||||||
require_once 'metatable/activity.php';
|
|
||||||
|
|
||||||
require_once('mt/Parameter.php');
|
|
||||||
|
|
||||||
class FesActivityController extends BaseAuthedController {
|
|
||||||
|
|
||||||
protected function readFesActDB($account_id) {
|
|
||||||
$conn = $this->getMysql($account_id);
|
|
||||||
$row = $conn->execQueryOne('SELECT blobdata FROM festival_activity WHERE accountid=:accountid;',
|
|
||||||
array(
|
|
||||||
':accountid' => $account_id
|
|
||||||
));
|
|
||||||
if (!empty($row)) {
|
|
||||||
$fes_db_str = $row['blobdata'];
|
|
||||||
$fes_db = json_decode($fes_db_str, true);
|
|
||||||
return $fes_db;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function saveFesActDB($account_id, $fes_db) {
|
|
||||||
$conn = $this->getMysql($account_id);
|
|
||||||
$row = $conn->execQueryOne('SELECT accountid FROM festival_activity WHERE accountid=:accountid;',
|
|
||||||
array(
|
|
||||||
':accountid' => $account_id
|
|
||||||
));
|
|
||||||
$fes_db_str = "";
|
|
||||||
if (!empty($fes_db)) {
|
|
||||||
$fes_db_str = json_encode($fes_db);
|
|
||||||
}
|
|
||||||
if (!empty($row)) {
|
|
||||||
//update
|
|
||||||
$row = $conn->execScript('UPDATE festival_activity SET blobdata=:blobdata, modify_time=:modify_time WHERE accountid=:accountid;',
|
|
||||||
array(
|
|
||||||
':accountid' => $account_id,
|
|
||||||
':blobdata' => $fes_db_str,
|
|
||||||
':modify_time' => phpcommon\getNowTime()
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
//insert
|
|
||||||
$row = $conn->execScript('INSERT INTO festival_activity(accountid, blobdata, create_time, modify_time) ' .
|
|
||||||
' VALUES(:account_id, :blobdata, :create_time, :modify_time) ' .
|
|
||||||
' ON DUPLICATE KEY UPDATE accountid=:account_id, blobdata=:blobdata, modify_time=:modify_time;',
|
|
||||||
array(
|
|
||||||
':account_id' => $account_id,
|
|
||||||
':blobdata' => $fes_db_str,
|
|
||||||
':create_time' => phpcommon\getNowTime(),
|
|
||||||
':modify_time' => phpcommon\getNowTime(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//节日活动
|
|
||||||
public function acitivityInfo()
|
|
||||||
{
|
|
||||||
$account_id = $_REQUEST['account_id'];
|
|
||||||
$conn = $this->getMysql($account_id);
|
|
||||||
//节日活动信息
|
|
||||||
$this->getfesActInfo($account_id);
|
|
||||||
$user_db = $this->readFesActDB($account_id);
|
|
||||||
//metatable\getRewardInfo(1,1,1);
|
|
||||||
echo json_encode(array(
|
|
||||||
'errcode' => 0,
|
|
||||||
'errmsg'=> '',
|
|
||||||
'isopen' => $user_db['isopen'],
|
|
||||||
'id' => $user_db['act_id'],
|
|
||||||
'info_list' => $user_db['info_list'],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getfesActInfo($account_id)
|
|
||||||
{
|
|
||||||
$user_db = $this->readFesActDB($account_id);
|
|
||||||
$act = metatable\getNowActivity();
|
|
||||||
$info_list = array();
|
|
||||||
if (!$act) {
|
|
||||||
//活动未开启
|
|
||||||
$act_db = array(
|
|
||||||
'isopen' => 0,
|
|
||||||
'act_id' => 0,
|
|
||||||
'info_list' => $info_list,
|
|
||||||
);
|
|
||||||
$this->saveFesActDB($account_id, $act_db);
|
|
||||||
} else {
|
|
||||||
//活动开启
|
|
||||||
if (empty($user_db) || empty($user_db['info_list'])) {
|
|
||||||
$info_list = $this->getActItem($act['id']);
|
|
||||||
$act_db = array(
|
|
||||||
'isopen' => 1,
|
|
||||||
'act_id' => $act['id'],
|
|
||||||
'info_list' => $info_list,
|
|
||||||
);
|
|
||||||
$this->saveFesActDB($account_id, $act_db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getActItem($id)
|
|
||||||
{
|
|
||||||
$act_conf = metatable\getActivityById($id);
|
|
||||||
if (!$act_conf) {
|
|
||||||
die();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return metatable\getActInfo($act_conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getActReward()
|
|
||||||
{
|
|
||||||
$account_id = $_REQUEST['account_id'];
|
|
||||||
$conn = $this->getMysql($account_id);
|
|
||||||
$user_db = $this->readFesActDB($account_id);
|
|
||||||
if (empty($user_db) || $user_db['isopen'] == 0) {
|
|
||||||
phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$reward = array();
|
|
||||||
$id = $_REQUEST['id'];
|
|
||||||
$status = 1;
|
|
||||||
foreach ($user_db['info_list'] as &$us) {
|
|
||||||
if ($us['id'] == $id) {
|
|
||||||
if ($us['status'] != 1) {
|
|
||||||
phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$us['status'] = 2;
|
|
||||||
$status = 2;
|
|
||||||
$reward = metatable\getRewardInfo($user_db['act_id'], $id, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($reward) || !$reward) {
|
|
||||||
phpcommon\sendError(ERR_USER_BASE + 5, '没有这个奖励');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//更新奖励状态
|
|
||||||
$this->saveFesActDB($account_id, $user_db);
|
|
||||||
//领取奖励
|
|
||||||
$item_list = array();
|
|
||||||
$all_item_list = array();
|
|
||||||
$addreward = new classes\AddReward();
|
|
||||||
for ($i = 0; $i < count($reward); $i++) {
|
|
||||||
$item_id = $reward[$i][0];
|
|
||||||
$num = $reward[$i][1];
|
|
||||||
$time = $reward[$i][2];
|
|
||||||
array_push($item_list, array(
|
|
||||||
'item_id' => $item_id,
|
|
||||||
'item_num' => $num,
|
|
||||||
'time' => $time,
|
|
||||||
));
|
|
||||||
$items = $addreward->addReward($item_id, $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'],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$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,
|
|
||||||
'status' => $status,
|
|
||||||
'id' => $id,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getActExtraReward()
|
|
||||||
{
|
|
||||||
$account_id = $_REQUEST['account_id'];
|
|
||||||
$conn = $this->getMysql($account_id);
|
|
||||||
$user_db = $this->readFesActDB($account_id);
|
|
||||||
if (empty($user_db) || $user_db['isopen'] == 0) {
|
|
||||||
phpcommon\sendError(ERR_USER_BASE + 3, '活动未开启');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$reward = array();
|
|
||||||
$id = $_REQUEST['id'];
|
|
||||||
$status = 0;
|
|
||||||
$times = 0;
|
|
||||||
foreach ($user_db['info_list'] as &$us) {
|
|
||||||
if ($us['id'] == $id) {
|
|
||||||
if ($us['status'] != 0) {
|
|
||||||
phpcommon\sendError(ERR_USER_BASE + 4, '奖励不可领');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($us['times'] + 1 >= $us['condition']) {
|
|
||||||
$status = 1;
|
|
||||||
$us['status'] = 1;
|
|
||||||
}
|
|
||||||
$times = $us['times'] + 1;
|
|
||||||
$us['times']++;
|
|
||||||
$reward = metatable\getRewardInfo($user_db['act_id'], $id, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//更新奖励状态
|
|
||||||
$this->saveFesActDB($account_id, $user_db);
|
|
||||||
// if (empty($reward) || !$reward) {
|
|
||||||
// phpcommon\sendError(ERR_USER_BASE + 5, '没有这个奖励');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
$item_list = array();
|
|
||||||
$all_item_list = array();
|
|
||||||
$addreward = new classes\AddReward();
|
|
||||||
if ($reward && !empty($reward)) {
|
|
||||||
//领取奖励
|
|
||||||
for ($i = 0; $i < count($reward); $i++) {
|
|
||||||
$item_id = $reward[$i][0];
|
|
||||||
$num = $reward[$i][1];
|
|
||||||
$time = $reward[$i][2];
|
|
||||||
array_push($item_list, array(
|
|
||||||
'item_id' => $item_id,
|
|
||||||
'item_num' => $num,
|
|
||||||
'time' => $time,
|
|
||||||
));
|
|
||||||
$items = $addreward->addReward($item_id, $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'],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$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,
|
|
||||||
'times' => $times,
|
|
||||||
'status' => $status,
|
|
||||||
'id' => $id,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
Loading…
x
Reference in New Issue
Block a user