game2004api/webapp/controller/FriendController.class.php
aozhiwei 1011f703a1 1
2020-12-04 11:55:34 +08:00

310 lines
11 KiB
PHP

<?php
require 'classes/Quest.php';
require 'classes/AddReward.php';
class FriendController{
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' => 'gamedb2004_' . $mysql_conf['instance_id']
));
return $conn;
}
protected function getAllMysql()
{
global $g_conf_mysql_cluster;
$conns = array();
foreach ($g_conf_mysql_cluster as $mysql_conf) {
$conn = new phpcommon\Mysql(array(
'host' => $mysql_conf['host'],
'port' => $mysql_conf['port'],
'user' => $mysql_conf['user'],
'passwd' => $mysql_conf['passwd'],
'dbname' => 'gamedb2004_' . $mysql_conf['instance_id']
));
array_push($conns, $conn);
}
return $conns;
}
protected function getSeasonPoint($seaPoint_id)
{
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
$seaPoint_meta = getSeasonPointConfig($seaPoint_meta_table, $seaPoint_id);
$seaPoint = array(
'id' => $seaPoint_meta['id'],
'min' => $seaPoint_meta['min_point'],
'max' => $seaPoint_meta['max_point'],
'des' => $seaPoint_meta['des'],
);
return $seaPoint;
}
public function selectUserInfo()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->getMysql($account_id);
if(!$conn){
phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在');
return;
}
$row = $conn->execQueryOne('SELECT accountid, user_name, avatar_url, game_times, win_times, kill_his, kills, harm_his, harm, integral, modify_time, alive_time, add_HP FROM user WHERE accountid=:account_id;',
array(
':account_id' => $account_id,
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在');
return;
}
$rank = 1;
$seaPoint_meta_table = require('../res/seasomPoint@seasomPoint.php');
for ($ii = 1; $ii <= count($seaPoint_meta_table); $ii++) {
$seaPoint = $this->getSeasonPoint($ii);
if ($row['integral'] >= $seaPoint['min'] && $row['integral'] <= $seaPoint['max']
|| $seaPoint['max'] == -1) {
$rank = $ii;
break;
}
}
$avatar_url = $row['avatar_url'];
if (phpcommon\extractChannel($row['accountid']) != 6001) {
$avatar_url = "https://wx.qlogo.cn/mmopen/vi_32/q4oRsMFYBwPEVAeVI7tiasWSqaibr0GPQia432JhibGRYhqqEJofpWDYxJPq6q0hQ0j7icdACdHL78hrjYYHSjZQ3YA/132";
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'accountid' => $row['accountid'],
'user_name' => $row['user_name'],
'avatar_url' => $avatar_url,
'game_times' => $row['game_times'],
'win_times' => $row['win_times'],
'kill_his' => $row['kill_his'],
'kills' => $row['kills'],
'harm_his' => $row['harm_his'],
'harm' => $row['harm'],
'level' => $rank,
'modify_time' => $row['modify_time'],
'alive_time' => $row['alive_time'],
'add_HP' => $row['add_HP'],
));
}
public function selectUser()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->getMysql();
if(!$conn){
phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在');
return;
}
$row = $conn->execQueryOne('SELECT accountid FROM user WHERE accountid=:account_id;',
array(
':account_id' => $account_id,
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在');
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
public function selectUserByName()
{
$account_id = $_REQUEST['account_id'];
$conns = $this->getAllMysql();
if (!$conns) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$accountid = '';
$user_name = $_REQUEST['user_name'];
foreach ($conns as $conn) {
$row = $conn->execQueryOne('SELECT accountid FROM user WHERE user_name=:user_name;',
array(
':user_name' => $user_name,
));
$flag = 0;
if (!$row) {
// phpcommon\sendError(ERR_USER_BASE + 2, '玩家不存在');
// return;
$robot_meta_cluster = require('../res/robot@robot.php');
for ($i = 0; $i < count($robot_meta_cluster); $i++) {
$robot_id = 10000 + $i;
$robot_meta = getRobotConfig($robot_meta_cluster, $robot_id);
if ($robot_meta['name'] == $user_name) {
$flag = 1;
$accountid = '6000_2004_robot' . $i;
break;
}
}
if ($flag == 0) {
phpcommon\sendError(ERR_USER_BASE + 2, '玩家不存在');
return;
} else {
break;
}
} else {
$accountid = $row['accountid'];
break;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'fri_accountid' => $accountid,
));
}
public function changeRoleInfo()
{
$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;
}
$user_name = $_REQUEST['user_name'];
$avatar_url = $_REQUEST['avatar_url'];
$ret = $conn->execScript('UPDATE user SET user_name=:user_name, avatar_url=:avatar_url, modify_time=:modify_time, create_user=1 ' .
' WHERE accountid=:accountid;',
array(
':user_name' => $user_name,
':avatar_url' => $avatar_url,
':modify_time' => time(),
':accountid' => $account_id
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'user_name' => $user_name,
'avatar_url' => $avatar_url,
'create_user' => 1,
));
}
public function selRepeatName()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$conns = $this->getAllMysql();
if (!$conns) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$user_name = $_REQUEST['user_name'];
foreach ($conns as $conn) {
$row = $conn->execQueryOne('SELECT accountid FROM user WHERE accountid!=:account_id AND user_name=:user_name;',
array(
':account_id' => $account_id,
':user_name' => $user_name,
));
if ($row) {
phpcommon\sendError(ERR_USER_BASE + 2, '名字重名');
return;
}
}
$robot_meta_cluster = require('../res/robot@robot.php');
for ($i = 0; $i < count($robot_meta_cluster); $i++) {
$robot_id = 10000 + $i;
$robot_meta = getRobotConfig($robot_meta_cluster, $robot_id);
if ($robot_meta['name'] == $user_name) {
phpcommon\sendError(ERR_USER_BASE + 2, '名字重名');
return;
}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
public function rechargeDiamond()
{
$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=:account_id;',
array(
':account_id' => $account_id,
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '玩家不存在');
return;
}
$num = $_REQUEST['num'];
$ret = $conn->execScript('UPDATE user SET diamond_num=:diamond_num, modify_time=:modify_time ' .
' WHERE accountid=:accountid;',
array(
':modify_time' => time(),
':accountid' => $account_id,
':diamond_num' => $num + $row['diamond_num'],
));
if (!$ret) {
die();
return;
}
$item_list = array();
$all_item_list = array();
array_push($item_list, array(
'item_id' => 10003,
'item_num' => $num,
'time' => 0,
));
array_push($all_item_list, array(
'item_id' => 10003,
'item_num' => $num,
'time' => 0,
));
$diamond_num = $num + $row['diamond_num'];
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'diamond_nums' => $diamond_num,
'item_list' => $item_list,
'all_item_list' => $all_item_list,
));
}
}
?>