where('doctor_id',$doctor['id'])->where('status',1)->limit($number)->page($page)->order('is_read asc,createdAt desc')->select(); $num = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',1)->count(); return json_encode(['status'=>'ok','code'=>'0000','info'=>$info,'sessionid'=>$sessionid,'num'=>$num]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } public function unreadMessage() { try{ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $info = DB::table('messages')->where('is_read', 0)->where('doctor_id', $doctor['id'])->where('status', 1)->order('createdAt desc')->limit(5)->select(); $num = DB::table('messages')->where('is_read', 0)->where('doctor_id', $doctor['id'])->where('status', 1)->count(); return json_encode(['status' => 'ok', 'code' => '0000', 'info' => $info, 'num' => $num,'sessionid'=>$sessionid]); }catch(\Exception $e){ return json_encode(['status'=>'fail','code'=>'2000','msg'=>$e->getMessage()]); } } //消息详情页 public function messageInfo(){ $sessionid = $_REQUEST['sessionid']; $doctor = Cache::get($sessionid); $param = $_REQUEST['param']; $id = $param['id']; $info = DB::table('messages')->where('id',$id)->where('status',1)->where('doctor_id', $doctor['id'])->field('title,content')->find(); if($info){ // 读取到消息 未读状态修改为已读 DB::table('messages')->where('id',$id)->update(['is_read'=>1]); return json_encode(['status'=>'ok','code'=>'0000','info'=>$info]); }else{ return json_encode(['status'=>'fail','code'=>'1012','msg'=>'该条信息不存在','sessionid'=>$sessionid]); } } public function changeRead(){ $id = $_REQUEST['id']; DB::table('messages')->where('id',$id)->update(['is_read'=>1]); return json_encode(['status'=>'ok','code'=>'0000','msg'=>'已读']); } }