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.
262 lines
9.8 KiB
PHTML
262 lines
9.8 KiB
PHTML
5 years ago
|
<?php
|
||
|
namespace Mobile\Controller;
|
||
|
use Think\Controller;
|
||
|
use User\Api\SuserApi;
|
||
|
|
||
|
/**
|
||
|
* 礼包
|
||
|
*/
|
||
|
class GiftController extends BaseController {
|
||
|
|
||
|
protected function _initialize(){
|
||
|
|
||
|
$config = api('Config/lists');
|
||
|
|
||
|
C($config);
|
||
|
|
||
|
}
|
||
|
|
||
|
public function index() {
|
||
|
$page = $page ? $page : 1; //默认显示第一页数据
|
||
|
$row = C('LIST_ROWS');
|
||
|
$devices = get_devices_type();
|
||
|
|
||
|
if(!empty($_REQUEST['name'])){
|
||
|
$map['tab_giftbag.game_name'] = array('LIKE','%'.$_REQUEST['name'].'%');
|
||
|
}
|
||
|
$map['status'] = 1;
|
||
|
$map['novice'] = array('neq','');
|
||
|
$map['g.sdk_version'] = array('like','%'.$devices.'%');
|
||
|
$time = NOW_TIME;
|
||
|
// $map['start_time'] = ['elt',$time];
|
||
|
$map['_string'] = "end_time > {$time} or end_time = 0";
|
||
|
if(is_cache() &&S('mobile_gift_data') &&I('name')=='' ){
|
||
|
$data=S('mobile_gift_data');
|
||
|
}else{
|
||
|
$table = D('Giftbag')
|
||
|
->field("tab_giftbag.id,tab_giftbag.game_id,tab_giftbag.desribe,tab_giftbag.game_name,tab_giftbag.giftbag_name,g.icon,g.relation_game_name")
|
||
|
->join("left join tab_game g on g.id = tab_giftbag.game_id and g.game_status = 1 and g.display_site like '%" . DISPLAY_SITE . "%' ")
|
||
|
->where($map)
|
||
|
->order('tab_giftbag.create_time desc')
|
||
|
->select(false);
|
||
|
$data = D('Giftbag')->table('('.$table.') as a' )->field('count(a.id) as num,a.desribe,a.game_name,a.giftbag_name,a.icon,a.relation_game_name,a.game_id')->group('a.game_id')->page($page,$row)->select();
|
||
|
|
||
|
foreach ($data as $key => $val){
|
||
|
$data[$key]['icon'] = get_cover($val['icon'],'path');
|
||
|
if(!is_mobile_request()){
|
||
|
$data[$key]['relation_game_name'] = $val['game_name'];
|
||
|
}
|
||
|
}
|
||
|
if(is_cache()&&I('name')=='' ){
|
||
|
S('mobile_gift_data',$data);
|
||
|
}
|
||
|
}
|
||
|
$this->assign('data',$data);
|
||
|
$this->assign('page',$page);
|
||
|
$this->assign('category',array('title'=>'礼包'));
|
||
|
$this->display();
|
||
|
}
|
||
|
|
||
|
|
||
|
public function gamegift(){
|
||
|
$game_id = I('get.id');
|
||
|
$page = intval($_REQUEST['p']);
|
||
|
$page = $page ? $page : 1; //默认显示第一页数据
|
||
|
$row = C('LIST_ROWS');
|
||
|
$map['status'] = 1;
|
||
|
$map['g.game_status'] = 1;
|
||
|
$map['g.display_site'] = ['like','%'. DISPLAY_SITE .'%'];
|
||
|
$time = NOW_TIME;
|
||
|
$map['game_id'] = $game_id;
|
||
|
//$map['start_time'] = ['elt',$time];
|
||
|
$map['_string'] = "end_time > {$time} or end_time = 0";
|
||
|
if(is_mobile_request()){
|
||
|
$map['giftbag_version'] = get_devices_type();
|
||
|
}
|
||
|
$map['novice'] = array('neq','');
|
||
|
$data = D('Giftbag')
|
||
|
->field("tab_giftbag.*,g.icon,g.relation_game_name")
|
||
|
->join("left join tab_game g on g.id = tab_giftbag.game_id ")
|
||
|
->where($map)
|
||
|
->order('create_time desc')
|
||
|
->page($page,$row)
|
||
|
->select();
|
||
|
|
||
|
if (empty($data) || !is_array($data)) {$this->error('此礼包不存在!!');}
|
||
|
|
||
|
foreach ($data as $key => $val){
|
||
|
$novice_arr = str2arr($val['novice'],',');
|
||
|
$novice_num = count(array_filter($novice_arr));
|
||
|
$data[$key]['novice_num'] = $novice_num;$member = new SuserApi;
|
||
|
$exist = D("Giftbag")->checkAccountGiftExist($member->login_info("user_id"),$val['id']);
|
||
|
if(empty($exist)){
|
||
|
$exist = 1;//未领取
|
||
|
}else{
|
||
|
$data[$key]['get_novice'] = $exist['novice'];
|
||
|
$exist = 0;//已领取
|
||
|
}
|
||
|
|
||
|
if($novice_num == 0){
|
||
|
$exist = 2;//激活码已领取完
|
||
|
}
|
||
|
$data[$key]['exist'] = $exist;
|
||
|
|
||
|
$data[$key]['icon'] = get_cover($val['icon'],'path');
|
||
|
$data[$key]['novice_num'] = $novice_num;
|
||
|
}
|
||
|
$this->assign('data',$data);
|
||
|
$this->assign('game_id',$game_id);
|
||
|
$this->assign('page',$page);
|
||
|
if(!is_mobile_request()){
|
||
|
$this->assign('mate_title',"《{$data[0]['game_name']}》礼包");
|
||
|
}else{
|
||
|
$this->assign('mate_title',"《{$data[0]['relation_game_name']}》礼包");
|
||
|
}
|
||
|
$this->display();
|
||
|
}
|
||
|
|
||
|
public function ajaxlists() {
|
||
|
$p = I('post.p');
|
||
|
$devices = get_devices_type();
|
||
|
$status=0;
|
||
|
$row = C('LIST_ROWS');
|
||
|
$map['status'] = 1;
|
||
|
$map['g.sdk_version'] = array('like','%'.$devices.'%');
|
||
|
$time = NOW_TIME;
|
||
|
$map['novice'] = array('neq','');
|
||
|
//$map['start_time'] = ['elt',$time];
|
||
|
$map['_string'] = "end_time > {$time} or end_time = 0";
|
||
|
$lists = D('Giftbag')
|
||
|
->field("count(tab_giftbag.id) as num,tab_giftbag.game_id,tab_giftbag.desribe,tab_giftbag.game_name,tab_giftbag.giftbag_name,g.icon,g.relation_game_name")
|
||
|
->join("left join tab_game g on g.id = tab_giftbag.game_id and g.game_status=1 and g.display_site like '%". DISPLAY_SITE ."%' ")
|
||
|
->where($map)
|
||
|
->page($p,$row)
|
||
|
->group("game_id")
|
||
|
->select();
|
||
|
foreach ($lists as $key => $val){
|
||
|
|
||
|
$lists[$key]['url'] = U('Gift/gamegift?id='.$val['game_id']);
|
||
|
$lists[$key]['icon'] = get_cover($val['icon'],'path');
|
||
|
if(!is_mobile_request()){
|
||
|
$lists[$key]['relation_game_name'] = $val['game_name'];
|
||
|
}
|
||
|
}
|
||
|
if (!empty($lists) && is_array($lists)) {
|
||
|
$status = 1;
|
||
|
}
|
||
|
echo json_encode(array('status'=>$status,'page'=>$p,'lists'=>$lists));
|
||
|
}
|
||
|
|
||
|
public function ajaxgift() {
|
||
|
$p = I('post.p');
|
||
|
$game_id = I('post.id');
|
||
|
$status=0;
|
||
|
$row = C('LIST_ROWS');
|
||
|
$map['status'] = 1;
|
||
|
$time = NOW_TIME;
|
||
|
$map['game_id'] = $game_id;
|
||
|
$map['novice'] = array('neq','');
|
||
|
//$map['start_time'] = ['elt',$time];
|
||
|
$map['_string'] = "end_time > {$time} or end_time = 0";
|
||
|
$lists = D('Giftbag')
|
||
|
->field("tab_giftbag.*,g.icon,g.relation_game_name")
|
||
|
->join("left join tab_game g on g.id = tab_giftbag.game_id and g.game_status=1 and g.display_site like '%". DISPLAY_SITE ."%' ")
|
||
|
->where($map)
|
||
|
->page($p,$row)
|
||
|
->select();
|
||
|
foreach ($lists as $key => $val){
|
||
|
$novice_arr = str2arr($val['novice'],',');
|
||
|
$novice_num = count(array_filter($novice_arr));
|
||
|
$lists[$key]['novice_num'] = $novice_num;$member = new SuserApi;
|
||
|
$exist = D("Giftbag")->checkAccountGiftExist($member->login_info("user_id"),$val['id']);
|
||
|
if(empty($exist)){
|
||
|
$exist = 1;//未领取
|
||
|
}else{
|
||
|
$exist = 0;//已领取
|
||
|
}
|
||
|
if($novice_num == 0){
|
||
|
$exist = 2;//激活码已领取完
|
||
|
}
|
||
|
$lists[$key]['exist'] = $exist;
|
||
|
$lists[$key]['url'] = U('Gift/detail?id='.$val['id']);
|
||
|
$lists[$key]['icon'] = get_cover($val['icon'],'path');
|
||
|
if(is_mobile_request()){
|
||
|
$lists[$key]['game_name'] = "《{$val['relation_game_name']}》".$val['giftbag_name'];
|
||
|
}else{
|
||
|
$lists[$key]['game_name'] = "《{$val['game_name']}》".$val['giftbag_name'];
|
||
|
}
|
||
|
}
|
||
|
if (!empty($lists) && is_array($lists)) {
|
||
|
$status = 1;
|
||
|
}
|
||
|
|
||
|
echo json_encode(array('status'=>$status,'page'=>$p,'lists'=>$lists));
|
||
|
}
|
||
|
|
||
|
public function detail($id) {
|
||
|
$id = I('get.id');
|
||
|
|
||
|
$map['tab_giftbag.id'] = $id;
|
||
|
|
||
|
$record = M('gift_record','tab_')->field('id')->where(['user_id'=>UID,'gift_id'=>$id])->find();
|
||
|
|
||
|
!empty($record) || $map['g.display_site'] = ['like','%'. DISPLAY_SITE .'%'];
|
||
|
|
||
|
$data = D('Giftbag')
|
||
|
->field("tab_giftbag.*,g.icon,g.relation_game_name")
|
||
|
->join("left join tab_game g on g.id = tab_giftbag.game_id and g.game_status = 1 ")
|
||
|
->where($map)
|
||
|
->find();
|
||
|
|
||
|
if (empty($data) || !is_array($data)) {$this->error('此礼包不存在!!');}
|
||
|
|
||
|
|
||
|
$novice_arr = str2arr($data['novice'],',');
|
||
|
$novice_num = count(array_filter($novice_arr));
|
||
|
unset($data['novice']);
|
||
|
$data['novice_num'] = $novice_num;
|
||
|
$data['icon'] = get_cover($data['icon'],'path');
|
||
|
$data['end'] = $data['end_time']==0 ? '永久' : date('Y-m-d');$member = new SuserApi;
|
||
|
$exist = D("Giftbag")->checkAccountGiftExist($member->login_info("user_id"),$id);
|
||
|
if(empty($exist)){
|
||
|
$exist = 1;//未领取
|
||
|
}else{
|
||
|
$data['get_novice'] = $exist['novice'];
|
||
|
$exist = 0;//已领取
|
||
|
}
|
||
|
if($novice_num == 0){
|
||
|
$exist = 2;//激活码已领取完
|
||
|
}
|
||
|
$this->assign('exist',$exist);
|
||
|
if(is_mobile_request()){
|
||
|
$this->assign('mate_title',"《{$data['relation_game_name']}》{$data['giftbag_name']}");
|
||
|
}else{
|
||
|
$this->assign('mate_title',"《{$data['game_name']}》{$data['giftbag_name']}");
|
||
|
}
|
||
|
$this->assign('data',$data);
|
||
|
$this->display();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 领取激活码
|
||
|
* @param $token
|
||
|
* @param $gift_id
|
||
|
* author: xmy 280564871@qq.com
|
||
|
*/
|
||
|
public function get_novice($gift_id){
|
||
|
if(!$this->islogin()){$this->error('请先登录','Mobile/User/login');}$member = new SuserApi;
|
||
|
$logininfo = $member->login_info();
|
||
|
$model = D("Giftbag");
|
||
|
$exist = $model->checkAccountGiftExist($logininfo['user_id'],$gift_id);
|
||
|
if($exist){
|
||
|
$this->error("您已经领取过该礼包!");
|
||
|
}
|
||
|
$novice = $model->getNovice($logininfo['user_id'],$logininfo['account'],$gift_id);
|
||
|
if(empty($novice)){
|
||
|
$this->error("暂无激活码");
|
||
|
}
|
||
|
$this->success("领取成功",$novice);
|
||
|
}
|
||
|
|
||
|
}
|