当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

【RT-Thread env 工具安装】

Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)

5billion, another master fund was born in Fujian

2022.07.05

Kirin Xin'an won the bid for the new generation dispatching project of State Grid!

PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!

索引总结(突击版本)

杰理之测试盒配置声道【篇】

Numpy——2. Shape of array
![[RT thread env tool installation]](/img/bc/9b39651d40a240f0893200793f67e9.png)
[RT thread env tool installation]
随机推荐
Flipping game (enumeration)
LeetCode 515(C#)
LeetCode 890(C#)
转置卷积理论解释(输入输出大小分析)
【Confluence】JVM内存调整
杰理之关于 TWS 交叉配对的配置【篇】
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
Policy mode - unity
Version 2.0 of tapdata, the open source live data platform, has been released
SlashData开发者工具榜首等你而定!!!
LeetCode 535(C#)
First time in China! The language AI strength of this Chinese enterprise is recognized as No.2 in the world! Second only to Google
网信办公布《数据出境安全评估办法》,9 月 1 日起施行
Unable to link the remote redis server (solution 100%
The research group of the Hunan Organizing Committee of the 24th China Association for science and technology visited Kirin Xin'an
ES6笔记一
脑洞从何而来?加州大学最新研究:有创造力的人神经连接会「抄近道」
2022.07.02
648. 单词替换
LeetCode 497(C#)