123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace catchAdmin\alarm\model;
- use catcher\base\CatchModel as Model;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use catchAdmin\alarm\model\get\AlarmReportGet;
- use think\facade\Db;
- class AlarmReport extends Model
- {
- // 表名
- public $name = 'alarm_report';
- use DataRangScopeTrait;
- use AlarmReportGet;
- // 数据库字段映射
- public $field = array(
- 'id',
- // 卡号
- 'device_number',
- // 告警时间
- 'alarm_time',
- // 基站Code
- 'station_code',
- // 告警地址
- 'address',
- //是否已读,
- 'is_read',
- // 学生id
- 'student_id',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- // 围栏id
- 'fence_id',
- // 告警裂隙
- 'alarm_type',
- // 经度
- 'longitude',
- // 纬度
- 'latitude',
- );
- public function getList()
- {
- return $this->dataRange()
- ->catchSearch()
- ->append(['alarm_type_name','alarm_time_str','realname','sent_result'])
- ->order($this->aliasField('id'), 'desc')
- ->paginate();
- }
- /**
- * 详情
- */
- public function getDetail($id)
- {
- // 告警信息
- $alarm_info = $this->where('id', $id)
- ->append(['alarm_type_name','realname'])
- ->findOrEmpty();
- if ($alarm_info->isEmpty()) {
- return [];
- }
- return $alarm_info;
- }
- /**
- * 总增长趋势
- */
- public function getTotalGrowthCountByDate($date)
- {
- return $this->dataRange()
- ->field('alarm_type,count(*) as count')
- ->catchSearch()
- ->whereBetweenTime('alarm_time', 0, $date .' 23:59:59')
- ->group('alarm_type')
- ->select();
- }
- /**
- * 学号
- */
- public function searchDeviceNumberAttr($query, $value, $data)
- {
- return $query->where('device_number', 'like', '%'. $value . '%');
- }
- /**
- * 学校
- */
- public function searchIsReadAttr($query, $value, $data)
- {
- return $query->where('is_read', $value);
- }
-
- /**
- * 围栏id
- */
- public function searchFenceIdAttr($query, $value, $data)
- {
- return $query->where('fence_id', $value);
- }
- /**
- * 告警类型
- */
- public function searchAlarmTypeAttr($query, $value, $data)
- {
- return $query->where('alarm_type', $value);
- }
- }
|