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.
155 lines
6.1 KiB
PHP
155 lines
6.1 KiB
PHP
<?php
|
|
namespace Sdk\Controller;
|
|
use Think\Controller;
|
|
use Common\Api\GaemApi;
|
|
class GameGiftController extends BaseController{
|
|
|
|
/**
|
|
*游戏礼包列表
|
|
*2.0接口修改 change yyh 2018.10.17
|
|
*/
|
|
public function gift_list($game_id=0){
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
$gift = M("Giftbag","tab_");
|
|
$map['game_id'] = $request['game_id'];
|
|
$map['status']=1;
|
|
$map['giftbag_name'] = ['NEQ','超级签专属礼包'];
|
|
$row = $request['row']?:10;
|
|
$page = $request['p']?:1;
|
|
switch ($request['sdk_version']) {
|
|
case 1:
|
|
case 2:
|
|
$map['tab_game.sdk_version'] = $request['sdk_version'];
|
|
break;
|
|
}
|
|
$list = $gift
|
|
->field("tab_giftbag.id,tab_giftbag.giftbag_name,tab_giftbag.novice,tab_giftbag.start_time,tab_giftbag.end_time,tab_giftbag.desribe,tab_game.icon,tab_game.game_name")
|
|
->join("LEFT JOIN tab_game ON tab_giftbag.game_id = tab_game.id ")
|
|
->where($map)
|
|
->page($page,$row)
|
|
->select();
|
|
|
|
//遍历数据获取游戏图片地址
|
|
foreach ($list as $key => $val) {
|
|
$res=M('gift_record','tab_')->field('id')->where(['gift_id'=>$val['id'],'user_id'=>$request['user_id']])->find();
|
|
if($res){
|
|
$list[$key]['received']=1;
|
|
}else{
|
|
$list[$key]['received']=0;
|
|
}
|
|
if($val['novice']!=''){
|
|
$novice = count(explode(',', $val['novice']));
|
|
$list[$key]['surplus']=$novice;//是否有剩余
|
|
}else{
|
|
$list[$key]['surplus']=0;//是否剩余
|
|
}
|
|
unset($list[$key]['novice']);
|
|
$list[$key]['game_name'] = $val['game_name'];
|
|
$list[$key]['icon'] = new_icon_url($val['icon']);
|
|
$list[$key]['now_time'] = NOW_TIME;
|
|
}
|
|
$this->new_set_message(200,"成功",$list);
|
|
}
|
|
|
|
/**
|
|
*领取礼包
|
|
*/
|
|
public function receive_gift($user_id=0,$gift_id=0,$game_id=0,$game_name=""){
|
|
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
C(api('Config/lists'));
|
|
$user_id = $request['user_id'];
|
|
$gift_id = $request['gift_id'];
|
|
$game_id = $request['game_id'];
|
|
$game_name = $request['game_name'];
|
|
$gift = M('giftbag','tab_');
|
|
$novice = $gift->where(array("id"=>$gift_id))->field("id,giftbag_name,novice")->find();
|
|
if(empty($novice['novice'])){
|
|
$this->new_set_message(1015,"礼包已被领取完",[]);
|
|
}
|
|
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'];
|
|
$this->new_set_message(200,"领取成功",$ddd);
|
|
}
|
|
}
|
|
|
|
/**
|
|
*添加礼包领取记录
|
|
*/
|
|
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'];
|
|
$this->new_set_message(1014,"您已经领取过该礼包",$ddd);
|
|
}
|
|
$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);
|
|
}
|
|
|
|
|
|
/**
|
|
*礼包详情
|
|
*author yyh 2018.10.17
|
|
*/
|
|
public function gift_detail(){
|
|
$request = json_decode(base64_decode(file_get_contents("php://input")),true);
|
|
$request['user_id']=$request['user_id']?:-1;
|
|
$gift = M("Giftbag","tab_");
|
|
$map['tab_giftbag.id'] = $request['gift_id'];
|
|
$map['tab_giftbag.status'] = 1;
|
|
$list = $gift
|
|
->field("tab_giftbag.id,tab_giftbag.giftbag_name,tab_giftbag.novice,tab_giftbag.start_time,tab_giftbag.end_time,tab_giftbag.desribe,tab_giftbag.digest,tab_game.icon,tab_game.game_name,tab_gift_record.id as record_id,tab_gift_record.novice as record_novice")
|
|
->join("LEFT JOIN tab_game ON tab_giftbag.game_id = tab_game.id")
|
|
->join('tab_gift_record on tab_gift_record.gift_id = tab_giftbag.id and user_id = '.$request['user_id'],'left')
|
|
->where($map)
|
|
->find();
|
|
if($list['record_id']!=''){
|
|
$list['received']=1;
|
|
}else{
|
|
$list['received']=0;
|
|
}
|
|
if($list['novice']!=''){
|
|
$novice = count(explode(',', $list['novice']));
|
|
$list['surplus']=$novice;//是否有剩余
|
|
}else{
|
|
$list['surplus']=0;//是否剩余
|
|
}
|
|
unset($list['record_id']);
|
|
unset($list['novice']);
|
|
$list['icon'] = new_icon_url($list['icon']);
|
|
$this->new_set_message(200, "success", $list);
|
|
}
|
|
}
|