Browse Source

调整轮训

develop
shuixiang 4 years ago
parent
commit
154887166a
  1. 5
      app/AdminAgent/Controllers/WorkorderController.php
  2. 4
      app/AdminGuide/Controllers/WorkorderController.php
  3. 4
      app/AdminSupplier/Controllers/WorkorderController.php
  4. 16
      app/Service/Admin/GlobalNoticeService.php
  5. 34
      public/js/workorder-notice.js

5
app/AdminAgent/Controllers/WorkorderController.php

@ -365,12 +365,7 @@ class WorkorderController extends AdminController
public function checkUnread() 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]);
} }
}
} }

4
app/AdminGuide/Controllers/WorkorderController.php

@ -328,10 +328,6 @@ class WorkorderController extends AdminController
public function checkUnread() 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]);
} }
}
} }

4
app/AdminSupplier/Controllers/WorkorderController.php

@ -330,10 +330,6 @@ class WorkorderController extends AdminController
public function checkUnread() 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]);
} }
}
} }

16
app/Service/Admin/GlobalNoticeService.php

@ -15,7 +15,7 @@ use Illuminate\Support\Facades\DB;
*/ */
class GlobalNoticeService class GlobalNoticeService
{ {
public function unreadWOrder($pointType, $isBadge = false)
public function unreadWOrder($pointType)
{ {
$cacheNotice = Cache::get('w_order_notice', '[]'); $cacheNotice = Cache::get('w_order_notice', '[]');
@ -27,19 +27,19 @@ class GlobalNoticeService
$query->where('point_id',Admin::user()->id) $query->where('point_id',Admin::user()->id)
->where('point_type',$pointType); ->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(); ->toArray();
$cacheNoticeIds = array_diff($cacheNoticeIds, $res); $cacheNoticeIds = array_diff($cacheNoticeIds, $res);
Cache::forever('w_order_notice', json_encode($cacheNoticeIds)); 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) public function cacheWOrderNotice($id)

34
public/js/workorder-notice.js

@ -4,9 +4,13 @@ const workordertimer = setInterval(function () {
url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice', url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice',
type: 'POST', type: 'POST',
data: {}, data: {},
dataType: 'text',
dataType: 'json',
success: function (res) { success: function (res) {
if (res == true) {
let notice = res.notice ? res.notice : '';
let badge = res.badge ? res.badge : '';
if (notice == 1) {
Dcat.info("你有新的工单信息 <a href='/"+window.location.pathname.split('/')[1]+"/workorder_item' target='_blank'>[前往查看]</a>", '新消息提醒', { Dcat.info("你有新的工单信息 <a href='/"+window.location.pathname.split('/')[1]+"/workorder_item' target='_blank'>[前往查看]</a>", '新消息提醒', {
closeButton: true, closeButton: true,
escapeHtml: false, 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) { 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 { } else {
$('a[href*="workorder_item"] p').append('<span class="workorder_badge" style="' + $('a[href*="workorder_item"] p').append('<span class="workorder_badge" style="' +
'display: inline-block; ' + 'display: inline-block; ' +
@ -45,11 +38,11 @@ const workordertimer = setInterval(function () {
'font-size: 12px; ' + 'font-size: 12px; ' +
'background-color: red;' + 'background-color: red;' +
'color: white;' + 'color: white;' +
'">'+res+'</span>');
'">'+badge+'</span>');
} }
if ($('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p .workorder_badge').length > 0) { 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 { } else {
$('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p').append('<span class="workorder_badge" style="' + $('a[href*="workorder_item"]').parent().parent().parent(':not(.menu-open)').find('a[href="#"] p').append('<span class="workorder_badge" style="' +
'display: inline-block; ' + 'display: inline-block; ' +
@ -61,8 +54,11 @@ const workordertimer = setInterval(function () {
'font-size: 12px; ' + 'font-size: 12px; ' +
'background-color: red;' + 'background-color: red;' +
'color: white;' + 'color: white;' +
'">' + res + '</span>');
'">' + badge + '</span>');
} }
} 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) { error: function (error) {
@ -70,4 +66,4 @@ const workordertimer = setInterval(function () {
} }
}); });
}, 1000);
}, 5000);
Loading…
Cancel
Save