| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- class Message extends Controller
- {
- public function index()
- {
- // 留言知识库(默认查询前七天的留言)
- $end = time();
- $start = time()-604800;
- if(request()->isPost()){
- $time = input("param.time/s");
- $key = input("param.key/s");
- $type = input("param.type/s");
- if($time == 'week'){
- //前一周
- $start = time()-604800;
- }
- if($time == 'oneMonth'){
- //前一个月
- $start = time()-2592000;
- }
- if($time == 'threeMonth'){
- //前三个月
- $start = time()-7776000;
- }
- if(!empty($start_time)){
- $start = strtotime($start_time);
- }
- if(!empty($end_time)){
- $end = strtotime($end_time . ' 23:59:59');
- }
- $where = array();
- if(!empty($type)){
- $type_id = db('messagetype')->where('name', $type)->find();
- if(!empty($type)){
- $where['type_id'] = $type_id['id'];
- }
- }
- }
- if(!empty($key)){
- $message = db('accountsmessage')->whereBetween('add_time', [$start, $end])->where($where)->whereLike('content','%'.$key.'%')->where('if_public', 1)->select();
- }else{
- $message = db('accountsmessage')->whereBetween('add_time', [$start, $end])->where($where)->where('if_public', 1)->select();
- }
- $type = db('messagetype')->select();
- foreach($message as $key=>$vo){
- for($i=0;$i<count($type);$i++){
- if($vo['type_id'] == $type[$i]['id']){
- $message[$key]['type_name'] = $type[$i]['name'];
- }
- }
- }
- $data = [
- 'status'=>1,
- 'msg'=>'成功',
- 'data'=>$message
- ];
- return json_encode($data,JSON_UNESCAPED_UNICODE);
- }
- }
|