礼包领取

master
chenzhi 5 years ago
parent 5635519c17
commit 8f5f4ba9bc

@ -399,4 +399,23 @@ class SsgController extends BaseController {
}
}
/**
* 领取激活码
* @param $token
* @param $gift_id
* author: xmy 280564871@qq.com
*/
public function get_novice($user_id,$gift_id){
$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);
}
}

@ -291,8 +291,22 @@ class Ipa365Controller extends BaseController{
$giftbag = M('giftbag', 'tab_')->field("*")->where(array("game_id"=>$gameId,"giftbag_version"=>3))->find();
if(empty($giftbag)){
$giftbag = false;
}
}else{
$desribe = $giftbag['desribe'];
$mygif = $this->checkAccountGiftExist($userId,$giftbag['id']);
if(!empty($mygif)){
//已经领取
$giftbag =$mygif;
}else{
if($giftbag['novice_num']>0){
//领取
$giftbag = $this->getNovice($userId,$this->userinfo['account'],$giftbag['id']);
}
}
$giftbag['desribe'] = $desribe;
}
//验证是否领取
$this->assign('giftbag', $giftbag);
$this->display();
}
@ -338,7 +352,7 @@ class Ipa365Controller extends BaseController{
'pay_status' => 1,
))->find();
if (!$gamesign) {
// pp(M('game_supersign', 'tab_')->_sql());
// pp(M('game_supersign', 'tab_')->_sql());
$this->error("支付记录不存在");
}
if ($gamesign['url']) {
@ -430,4 +444,49 @@ class Ipa365Controller extends BaseController{
return $pay_;
}
//领取礼包码
public function getNovice($user_id,$account,$gift_id){
$data =M("giftbag",'tab_')->find($gift_id);
$novice_str = $data['novice'];
$novice_arr = str2arr($novice_str,",");
if (empty($novice_arr)){
return "";
}
$novice_arr = array_filter($novice_arr);
$novice = array_pop($novice_arr);
$data['novice_num'] = count($novice_arr);
$data['novice'] = arr2str($novice_arr,",");
M("giftbag",'tab_')->startTrans();
$novice_result = M("giftbag",'tab_')->save($data);
if(!empty($novice)){
//记录领取
$record['game_id'] = $data['game_id'];
$record['game_name'] = $data['game_name'];//get_game_name($data['game_id']);
$record['gift_id'] = $gift_id;
$record['gift_name'] = $data['giftbag_name'];
$record['status'] = 0;
$record['novice'] = $novice;
$record['user_id'] = $user_id;
$record['user_account'] = $account;
$record['create_time'] = time();
$record['start_time'] = $data['start_time'];
$record['end_time'] = $data['end_time'];
$record_result = M("gift_record",'tab_')->add($record);
}else{
$novice_result = false;
}
if($novice_result === false || $record_result === false){
M("giftbag",'tab_')->rollback();
return "";
}else{
M("giftbag",'tab_')->commit();
return $record;
}
}
public function checkAccountGiftExist($user_id,$gift_id){
$map['user_id'] = $user_id;
$map['gift_id'] = $gift_id;
return M("gift_record",'tab_')->field('*')->where($map)->find();
}
}

@ -136,7 +136,7 @@ p,input{
<ul>
<li >
<div class="gift-title">
<h2>{$giftbag['giftbag_name']}</h2>
<h2>{$giftbag['gift_name']}</h2>
</div>
<p class="gift-info">{$giftbag['desribe']}</p>
<p class="gift-code">

Loading…
Cancel
Save