Hydraulic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 getModelNameAttr()
  112. // {
  113. // $id = $this->getData('model');
  114. // return Db::table('device_mold')->where('id', $id)->value('name');
  115. // }
  116. // /**
  117. // * 获取部门名称(文本)
  118. // */
  119. // public function getOnlineTimeAttr($value)
  120. // {
  121. // if($value){
  122. // return date('Y-m-d H:i:s',$value);
  123. // }else{
  124. // return '-';
  125. // }
  126. // }
  127. /**
  128. * 校验日期
  129. */
  130. public function getEffectiveTimeAttr($value)
  131. {
  132. if($value){
  133. return date('Y-m-d H:i:s',$value);
  134. }else{
  135. return '-';
  136. }
  137. }
  138. /**
  139. * 校验日期
  140. */
  141. public function getCheckTimeAttr($value)
  142. {
  143. if($value){
  144. return date('Y-m-d H:i:s',$value);
  145. }else{
  146. return '-';
  147. }
  148. }
  149. /**
  150. * 获取告警状态文本
  151. */
  152. public function getAlarmStateTextAttr($value)
  153. {
  154. $alarm_state = $this->getData('alarm_state');
  155. return $alarm_state ? '告警' : '正常';
  156. }
  157. /**
  158. * 根据部门搜索
  159. */
  160. public function searchDepartmentIdAttr($query, $value, $data)
  161. {
  162. if ($value) {
  163. $id = end($value);
  164. return $query->where('department_id', '=', $id);
  165. }
  166. }
  167. /**
  168. * 根据number搜索
  169. */
  170. public function searchNumberAttr($query, $value, $data)
  171. {
  172. return $query->where('number', 'like', '%'.$value.'%');
  173. }
  174. /**
  175. * 根据name搜索
  176. */
  177. public function searchNameAttr($query, $value, $data)
  178. {
  179. return $query->where('name', 'like', '%'.$value.'%');
  180. }
  181. /**
  182. * 根据model搜索
  183. */
  184. public function searchModelAttr($query, $value, $data)
  185. {
  186. return $query->where('model', 'like', '%'.$value.'%');
  187. }
  188. /**
  189. * 根据name搜索
  190. */
  191. public function searchIsUsedAttr($query, $value, $data)
  192. {
  193. return $query->where('is_used', $value);
  194. }
  195. }