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.

134 lines
5.4 KiB
PHP

<?php
namespace Mobile\Controller;
use Think\Controller;
/**
* 首页
*/
class CategoryController extends BaseController {
public function index(){
$model = M('GameType','tab_');
//添加过滤条件,去除重复统计
$devices = get_devices_type();
$where['t.status_show'] = 1;
$where['g.online_status'] = 1;
$data = $model
->alias("t")
->field("t.id,t.icon,t.type_name,count(distinct(g.relation_game_id)) as game_num")
->join("left join tab_game as g on g.game_type_id = t.id and g.game_status = 1 and g.apply_status =1 and g.online_status=1 and g.sdk_version like '%$devices%' and g.display_site like '%".DISPLAY_SITE."%' ") //and g.sdk_version = {$version}
->where($where)
->group("t.id")
->select();
$this->assign('data',$data);
$this->assign('mate_title','游戏分类');
$this->display();
}
public function categorydetail(){
$page = $page ? $page : 1; //默认显示第一页数据
$row = C('LIST_ROWS');
$id = $_REQUEST['id'];//I('request.id');
$name = I('post.name');
$model = M('Game','tab_');
$promote_id = empty(PROMOTE_ID) ? 0 : PROMOTE_ID;
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
$time = NOW_TIME;
$devices = get_devices_type();
$where['g.game_type_id'] = $id;
$where['g.game_status'] = 1;
$where['g.display_site'] = ['like','%'.DISPLAY_SITE.'%'];
$where['g.apply_status'] = 1;
$where['g.online_status'] = 1;
$where['g.sdk_version'] = array('like','%'.$devices.'%');
if(trim($name)){
$where['g.relation_game_name'] = ['like','%'.$name.'%'];
}
if(is_cache() &&S('mobile_game_data'.$devices.'_'.$id) &&$name=='' ){
$data=S('mobile_game_data'.$devices.'_'.$id);
}else{
//去除重复数据
$data = $model
->alias('g')
->field('g.id,g.sort,g.relation_game_id,g.relation_game_name,g.sdk_version,g.down_port,g.id as game_id,g.game_name,g.icon,g.dow_num,g.marking,g.game_size,g.game_score,g.dow_status,g.features,g.and_dow_address,g.ios_dow_address,g.add_game_address,g.ios_game_address,g.bind_recharge_discount as discount,s.pack_name,IFNULL(r.ratio,0) as ratio')
//游戏原包
->join("left join tab_game_source as s on s.game_id = g.id")
//返利
->join("left join tab_rebate r on r.game_id = g.id {$rebate_join} and r.starttime <{$time} and
(endtime = 0 or endtime > {$time})")
->where($where)
->page($page, $row)
->order('g.sort desc,g.id desc')
->group("g.relation_game_id")
->select();
foreach ($data as $key => $val){
$data[$key]['icon'] = get_cover($val['icon'],'path');
$data[$key]['game_score'] = $val['game_score'];
$data[$key]['game_size'] = empty($val['game_size'])?"0MB":$val['game_size'];
if(!is_mobile_request()){
$data[$key]['relation_game_name'] = $val['game_name'];
}
}
if(is_cache() &&$name=='' ){
S('mobile_game_data'.$devices.'_'.$id,$data);
}
}
$this->assign('data',$data);
$this->assign('page',$page);
$this->assign('name',$name);
$this->assign('type',$id);
$this->assign('mate_title',get_game_category_name($id));
$this->display();
}
public function ajaxlists() {
$id = I('post.type');
$p = I('post.p');
$status = 0;
$row = C('LIST_ROWS');
$model = M('Game','tab_');
$devices = get_devices_type();
$promote_id = empty(PROMOTE_ID) ? 0 : PROMOTE_ID;
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
$time = NOW_TIME;
$where['g.game_type_id'] = I('request.type');
$where['g.game_status'] = 1;
$where['g.apply_status'] = 1;
$where['g.online_status'] = 1;
$where['g.sdk_version'] = array('like','%'.$devices.'%');
$data = $model
->alias('g')
->field('g.id,g.sort,g.relation_game_id,g.relation_game_name,g.sdk_version,g.down_port,g.id as game_id,g.game_name,g.icon,g.dow_num,g.marking,g.game_size,g.game_score,g.dow_status,g.features,g.and_dow_address,g.ios_dow_address,g.add_game_address,g.ios_game_address,g.bind_recharge_discount as discount,s.pack_name,IFNULL(r.ratio,0) as ratio')
//游戏原包
->join("left join tab_game_source as s on s.game_id = g.id")
//返利
->join("left join tab_rebate r on r.game_id = g.id {$rebate_join} and r.starttime < {$time} and (endtime = 0 or endtime > {$time})")
->where($where)
->page($p, $row)
->order('g.sort desc,g.id desc')
->group("g.relation_game_id")
->select();
foreach ($data as $key => $val){
$data[$key]['icon'] = get_cover($val['icon'],'path');
$data[$key]['game_score'] = round($val['game_score'] / 2);
$data[$key]['game_size'] = empty($val['game_size'])?"0MB":$val['game_size'];
if(!is_mobile_request()){
$data[$key]['relation_game_name'] = $val['game_name'];
}
}
if (!empty($data) && is_array($data)) {$status=1;}
echo json_encode(array('status'=>$status,'page'=>$p,'data'=>$data));
}
}