Procházet zdrojové kódy

新增后台新数据提醒

olym před 7 roky
rodič
revize
17bd1fd27e

binární
global/img/wen.png


+ 52 - 2
global/js/admin/admin.js

@@ -1,8 +1,13 @@
 var editor="";
 var editor2="";
 var art_editor;
+var notify = null;
+var isNotifyShowing = false;
+var isError = false;
 $(function() {
-	$("#addanswerkvip").click(function (){
+    Notification.requestPermission(function(status) {});
+
+    $("#addanswerkvip").click(function (){
 
 		if(!editor.hasContents()){ //此处以非空为例
 			alert("请输入内容");
@@ -18,9 +23,54 @@ $(function() {
 		}
 		
 	});
-})
 
+	// 轮询查找是否有未处理的审批
+    var permission = Notification.permission;
+    if (permission === 'granted') {
+        var interval = setInterval(checkNotify, 10000);
+        if (isError) {
+            clearInterval(interval);
+        }
 
+    }
+});
+
+/**
+ * 获取未审批数量
+ */
+function checkNotify() {
+	$.ajax({
+		url: '/examine_check',
+		type: 'get',
+		data: '',
+		dataType: 'json',
+		error: function() {
+            console.log('数据错误');
+            isError = true;
+		},
+		success: function(response) {
+		    var count = response.count;
+            count = parseInt(count);
+            if (count > 0 && !isNotifyShowing) {
+                notify = new Notification("你有"+ count +"条问答需要审批", {
+                    icon: '/global/img/wen.png',
+                    body: '点击本消息可跳转至审批页',
+                    silent: true
+                });
+                notify.onclick = function() {
+                    notify.close();
+                    window.location.href = '/index/main_examine_manage';
+                };
+                notify.onshow = function () {
+                    isNotifyShowing = true;
+                };
+                notify.onclose = function () {
+                    isNotifyShowing = false;
+                };
+            }
+		}
+	});
+}
 	
 
 function login_form() {

+ 1 - 0
protected/config/routes.conf.php

@@ -165,6 +165,7 @@ $route['*']['/index/main_category_update_manage'] = array('AdminController', 'ca
 $route['*']['/index/main_examine_manage'] = array('AdminController', 'examine_manage');
 $route['*']['/index/examine_clear'] = array('AdminController', 'examine_manage_clear');
 $route['*']['/examine_add/:id'] = array('AdminController', 'examine_add');
+$route['*']['/examine_check'] = array('AdminController', 'is_exist_unapproved');
 
 
 $route['*']['/index/admin_exit'] = array('AdminController', 'admin_user_exit');

+ 22 - 6
protected/controller/AdminController.php

@@ -75,7 +75,7 @@ class AdminController extends DooController {
 		$is_login = $client->zhsso_member_login ( $data ['name'], $data ['password'] );
 
 		$is_login = explode ( "\r", $is_login );
-		
+
 		if (is_numeric ( $is_login [0] )) {
 			if ($is_login [0] == USERNAME_ONFINE) {
 				
@@ -140,13 +140,13 @@ class AdminController extends DooController {
 	 */
 	function navon() {
 		$data ['now'] = 'use';
-		
+
 		$list=$this->adminlogic->get_examine_list();
-		
+
 		if(!empty($list)){
 			$this->menu ['navon'][4]='<a href="/index/main_examine_manage" target="main">审批问题 <b style="color:#f00;">'.count($list).'</b></a>';
 		}
-		
+
 		
 		$data ['li'] = $this->menu ['navon'];
 		
@@ -1364,13 +1364,13 @@ class AdminController extends DooController {
 	function examine_add(){
 		$idKey = $this->check_params ( "id" );
 		$data=$this->adminlogic->get_examine ($idKey);
-		
+
 		if(empty($data))
 			die('illegal request');
 		
 		$data ['category_id']=$data['cid'];
 		$id = $this->userlogic->add_question ( $data );
-		
+
 		if (empty($id)){//金钱不够 发送站内通知---暂停开发站内通知
 			//$this->send_email ( $data ['authorid'], "PAY_FORMONEY", $result, 0 );
 			/*			 
@@ -1385,6 +1385,22 @@ class AdminController extends DooController {
 		//$rs=$this->adminlogic->examine_add ($idKey);
 		
 	}
+
+	/**
+     * 轮询查询是否有待审批数据
+     *
+     * @return void
+	 */
+	function is_exist_unapproved() {
+        $count = $this->adminlogic->get_unapproved_num();
+        $response = array(
+            'error' => 0,
+            'count' => $count
+        );
+
+        echo json_encode($response);
+        exit();
+    }
 	
 	/**
 	 * 获取get或者POST值

+ 15 - 2
protected/logic/AdminLogic.php

@@ -33,7 +33,7 @@ class AdminLogic extends BaseLogic {
 	function get_examine_list() {
 		$list = $this->examinedao->get_examine_list ();
 		$list = $this->_format_question_data ( $list );
-		
+
 		Doo::loadClass ( 'XDeode' );
 		$XDeode = new XDeode ( 5 );
 		
@@ -58,7 +58,7 @@ class AdminLogic extends BaseLogic {
 		$idKey = $XDeode->decode ( $idKey );
 		if (! is_numeric ( $idKey ))
 			return array ();
-		
+
 		$list = $this->examinedao->get_examine ($idKey);
 		return $list;
 	}
@@ -92,6 +92,19 @@ class AdminLogic extends BaseLogic {
 	 */
 	protected function format_email_content($html_templete, $templete_name, $qid, $aid) {
 	}
+
+    /**
+     * 获取还未审批的数量
+     *
+     * @return int
+     */
+    function get_unapproved_num() {
+        $count = $this->examinedao->count(array(
+            'where' => 'isdelete = 0',
+        ));
+
+        return $count;
+    }
 }
 
 ?>

+ 0 - 1
protected/view/admin/welcome.html

@@ -5,7 +5,6 @@
 <link href="<?= WEB_SITE_GLOBAL ?>/img/admin/style.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="<?= WEB_SITE_GLOBAL ?>/js/jquery-1.7.1.min.js"></script>
 <script type="text/javascript" src="<?= WEB_SITE_GLOBAL ?>/js/admin/over.js"></script>
-<script type="text/javascript" src="<?= WEB_SITE_GLOBAL ?>/js/admin/admin.js"></script>
 </head>
 <body>
 <div class="main_content new_product">

+ 0 - 1
protected/viewc/admin/welcome.php

@@ -5,7 +5,6 @@
 <link href="<?php echo  WEB_SITE_GLOBAL  ?>/img/admin/style.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="<?php echo  WEB_SITE_GLOBAL  ?>/js/jquery-1.7.1.min.js"></script>
 <script type="text/javascript" src="<?php echo  WEB_SITE_GLOBAL  ?>/js/admin/over.js"></script>
-<script type="text/javascript" src="<?php echo  WEB_SITE_GLOBAL  ?>/js/admin/admin.js"></script>
 </head>
 <body>
 <div class="main_content new_product">