From 154887166a8a3f6dbd05700169bf890dcee6817e Mon Sep 17 00:00:00 2001 From: shuixiang Date: Sat, 11 Sep 2021 14:28:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BD=AE=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WorkorderController.php | 7 +--- .../Controllers/WorkorderController.php | 6 +--- .../Controllers/WorkorderController.php | 6 +--- app/Service/Admin/GlobalNoticeService.php | 16 ++++----- public/js/workorder-notice.js | 34 ++++++++----------- 5 files changed, 26 insertions(+), 43 deletions(-) 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);