12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\inter\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Cache;
- use think\Log;
- class Messages extends Base
- {
- public function allMessage(){
- try{
- $sessionid = $_REQUEST['sessionid'];
- log::record('-----------------请求的session-------');
- log::record($sessionid);
- $doctor = Cache::get($sessionid);
- $param = $_REQUEST['param'];
- $page = $param['page'];
- $number = $param['number'];
- $info = DB::table('messages')->where('doctor_id',$doctor['id'])->where('status',1)->limit($number)->page($page)->order('is_read asc,ctime 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('ctime 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'=>'已读']);
- }
- }
|