AlarmReport.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace catchAdmin\alarm\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use catchAdmin\alarm\model\get\AlarmReportGet;
  6. use think\facade\Db;
  7. class AlarmReport extends Model
  8. {
  9. // 表名
  10. public $name = 'alarm_report';
  11. use DataRangScopeTrait;
  12. use AlarmReportGet;
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. // 卡号
  17. 'device_number',
  18. // 告警时间
  19. 'alarm_time',
  20. // 基站Code
  21. 'station_code',
  22. // 告警地址
  23. 'address',
  24. //是否已读,
  25. 'is_read',
  26. // 学生id
  27. 'student_id',
  28. // 创建人ID
  29. 'creator_id',
  30. // 创建时间
  31. 'created_at',
  32. // 更新时间
  33. 'updated_at',
  34. // 软删除
  35. 'deleted_at',
  36. // 围栏id
  37. 'fence_id',
  38. // 告警裂隙
  39. 'alarm_type',
  40. // 经度
  41. 'longitude',
  42. // 纬度
  43. 'latitude',
  44. );
  45. public function getList()
  46. {
  47. return $this->dataRange()
  48. ->catchSearch()
  49. ->append(['alarm_type_name','alarm_time_str','realname','sent_result'])
  50. ->order($this->aliasField('id'), 'desc')
  51. ->paginate();
  52. }
  53. /**
  54. * 详情
  55. */
  56. public function getDetail($id)
  57. {
  58. // 告警信息
  59. $alarm_info = $this->where('id', $id)
  60. ->append(['alarm_type_name','realname'])
  61. ->findOrEmpty();
  62. if ($alarm_info->isEmpty()) {
  63. return [];
  64. }
  65. return $alarm_info;
  66. }
  67. /**
  68. * 总增长趋势
  69. */
  70. public function getTotalGrowthCountByDate($date)
  71. {
  72. return $this->dataRange()
  73. ->field('alarm_type,count(*) as count')
  74. ->catchSearch()
  75. ->whereBetweenTime('alarm_time', 0, $date .' 23:59:59')
  76. ->group('alarm_type')
  77. ->select();
  78. }
  79. /**
  80. * 学号
  81. */
  82. public function searchDeviceNumberAttr($query, $value, $data)
  83. {
  84. return $query->where('device_number', 'like', '%'. $value . '%');
  85. }
  86. /**
  87. * 学校
  88. */
  89. public function searchIsReadAttr($query, $value, $data)
  90. {
  91. return $query->where('is_read', $value);
  92. }
  93. /**
  94. * 围栏id
  95. */
  96. public function searchFenceIdAttr($query, $value, $data)
  97. {
  98. return $query->where('fence_id', $value);
  99. }
  100. /**
  101. * 告警类型
  102. */
  103. public function searchAlarmTypeAttr($query, $value, $data)
  104. {
  105. return $query->where('alarm_type', $value);
  106. }
  107. }