diff --git a/app/AdminAgent/Controllers/WorkorderController.php b/app/AdminAgent/Controllers/WorkorderController.php index fa26c8f..ece73bb 100755 --- a/app/AdminAgent/Controllers/WorkorderController.php +++ b/app/AdminAgent/Controllers/WorkorderController.php @@ -37,7 +37,9 @@ class WorkorderController extends AdminController $workorder = \App\Models\Workorder::query() ->with(['point','publisher']) ->withCount(['items' => function($query) { - $query->where('is_read', 0); + $query->where('is_read', 0) + ->where('point_id',Admin::user()->id) + ->where('point_type',DemandTraits::$col[0]); }]) ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]]) ->orWhere(function ($query) { @@ -363,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 8cb2ae1..f1ae3aa 100755 --- a/app/AdminGuide/Controllers/WorkorderController.php +++ b/app/AdminGuide/Controllers/WorkorderController.php @@ -37,7 +37,9 @@ class WorkorderController extends AdminController $workorder = \App\Models\Workorder::query() ->with(['point','publisher']) ->withCount(['items' => function($query) { - $query->where('is_read', 0); + $query->where('is_read', 0) + ->where('point_id',Admin::user()->id) + ->where('point_type',DemandTraits::$col[2]); }]) ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]]) ->orWhere(function ($query) { @@ -326,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 1f2f2b3..ec8e996 100755 --- a/app/AdminSupplier/Controllers/WorkorderController.php +++ b/app/AdminSupplier/Controllers/WorkorderController.php @@ -35,6 +35,11 @@ class WorkorderController extends AdminController $workorder = \App\Models\Workorder::query() ->with(['point','publisher']) + ->withCount(['items' => function($query) { + $query->where('is_read', 0) + ->where('point_id',Admin::user()->id) + ->where('point_type',DemandTraits::$col[1]); + }]) ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[1]]) ->orWhere(function ($query) { $query->where('point_id',Admin::user()->id) @@ -325,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/guide-index.blade.php b/resources/views/admin/pages/guide-index.blade.php index 61c7cb2..37d3a97 100644 --- a/resources/views/admin/pages/guide-index.blade.php +++ b/resources/views/admin/pages/guide-index.blade.php @@ -156,7 +156,7 @@