noticeModel = new NoticeModel; $this->msgtypeModel = new \app\common\model\base\msg\Msgtype; } /** * @title: 消息提醒记录列表 * @desc: * @param {int} {read_status} {} {是否已读} * @param {int} {channel} {} {发送渠道,1=站内信,2=短信,3=邮件} * @return {*} * @Author: Rock * @Date: 2021-05-24 10:53:28 * @LastEditTime: Do not edit */ public function getList($read_status=0,$channel=0,$pageNo=1,$pageSize=50) { $user_id = 0; if(empty($this->userinfo)){ return res(2,"请登录"); }else{ $user_id = !empty($this->userinfo)?$this->userinfo['user_id']:0; } $where = []; $where[] = ['receive_uid','=',$user_id]; if(!empty($read_status)){ $where[] = ['read_status','=',$read_status]; } if(!empty($channel)){ $where[] = ['channel','=',$channel]; } $list = $this->noticeModel->where($where)->with(['msgtype','receiver'])->order('send_at DESC')->paginate(['page'=>$pageNo,'list_rows'=>$pageSize]); $total = $list->total(); $items = $list->items(); return pageRes(1,"获取成功",$total,$items); } /** * @title: 删除消息提醒记录 * @desc: * @param {mixed} {ids} {} {要删除的类型id} * @return {*} * @Author: Rock * @Date: 2021-05-24 10:53:28 * @LastEditTime: Do not edit */ public function deDelete($ids='') { $where = []; if(empty($ids)){ return res(2,'参数错误'); }elseif(strstr($ids,',')){ $ids = explode(',',$ids); $where[] = ['notice_id','IN',$ids]; }elseif(is_array($ids)){ $where[] = ['notice_id','IN',$ids]; }elseif($ids){ $where[] = ['notice_id','=',$ids]; } $this->noticeModel->where($where)->delete(); slog(1,"删除了消息提醒"); return res(1,"删除成功"); } /** * @title: 消息提醒记录选项 * @desc: * @param {*} * @return {*} * @Author: Rock * @Date: 2021-05-26 10:01:02 * @LastEditTime: Do not edit */ public function getOptions() { $data = [ 'channelList' => $this->noticeModel->channelList(), 'sendStatusList'=> $this->noticeModel->sendStatusList(), 'readStatusList'=> $this->noticeModel->readStatusList(), ]; return res(1,'获取成功',$data); } /** * @title: 测试发送消息通知 * @desc: * @param {*} * @return {*} * @Author: Rock * @Date: 2021-05-26 18:49:48 * @LastEditTime: Do not edit */ public function testSend() { try{ $year = date('Y'); $month = date('m'); $day = date('d'); $h = date('H'); $i = date('i'); $notice = [ 'uids' => 1, 'title' => '测试发送一个消息', 'type_code' => 'USECARNEWTASK', 'param1' => 1, 'param2' => 2, 'data' =>[$year,$month,$day,$h,$i] ]; $res = NoticeModel::sendNotice($notice); return $res; }catch(\Exception $e){ return res(2,$e->getFile().$e->getLine().$e->getMessage()); } } /** * @title: 重新发送消息通知 * @desc: * @param {Int} {notice_id} {} {消息ID} * @return {*} * @Author: Rock * @Date: 2021-05-24 16:43:30 * @LastEditTime: Do not edit */ public function reSend($notice_id=0) { $notice = $this->noticeModel->where('notice_id',$notice_id)->with(['msgtype','receiver'])->find(); $pcHost = sysconfig('base.pc_host'); switch($notice->channel){ case 2://短信 $res = NoticeModel::sendSms($notice->receive_uid,[$notice->title],771289); break; case 3://邮件 $content = ''.$notice->title.''; $res = NoticeModel::sendMail($notice->receive_uid,$notice->title,$content); break; case 1://站内信 $notice->read_status = 1; $notice->save(); $res = NoticeModel::sendWs($notice->receive_uid,$notice->toArray()); return res(1,"发送成功"); default: break; } if($res['code']==1){ return res(1,'发送成功'); }else{ return res(2,$res['msg']); } } /** * @title: 清除未读消息 * @desc: * @param {*} $notice_id * @return {*} * @Author: Rock * @Date: 2021-06-04 09:32:29 * @LastEditTime: Do not edit */ public function clearNoRead($notice_id=0) { $where = []; $where[] = ['read_status','=',1]; $where[] = ['receive_uid','=',$this->userinfo['user_id']]; if(!empty($notice_id)){ $where[] = ['notice_id','=',$notice_id]; } $this->noticeModel->where($where)->update(['read_status'=>2]); return res(1,"操作成功"); } /** * @title: 获取消息未读数等 * @Author: wangkewei * @return {*} * @Date: 2021/7/13 15:07 */ public function MsgUnreadNum() { $ids = Org::getChildrenIds($this->userinfo['org_id']); $user_id = $this->userinfo['user_id']; $role_code = $this->userinfo['role_code']; $res = $this->noticeModel->MsgUnreadNum($user_id,$role_code,$ids); return res(1,"操作成功",$res); } }