10 changed files with 262 additions and 43 deletions
			
			
		- 
					64app/AdminAgent/Controllers/WorkorderController.php
 - 
					7app/AdminAgent/routes.php
 - 
					57app/AdminGuide/Controllers/WorkorderController.php
 - 
					1app/AdminGuide/routes.php
 - 
					58app/AdminSupplier/Controllers/WorkorderController.php
 - 
					1app/AdminSupplier/routes.php
 - 
					47app/Service/Admin/GlobalNoticeService.php
 - 
					4database/migrations/2021_09_10_144727_update_workorder_table.php
 - 
					46public/js/workorder-notice.js
 - 
					20resources/views/admin/pages/workorder.blade.php
 
@ -0,0 +1,47 @@ | 
				
			|||
<?php | 
				
			|||
 | 
				
			|||
namespace App\Service\Admin; | 
				
			|||
 | 
				
			|||
use App\Models\WorkorderItem; | 
				
			|||
use App\Traits\DemandTraits; | 
				
			|||
use Dcat\Admin\Admin; | 
				
			|||
use Illuminate\Support\Facades\Cache; | 
				
			|||
use Illuminate\Support\Facades\DB; | 
				
			|||
 | 
				
			|||
/** | 
				
			|||
 * 全局通知-后台 | 
				
			|||
 * Class GlobalNoticeService | 
				
			|||
 * @package App\Service | 
				
			|||
 */ | 
				
			|||
class GlobalNoticeService | 
				
			|||
{ | 
				
			|||
	public function unreadWOrder($pointType) | 
				
			|||
	{ | 
				
			|||
 | 
				
			|||
		$cacheNotice = Cache::get('w_order_notice', '[]'); | 
				
			|||
		$cacheNoticeIds = json_decode($cacheNotice, true); | 
				
			|||
 | 
				
			|||
		$res = 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') | 
				
			|||
			->toArray(); | 
				
			|||
 | 
				
			|||
		$cacheNoticeIds = array_diff($cacheNoticeIds, $res); | 
				
			|||
		Cache::forever('w_order_notice', json_encode($cacheNoticeIds)); | 
				
			|||
		return empty($res) ? 0 : 1; | 
				
			|||
	} | 
				
			|||
 | 
				
			|||
	public function cacheWOrderNotice($id) | 
				
			|||
	{ | 
				
			|||
		$cacheNotice = Cache::get('w_order_notice', '[]'); | 
				
			|||
		$cacheNoticeIds = json_decode($cacheNotice, true); | 
				
			|||
		$cacheNoticeIds[] = $id; | 
				
			|||
		Cache::forever('w_order_notice', json_encode($cacheNoticeIds)); | 
				
			|||
	} | 
				
			|||
} | 
				
			|||
@ -1,22 +1,28 @@ | 
				
			|||
Dcat.ready(function () { | 
				
			|||
const workordertimer = setInterval(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);
 | 
				
			|||
	$.ajax({ | 
				
			|||
		url: '/'+window.location.pathname.split('/')[1]+'/workorder_notice', | 
				
			|||
		type: 'POST', | 
				
			|||
		data: {}, | 
				
			|||
		dataType: 'text', | 
				
			|||
		success: function (res) { | 
				
			|||
			if (res == true) { | 
				
			|||
				Dcat.info("你有新的工单信息 <a href='/"+window.location.pathname.split('/')[1]+"/workorder_item' target='_blank'>[前往查看]</a>", '新消息提醒', { | 
				
			|||
					closeButton: true, | 
				
			|||
					escapeHtml: false, | 
				
			|||
					timeOut: 10000, | 
				
			|||
					extendedTimeOut: 5000, | 
				
			|||
					onHidden: function () { | 
				
			|||
						if (window.location.pathname == '/'+window.location.pathname.split('/')[1]+'/workorder_item') { | 
				
			|||
							location.reload() | 
				
			|||
						} | 
				
			|||
					} | 
				
			|||
				}) | 
				
			|||
			} | 
				
			|||
		}, | 
				
			|||
		error: function (error) { | 
				
			|||
 | 
				
			|||
}); | 
				
			|||
		} | 
				
			|||
	}); | 
				
			|||
 | 
				
			|||
}, 5000); | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue