当前位置:网站首页>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;
}
边栏推荐
- In the first half of 2022, I found 10 books that have been passed around by my circle of friends
- 5billion, another master fund was born in Fujian
- 最长公共前缀(leetcode题14)
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- 解决rosdep的报错问题
- LeetCode 535(C#)
- “本真”是什么意思
- 2022如何评估与选择低代码开发平台?
- CMD command enters MySQL times service name or command error (fool teaching)
- 银行理财产品怎么买?需要办银行卡吗?
猜你喜欢
cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
Kirin Xin'an cloud platform is newly upgraded!
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
杰理之关于 TWS 配对方式配置【篇】
Install mysql8 for Linux X ultra detailed graphic tutorial
PV static creation and dynamic creation
编译原理 实验一:词法分析器的自动实现(Lex词法分析)
Jürgen Schmidhuber回顾LSTM论文等发表25周年:Long Short-Term Memory. All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversarial RL. Soccer learn
Policy mode - unity
索引总结(突击版本)
随机推荐
最长公共前缀(leetcode题14)
杰理之开机自动配对【篇】
杰理之关于 TWS 交叉配对的配置【篇】
2022.07.04
How to share the same storage among multiple kubernetes clusters
Command mode - unity
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
2022如何评估与选择低代码开发平台?
Initial experience of cache and ehcache "suggestions collection"
MySQL、sqlserver oracle数据库连接方式
LeetCode 890(C#)
杰理之快速配对,不支持取消配对【篇】
Responsibility chain model - unity
ES6 note 1
How to estimate the value of "not selling pens" Chenguang?
杰理之关于 TWS 配对方式配置【篇】
Policy mode - unity
POJ 1182: food chain (parallel search) [easy to understand]
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
Solve the problem of remote rviz error reporting