Messages.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\inter\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use think\Cache;
  7. use think\Log;
  8. class Messages extends Base
  9. {
  10. public function allMessage(){
  11. try{
  12. $sessionid = $_REQUEST['sessionid'];
  13. log::record('-----------------请求的session-------');
  14. log::record($sessionid);
  15. $doctor = Cache::get($sessionid);
  16. $param = $_REQUEST['param'];
  17. $page = $param['page'];
  18. $number = $param['number'];
  19. $info = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',1)->limit($number)->page($page)->order('is_read asc,ctime desc')->select();
  20. $num = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',1)->count();
  21. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'num'=>$num]);
  22. }catch(\Exception $e){
  23. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  24. }
  25. }
  26. public function unreadMessage()
  27. {
  28. try{
  29. $sessionid = $_REQUEST['sessionid'];
  30. $doctor = Cache::get($sessionid);
  31. $info = DB::table('messages')->where('is_read', 0)->where('doctor_id', $doctor['id'])->where('status', 1)->order('ctime desc')->limit(5)->select();
  32. $num = DB::table('messages')->where('is_read', 0)->where('doctor_id', $doctor['id'])->where('status', 1)->count();
  33. return json_encode(['status' => 'ok', 'code' => '0000', 'info' => $info, 'num' => $num,'sessionid'=>$sessionid]);
  34. }catch(\Exception $e){
  35. return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]);
  36. }
  37. }
  38. //消息详情页
  39. public function messageInfo(){
  40. $sessionid = $_REQUEST['sessionid'];
  41. $doctor = Cache::get($sessionid);
  42. $param = $_REQUEST['param'];
  43. $id = $param['id'];
  44. $info = DB::table('messages')->where('id',$id)->where('status',1)->where('doctor_id', $doctor['id'])->field('title,content')->find();
  45. if($info){
  46. // 读取到消息 未读状态修改为已读
  47. DB::table('messages')->where('id',$id)->update(['is_read'=>1]);
  48. return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]);
  49. }else{
  50. return json_encode(['status'=>'fail','code'=>'1012','msg'=>'该条信息不存在','sessionid'=>$sessionid]);
  51. }
  52. }
  53. public function changeRead(){
  54. $id = $_REQUEST['id'];
  55. DB::table('messages')->where('id',$id)->update(['is_read'=>1]);
  56. return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已读']);
  57. }
  58. }