当前位置:网站首页>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;
}
边栏推荐
- 浏览积分设置的目的
- L1-025 positive integer a+b (Lua)
- The top of slashdata developer tool is up to you!!!
- ASP.NET幼儿园连锁管理系统源码
- Teach your sister to write the message queue hand in hand
- Solve the error reporting problem of rosdep
- 杰理之按键发起配对【篇】
- Solve the problem of remote rviz error reporting
- J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
- 2022.07.02
猜你喜欢

杰理之相同声道的耳机不允许配对【篇】

杰理之关于 TWS 配对方式配置【篇】

关于ssh登录时卡顿30s左右的问题调试处理

2022如何评估与选择低代码开发平台?

Numpy——axis
![[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer](/img/7d/ed9a5c536b4cc1913fb69640afb98d.png)
[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer

2022.07.05

ASP.NET幼儿园连锁管理系统源码

Kirin Xin'an cloud platform is newly upgraded!

Zhong Xuegao wants to remain innocent in the world
随机推荐
The top of slashdata developer tool is up to you!!!
Uvalive – 4621 CAV greed + analysis "suggestions collection"
杰理之开机自动配对【篇】
爬虫实战(七):爬王者英雄图片
AI writes a poem
How many are there (Lua)
[HDU] 5248 sequence transformation (greedy + dichotomy) [recommended collection]
LeetCode 890(C#)
索引总结(突击版本)
8 CAS
Key points of anti reptile: identifying reptiles
Initial experience of cache and ehcache "suggestions collection"
Longest common prefix (leetcode question 14)
ES6笔记一
AI写首诗
L1-019 who falls first (Lua)
ES6 note 1
炒股如何开户?请问一下手机开户股票开户安全吗?
R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
Seize Jay Chou