123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\admin\controller\base\msg;
- /**
- * @title : 消息提醒记录
- * @desc : 系统消息提醒
- * @Author : Rock
- * @Date : 2021-05-24 10:38:34
- * @LastEditTime: 2024-08-30 10:55:39
- */
- use app\admin\controller\Base;
- use app\common\model\base\msg\Notice as NoticeModel;
- class Notice extends Base
- {
- protected $noNeedAuth = ['getList','getOptions','clearNoRead','MsgUnreadNum'];
- protected $noticeModel = null;
- protected $msgtypeModel = null;
- public function initialize()
- {
- parent::initialize();
- $this->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 = '<a href="'.$pcHost.$notice->url.'">'.$notice->title.'</a>';
- $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);
- }
- }
|