Hydraulic.php 3.7 KB

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