礼物列表新建控制器和方法
This commit is contained in:
29
application/api/controller/GiftNew.php
Normal file
29
application/api/controller/GiftNew.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
|
||||
class GiftNew extends BaseCom
|
||||
{
|
||||
|
||||
/*
|
||||
* 获取礼物列表
|
||||
* @param int $label 礼物标签
|
||||
* @param int $type 类型:1-房间送礼礼物,2-排麦设置插麦礼物,3-拍卖位选择拍卖礼物,4-歌手添加歌单礼物,5-动态打赏礼物
|
||||
* @return array
|
||||
*/
|
||||
public function get_gift_list()
|
||||
{
|
||||
$key_name = "api:gift_new:get_gift_list:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$label = input('label', 0);
|
||||
$type = input('type');
|
||||
if (empty($type)) {
|
||||
return V(0, 'type参数错误');
|
||||
}
|
||||
$reslut = model('GiftNew')->get_gift_list($this->uid, $type, $label);
|
||||
redis_unlocks($key_name);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
79
application/api/model/GiftNew.php
Normal file
79
application/api/model/GiftNew.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\model;
|
||||
|
||||
use think\Cache;
|
||||
use think\Model;
|
||||
use think\Db;
|
||||
|
||||
class GiftNew extends Model
|
||||
{
|
||||
/*
|
||||
* 获取礼物列表
|
||||
* @param int $label 礼物标签
|
||||
* @param int $type 类型:1-房间送礼礼物,2-排麦设置插麦礼物,3-拍卖位选择拍卖礼物,4-歌手添加歌单礼物,5-动态打赏礼物
|
||||
*/
|
||||
public function get_gift_list($user_id, $type, $label)
|
||||
{
|
||||
$is_lock = 0;
|
||||
if ($label == 13) { // 专属礼物
|
||||
$Nobility = model('api/Nobility')->getUserNobilityInfo($user_id);
|
||||
$power_list_ids = array_column($Nobility['power_list'],'id');
|
||||
if(!in_array(5,$power_list_ids)){
|
||||
$is_lock = 1;
|
||||
}
|
||||
}
|
||||
|
||||
//1,先从缓存获取
|
||||
if($is_lock){//根据这个判断是不是爵位礼物 创建不同的key
|
||||
$cache_key = 'gift_list_'.$label.'_'.$is_lock;
|
||||
}else{
|
||||
$cache_key = 'gift_list_'.$label;
|
||||
}
|
||||
//2,缓存获取
|
||||
$list = json_decode(Cache::get($cache_key), true);
|
||||
//获取到就返回
|
||||
if($list){
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
//================================从这里开始写逻辑==================================
|
||||
//根据type的值分析拉起礼物的场合 加$label的条件 给出对应的列表
|
||||
|
||||
//根据类型组装查询条件
|
||||
$where['is_show'] = 1;
|
||||
$where['delete_time'] = 0;
|
||||
switch ($type) {
|
||||
case 1:
|
||||
$where['label'] = $label;
|
||||
break;
|
||||
case 2:
|
||||
$where['label'] = 5;
|
||||
break;
|
||||
case 3:
|
||||
$where['type'] = 1;
|
||||
//爆币id
|
||||
$bb_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value');
|
||||
$where['gid'] = ['<>',$bb_gift_id];//拍卖位选礼物 不能是爆币这个礼物
|
||||
break;
|
||||
case 4:
|
||||
$where['type'] = 1;
|
||||
$where['gift_price'] = ['>',128];//歌单礼物价格要大于128 老板26年1月2号提的要求
|
||||
break;
|
||||
case 5:
|
||||
$where['type'] = 1;
|
||||
break;
|
||||
}
|
||||
$list = db::name('vs_gift')
|
||||
->field('gid as gift_id,gift_name,base_image,gift_price,icon')
|
||||
->where($where)->order('sort desc, gift_price asc')->select();
|
||||
|
||||
|
||||
//================================到这里结束逻辑==================================
|
||||
|
||||
//设置缓存
|
||||
Cache::set($cache_key, json_encode($list), 3600);
|
||||
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user