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='
'; $html.='

附件

'; foreach ($files as $file){ $html.='

'.$file['file_name'].'

'; } $html.='

注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!

'; $html.='
'; } $data['content']=str_replace("\r\n","
",$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='
'; $html.='

附件

'; foreach ($files as $file){ $html.='

'.$file['file_name'].'

'; } $html.='

注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!

'; $html.='
'; } $rs['content']=str_replace("\r\n","
",$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); } }