更新
This commit is contained in:
131
application/api/controller/BlindBoxTurntable.php
Normal file
131
application/api/controller/BlindBoxTurntable.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
/*
|
||||
* 盲盒转盘
|
||||
* 2025-08-16
|
||||
*/
|
||||
|
||||
class BlindBoxTurntable extends BaseCom
|
||||
{
|
||||
protected function initialize()
|
||||
{
|
||||
//允许跨域
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取活动奖池礼物列表
|
||||
*/
|
||||
public function get_gift_list(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->get_gift_list($gift_bag_id,$room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 抽奖
|
||||
*
|
||||
*/
|
||||
public function draw_gift(){
|
||||
$gift_bag_id = input('gift_bag_id',0);
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$gift_user_ids = input('gift_user_ids',0);
|
||||
$num = input('num',1);
|
||||
$heart_id = input('heart_id',0);
|
||||
$auction_id = input('auction_id',0);
|
||||
$reslut = model('BlindBoxTurntableGiftDrawWorld')->draw_gift($gift_bag_id, $user_id, $gift_user_ids,$num,$room_id,$heart_id,$auction_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 礼物发放
|
||||
*/
|
||||
public function gift_send(){
|
||||
// $key_name = "api:blind_box_turntable:gift_send:" . $this->uid;
|
||||
// redis_lock_exit($key_name);
|
||||
$send_id = input('send_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->gift_send($send_id);
|
||||
// redis_unlock($key_name);
|
||||
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']);
|
||||
}
|
||||
/*
|
||||
* 巡乐会
|
||||
*/
|
||||
public function xlh(){
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_gift_list($room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会抽奖
|
||||
*/
|
||||
public function xlh_draw_gift(){
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$num = input('num',1);
|
||||
$reslut = model('BlindBoxTurntableGiftDrawWorld')->xlh_draw_gift($user_id,$num,$room_id);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 获取我的巡乐会记录
|
||||
*/
|
||||
public function get_xlh_my_record(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$user_id = $this->uid;
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_get_user_record($user_id,$room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
/*
|
||||
* 获取全服巡乐会记录(榜单)
|
||||
*/
|
||||
public function get_xlh_all_record(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_ranking($room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/*
|
||||
* 巡乐会榜单 (以期数显示)
|
||||
*/
|
||||
public function get_xlh_ranking(){
|
||||
$page = input('page',1);
|
||||
$page_size = input('page_size',12);
|
||||
$room_id = input('room_id',0);
|
||||
$reslut = model('BlindBoxTurntableGift')->xlh_ranking_list($room_id,$page,$page_size);
|
||||
return v($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
}
|
||||
65
application/api/controller/Friend.php
Normal file
65
application/api/controller/Friend.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
|
||||
class Friend extends BaseCom
|
||||
{
|
||||
//交友开始
|
||||
public function start_friend(){
|
||||
$key_name = "api:friend:start_friend:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$room_id = input('room_id', '');
|
||||
$reslut = model('Friend')->start_friend($this->uid,$room_id);
|
||||
redis_unlocks($key_name);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//交友延时
|
||||
public function delay(){
|
||||
$friend_id = input('friend_id', '');
|
||||
$room_id = input('room_id', '');
|
||||
$delay_times = input('delay_times', '');//分钟
|
||||
|
||||
$reslut = model('Friend')->delay($this->uid,$room_id,$friend_id,$delay_times);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
//交友结束
|
||||
public function end_friend(){
|
||||
|
||||
$friend_id = input('friend_id', '');
|
||||
$room_id = input('room_id', '');
|
||||
|
||||
$result = model('Friend')->end_friend($this->uid,$room_id,$friend_id);
|
||||
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
|
||||
//卡关系 创建关系
|
||||
public function create_relation()
|
||||
{
|
||||
$key_name = "api:friend:create_relation:" . $this->uid;
|
||||
redis_lock_exits($key_name);
|
||||
$room_id = input('room_id', '');
|
||||
$friend_id = input('friend_id', '');
|
||||
$user1_id = input('user1_id', '');
|
||||
$user2_id = input('user2_id', '');
|
||||
$relation_id = input('relation_id', '');
|
||||
$result = model('Friend')->createRelation($this->uid,$room_id,$friend_id,$user1_id,$user2_id,$relation_id);
|
||||
redis_unlocks($key_name);
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
|
||||
//退出私密小屋
|
||||
public function out_room()
|
||||
{
|
||||
$room_id = input('room_id', '');
|
||||
|
||||
$result = model('Friend')->outRoom($this->uid,$room_id);
|
||||
|
||||
return V($result['code'], $result['msg'], $result['data']);
|
||||
}
|
||||
}
|
||||
119
application/api/controller/Redpacket.php
Normal file
119
application/api/controller/Redpacket.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use app\common\service\RedpacketService;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 红包接口
|
||||
*/
|
||||
class Redpacket extends BaseCom
|
||||
{
|
||||
|
||||
/**
|
||||
* 发红包
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
|
||||
$data['user_id'] = $this->uid;
|
||||
|
||||
$service = new RedpacketService();
|
||||
$reslut = $service->create($data);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 抢红包
|
||||
*/
|
||||
public function grab()
|
||||
{
|
||||
$redpacketId = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在抢红包前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$reslut = $service->grabWithResult($redpacketId, $this->uid);
|
||||
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取抢红包结果
|
||||
*/
|
||||
public function grabResult()
|
||||
{
|
||||
$redpacketId = $this->request->get('redpacket_id');
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
$result = $service->getGrabResult($redpacketId, $this->uid);
|
||||
|
||||
if (!$result) {
|
||||
return V(0, '红包不存在');
|
||||
}
|
||||
|
||||
return V(1, '获取成功', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包详情
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$redpacketId = input('redpacket_id', 0);
|
||||
|
||||
if (empty($redpacketId)) {
|
||||
return V(0, '红包ID不能为空');
|
||||
}
|
||||
|
||||
$service = new RedpacketService();
|
||||
// 在获取详情前确保状态正确
|
||||
$service->checkAndUpdateRedpacketStatus($redpacketId);
|
||||
$detail = $service->getDetail($redpacketId, $this->uid);
|
||||
|
||||
if (!$detail) {
|
||||
return V(0, '红包不存在');
|
||||
}
|
||||
|
||||
return V(1, '获取成功', $detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取倒计时选项
|
||||
*/
|
||||
public function countdownOptions()
|
||||
{
|
||||
$options = \app\common\model\Redpacket::$countdownOptions;
|
||||
$this->success('获取成功', $options);
|
||||
}
|
||||
|
||||
// 获取房间内红包列表
|
||||
public function roomRedPackets()
|
||||
{
|
||||
$roomId = $this->request->get('room_id');
|
||||
$result = Db::name('redpacket')->where(['room_id' => $roomId, 'status' => ['<=',1]])->select();
|
||||
if($result){
|
||||
foreach ($result as &$item) {
|
||||
$item['redpacket_id'] = $item['id'];
|
||||
$item['redpacket_time'] = get_system_config_value('red_packet_time');//展示时间
|
||||
$item['nickname'] = Db::name('user')->where('id', $item['user_id'])->value('nickname');
|
||||
$item['avatar'] = Db::name('user')->where('id', $item['user_id'])->value('avatar');
|
||||
$is_qiang = Db::name('redpacket_record')->where(['redpacket_id' => $item['id'], 'user_id' => $this->uid])->find();
|
||||
$item['is_qiang'] = $is_qiang ? 1 : 0;
|
||||
}
|
||||
}
|
||||
return V(1, '获取成功', $result);
|
||||
}
|
||||
}
|
||||
34
application/api/controller/RoomHourRanking.php
Normal file
34
application/api/controller/RoomHourRanking.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
use think\Db;
|
||||
|
||||
class RoomHourRanking extends BaseCom
|
||||
{
|
||||
//房间小时榜是否开启
|
||||
public function room_hour_ranking_is_open()
|
||||
{
|
||||
$open_time = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('open_time');
|
||||
return V(1, '获取成功', ['open_time' => $open_time]);
|
||||
}
|
||||
|
||||
//房间小时榜玩法
|
||||
public function room_hour_ranking_play()
|
||||
{
|
||||
$introd = db::name('vs_hour_ranking_config')->order('id', 'desc')->value('introd');
|
||||
return V(1, '获取成功', ['introd' => $introd]);
|
||||
}
|
||||
|
||||
//房间小时榜
|
||||
public function room_hour_ranking()
|
||||
{
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 20);
|
||||
|
||||
$reslut = model('RoomHourRanking')->room_hour_ranking($page, $page_limit);
|
||||
return V($reslut['code'], $reslut['msg'], $reslut['data']);
|
||||
}
|
||||
|
||||
}
|
||||
39
application/api/controller/Xintiao.php
Normal file
39
application/api/controller/Xintiao.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
use app\common\controller\BaseCom;
|
||||
|
||||
class Xintiao extends BaseCom
|
||||
{
|
||||
|
||||
|
||||
public function keep_xintiao()
|
||||
{
|
||||
$user_id = $this->uid;
|
||||
$is_xintiao = db::name('vs_xintiao')->where('user_id' , $user_id)->find();
|
||||
if($is_xintiao){
|
||||
db::name('vs_xintiao')->where('user_id' , $user_id)->update(['updatetime' => time()]);
|
||||
}else{
|
||||
db::name('vs_xintiao')->insert([
|
||||
'user_id' => $user_id,
|
||||
'createtime' => time(),
|
||||
'updatetime' => time()
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
434
application/api/controller/Xxiaoshi.php
Normal file
434
application/api/controller/Xxiaoshi.php
Normal file
@@ -0,0 +1,434 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
|
||||
use app\common\controller\Push;
|
||||
|
||||
class Xxiaoshi extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function send_gift()
|
||||
{
|
||||
//获取上一个小时的开始时间和结束时间
|
||||
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
$end_time = strtotime(date('Y-m-d H:00:00'));
|
||||
echo "开始时间:" .$start_time."\n";
|
||||
echo "结束时间:" .$end_time."\n";
|
||||
//当前小时的前一个小时(24小时计时法,0-23)
|
||||
$pre_hour = date('H', strtotime('-1 hour'));
|
||||
echo "上个时间段:" .$pre_hour."\n";
|
||||
$is_open_time = db::name('vs_hour_ranking_config')->where('id', 1)->value('open_time');
|
||||
if ($is_open_time == 0) {
|
||||
echo "未开启时间段:" .$is_open_time."\n";
|
||||
return;
|
||||
}
|
||||
//是否全局飘瓶
|
||||
$is_public_server = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_public_server');
|
||||
if ($is_public_server == 1) {
|
||||
//全局飘瓶时间段
|
||||
$xlh_time_range = db::name('vs_hour_ranking_config')->where('id', 1)->value('broadcast_times');
|
||||
if($xlh_time_range){
|
||||
if($xlh_time_range == 25){
|
||||
$is_piao = 1;
|
||||
}else{
|
||||
|
||||
//当前的前一个小时是否在 $xlh_time_range中
|
||||
if (in_array($pre_hour, explode(',', $xlh_time_range))) {
|
||||
$is_piao = 1;
|
||||
} else {
|
||||
$is_piao = 0;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
}else{
|
||||
$is_piao = 0;
|
||||
}
|
||||
|
||||
//获取上一个时间段的配置
|
||||
// $gift_list = db::name('vs_hour_ranking_gift_config')->where('time_id',$pre_hour)->group('ranking')->order('id', 'desc')->select();
|
||||
$gift_list = $this->get_hour_ranking($pre_hour);
|
||||
// echo "上个时间段的配置:" .json_encode($gift_list)."\n";
|
||||
// 提取所有有奖励的内容
|
||||
$allRewards = $this->extractAllRewards($gift_list);
|
||||
// 按index分组
|
||||
$groupedRewards = $this->groupRewardsByIndex($allRewards);
|
||||
// 按名次顺序分配奖励
|
||||
$distributionResult = $this->distributeByRank($groupedRewards);
|
||||
|
||||
//获取上个数组的个数,从而获取配置了多少个名次
|
||||
$count = count($distributionResult);
|
||||
echo "上个时间段的配置总数:" .$count."\n";
|
||||
//获取前一个小时的 前$count名房间排行
|
||||
$room_list = model('api/RoomHourRanking')->room_hour_ranking(1, $count, $start_time, $end_time);
|
||||
$room_owner = [];
|
||||
if ($room_list['code'] == 1) {
|
||||
//获取房间排行奖励最低值
|
||||
$min_price = db::name('vs_hour_ranking_config')->where('id', 1)->value('min_price');
|
||||
if ($room_list['data']['lists']) {
|
||||
echo "房间列表:" .json_encode($room_list['data']['lists'])."\n";
|
||||
foreach ($room_list['data']['lists'] as $v){
|
||||
if ($v['total_price'] >= $min_price) {
|
||||
$room_owner[] = [
|
||||
'user_id' => $v['user_id'],
|
||||
'room_name' => $v['room_name'],
|
||||
'room_id' => $v['room_id'],
|
||||
'total_price' => $v['total_price']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($distributionResult && $room_owner) {
|
||||
$text_list_new = [];
|
||||
echo "礼物数:" .json_encode($distributionResult)."\n";
|
||||
echo "房主:" .json_encode($room_owner)."\n";
|
||||
foreach ($distributionResult as $k => $value) {
|
||||
//礼物全部给他偷偷放在装扮表及金额 中
|
||||
//有几个用户就发几个
|
||||
if(count($room_owner) > $k){
|
||||
// 为每个房间添加一个标志,表示是否已处理推送信息
|
||||
$hasProcessedPush = false;
|
||||
|
||||
foreach ($value['rewards'] as $v){
|
||||
// if($v['type'] == 0){//1金币2礼物3头像4坐骑
|
||||
// echo "发金币:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
// $res = $this->add_coin($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
// }elseif ($v['type'] == 1){
|
||||
// echo "发礼物:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
|
||||
// $res = $this->add_gift($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
|
||||
// }elseif ($v['type'] == 2){
|
||||
// $res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,3);
|
||||
// }elseif ($v['type'] == 3){
|
||||
// $res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,4);
|
||||
// }
|
||||
// 只有在第一次处理奖励时添加推送信息,避免重复推送
|
||||
if(!$hasProcessedPush && $is_piao == 1) {
|
||||
$room_name = $room_owner[$k]['room_name'];
|
||||
//推送礼物横幅
|
||||
if ($k == 0) {
|
||||
$text = '新科状元!【' . $room_name . '】独占鳌头!';
|
||||
} elseif ($k == 1) {
|
||||
$text = '金榜榜眼!【' . $room_name . '】才气逼人!';
|
||||
} elseif ($k == 2) {
|
||||
$text = '风采探花!【' . $room_name . '】实力绽放!';
|
||||
}
|
||||
|
||||
$text_list_new[] = [
|
||||
'text' => $text ?? '恭喜【' . $room_name . '】获得礼物!',
|
||||
'room_id' => $room_owner[$k]['room_id'],
|
||||
'room_name' => $room_name,
|
||||
'rank_number' => $k + 1,
|
||||
];
|
||||
|
||||
$hasProcessedPush = true; // 标记已处理推送
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(!empty($text_list_new)){
|
||||
$push = new Push();
|
||||
$push->hourRankingcs($text_list_new);
|
||||
Log::record("小时榜推送:".json_encode($text_list_new),"infos");
|
||||
}
|
||||
}
|
||||
echo "送礼-共" . count($room_owner) . "个房间房主获益\n";
|
||||
}
|
||||
|
||||
//添加金币到钱包
|
||||
// public function add_coin($coin,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
// if($coin > 0){
|
||||
// $data = [
|
||||
// 'user_id' => $user_id,
|
||||
// 'change_value' => $coin,
|
||||
// // 'room_id' => $room_ids,
|
||||
// 'money_type' => 1,
|
||||
// 'change_type' => 27,
|
||||
// 'from_id' => 0,
|
||||
// 'remarks' => '小时榜获得',
|
||||
// 'createtime' => time()
|
||||
// ];
|
||||
|
||||
// //开启事务
|
||||
// Db::startTrans();
|
||||
// $res = Db::name('vs_user_money_log')->insert($data);
|
||||
// if(!$res){
|
||||
// Db::rollback();
|
||||
// }
|
||||
|
||||
// //增加用户金币
|
||||
// $res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc('coin',$coin);
|
||||
// if(!$res1){
|
||||
// Db::rollback();
|
||||
// }
|
||||
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'coin' => $coin,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Db::rollback();
|
||||
// }
|
||||
// Db::commit();
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// //添加礼物到背包
|
||||
// public function add_gift($gift_id,$user_id,$ranking,$room_id,$total_price,$is_piao){
|
||||
// $res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$gift_id,1,model('UserGiftPack')::HOUR_RANK_GET,"小时榜获得");
|
||||
// if($res['code'] == 0){
|
||||
// Log::record("小时榜获取礼物失败:".$res['msg'],"info");
|
||||
// }
|
||||
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'gift_id' => $gift_id,
|
||||
// 'gift_type' => 2,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Log::record("小时榜礼物锁定失败","info");
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// //添加装扮到背包
|
||||
// public function add_decorate($avatar_id,$user_id,$ranking,$room_id,$total_price,$is_piao,$type){
|
||||
// $decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$avatar_id])->find();
|
||||
// if(empty($decorate_price_info)){
|
||||
// Log::record("小时榜获取装扮失败:没有找到装扮!".$avatar_id,"info");
|
||||
// }
|
||||
// $res = model('api/Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],2);
|
||||
// if($res['code'] == 0){
|
||||
// Log::record("小时榜获取装扮失败:".$res['msg']."-".$avatar_id,"info");
|
||||
// }
|
||||
// //添加到排行表
|
||||
// $start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
|
||||
// $end_time = strtotime(date('Y-m-d H:00:00')) - 1;
|
||||
// $res2 = db::name('vs_hour_ranking')->insert([
|
||||
// 'ranking' => $ranking,
|
||||
// 'room_id' => $room_id,
|
||||
// 'flowing_water' => $total_price,
|
||||
// 'gift_id' => $avatar_id,
|
||||
// 'gift_type' => $type,
|
||||
// 'time_id' => date('H', strtotime('-1 hour')),
|
||||
// 'stime' => $start_time,
|
||||
// 'etime' => $end_time,
|
||||
// 'createtime' => time(),
|
||||
// 'updatetime' => time(),
|
||||
// 'is_public_server' => $is_piao,
|
||||
// ]);
|
||||
// if(!$res2){
|
||||
// Log::record("小时榜咋装扮锁定失败","info");
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 提取所有有奖励的内容
|
||||
*/
|
||||
private function extractAllRewards($responseData)
|
||||
{
|
||||
$allRewards = [];
|
||||
|
||||
foreach ($responseData as $timeSlot) {
|
||||
foreach ($timeSlot['reward'] as $rewardItem) {
|
||||
$index = $rewardItem['index'];
|
||||
$content = $rewardItem['content'];
|
||||
|
||||
// 只处理有奖励内容的数据
|
||||
if (!empty($content)) {
|
||||
foreach ($content as $rewardContent) {
|
||||
$allRewards[] = [
|
||||
'index' => $index,
|
||||
'type' => $rewardContent['type'],
|
||||
'value' => $rewardContent['value'],
|
||||
'name' => $rewardContent['name'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $allRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按index分组奖励
|
||||
*/
|
||||
private function groupRewardsByIndex($allRewards)
|
||||
{
|
||||
$grouped = [];
|
||||
|
||||
foreach ($allRewards as $reward) {
|
||||
$index = $reward['index'];
|
||||
if (!isset($grouped[$index])) {
|
||||
$grouped[$index] = [];
|
||||
}
|
||||
$grouped[$index][] = $reward;
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($grouped);
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按名次顺序分配奖励
|
||||
*/
|
||||
private function distributeByRank($groupedRewards)
|
||||
{
|
||||
$distribution = [];
|
||||
$currentRank = 0; // 从第1名开始
|
||||
|
||||
// 按index顺序分配(index 0 = 第1名,index 1 = 第2名,以此类推)
|
||||
foreach ($groupedRewards as $index => $rewards) {
|
||||
// 确保名次连续,如果有空缺则填充空名次
|
||||
while ($currentRank < $index) {
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => []
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
// 分配当前名次的奖励
|
||||
$distribution[] = [
|
||||
'rank' => $currentRank + 1,
|
||||
'rewards' => $rewards
|
||||
];
|
||||
$currentRank++;
|
||||
}
|
||||
|
||||
return $distribution;
|
||||
}
|
||||
|
||||
public function get_hour_ranking($time){
|
||||
// 先按时间段和排名索引分组查询
|
||||
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
|
||||
->where('time_id', '=', $time)
|
||||
->order('time_id')
|
||||
->column('time_id');
|
||||
|
||||
$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' => []
|
||||
];
|
||||
}
|
||||
|
||||
// 添加奖励内容到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'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 按index排序
|
||||
ksort($rewardMap);
|
||||
|
||||
$result[] = [
|
||||
'time' => $timeRange,
|
||||
'reward' => array_values($rewardMap)
|
||||
];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function give_gifts(){
|
||||
$data = db::name('vs_give_gift')->where('from_id',5483)->select();
|
||||
$num = 0;
|
||||
$i=0;
|
||||
$j = 0;
|
||||
foreach($data as $v){
|
||||
$j += $v['total_price'];
|
||||
$nuu = db::name('vs_give_gift_ratio_log')->where('give_gift_id',$v['id'])->value('room_owner_earning');
|
||||
$id = db::name('vs_give_gift_ratio_log')->where('give_gift_id',$v['id'])->value('id');
|
||||
// echo $id."--".$nuu."\n";
|
||||
$num += $nuu;
|
||||
$i++;
|
||||
}
|
||||
echo $num;
|
||||
echo "==".$i."==".$j;
|
||||
|
||||
// echo db::name()->where(['user_id' => 10857,'money_type' =>2,'change_type' =>18])-sum('change_value');
|
||||
}
|
||||
|
||||
|
||||
public function room_liushui(){
|
||||
// $room = db::name('vs_give_gift')->where(['from_id' => ['<>',5418],'from' => 2])->group('from_id');
|
||||
$dd = db::name('vs_user_gift_pack')->alias('a')->join('vs_gift b','a.gid = b.gid')->field('a.gid,a.num,b.gift_price')->where(['a.num' =>['>',0]])->select();
|
||||
$count = 0;
|
||||
foreach ($dd as $v){
|
||||
$count += $v['gift_price'] * $v['num'];
|
||||
}
|
||||
echo $count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user