Wind.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace catchAdmin\wind\model;
  3. use catchAdmin\api\Listen;
  4. use catcher\base\CatchModel as Model;
  5. use catchAdmin\permissions\model\DataRangScopeTrait;
  6. use \think\facade\Db;
  7. class Wind extends Model
  8. {
  9. use DataRangScopeTrait;
  10. use Listen;
  11. // 表名
  12. public $name = 'wind';
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. // 风场名称
  17. 'name',
  18. // 编号
  19. 'number',
  20. // 所属部门
  21. 'department_id',
  22. // 风场地址
  23. 'address',
  24. // 维保设备数量
  25. 'maintenance_count',
  26. // 泵设备数量
  27. 'pump_count',
  28. //风场形状
  29. 'wind_shape',
  30. //风场区域经纬度信息
  31. 'wind_info',
  32. //风场边缘颜色
  33. 'side_color',
  34. //风场内部颜色
  35. 'inside_color',
  36. // 备注
  37. 'remark',
  38. // 创建人ID
  39. 'creator_id',
  40. // 创建时间
  41. 'created_at',
  42. // 更新时间
  43. 'updated_at',
  44. // 软删除
  45. 'deleted_at',
  46. );
  47. public function getList()
  48. {
  49. // 分页列表
  50. return $this->dataRange()
  51. ->catchSearch()
  52. ->field('*')
  53. ->catchOrder()
  54. ->append(['type_name', 'depart_name'])
  55. ->creator()
  56. ->paginate();
  57. }
  58. public function getWindList()
  59. {
  60. // 不分页
  61. return $this->dataRange()
  62. ->catchSearch()
  63. ->field('*')
  64. ->catchOrder()
  65. ->append(['type_name', 'depart_name'])
  66. ->creator()
  67. ->select();
  68. }
  69. /**
  70. * 获取风场类型(文本)
  71. */
  72. public function getTypeNameAttr($value)
  73. {
  74. $type_arr = [
  75. 'circle' => '圆形围栏',
  76. 'polygon' => '多边形围栏',
  77. ];
  78. return $type_arr[$this->getData('wind_shape')] ?: '未知';
  79. }
  80. public function getDepartmentIdAttr($value)
  81. {
  82. return json_decode($value, true);
  83. }
  84. public function getWindInfoAttr($value)
  85. {
  86. return json_decode($value, true);
  87. }
  88. public function getDepartNameAttr($value)
  89. {
  90. $id = $this->department_id;
  91. return Db::table('departments')->where('id', $id)->value('department_name');
  92. }
  93. public function searchNameAttr($query, $value, $data)
  94. {
  95. return $query->where('name', 'like', '%' . $value . '%');
  96. }
  97. //下发数据
  98. public function addContent(&$obj)
  99. {
  100. //var_dump($obj);
  101. $data = null;
  102. $content = null;
  103. $jsonInfo = $obj->wind_info;
  104. $data = [
  105. 'id' => $obj->id,
  106. 'number' => $obj->number,
  107. 'name' => $obj['name'],
  108. 'lon' => $jsonInfo['center']['lng'],
  109. 'lat' => $jsonInfo['center']['lat']
  110. ];
  111. $content['data'] = $data;
  112. $content['type'] = 'Wind';
  113. return $content;
  114. }
  115. }