当前位置:网站首页>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;
}
边栏推荐
- Responsibility chain model - unity
- R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
- R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
- How to share the same storage among multiple kubernetes clusters
- 我的创作纪念日
- [information security laws and regulations] review
- R语言dplyr包select函数、group_by函数、filter函数和do函数获取dataframe中指定因子变量中指定水平中特定数值数据列的值第三大的值
- Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
- 杰理之按键发起配对【篇】
- Research and practice of super-resolution technology in the field of real-time audio and video
猜你喜欢
Kirin Xin'an joins Ningxia commercial cipher Association
648. 单词替换
PV static creation and dynamic creation
Micro service remote debug, nocalhost + rainbow micro service development second bullet
Numpy——axis
Chief technology officer of Pasqual: analog quantum computing takes the lead in bringing quantum advantages to industry
# 欢迎使用Markdown编辑器
索引总结(突击版本)
Review of network attack and defense
Numpy——2.数组的形状
随机推荐
[information security laws and regulations] review
Matplotlib drawing 3D graphics
歌单11111
Specify the version of OpenCV non-standard installation
Business experience in virtual digital human
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
2022年投资哪个理财产品收益高?
2022上半年朋友圈都在传的10本书,找到了
How many are there (Lua)
2022.07.05
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
Numpy——2.数组的形状
[tpm2.0 principle and Application guide] Chapter 9, 10 and 11
国内首次!这家中国企业的语言AI实力被公认全球No.2!仅次于谷歌
how to prove compiler‘s correctness
超分辨率技术在实时音视频领域的研究与实践
MySQL、sqlserver oracle数据库连接方式
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
Uvalive – 4621 CAV greed + analysis "suggestions collection"
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind