当前位置:网站首页>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;
}
边栏推荐
- 杰理之按键发起配对【篇】
- Command mode - unity
- Hongmeng smart home [1.0]
- Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
- 【Confluence】JVM内存调整
- Solve the error reporting problem of rosdep
- 博睿数据入选《2022爱分析 · IT运维厂商全景报告》
- tp6 实现佣金排行榜
- 解决rosdep的报错问题
- how to prove compiler‘s correctness
猜你喜欢

Pasqal首席技术官:模拟量子计算率先为工业带来量子优势

Numpy——axis

PV静态创建和动态创建

小试牛刀之NunJucks模板引擎

Kirin Xin'an cloud platform is newly upgraded!

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference

谷歌seo外链Backlinks研究工具推荐

SlashData开发者工具榜首等你而定!!!

Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
随机推荐
Draw squares with Obama (Lua)
PV static creation and dynamic creation
ES6笔记一
2022年投资哪个理财产品收益高?
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
Make insurance more "safe"! Kirin Xin'an one cloud multi-core cloud desktop won the bid of China Life Insurance, helping the innovation and development of financial and insurance information technolog
LC: string conversion integer (ATOI) + appearance sequence + longest common prefix
2022.07.02
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
“本真”是什么意思
cmd命令进入MySQL时报服务名或者命令错误(傻瓜式教学)
杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】
杰理之关于 TWS 配对方式配置【篇】
How to estimate the value of "not selling pens" Chenguang?
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
Seize Jay Chou
杰理之相同声道的耳机不允许配对【篇】
# 欢迎使用Markdown编辑器
杰理之按键发起配对【篇】