123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- namespace catchAdmin\hydraulic\model;
- use catchAdmin\api\Listen;
- use catcher\base\CatchModel as Model;
- use \think\facade\Db;
- use catchAdmin\system\model\SysDictData;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- class Hydraulic extends Model
- {
- use DataRangScopeTrait;
- // 表名
- public $name = 'hydraulic';
- // 数据库字段映射
- public $field = array(
- 'id',
- // 编号
- 'number',
- // 所属部门
- 'department_id',
- // 告警状态
- 'alarm_state',
- // 网络状态
- 'net_state',
- // //扭矩
- // 'torque',
- // //压力
- // 'stress',
- // //螺栓尺寸
- // 'bolts_size',
- // //螺栓数量
- // 'bolts_num',
- //备注
- 'remark',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- 'longitude',
- 'latitude',
- 'max_pressure',
- 'min_pressure',
- 'imei',
- 'sim_card',
- 'effective_time',
- 'effective_period',
- //设备的id
- 'eq_id'
- );
- /**
- * 获取列表
- */
- public function getList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['depart_name', 'alarm_state_text', 'creator_user', 'model_name'])
- ->order($this->aliasField('id'), 'desc')
- ->paginate();
- return $res;
- }
- /**
- * 获取轨迹地图列表定位不分页 只查询有定位时间的
- */
- public function queryLocationList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->select();
- return $res;
- }
- /**
- * 获取导入用户(文本)
- */
- public function getCreatorUserAttr($value)
- {
- $uid = $this->creator_id;
- return Db::table('users')->where('id', $uid)->value('username') ?: '';
- }
- /**
- * 使用状态
- */
- public function getIsUsedAttr($value)
- {
- if ($value != 0) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * 获取部门名称(文本)
- */
- public function getDepartNameAttr()
- {
- $id = $this->getData('department_id');
- return Db::table('departments')->where('id', $id)->value('department_name');
- }
- /**
- * 获取类型名称
- */
- public function getModelAttr($value)
- {
- return (int)$value;
- }
- /**
- * 校验日期
- */
- public function getEffectiveTimeAttr($value)
- {
- if ($value) {
- return date('Y-m-d H:i:s', $value);
- } else {
- return '-';
- }
- }
- /**
- * 校验日期
- */
- public function getCheckTimeAttr($value)
- {
- if ($value) {
- return date('Y-m-d H:i:s', $value);
- } else {
- return '-';
- }
- }
- /**
- * 获取告警状态文本
- */
- public function getAlarmStateTextAttr($value)
- {
- $alarm_state = $this->getData('alarm_state');
- return $alarm_state ? '告警' : '正常';
- }
- /**
- * 根据部门搜索
- */
- public function searchDepartmentIdAttr($query, $value, $data)
- {
- if ($value) {
- $id = end($value);
- return $query->where('department_id', '=', $id);
- }
- }
- /**
- * 根据number搜索
- */
- public function searchNumberAttr($query, $value, $data)
- {
- return $query->where('number', 'like', '%' . $value . '%');
- }
- /**
- * 根据name搜索
- */
- public function searchNameAttr($query, $value, $data)
- {
- return $query->where('name', 'like', '%' . $value . '%');
- }
- /**
- * 根据model搜索
- */
- public function searchModelAttr($query, $value, $data)
- {
- return $query->where('model', 'like', '%' . $value . '%');
- }
- /**
- * 根据name搜索
- */
- public function searchIsUsedAttr($query, $value, $data)
- {
- return $query->where('is_used', $value);
- }
- }
|