Message.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. class Message extends Controller
  5. {
  6. public function index()
  7. {
  8. // 留言知识库(默认查询前七天的留言)
  9. $end = time();
  10. $start = time()-604800;
  11. if(request()->isPost()){
  12. $time = input("param.time/s");
  13. $key = input("param.key/s");
  14. $type = input("param.type/s");
  15. if($time == 'week'){
  16. //前一周
  17. $start = time()-604800;
  18. }
  19. if($time == 'oneMonth'){
  20. //前一个月
  21. $start = time()-2592000;
  22. }
  23. if($time == 'threeMonth'){
  24. //前三个月
  25. $start = time()-7776000;
  26. }
  27. if(!empty($start_time)){
  28. $start = strtotime($start_time);
  29. }
  30. if(!empty($end_time)){
  31. $end = strtotime($end_time . ' 23:59:59');
  32. }
  33. $where = array();
  34. if(!empty($type)){
  35. $type_id = db('messagetype')->where('name', $type)->find();
  36. if(!empty($type)){
  37. $where['type_id'] = $type_id['id'];
  38. }
  39. }
  40. }
  41. if(!empty($key)){
  42. $message = db('accountsmessage')->whereBetween('add_time', [$start, $end])->where($where)->whereLike('content','%'.$key.'%')->where('if_public', 1)->select();
  43. }else{
  44. $message = db('accountsmessage')->whereBetween('add_time', [$start, $end])->where($where)->where('if_public', 1)->select();
  45. }
  46. $type = db('messagetype')->select();
  47. foreach($message as $key=>$vo){
  48. for($i=0;$i<count($type);$i++){
  49. if($vo['type_id'] == $type[$i]['id']){
  50. $message[$key]['type_name'] = $type[$i]['name'];
  51. }
  52. }
  53. }
  54. $data = [
  55. 'status'=>1,
  56. 'msg'=>'成功',
  57. 'data'=>$message
  58. ];
  59. return json_encode($data,JSON_UNESCAPED_UNICODE);
  60. }
  61. }