当前位置:网站首页>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;
}
边栏推荐
- Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
- 2022如何评估与选择低代码开发平台?
- AI写首诗
- 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
- 杰理之手动配对方式【篇】
- 2022.07.02
- Initial experience of cache and ehcache "suggestions collection"
- 索引总结(突击版本)
- Key points of anti reptile: identifying reptiles
- Hongmeng smart home [1.0]
猜你喜欢
Numpy——axis
ES6笔记一
ASP.NET幼儿园连锁管理系统源码
2022.07.05
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
一张图深入的理解FP/FN/Precision/Recall
Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
2022如何评估与选择低代码开发平台?
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
项目经理『面试八问』,看了等于会了
随机推荐
L1-027 rental (Lua)
SlashData开发者工具榜首等你而定!!!
杰理之关于 TWS 声道配置【篇】
一张图深入的理解FP/FN/Precision/Recall
ES6 note 1
Numpy——2.数组的形状
Unable to link the remote redis server (solution 100%
State mode - Unity (finite state machine)
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer
Numpy——axis
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
Longest common prefix (leetcode question 14)
Big Ben (Lua)
Research and practice of super-resolution technology in the field of real-time audio and video
杰理之按键发起配对【篇】
2022.07.05
Number - number (Lua)
LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀