From ad11196aa88dda71232cf3ac5d9411d657bd2c49 Mon Sep 17 00:00:00 2001 From: shuixiang Date: Fri, 10 Sep 2021 18:49:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=8D=95=E5=86=85=E9=83=A8=E5=81=9A?= =?UTF-8?q?=E4=BA=86=E5=B7=B2=E8=AF=BB=E7=BA=A2=E7=82=B9=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=8C=E5=85=A8=E5=B1=80=E7=9A=84=E5=BE=85=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WorkorderController.php | 13 +++++++++++ app/AdminAgent/bootstrap.php | 2 ++ app/AdminAgent/routes.php | 6 +++++ .../Controllers/WorkorderController.php | 8 +++++++ app/AdminGuide/bootstrap.php | 2 ++ .../Controllers/WorkorderController.php | 5 +++++ app/AdminSupplier/bootstrap.php | 2 ++ public/js/workorder-notice.js | 22 +++++++++++++++++++ .../views/admin/pages/guide-index.blade.php | 14 +++++++----- resources/views/admin/pages/index.blade.php | 21 +++++++++++------- .../admin/pages/supplier-index.blade.php | 14 +++++++----- 11 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 public/js/workorder-notice.js diff --git a/app/AdminAgent/Controllers/WorkorderController.php b/app/AdminAgent/Controllers/WorkorderController.php index 901b488..ffa9f72 100755 --- a/app/AdminAgent/Controllers/WorkorderController.php +++ b/app/AdminAgent/Controllers/WorkorderController.php @@ -35,6 +35,9 @@ class WorkorderController extends AdminController $workorder = \App\Models\Workorder::query() ->with(['point','publisher']) + ->withCount(['items' => function($query) { + $query->where('is_read', 0); + }]) ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[0]]) ->orWhere(function ($query) { $query->where('point_id',Admin::user()->id) @@ -58,6 +61,7 @@ class WorkorderController extends AdminController 'content' => $v->title, 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '', 'last_message_time' => $item->created_at ?? '', + 'items_count' => $workorderId != $v->id ? $v->items_count : 0, ]; $userList [] = $arr; } @@ -75,10 +79,14 @@ class WorkorderController extends AdminController 'name' => $v->publisher->name, 'content' => $v->content, 'created_at_text' => $v->created_at, + 'is_read' => $v->is_read, ]; $msgList [] = $arr; } + // 更新已读未读,此处没有考虑性能代码解藕等问题 + WorkorderItem::query()->where('workorder_id',$workorderId)->update(['is_read' => 1]); + $data = [ 'user_list' => $userList, 'msg_list' => $msgList, @@ -298,4 +306,9 @@ class WorkorderController extends AdminController return $this->jsonSuccess($item); } + + public function checkUnread() + { + + } } diff --git a/app/AdminAgent/bootstrap.php b/app/AdminAgent/bootstrap.php index 20a5ab9..7681744 100644 --- a/app/AdminAgent/bootstrap.php +++ b/app/AdminAgent/bootstrap.php @@ -32,3 +32,5 @@ app('view')->prependNamespace('admin', resource_path('views/admin')); Filter::resolving(function (Filter $filter) { $filter->panel(); }); + +Admin::js('/js/workorder-notice.js'); diff --git a/app/AdminAgent/routes.php b/app/AdminAgent/routes.php index 08fd9c9..986b917 100644 --- a/app/AdminAgent/routes.php +++ b/app/AdminAgent/routes.php @@ -51,3 +51,9 @@ Route::group([ $router->any('workorder_item', 'WorkorderController@index'); }); +Route::group([ + 'namespace' => config('admin.route.namespace'), + 'middleware' => config('admin.route.middleware'), +], function (Router $router) { + $router->any('workorder_notice', 'WorkorderController@checkUnread'); +}); diff --git a/app/AdminGuide/Controllers/WorkorderController.php b/app/AdminGuide/Controllers/WorkorderController.php index 83b287b..d31b82b 100755 --- a/app/AdminGuide/Controllers/WorkorderController.php +++ b/app/AdminGuide/Controllers/WorkorderController.php @@ -35,6 +35,9 @@ class WorkorderController extends AdminController $workorder = \App\Models\Workorder::query() ->with(['point','publisher']) + ->withCount(['items' => function($query) { + $query->where('is_read', 0); + }]) ->where(['publisher_id' => Admin::user()->id,'publisher_type' => DemandTraits::$col[2]]) ->orWhere(function ($query) { $query->where('point_id',Admin::user()->id) @@ -58,6 +61,7 @@ class WorkorderController extends AdminController 'content' => $v->title, 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '', 'last_message_time' => $item->created_at ?? '', + 'items_count' => $workorderId != $v->id ? $v->items_count : 0, ]; $userList [] = $arr; } @@ -75,10 +79,14 @@ class WorkorderController extends AdminController 'name' => $v->publisher->name, 'content' => $v->content, 'created_at_text' => $v->created_at, + 'is_read' => $v->is_read, ]; $msgList [] = $arr; } + // 更新已读未读,此处没有考虑性能代码解藕等问题 + WorkorderItem::query()->where('workorder_id',$workorderId)->update(['is_read' => 1]); + $data = [ 'user_list' => $userList, 'msg_list' => $msgList, diff --git a/app/AdminGuide/bootstrap.php b/app/AdminGuide/bootstrap.php index 20a5ab9..7681744 100644 --- a/app/AdminGuide/bootstrap.php +++ b/app/AdminGuide/bootstrap.php @@ -32,3 +32,5 @@ app('view')->prependNamespace('admin', resource_path('views/admin')); Filter::resolving(function (Filter $filter) { $filter->panel(); }); + +Admin::js('/js/workorder-notice.js'); diff --git a/app/AdminSupplier/Controllers/WorkorderController.php b/app/AdminSupplier/Controllers/WorkorderController.php index c510f35..23740a1 100755 --- a/app/AdminSupplier/Controllers/WorkorderController.php +++ b/app/AdminSupplier/Controllers/WorkorderController.php @@ -57,6 +57,7 @@ class WorkorderController extends AdminController 'content' => $v->title, 'last_message' => $item ? ($item->type == 1 ? $item->content : '【 图片 】') : '', 'last_message_time' => $item->created_at ?? '', + 'items_count' => $workorderId != $v->id ? $v->items_count : 0, ]; $userList [] = $arr; } @@ -74,10 +75,14 @@ class WorkorderController extends AdminController 'name' => $v->publisher->name, 'content' => $v->content, 'created_at_text' => $v->created_at, + 'is_read' => $v->is_read, ]; $msgList [] = $arr; } + // 更新已读未读,此处没有考虑性能代码解藕等问题 + WorkorderItem::query()->where('workorder_id',$workorderId)->update(['is_read' => 1]); + $data = [ 'user_list' => $userList, 'msg_list' => $msgList, diff --git a/app/AdminSupplier/bootstrap.php b/app/AdminSupplier/bootstrap.php index a49cc21..515ed00 100644 --- a/app/AdminSupplier/bootstrap.php +++ b/app/AdminSupplier/bootstrap.php @@ -59,3 +59,5 @@ Filter::resolving(function (Filter $filter) { } $menu->add($items); });*/ + +Admin::js('/js/workorder-notice.js'); diff --git a/public/js/workorder-notice.js b/public/js/workorder-notice.js new file mode 100644 index 0000000..91c2ac4 --- /dev/null +++ b/public/js/workorder-notice.js @@ -0,0 +1,22 @@ +Dcat.ready(function () { + + // const workorderNoticeTimer = setInterval(function () { + // + // $.ajax({ + // url: '/workorder_notice', + // type: 'POST', + // data: {}, + // dataType: 'json', + // success: function (res) { + // Dcat.info('您有新的工单信息', null, { + // timeOut: 5000, // 5秒后自动消失 + // }); + // }, + // error: function (error) { + // + // } + // }); + // + // }, 2000); + +}); diff --git a/resources/views/admin/pages/guide-index.blade.php b/resources/views/admin/pages/guide-index.blade.php index 2907cb5..61c7cb2 100644 --- a/resources/views/admin/pages/guide-index.blade.php +++ b/resources/views/admin/pages/guide-index.blade.php @@ -63,11 +63,9 @@
{{$item['last_message_time']}}
- {{--@if($item['unread'] == true)--}} - {{--
--}} - {{--@else--}} - {{--
--}} - {{--@endif--}} + @if($item['items_count'] > 0) +
{{$item['items_count']}}
+ @endif @endforeach @endif @@ -108,6 +106,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif
@@ -133,6 +134,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif
diff --git a/resources/views/admin/pages/index.blade.php b/resources/views/admin/pages/index.blade.php index 9e3fb9a..597e4e4 100644 --- a/resources/views/admin/pages/index.blade.php +++ b/resources/views/admin/pages/index.blade.php @@ -29,10 +29,11 @@ .msg-list-content { color: gray; background-color: #f4f4f4; border-radius: 5px; padding: 2px 5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; } .msg-list-badge { position: absolute; right: 5px; top: 5px; - width: 10px; height: 10px; border-radius: 10px; + width: 20px; height: 20px; border-radius: 20px; line-height: 20px; + text-align: center; font-size: 12px; } - .background-red { background-color: red; } - .background-gray { background-color: gray; } + .background-red { color: white; background-color: red; } + .background-gray { color: white; background-color: gray; }
@@ -63,11 +64,9 @@
{{$item['last_message_time']}}
- {{--@if($item['unread'] == true)--}} - {{--
--}} - {{--@else--}} - {{--
--}} - {{--@endif--}} + @if($item['items_count'] > 0) +
{{$item['items_count']}}
+ @endif
@endforeach @endif @@ -108,6 +107,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif
@@ -133,6 +135,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif
diff --git a/resources/views/admin/pages/supplier-index.blade.php b/resources/views/admin/pages/supplier-index.blade.php index 7f92b4d..ba45ca2 100644 --- a/resources/views/admin/pages/supplier-index.blade.php +++ b/resources/views/admin/pages/supplier-index.blade.php @@ -63,11 +63,9 @@
{{$item['last_message_time']}}
- {{--@if($item['unread'] == true)--}} - {{--
--}} - {{--@else--}} - {{--
--}} - {{--@endif--}} + @if($item['items_count'] > 0) +
{{$item['items_count']}}
+ @endif @endforeach @endif @@ -108,6 +106,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif
@@ -133,6 +134,9 @@
{{$item['created_at_text']}} + @if($item['is_read'] == 0) + [ 新消息 ] + @endif