You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.3 KiB
PHP
106 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Home\Controller;
|
|
|
|
/**
|
|
* 前台首页控制器
|
|
* 主要获取首页聚合数据
|
|
*/
|
|
class SiteServerController extends BaseController {
|
|
|
|
public function add(){
|
|
if(IS_POST){
|
|
$model = D('SiteServer');
|
|
$res = $model->saveData();
|
|
if($res !== false){
|
|
$this->success('添加成功!');
|
|
}else{
|
|
$this->error('添加失败:'.$model->getError());
|
|
}
|
|
}else {
|
|
$game = D("SiteGame")->get_self_game();
|
|
$this->meta_title = "添加区服";
|
|
$this->assign('game', $game);
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
public function edit($id=0){
|
|
$model = D('SiteServer');
|
|
if(IS_POST){
|
|
$res = $model->saveData();
|
|
if($res !== false){
|
|
$this->success('添加成功!');
|
|
}else{
|
|
$this->error('添加失败:'.$model->getError());
|
|
}
|
|
}else {
|
|
$game = D("SiteGame")->get_self_game();
|
|
$data = $model->where(['promote_id'=>PID])->find($id);
|
|
$game_source = D('SiteGame')->field('game_source')->where(array('id'=>$data['game_id']))->find();
|
|
$data['game_source'] = $game_source['game_source'];
|
|
$this->assign('data',$data);
|
|
$this->assign('game', $game);
|
|
$this->meta_title = "编辑区服";
|
|
$this->display();
|
|
}
|
|
}
|
|
|
|
public function del($id){
|
|
$model = D('SiteServer');
|
|
$map['id'] = $id;
|
|
$map['promote_id'] = PID;
|
|
$res = $model->where($map)->delete();
|
|
if($res){
|
|
$this->ajaxReturn(array('status'=>1,'msg'=>"删除成功"));exit;
|
|
}else{
|
|
$this->ajaxReturn(array('status'=>0,'msg'=>"删除失败"));exit;
|
|
}
|
|
}
|
|
public function index($p=0,$server_name='',$game_name=''){
|
|
$page = intval($p);
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
$row = 10;
|
|
$map['promote_id'] = PID;
|
|
$map['status'] = 1;
|
|
if($server_name != ''){
|
|
$map['server_name'] = array('like','%'.$server_name.'%');
|
|
$parameter['server_name'] = $server_name;
|
|
}
|
|
if($game_name != ''){
|
|
$map['game_name'] = array('like','%'.$game_name.'%');
|
|
$parameter['game_name'] = $game_name;
|
|
}
|
|
$game=D("SiteGame")->field('id,game_name')->distinct(true)->where($map)->select();
|
|
foreach ($game as $k => $v) {
|
|
if(empty($v['id'])){
|
|
unset($game[$k]);
|
|
}
|
|
if(!empty($v['id'])){
|
|
$gameName[$k] = $v['id'];
|
|
}
|
|
}
|
|
$SiteServer = D('SiteServer');
|
|
if(!empty($gameName)){
|
|
$map['game_id'] = array('in',implode(',',$gameName));
|
|
}
|
|
if(!empty($game)){
|
|
$data = $SiteServer->where($map)->page($page,$row)->select();
|
|
$count = $SiteServer->field('id')->where($map)->select();
|
|
$count =count($count);
|
|
|
|
|
|
$parameter['p']=I('get.p',1);
|
|
$parameter['row']=I('get.row');
|
|
|
|
|
|
$page = set_pagination($count,$row,$parameter);
|
|
if($page) {$this->assign('_page', $page);}
|
|
|
|
}
|
|
$this->assign('data',$data);
|
|
$this->meta_title = "区服列表";
|
|
$this->display();
|
|
}
|
|
|
|
} |