|
@@ -67,7 +67,7 @@ class Active extends Api
|
|
|
}
|
|
|
|
|
|
//奖项参数
|
|
|
- $conf_arr = Db::name('actives_info')->field('id,name,info,rate,number,msg')->where(['active_id'=>$active['id'],'is_show'=>1])->order('sort asc,id asc')->limit(6)->select();
|
|
|
+ $conf_arr = Db::name('actives_info')->field('id,name,info,rate,number,gift_ids')->where(['active_id'=>$active['id'],'is_show'=>1])->order('sort asc,id asc')->limit(6)->select();
|
|
|
|
|
|
//目前已有奖项
|
|
|
$user_log = Db::name('actives_user_log')->field('active_info_id,count(id) as num')->where(['active_id'=>$active['id']])->group('active_info_id')->select();
|
|
@@ -116,18 +116,57 @@ class Active extends Api
|
|
|
|
|
|
Db::startTrans();
|
|
|
|
|
|
+ //礼物id
|
|
|
+ $gift_id = 0;
|
|
|
+ $remark = $result['info'];
|
|
|
+ if(!empty($result['gift_ids'])){
|
|
|
+ $gift_ids = explode(',',$result['gift_ids']);
|
|
|
+ $gift_id = $gift_ids[rand(0,count($gift_ids)-1)];
|
|
|
+
|
|
|
+ $gift_info = Db::name('gift')->where('id',$gift_id)->find();
|
|
|
+ if(!empty($gift_info)){
|
|
|
+ //加入到背包
|
|
|
+ $back = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'gift_id' => $gift_id,
|
|
|
+ 'name' => $gift_info['name'],
|
|
|
+ 'image' => $gift_info['image'],
|
|
|
+ 'gif_image' => $gift_info['special'],
|
|
|
+ 'value' => $gift_info['value'],
|
|
|
+ 'number' => 1,
|
|
|
+ 'is_use' => 0,
|
|
|
+ 'use_time' => 0,
|
|
|
+ 'get_way' => 1,
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+ $gift_back = Db::name('gift_back')->insertGetId($back);
|
|
|
+ if(!$gift_back){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('加入背包失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $remark .= ':'.$gift_info['name'];
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $gift_id = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//插入抽奖记录
|
|
|
$data = [];
|
|
|
$data['user_id'] = $this->auth->id;
|
|
|
$data['active_id'] = $active['id'];
|
|
|
$data['active_info_id'] = $result['id'];
|
|
|
+ $data['gift_id'] = $gift_id;
|
|
|
|
|
|
$data['name'] = $result['name'];
|
|
|
$data['status'] = 0;
|
|
|
- $data['remark'] = $result['info'];
|
|
|
+ $data['remark'] = $remark;
|
|
|
$data['createtime'] = $time;
|
|
|
$log_id = Db::name('actives_user_log')->insertGetId($data);
|
|
|
if(!$log_id){
|
|
|
+ Db::rollback();
|
|
|
$this->error('抽奖记录更新有误');
|
|
|
}
|
|
|
|
|
@@ -141,6 +180,8 @@ class Active extends Api
|
|
|
Db::commit();
|
|
|
unset($result['name']);
|
|
|
unset($result['info']);
|
|
|
+ unset($result['gift_ids']);
|
|
|
+ $result['remark'] = $remark;
|
|
|
$this->success('success',$result);
|
|
|
}
|
|
|
|