海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\Service\Admin;
  3. use App\Models\WorkorderItem;
  4. use App\Traits\DemandTraits;
  5. use Dcat\Admin\Admin;
  6. use Illuminate\Support\Facades\Cache;
  7. use Illuminate\Support\Facades\DB;
  8. /**
  9. * 全局通知-后台
  10. * Class GlobalNoticeService
  11. * @package App\Service
  12. */
  13. class GlobalNoticeService
  14. {
  15. public function unreadWOrder($pointType, $isBadge = false)
  16. {
  17. $cacheNotice = Cache::get('w_order_notice', '[]');
  18. $cacheNoticeIds = json_decode($cacheNotice, true);
  19. $builder = WorkorderItem::query()
  20. ->has('workorder')
  21. ->where(function ($query) use ($pointType) {
  22. $query->where('point_id',Admin::user()->id)
  23. ->where('point_type',$pointType);
  24. })
  25. ->where('is_read', 0)
  26. ->whereIn('id', $cacheNoticeIds);
  27. if ($isBadge === true) {
  28. return $builder->count();
  29. }
  30. $res = $builder->pluck('id')
  31. ->toArray();
  32. $cacheNoticeIds = array_diff($cacheNoticeIds, $res);
  33. Cache::forever('w_order_notice', json_encode($cacheNoticeIds));
  34. return empty($res) ? 0 : 1;
  35. }
  36. public function cacheWOrderNotice($id)
  37. {
  38. $cacheNotice = Cache::get('w_order_notice', '[]');
  39. $cacheNoticeIds = json_decode($cacheNotice, true);
  40. $cacheNoticeIds[] = $id;
  41. Cache::forever('w_order_notice', json_encode($cacheNoticeIds));
  42. }
  43. }