SystemNoticeLogDao.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\common\dao\system\notice;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\BaseModel;
  5. use app\common\model\system\notice\SystemNoticeLog;
  6. /**
  7. * Class SystemNoticeLogDao
  8. * @package app\common\dao\system\notice
  9. * @author xaboy
  10. * @day 2020/11/6
  11. */
  12. class SystemNoticeLogDao extends BaseDao
  13. {
  14. /**
  15. * @return string
  16. * @author xaboy
  17. * @day 2020/11/6
  18. */
  19. protected function getModel(): string
  20. {
  21. return SystemNoticeLog::class;
  22. }
  23. /**
  24. * @param $id
  25. * @param $merId
  26. * @return int
  27. * @throws \think\db\exception\DbException
  28. * @author xaboy
  29. * @day 2020/11/6
  30. */
  31. public function read($id, $merId)
  32. {
  33. 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')]);
  34. }
  35. public function unreadCount($merId)
  36. {
  37. return SystemNoticeLog::getDB()->where('mer_id', $merId)->where('is_read', 0)->count();
  38. }
  39. /**
  40. * @param $id
  41. * @param $merId
  42. * @return int
  43. * @throws \think\db\exception\DbException
  44. * @author xaboy
  45. * @day 2020/11/6
  46. */
  47. public function del($id, $merId)
  48. {
  49. return SystemNoticeLog::getDB()->where('notice_log_id', $id)->where('mer_id', $merId)->delete();
  50. }
  51. public function search(array $where)
  52. {
  53. 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) {
  54. $query->where('A.is_read', intval($where['is_read']));
  55. })->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  56. getModelTime($query, $where['date'], 'B.create_time');
  57. })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
  58. $query->whereLike('B.notice_title|B.notice_content', "%{$where['keyword']}%");
  59. })->where('A.is_del', 0);
  60. }
  61. }