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.
jy-sdk/Application/Home/Controller/SiteGameController.class.php

290 lines
13 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Home\Controller;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class SiteGameController extends BaseController {
//站点申请
public function index($p=0,$game_name='',$recommend_status=''){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row = 10;
$model = D('SiteGame');
$map['tab_site_game.status'] = 1;
$map['tab_site_game.promote_id'] = PID;
if($game_name != ''){
$map['tab_site_game.game_name'] = array('like','%'.$game_name.'%');
$parameter['game_name'] = $game_name;
}
if($recommend_status != ''){
$map['tab_site_game.recommend_status'] = array('like','%'.$recommend_status.'%');;
$parameter['recommend_status'] = $recommend_status;
}
$data = $model->field('tab_site_game.*,sg.group_code,sg.group_name,sg.in_num')->join('tab_site_group as sg on sg.site_game_id = tab_site_game.id','left')->where($map)->order('is_top desc,top_time desc')->page($page,$row)->select();//
/* 查询记录总数 */
$count = $model->join('tab_site_group as sg on sg.site_game_id = tab_site_game.id','left')->where($map)->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('p',$p);
$this->assign('data',$data);
$this->meta_title = "游戏列表";
$this->display();
}
public function add(){
if(IS_POST){
$model = D('SiteGame');
$map['promote_id'] = PID;
$topData = $model->field('id,game_name')->where($map)->order('top_time desc')->find();
$topId = $topData['id'];
$_POST['game_name'] = str_replace(array('(安卓版)','(苹果版)'),'',$_POST['game_name']);
$_POST['recommend_status']=implode(',',$_POST['recommend_status']);
empty($_POST['description']) || $_POST['description'] = str_replace(array("\r\n", "\r", "\n"),'~~',$_POST['description']);
$sdk_version = $_POST['sdk_version'];
$game_name = $_POST['game_name'];
$condition['game_name'] = $game_name;
$condition['sdk_version'] = $sdk_version;
$condition['promote_id'] = PID;
$is_setting = $model->field('id,game_name')->where($condition)->order('top_time desc')->find();
if($is_setting)$this->error('添加失败:游戏已存在');
$res = $model->saveData();
if($res !== false){
$index = $model->field('id')->order('id desc')->find();
$SiteGroup = D('SiteGroup');$data['site_game_id'] = $index['id'];
foreach ($_POST as $k =>$v) {
if (strpos($k,'qq_') !== false) {
if (($k == 'qq_group_code' || $k == 'qq_pc_url') && empty($v)) {$data='';break;}
$data[str_replace('qq_','',$k)] = $v;
}
}
if ($data){
$data['game_name']=$_POST['game_name'];
$res = $SiteGroup->saveData2($data);
}
//添加后保持 置顶状态
$model->where(array('id'=> $topId ,'promote_id'=>PID))->save(array('top_time'=>time()));
$condition1['game_name'] = $game_name;
$condition1['sdk_version'] = $sdk_version == 1 ? 2 : 1;
$data1 = array(
'open_type' => $_POST['open_type'],
'version' => $_POST['version'],
'summary' => $_POST['summary'],
'description' => $_POST['description'],
'recommend_status' => $_POST['recommend_status'],
'game_icon' => $_POST['game_icon'],
'game_img' => $_POST['game_img'],
//'screenshot' => $_POST['screenshot'],
'game_bg_img' => $_POST['game_bg_img'],
);
$model->where($condition1)->save($data1);
$this->success('添加成功!');
}else{
$this->error('添加失败:'.$model->getError());
}
}else {
$map['promote_id'] = PID;
$map['pack_url'] = ['neq', ''];
$game = M('apply', 'tab_')->where($map)->select();
foreach ($game as $key=>$val){
$data = M('game', 'tab_')->where(array('id'=>$val['game_id']))->find();
if(!$data){
unset($game[$key]);
}
}
$this->meta_title = "添加游戏";
$this->assign('game', $game);
$this->display();
}
}
public function edit($id=0){
$model = D('SiteGame');
$SiteGroup = D('SiteGroup');
if(IS_POST){
$p = I("post.p",1,'intval');
if ($_POST['cate_type'] == 1) {
$_POST['game_name'] = str_replace(array('(安卓版)','(苹果版)'),'',$_POST['game_name']);
$_POST['recommend_status']=implode(',',$_POST['recommend_status']);
empty($_POST['description']) || $_POST['description'] = str_replace(array("\r\n", "\r", "\n"),'~~',$_POST['description']);
$res = $model->saveData();
$game = $model->where(array('id'=>$_POST['id']))->field("game_name,sdk_version,open_type,version,summary,description,recommend_status,game_icon,game_img,screenshot,game_bg_img")->find();
$condition1['game_name'] = $game['game_name'];
$condition1['sdk_version'] = $game['sdk_version'] == 1 ? 2 : 1;
$data1 = array(
'open_type' => $game['open_type'],
'version' => $game['version'],
'summary' => $game['summary'],
'description' => $game['description'],
'recommend_status' => $game['recommend_status'],
'game_icon' => $game['game_icon'],
'game_img' => $game['game_img'],
//'screenshot' => $game['screenshot'],
'game_bg_img' => $game['game_bg_img']
);
$model->where($condition1)->save($data1);
if($res !== false){
$this->success('基础信息保存成功!',U('SiteGame/index',array('p'=>$p)));
}else{
$this->error('基础信息保存失败:'.$model->getError());
}
} elseif ($_POST['cate_type']==2) {
foreach ($_POST as $k =>$v) {
if (strpos($k,'qq_') !== false) {
if (($k == 'qq_group_code' || $k == 'qq_pc_url') && empty($v)) {$data='';break;}
$data[str_replace('qq_','',$k)] = $v;
}
}
if ($data){
$res = $SiteGroup->saveData2($data);
}
if($res !== false){
$this->success('QQ群设置保存成功',U('SiteGame/index',array('p'=>$p)));
}else{
$this->error('QQ群设置保存失败:'.$model->getError());
}
} else {
$this->error('保存失败');
}
}else {
$p = I("get.p",1,'intval');
$this->assign('p',$p);
$map['promote_id'] = PID;
$map['pack_url'] = ['neq', ''];
$game = M('apply', 'tab_')->where($map)->select();
$data = $model->get_site_game_detail($id);
$qq_data = $SiteGroup->where(array('site_game_id'=>$data['id']))->find();
$this->assign('data',$data);
$this->assign('qq_data',$qq_data);
$this->assign('game', $game);
if ($data['game_source'] == 2) {
$this->assign('type', M('game_type','tab_')->field('id,type_name')->where(array('status'=>1,'status_show'=>1))->select());
}
$this->meta_title = "编辑游戏";
$this->display();
}
}
public function del(){
$id = $_POST['id'];
M()->startTrans();
$model = D('SiteGame');
$map['id'] = $id;
$map['promote_id'] = PID;
$game = $model->where($map)->delete();
$map = [];
$map['promote_id'] = PID;
$map['game_id'] = $id;
$serverdata = M('Site_server','tab_')->where($map)->find();
if($serverdata){
$server = D("SiteServer")->where($map)->delete();
}
if($game){
D('SiteGroup')->where(array('site_game_id'=>$id,'promote_id'=>PID))->delete();
$this->ajaxReturn(array('status'=>1,'msg'=>"删除成功"));exit;
// M()->commit();
}else{
$this->ajaxReturn(array('status'=>0,'msg'=>"删除失败"));exit;
// M()->rollback();
}
// $this->redirect('index');
}
public function game_detail($game_id){
if (!$game_id){
return '';
}
$Model = M('game','tab_');
$map['tab_game.id'] =$game_id;
$data = $Model
->field('tab_game.id,tab_game.game_name,tab_game.game_type_name as game_type,p.open_name,tab_game.game_size,g.version,category,tab_game.sdk_version,tab_game.game_type_id')
->join('left join tab_game_source g on g.game_id = tab_game.id ')
->join('left join tab_opentype p on tab_game.category = p.id')
->where($map)
->find();
if($data['category'] == 0){
$data['open_name'] = '公测';
}
if ($data['game_size']){
$data['game_size'] = substr($data['game_size'],0,-2);
}
$where['game_name'] = str_replace(array('(安卓版)','(苹果版)'),'',$data['game_name']);
$where['sdk_version'] = $data['sdk_version'] == 1 ? 2 : 1;
$game = M("site_game","tab_")->where($where)->field("game_type,open_type,version,summary,description,recommend_status,game_icon,game_img,screenshot,game_bg_img")->find();
if($game){
$data['open_type'] = $game['open_type'];
$data['version'] = $game['version'];
$data['summary'] = $game['summary'];
$data['description'] = $game['description'];
$data['recommend_status'] = explode(",",$game['recommend_status']);
$data['game_icon'] = $game['game_icon'];
$data['game_icon_src'] = get_cover($game['game_icon'],'path');
$data['game_img'] = $game['game_img'];
$data['game_img_src'] = get_cover($game['game_img'],'path');
$data['screenshot'] = $game['screenshot'];
$data['game_bg_img'] = $game['game_bg_img'];
$data['game_bg_img_src'] = get_cover($game['game_bg_img'],'path');
}
$this->ajaxReturn($data);
}
public function game_detail1($game_name){
if (!$game_name){
return '';
}
$where['game_name'] = $game_name;
$game = M("site_game","tab_")->where($where)->field("game_type,open_type,version,summary,description,recommend_status,game_icon,game_img,screenshot,game_bg_img,game_type_id")->find();
$data['open_type'] = $game['open_type'];
$data['version'] = $game['version'];
$data['summary'] = $game['summary'];
$data['description'] = $game['description'];
$data['recommend_status'] = explode(",",$game['recommend_status']);
$data['game_icon'] = $game['game_icon'];
$data['game_icon_src'] = get_cover($game['game_icon'],'path');
$data['game_img'] = $game['game_img'];
$data['game_img_src'] = get_cover($game['game_img'],'path');
$data['screenshot'] = $game['screenshot'];
$data['game_bg_img'] = $game['game_bg_img'];
$data['game_bg_img_src'] = get_cover($game['game_bg_img'],'path');
$data['game_type_id'] = $game['game_type_id'];
$this->ajaxReturn($data);
}
public function game_type() {
$data = M('game_type','tab_')->field('id,type_name')->where(array('status'=>1,'status_show'=>1))->select();
$this->ajaxReturn($data);
}
public function top($id){
$model = D('SiteGame');
$sql = "UPDATE `tab_site_game` SET `is_top`='0' WHERE `is_top` = '1'";
M()->execute($sql);
$map['id'] = $id;
$data['is_top'] = 1;
$model->where($map)->setField($data);
$this->redirect('SiteGame/index');
}
public function endtop($id){
$model = D('SiteGame');
$map['id'] = $id;//查询创建时间
$data['is_top'] = 0;
$model->where($map)->setField($data);
$this->redirect('SiteGame/index');
}
}