342 lines
12 KiB
PHP
342 lines
12 KiB
PHP
<?php
|
|
|
|
require 'classes/AddReward.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' => 'gamedb2003_' . $mysql_conf['instance_id']
|
|
));
|
|
return $conn;
|
|
}
|
|
|
|
protected function getRedis($shop_uuid)
|
|
{
|
|
$redis_conf = getRedisConfig(crc32($shop_uuid));
|
|
$r = new phpcommon\Redis(array(
|
|
'host' => $redis_conf['host'],
|
|
'port' => $redis_conf['port'],
|
|
'passwd' => $redis_conf['passwd']
|
|
|
|
));
|
|
return $r;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public function getKefuReward()
|
|
{
|
|
$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;
|
|
}
|
|
$mail_id = $_REQUEST['mail_ids'];
|
|
|
|
$url = '';
|
|
if (SERVER_ENV == _ONLINE) {
|
|
$url = 'https://gamemail.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&';
|
|
} else {
|
|
$url = 'https://gamemail-test.kingsome.cn/webapp/index.php?c=Mail&a=getAttachment&';
|
|
}
|
|
$params = array(
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'mail_ids' => $mail_id,
|
|
'session_id' => $_REQUEST['session_id']
|
|
);
|
|
if (!phpcommon\HttpClient::get($url, $params, $response)) {
|
|
phpcommon\sendError(ERR_RETRY, '系统繁忙');
|
|
return;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT kefu_status FROM user WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
if ($row['kefu_status'] != 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 3, '客服奖励已领取');
|
|
die();
|
|
return;
|
|
}
|
|
$item_list = array();
|
|
$item_id = 0;
|
|
$item_num = 0;
|
|
$data = json_decode($response, true);
|
|
$errcode = $data['errcode'];
|
|
$errmsg = $data['errmsg'];
|
|
if ($errcode == 0) {
|
|
foreach($data['attachments'] as $kefu){
|
|
$item_id = $kefu['itemid'];
|
|
$item_num = $kefu['itemnum'];
|
|
}
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item_id, $item_num, $account_id);
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num,
|
|
));
|
|
|
|
//保存客服奖励
|
|
$kefureward_uuid = 'game2003api_kefureward_uuid:' . md5($_REQUEST['account_id']);
|
|
$kefureward_list = array();
|
|
$r = $this->getRedis($kefureward_uuid);
|
|
$user_db_str = $r->get($kefureward_uuid);
|
|
if (!$r) {
|
|
die();
|
|
return;
|
|
}
|
|
if (empty($user_db_str)) {
|
|
$kefureward_db = array(
|
|
'kefureward_uuid' => $kefureward_uuid,
|
|
'kefureward_list' => $item_list,
|
|
);
|
|
$r -> set($kefureward_uuid, json_encode($kefureward_db));
|
|
$r -> pexpire($kefureward_uuid, 1000 * 7200);
|
|
} else {
|
|
$kefureward_db = array(
|
|
'kefureward_uuid' => $kefureward_uuid,
|
|
'kefureward_list' => $item_list,
|
|
);
|
|
$r -> set($kefureward_uuid, json_encode($kefureward_db));
|
|
$r -> pexpire($kefureward_uuid, 1000 * 7200);
|
|
}
|
|
//更新状态
|
|
$ret = $conn->execScript('UPDATE user SET kefu_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time(),
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => $errcode,
|
|
'errmsg' => $errmsg,
|
|
'item_list' => $item_list
|
|
));
|
|
}
|
|
|
|
public function collectReward()
|
|
{
|
|
$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;
|
|
}
|
|
$type = $_REQUEST['type'];
|
|
switch ($type)
|
|
{
|
|
case 1: //收藏
|
|
$this->updateCollectStatus($account_id);
|
|
$item_list = $this->rewardList(COLLECT_REWARDS, $account_id);
|
|
break;
|
|
case 2: //浮窗
|
|
$this->updateWindowStatus($account_id);
|
|
$item_list = $this->rewardList(WINDOWS_REWARDS, $account_id);
|
|
break;
|
|
case 3: //限时
|
|
$this->updateDailyReward($account_id);
|
|
$item_list = $this->rewardList(FREE_DIAMOND, $account_id);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list
|
|
));
|
|
}
|
|
|
|
public function updateDailyReward($account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$ret = $conn->execScript('UPDATE user SET daily_reward=daily_reward + 1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':modify_time' => time(),
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function updateCollectStatus($account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':modify_time' => time(),
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function updateWindowStatus($account_id)
|
|
{
|
|
$conn = $this->getMysql($account_id);
|
|
$ret = $conn->execScript('UPDATE user SET collect_status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid;',
|
|
array(
|
|
':modify_time' => time(),
|
|
':accountid' => $account_id
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
}
|
|
}
|
|
|
|
public function rewardList($key, $account_id)
|
|
{
|
|
$item_list = array();
|
|
$p = $this->getParameter($key);
|
|
$item_id = 10003;
|
|
$item_num = $p['value'];
|
|
$addreward = new classes\AddReward();
|
|
$addreward->addReward($item_id, $item_num, $account_id);
|
|
array_push($item_list, array(
|
|
'item_id' => $item_id,
|
|
'item_num' => $item_num
|
|
));
|
|
return $item_list;
|
|
}
|
|
|
|
public function tryPlayInfo()
|
|
{
|
|
$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;
|
|
}
|
|
$play_list = array();
|
|
$rows = $conn->execQuery('SELECT appid, status FROM try_play WHERE accountid=:accountid;',
|
|
array(
|
|
':accountid' => $account_id
|
|
));
|
|
if ($rows) {
|
|
foreach ($rows as $row) {
|
|
array_push($play_list, array(
|
|
'appid' => $row['appid'],
|
|
'status' => $row['status']
|
|
));
|
|
}
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'play_list' => $play_list
|
|
));
|
|
}
|
|
|
|
public function tryPlayReward()
|
|
{
|
|
$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);
|
|
$appid = $_REQUEST['appid'];
|
|
if (!$conn) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
|
|
return;
|
|
}
|
|
$play_list = array();
|
|
$row = $conn->execQueryOne('SELECT status FROM try_play WHERE accountid=:accountid AND appid=:appid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':appid' => $appid
|
|
));
|
|
if (!$row) {
|
|
//插入
|
|
$ret = $conn->execScript('INSERT INTO try_play(accountid, appid, status, create_time, modify_time) ' .
|
|
' VALUES(:account_id, :appid, :status, :create_time, :modify_time) ' .
|
|
' ON DUPLICATE KEY UPDATE accountid=:account_id, appid=:appid, status=:status, modify_time=:modify_time;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':ach_id' => $appid,
|
|
':status' => 1,
|
|
':create_time' => time(),
|
|
':modify_time' => time()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
} else {
|
|
//更新
|
|
$ret = $conn->execScript('UPDATE try_play SET status=1, modify_time=:modify_time ' .
|
|
' WHERE accountid=:accountid AND appid=:ach_appid;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':modify_time' => time(),
|
|
':appid' => $appid
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
//获得奖励
|
|
$item_list = $this->rewardList(NEWGAME_REWARDS, $account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'play_list' => $play_list
|
|
));
|
|
}
|
|
|
|
}
|
|
?>
|