NotificationController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: 刘红伟
  5. * QQ : 454303753
  6. * Date: 2018/3/7 0007
  7. * Time: 下午 14:37
  8. */
  9. class NotificationController extends Controller
  10. {
  11. public function actionIndex()
  12. {
  13. $start_time = Req::get("start_time");
  14. $end_time = Req::get("end_time");
  15. $mode = Req::get("mode");
  16. $_page = Req::get("page");
  17. $criteria = new CDbCriteria();
  18. if($start_time)
  19. {
  20. $criteria->addCondition('create_time>=:create_time');
  21. $criteria->params[':create_time'] = strtotime($start_time);
  22. }
  23. if(empty($_page))
  24. {
  25. $_page = 1;
  26. }
  27. if($end_time)
  28. {
  29. $criteria->addCondition('create_time<=:end_time');
  30. $criteria->params[':end_time'] = strtotime($end_time);
  31. }
  32. if($mode<0){
  33. $criteria->addCondition('mode=:mode');
  34. $criteria->params[':mode'] = 0;
  35. }
  36. if($mode>0){
  37. $criteria->addInCondition('mode',array(1,2));
  38. }
  39. $criteria->order = "create_time desc";
  40. $count = SNotificationModel::model()->count($criteria);
  41. $pager = new CPagination($count,10);
  42. $criteria->limit=$pager->getLimit();
  43. $criteria->offset=$pager->getOffset();
  44. $notification_data = SNotificationModel::model()->findAll($criteria);
  45. $data = array();
  46. $data['page'] = $pager;
  47. $data['start_time'] = $start_time;
  48. $data['end_time'] = $end_time;
  49. $data['_page'] = $_page;
  50. $data['page_total'] = $count;
  51. $data['mode'] = $mode;
  52. $data['list'] = $notification_data;
  53. $this->render("index",$data);
  54. }
  55. public function actionDel()
  56. {
  57. $n_id = Req::post('n_id');
  58. if($n_id)
  59. {
  60. $n_ids = explode(',',$n_id);
  61. $criteria = new CDbCriteria();
  62. $criteria->addInCondition('id',$n_ids);
  63. SNotificationModel::model()->deleteAll($criteria);
  64. echo json_encode(array('status'=>1));exit;
  65. }
  66. echo json_encode(array('status'=>0));exit;
  67. }
  68. public function actionAjax_exam_info()
  69. {
  70. $data = array();
  71. $exam_group_id = Req::post('exam_group_id');
  72. $n_id = Req::post('n_id');
  73. $mode = Req::post('mode');
  74. $teacher_data = array();
  75. $class_data = array();
  76. $class_name = array();
  77. $teacher_ids = array();
  78. $subject_id = 3;
  79. //更新已读
  80. if($n_id)
  81. {
  82. SNotificationModel::model()->updateAll(array('status'=>1,'update_time'=>time()),'id=:id',array(':id'=>$n_id));
  83. }
  84. if($mode>1){
  85. $notification = SNotificationModel::model()->find('id=:id',array(':id'=>$n_id));
  86. if($notification)
  87. {
  88. $data['mode'] = 2;
  89. $data['title'] = $notification->title;
  90. $data['create_time'] = date('Y-m-d',$notification->create_time);
  91. $data['alarm_level'] = $notification->alarm_level;
  92. $data['alarm_description'] = $notification->alarm_description;
  93. $data['school_name'] = $this->schoolInfo['school_name'];
  94. echo json_encode($data);exit;
  95. }
  96. }
  97. //获取本校所有老师信息
  98. $teachers = Teacher::model()->findAll();
  99. if($teachers){
  100. foreach ($teachers as $v)
  101. {
  102. $teacher_data[$v->teacher_id] = $v->teacher_name;
  103. }
  104. }
  105. //获取本学期班级信息
  106. $classes = ClassModel::model()->findAll('semester_id=:semester_id',array(':semester_id'=>$this->semesterId));
  107. if($classes)
  108. {
  109. foreach ($classes as $v)
  110. {
  111. $class_data[$v->class_id] = $v->class_name;
  112. }
  113. }
  114. //获取本次考试信息
  115. $exam_group = ExamGroup::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  116. if($exam_group)
  117. {
  118. $data['mark_type'] = $exam_group->mark_type;
  119. if(isset($teacher_data[$exam_group->teacher_id]))
  120. {
  121. $data['teacher_name'] = $teacher_data[$exam_group->teacher_id];
  122. }
  123. }
  124. //获取考试名称
  125. $exam = Exam::model()->find('exam_group_id=:exam_group_id',array(':exam_group_id'=>$exam_group_id));
  126. if($exam)
  127. {
  128. $data['exam_name'] = $exam->name;
  129. $data['exam_time'] = date('Y-m-d',$exam->create_time);
  130. $data['subject_id'] = $exam->subject_id;
  131. $subject_id = $exam->subject_id;
  132. }
  133. //获取通知信息
  134. $notification = SNotificationModel::model()->find('id=:id',array(':id'=>$n_id));
  135. if($notification)
  136. {
  137. $class_ids = explode(',',$notification->classids);
  138. foreach ($class_ids as $v)
  139. {
  140. if(isset($class_data[$v]))
  141. {
  142. $class_name[] = $class_data[$v];
  143. }
  144. }
  145. $teacher_name=array();
  146. if($exam_group&& isset($exam_group->mark_type)&&$exam_group->mark_type==4)
  147. {
  148. $criteria1 = new CDbCriteria();
  149. $criteria1->addInCondition('class_id',$class_ids);
  150. $teacher_class = TeacherToClass::model()->findAll($criteria1);
  151. if($teacher_class)
  152. {
  153. if(in_array($subject_id,$this->mathSubjectId)){
  154. $subject_id = 3;
  155. }
  156. foreach ($teacher_class as $v)
  157. {
  158. $teacher_ids[$v->teacher_id] = $v->teacher_id;
  159. }
  160. //
  161. $criteria = new CDbCriteria();
  162. $criteria->addInCondition('teacher_id',$teacher_ids);
  163. $criteria->addCondition('subjects=:subjects');
  164. $criteria->params[':subjects'] = $subject_id;
  165. $teacher_ids = Teacher::model()->findAll($criteria);
  166. if($teacher_ids){
  167. foreach ($teacher_ids as $val){
  168. $teacher_name[]=$val->teacher_name;
  169. }
  170. }
  171. }
  172. $data['teacher_name'] = join(',',$teacher_name);
  173. }
  174. $data['class_name'] = join(',',$class_name);
  175. $data['mode'] = 1;
  176. $count = SNotificationModel::model()->count('status=:status',array(':status'=>0));
  177. $data['count'] = $count;
  178. }
  179. echo json_encode($data);exit;
  180. }
  181. //2021新版客户端通知
  182. public function actionList(){
  183. $title = Req::get("title");
  184. $_page = Req::get("page");
  185. $criteria = new CDbCriteria();
  186. if(empty($_page))
  187. {
  188. $_page = 1;
  189. }
  190. if($title){
  191. $criteria->addCondition("title like :title");
  192. $criteria->params[':title'] = '%'.$title.'%';
  193. }
  194. if(!isset(Yii::app()->session['testFlag']) || (Yii::app()->session['testFlag']!=1)){
  195. $criteria->addCondition("status =2");
  196. }
  197. $criteria->order = "create_time desc";
  198. $count = ClientNotifyModel::model()->count($criteria);
  199. $pager = new CPagination($count,10);
  200. $criteria->limit=$pager->getLimit();
  201. $criteria->offset=$pager->getOffset();
  202. $notification_data = ClientNotifyModel::model()->findAll($criteria);
  203. $data = array();
  204. $data['page'] = $pager;
  205. $data['_page'] = $_page;
  206. $data['page_total'] = $count;
  207. $data['title'] = $title;
  208. $data['list'] = $notification_data;
  209. $this->render("list",$data);
  210. }
  211. public function actionPush(){
  212. $id = Req::post("id");
  213. $result=array();
  214. $result['status']=0;
  215. if(!$id){
  216. $result['msg']='id不能为空';
  217. exit(json_encode($result));
  218. }
  219. $criteria = new CDbCriteria();
  220. $criteria->addCondition('id=:id');
  221. $criteria->params[':id'] = $id;
  222. $rs = ClientNotifyModel::model()->updateAll(array('status'=>2,'update_time'=>time()),$criteria);
  223. if($rs){
  224. $result['status']=1;
  225. }
  226. exit(json_encode($result));
  227. }
  228. public function actionDeleteNo(){
  229. $id = Req::post('id');
  230. $result['status']=0;
  231. $criteria = new CDbCriteria();
  232. $criteria->addCondition('id=:id');
  233. $criteria->params[':id'] = $id;
  234. //ClientNotifyModel::model()->deleteAll($criteria);
  235. $rs = ClientNotifyModel::model()->updateAll(array('status'=>0,'update_time'=>time()),$criteria);
  236. if($rs){
  237. $result['status']=1;
  238. }
  239. exit(json_encode($result));
  240. }
  241. public function actionEdit(){
  242. if (Yii::app()->request->getIsPostRequest()){
  243. $title=Req::post('title');
  244. $content=Req::post('content');
  245. $eid=Req::post('eid');
  246. $files=Req::post('files');
  247. $time=time();
  248. if($eid){
  249. $criteria = new CDbCriteria();
  250. $criteria->addCondition('id=:id');
  251. $criteria->params[':id'] = $eid;
  252. $rs = ClientNotifyModel::model()->updateAll(array('title'=>$title,'content'=>$content,'update_time'=>time(),'file_list'=>$files),$criteria);
  253. if($rs){
  254. Yii::app()->jump->error('保存成功',Yii::app()->createUrl('notification/list'));
  255. }else{
  256. Yii::app()->jump->error('保存失败',Yii::app()->createUrl('notification/edit'));
  257. }
  258. }else{
  259. $notifyModel=new ClientNotifyModel();
  260. $notifyModel->title=$title;
  261. $notifyModel->content=$content;
  262. $notifyModel->create_time=$time;
  263. $notifyModel->status=1;
  264. $notifyModel->update_time=$time;
  265. $notifyModel->file_list=$files;
  266. if($notifyModel->save()){
  267. Yii::app()->jump->error('保存成功',Yii::app()->createUrl('notification/list'));
  268. }else{
  269. Yii::app()->jump->error('保存失败',Yii::app()->createUrl('notification/edit'));
  270. }
  271. }
  272. }
  273. $id=Req::get('id');
  274. $data=array();
  275. if($id){
  276. $rs=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
  277. $files=json_decode(str_replace("&quot;",'"',$rs['file_list']),true);
  278. $data=array(
  279. 'title'=>$rs['title'],
  280. 'content'=>$rs['content'],
  281. 'id'=>$rs['id'],
  282. 'file_list'=>$files
  283. );
  284. }
  285. $this->render("edit",$data);
  286. }
  287. public function actionAjaxGetData(){
  288. $id=Req::post('id');
  289. $result['status']=0;
  290. if(!$id){
  291. exit(json_encode($result));
  292. }
  293. $data=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
  294. $files=json_decode(str_replace("&quot;",'"',$data['file_list']),true);
  295. $html='';
  296. if($files){
  297. $html='<div class="atta_list">';
  298. $html.='<p><b>附件</b></p>';
  299. foreach ($files as $file){
  300. $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>';
  301. }
  302. $html.='<p class="red-tips"> 注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!</p>';
  303. $html.='</div>';
  304. }
  305. $data['content']=str_replace("\r\n","<br>",$data['content']);
  306. $notify=array(
  307. 'title'=>$data['title'],
  308. 'content'=>$data['content'],
  309. 'files'=>$html
  310. );
  311. $result['status']=1;
  312. $result['data']=$notify;
  313. exit(json_encode($result));
  314. }
  315. public function actionView(){
  316. $id=Req::get('id');
  317. $data=array();
  318. if($id){
  319. $rs=ClientNotifyModel::model()->find("id=:id",array(":id"=>$id));
  320. $files=json_decode(str_replace("&quot;",'"',$rs['file_list']),true);
  321. $html='';
  322. if($files){
  323. $html='<div class="atta_list">';
  324. $html.='<p><b>附件</b></p>';
  325. foreach ($files as $file){
  326. $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>';
  327. }
  328. $html.='<p class="red-tips"> 注:通知发布一个月后,文档将不支持下载,请及时下载所需文档!</p>';
  329. $html.='</div>';
  330. }
  331. $rs['content']=str_replace("\r\n","<br>",$rs['content']);
  332. $data=array(
  333. 'title'=>$rs['title'],
  334. 'content'=>$rs['content'],
  335. 'id'=>$rs['id'],
  336. 'files'=>$html
  337. );
  338. }
  339. $this->renderPartial("view",$data);
  340. }
  341. public function actionUpload(){
  342. $error['success'] = 0;
  343. $fileUrlArr=array();
  344. $file_max_size = 11 * 1024 * 1024;
  345. foreach ($_FILES as $key =>$val){
  346. if ($_FILES[$key]["size"] > $file_max_size) {
  347. $error['message'] = '文件超过最大限制,最大为10M';
  348. echo json_encode($error);exit();
  349. }
  350. if ($_FILES[$key]['error'] > 0) {
  351. switch ($_FILES[$key]['error']) {
  352. case 1:
  353. $error['message'] = '文件大小超出了服务器的空间大小!';
  354. break;
  355. case 2:
  356. $error['message'] = '要上传的文件大小超出浏览器限制!';
  357. break;
  358. case 3:
  359. $error['message'] = '文件只有部分被上传!';
  360. break;
  361. case 4:
  362. $error['message'] = '没有找到要上传的文件!';
  363. break;
  364. case 5:
  365. $error['message'] = '服务器临时文件夹丢失!';
  366. break;
  367. case 6:
  368. $error['message'] = '文件写入到临时文件夹出错!';
  369. break;
  370. }
  371. echo json_encode($error);exit();
  372. }
  373. // 保存上传文件至服务器
  374. $extName = substr($_FILES[$key]['name'],strrpos($_FILES[$key]['name'],'.'));
  375. $fileName=uniqid().$extName;
  376. $oldFileName=$_FILES[$key]['name'];
  377. $path="upload/tmpDir/notification/";
  378. if (!file_exists($path)) {
  379. mkdir($path, 0777, true);
  380. }
  381. $filePath = $path . $fileName;
  382. if (!move_uploaded_file($val["tmp_name"], $filePath)) {
  383. $error['message'] = '保存Pdf文件失败!';
  384. echo json_encode($error);
  385. exit();
  386. }
  387. }
  388. $error['success'] = 1;
  389. $error['message'] = '上传文件成功!';
  390. $error['url'] = $filePath;
  391. $error['file_name'] = $oldFileName;
  392. echo json_encode($error);exit();
  393. }
  394. public function actionDownload()
  395. {
  396. $url = Req::get('url');
  397. $title = Req::get('title');
  398. if (empty($url) ) {
  399. return false;
  400. }
  401. header('content-type:application/octet-stream');
  402. header('content-disposition:attachment; filename='.get_basename($title));
  403. header('content-length:'.filesize($url));
  404. readfile($url);
  405. }
  406. }