diff --git a/app/AdminAgent/Controllers/WorkorderController.php b/app/AdminAgent/Controllers/WorkorderController.php
index 5cc6aba..7167cba 100755
--- a/app/AdminAgent/Controllers/WorkorderController.php
+++ b/app/AdminAgent/Controllers/WorkorderController.php
@@ -365,12 +365,7 @@ class WorkorderController extends AdminController
public function checkUnread()
{
- if (\request('badge', '')) {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0], true);
- } else {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0]);
- }
-
+ return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0]);
}
}
diff --git a/app/AdminGuide/Controllers/WorkorderController.php b/app/AdminGuide/Controllers/WorkorderController.php
index 994b987..1fb897e 100755
--- a/app/AdminGuide/Controllers/WorkorderController.php
+++ b/app/AdminGuide/Controllers/WorkorderController.php
@@ -328,10 +328,6 @@ class WorkorderController extends AdminController
public function checkUnread()
{
- if (\request('badge', '')) {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2], true);
- } else {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2]);
- }
+ return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2]);
}
}
diff --git a/app/AdminSupplier/Controllers/WorkorderController.php b/app/AdminSupplier/Controllers/WorkorderController.php
index 30c4867..1ed4a43 100755
--- a/app/AdminSupplier/Controllers/WorkorderController.php
+++ b/app/AdminSupplier/Controllers/WorkorderController.php
@@ -330,10 +330,6 @@ class WorkorderController extends AdminController
public function checkUnread()
{
- if (\request('badge', '')) {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1], true);
- } else {
- return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1]);
- }
+ return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1]);
}
}
diff --git a/app/Service/Admin/GlobalNoticeService.php b/app/Service/Admin/GlobalNoticeService.php
index e265145..aeb778e 100644
--- a/app/Service/Admin/GlobalNoticeService.php
+++ b/app/Service/Admin/GlobalNoticeService.php
@@ -15,7 +15,7 @@ use Illuminate\Support\Facades\DB;
*/
class GlobalNoticeService
{
- public function unreadWOrder($pointType, $isBadge = false)
+ public function unreadWOrder($pointType)
{
$cacheNotice = Cache::get('w_order_notice', '[]');
@@ -27,19 +27,19 @@ class GlobalNoticeService
$query->where('point_id',Admin::user()->id)
->where('point_type',$pointType);
})
- ->where('is_read', 0)
- ->whereIn('id', $cacheNoticeIds);
+ ->where('is_read', 0);
- if ($isBadge === true) {
- return $builder->count();
- }
+ $count = $builder->count();
- $res = $builder->pluck('id')
+ $res = $builder
+ ->whereIn('id', $cacheNoticeIds)
+ ->pluck('id')
->toArray();
$cacheNoticeIds = array_diff($cacheNoticeIds, $res);
Cache::forever('w_order_notice', json_encode($cacheNoticeIds));
- return empty($res) ? 0 : 1;
+ $notice = empty($res) ? 0 : 1;
+ return json_encode(['notice' => $notice, 'badge' => $count]);
}
public function cacheWOrderNotice($id)
diff --git a/public/js/workorder-notice.js b/public/js/workorder-notice.js
index 33379ac..bc34a18 100644
--- a/public/js/workorder-notice.js
+++ b/public/js/workorder-notice.js
@@ -4,9 +4,13 @@ const workordertimer = setInterval(function () {
url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice',
type: 'POST',
data: {},
- dataType: 'text',
+ dataType: 'json',
success: function (res) {
- if (res == true) {
+
+ let notice = res.notice ? res.notice : '';
+ let badge = res.badge ? res.badge : '';
+
+ if (notice == 1) {
Dcat.info("你有新的工单信息 [前往查看]", '新消息提醒', {
closeButton: true,
escapeHtml: false,
@@ -19,21 +23,10 @@ const workordertimer = setInterval(function () {
}
})
}
- },
- error: function (error) {
- }
- });
-
- $.ajax({
- url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice',
- type: 'POST',
- data: {badge: 1},
- dataType: 'text',
- success: function (res) {
- if (res > 0) {
+ if (badge > 0) {
if ($('a[href*="workorder_item"] p .workorder_badge').length > 0) {
- $('a[href*="workorder_item"] p .workorder_badge').text(res);
+ $('a[href*="workorder_item"] p .workorder_badge').text(badge);
} else {
$('a[href*="workorder_item"] p').append(''+res+'');
+ '">'+badge+'');
}
if ($('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p .workorder_badge').length > 0) {
- $('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p .workorder_badge').text(res);
+ $('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p .workorder_badge').text(badge);
} else {
$('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p').append('' + res + '');
+ '">' + badge + '');
}
+ } else {
+ $('a[href*="workorder_item"] p .workorder_badge').remove()
+ $('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p .workorder_badge').remove()
}
},
error: function (error) {
@@ -70,4 +66,4 @@ const workordertimer = setInterval(function () {
}
});
-}, 1000);
+}, 5000);