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.
306 lines
9.0 KiB
PHP
306 lines
9.0 KiB
PHP
<?php
|
|
namespace Site\Model;
|
|
|
|
use Think\Model;
|
|
|
|
/**
|
|
* 分类模型 游戏
|
|
* lwx
|
|
*/
|
|
class SiteGameModel extends Model{
|
|
|
|
protected $_validate = array(
|
|
);
|
|
|
|
protected $_auto = array(
|
|
);
|
|
|
|
/**
|
|
* 构造函数
|
|
* @param string $name 模型名称
|
|
* @param string $tablePrefix 表前缀
|
|
* @param mixed $connection 数据库连接信息
|
|
*/
|
|
public function __construct($name = '', $tablePrefix = '', $connection = '') {
|
|
/* 设置默认的表前缀 */
|
|
$this->tablePrefix ='tab_';
|
|
/* 执行构造方法 */
|
|
parent::__construct($name, $tablePrefix, $connection);
|
|
}
|
|
|
|
/**
|
|
* 游戏列表
|
|
* @param integer $p 当前页码
|
|
* @param string $field 游戏表字段
|
|
* @param integer $row 限制条数
|
|
* @param string $order 排序条件
|
|
* @return array 结果数据列表
|
|
*/
|
|
public function lists($p=1,$field=true,$row=10,$order='sort desc,id desc') {
|
|
|
|
$page = intval($p);
|
|
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
|
|
$map['promote_id'] = PID;
|
|
|
|
if($field === true) {$field = '*';}
|
|
|
|
if (DEVICES) {
|
|
|
|
$map['sdk_version'] = DEVICES;
|
|
|
|
!empty($_GET['rs']) && $map['recommend_status']= array('like','%'.$_GET['rs'].'%');
|
|
|
|
$count = $this->where($map)->count();
|
|
|
|
$total = intval(($count-1)/$row)+1;
|
|
|
|
if ($page>$total) {return array('data'=>'','total'=>$total);}
|
|
|
|
$data = $this->field($field)->where($map)->order($order)->page($page,$row)->select();
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
$data[$k]['downloadurl'] = $v['game_source']==2?($v['game_dow_url']?$v['game_dow_url']:''):('http://'.$_SERVER['HTTP_HOST'].U('Down/down_file',array('game_id'=>$v['game_id'],'promote_id'=>PID,'type'=>$v['sdk_version'])));
|
|
|
|
$data[$k]['game_icon_url'] = get_cover($v['game_icon'],'path');
|
|
|
|
$data[$k]['jump_url'] = U('Game/detail',array('name'=>$v['game_name'],'source'=>$v['game_source'],'account'=>I('account')));
|
|
|
|
$data[$k]['game_name']=str_replace(array('(安卓版)','(苹果版)'),'',$v['game_name']);
|
|
|
|
$data[$k]['download_number'] = set_number_short($v['download_number']);
|
|
|
|
$data[$k]['game_size'] = $v['game_size']?$v['game_size']:0;
|
|
|
|
}
|
|
|
|
return array('data'=>$data,'total'=>$total);
|
|
|
|
} else {
|
|
|
|
$arr = ['gt'=>'game_type_id','rs'=>'recommend_status-like','sv'=>'sdk_version'];
|
|
|
|
$search = $_GET;
|
|
|
|
unset($search['account']);
|
|
|
|
foreach($search as $k => $v) {
|
|
|
|
$value = explode('-',$arr[$k]);
|
|
|
|
switch($value[1]) {
|
|
|
|
case 'like':{
|
|
|
|
$map[$value[0]] = array('like','%'.$v.'%');
|
|
|
|
};break;
|
|
|
|
default:
|
|
$map[$arr[$k]]=$v;
|
|
}
|
|
|
|
}
|
|
|
|
$data = $this->field($field.',count(distinct game_name,game_source)')->where($map)->group('game_name,game_source')->order($order)->page($page,$row)->select();
|
|
|
|
$count = $this->field($field.',count(distinct game_name,game_source)')->where($map)->group('game_name,game_source')->select();
|
|
return array('data'=>$data,'count'=>count($count),'row'=>$row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 取几条游戏数据
|
|
* @param array $map 搜索条件
|
|
* @param integer $limit 限制条数
|
|
* @param string $field 游戏表字段
|
|
* @return array 结果数据列表
|
|
*/
|
|
public function limits($map=array(),$limit=10,$field=true) {
|
|
|
|
if (PID<=0) {return null;}
|
|
|
|
$map['promote_id'] = PID;
|
|
|
|
if($field === true) {$field = '*';}
|
|
|
|
if (DEVICES) {
|
|
|
|
$map['sdk_version'] = DEVICES;
|
|
|
|
$data = $this->field($field)->where($map)->limit($limit)->order('sort desc,id desc')->select();
|
|
foreach ($data as $k=>$v){
|
|
$data[$k]['jump_url'] = U('Game/detail',array('name'=>$v['game_name'],'source'=>$v['game_source'],'account'=>I('account')));
|
|
}
|
|
} else {
|
|
|
|
$data = $this->field($field.',count(distinct game_name,game_source)')->where($map)->group('game_name,game_source')->limit($limit)->order('sort desc,id desc')->select();
|
|
|
|
foreach($data as $k => $v) {
|
|
$data[$k]['download'] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file1',array('id'=>$v['id'],'promote_id'=>PID,'type'=>$v['sdk_version']));
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 数据来源地址变更
|
|
* @param array $data 游戏列表数据
|
|
* @return array 结果数据列表
|
|
*/
|
|
private function op($data) {
|
|
|
|
foreach($data as $k => $v) {
|
|
if ($v['game_source']==1) {
|
|
$data[$k]['download'] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file',array('game_id'=>$v['game_id'],'promote_id'=>PID));
|
|
}elseif ($v['game_source']==2) {
|
|
$data[$k]['download'] = $v['game_dow_url'];
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 游戏详情
|
|
* @param string $name 游戏名称
|
|
* @param integer $source 游戏来源
|
|
* @param string $field 游戏表字段
|
|
* @return array 结果数据
|
|
*/
|
|
public function detail($name='',$source=1,$field=true) {
|
|
|
|
if (empty($name) || !is_string($name)) {return null;}
|
|
|
|
$map['tab_site_game.game_name']=$name;
|
|
|
|
if (!is_numeric($source) || ($source != 1 && $source != 2)) {return null;}
|
|
|
|
$map['tab_site_game.promote_id']=PID;
|
|
|
|
$map['tab_site_game.game_source']=$source;
|
|
|
|
if($field === true) {$field = 'tab_site_game.*';}
|
|
|
|
if (DEVICES) {
|
|
|
|
$map['sdk_version'] = DEVICES;
|
|
|
|
$data = $this->field($field.',tab_site_group.group_code,tab_site_group.group_name,tab_site_group.pc_url')->join('tab_site_group on tab_site_group.site_game_id = tab_site_game.id','left')->where($map)->order('update_time desc')->find();
|
|
if ($data) {
|
|
$data['ids']=[$data['id']];
|
|
$game = get_game_entity($data['game_id']);
|
|
if ($data['game_source']==1 && $game['dow_status'] == 1) {
|
|
|
|
$data['download'] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file',array('game_id'=>$data['game_id'],'promote_id'=>PID,'type'=>$data['sdk_version']));
|
|
}elseif ($data['game_source']==2 && $game['dow_status'] == 1) {
|
|
|
|
$data['download'] = $data['game_dow_url'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
unset($map['tab_site_game.game_source']);
|
|
$list = $this->field($field.',tab_site_group.group_code,tab_site_group.group_name,tab_site_group.pc_url')->join('tab_site_group on tab_site_group.site_game_id = tab_site_game.id','left')->where($map)->order('update_time desc')->select();
|
|
|
|
// 按最新的更新数据来展示
|
|
|
|
if (empty($list[0])) {return '';}
|
|
|
|
$data = $list[0];
|
|
$game = get_game_info($data['game_id']);
|
|
if ($data['game_source']==1 && $game['dow_status'] == 1) {
|
|
$data['download'.$list[0]['sdk_version']] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file',array('game_id'=>$data['game_id'],'promote_id'=>PID,'type'=>$data['sdk_version']));
|
|
}elseif ($data['game_source']==2 && $game['dow_status'] == 1) {
|
|
$data['download'.$list[0]['sdk_version']] = $data['game_dow_url'];
|
|
}
|
|
|
|
$data['download'] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file1',array('id'=>urlencode($data['id']),'promote_id'=>$data['promote_id']));
|
|
|
|
$data['sdk_version'.$data['sdk_version']] = $data['sdk_version'];
|
|
|
|
$data['ids']=[$data['id']];
|
|
if ($list[1]) {
|
|
$game1 = get_game_info($list[1]['game_id']);
|
|
if ($list[1]['game_source']==1 && $game1['dow_status'] == 1) {
|
|
$data['download'.$list[1]['sdk_version']] = 'http://'.$_SERVER['HTTP_HOST'].U('Down/down_file',array('game_id'=>$list[1]['game_id'],'promote_id'=>PID,'type'=>$list[1]['sdk_version']));
|
|
}elseif ($list[1]['game_source']==2 && $game1['dow_status'] == 1) {
|
|
$data['download'.$list[1]['sdk_version']] = $list[1]['game_dow_url'];
|
|
}
|
|
|
|
array_filter($data); // 去空值
|
|
|
|
$data['sdk_version'.$list[1]['sdk_version']]= $list[1]['sdk_version'];
|
|
$data['download_number'] = $data['download_number'] + $list[1]['download_number'];
|
|
$data = array_merge($list[1],$data);
|
|
$data['ids'][]=$list[1]['id'];
|
|
}
|
|
}
|
|
|
|
$data['description'] = str_replace('~~','<br />',$data['description']);
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
/**
|
|
* 游戏基本信息
|
|
* @param string $name 游戏名称
|
|
* @param integer $source 游戏来源
|
|
* @return array 结果数据
|
|
*/
|
|
public function base($name='',$source=1) {
|
|
|
|
return $this->detail($name,$source,'tab_site_game.id,tab_site_game.game_name,tab_site_game.game_icon,tab_site_game.game_bg_img,tab_site_game.sdk_version,tab_site_game.download_number,tab_site_game.game_type_id,tab_site_game.open_type,tab_site_game.version,tab_site_game.game_dow_url,tab_site_game.game_source,tab_site_game.game_size');
|
|
|
|
}
|
|
|
|
/**
|
|
* 游戏下载信息
|
|
* @param string $name 游戏名称
|
|
* @param integer $source 游戏来源
|
|
* @return array 结果数据
|
|
*/
|
|
public function down($name='',$source=1,$sdk_version='',$pid) {
|
|
|
|
$map['tab_site_game.promote_id']=$pid;
|
|
|
|
$map['tab_site_game.game_name']=urldecode($name);
|
|
|
|
$map['tab_site_game.game_source']=$source;
|
|
|
|
$map['tab_site_game.sdk_version']=$sdk_version;
|
|
|
|
return $this->field('tab_site_game.game_id,tab_site_game.game_dow_url,tab_site_game.sdk_version')->where($map)->find();
|
|
|
|
}
|
|
|
|
/**
|
|
* 游戏类型
|
|
* @param string $typename 类型名称
|
|
* @return array 结果数据列表
|
|
*/
|
|
public function type($typename='') {
|
|
|
|
$map=array('status'=>1,'status_show'=>1);
|
|
|
|
empty($typename) || $map['type_name']=array('like','%'.$typename.'%');
|
|
|
|
return M('game_type','tab_')->field('id,type_name,icon,cover')->where($map)->select();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|