From ff17ef3f2faf00ba8a4374a3f9935c067175238c Mon Sep 17 00:00:00 2001 From: shuixiang Date: Sat, 11 Sep 2021 11:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=8F=E7=BA=A2=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WorkorderController.php | 8 +++- .../Controllers/WorkorderController.php | 6 ++- .../Controllers/WorkorderController.php | 6 ++- app/Service/Admin/GlobalNoticeService.php | 13 +++-- public/js/workorder-notice.js | 47 ++++++++++++++++++- .../views/admin/pages/workorder.blade.php | 35 +++++++++----- 6 files changed, 95 insertions(+), 20 deletions(-) diff --git a/app/AdminAgent/Controllers/WorkorderController.php b/app/AdminAgent/Controllers/WorkorderController.php index 7c789ca..ece73bb 100755 --- a/app/AdminAgent/Controllers/WorkorderController.php +++ b/app/AdminAgent/Controllers/WorkorderController.php @@ -365,6 +365,12 @@ class WorkorderController extends AdminController public function checkUnread() { - return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0]); + if (\request('badge', '')) { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0], true); + } else { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[0]); + } + } + } diff --git a/app/AdminGuide/Controllers/WorkorderController.php b/app/AdminGuide/Controllers/WorkorderController.php index 53fb9ba..f1ae3aa 100755 --- a/app/AdminGuide/Controllers/WorkorderController.php +++ b/app/AdminGuide/Controllers/WorkorderController.php @@ -328,6 +328,10 @@ class WorkorderController extends AdminController public function checkUnread() { - return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2]); + if (\request('badge', '')) { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2], true); + } else { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[2]); + } } } diff --git a/app/AdminSupplier/Controllers/WorkorderController.php b/app/AdminSupplier/Controllers/WorkorderController.php index 74c64d3..ec8e996 100755 --- a/app/AdminSupplier/Controllers/WorkorderController.php +++ b/app/AdminSupplier/Controllers/WorkorderController.php @@ -330,6 +330,10 @@ class WorkorderController extends AdminController public function checkUnread() { - return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1]); + if (\request('badge', '')) { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1], true); + } else { + return (new GlobalNoticeService())->unreadWOrder(DemandTraits::$col[1]); + } } } diff --git a/app/Service/Admin/GlobalNoticeService.php b/app/Service/Admin/GlobalNoticeService.php index e673d32..e265145 100644 --- a/app/Service/Admin/GlobalNoticeService.php +++ b/app/Service/Admin/GlobalNoticeService.php @@ -15,21 +15,26 @@ use Illuminate\Support\Facades\DB; */ class GlobalNoticeService { - public function unreadWOrder($pointType) + public function unreadWOrder($pointType, $isBadge = false) { $cacheNotice = Cache::get('w_order_notice', '[]'); $cacheNoticeIds = json_decode($cacheNotice, true); - $res = WorkorderItem::query() + $builder = WorkorderItem::query() ->has('workorder') ->where(function ($query) use ($pointType) { $query->where('point_id',Admin::user()->id) ->where('point_type',$pointType); }) ->where('is_read', 0) - ->whereIn('id', $cacheNoticeIds) - ->pluck('id') + ->whereIn('id', $cacheNoticeIds); + + if ($isBadge === true) { + return $builder->count(); + } + + $res = $builder->pluck('id') ->toArray(); $cacheNoticeIds = array_diff($cacheNoticeIds, $res); diff --git a/public/js/workorder-notice.js b/public/js/workorder-notice.js index 378911b..33379ac 100644 --- a/public/js/workorder-notice.js +++ b/public/js/workorder-notice.js @@ -25,4 +25,49 @@ const workordertimer = setInterval(function () { } }); -}, 5000); + $.ajax({ + url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice', + type: 'POST', + data: {badge: 1}, + dataType: 'text', + success: function (res) { + if (res > 0) { + if ($('a[href*="workorder_item"] p .workorder_badge').length > 0) { + $('a[href*="workorder_item"] p .workorder_badge').text(res); + } else { + $('a[href*="workorder_item"] p').append(''+res+''); + } + + 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); + } else { + $('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p').append('' + res + ''); + } + } + }, + error: function (error) { + + } + }); + +}, 1000); diff --git a/resources/views/admin/pages/workorder.blade.php b/resources/views/admin/pages/workorder.blade.php index 4aa3007..8fdd5c2 100644 --- a/resources/views/admin/pages/workorder.blade.php +++ b/resources/views/admin/pages/workorder.blade.php @@ -1,20 +1,21 @@