SystemNoticeLogDao.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\BaseModel;
  14. use app\common\model\system\notice\SystemNoticeLog;
  15. /**
  16. * Class SystemNoticeLogDao
  17. * @package app\common\dao\system\notice
  18. * @author xaboy
  19. * @day 2020/11/6
  20. */
  21. class SystemNoticeLogDao extends BaseDao
  22. {
  23. /**
  24. * @return string
  25. * @author xaboy
  26. * @day 2020/11/6
  27. */
  28. protected function getModel(): string
  29. {
  30. return SystemNoticeLog::class;
  31. }
  32. /**
  33. * @param $id
  34. * @param $merId
  35. * @return int
  36. * @throws \think\db\exception\DbException
  37. * @author xaboy
  38. * @day 2020/11/6
  39. */
  40. public function read($id, $merId)
  41. {
  42. return SystemNoticeLog::getDB()->where('notice_log_id', $id)->where('mer_id', $merId)->update(['is_read' => 1, 'read_time' => date('Y-m-d H:i:s')]);
  43. }
  44. public function unreadCount($merId)
  45. {
  46. return SystemNoticeLog::getDB()->where('mer_id', $merId)->where('is_read', 0)->count();
  47. }
  48. /**
  49. * @param $id
  50. * @param $merId
  51. * @return int
  52. * @throws \think\db\exception\DbException
  53. * @author xaboy
  54. * @day 2020/11/6
  55. */
  56. public function del($id, $merId)
  57. {
  58. return SystemNoticeLog::getDB()->where('notice_log_id', $id)->where('mer_id', $merId)->delete();
  59. }
  60. public function search(array $where)
  61. {
  62. return SystemNoticeLog::getDB()->alias('A')->join('SystemNotice B', 'A.notice_id = B.notice_id')->where('mer_id', $where['mer_id'])->when(isset($where['is_read']) && $where['is_read'] !== '', function ($query) use ($where) {
  63. $query->where('A.is_read', intval($where['is_read']));
  64. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  65. getModelTime($query, $where['date'], 'B.create_time');
  66. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  67. $query->whereLike('B.notice_title|B.notice_content', "%{$where['keyword']}%");
  68. })->where('A.is_del', 0);
  69. }
  70. }