SystemNoticeLog.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\controller\merchant\system\notice;
  12. use app\common\repositories\system\notice\SystemNoticeLogRepository;
  13. use crmeb\basic\BaseController;
  14. use think\App;
  15. /**
  16. * Class SystemNotice
  17. * @package app\controller\merchant\system\notice
  18. * @author xaboy
  19. * @day 2020/11/6
  20. */
  21. class SystemNoticeLog extends BaseController
  22. {
  23. /**
  24. * @var SystemNoticeLogRepository
  25. */
  26. protected $repository;
  27. /**
  28. * 构造函数
  29. *
  30. * @param App $app 应用实例
  31. * @param SystemNoticeLogRepository $repository 系统通知日志仓库实例
  32. */
  33. public function __construct(App $app, SystemNoticeLogRepository $repository)
  34. {
  35. parent::__construct($app);
  36. $this->repository = $repository;
  37. }
  38. /**
  39. * 获取系统通知列表
  40. *
  41. * @return \think\response\Json
  42. */
  43. public function lst()
  44. {
  45. // 获取分页参数
  46. [$page, $limit] = $this->getPage();
  47. // 获取查询条件
  48. $where = $this->request->params(['is_read', 'date', 'keyword']);
  49. // 添加商家ID条件
  50. $where['mer_id'] = $this->request->merId();
  51. // 调用仓库方法获取系统通知列表并返回JSON格式数据
  52. return app('json')->success($this->repository->getList($where, $page, $limit));
  53. }
  54. /**
  55. * 标记系统通知已读
  56. *
  57. * @param int $id 系统通知ID
  58. * @return \think\response\Json
  59. */
  60. public function read($id)
  61. {
  62. // 调用仓库方法标记系统通知已读
  63. $this->repository->read(intval($id), $this->request->merId());
  64. // 返回JSON格式数据
  65. return app('json')->success();
  66. }
  67. /**
  68. * 删除指定ID的数据
  69. *
  70. * @param int $id 要删除的数据ID
  71. * @return \Illuminate\Http\JsonResponse 返回JSON格式的成功响应
  72. */
  73. public function del($id)
  74. {
  75. // 调用repository的del方法删除指定ID的数据,并传入当前商家ID
  76. $this->repository->del(intval($id), $this->request->merId());
  77. // 返回JSON格式的成功响应
  78. return app('json')->success();
  79. }
  80. /**
  81. * 获取未读消息数量
  82. *
  83. * @return \Illuminate\Http\JsonResponse 返回JSON格式的成功响应,其中包含未读消息数量
  84. */
  85. public function unreadCount()
  86. {
  87. // 调用repository的unreadCount方法获取未读消息数量,并传入当前商家ID
  88. return app('json')->success(['count' => $this->repository->unreadCount($this->request->merId())]);
  89. }
  90. }