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.
271 lines
8.1 KiB
PHP
271 lines
8.1 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xmy 280564871@qq.com
|
|
* Date: 2017/3/28
|
|
* Time: 9:03
|
|
*/
|
|
namespace App\Model;
|
|
|
|
class GameModel extends BaseModel{
|
|
const ORDER_RECOMMEND = 1; //推荐
|
|
const ORDER_HOT = 2; //热门
|
|
const ORDER_NEWEST = 3; //最新
|
|
const ORDER_DOWN_NUM = 4; //下载量
|
|
const ANDROID = 1;
|
|
const IOS = 2;
|
|
const DOWN_OFF = 0;
|
|
const DOWN_ON = 1;
|
|
const COLLECT = 1;
|
|
const COLLECT_CANCEL = 2;
|
|
|
|
/**
|
|
* 游戏列表
|
|
* @param string $map
|
|
* @param string $order
|
|
* @param int $p
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getGameLists($map="",$order="sort desc",$p=0,$account=''){
|
|
$page = intval($p);
|
|
$page = $page ? $page : 1; //默认显示第一页数据
|
|
$row = 10;
|
|
$map['g.game_status'] = 1;
|
|
$map['g.apply_status'] = 1;
|
|
$map['g.display_site'] = ['like','%'.DISPLAY_SITE.'%'];
|
|
if($account){
|
|
$promote_id =empty( get_user_entity($account,1)['promote_id'] ) ? 0 : 1;
|
|
}else{
|
|
$promote_id = -1;
|
|
}
|
|
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
|
|
$time = NOW_TIME;
|
|
$data = $this->table('tab_game as g')
|
|
->field('g.id,g.game_name,if(g.down_port=1,g.game_size,g.game_address_size) as game_size,g.down_port,g.add_game_address,g.icon,g.dow_num,g.marking,g.game_score,g.dow_status,g.game_type_name,g.features,g.bind_recharge_discount as discount,s.pack_name,IFNULL(r.ratio,0) as ratio,sort')
|
|
//游戏原包
|
|
->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($map)
|
|
->page($page, $row)
|
|
->order('sort desc,g.id desc')
|
|
->group("g.id")
|
|
->select();
|
|
foreach ($data as $key => $val){
|
|
$data[$key]['icon'] = get_img_url($val['icon'],'path');
|
|
$data[$key]['game_score'] = $val['game_score'] / 2;
|
|
/* if($val['game_size']=='0'){
|
|
if(!empty($val['game_address_size'])){
|
|
$data[$key]['game_size'] = $val['game_address_size'];
|
|
}else{
|
|
$data[$key]['game_size'] = '0M';
|
|
}
|
|
} */
|
|
if($val['dow_status'] == self::DOWN_OFF){
|
|
$data[$key]['down_url'] = "";
|
|
}else{
|
|
$data[$key]['down_url'] = $this::generateDownUrl($val['id']);
|
|
}
|
|
$data[$key]['xia_status']=check_game_sorue($val['id']);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 游戏详情
|
|
* @param $id
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getGameDetail($id,$account='',$type=0){
|
|
$map['g.id'] = $id;
|
|
if($account){
|
|
$promote_id =empty( get_user_entity($account,1)['promote_id'] ) ? 0 : 1;
|
|
}else{
|
|
$map['g.display_site'] = ['like','%'.DISPLAY_SITE.'%'];
|
|
$promote_id = -1;
|
|
}
|
|
$rebate_join = "and (r.promote_id = {$promote_id} or r.promote_id = -1)";
|
|
$time = NOW_TIME;
|
|
$data = $this->table('tab_game as g')
|
|
->field('g.id,g.game_name,g.relation_game_id,g.relation_game_name,g.icon,if(down_port=1,g.game_size,g.game_address_size) as game_size,g.down_port,g.add_game_address,g.dow_num,g.game_score,g.dow_status,g.screenshot,g.features,g.introduction,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($map)
|
|
->find();
|
|
if(empty($data)){
|
|
return $data;
|
|
}
|
|
/* if($data['game_size'] == '0'){
|
|
if(!empty($data['game_address_size'])){
|
|
$data['game_size'] = $data['game_address_size'];
|
|
}else{
|
|
$data['game_size'] = '0M';
|
|
}
|
|
} */
|
|
$data['xia_status']=check_game_sorue($data['id']);
|
|
|
|
//是否收藏
|
|
$data['is_collect'] = self::COLLECT_CANCEL;
|
|
if(defined("USER_ACCOUNT")){
|
|
$collect = M("collect_game",'tab_')->where(["account"=>USER_ACCOUNT,'status'=>self::COLLECT,"game_id"=>$id])->find();
|
|
empty($collect) || $data['is_collect'] = self::COLLECT;
|
|
}
|
|
if($data['screenshot']==''){
|
|
$screenshot=[];
|
|
}else{
|
|
$screenshot = str2arr($data['screenshot'],',');
|
|
}
|
|
$data['icon'] = get_img_url($data['icon'],'path');
|
|
$gamescore = $data['game_score'] / 2;
|
|
is_float($gamescore) && $data['half'] = 1;
|
|
$data['game_score'] = intval($gamescore);
|
|
$data['screenshot'] = array_map("array_map_self",$screenshot);//截图转URL
|
|
if($type==1){
|
|
$data['introduction'] = str_replace("~~","<br/>",$data['introduction']);
|
|
}else{
|
|
$data['introduction'] = str_replace("~~","\n",$data['introduction']);
|
|
}
|
|
!empty($data['discount']) || $data['discount'] = 10; //未设置折扣则返回10折
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 生成游戏下载链接
|
|
* @param $game_id
|
|
* @return string
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public static function generateDownUrl($game_id){
|
|
$url = U('Down/down',['game_id'=>$game_id,'promote_id'=>PROMOTE_ID],'',true);
|
|
return $url;
|
|
}
|
|
|
|
/**
|
|
* 游戏下载信息
|
|
* @param $game_id
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getGameDownInfo($game_id){
|
|
$map['id'] = $game_id;
|
|
$map['apply_status'] = 1;
|
|
$map['game_status'] = 1;
|
|
$map['display_site'] = ['like','%'.DISPLAY_SITE.'%'];
|
|
$data['game_info'] = $this->field('id,game_name,add_game_address,ios_game_address,sdk_version')->where(['id'=>$game_id])->find();
|
|
$data['packet'] = M("game_source",'tab_')->where(['game_id'=>$game_id])->find();
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 增加下载次数
|
|
* @param $game_id
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function addGameDownNum($game_id){
|
|
$map['id'] = $game_id;
|
|
$this->where($map)->setInc('dow_num');
|
|
}
|
|
|
|
|
|
/**
|
|
* 游戏收藏
|
|
* @param $game_id
|
|
* @param $account
|
|
* @param $status 1 收藏 2 取消收藏
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function collectGame($game_id,$account,$status){
|
|
$data['game_id'] = $game_id;
|
|
$data['account'] = $account;
|
|
$collect = M("collect_game",'tab_')->where($data)->find();
|
|
if(empty($collect)){
|
|
$data['create_time'] = time();
|
|
$data['status'] = $status;
|
|
$result = M("collect_game",'tab_')->add($data);
|
|
}else{
|
|
$result = M("collect_game",'tab_')->where($data)->setField(['status'=>$status]);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 我的游戏收藏
|
|
* @param $account
|
|
* @param $p
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getMyCollectGame($account,$p){
|
|
$map['account'] = $account;
|
|
$map['status'] = self::COLLECT;
|
|
$collect = M("collect_game",'tab_')->field("game_id")->where($map)->select();
|
|
if(empty($collect)){
|
|
return $collect;
|
|
}
|
|
$game_map['g.sdk_version'] = get_devices_type();
|
|
$game_map['g.id'] = ['in',array_column($collect,"game_id")];
|
|
$data = $this->getGameLists($game_map,'',$p);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 获取绑币充值折扣
|
|
* @param $game_id
|
|
* @return int
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getBindRechargeDiscount($game_id){
|
|
$data = $this->field("bind_recharge_discount")->find($game_id);
|
|
$discount = empty($data['bind_recharge_discount']) ? 10 : $data['bind_recharge_discount'];
|
|
return $discount;
|
|
}
|
|
|
|
/**
|
|
* 游戏列表
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getLists($map=""){
|
|
$map['game_status'] = 1;
|
|
$map['apply_status'] = 1;
|
|
$map['display_site'] = ['like','%'.DISPLAY_SITE.'%'];
|
|
return $this->field("id,game_name")->where($map)->select();
|
|
}
|
|
|
|
/**
|
|
* 绑币充值游戏列表
|
|
* @param $user_id
|
|
* @return mixed
|
|
* author: xmy 280564871@qq.com
|
|
*/
|
|
public function getUserRechargeGame($user_id,$version){
|
|
$map['user_id'] = $user_id;
|
|
$map['g.sdk_version'] = $version;
|
|
$data = M("user_play","tab_")->alias("p")->field("p.game_name,p.game_id")
|
|
->join("right join tab_game g on g.id = p.game_id")
|
|
->where($map)->where('g.game_status=1')->group('p.game_id')->select();
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 读取指定字段
|
|
* @param string $field_name 要读取字段的名字
|
|
* @param int $id 要读取字段的主键
|
|
* @return mixed
|
|
* 小纯洁
|
|
*/
|
|
public function get_table_fields($field_name="",$id=0){
|
|
$data = "";
|
|
if(empty($field_name)){
|
|
$data = $this->find($id);
|
|
}else{
|
|
$data = $this->where(["id"=>$id])->getField($field_name);
|
|
}
|
|
return $data;
|
|
}
|
|
} |