当前位置:网站首页>列表查询排序参数处理
列表查询排序参数处理
2022-06-23 14:24:00 【xufengnian_boke】
public function deviceList($params)
{
$time = time();
$page = isset($params['page']) ? $params['page'] : 1;
$page_size = isset($params['page_size']) ? $params['page_size'] : 10;
$type = isset($params['type']) ? $params['type'] : 1;//1正常,2过期
$nickname = $params['nickname'] ?? "";
$account = $params['account'] ?? "";
$uid = $params['uid'] ?? "";
$time_type = $params['time_type'] ?? 1;//1购买时间,2有效期
$device_type = $params['device_type'] ?? "";
$device_str = $params['device_str'] ?? "";
$start_time = $params['start_time'] ?? "";
$end_time = $params['end_time'] ?? "";
$export = $params['export'] ?? "";
if ($device_type != 'asc' && $device_type != 'desc'){
$device_type = 'desc';
}
if ($device_str == 'device_days'){
//设备天数
$order = 'c.expire_time '. $device_type;
}elseif ($device_str == 'defer_count'){
//续费次数
$order = 'defer_count '.$device_type;
}elseif ($device_str == 'use_duration'){
//使用时长
$order = 'c.use_duration '.$device_type;
}elseif ($device_str == 'surplus'){
//剩余时长
$order = 'surplus '.$device_type;
}elseif ($device_str == 'use_duration_rate'){
//使用占比时长
$order = 'use_duration_rate '.$device_type;
}elseif ($device_str == 'buy_time'){
//购买时间
$order = 'c.valid_time '.$device_type;
}elseif ($device_str == 'expire_time'){
//过期时间
$order = 'c.expire_time '.$device_type;
}else{
$order = 'c.valid_time '.$device_type;
}
$map = [];
$map_time = [];
if ($type == 1){
//未过期
$map['c.expire_time'] = ['>',$time];
}else{
$map['c.expire_time'] = ['<',$time];
}
if (!empty($nickname)){
$map['u.nick_name'] = ['=',$nickname];
}
if (!empty($account)){
$map['u.account'] = ['=',$account];
}
if (!empty($uid)){
$map['c.uid'] = ['=',$uid];
}
if (!empty($uid)){
$map['c.uid'] = ['=',$uid];
}
if ($time_type == 1){
if (!empty($start_time)){
$start_time = strtotime($start_time);
$map['c.valid_time'] = ['>',$start_time];
$map_time['valid_time'] = ['>',$start_time];
}
if (!empty($end_time)){
$end_time = strtotime($end_time) + 86400;
$map['c.valid_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];
// $map['c.valid_time'] = ['<',$end_time];
$map_time['valid_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];;
}
}elseif($time_type == 2){
if (!empty($start_time)){
$start_time = strtotime($start_time);
$map['c.expire_time'] = ['>',$start_time];
$map_time['expire_time'] = ['>',$start_time];
}
if (!empty($end_time)){
$end_time = strtotime($end_time) + 86400;
$map['c.expire_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];;
$map_time['expire_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];;
}
}else{
if (!empty($start_time)){
$start_time = strtotime($start_time);
$map['c.expire_time'] = ['>',$start_time];
$map_time['create_time'] = ['>',$start_time];
}
if (!empty($end_time)){
$end_time = strtotime($end_time) + 86400;
$map['c.expire_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];;
$map_time['create_time'] = $start_time ? [['>',$start_time],['<',$end_time]] : ['<',$end_time];;
}
}
$model = new CloudDevice();
$field = [
'c.id',
'c.uid',
'c.valid_time',
'c.use_duration',
'c.last_event_time',
'c.last_event_type',
'c.defer_count',
Db::raw('(c.expire_time-c.use_duration-c.valid_time) surplus'),
Db::raw('(c.use_duration/(c.expire_time-c.valid_time)) use_duration_rate'),
'c.expire_time',
'u.nick_name',
'u.account',
];
$list = $model->alias('c')
->join('box_user u','c.uid=u.id','left')
->field($field)->where($map)->order($order)
->paginate($page_size)->toArray();
// dump($model->getLastSql());
//dump($list);die();
if (!empty($list['data'])){
foreach ($list['data'] as $key=>$value){
$list['data'][$key]['device_day'] = intval(($value['expire_time']-$value['valid_time'])/86400).'天';
if ($value['last_event_type'] == 'RUN' || $value['last_event_type'] == 'HANG'){
$value['use_duration'] += $time - $value['last_event_time'];
}
$list['data'][$key]['use_duration'] = $this->secsToStr($value['use_duration']);
$list['data'][$key]['surplus'] = $this->secsToStr($value['expire_time']-$value['use_duration']-$value['valid_time']);
$list['data'][$key]['use_duration_rate'] = round(($value['use_duration']/($value['expire_time']-$value['valid_time']))*100,2).'%';
$list['data'][$key]['valid_time'] = date('Y-m-d H:i:s',$value['valid_time']);
$list['data'][$key]['expire_time'] = date('Y-m-d H:i:s',$value['expire_time']);
}
//导出
if (!empty($export)){
$this->exportCsv($list['data']);
}
}
$valid_device = $model->where($map_time)->where('expire_time','>',$time)->count();
$valid_account = $model->where($map_time)->where('expire_time','>',$time)->group('uid')->count();
$invalid_device = $model->where($map_time)->where('expire_time','<',$time)->count();
$list['valid_device'] = $valid_device ?? 0;
$list['valid_account'] = $valid_account ?? 0;
$list['invalid_device'] = $invalid_device ?? 0;
return $list;
}
边栏推荐
- 图解OneFlow的学习率调整策略
- ICML 2022 𞓜 context integrated transformer based auction design neural network
- 2021-04-15
- [Level 2 warranty] which brand of Fortress machine is good for Level 2 warranty?
- Idea view View the class file idea Class folder
- Teach you how to build Tencent cloud server (explanation with pictures and pictures)
- Force deduction solution summary 513- find the value of the lower left corner of the tree
- 2021-05-08
- Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
- 微信小程序引导用户添加小程序动画页
猜你喜欢

大厂架构师:如何画一张大气的业务大图?

The well-known face search engine provokes public anger: just one photo will strip you of your pants in a few seconds

【深入理解TcaplusDB技術】TcaplusDB構造數據

Un million de bonus vous attend, le premier concours d'innovation et d'application de la Chine Yuan cosmique Joint Venture Black Horse Hot Recruitment!

2021-05-08

狂奔的极兔,摔了一跤

信贷产品额度定价场景下的回归模型效果评估

山东:美食“隐藏款”,消费“扫地僧”

Introduction to helm basics helm introduction and installation

The largest IPO of Hong Kong stocks this year, with a net worth of 66billion, is the "King" sitting on the mine
随机推荐
useState vs useRef 和 useReducer:相同点、不同点和用例
idea查看.class文件 idea查看.class文件夹
Cause analysis and intelligent solution of information system row lock waiting
Mysql数据库---日志管理、备份与恢复
Distributed database uses logical volume to manage storage expansion
NFNet:NF-ResNet的延伸,不用BN的4096超大batch size训练 | 21年论文
Why is Xiaomi stuck in the chip quagmire?
2021-05-08
系统设计与分析-技术报告-定时清理验证码的一种解决方案
The principle of redis cache consistency deep analysis
Google &huggingface| zero sample language model structure with the strongest ability
如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版
阿里 Seata 新版本终于解决了 TCC 模式的幂等、悬挂和空回滚问题
腾讯云服务器发送邮件失败
2021-04-15
Effect evaluation of regression model under credit product quota pricing scenario
go语言的变量声明
Redis缓存三大异常的处理方案梳理总结
2021-05-08
操作系统底层知识总结(面试)