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.

337 lines
13 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);
}
public function getTFGiftbags() {
$game_id = I('post.game_id');
$status = 0;
$row = C('LIST_ROWS');
$map['status'] = 1;
$time = NOW_TIME;
$map['game_id'] = $game_id;
$map['giftbag_version'] = 4;
$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)
->select();
$existRecords = [];
if (count($lists) > 0 && $this->islogin()) {
$member = new SuserApi;
$logininfo = $member->login_info();
$conditions = [];
$conditions['user_id'] = $logininfo['user_id'];
$conditions['gift_id'] = ['in', array_column($lists, 'id')];
5 years ago
$existRecords = M("gift_record",'tab_')->field(['id', 'gift_id', 'novice'])->where($conditions)->select();
$existRecords = index_by_column('gift_id', $existRecords);
}
$records = [];
foreach ($lists as $key => $val){
$novices = str2arr($val['novice'],',');
$noviceNum = count(array_filter($novices));
5 years ago
$novice = '';
if (isset($existRecords[$val['id']])) {
$getStatus = 1;
5 years ago
$novice = $existRecords[$val['id']]['novice'];
} else {
$getStatus = 0;
}
$records[$key]['id'] = $val['id'];
$records[$key]['desribe'] = $val['desribe'];
$records[$key]['giftbag_name'] = $val['giftbag_name'];
$records[$key]['digest'] = $val['digest'];
$records[$key]['get_status'] = $getStatus;
5 years ago
$records[$key]['novice'] = $novice;
$records[$key]['novice_num'] = $noviceNum;
$records[$key]['game_icon'] = get_cover($val['icon'],'path');
$records[$key]['game_name'] = $val['giftbag_name'];
$records[$key]['useful_date'] = set_show_time($val['start_time'],'date') . ' 至 '. set_show_time($val['end_time'],'date','forever');
}
echo json_encode(['status' => true, 'message' => '获取成功', 'data' => ['records' => $records]]);
}
public function getNovice($gift_id){
if(!$this->islogin()) {
echo json_encode(['status' => false, 'code' => '1001', 'message' => '请先登录']); exit();
}
$giftId = I('post.gift_id');
$member = new SuserApi;
$logininfo = $member->login_info();
$model = D("Giftbag");
$exist = $model->checkAccountGiftExist($logininfo['user_id'], $giftId);
if($exist){
echo json_encode(['status' => false, 'code' => '1000', 'message' => '您已经领取过该礼包!']); exit();
}
$novice = $model->getNovice($logininfo['user_id'], $logininfo['account'], $giftId);
if(empty($novice)){
echo json_encode(['status' => false, 'code' => '1000', 'message' => '暂无激活码']); exit();
}
echo json_encode(['status' => true, 'code' => '0000', 'message' => '领取成功', 'data' => ['novice' => $novice]]); exit();
}
5 years ago
}