小时榜礼物配置
This commit is contained in:
@@ -8,7 +8,7 @@ class RoomHourRanking
|
||||
{
|
||||
public static function withdraw_status (){
|
||||
return [
|
||||
[25 => '全时段'],
|
||||
// [25 => '全时段'],
|
||||
[0 => '00:00-01:00'],
|
||||
[1 => '01:00-02:00'],
|
||||
[2 => '02:00-03:00'],
|
||||
@@ -64,6 +64,8 @@ class RoomHourRanking
|
||||
if($v['user_id']){
|
||||
$v['nickname'] = db::name('user')->where(['id'=>$v['user_id']])->value('nickname');
|
||||
}
|
||||
$v['stime'] = date('Y-m-d H:i', $v['stime']);
|
||||
$v['etime'] = date('Y-m-d H:i', $v['etime']);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -79,7 +81,11 @@ class RoomHourRanking
|
||||
//房间小时榜配置
|
||||
public function room_hour_ranking_config()
|
||||
{
|
||||
$list = db::name('vs_hour_ranking_config')->order('id', 'desc')->find();
|
||||
$list = db::name('vs_hour_ranking_config')->where('id', '1')->find();
|
||||
if($list){
|
||||
//open_time 字段转化为2025-09-30 07:00 的格式
|
||||
$list['open_time'] = $list['open_time'] ? date('Y-m-d H:i', $list['open_time']) : 0;
|
||||
}
|
||||
return V(1,"成功", $list);
|
||||
}
|
||||
|
||||
@@ -92,14 +98,97 @@ class RoomHourRanking
|
||||
$data['broadcast_times'] = input('broadcast_times');
|
||||
$data['is_open_xlh'] = input('is_open_xlh');
|
||||
$data['min_price'] = input('min_price');
|
||||
// $data['introd'] = input('introd');
|
||||
$open_time = input('open_time');
|
||||
$data['open_time'] = $open_time ? strtotime($open_time) : 0;
|
||||
$data['createtime'] = time();
|
||||
$data['updatetime'] = time();
|
||||
|
||||
$timeSlots = json_decode(input('timeJson'), true);
|
||||
|
||||
$timePeriods = $this->withdraw_status();
|
||||
|
||||
// 构建正确的时间映射关系
|
||||
$timeMap = [];
|
||||
foreach($timePeriods as $period) {
|
||||
foreach($period as $key => $value) {
|
||||
$timeMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
//$timeMap 里面 键值互换
|
||||
$timeMap = array_flip($timeMap);
|
||||
//开启事务
|
||||
db::startTrans();
|
||||
if($timeSlots){
|
||||
$insertData = [];
|
||||
foreach ($timeSlots as $timeSlot) {
|
||||
// $timeRange = ;
|
||||
$timeRange = $timeMap[$timeSlot['time']] ?? '99';
|
||||
|
||||
foreach ($timeSlot['reward'] as $rewardItem) {
|
||||
$hasReward = !empty($rewardItem['content']);
|
||||
|
||||
if ($hasReward) {
|
||||
// 有奖励内容:为每个奖励内容创建一条记录
|
||||
foreach ($rewardItem['content'] as $rewardContent) {
|
||||
if($rewardContent['type'] == 0){
|
||||
$coin = $rewardContent['value'];
|
||||
$gift_id = 0;
|
||||
$gift_name = '';
|
||||
}else{
|
||||
$coin = 0;
|
||||
$gift_id = $rewardContent['value'];
|
||||
$gift_name = $rewardContent['name'];
|
||||
}
|
||||
$insertData[] = [
|
||||
'time_id' => $timeRange,
|
||||
'ranking' => $rewardItem['index'],
|
||||
// 'rank_name' => $rewardItem['name'],
|
||||
'gift_type' => $rewardContent['type'],
|
||||
'gift_id' => $gift_id,
|
||||
'coin' => $coin,
|
||||
'name' => $gift_name,
|
||||
'createtime' => time()
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// 无奖励内容:插入一条空奖励记录
|
||||
$insertData[] = [
|
||||
'time_id' => $timeRange,
|
||||
'ranking' => $rewardItem['index'],
|
||||
// 'rank_name' => $rewardItem['name'],
|
||||
'gift_type' => 0,
|
||||
'gift_id' => 0,
|
||||
'coin' => 0,
|
||||
'name' => '',
|
||||
'createtime' => time(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 批量插入
|
||||
if (!empty($insertData)) {
|
||||
$del = db::name('vs_hour_ranking_gift_config')->where('id','>',0)->delete();
|
||||
$ins = db::name('vs_hour_ranking_gift_config')->insertAll($insertData);
|
||||
}else{
|
||||
$ins = false;
|
||||
$del = false;
|
||||
}
|
||||
|
||||
}else{
|
||||
$del = true;
|
||||
$ins = true;
|
||||
}
|
||||
|
||||
// $res = db::name('vs_hour_ranking_config')->where('id', $id)->update($data);
|
||||
$res = db::name('vs_hour_ranking_config')->where('id', $id)->update($data);
|
||||
if ($res) {
|
||||
// if ($del && $ins && $res) {
|
||||
if ($ins) {
|
||||
db::commit();
|
||||
return V(1, "成功");
|
||||
} else {
|
||||
db::rollback();
|
||||
return V(0, "失败");
|
||||
}
|
||||
}
|
||||
@@ -133,73 +222,6 @@ class RoomHourRanking
|
||||
//核心配置列表
|
||||
public function core_config_list()
|
||||
{
|
||||
$list = db::name('vs_hour_ranking_gift_config')->select();
|
||||
$data = [];
|
||||
|
||||
if($list){
|
||||
// 获取时间段对应关系
|
||||
$timePeriods = $this->withdraw_status();
|
||||
$timeMap = [];
|
||||
foreach($timePeriods as $period) {
|
||||
foreach($period as $key => $value) {
|
||||
$timeMap[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// 按时间段和排名分组数据
|
||||
$groupedData = [];
|
||||
foreach ($list as $item) {
|
||||
$timeId = $item['time_id'];
|
||||
$ranking = $item['ranking'];
|
||||
|
||||
if (!isset($groupedData[$timeId])) {
|
||||
$groupedData[$timeId] = [];
|
||||
}
|
||||
|
||||
if (!isset($groupedData[$timeId][$ranking])) {
|
||||
$groupedData[$timeId][$ranking] = [];
|
||||
}
|
||||
|
||||
// 根据礼物类型确定值
|
||||
if($item['gift_type'] == 1) {
|
||||
$value = $item['coin'];
|
||||
} else {
|
||||
$value = $item['gift_id'];
|
||||
}
|
||||
|
||||
$groupedData[$timeId][$ranking][] = [
|
||||
'type' => $item['gift_type'],
|
||||
'value' => $value
|
||||
];
|
||||
}
|
||||
|
||||
// 构建最终数据结构
|
||||
foreach ($groupedData as $timeId => $rankings) {
|
||||
$timeKey = $timeMap[$timeId] ?? "未知时间段";
|
||||
$data[$timeKey] = [];
|
||||
|
||||
// 按排名排序
|
||||
ksort($rankings);
|
||||
|
||||
foreach ($rankings as $ranking => $contents) {
|
||||
$data[$timeKey][] = [
|
||||
'index' => $ranking,
|
||||
'content' => $contents
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return V(1, "成功", $data);
|
||||
}
|
||||
|
||||
public function core_config_lists()
|
||||
{
|
||||
$list = db::name('vs_hour_ranking_gift_config')->select();
|
||||
$data = [];
|
||||
|
||||
// 按 time_id 和 ranking 重组数据
|
||||
$reorganizedData = [];
|
||||
$timePeriods = $this->withdraw_status();
|
||||
|
||||
// 构建正确的时间映射关系
|
||||
@@ -210,41 +232,118 @@ class RoomHourRanking
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($list as $item) {
|
||||
// $timeId = $item['time_id'];
|
||||
$timeId = $timeMap[$item['time_id']] ?? '未知时间段';
|
||||
$ranking = $item['ranking'];
|
||||
// 先按时间段和排名索引分组查询
|
||||
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
|
||||
->order('time_id')
|
||||
->column('time_id');
|
||||
|
||||
if (!isset($reorganizedData[$timeId])) {
|
||||
$reorganizedData[$timeId] = [];
|
||||
}
|
||||
if (!isset($reorganizedData[$timeId][$ranking])) {
|
||||
$reorganizedData[$timeId][$ranking] = [];
|
||||
}
|
||||
if($item['gift_id']){
|
||||
if($item['gift_type'] == 2){
|
||||
$gift_name = db::name('vs_gift')->where(['gid'=>$item['gift_id']])->value('gift_name');
|
||||
}
|
||||
if($item['gift_type'] == 3 || $item['gift_type'] == 4){
|
||||
$gift_name = db::name('vs_decorate')->where(['did'=>$item['gift_id']])->value('title');
|
||||
$result = [];
|
||||
foreach ($timeRanges as $timeRange) {
|
||||
// 查询该时间段的所有数据
|
||||
$rewards = db::name('vs_hour_ranking_gift_config')->where('time_id', $timeRange)
|
||||
->field('ranking, gift_type, gift_id,coin,name')
|
||||
->order('ranking')
|
||||
->select();
|
||||
|
||||
$rewardMap = [];
|
||||
foreach ($rewards as $reward) {
|
||||
$rankIndex = $reward['ranking'];
|
||||
|
||||
if (!isset($rewardMap[$rankIndex])) {
|
||||
$rewardMap[$rankIndex] = [
|
||||
'index' => $rankIndex,
|
||||
// 'name' => $reward['rank_name'],
|
||||
'content' => []
|
||||
];
|
||||
}
|
||||
|
||||
}else{
|
||||
$gift_name = '';
|
||||
// 添加奖励内容到content数组
|
||||
if ($reward['gift_id'] != 0 || $reward['coin'] != 0) {
|
||||
if($reward['gift_id'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['gift_id'],
|
||||
// 'coin' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
if($reward['coin'] != 0){
|
||||
$rewardMap[$rankIndex]['content'][] = [
|
||||
'type' => $reward['gift_type'],
|
||||
'value' => $reward['coin'],
|
||||
'name' => $reward['name'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$reorganizedData[$timeId][$ranking][] = [
|
||||
'gift_type' => $item['gift_type'],
|
||||
'gift_id' => $item['gift_id'],
|
||||
'gift_name' => $gift_name,
|
||||
'coin' => $item['coin']
|
||||
|
||||
// 按index排序
|
||||
ksort($rewardMap);
|
||||
|
||||
$result[] = [
|
||||
'time' => $timeMap[$timeRange],
|
||||
'reward' => array_values($rewardMap)
|
||||
];
|
||||
}
|
||||
|
||||
// 输出重组后的数据
|
||||
print_r($reorganizedData);
|
||||
return V(1, "成功", $data);
|
||||
return V(1, "成功", $result);
|
||||
|
||||
}
|
||||
|
||||
// public function core_config_lists()
|
||||
// {
|
||||
// $list = db::name('vs_hour_ranking_gift_config')->select();
|
||||
// $data = [];
|
||||
//
|
||||
// // 按 time_id 和 ranking 重组数据
|
||||
// $reorganizedData = [];
|
||||
// $timePeriods = $this->withdraw_status();
|
||||
//
|
||||
// // 构建正确的时间映射关系
|
||||
// $timeMap = [];
|
||||
// foreach($timePeriods as $period) {
|
||||
// foreach($period as $key => $value) {
|
||||
// $timeMap[$key] = $value;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// foreach ($list as $item) {
|
||||
//// $timeId = $item['time_id'];
|
||||
// $timeId = $timeMap[$item['time_id']] ?? '未知时间段';
|
||||
// $ranking = $item['ranking'];
|
||||
//
|
||||
// $gift_name = '';
|
||||
// if (!isset($reorganizedData[$timeId])) {
|
||||
// $reorganizedData[$timeId] = [];
|
||||
// }
|
||||
// if (!isset($reorganizedData[$timeId][$ranking])) {
|
||||
// $reorganizedData[$timeId][$ranking] = [];
|
||||
// }
|
||||
// if($item['gift_id']){
|
||||
// if($item['gift_type'] == 2){
|
||||
// $gift_name = db::name('vs_gift')->where(['gid'=>$item['gift_id']])->value('gift_name');
|
||||
// }
|
||||
// if($item['gift_type'] == 3 || $item['gift_type'] == 4){
|
||||
// $gift_name = db::name('vs_decorate')->where(['did'=>$item['gift_id']])->value('title');
|
||||
// }
|
||||
//
|
||||
// }else{
|
||||
// $gift_name = '';
|
||||
// }
|
||||
// $reorganizedData[$timeId][$ranking][] = [
|
||||
// 'gift_type' => $item['gift_type'],
|
||||
// 'gift_id' => $item['gift_id'],
|
||||
// 'gift_name' => $gift_name,
|
||||
// 'coin' => $item['coin']
|
||||
// ];
|
||||
// }
|
||||
//
|
||||
// // 输出重组后的数据
|
||||
// print_r($reorganizedData);
|
||||
// return V(1, "成功", $data);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user