新需求: 盲盒转盘开发-转盘抽奖接口开发-抽奖记录接口 -送礼接口调整
This commit is contained in:
@@ -184,6 +184,8 @@ class BlindBox extends adminApi
|
||||
public function blind_box_edit(){
|
||||
$id = input('id', '');
|
||||
$quantity = input('quantity', 0);
|
||||
$is_world_show = input('is_world_show', 0);
|
||||
$gift_id = input('gift_id', 0);
|
||||
if(empty($id)){
|
||||
return V(0,"参数错误");
|
||||
}
|
||||
@@ -195,8 +197,10 @@ class BlindBox extends adminApi
|
||||
$data = [];
|
||||
$data['quantity'] = $quantity;
|
||||
$data['remaining_number'] = $quantity;
|
||||
if($weight){
|
||||
$data['$is_world_show'] = $is_world_show;
|
||||
$data['weight'] = $weight;
|
||||
if(!empty($gift_id)){
|
||||
$data['foreign_id'] = $gift_id;
|
||||
}
|
||||
$res = db::name($this->table)->where(['id'=>$id])->update($data);
|
||||
if($res){
|
||||
|
||||
@@ -48,4 +48,27 @@ class BlindBoxTurntable extends BaseCom
|
||||
$reslut = model('BlindBoxTurntableGift')->gift_send($send_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取我的抽奖记录
|
||||
*/
|
||||
public function get_my_record(){
|
||||
$user_id = $this->uid;
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_user_record($gift_bag_id,$user_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取全服抽奖记录
|
||||
*/
|
||||
public function get_all_record(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_all_record($gift_bag_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,7 @@ class BlindBoxTurntableGift extends Model
|
||||
$result_data = [
|
||||
'title' => $box['name'],
|
||||
'rule_url' => get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"],
|
||||
'rule' => $ext['introd'],
|
||||
'box_price' => $box_gift['gift_price'],
|
||||
'gift_list' => $gift_list,
|
||||
];
|
||||
@@ -54,9 +55,23 @@ class BlindBoxTurntableGift extends Model
|
||||
$ext = json_decode($bag_data['ext'],true);
|
||||
$bag_gift = db::name("vs_gift")->where(['gid'=>$ext['gift_id']])->find();// 获取盲盒信息
|
||||
$toarray = explode(',',$gift_user_ids);
|
||||
//判断是否有足够的金币
|
||||
$user_waller = db::name('user_wallet')->where(['user_id'=>$user_id])->find();
|
||||
if ($user_waller['coin'] < $bag_gift['gift_price'] * $num) {
|
||||
return ['code' => 0, 'msg' => '用户金币不足', 'data' => null];
|
||||
}
|
||||
//盲盒转盘抽奖记录
|
||||
$box_turntable_log = db::name('vs_blind_box_turntable_log')->insertGetId([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'num' => $num,
|
||||
'room_id' => $room_id,
|
||||
'bag_price' => $bag_gift['gift_price'],
|
||||
'createtime' => time()
|
||||
]);
|
||||
foreach ($toarray as $gift_user_id){
|
||||
for($i = 0; $i < $num; $i++){
|
||||
$reslut_draw_gift_data = $this->draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$bag_gift['gift_price'],$bag_data['periods'],$room_id);
|
||||
$reslut_draw_gift_data = $this->draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$bag_gift['gift_price'],$bag_data['periods'],$room_id,$box_turntable_log);
|
||||
$reslut_draw_gift[] = $reslut_draw_gift_data['data'];
|
||||
}
|
||||
}
|
||||
@@ -89,16 +104,18 @@ class BlindBoxTurntableGift extends Model
|
||||
}
|
||||
}
|
||||
$reslut_gift = array_values($reslut_gift);
|
||||
//盲盒转盘抽奖记录
|
||||
$box_turntable_log = db::name('vs_blind_box_turntable_log')->insertGetId([
|
||||
'user_id' => $user_id,
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
'num' => $num,
|
||||
'room_id' => $room_id,
|
||||
'bag_price' => $bag_gift['gift_price'],
|
||||
'lottery_result' => json_encode($reslut_gift),
|
||||
foreach ($reslut_gift as $key => $value) {
|
||||
db::name('vs_blind_box_turntable_results_log')->insert([
|
||||
'tid' => $box_turntable_log,
|
||||
'gift_user_id' => $value['gift_user_id'],
|
||||
'gift_id' => $value['gift_id'],
|
||||
'count' => $value['count'],
|
||||
'gift_price' => $value['gift_price'],
|
||||
'all_gift_price' => $value['gift_price'] * $value['count'],
|
||||
'createtime' => time()
|
||||
]);
|
||||
}
|
||||
$reslut = [];
|
||||
$reslut['blind_box_turntable_id'] = $box_turntable_log;
|
||||
$reslut['reslut_list'] = array_values($reslut_data);
|
||||
return V(1,"成功", $reslut);
|
||||
@@ -106,7 +123,7 @@ class BlindBoxTurntableGift extends Model
|
||||
/*
|
||||
* 单人单次抽奖
|
||||
*/
|
||||
public function draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$gift_price,$periods,$room_id=0){
|
||||
public function draw_gift_one($gift_bag_id, $user_id, $gift_user_id,$gift_price,$periods,$room_id=0,$box_turntable_log=0){
|
||||
//随机获取一个礼物
|
||||
$where = [
|
||||
'gift_bag_id' => $gift_bag_id,
|
||||
@@ -151,6 +168,7 @@ class BlindBoxTurntableGift extends Model
|
||||
$data = [];
|
||||
$data['user_id'] = $user_id;
|
||||
$data['gift_user_id'] = $gift_user_id;
|
||||
$data['parent_id'] = $box_turntable_log;
|
||||
$data['gift_bag_id'] = $gift_bag_id;
|
||||
$data['gift_id'] = $gift_bag_detail['foreign_id'];
|
||||
$data['periods'] = $periods;
|
||||
@@ -194,14 +212,72 @@ class BlindBoxTurntableGift extends Model
|
||||
if(!$blind_box_turntable){
|
||||
return ['code' => 0, 'msg' => '数据不存在'];
|
||||
}
|
||||
$reslut_gift = json_decode($blind_box_turntable['lottery_result'],true);
|
||||
foreach ($reslut_gift as $key => $value) {
|
||||
$res = model('GiveGift')->give_gift($blind_box_turntable['user_id'], $value['gift_user_id'], $value['gift_id'], $value['count'],2,1, $blind_box_turntable['room_id']);
|
||||
$blind_box_turntable_log = db('vs_blind_box_turntable_results_log')->where('tid',$send_id)->select();
|
||||
if(!$blind_box_turntable_log){
|
||||
return ['code' => 0, 'msg' => '开奖数据不存在'];
|
||||
}
|
||||
//获取盲盒配置
|
||||
$bag_data = db::name("vs_gift_bag")->field('id,name,ext,periods')->where('id',$blind_box_turntable['gift_bag_id'])->find();
|
||||
$ext = json_decode($bag_data['ext'],true);
|
||||
foreach ($blind_box_turntable_log as $key => $value) {
|
||||
$give_gift_ext['gift_id'] = $value['gift_id'];
|
||||
$give_gift_ext['count'] = $value['count'];
|
||||
$give_gift_ext['gift_price'] = $value['gift_price'];
|
||||
$give_gift_ext['all_gift_price'] = $value['all_gift_price'];
|
||||
$give_gift_ext['is_draw_gift'] = 1;
|
||||
$res = model('GiveGift')->give_gift($blind_box_turntable['user_id'], $value['gift_user_id'], $ext['gift_id'], $value['count'],2,1, $blind_box_turntable['room_id'],$give_gift_ext);
|
||||
if (isset($res) && $res['code'] != 1) {
|
||||
return V(0, $res['msg']);
|
||||
}
|
||||
db('vs_blind_box_turntable_results_log')->where('id', $value['id'])->update(['is_sued' => 1, 'updatetime' => time()]);
|
||||
}
|
||||
$res = db('vs_blind_box_turntable_log')->where('id', $blind_box_turntable['id'])->update(['is_sued' => 1, 'updatetime' => time()]);
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $res];
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => null];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取用户抽奖记录
|
||||
*/
|
||||
public function get_user_record($gift_bag_id,$user_id=0,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
if($user_id > 0){
|
||||
$where['b.user_id'] = $user_id;
|
||||
}
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','a.gift_user_id = c.id','left')
|
||||
->join('vs_gift d','d.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,a.gift_user_id,b.createtime,c.nickname,d.gift_name as gift_name,d.play_image')
|
||||
->where($where)
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
/*
|
||||
* 获取全服抽奖记录
|
||||
*/
|
||||
public function get_all_record($gift_bag_id,$page=1,$page_size=12){
|
||||
$where = [];
|
||||
$where['b.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.gift_bag_id'] = $gift_bag_id;
|
||||
$where['d.is_world_show'] = 1;
|
||||
$list = db('vs_blind_box_turntable_results_log')
|
||||
->alias('a')
|
||||
->join('vs_blind_box_turntable_log b','b.id = a.tid','left')
|
||||
->join('user c','b.user_id = c.id','left')
|
||||
->join('vs_gift_bag_detail d','d.foreign_id = a.gift_id','left')
|
||||
->join('vs_gift e','e.gid = a.gift_id','left')
|
||||
->field('a.gift_id,a.count,a.gift_user_id,b.createtime,c.nickname,d.name as gift_name,e.play_image')
|
||||
->where($where)
|
||||
->page($page,$page_size)
|
||||
->select();
|
||||
foreach ($list as &$v){
|
||||
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
|
||||
}
|
||||
return ['code' => 1, 'msg' => '成功', 'data' => $list];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class GiveGift extends Model
|
||||
* @return array
|
||||
* 用户,在房间中,给谁,送了什么礼物,多少个,来源
|
||||
*/
|
||||
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0)
|
||||
public function give_gift($uid,$to_uid,$gid,$num,$from_type,$type,$from_id = 0,$pit_number = 0,$change_type = 0,$ext = [])
|
||||
{
|
||||
//送的礼物信息
|
||||
$gift_info = Db::name('vs_gift')->where(['gid'=>$gid])
|
||||
@@ -133,6 +133,18 @@ class GiveGift extends Model
|
||||
//查询礼物是否是盲盒
|
||||
if($gift_info['label'] == 2){//趣味礼物(盲盒)
|
||||
$gift_price_box = 0;
|
||||
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){
|
||||
//收礼记录行为日志
|
||||
$give_gift = $this -> change_user_give_gift_log($uid,$ext['gift_id'],$ext['all_gift_price'],$ext['count'],$to_id,$from_type,$type,$from_id,$pit_number,2);
|
||||
if(!$give_gift){
|
||||
Db::rollback();
|
||||
return ['code' => 0, 'msg' => '送礼失败', 'data' => null];
|
||||
}
|
||||
$gift_price_box = $ext['all_gift_price'];
|
||||
$gift_box[0]['gift_id'] = $ext['gift_id'];
|
||||
$gift_box[0]['gift_price'] = $ext['all_gift_price'];
|
||||
$gift_box[0]['give_gift_id'] = $give_gift;
|
||||
}else{
|
||||
for($i = 0; $i < $num; $i++){
|
||||
$gift_box1[$i] = $this -> open_box($gid,$uid,$to_id,$from_id);
|
||||
if($gift_box1[$i]['code'] != 1){
|
||||
@@ -150,6 +162,7 @@ class GiveGift extends Model
|
||||
$gift_price_box += $gift_box[$i]['gift_price'];
|
||||
Log::record("盲盒礼物".json_encode($gift_box1),"info");
|
||||
}
|
||||
}
|
||||
$gift_total += $gift_price_box;
|
||||
$gift_price = $gift_price_box;
|
||||
}else{
|
||||
@@ -366,6 +379,51 @@ class GiveGift extends Model
|
||||
}
|
||||
//推送礼物特效
|
||||
if($gift_info['label'] == 2){
|
||||
if(isset($ext['is_draw_gift']) && $ext['is_draw_gift'] == 1){
|
||||
$draw_gift = Db::name('vs_gift')->where(['gid'=>$ext['gift_id']])->find();
|
||||
$textMessage = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$ext['count'];
|
||||
$text = [
|
||||
'FromUserInfo' => $FromUserInfo,
|
||||
'ToUserInfo' => $ToUserInfo,
|
||||
'GiftInfo' => $draw_gift,
|
||||
'GiftNum' => $draw_gift['gift_name'],
|
||||
'text' => $textMessage
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1005,$from_id,$text);
|
||||
$roomtype = Db::name('vs_room')->where(['id' => $from_id])->value('type_id');
|
||||
if($roomtype == 6){
|
||||
//推送消息
|
||||
$hot_value = db::name('vs_give_gift')->where('from_id', $from_id)->where('from',6)
|
||||
->sum('total_price');
|
||||
$text1 = [
|
||||
'room_id' => $from_id,
|
||||
'hot_value' => $hot_value * 10,
|
||||
'text' => '房间心动值变化'
|
||||
];
|
||||
//聊天室推送系统消息
|
||||
model('Chat')->sendMsg(1028,$from_id,$text1);
|
||||
}else{
|
||||
if($draw_gift['is_public_server'] == 1){
|
||||
//推送礼物横幅
|
||||
$push = new Push(UID, $from_id);
|
||||
$room_name = Db::name('vs_room')->where(['id' => $from_id, 'apply_status' => 2])->value('room_name');
|
||||
$text = $FromUserInfo['nickname'] . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $num;
|
||||
$text_list_new = [
|
||||
'text' => $text,
|
||||
'gift_picture' => $draw_gift['base_image'],
|
||||
'room_id' => $from_id,
|
||||
'fromUserName' => $FromUserInfo['nickname'],
|
||||
'toUserName' => $ToUserInfo['nickname'],
|
||||
'giftName' => $draw_gift['gift_name'],
|
||||
'roomId' => $from_id,
|
||||
'number' => $num,
|
||||
];
|
||||
$push->giftBanner($text_list_new);
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
//循环开出来的盲盒,相同的礼物只推送一次,消息推送为$FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 趣味礼物 ' .$gift_inf['gift_name'].' x 多少';
|
||||
if($gift_box){
|
||||
// 统计相同礼物的数量
|
||||
@@ -460,7 +518,7 @@ class GiveGift extends Model
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
$text = $FromUserInfo['nickname'] . ' 送给 ' . $ToUserInfo['nickname'].' 礼物 ' .$gift_info['gift_name'].' x ' .$num;
|
||||
$text = [
|
||||
@@ -1023,7 +1081,7 @@ class GiveGift extends Model
|
||||
/*
|
||||
* 开盲盒
|
||||
*/
|
||||
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0){
|
||||
public function open_box($gift_id,$user_id,$gift_user_id,$room_id=0,$gift_bag_id=0){
|
||||
//获取盲盒配置
|
||||
$bag_list = db::name("vs_gift_bag")->field('id,name,ext,periods')->where(['activities_id'=>4,'status'=>1])->select();
|
||||
$gift_bag_id = 0;
|
||||
|
||||
Reference in New Issue
Block a user