jsonResult('',0,'已经关闭游戏角色收集'); } } /** * 角色信息收集接口(暂未使用)) * PS: 接口改版过,需要客户端把角色管理相关接口统一使用这个; */ public function index(){ $input = $this->input; $role_action = $this->input('role_action'); $partyname = $this->input('partyname', ""); $imeil = trim($this->input('imeil')); // 角色事件:create=创角, enter=进入服务器, up_level=角色升级 if(!in_array($role_action, ['create', 'enter', 'up_level'])){ $this->jsonResult('', -110, '事件类型有误!'); } $channelId = model('Subaccount')->where(['game_id' => $input['gameid'], 'member_id' => $input['userid']])->value('channel_id'); // 子账户的 if ($channelId == 0) { $channelId = model('common/Members')->where('id', $input['userid'])->value('channel_id'); // 主账户的 } $serverid = repairRoleServerid($input['gameid'], $input['gameid']); $cahce_key = 'role_action:'.$role_action .':'. md5($input['userid'] . $input['gameid'] . $serverid . $input['roleid'] . $channelId); if($role_action == 'up_level'){ if (Cache::get($cahce_key)) { $this->jsonResult('', 200, '更新角色成功#cache!'); } else { Cache::set($cahce_key, '1', 3600); } } $update_time = $create_time = NOW_TIMESTAMP; $roleInfoModel = new roleInfo(); $result = $roleInfoModel->insert([ 'role_action' => $input['role_action'], 'userid' => $input['userid'], 'channel_id' => $channelId, 'servername' => $input['servername'], 'gameid' => $input['gameid'], 'serverid' => $serverid, 'roleid' => $input['roleid'], 'rolename' => $input['rolename'], 'viplevel' => $input['viplevel'], 'rolelevel' => $input['rolelevel'], 'rolebalance' => $input['rolebalance'], 'partyname' => $partyname, 'ip' => request()->ip(), 'imeil' => $imeil, 'create_time' => $create_time, 'update_time' => $update_time ]); if($result){ if($this->saveGameServer($input['userid'], $input['gameid'], $imeil,'role')){ $this->jsonResult('',200,'操作成功!!'); } else { $this->jsonResult('',-111,'添加操作失败!'); } } else { $this->jsonResult('',200,'操作成功!!!'); } } /** * 新增角色信息 */ public function add() { $userid = $this->input('userid'); $servername = $this->input('servername'); $gameid = $this->input('gameid'); $serverid = $this->input('serverid'); $roleid = $this->input('roleid'); $rolename = $this->input('rolename'); $viplevel = $this->input('viplevel'); $rolelevel = $this->input('rolelevel'); $rolebalance = $this->input('rolebalance'); $partyname = $this->input('partyname', ""); $update_time = $create_time = NOW_TIMESTAMP; $imeil = trim($this->input('imeil')); //手机imeil码 //游戏ID不能为空 if (empty($gameid)) { $this->jsonResult('', 0, '游戏ID不能为空'); } if (empty($serverid)) { $this->jsonResult('', 0, '游戏区服ID不能为空'); } elseif (empty($userid) || empty($servername) || empty($roleid) || empty($rolename)) { $this->jsonResult('', 0, '角色参数不全'); } // $channelId = getChannelId($userid); // 登陆渠道的 $channelId = model('Subaccount')->where(['game_id' => $gameid, 'member_id' => $userid])->value('channel_id'); // 子账户的 if ($channelId == 0) { $channelId = model('common/Members')->where('id', $userid)->value('channel_id'); // 主账户的 // setChannelId($userid,$channelId); } $serverid = repairRoleServerid($gameid, $serverid); // $cahce_key = md5($userid . $servername . $gameid . $serverid . $roleid . $rolename . $viplevel . $rolelevel . $rolebalance . $partyname . $channelId); $cahce_key = 'Role_add:'.md5($gameid.$userid.$serverid.$roleid); if (Cache::get($cahce_key)) { $this->jsonResult('', 1, '添加角色成功#cache!!'); } else { Cache::set($cahce_key, '1', 60); } // 角色事件:create=创角, enter=进入服务器, up_level=角色升级, offline=角色下线 $role_action = 'create'; $roleInfoModel = new roleInfo(); $info = $roleInfoModel->where(['gameid' => $gameid, 'userid' => $userid, 'roleid' => $roleid, 'serverid' => $serverid])->find(); if($info){ // $this->jsonResult('',1,'添加角色成功!'); $role_action = 'enter'; } $result = $roleInfoModel->create([ 'userid' => $userid, 'channel_id' => $channelId, 'servername' => $servername, 'gameid' => $gameid, 'serverid' => $serverid, 'roleid' => $roleid, 'rolename' => $rolename, 'viplevel' => $viplevel, 'rolelevel' => $rolelevel, 'rolebalance' => $rolebalance, 'partyname' => $partyname, 'ip' => request()->ip(), 'imeil' => $imeil, 'create_time' => $create_time, 'update_time' => $update_time, 'role_action' => $role_action, ]); if($result){ if($this->saveGameServer($userid,$gameid,$imeil,'role')){ $this->jsonResult('',1,'添加角色成功!'); }else{ $this->jsonResult('',0,'添加角色失败,更新区服失败!'); } }else{ $this->jsonResult('',0,'添加角色失败!'); } } /** * 更新角色信息(cp那边roleid等有可能为空,所以改成直接插入数据库) */ public function update() { $userid = $this->input('userid'); $roleid = $this->input('roleid'); $gameid = $this->input('gameid'); $serverid = $this->input('serverid'); $servername = $this->input('servername'); $rolename = $this->input('rolename', ''); $viplevel = $this->input('viplevel', ''); $rolelevel = $this->input('rolelevel', ''); $rolebalance = $this->input('rolebalance', ''); $partyname = $this->input('partyname', ''); $imeil = trim($this->input('imeil')); //手机imeil码 //游戏ID不能为空 if (empty($gameid)) { $this->jsonResult('',0,'游戏ID不能为空'); } if (empty($serverid)) { $this->jsonResult('',0,'游戏区服ID不能为空'); } elseif(empty($userid) || empty($servername) || empty($roleid) || empty($rolename)){ $this->jsonResult('', 0, '角色参数不全'); } // $channelId = getChannelId($userid); // 登陆渠道的 $channelId = model('Subaccount')->where(['game_id' => $gameid, 'member_id' => $userid])->value('channel_id'); // 子账户的 if ($channelId == 0) { $channelId = model('common/Members')->where('id', $userid)->value('channel_id'); // 主账户的 // setChannelId($userid,$channelId); } $serverid = repairRoleServerid($gameid, $serverid); // $cahce_key = md5($userid . $servername . $gameid . $serverid . $roleid . $rolename . $viplevel . $rolelevel . $rolebalance . $partyname . $channelId); $cahce_key = md5($gameid.$userid.$serverid.$roleid); if (Cache::get(':Role_update:' . $cahce_key)) { $this->jsonResult('', 1, '更新角色信息成功!!'); } else { Cache::set(':Role_update:' . $cahce_key, '1', 60); } $roleInfoModel = new roleInfo(); $result = $roleInfoModel->insert([ 'userid' => $userid, 'channel_id' =>$channelId, 'servername' => $servername, 'gameid' => $gameid, 'serverid' => $serverid, 'roleid' => $roleid, 'rolename' => $rolename, 'viplevel' => $viplevel, 'rolelevel' => $rolelevel, 'rolebalance' => $rolebalance, 'partyname' => $partyname, 'ip' => request()->ip(), 'imeil' => $imeil, 'create_time' => NOW_TIMESTAMP, 'update_time' => NOW_TIMESTAMP, 'role_action' => 'up_level', ]); if($result){ if($this->saveGameServer($userid,$gameid,$imeil,'role')){ $this->jsonResult('',1,'更新角色信息成功!'); }else{ $this->jsonResult('',0,'更新角色信息失败,更新区服失败!'); } }else{ $this->jsonResult('',0,'更新角色信息失败!'); } } }