当前位置:网站首页>tp6 实现佣金排行榜
tp6 实现佣金排行榜
2022-07-07 17:29:00 【坚持与努力的成果】
参考数据(表)
CREATE TABLE `user_money` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`gid` int(10) DEFAULT NULL COMMENT '商品id',
`tid` int(10) DEFAULT NULL COMMENT '用户id',
`money` int(11) DEFAULT NULL COMMENT '佣金',
`add_time` datetime DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
排行榜逻辑代码
public function rankingList($time)
{
//连接redis
$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
//查询数据
$data = UserMoney::with('UserCommander')->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;
}
}
//添加到redis有序集合
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);
//判断数据时间排行
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;
}
边栏推荐
- Matplotlib drawing 3D graphics
- SlashData开发者工具榜首等你而定!!!
- Version 2.0 of tapdata, the open source live data platform, has been released
- LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
- 微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
- 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
- 鸿蒙智能家居【1.0】
- Kirin Xin'an with heterogeneous integration cloud financial information and innovation solutions appeared at the 15th Hunan Financial Technology Exchange Conference
- 谷歌seo外链Backlinks研究工具推荐
- [mime notes]
猜你喜欢
Numpy——2. Shape of array
Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
多个kubernetes集群如何实现共享同一个存储
Numpy——2.数组的形状
Numpy——axis
In 2021, the national average salary was released. Have you reached the standard?
关于ssh登录时卡顿30s左右的问题调试处理
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
PV静态创建和动态创建
Numpy——axis
随机推荐
Hongmeng smart home [1.0]
关于ssh登录时卡顿30s左右的问题调试处理
ASP.NET体育馆综合会员管理系统源码,免费分享
我的创作纪念日
Solve the problem of remote rviz error reporting
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks
Experiment 1 of Compilation Principle: automatic implementation of lexical analyzer (Lex lexical analysis)
[information security laws and regulations] review
最长公共前缀(leetcode题14)
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
LC:字符串转换整数 (atoi) + 外观数列 + 最长公共前缀
指定opencv非标准安装的版本
Numpy——axis
Pasqal首席技术官:模拟量子计算率先为工业带来量子优势
微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹
超分辨率技术在实时音视频领域的研究与实践
Research and practice of super-resolution technology in the field of real-time audio and video
The top of slashdata developer tool is up to you!!!
Longest common prefix (leetcode question 14)