当前位置:网站首页>Tp6 realize Commission ranking
Tp6 realize Commission ranking
2022-07-07 19:39:00 【Results of persistence and efforts】
Reference data ( surface )
CREATE TABLE `user_money` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`gid` int(10) DEFAULT NULL COMMENT ' goods id',
`tid` int(10) DEFAULT NULL COMMENT ' user id',
`money` int(11) DEFAULT NULL COMMENT ' commission ',
`add_time` datetime DEFAULT NULL COMMENT ' Add the time ',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
Leaderboard logic code
public function rankingList($time)
{
// Connect redis
$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
// Query data
$data = UserMoney::with('UserCommander')->select()->toArray();
// Array processing Cumulative Commission
$newArr = array();
foreach ($data as $v)
{
if (array_key_exists($v['tid'], $newArr))
{
$newArr[$v['tid']]['money'] += $v['money'];
}
else {
$newArr[$v['tid']] = $v;
}
}
// Add to redis Ordered set
foreach ($data as $k =>$v)
{
$redis->zincrby('tag1',$v['money'],$v['tid']);
}
$data = $redis->zrevrange('tag1', 0, -1);
$ids = implode(',', $data);
$score = $redis->zRevRange('tag1', 0, -1, true);
// Judge data time ranking
if(!empty($time))
{
$data = UserMoney::with('UserCommander')->whereTime('add_time',$time)->whereIn('tid', $data)->order(Db::raw("FIELD(tid,$ids)"))->select()->toArray();
$newArr = array();
foreach ($data as $v)
{
if (array_key_exists($v['tid'], $newArr))
{
$newArr[$v['tid']]['money'] += $v['money'];
}
else {
$newArr[$v['tid']] = $v;
}
}
}else{
$data = UserMoney::whereIn('tid', $data)->order(Db::raw("FIELD(tid,$ids)"))->select()->toArray();
$newArr = array();
foreach ($data as $v)
{
if (array_key_exists($v['tid'], $newArr))
{
$newArr[$v['tid']]['money'] += $v['money'];
}
else {
$newArr[$v['tid']] = $v;
}
}
}
$res = [];
foreach ($newArr as $key => $val) {
$res[] = [
'tid' => $val['tid'],
'money' => $val['money'],
'id' => $val['id'],
'name' => $val['UserCommander']['name'],
];
}
return $res;
}
边栏推荐
- 杰理之开机自动配对【篇】
- 浏览积分设置的目的
- LeetCode 648(C#)
- Hongmeng smart home [1.0]
- Numpy——2.数组的形状
- Classification and application of enterprise MES Manufacturing Execution System
- ES6笔记一
- R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
- Research and practice of super-resolution technology in the field of real-time audio and video
- AI写首诗
猜你喜欢
2022.07.05
Former richest man, addicted to farming
Responsibility chain model - unity
Zhong Xuegao wants to remain innocent in the world
8 CAS
648. 单词替换
Policy mode - unity
Seize Jay Chou
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
随机推荐
转置卷积理论解释(输入输出大小分析)
怎么在手机上买股票开户 股票开户安全吗
实训九 网络服务的基本配置
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
杰理之关于 TWS 配对方式配置【篇】
Former richest man, addicted to farming
SlashData开发者工具榜首等你而定!!!
The top of slashdata developer tool is up to you!!!
银行理财产品怎么买?需要办银行卡吗?
Hongmeng smart home [1.0]
L1-019 who falls first (Lua)
9 原子操作类之18罗汉增强
PV static creation and dynamic creation
Solve the problem of remote rviz error reporting
Tips and tricks of image segmentation summarized from 39 Kabul competitions
[RT thread env tool installation]
Number - number (Lua)
【RT-Thread env 工具安装】
how to prove compiler‘s correctness