MessageSystemServices.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\services\system;
  13. use app\dao\system\MessageSystemDao;
  14. use app\services\BaseServices;
  15. use think\exception\ValidateException;
  16. /**
  17. *
  18. * Class MessageSystemServices
  19. * @package app\services\system
  20. * @method save(array $data) 保存数据
  21. * @method mixed saveAll(array $data) 批量保存数据
  22. * @method update($id, array $data, ?string $key = null) 修改数据
  23. *
  24. */
  25. class MessageSystemServices extends BaseServices
  26. {
  27. /**
  28. * SystemNotificationServices constructor.
  29. * @param MessageSystemDao $dao
  30. */
  31. public function __construct(MessageSystemDao $dao)
  32. {
  33. $this->dao = $dao;
  34. }
  35. /**
  36. * 站内信列表
  37. * @param $uid
  38. * @return array
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function getMessageSystemList($uid)
  44. {
  45. [$page, $limit] = $this->getPageValue();
  46. $where['is_del'] = 0;
  47. $where['uid'] = $uid;
  48. $list = $this->dao->getMessageList($where, '*', $page, $limit);
  49. $count = $this->dao->getCount($where);
  50. if (!$list) return ['list' => [], 'count' => 0];
  51. foreach ($list as &$item) {
  52. $item['add_time'] = time_tran($item['add_time']);
  53. }
  54. return ['list' => $list, 'count' => $count];
  55. }
  56. /**
  57. * 站内信详情
  58. * @param $where
  59. * @return array
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function getInfo($where)
  65. {
  66. $info = $this->dao->getOne($where);
  67. if (!$info || $info['is_del'] == 1) {
  68. throw new ValidateException('数据不存在');
  69. }
  70. $info = $info->toArray();
  71. if ($info['look'] == 0) {
  72. $this->update($info['id'], ['look' => 1]);
  73. }
  74. $info['add_time'] = time_tran($info['add_time']);
  75. return $info;
  76. }
  77. }