123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace catchAdmin\device\model;
- use catcher\base\CatchModel as Model;
- use catchAdmin\device\model\search\DeviceSearch;
- use catchAdmin\device\model\get\DeviceGet;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- class Device extends Model
- {
- use DeviceSearch;
- use DeviceGet;
- use DataRangScopeTrait;
- // 表名
- public $name = 'devices';
- // 数据库字段映射
- public $field = array(
- 'id',
- // GPS编号
- 'imei',
- // 标签编号
- 'rfid',
- // 设备名称
- 'name',
- // 设备型号
- 'model',
- // 关联物体
- 'bind_id',
- // 所属部门
- 'department_id',
- // ICCID
- 'iccid',
- // 应用场景
- 'scenario',
- // SIM卡号
- 'sim_no',
- // 经度
- 'longitude',
- // 纬度
- 'latitude',
- // 在线时间
- 'online_time',
- // 地址
- 'address',
- // 定位模式
- 'loc_mode',
- // 软件版本
- 'soft_ver',
- // 硬件版本
- 'hard_ver',
- // 备注
- 'remark',
- 'wifi_macs',
- 'wifi_online_time',
- 'wifi_longitude',
- 'wifi_latitude',
- 'loc_ploy_state',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- );
- /**
- * 获取设备列表
- */
- public function getList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['status_icon','status_text','last_online_time'])
- ->order([$this->aliasField('online_time')=> 'desc','wifi_online_time'=>'desc', $this->aliasField('id') => 'desc'])
- ->paginate();
- return $res;
- }
- public function queryLocationList(){
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['status_icon','status_text','last_online_time'])
-
- ->order([$this->aliasField('online_time')=> 'desc','wifi_online_time'=>'desc', $this->aliasField('id') => 'desc'])
- ->select()
- ->each(function($item, $key) {
- if($item['online_time']<$item['wifi_online_time']){
- $item['longitude']=$item['wifi_longitude'];
- $item['latitude']=$item['wifi_latitude'];
- }
- })->toArray();
- return $res;
- }
- /**
- * 获取设备列表
- */
- public function getDeviceList($field, $order)
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['depart_name', 'device_state', 'alarm_state_text', 'bind_number', 'creator_user', 'model_text','net_state','loc_mode_text'])
- ->order($this->aliasField($field), $order)
- ->paginate();
- return $res;
- }
- /**
- * 获取设备导出列表
- */
- public function getDevicesExportList()
- {
- $res = $this->dataRange()
- ->catchSearch()
- ->append(['depart_name', 'device_state', 'alarm_state_text', 'bind_number', 'creator_user', 'model_text','net_state','loc_mode_text','alarm_reason'])
- ->order($this->aliasField('id'), 'desc')
- ->select();
- return $res;
- }
- }
|