123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- <?php
- /**
- * Created by 上海互教教育科技有限公司.
- * User: 刘红伟
- * QQ : 454303753
- * Date: 2018/3/7 0007
- * Time: 下午 14:37
- */
- class NotificationController extends Controller
- {
- public function actionIndex()
- {
- $start_time = Req::get("start_time");
- $end_time = Req::get("end_time");
- $mode = Req::get("mode");
- $_page = Req::get("page");
- $criteria = new CDbCriteria();
- if($start_time)
- {
- $criteria->addCondition('create_time>=:create_time');
- $criteria->params[':create_time'] = strtotime($start_time);
- }
- if(empty($_page))
- {
- $_page = 1;
- }
- if($end_time)
- {
- $criteria->addCondition('create_time<=:end_time');
- $criteria->params[':end_time'] = strtotime($end_time);
- }
- if($mode<0){
- $criteria->addCondition('mode=:mode');
- $criteria->params[':mode'] = 0;
- }
- if($mode>0){
- $criteria->addInCondition('mode',array(1,2));
- }
- $criteria->order = "create_time desc";
- $count = SNotificationModel::model()->count($criteria);
- $pager = new CPagination($count,10);
- $criteria->limit=$pager->getLimit();
- $criteria->offset=$pager->getOffset();
- $notification_data = SNotificationModel::model()->findAll($criteria);
- $data = array();
- $data['page'] = $pager;
- $data['start_time'] = $start_time;
- $data['end_time'] = $end_time;
- $data['_page'] = $_page;
- $data['page_total'] = $count;
- $data['mode'] = $mode;
- $data['list'] = $notification_data;
- $this->render("index",$data);
- }
- public function actionDel()
- {
- $n_id = Req::post('n_id');
- if($n_id)
- {
- $n_ids = explode(',',$n_id);
- $criteria = new CDbCriteria();
- $criteria->addInCondition('id',$n_ids);
- SNotificationModel::model()->deleteAll($criteria);
- echo json_encode(array('status'=>1));exit;
- }
- echo json_encode(array('status'=>0));exit;
- }
- public function actionAjax_exam_info()
- {
- $data = array();
- $exam_group_id = Req::post('exam_group_id');
- $n_id = Req::post('n_id');
- $mode = Req::post('mode');
- $teacher_data = array();
- $class_data = array();
- $class_name = array();
- $teacher_ids = array();
- $subject_id = 3;
- //更新已读
- if($n_id)
- {
- SNotificationModel::model()->updateAll(array('status'=>1,'update_time'=>time()),'id=:id',array(':id'=>$n_id));
- }
- if($mode>1){
- $notification = SNotificationModel::model()->find('id=:id',array(':id'=>$n_id));
- if($notification)
- {
- $data['mode'] = 2;
- $data['title'] = $notification->title;
- $data['create_time'] = date('Y-m-d',$notification->create_time);
- $data['alarm_level'] = $notification->alarm_level;
- $data['alarm_description'] = $notification->alarm_description;
- $data['school_name'] = $this->schoolInfo['school_name'];
- echo json_encode($data);exit;
- }
- }
- //获取本校所有老师信息
- $teachers = Teacher::model()->findAll();
- if($teachers){
- foreach ($teachers as $v)
- {
- $teacher_data[$v->teacher_id] = $v->teacher_name;
- }
- }
- //获取本学期班级信息
- $classes = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
- if($classes)
- {
- foreach ($classes as $v)
- {
- $class_data[$v->class_id] = $v->class_name;
- }
- }
- //获取本次考试信息
- $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam_group)
- {
- $data['mark_type'] = $exam_group->mark_type;
- if(isset($teacher_data[$exam_group->teacher_id]))
- {
- $data['teacher_name'] = $teacher_data[$exam_group->teacher_id];
- }
- }
- //获取考试名称
- $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
- if($exam)
- {
- $data['exam_name'] = $exam->name;
- $data['exam_time'] = date('Y-m-d',$exam->create_time);
- $data['subject_id'] = $exam->subject_id;
- $subject_id = $exam->subject_id;
- }
- //获取通知信息
- $notification = SNotificationModel::model()->find('id=:id',array(':id'=>$n_id));
- if($notification)
- {
- $class_ids = explode(',',$notification->classids);
- foreach ($class_ids as $v)
- {
- if(isset($class_data[$v]))
- {
- $class_name[] = $class_data[$v];
- }
- }
- $teacher_name=array();
- if($exam_group&& isset($exam_group->mark_type)&&$exam_group->mark_type==4)
- {
- $criteria1 = new CDbCriteria();
- $criteria1->addInCondition('class_id',$class_ids);
- $teacher_class = TeacherToClass::model()->findAll($criteria1);
- if($teacher_class)
- {
- if(in_array($subject_id,$this->mathSubjectId)){
- $subject_id = 3;
- }
- foreach ($teacher_class as $v)
- {
- $teacher_ids[$v->teacher_id] = $v->teacher_id;
- }
- //
- $criteria = new CDbCriteria();
- $criteria->addInCondition('teacher_id',$teacher_ids);
- $criteria->addCondition('subjects=:subjects');
- $criteria->params[':subjects'] = $subject_id;
- $teacher_ids = Teacher::model()->findAll($criteria);
- if($teacher_ids){
- foreach ($teacher_ids as $val){
- $teacher_name[]=$val->teacher_name;
- }
- }
- }
- $data['teacher_name'] = join(',',$teacher_name);
- }
- $data['class_name'] = join(',',$class_name);
- $data['mode'] = 1;
- $count = SNotificationModel::model()->count('status=:status',array(':status'=>0));
- $data['count'] = $count;
- }
- echo json_encode($data);exit;
- }
- //2021新版客户端通知
- public function actionList(){
- $title = Req::get("title");
- $_page = Req::get("page");
- $criteria = new CDbCriteria();
- if(empty($_page))
- {
- $_page = 1;
- }
- if($title){
- $criteria->addCondition("title like :title");
- $criteria->params[':title'] = '%'.$title.'%';
- }
- if(!isset(Yii::app()->session['testFlag']) || (Yii::app()->session['testFlag']!=1)){
- $criteria->addCondition("status =2");
- }
- $criteria->order = "create_time desc";
- $count = ClientNotifyModel::model()->count($criteria);
- $pager = new CPagination($count,10);
- $criteria->limit=$pager->getLimit();
- $criteria->offset=$pager->getOffset();
- $notification_data = ClientNotifyModel::model()->findAll($criteria);
- $data = array();
- $data['page'] = $pager;
- $data['_page'] = $_page;
- $data['page_total'] = $count;
- $data['title'] = $title;
- $data['list'] = $notification_data;
- $this->render("list",$data);
- }
- public function actionPush(){
- $id = Req::post("id");
- $result=array();
- $result['status']=0;
- if(!$id){
- $result['msg']='id不能为空';
- exit(json_encode($result));
- }
- $criteria = new CDbCriteria();
- $criteria->addCondition('id=:id');
- $criteria->params[':id'] = $id;
- $rs = ClientNotifyModel::model()->updateAll(array('status'=>2,'update_time'=>time()),$criteria);
- if($rs){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- public function actionDeleteNo(){
- $id = Req::post('id');
- $result['status']=0;
- $criteria = new CDbCriteria();
- $criteria->addCondition('id=:id');
- $criteria->params[':id'] = $id;
- //ClientNotifyModel::model()->deleteAll($criteria);
- $rs = ClientNotifyModel::model()->updateAll(array('status'=>0,'update_time'=>time()),$criteria);
- if($rs){
- $result['status']=1;
- }
- exit(json_encode($result));
- }
- public function actionEdit(){
- if (Yii::app()->request->getIsPostRequest()){
- $title=Req::post('title');
- $content=Req::post('content');
- $eid=Req::post('eid');
- $files=Req::post('files');
- $time=time();
- if($eid){
- $criteria = new CDbCriteria();
- $criteria->addCondition('id=:id');
- $criteria->params[':id'] = $eid;
- $rs = ClientNotifyModel::model()->updateAll(array('title'=>$title,'content'=>$content,'update_time'=>time(),'file_list'=>$files),$criteria);
- if($rs){
- Yii::app()->jump->error('保存成功',Yii::app()->createUrl('notification/list'));
- }else{
- Yii::app()->jump->error('保存失败',Yii::app()->createUrl('notification/edit'));
- }
- }else{
- $notifyModel=new ClientNotifyModel();
- $notifyModel->title=$title;
- $notifyModel->content=$content;
- $notifyModel->create_time=$time;
- $notifyModel->status=1;
- $notifyModel->update_time=$time;
- $notifyModel->file_list=$files;
- if($notifyModel->save()){
- Yii::app()->jump->error('保存成功',Yii::app()->createUrl('notification/list'));
- }else{
- Yii::app()->jump->error('保存失败',Yii::app()->createUrl('notification/edit'));
- }
- }
- }
- $id=Req::get('id');
- $data=array();
- if($id){
- $rs=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
- $files=json_decode(str_replace(""",'"',$rs['file_list']),true);
- $data=array(
- 'title'=>$rs['title'],
- 'content'=>$rs['content'],
- 'id'=>$rs['id'],
- 'file_list'=>$files
- );
- }
- $this->render("edit",$data);
- }
- public function actionAjaxGetData(){
- $id=Req::post('id');
- $result['status']=0;
- if(!$id){
- exit(json_encode($result));
- }
- $data=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
- $files=json_decode(str_replace(""",'"',$data['file_list']),true);
- $html='';
- if($files){
- $html='<div class="atta_list">';
- $html.='<p><b>附件</b></p>';
- foreach ($files as $file){
- $html.='<p><span class="blue">'.$file['file_name'].'</span> <span class="atta" title="'.$file['file_name'].'" href="'.$file['url'].'"><img src="/images/download-atta.png" width="20px" height="18px"></span></p>';
- }
- $html.='<p class="red-tips"> 注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!</p>';
- $html.='</div>';
- }
- $data['content']=str_replace("\r\n","<br>",$data['content']);
- $notify=array(
- 'title'=>$data['title'],
- 'content'=>$data['content'],
- 'files'=>$html
- );
- $result['status']=1;
- $result['data']=$notify;
- exit(json_encode($result));
- }
- public function actionView(){
- $id=Req::get('id');
- $data=array();
- if($id){
- $rs=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
- $files=json_decode(str_replace(""",'"',$rs['file_list']),true);
- $html='';
- if($files){
- $html='<div class="atta_list">';
- $html.='<p><b>附件</b></p>';
- foreach ($files as $file){
- $html.='<p><span class="blue">'.$file['file_name'].'</span> <span class="atta" title="'.$file['file_name'].'" href="'.$file['url'].'"><img src="/images/download-atta.png" width="20px" height="18px"></span></p>';
- }
- $html.='<p class="red-tips"> 注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!</p>';
- $html.='</div>';
- }
- $rs['content']=str_replace("\r\n","<br>",$rs['content']);
- $data=array(
- 'title'=>$rs['title'],
- 'content'=>$rs['content'],
- 'id'=>$rs['id'],
- 'files'=>$html
- );
- }
- $this->renderPartial("view",$data);
- }
- public function actionUpload(){
- $error['success'] = 0;
- $fileUrlArr=array();
- $file_max_size = 11 * 1024 * 1024;
- foreach ($_FILES as $key =>$val){
- if ($_FILES[$key]["size"] > $file_max_size) {
- $error['message'] = '文件超过最大限制,最大为10M';
- echo json_encode($error);exit();
- }
- if ($_FILES[$key]['error'] > 0) {
- switch ($_FILES[$key]['error']) {
- case 1:
- $error['message'] = '文件大小超出了服务器的空间大小!';
- break;
- case 2:
- $error['message'] = '要上传的文件大小超出浏览器限制!';
- break;
- case 3:
- $error['message'] = '文件只有部分被上传!';
- break;
- case 4:
- $error['message'] = '没有找到要上传的文件!';
- break;
- case 5:
- $error['message'] = '服务器临时文件夹丢失!';
- break;
- case 6:
- $error['message'] = '文件写入到临时文件夹出错!';
- break;
- }
- echo json_encode($error);exit();
- }
- // 保存上传文件至服务器
- $extName = substr($_FILES[$key]['name'],strrpos($_FILES[$key]['name'],'.'));
- $fileName=uniqid().$extName;
- $oldFileName=$_FILES[$key]['name'];
- $path="upload/tmpDir/notification/";
- if (!file_exists($path)) {
- mkdir($path, 0777, true);
- }
- $filePath = $path . $fileName;
- if (!move_uploaded_file($val["tmp_name"], $filePath)) {
- $error['message'] = '保存Pdf文件失败!';
- echo json_encode($error);
- exit();
- }
- }
- $error['success'] = 1;
- $error['message'] = '上传文件成功!';
- $error['url'] = $filePath;
- $error['file_name'] = $oldFileName;
- echo json_encode($error);exit();
- }
- public function actionDownload()
- {
- $url = Req::get('url');
- $title = Req::get('title');
- if (empty($url) ) {
- return false;
- }
- header('content-type:application/octet-stream');
- header('content-disposition:attachment; filename='.get_basename($title));
- header('content-length:'.filesize($url));
- readfile($url);
- }
- }
|