当前位置:网站首页>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;
}
边栏推荐
- Zhong Xuegao wants to remain innocent in the world
- 2022上半年朋友圈都在传的10本书,找到了
- 网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
- R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
- Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
- Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
- L1-027 rental (Lua)
- 反爬虫的重点:识别爬虫
- 歌单11111
- 杰理之手动配对方式【篇】
猜你喜欢

2022.07.02

Kirin Xin'an cloud platform is newly upgraded!

The top of slashdata developer tool is up to you!!!

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

从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks

99% of people don't know that privatized deployment is also a permanently free instant messaging software!

2022.07.04

一张图深入的理解FP/FN/Precision/Recall

PMP每日一练 | 考试不迷路-7.7

Borui data was selected in the 2022 love analysis - Panoramic report of it operation and maintenance manufacturers
随机推荐
Specify the version of OpenCV non-standard installation
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
吞吐量Throughout
Jerry's headphones with the same channel are not allowed to pair [article]
PV静态创建和动态创建
Numpy——2.数组的形状
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
【RT-Thread env 工具安装】
ES6笔记一
Business experience in virtual digital human
谷歌seo外链Backlinks研究工具推荐
[tpm2.0 principle and Application guide] Chapter 16, 17 and 18
指定opencv非标准安装的版本
Longest common prefix (leetcode question 14)
[mime notes]
How to share the same storage among multiple kubernetes clusters
POJ 1182: food chain (parallel search) [easy to understand]
how to prove compiler‘s correctness
AD域组策略管理