SysNoticeLog.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\model\sys;
  12. use app\dict\notice\NoticeDict;
  13. use app\dict\notice\NoticeTypeDict;
  14. use core\base\BaseModel;
  15. use think\db\Query;
  16. /**
  17. * 系统消息发送记录
  18. * Class SysMessageLog
  19. * @package app\model\sys
  20. */
  21. class SysNoticeLog extends BaseModel
  22. {
  23. /**
  24. * 数据表主键
  25. * @var string
  26. */
  27. protected $pk = 'id';
  28. /**
  29. * 模型名称
  30. * @var string
  31. */
  32. protected $name = 'sys_notice_log';
  33. protected $type = [
  34. 'send_time' => 'timestamp',
  35. ];
  36. // 设置json类型字段
  37. protected $json = ['params', 'content'];
  38. // 设置JSON数据返回数组
  39. protected $jsonAssoc = true;
  40. /**
  41. * 名称
  42. * @param $value
  43. * @param $data
  44. * @return string
  45. */
  46. public function getContentAttr($value, $data)
  47. {
  48. if ($value) {
  49. if (is_string($value)) {
  50. $temp = json_decode($value, true);
  51. }
  52. }
  53. return $temp ?? $value;
  54. }
  55. /**
  56. * 名称
  57. * @param $value
  58. * @param $data
  59. * @return string
  60. */
  61. public function getNameAttr($value, $data)
  62. {
  63. $name = '';
  64. if (!empty($data['key'])) {
  65. $temp = NoticeDict::getNotice()[$data['key']] ?? [];
  66. $name = $temp['name'] ?? '';
  67. }
  68. return $name;
  69. }
  70. /**
  71. * 名称
  72. * @param $value
  73. * @param $data
  74. * @return string
  75. */
  76. public function getNoticeTypeNameAttr($value, $data)
  77. {
  78. $name = '';
  79. if (!empty($data['notice_type'])) {
  80. $temp = NoticeTypeDict::getType()[$data['notice_type']] ?? [];
  81. $name = $temp['name'] ?? '';
  82. }
  83. return $name;
  84. }
  85. /**
  86. * 消息类型
  87. * @param $query
  88. * @param $value
  89. * @return void
  90. */
  91. public function searchKeyAttr($query, $value)
  92. {
  93. if ($value) {
  94. $query->where('key', $value);
  95. }
  96. }
  97. /**
  98. * 接收人
  99. * @param $query
  100. * @param $value
  101. * @return void
  102. */
  103. public function searchReceiverAttr($query, $value)
  104. {
  105. if ($value) {
  106. $query->where('receiver', $value);
  107. }
  108. }
  109. /**
  110. * 创建时间搜索器
  111. * @param Query $query
  112. * @param $value
  113. * @param $data
  114. */
  115. public function searchCreateTimeAttr(Query $query, $value, $data)
  116. {
  117. $start_time = empty($value[0]) ? 0 : strtotime($value[0]);
  118. $end_time = empty($value[1]) ? 0 : strtotime($value[1]);
  119. if ($start_time > 0 && $end_time > 0) {
  120. $query->whereBetweenTime('create_time', $start_time, $end_time);
  121. } else if ($start_time > 0 && $end_time == 0) {
  122. $query->where([['create_time', '>=', $start_time]]);
  123. } else if ($start_time == 0 && $end_time > 0) {
  124. $query->where([['create_time', '<=', $end_time]]);
  125. }
  126. }
  127. }