Files
yusheng-php/application/api/model/Gift.php

147 lines
5.4 KiB
PHP
Raw Normal View History

2025-08-07 20:21:47 +08:00
<?php
namespace app\api\model;
2025-12-25 16:20:02 +08:00
use think\Cache;
2025-08-07 20:21:47 +08:00
use think\Model;
use think\Db;
use think\Session;
class Gift extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 定义字段类型
protected $label = [1=>'热门',2=>'趣味', 3=>'情侣', 4=>'挂件'];
protected $table = 'fa_vs_gift';
//获取礼物类型
public function get_gift_label()
{
2025-12-25 16:28:50 +08:00
$giftType = [];
2025-10-20 09:59:39 +08:00
$giftTypeData = db::name('vs_gift_label')->where('delete_time',0)->where('tid',1)->order("sort asc,id desc")->select();
2025-08-07 20:21:47 +08:00
foreach ($giftTypeData as $key => $value) {
$giftType[$key]['id'] = $value['id'];
$giftType[$key]['name'] = $value['name'];
}
return ['code' => 1, 'msg' => '获取成功', 'data' => $giftType];
}
2025-12-25 16:20:02 +08:00
//拉取礼物列表
public function get_gift_list($label = 0,$room_id = 0,$user_id = 0)
2025-08-07 20:21:47 +08:00
{
2025-12-25 16:20:02 +08:00
$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;
}
}
//先从缓存获取
if($is_lock){
$cache_key = 'gift_list_'.$label.'_'.$is_lock;
}else{
$cache_key = 'gift_list_'.$label;
}
$list = json_decode(Cache::get($cache_key), true);
if($list){
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
}
2025-08-07 20:21:47 +08:00
$map['delete_time'] = 0;
$where['is_show'] = 1;
if ($label && $label != 99) {
2025-08-07 20:21:47 +08:00
$map['label'] = $label;
}
if ($label == 99) {
$gift_price = get_system_config_value('room_love_auction_cion');
$where['gift_price'] = ['>',$gift_price];
$where['label'] = ['<>',2];
2025-08-07 20:21:47 +08:00
}
2025-12-25 16:20:02 +08:00
2025-12-17 12:57:36 +08:00
$is_open_blind_box_turntable = 1;
// if($room_id){
// $is_open_blind_box_turntable = Db::name('vs_room')->where(['id'=>$room_id])->value('is_open_blind_box_turntable');
// }
2025-12-23 16:19:57 +08:00
$list = $this->field('gid as gift_id,gift_name,base_image,gift_price,icon')->where($map)->where($where)->order('sort desc, gift_price asc')->select();
2025-08-07 20:21:47 +08:00
if($label==2){
2025-10-20 09:59:39 +08:00
$list_data = [];
2025-08-07 20:21:47 +08:00
foreach ($list as &$v) {
//获取盲盒列表
2025-10-20 09:59:39 +08:00
$box_list = Db::name('vs_gift_bag')->where(['status'=>1])->where(['activities_id'=>["in",[4,5]]])->select();
2025-08-07 20:21:47 +08:00
foreach ($box_list as $key =>$box) {
$ext = json_decode($box['ext'],true);
if ($ext['gift_id'] == $v['gift_id']) {
$v['gift_bag_name'] = $box['name'];
$v['rule'] = $ext['description'];
$v['rule_url'] = get_system_config_value('web_site')."/api/Page/get_gift_box_rule?box_id=".$box["id"];
2025-10-20 09:59:39 +08:00
$v['activities_id'] = $box['activities_id'];
$v['gift_bag'] = $box['id'];
2025-08-07 20:21:47 +08:00
break;
}
}
2025-12-25 14:49:41 +08:00
//爆币
$pool_gift_id = db::name('bb_lottery_config')->where(['key' => 'pool_gift_id'])->value('value');
if($pool_gift_id == $v['gift_id']){
2025-12-25 16:29:14 +08:00
$v['gift_bag_name'] = "幸运币活动";
$v['rule'] = "幸运羽币";
$v['rule_url'] = get_system_config_value('web_site')."/api/Page/page_show?id=35";
2025-12-25 14:49:41 +08:00
$v['activities_id'] = 88;
$v['gift_bag'] = 0;
}
2025-08-07 20:21:47 +08:00
}
2025-10-20 09:59:39 +08:00
foreach ($list as $gift) {
if($is_open_blind_box_turntable == 1){
$list_data[] = $gift;
}else{
if(isset($gift['activities_id']) && $gift['activities_id'] == 4){
$list_data[] = $gift;
}
}
}
2025-12-23 16:19:57 +08:00
// usort($list_data, function($a, $b) {
// return $a['gift_id'] <=> $b['gift_id'];
// });
2025-10-20 09:59:39 +08:00
$list = $list_data;
2025-08-07 20:21:47 +08:00
}
2025-12-25 16:20:02 +08:00
2025-11-18 17:42:58 +08:00
//获取配置里面的CP礼物
$cp_gift_ids = explode(',', get_system_config_value('cp_gift_id'));
2025-12-12 18:27:36 +08:00
$teacher_gift_ids = explode(',', get_system_config_value('master_special_gift'));
2025-11-18 18:21:32 +08:00
$cp_gift = [];
2025-12-12 18:27:36 +08:00
$teacher_gift = [];
2025-11-18 18:21:32 +08:00
foreach ($list as $key =>&$v) {
$v['is_lock'] = $is_lock;
2025-11-18 17:42:58 +08:00
if (in_array($v['gift_id'], $cp_gift_ids)) {
$v['is_cp'] = 1;
2025-11-18 18:21:32 +08:00
$cp_gift[] = $v;
unset($list[$key]);
2025-11-18 17:42:58 +08:00
}else{
$v['is_cp'] = 0;
}
2025-12-12 18:27:36 +08:00
if (in_array($v['gift_id'], $teacher_gift_ids)) {
$v['is_teacher'] = 1;
$teacher_gift[] = $v;
unset($list[$key]);
}else{
$v['is_teacher'] = 0;
}
}
2025-11-18 18:21:32 +08:00
//如果有CP礼物 则放在最前面
if ($cp_gift) {
array_unshift($list, ...$cp_gift);
}
2025-12-12 18:27:36 +08:00
if ($teacher_gift) {
array_unshift($list, ...$teacher_gift);
}
2025-12-25 16:20:02 +08:00
//设置缓存
Cache::set($cache_key, json_encode($list), 3600);
2025-08-07 20:21:47 +08:00
return ['code' => 1, 'msg' => '获取成功', 'data' => $list];
}
}