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.

666 lines
27 KiB
PHTML

5 years ago
<?php
namespace Mobile\Controller;
use Think\Controller;
use App\Model\AdvModel;
/**
* 首页
*/
class IndexController extends BaseController {
protected function _initialize(){
$config = api('Config/lists');
C($config);
}
public function index(){
$adv = get_adv_data(['in','wap_index,and_wap_index_gift,ios_wap_index_gift,wap_index_gg,wap_index_zx,wap_index_activity']);
foreach ($adv as $key => $value) {
if($value['name']=='wap_index'){
$wap_index[]=$value;
unset($adv[$key]);
}
if($value['name']=='and_wap_index_gift'){
$and_wap_index_gift=$value;
unset($adv[$key]);
if($and_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $and_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$and_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='ios_wap_index_gift'){
$ios_wap_index_gift=$value;
unset($adv[$key]);
if($ios_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $ios_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$ios_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='wap_index_gg'){
$wap_index_gg=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_zx'){
$wap_index_zx=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_activity'){
$wap_index_activity=$value;
unset($adv[$key]);
}
}
5 years ago
foreach ($wap_index as $k1 => $v1) {
if(strpos($v1['url'],'http')===false){
$wap_index[$k1]['url'] = U('Game/detail',array('id'=>$v1['url']));
}
}
$this->assign('wap_index',$wap_index);
if(get_devices_type()==1){
$this->assign('wap_index_gift',$and_wap_index_gift);
}elseif(get_devices_type()==2){
$this->assign('wap_index_gift',$ios_wap_index_gift);
}else{
$this->assign('wap_index_gift',$and_wap_index_gift['id']>$ios_wap_index_gift['id']?$and_wap_index_gift:$ios_wap_index_gift);
}
if(strpos($wap_index_gg['url'],'http')===false){
$wap_index_gg['url'] = U('Game/detail',array('id'=>$wap_index_gg['url']));
}
if(strpos($wap_index_zx['url'],'http')===false){
$wap_index_zx['url'] = U('Game/detail',array('id'=>$wap_index_zx['url']));
}
if(strpos($wap_index_activity['url'],'http')===false){
$wap_index_activity['url'] = U('Game/detail',array('id'=>$wap_index_activity['url']));
}
$this->assign('wap_index_gg',$wap_index_gg);
$this->assign('wap_index_zx',$wap_index_zx);
$this->assign('wap_index_activity',$wap_index_activity);
$promote_id = empty(PROMOTE_ID) ? 0 : PROMOTE_ID;
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
$time = NOW_TIME;
$model = M('Game','tab_');
//热门游戏
$devices = get_devices_type();
$game_h['g.recommend_status'] = 2;
$game_h['g.game_status'] = 1;
$game_h['g.display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$game_h['g.sdk_version'] = array('like','%'.$devices.'%');
if(is_cache() && S('moblie_index_hot')){
$hot=S('moblie_index_hot');
}else{
$hot = $model
->alias('g')
->field('g.id,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,IF(g.down_port=1,s.file_size,g.game_address_size) as 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.game_address_size,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($game_h)
->page(0,7)
->order('g.sort desc,g.id desc')
->select();
if(is_cache()){
S('moblie_index_hot',$hot);
}
foreach ($hot as $key => $value) {
if(!is_mobile_request()){
$hot[$key]['relation_game_name'] = $value['game_name'];
}
}
}
$this->assign('hot',$hot);
$media_gg = $this->newzixun('notice_wap');
$media_activity = $this->newzixun('activity_wap');
$media_zx = $this->newzixun('news_wap');
$this->assign('media_gg',$media_gg);
$this->assign('media_activity',$media_activity);
$this->assign('media_zx',$media_zx);
$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(is_cache() && S('moblie_rank_new')){
$ranknew=S('moblie_rank_new');
}else{
$where['g.recommend_status'] = 3;
$order = 'g.sort desc,g.id desc';
$ranknew = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_new',$ranknew);
}
}
$this->assign('ranknew',$ranknew);
if(is_cache() && S('moblie_rank_rec')){
$rankrec=S('moblie_rank_rec');
}else{
$where['g.recommend_status'] = 1;
$order = 'g.sort desc,g.id desc';
$rankrec = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_rec',$rankrec);
}
}
$this->assign('rankrec',$rankrec);
if(is_cache() && S('moblie_rank_hot')){
$rankhot=S('moblie_rank_hot');
}else{
$where['g.recommend_status'] = 2;
$order = 'g.sort desc,g.id desc';
$rankhot = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_hot',$rankhot);
}
}
$this->assign('rankhot',$rankhot);
if(is_cache() && S('moblie_rank_dow')){
$rankdow=S('moblie_rank_dow');
}else{
$order = 'g.dow_num desc,g.id desc';
unset($where['g.recommend_status']);
$rankdow = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_dow',$rankdow);
}
}
$this->assign('rankdow',$rankdow);
//礼包
$this->gift();
//开服
$this->server();
//热门游戏(实质为推荐游戏)
$this->recommend();
$this->display();
}
private function recommend(){
$devices = get_devices_type();
$model = array(
'm_name'=>'Game',
'prefix'=>'tab_',
'map' =>array('game_status'=>1,'recommend_status'=>1,'sdk_version'=>$devices,'display_site'=>['like','%' . DISPLAY_SITE . '%']),
'field' =>'*,min(id) as id',
'order' =>'sort desc,id desc',
'group' =>'relation_game_id',
'limit' =>'0,4',
);
if(is_cache() && S('index_reco')){
$reco=S('index_reco');
}else{
$reco = self::list_data($model);
if(is_cache() ){
S('index_reco',$reco);
}
}
$reco=game_merge($reco,$model['map']);
// var_dump($reco);die;
$this->assign('recommend',$reco);
}
protected function list_data($model){
$game = M($model['m_name'],$model['prefix']);
$map = $model['map'];
$data = $game
->field($model['field'])
->limit($model['limit'])
->where($map)
->group($model['group'])
->order($model['order'])
->select();
return $data;
}
private function server(){
$devices = get_devices_type();
$time = time();
$where['start_time'] = ['lt',$time];
$order = 'start_time desc';
$where['show_status'] = 1;
$where['g.sdk_version'] = array('like','%'.$devices.'%');
$lists = D("Server")
->alias('ser')
->field('server_name,start_time,ser.game_name,sor.pack_name,ser.game_id,sor.file_url,g.sdk_version,g.icon,g.down_port,g.and_dow_address,g.dow_status,g.ios_dow_address,g.add_game_address,g.ios_game_address,g.relation_game_name')
->join('tab_game g on g.id = ser.game_id and g.game_status = 1 and g.display_site like "%'.DISPLAY_SITE.'%" ')
->join("left join tab_game_source as sor on sor.game_id = ser.game_id")
->where($where)
->order($order)
->limit(0,12)
->select();
foreach ($lists as $key => $value) {
$lists[$key]['icon_path'] = get_cover($value['icon'],'path');
if($value['dow_status']!=1){
$lists[$key]['status'] = 0;
}elseif($value["down_port"] == 1 && $value["sdk_version"] == 1 && empty($value["and_dow_address"]) || $value["down_port"] == 1 && $value["sdk_version"] == 2 && empty($value["ios_dow_address"]) || $value["down_port"] == 2 && $value["sdk_version"] == 1 && empty($value["add_game_address"]) || $value["down_port"] == 2 && $value["sdk_version"] == 2 && empty($value["ios_game_address"])){
$lists[$key]['status'] = 0;
}else{
if($value["down_port"] == 1){
if($value["sdk_version"] == 2){
$lists[$key]['down_url'] = $value["ios_dow_address"];
}else{
$lists[$key]['down_url'] = U('AjaxDown/down_file',['game_id'=>$value['game_id'],'sdk_version'=>$value['sdk_version']]);
}
}else{
if($value["sdk_version"] == 2){
$lists[$key]['down_url'] = $value["ios_game_address"];
}else{
$lists[$key]['down_url'] = U('AjaxDown/down_file',['game_id'=>$value['game_id'],'sdk_version'=>$value['sdk_version']]);
}
}
$lists[$key]['status'] = 1;
}
$lists[$key]['time'] = date('Y-m-d H:i',$value['start_time']);
if(!is_mobile_request()){
$lists[$key]['relation_game_name'] = $value['game_name'];
}
}
// var_dump($lists);die;
$this->assign('rankrec',$lists);
}
private function gift(){
$map['game_status']=1;
$map['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$map['end_time']=array(array('gt',time()),array('eq',0),'or');
$map['giftbag_type']=2;
$map['status'] = 1;
if(is_mobile_request()){
$map['giftbag_version'] = get_devices_type();
}
$map['novice'] = array('neq','');
$model = array(
'm_name'=>'Giftbag',
'prefix'=>'tab_',
'field' =>'tab_giftbag.id as gift_id,relation_game_name,game_id,tab_giftbag.game_name,giftbag_name,giftbag_type,tab_game.icon,tab_giftbag.create_time',
'join' =>'tab_game on tab_giftbag.game_id = tab_game.id',
'map' =>$map,
'order' =>'create_time desc',
'limit' =>4,
);
if(is_cache() && S('index_gift')){
$gift=S('index_gift');
}else{
$gift = parent::join_data($model);
if(is_cache() ){
S('index_gift',$gift);
}
}
foreach ($gift as $key => $value) {
$gift[$key]['gift_num']=gift_recorded($value['game_id'],$value['gift_id']);
if(!is_mobile_request()){
$gift[$key]['relation_game_name'] = $value['game_name'];
}
}
$this->assign('gift',$gift);
}
private function rank($where,$order,$limit=7){
$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;
$data = $model
->alias('g')
->field('g.id as game_id,g.game_name,g.sort,g.game_type_id,g.game_type_name,g.game_score,g.features,g.icon,g.relation_game_id,g.relation_game_name,g.game_address_size,IF(g.down_port=1,s.file_size,g.game_address_size) as game_size')
//游戏原包
->join("left join tab_game_source as s on s.game_id = g.id")
->where($where)
->order($order)
->limit($limit)
->select();
foreach ($data as $key => $val){
$data[$key]['icon'] = get_cover($val['icon'],'path');
$data[$key]['game_score'] = round($val['game_score'] / 2);
if(empty($data[$key]['game_type_name'])){
$data[$key]['game_type_name'] = '全部';
}
if($data[$key]['game_size']==0){
$data[$key]['game_size'] = '0MB';
}
if(!is_mobile_request()){
$data[$key]['relation_game_name'] = $val['game_name'];
}
}
return $data;
}
public function asd(){
$Yan =M('Game','tab_');
$page = intval($_GET['page']); //获取请求的页数
$start = $page*10;
$data = $Yan->field('game_name,create_time')->order('id desc')->limit($start,10)->select();
echo json_encode($data); //转换为json数据输出
}
public function newzixun($category_name="media_gg",$limit=5){
$map['sys_category.name']=array('eq',$category_name);//显示公告和资讯
$map['sys_document.status']=1;
$map['sys_document.display']=1;
$map['deadline']=array(array('gt',time()),array('eq',0),'or');
$data=M('document')
->field('sys_category.name,cover_id,category_id,sys_document.description,sys_document.title,sys_document.update_time,sys_document.id')
->join('sys_category on sys_document.category_id = sys_category.id and sys_category.pid = 46')
->where($map)
->order('level desc,id desc')
->limit($limit)
->select();
return $data;
}
//生成二维码
public function qrcode($url='pc.vlcms.com',$level=3,$size=4){
$url = base64_decode(base64_decode($url));
Vendor('phpqrcode.phpqrcode');
$errorCorrectionLevel =intval($level) ;//容错级别
$matrixPointSize = intval($size);//生成图片大小
//生成二维码图片
//echo $_SERVER['REQUEST_URI'];
ob_clean();
$object = new \QRcode();
echo $object->png($url, false, $errorCorrectionLevel, $matrixPointSize, 2);
}
public function join(){
$this->display();
}
public function product(){
$adv = get_adv_data(['in','wap_index,and_wap_index_gift,ios_wap_index_gift,wap_index_gg,wap_index_zx,wap_index_activity']);
foreach ($adv as $key => $value) {
if($value['name']=='wap_index'){
$wap_index[]=$value;
unset($adv[$key]);
}
if($value['name']=='and_wap_index_gift'){
$and_wap_index_gift=$value;
unset($adv[$key]);
if($and_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $and_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$and_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='ios_wap_index_gift'){
$ios_wap_index_gift=$value;
unset($adv[$key]);
if($ios_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $ios_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$ios_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='wap_index_gg'){
$wap_index_gg=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_zx'){
$wap_index_zx=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_activity'){
$wap_index_activity=$value;
unset($adv[$key]);
}
}
foreach ($wap_index as $k1 => $v1) {
if(strpos($v1['url'],'http')===false){
$wap_index[$k1]['url'] = U('Game/detail',array('id'=>$v1['url']));
}
}
$this->assign('wap_index',$wap_index);
if(get_devices_type()==1){
$this->assign('wap_index_gift',$and_wap_index_gift);
}elseif(get_devices_type()==2){
$this->assign('wap_index_gift',$ios_wap_index_gift);
}else{
$this->assign('wap_index_gift',$and_wap_index_gift['id']>$ios_wap_index_gift['id']?$and_wap_index_gift:$ios_wap_index_gift);
}
if(strpos($wap_index_gg['url'],'http')===false){
$wap_index_gg['url'] = U('Game/detail',array('id'=>$wap_index_gg['url']));
}
if(strpos($wap_index_zx['url'],'http')===false){
$wap_index_zx['url'] = U('Game/detail',array('id'=>$wap_index_zx['url']));
}
if(strpos($wap_index_activity['url'],'http')===false){
$wap_index_activity['url'] = U('Game/detail',array('id'=>$wap_index_activity['url']));
}
$this->assign('wap_index_gg',$wap_index_gg);
$this->assign('wap_index_zx',$wap_index_zx);
$this->assign('wap_index_activity',$wap_index_activity);
$promote_id = empty(PROMOTE_ID) ? 0 : PROMOTE_ID;
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
$time = NOW_TIME;
$model = M('Game','tab_');
//热门游戏
$devices = get_devices_type();
$game_h['g.recommend_status'] = 2;
$game_h['g.game_status'] = 1;
$game_h['g.display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$game_h['g.sdk_version'] = array('like','%'.$devices.'%');
if(is_cache() && S('moblie_index_hot')){
$hot=S('moblie_index_hot');
}else{
$hot = $model
->alias('g')
->field('g.id,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,IF(g.down_port=1,s.file_size,g.game_address_size) as 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.game_address_size,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($game_h)
->page(0,7)
->order('g.sort desc,g.id desc')
->select();
if(is_cache()){
S('moblie_index_hot',$hot);
}
foreach ($hot as $key => $value) {
if(!is_mobile_request()){
$hot[$key]['relation_game_name'] = $value['game_name'];
}
}
}
$this->assign('hot',$hot);
$media_gg = $this->newzixun('notice_wap');
$media_activity = $this->newzixun('activity_wap');
$media_zx = $this->newzixun('news_wap');
$this->assign('media_gg',$media_gg);
$this->assign('media_activity',$media_activity);
$this->assign('media_zx',$media_zx);
$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(is_cache() && S('moblie_rank_new')){
$ranknew=S('moblie_rank_new');
}else{
$where['g.recommend_status'] = 3;
$order = 'g.sort desc,g.id desc';
$ranknew = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_new',$ranknew);
}
}
$this->assign('ranknew',$ranknew);
if(is_cache() && S('moblie_rank_rec')){
$rankrec=S('moblie_rank_rec');
}else{
$where['g.recommend_status'] = 1;
$order = 'g.sort desc,g.id desc';
$rankrec = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_rec',$rankrec);
}
}
$this->assign('rankrec',$rankrec);
if(is_cache() && S('moblie_rank_hot')){
$rankhot=S('moblie_rank_hot');
}else{
$where['g.recommend_status'] = 2;
$order = 'g.sort desc,g.id desc';
$rankhot = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_hot',$rankhot);
}
}
$this->assign('rankhot',$rankhot);
if(is_cache() && S('moblie_rank_dow')){
$rankdow=S('moblie_rank_dow');
}else{
$order = 'g.dow_num desc,g.id desc';
unset($where['g.recommend_status']);
$rankdow = $this->rank($where,$order);
if(is_cache()){
S('moblie_rank_dow',$rankdow);
}
}
$this->assign('rankdow',$rankdow);
//礼包
$this->gift();
//开服
$this->server();
//热门游戏(实质为推荐游戏)
$this->recommend();
$this->display();
}
public function business(){
$adv = get_adv_data(['in','wap_index,and_wap_index_gift,ios_wap_index_gift,wap_index_gg,wap_index_zx,wap_index_activity']);
foreach ($adv as $key => $value) {
if($value['name']=='wap_index'){
$wap_index[]=$value;
unset($adv[$key]);
}
if($value['name']=='and_wap_index_gift'){
$and_wap_index_gift=$value;
unset($adv[$key]);
if($and_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $and_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$and_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='ios_wap_index_gift'){
$ios_wap_index_gift=$value;
unset($adv[$key]);
if($ios_wap_index_gift['game_id'] != 0){
if(is_mobile_request()){
$gmap['giftbag_version'] = get_devices_type();
}
$gmap['status'] = 1;
$gmap['display_site'] = ['like','%'. DISPLAY_SITE .'%'];
$gmap['novice'] = array('neq','');
$time = NOW_TIME;
$gmap['game_id'] = $ios_wap_index_gift['game_id'];
$gmap['start_time'] = ['elt',$time];
$gmap['_string'] = "end_time > {$time} or end_time = 0";
$gdata = M('giftbag','tab_')->where($gmap)->find();
if(empty($gdata)){
$ios_wap_index_gift['game_id'] = 0;
}
}
}
if($value['name']=='wap_index_gg'){
$wap_index_gg=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_zx'){
$wap_index_zx=$value;
unset($adv[$key]);
}
if($value['name']=='wap_index_activity'){
$wap_index_activity=$value;
unset($adv[$key]);
}
}
foreach ($wap_index as $k1 => $v1) {
if(strpos($v1['url'],'http')===false){
$wap_index[$k1]['url'] = U('Game/detail',array('id'=>$v1['url']));
}
}
$this->assign('wap_index',$wap_index);
$this->display();
}
/**
*公司简介
*/
public function introduce()
{
$this->display();
}
5 years ago
}