game2001api/webapp/controller/TeamController.class.php
wangwei01 17f9a521a3 1
2019-03-27 17:22:56 +08:00

132 lines
3.9 KiB
PHP

<?php
class teamController{
protected function getRedis($team_uuid)
{
$redis_conf = getRedisConfig(crc32($team_uuid));
$r = new phpcommon\Redis(array(
'host' => $redis_conf['host'],
'port' => $redis_conf['port'],
'passwd' => $redis_conf['passwd']
));
return $r;
}
public function createTeam()
{
$team_uuid = md5($_REQUEST['account_id']);
$team_db = array(
'team_uuid' => $team_uuid,
'auto_fill' => $_REQUEST['auto_fill'],
'member_list' => array(
array(
'idx' => 1,
'account_id' => $_REQUEST['account_id'],
'name' => $_REQUEST['name'],
'avatar_url' => $_REQUEST['avatar_url'],
)
));
$r = $this->getRedis($team_uuid);
$r->set(TEAMID_KEY . $team_uuid, json_encode($team_db));
$r->pexpire(TEAMID_KEY . $team_uuid, 1000 * 3600);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'team_uuid' => $team_uuid
));
}
public function teamInfo()
{
$r = $this->getRedis($team_uuid);
if(!$r){
echo 'is null';
}else{
$accountid = $_REQUEST['accout_id'];
$sessionid = $_REQUEST['session_id'];
$team_uuid = $_REQUEST['team_uuid'];
$user_db_str = $r->get(TEAMID_KEY . $team_uuid);
if (empty($user_db_str)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
return;
}
$user_db = json_decode($user_db_str, true);
if (empty($user_db)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
return;
}
$member_list = array();
foreach ($user_db['member_list'] as $member) {
array_push($member_list, array(
'idx' => $member['idx'],
'account_id' => $member['account_id'],
'name' => $member['name'],
'avatar_url' => $member['avatar_url'],
));
}
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'team_uuid' => $_REQUSET['team_uuid'],
'auto_fill' => $user_db['auto_fill'],
'member_list' => $member_list,
));
}
}
public function joinTeam()
{
$r = $this->getRedis($team_uuid);
if(!$r){
echo 'is null';
}else{
$user_db_str = $r->get(TEAMID_KEY.$team_uuid);
if(empty($user_db_str)){
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return;
}
$user_db = json_decode($user_db_str, true);
if(empty($user_db)){
phpcommon\sendError(ERR_USER_BASE + 1, 'session失效');
return;
}
}
}
public function updateTeam()
{
$r = $this->getRedis($team_uuid);
if(!$r){
echo 'is null';
}else{
$user_db_str = $r->get(TEAMID_KEY.$team_uuid);
if(empty($user_db_str)){
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return;
}
$user_db = json_decode($user_db_str, true);
if(empty($user_db)){
phpcommon\sendError(ERR_USER_BASE + 1,'session失效');
return;
}
$user_db['auto_fill'] = $_REQUEST['auto_fill'];
$redis->set(TEAMID_KEY.$team_uuid, json_encode($user_db));
$redis->pexpire(TEAMID_KEY.$team_uuid, 1000 * 3600);
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
));
}
}
?>