Files
yusheng-php/application/adminapi/controller/Lottery.php

129 lines
5.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\adminapi\controller;
use app\admin\model\AdminLog;
use app\common\controller\adminApi;
use think\Config;
use think\Db;
use think\Hook;
use think\Session;
use think\Validate;
/**
* 等级管理
* @internal
*/
class Lottery extends adminApi
{
protected $noNeedLogin = [];
protected $noNeedRight = [];
public function _initialize()
{
parent::_initialize();
}
/*
* 配置列表
*/
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);
}
return V(1,"成功");
}
/*
* 中奖记录
*/
public function record_list(){
$page = input('page', 1);
$page_limit = input('page_limit', 30);
$stime = input('stime', '');
$etime = input('etime', '');
$where = [];
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();
$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();
foreach ($lists_data as $k=>$v){
$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'];
//奖项类型1-小奖 2-大奖
$lists_data[$k]['prize_type_str'] = $v['prize_type']==1?"小奖":"大奖";
//状态1-已发放 0-未发放'
$lists_data[$k]['status_str'] = $v['status']==1?"已发放":"未发放";
$lists_data[$k]['createtime'] = date("Y-m-d H:i:s", $v['createtime']);
}
$return_data = [
'page' =>$page,
'page_limit' => $page_limit,
'count' => $count,
'lists' => $lists_data,
'total_data' => [
]
];
return V(1,"成功", $return_data);
}
/*
* 实时统计
*/
public function realtime_statistics(){
$bb_config = db::name('bb_lottery_config')->field('key,value')->select();
$bb_config = array_column($bb_config, null, 'key');
// 循环奖池进度
//最新轮次
$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."金币)";
//蓄水池当前金额
$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;
//最近中奖用户
$last_winner_user_id = db::name('bb_lottery_winner_record')->where(['status'=>1])->order('id desc')->find();
$last_winner_user_info = db::name('user')->where(['id'=>$last_winner_user_id['uid']])->find();
//平台累计收入
$platform_total_income = db::name('bb_lottery_pool_flow')->where(['type'=>4])->sum('amount');
$return_data=[
'pool_progress' => $pool_progress_str,
'pool_amount_now' => ($bigAddGold)."金币 ".(($bigAddGold)/$bb_config['big_pool_threshold']['value'])."%)",
'last_winner_user' => "用户ID:".$last_winner_user_info['user_code']." 获得 ".$last_winner_user_id['prize_amount']." 金币 ".$last_winner_user_id['ratio']."%)",
'platform_total_income' => $platform_total_income." 金币",
];
return V(1,"成功", $return_data);
}
}