123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace catchAdmin\wind\model;
- use catchAdmin\api\Listen;
- use catcher\base\CatchModel as Model;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use \think\facade\Db;
- class Wind extends Model
- {
- use DataRangScopeTrait;
- use Listen;
- // 表名
- public $name = 'wind';
- // 数据库字段映射
- public $field = array(
- 'id',
- // 风场名称
- 'name',
- // 编号
- 'number',
- // 所属部门
- 'department_id',
- // 风场地址
- 'address',
- // 维保设备数量
- 'maintenance_count',
- // 泵设备数量
- 'pump_count',
- //风场形状
- 'wind_shape',
- //风场区域经纬度信息
- 'wind_info',
- //风场边缘颜色
- 'side_color',
- //风场内部颜色
- 'inside_color',
- // 备注
- 'remark',
- // 创建人ID
- 'creator_id',
- // 创建时间
- 'created_at',
- // 更新时间
- 'updated_at',
- // 软删除
- 'deleted_at',
- );
- public function getList()
- {
- // 分页列表
- return $this->dataRange()
- ->catchSearch()
- ->field('*')
- ->catchOrder()
- ->append(['type_name', 'depart_name'])
- ->creator()
- ->paginate();
- }
- public function getWindList()
- {
- // 不分页
- return $this->dataRange()
- ->catchSearch()
- ->field('*')
- ->catchOrder()
- ->append(['type_name', 'depart_name'])
- ->creator()
- ->select();
- }
- /**
- * 获取风场类型(文本)
- */
- public function getTypeNameAttr($value)
- {
- $type_arr = [
- 'circle' => '圆形围栏',
- 'polygon' => '多边形围栏',
- ];
- return $type_arr[$this->getData('wind_shape')] ?: '未知';
- }
- public function getDepartmentIdAttr($value)
- {
- return json_decode($value, true);
- }
- public function getWindInfoAttr($value)
- {
- return json_decode($value, true);
- }
- public function getDepartNameAttr($value)
- {
- $id = $this->department_id;
- return Db::table('departments')->where('id', $id)->value('department_name');
- }
- public function searchNameAttr($query, $value, $data)
- {
- return $query->where('name', 'like', '%' . $value . '%');
- }
- //下发数据
- public function addContent(&$obj)
- {
- //var_dump($obj);
- $data = null;
- $content = null;
- $jsonInfo = $obj->wind_info;
- $data = [
- 'id' => $obj->id,
- 'number' => $obj->number,
- 'name' => $obj['name'],
- 'lon' => $jsonInfo['center']['lng'],
- 'lat' => $jsonInfo['center']['lat']
- ];
- $content['data'] = $data;
- $content['type'] = 'Wind';
- return $content;
- }
- }
|