Hydraulic.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace catchAdmin\hydraulic\model;
  3. use catcher\base\CatchModel as Model;
  4. use \think\facade\Db;
  5. use catchAdmin\system\model\SysDictData;
  6. use catchAdmin\permissions\model\DataRangScopeTrait;
  7. class Hydraulic extends Model
  8. {
  9. use DataRangScopeTrait;
  10. // 表名
  11. public $name = 'hydraulic';
  12. // 数据库字段映射
  13. public $field = array(
  14. 'id',
  15. // 编号
  16. 'number',
  17. // 所属部门
  18. 'department_id',
  19. // 告警状态
  20. 'alarm_state',
  21. // 网络状态
  22. 'net_state',
  23. // //扭矩
  24. // 'torque',
  25. // //压力
  26. // 'stress',
  27. // //螺栓尺寸
  28. // 'bolts_size',
  29. // //螺栓数量
  30. // 'bolts_num',
  31. //备注
  32. 'remark',
  33. // 创建人ID
  34. 'creator_id',
  35. // 创建时间
  36. 'created_at',
  37. // 更新时间
  38. 'updated_at',
  39. // 软删除
  40. 'deleted_at',
  41. 'longitude',
  42. 'latitude',
  43. 'max_pressure',
  44. 'min_pressure',
  45. 'imei',
  46. 'sim_card',
  47. 'effective_time',
  48. 'effective_period',
  49. //设备的id
  50. 'eq_id'
  51. );
  52. /**
  53. * 获取列表
  54. */
  55. public function getList()
  56. {
  57. $res = $this->dataRange()
  58. ->catchSearch()
  59. ->append(['depart_name', 'alarm_state_text', 'creator_user', 'model_name'])
  60. ->order($this->aliasField('id'), 'desc')
  61. ->paginate();
  62. return $res;
  63. }
  64. /**
  65. * 获取轨迹地图列表定位不分页 只查询有定位时间的
  66. */
  67. public function queryLocationList()
  68. {
  69. $res = $this->dataRange()
  70. ->catchSearch()
  71. ->select();
  72. return $res;
  73. }
  74. /**
  75. * 获取导入用户(文本)
  76. */
  77. public function getCreatorUserAttr($value)
  78. {
  79. $uid = $this->creator_id;
  80. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  81. }
  82. /**
  83. * 使用状态
  84. */
  85. public function getIsUsedAttr($value)
  86. {
  87. if ($value != 0) {
  88. return true;
  89. } else {
  90. return false;
  91. }
  92. }
  93. /**
  94. * 获取部门名称(文本)
  95. */
  96. public function getDepartNameAttr()
  97. {
  98. $id = $this->getData('department_id');
  99. return Db::table('departments')->where('id', $id)->value('department_name');
  100. }
  101. /**
  102. * 获取类型名称
  103. */
  104. public function getModelAttr($value)
  105. {
  106. return (int)$value;
  107. }
  108. /**
  109. * 校验日期
  110. */
  111. public function getEffectiveTimeAttr($value)
  112. {
  113. if ($value) {
  114. return date('Y-m-d H:i:s', $value);
  115. } else {
  116. return '-';
  117. }
  118. }
  119. /**
  120. * 校验日期
  121. */
  122. public function getCheckTimeAttr($value)
  123. {
  124. if ($value) {
  125. return date('Y-m-d H:i:s', $value);
  126. } else {
  127. return '-';
  128. }
  129. }
  130. /**
  131. * 获取告警状态文本
  132. */
  133. public function getAlarmStateTextAttr($value)
  134. {
  135. $alarm_state = $this->getData('alarm_state');
  136. return $alarm_state ? '告警' : '正常';
  137. }
  138. /**
  139. * 根据部门搜索
  140. */
  141. public function searchDepartmentIdAttr($query, $value, $data)
  142. {
  143. if ($value) {
  144. $id = end($value);
  145. return $query->where('department_id', '=', $id);
  146. }
  147. }
  148. /**
  149. * 根据number搜索
  150. */
  151. public function searchNumberAttr($query, $value, $data)
  152. {
  153. return $query->where('number', 'like', '%' . $value . '%');
  154. }
  155. /**
  156. * 根据name搜索
  157. */
  158. public function searchNameAttr($query, $value, $data)
  159. {
  160. return $query->where('name', 'like', '%' . $value . '%');
  161. }
  162. /**
  163. * 根据model搜索
  164. */
  165. public function searchModelAttr($query, $value, $data)
  166. {
  167. return $query->where('model', 'like', '%' . $value . '%');
  168. }
  169. /**
  170. * 根据name搜索
  171. */
  172. public function searchIsUsedAttr($query, $value, $data)
  173. {
  174. return $query->where('is_used', $value);
  175. }
  176. }