2025-12-21 20:01:47 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\adminapi\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\admin\model\AdminLog;
|
|
|
|
|
|
use app\common\controller\adminApi;
|
2026-01-26 19:21:32 +08:00
|
|
|
|
use think\Cache;
|
2025-12-21 20:01:47 +08:00
|
|
|
|
use think\Config;
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
use think\Hook;
|
|
|
|
|
|
use think\Session;
|
|
|
|
|
|
use think\Validate;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 等级管理
|
|
|
|
|
|
* @internal
|
|
|
|
|
|
*/
|
|
|
|
|
|
class Lottery extends adminApi
|
|
|
|
|
|
{
|
2026-01-26 19:36:22 +08:00
|
|
|
|
// Redis实例
|
|
|
|
|
|
private $redis;
|
2025-12-21 20:01:47 +08:00
|
|
|
|
protected $noNeedLogin = [];
|
|
|
|
|
|
protected $noNeedRight = [];
|
|
|
|
|
|
public function _initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
parent::_initialize();
|
2026-01-26 19:24:12 +08:00
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 配置列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function config_list(){
|
|
|
|
|
|
$list = db::name("bb_lottery_config")->order('sort desc')->select();
|
|
|
|
|
|
$list_data = [];
|
|
|
|
|
|
foreach ($list as $k=>$v){
|
|
|
|
|
|
$list_data[$k]['id'] = $v['id'];
|
|
|
|
|
|
$list_data[$k]['key'] = $v['key'];
|
|
|
|
|
|
$list_data[$k]['value'] = $v['value'];
|
|
|
|
|
|
$list_data[$k]['desc'] = $v['desc'];
|
|
|
|
|
|
$list_data[$k]['sort'] = $v['sort'];
|
|
|
|
|
|
}
|
|
|
|
|
|
return V(1,"成功", $list_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 配置设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function config_set(){
|
|
|
|
|
|
$params = $this->request->post();
|
|
|
|
|
|
foreach ($params as $k=>$v){
|
|
|
|
|
|
$data = [
|
|
|
|
|
|
'value'=>$v,
|
|
|
|
|
|
];
|
|
|
|
|
|
db::name("bb_lottery_config")->where(['key'=>$k])->update($data);
|
|
|
|
|
|
}
|
2026-01-26 19:36:22 +08:00
|
|
|
|
$this->redis = Cache::store('redis')->handler();
|
|
|
|
|
|
$prize_amount = $this->redis->get('lottery:small_pool:total_gold');
|
2026-01-26 19:21:32 +08:00
|
|
|
|
|
|
|
|
|
|
Db::name('bb_lottery_winner_record')->insert([
|
|
|
|
|
|
'uid' => 0,
|
|
|
|
|
|
'prize_type' => 1,
|
|
|
|
|
|
'prize_amount' => $prize_amount,
|
|
|
|
|
|
'pool_amount' => $prize_amount,
|
|
|
|
|
|
'ratio' => 100,
|
|
|
|
|
|
'release_amount' => $prize_amount,
|
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
|
'status' => 0 // 未发放
|
|
|
|
|
|
]);
|
2026-01-26 19:49:13 +08:00
|
|
|
|
//修改开启下一轮
|
|
|
|
|
|
$dd =$this->redis->get('lottery:small_pool:round');
|
|
|
|
|
|
$this->redis->set('lottery:small_pool:round', $dd+1);
|
|
|
|
|
|
$this->redis->set('lottery:small_pool:total_times',0);
|
|
|
|
|
|
$this->redis->set('lottery:small_pool:total_gold',0);
|
2026-01-26 19:21:32 +08:00
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
return V(1,"成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 中奖记录
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function record_list(){
|
|
|
|
|
|
$page = input('page', 1);
|
|
|
|
|
|
$page_limit = input('page_limit', 30);
|
|
|
|
|
|
$stime = input('stime', '');
|
|
|
|
|
|
$etime = input('etime', '');
|
2026-01-27 19:25:16 +08:00
|
|
|
|
$pool_type = input('pool_type', '1');
|
|
|
|
|
|
$user_code = input('user_code');
|
|
|
|
|
|
if($user_code){
|
|
|
|
|
|
$userId = db::name('user')->where(['user_code'=>$user_code])->value('id');
|
|
|
|
|
|
if($userId){
|
|
|
|
|
|
$where['uid'] = $userId;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$where['uid'] = '1';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-21 20:01:47 +08:00
|
|
|
|
$where = [];
|
2026-01-27 19:25:16 +08:00
|
|
|
|
$where['prize_type'] = $pool_type;
|
2025-12-21 20:01:47 +08:00
|
|
|
|
if($stime!==""){
|
|
|
|
|
|
$where['create_time'] = ['>=', strtotime($stime)];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($etime!==""){
|
|
|
|
|
|
$where['create_time'] = ['<=', strtotime($etime)];
|
|
|
|
|
|
}
|
|
|
|
|
|
if($stime!=="" && $etime!==""){
|
|
|
|
|
|
$where['create_time'] = ['between', [strtotime($stime), strtotime($etime)]];
|
|
|
|
|
|
}
|
|
|
|
|
|
$count = db::name('bb_lottery_winner_record')->where($where)->count();
|
2026-01-27 19:25:16 +08:00
|
|
|
|
$lists_data = db::name('bb_lottery_winner_record')
|
|
|
|
|
|
->field('id,uid as user_id,prize_type,prize_amount,pool_amount,ratio,release_amount,status,create_time as createtime')
|
|
|
|
|
|
->where($where)->page($page, $page_limit)->order("id desc")->select();
|
2025-12-21 20:01:47 +08:00
|
|
|
|
foreach ($lists_data as $k=>$v){
|
2026-01-26 19:21:32 +08:00
|
|
|
|
if($v['user_id'] > 0){
|
|
|
|
|
|
$user_info = db::name('user')->where(['id'=>$v['user_id']])->find();
|
|
|
|
|
|
$lists_data[$k]['user_code'] = $user_info['user_code']??"";
|
|
|
|
|
|
$lists_data[$k]['nickname'] = $user_info['user_code']."-".$user_info['nickname'];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$lists_data[$k]['user_code'] = "";
|
|
|
|
|
|
$lists_data[$k]['nickname'] = "后台重置,全部释放";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
//奖项类型:1-小奖 2-大奖
|
2026-01-27 19:25:16 +08:00
|
|
|
|
if($v['prize_type']==4){
|
|
|
|
|
|
$lists_data[$k]['prize_type_str'] = "高级奖";
|
|
|
|
|
|
}elseif ($v['prize_type']==2){
|
|
|
|
|
|
$lists_data[$k]['prize_type_str'] = "大奖";
|
|
|
|
|
|
}elseif ($v['prize_type']==3){
|
|
|
|
|
|
$lists_data[$k]['prize_type_str'] = "中级奖";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$lists_data[$k]['prize_type_str'] = "小奖";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
//状态:1-已发放 0-未发放'
|
|
|
|
|
|
$lists_data[$k]['status_str'] = $v['status']==1?"已发放":"未发放";
|
|
|
|
|
|
$lists_data[$k]['createtime'] = date("Y-m-d H:i:s", $v['createtime']);
|
2026-01-26 19:05:43 +08:00
|
|
|
|
$lists_data[$k]['prize_amount'] = floor($v['prize_amount']);
|
|
|
|
|
|
$lists_data[$k]['beilv'] = floor($v['prize_amount']);
|
2025-12-21 20:01:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
$return_data = [
|
|
|
|
|
|
'page' =>$page,
|
|
|
|
|
|
'page_limit' => $page_limit,
|
|
|
|
|
|
'count' => $count,
|
|
|
|
|
|
'lists' => $lists_data,
|
|
|
|
|
|
'total_data' => [
|
|
|
|
|
|
]
|
|
|
|
|
|
];
|
|
|
|
|
|
return V(1,"成功", $return_data);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 实时统计
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function realtime_statistics(){
|
2026-01-27 19:25:16 +08:00
|
|
|
|
$pool_type = input('pool_type', '1');
|
|
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
$bb_config = db::name('bb_lottery_config')->field('key,value')->select();
|
|
|
|
|
|
$bb_config = array_column($bb_config, null, 'key');
|
2026-01-27 19:25:16 +08:00
|
|
|
|
if($pool_type == 4){
|
|
|
|
|
|
$latest_times = db::name('bb_lottery_pool_flow_10')->where(['pool_type'=>1])->max('times');//最新轮次
|
|
|
|
|
|
$pool_progress = db::name('bb_lottery_pool_flow_10')->where(['pool_type'=>1,'times'=>$latest_times])->count();//当前进度
|
|
|
|
|
|
$pool_total_amount = db::name('bb_lottery_pool_flow_10')->where(['pool_type'=>1,'times'=>$latest_times,'type'=>1])->sum('amount');
|
|
|
|
|
|
//获取配置表中奖池配置
|
|
|
|
|
|
$pool_progress_str = $pool_progress."/".$bb_config['small_pool_trigger_times_10']['value']."(".$pool_total_amount."金币)";
|
|
|
|
|
|
//最近中奖用户
|
|
|
|
|
|
$last_winner_user_id = db::name('bb_lottery_winner_record')->where(['status'=>1,'prize_type'=>4])->order('id desc')->find();
|
|
|
|
|
|
//平台累计收入
|
|
|
|
|
|
$platform_total_income = db::name('bb_lottery_winner_record')->where(['prize_type'=>4])->sum('release_amount');
|
|
|
|
|
|
}elseif($pool_type == 3){
|
|
|
|
|
|
$latest_times = db::name('bb_lottery_pool_flow_5')->where(['pool_type'=>1])->max('times');//最新轮次
|
|
|
|
|
|
$pool_progress = db::name('bb_lottery_pool_flow_5')->where(['pool_type'=>1,'times'=>$latest_times])->count();//当前进度
|
|
|
|
|
|
$pool_total_amount = db::name('bb_lottery_pool_flow_5')->where(['pool_type'=>1,'times'=>$latest_times,'type'=>1])->sum('amount');
|
|
|
|
|
|
//获取配置表中奖池配置
|
|
|
|
|
|
$pool_progress_str = $pool_progress."/".$bb_config['small_pool_trigger_times_5']['value']."(".$pool_total_amount."金币)";
|
|
|
|
|
|
//最近中奖用户
|
|
|
|
|
|
$last_winner_user_id = db::name('bb_lottery_winner_record')->where(['status'=>1,'prize_type'=>3])->order('id desc')->find();
|
|
|
|
|
|
//平台累计收入
|
|
|
|
|
|
$platform_total_income = db::name('bb_lottery_winner_record')->where(['prize_type'=>3])->sum('release_amount');
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$latest_times = db::name('bb_lottery_pool_flow')->where(['pool_type'=>1])->max('times');//最新轮次
|
|
|
|
|
|
$pool_progress = db::name('bb_lottery_pool_flow')->where(['pool_type'=>1,'times'=>$latest_times])->count();//当前进度
|
|
|
|
|
|
$pool_total_amount = db::name('bb_lottery_pool_flow')->where(['pool_type'=>1,'times'=>$latest_times,'type'=>1])->sum('amount');
|
|
|
|
|
|
//获取配置表中奖池配置
|
|
|
|
|
|
$pool_progress_str = $pool_progress."/".$bb_config['small_pool_trigger_times']['value']."(".$pool_total_amount."金币)";
|
|
|
|
|
|
//最近中奖用户
|
|
|
|
|
|
$last_winner_user_id = db::name('bb_lottery_winner_record')->where(['status'=>1,'prize_type'=>1])->order('id desc')->find();
|
|
|
|
|
|
//平台累计收入
|
|
|
|
|
|
$platform_total_income = db::name('bb_lottery_winner_record')->where(['prize_type'=>1])->sum('release_amount');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
|
|
|
|
|
|
//蓄水池当前金额
|
2026-01-27 19:25:16 +08:00
|
|
|
|
// $big_round = db::name('bb_lottery_pool_flow')->where(['pool_type'=>2])->max('times');
|
|
|
|
|
|
// $bigAddGold = Db::name('bb_lottery_pool_flow')->where(['pool_type' => 2, 'type' => 3, 'times' => $big_round])->sum('amount') ?: 0;
|
|
|
|
|
|
$bigAddGold = 0;
|
|
|
|
|
|
|
2026-01-13 14:01:57 +08:00
|
|
|
|
if($last_winner_user_id){
|
|
|
|
|
|
$last_winner_user_info = db::name('user')->where(['id'=>$last_winner_user_id['uid']])->find();
|
|
|
|
|
|
$last_winner_user_text = "用户ID:".$last_winner_user_info['user_code']." 获得 ".$last_winner_user_id['prize_amount']." 金币 (".$last_winner_user_id['ratio']."%)";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$last_winner_user_text = "无";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
//平台累计收入
|
2026-01-26 20:00:19 +08:00
|
|
|
|
// $platform_total_income = db::name('bb_lottery_pool_flow')->where(['type'=>4])->sum('amount');
|
2026-01-27 19:25:16 +08:00
|
|
|
|
|
2025-12-21 20:01:47 +08:00
|
|
|
|
$return_data=[
|
|
|
|
|
|
'pool_progress' => $pool_progress_str,
|
|
|
|
|
|
'pool_amount_now' => ($bigAddGold)."金币 (".(($bigAddGold)/$bb_config['big_pool_threshold']['value'])."%)",
|
2026-01-13 14:01:57 +08:00
|
|
|
|
'last_winner_user' => $last_winner_user_text,
|
2025-12-21 20:01:47 +08:00
|
|
|
|
'platform_total_income' => $platform_total_income." 金币",
|
|
|
|
|
|
];
|
|
|
|
|
|
return V(1,"成功", $return_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|