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.
183 lines
6.3 KiB
PHTML
183 lines
6.3 KiB
PHTML
5 years ago
|
<?php
|
||
|
namespace Sdk\Controller;
|
||
|
use Think\Controller;
|
||
|
use Common\Api\GaemApi;
|
||
|
class GameGiftPageController extends BaseController{
|
||
|
|
||
|
public function gift_list($game_id = 0){
|
||
|
|
||
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
||
|
$gift = M("Giftbag","tab_");
|
||
|
$map['game_id'] = $request['game_id'];
|
||
|
if(!empty($request['server_id']))
|
||
|
{
|
||
|
$map['server_id'] = $request['server_id'];
|
||
|
}
|
||
|
|
||
|
$map['status']=1;
|
||
|
switch ($request['sdk_version']) {
|
||
|
case 1:
|
||
|
case 2:
|
||
|
$map['sdk_version'] = $request['sdk_version'];
|
||
|
break;
|
||
|
}
|
||
|
$list = $gift
|
||
|
->field("id,giftbag_name,novice,start_time,end_time,desribe,game_name")
|
||
|
->where($map)
|
||
|
->select();
|
||
|
//遍历数据获取游戏图片地址
|
||
|
foreach ($list as $key => $val) {
|
||
|
$res = M('gift_record','tab_')->field('id')->where(['gift_id' => $val['id'],'user_id' => $this->user_id])->find();
|
||
|
if($res){
|
||
|
$list[$key]['received']=1;
|
||
|
}else{
|
||
|
$list[$key]['received']=0;
|
||
|
}
|
||
|
|
||
|
if($val['end_time'] != 0 && NOW_TIME > $val['end_time'])
|
||
|
{
|
||
|
unset($list[$key]);
|
||
|
}
|
||
|
unset($list[$key]['novice']);
|
||
|
$list[$key]['icon'] = new_icon_url($val['icon']);
|
||
|
$list[$key]['now_time'] = NOW_TIME;
|
||
|
}
|
||
|
$game = M('game','tab_')->where(['id' => $request['game_id']])->field('icon,game_name')->find();
|
||
|
$game['icon'] = new_icon_url($game['icon']);
|
||
|
$game['gift_num'] = count($list);
|
||
|
$this->assign('user_id',$this->user_id);
|
||
|
$this->assign('game_id',$request['game_id']);
|
||
|
$this->assign('game',$game);
|
||
|
$this->assign('data',$list);
|
||
|
$this->display('lists');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function details($gift_id = '',$user_id = '')
|
||
|
{
|
||
|
if(empty($gift_id))
|
||
|
{
|
||
|
$this->error('礼包不存在');
|
||
|
}
|
||
|
|
||
|
$content = M('Giftbag','tab_')->where(['id' => $gift_id])->field('id,novice,giftbag_name,start_time,end_time,desribe,digest')->find();
|
||
|
|
||
|
$novice = M('gift_record','tab_')->field('id')->where(['gift_id' => $gift_id,'user_id' => $user_id])->getField('novice');
|
||
|
|
||
|
$content['start_time'] = date('Y-m-d H:i:s',$content['start_time']);
|
||
|
$content['end_time'] = $content['end_time'] == 0?'长期有效':date('Y-m-d H:i:s',$content['start_time']);
|
||
|
|
||
|
if($content['novice']!='')
|
||
|
{
|
||
|
$novice_num = count(explode(',', $content['novice']));
|
||
|
$content['novice_num'] = $novice_num;//是否有剩余
|
||
|
}else{
|
||
|
$content['novice_num'] = 0;//是否剩余
|
||
|
}
|
||
|
|
||
|
$this->assign('content',$content);
|
||
|
$this->assign('novice',$novice);
|
||
|
$this->display('details');
|
||
|
}
|
||
|
|
||
|
public function receive($gift_id = 0,$user_id = 0,$game_id = 0,$game_name = "")
|
||
|
{
|
||
|
if(empty($gift_id))
|
||
|
{
|
||
|
$this->error('礼包不存在');
|
||
|
}
|
||
|
|
||
|
$content = M('Giftbag','tab_')->where(['id' => $gift_id])->field('id,novice,giftbag_name,start_time,end_time,desribe,digest')->find();
|
||
|
|
||
|
$content['start_time'] = date('Y-m-d H:i:s',$content['start_time']);
|
||
|
$content['end_time'] = $content['end_time'] == 0?'长期有效':date('Y-m-d H:i:s',$content['start_time']);
|
||
|
|
||
|
if($content['novice']!='')
|
||
|
{
|
||
|
$novice = count(explode(',', $content['novice']));
|
||
|
$content['novice_num'] = $novice;//是否有剩余
|
||
|
}else{
|
||
|
$content['novice_num'] = 0;//是否剩余
|
||
|
}
|
||
|
|
||
|
$res = M('gift_record','tab_')->field('id')->where(['gift_id' => $gift_id,'user_id' => $user_id])->find();
|
||
|
if($res){
|
||
|
$content['received']=1;
|
||
|
}else{
|
||
|
$content['received']=0;
|
||
|
}
|
||
|
$this->assign('user_id',$user_id);
|
||
|
$this->assign('gift_id',$gift_id);
|
||
|
$this->assign('game_id',$game_id);
|
||
|
$this->assign('game_name',$game_name);
|
||
|
$this->assign('content',$content);
|
||
|
$this->display('receive');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
*领取礼包
|
||
|
*/
|
||
|
public function receive_gift($user_id = 0,$gift_id = 0,$game_id = 0,$game_name = ""){
|
||
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
||
|
$post = I('post.');
|
||
|
$user_id = $post['user_id'];
|
||
|
$gift_id = $post['gift_id'];
|
||
|
$game_id = $post['game_id'];
|
||
|
$game_name = $post['game_name'];
|
||
|
$gift = M('giftbag','tab_');
|
||
|
$novice = $gift->where(["id" => $gift_id])->field("id,giftbag_name,novice")->find();
|
||
|
if(empty($novice['novice'])){
|
||
|
echo "该礼包已被领完";die();
|
||
|
}
|
||
|
else{
|
||
|
#将激活码分成数据
|
||
|
$novice_arr = explode(",",$novice['novice']);
|
||
|
#礼包记录数据
|
||
|
$data_record['user_id'] = $user_id;
|
||
|
$data_record['game_id'] = $game_id;
|
||
|
$data_record['game_name'] = $game_name;
|
||
|
$data_record['gift_id'] = $gift_id;
|
||
|
$data_record['gift_name'] = $novice['giftbag_name'];
|
||
|
$data_record['novice'] = $novice_arr[0];
|
||
|
$this->add_gift_record($data_record);
|
||
|
#领取成功后移除这个激活码
|
||
|
unset($novice_arr[0]);
|
||
|
#将新的激活码转换成字符串 保存
|
||
|
$act['novice']=implode(",", $novice_arr);
|
||
|
$act['novice_num'] = count($novice_arr);
|
||
|
$gift->where("id=".$gift_id)->save($act);
|
||
|
$ddd['novice'] = $data_record['novice'];
|
||
|
echo "领取成功";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
*添加礼包领取记录
|
||
|
*/
|
||
|
private function add_gift_record($data = array()){
|
||
|
$record = M('GiftRecord',"tab_");
|
||
|
$map['user_id'] = $data['user_id'];
|
||
|
$map['gift_id'] = $data['gift_id'];
|
||
|
$isReceive = $record->where($map)->find();
|
||
|
if(!empty($isReceive)){
|
||
|
$ddd['novice'] = $isReceive['novice'];
|
||
|
echo "您已经领取过该礼包";die();
|
||
|
}
|
||
|
$user_data = get_user_entity($data['user_id']);
|
||
|
$data_record['game_id'] = $data['game_id'];
|
||
|
$data_record['game_name'] = $data['game_name'];
|
||
|
$data_record['server_id'] = 0;
|
||
|
$data_record['server_name'] = "";
|
||
|
$data_record['gift_id'] = $data['gift_id'];
|
||
|
$data_record['gift_name'] = $data['gift_name'];
|
||
|
$data_record['status'] = 0;
|
||
|
$data_record['novice'] = $data['novice'];
|
||
|
$data_record['user_id'] = $data['user_id'];
|
||
|
$data_record['user_account'] = $user_data['account'];
|
||
|
$data_record['user_nickname'] = $user_data['nickname'];
|
||
|
$data_record['create_time'] = NOW_TIME;
|
||
|
return $record->add($data_record);
|
||
|
}
|
||
|
|
||
|
}
|