SystemNoticeDao.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system\notice;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\system\notice\SystemNotice;
  14. class SystemNoticeDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return SystemNotice::class;
  19. }
  20. /**
  21. * 根据条件搜索系统通知
  22. *
  23. * 本函数用于根据提供的条件搜索系统通知。支持的条件包括关键字和日期。
  24. * - 关键字搜索:通过关键词在通知标题和内容中进行模糊搜索。
  25. * - 日期搜索:根据指定的日期范围筛选通知。
  26. *
  27. * @param array $where 搜索条件数组,包含关键字(keyword)和日期(date)等条件。
  28. * @return \think\Paginator 返回搜索结果的分页对象,包含符合搜索条件的通知。
  29. */
  30. public function search(array $where)
  31. {
  32. // 从系统通知模型中获取数据库实例
  33. return SystemNotice::getDB()->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  34. // 如果提供了关键字,则在通知标题和内容中进行模糊搜索
  35. $query->whereLike('notice_title|notice_content', '%' . $where['keyword'] . '%');
  36. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  37. // 如果提供了日期,则根据日期进行筛选
  38. getModelTime($query, $where['date'], 'create_time');
  39. })->where('is_del', 0);
  40. }
  41. }