当前位置:网站首页>List query sorting parameter processing
List query sorting parameter processing
2022-06-23 15:11: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 normal ,2 Be overdue
$nickname = $params['nickname'] ?? "";
$account = $params['account'] ?? "";
$uid = $params['uid'] ?? "";
$time_type = $params['time_type'] ?? 1;//1 Time of purchase ,2 The period of validity
$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'){
// Equipment days
$order = 'c.expire_time '. $device_type;
}elseif ($device_str == 'defer_count'){
// Renewal times
$order = 'defer_count '.$device_type;
}elseif ($device_str == 'use_duration'){
// Use time
$order = 'c.use_duration '.$device_type;
}elseif ($device_str == 'surplus'){
// Remaining time
$order = 'surplus '.$device_type;
}elseif ($device_str == 'use_duration_rate'){
// Duration of use proportion
$order = 'use_duration_rate '.$device_type;
}elseif ($device_str == 'buy_time'){
// Time of purchase
$order = 'c.valid_time '.$device_type;
}elseif ($device_str == 'expire_time'){
// Expiration time
$order = 'c.expire_time '.$device_type;
}else{
$order = 'c.valid_time '.$device_type;
}
$map = [];
$map_time = [];
if ($type == 1){
// Not expired
$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).' God ';
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']);
}
// export
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;
}
边栏推荐
- ICML 2022 𞓜 context integrated transformer based auction design neural network
- MySQL advanced statement 2
- Selenium Edge的IE模式
- 一款自动生成单元测试的 IDEA 插件
- 巴比特 | 元宇宙每日必读:Meta、微软等科技巨头成立元宇宙标准论坛组织,华为、阿里加入,英伟达高管称欢迎来自加密世界的参与者...
- 等保備案是什麼意思?應該去哪裏辦理備案?
- 中国矿大团队,开发集成多尺度深度学习模型,用于 RNA 甲基化位点预测
- AXI_ Round_ Robin_ Arbiter design - aw and W channels
- Sectigo(Comodo)证书的由来
- Mysql双主配置的详细步骤
猜你喜欢

JS创建一个数组(字面量)

Self inspection is recommended! The transaction caused by MySQL driver bug is not rolled back. Maybe you are facing this risk!

2021-06-07

2021-04-15

这届文娱人,将副业做成了主业

小米为何深陷芯片泥潭?

Uniswap 收购 NFT交易聚合器 Genie,NFT 交易市场将生变局?

Babbitt | metauniverse daily must read: meta, Microsoft and other technology giants set up the metauniverse Standards Forum. Huawei and Alibaba joined. NVIDIA executives said that they welcomed partic

js的slice()和splice()

从3开始,在业务系统中增加分页功能
随机推荐
乐高宣布涨价,炒家更嗨皮了
The largest IPO of Hong Kong stocks this year, with a net worth of 66billion, is the "King" sitting on the mine
Golang -- multiple processing scenarios for files
【云驻共创】制造业企业如何建设“条码工厂”
RF Analyzer Demo搭建
Raspberry PI installing the wiring pi
idea查看.class文件 idea查看.class文件夹
大厂架构师:如何画一张大气的业务大图?
Execute the sc.exe QC command to query some services. The data area passed to the system call is too small
Error creating bean with name xxx Factory method ‘sqlSessionFactory‘ threw exception; nested excepti
[cloud based co creation] how manufacturing enterprises build "barcode factories"
When I went to oppo for an interview, I got numb...
2021-04-15
MySQL advanced statement 2
Sectigo(Comodo)证书的由来
An idea plug-in for automatically generating unit tests
Effect evaluation of regression model under credit product quota pricing scenario
[cloud based co creation] intelligent supply chain plan: improve the decision-making level of the supply chain and help enterprises reduce costs and increase efficiency
5分钟快速上线Web应用和API(Vercel)
Selenium Edge的IE模式