Hydraulic.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. 'model',
  19. // 所属部门
  20. 'department_id',
  21. // 名称
  22. 'name',
  23. // 使用状态
  24. 'is_used',
  25. // 品牌
  26. 'brand',
  27. // 供应商
  28. 'supplier',
  29. // 出厂日期
  30. 'out_date',
  31. // 告警状态
  32. 'alarm_state',
  33. // 网络状态
  34. 'net_state',
  35. // 在线时间
  36. 'online_time',
  37. //扭矩
  38. 'torque',
  39. //压力
  40. 'stress',
  41. //螺栓尺寸
  42. 'bolts_size',
  43. //螺栓数量
  44. 'bolts_num',
  45. //备注
  46. 'remark',
  47. // 创建人ID
  48. 'creator_id',
  49. // 创建时间
  50. 'created_at',
  51. // 更新时间
  52. 'updated_at',
  53. // 软删除
  54. 'deleted_at',
  55. 'longitude',
  56. 'latitude',
  57. 'max_pressure',
  58. 'min_pressure',
  59. 'imei',
  60. 'sim_card'
  61. );
  62. /**
  63. * 获取列表
  64. */
  65. public function getList()
  66. {
  67. $res = $this->dataRange()
  68. ->catchSearch()
  69. ->append(['depart_name', 'alarm_state_text','creator_user','model_name'])
  70. ->order($this->aliasField('id'), 'desc')
  71. ->paginate();
  72. return $res;
  73. }
  74. /**
  75. * 获取轨迹地图列表定位不分页 只查询有定位时间的
  76. */
  77. public function queryLocationList()
  78. {
  79. $res = $this->dataRange()
  80. ->catchSearch()
  81. ->select();
  82. return $res;
  83. }
  84. /**
  85. * 获取导入用户(文本)
  86. */
  87. public function getCreatorUserAttr($value)
  88. {
  89. $uid = $this->creator_id;
  90. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  91. }
  92. /**
  93. * 使用状态
  94. */
  95. public function getIsUsedAttr($value)
  96. {
  97. if($value!=0){
  98. return true;
  99. }else{
  100. return false;
  101. }
  102. }
  103. /**
  104. * 获取部门名称(文本)
  105. */
  106. public function getDepartNameAttr()
  107. {
  108. $id = $this->getData('department_id');
  109. return Db::table('departments')->where('id', $id)->value('department_name');
  110. }
  111. /**
  112. * 获取类型名称
  113. */
  114. public function getModelAttr($value)
  115. {
  116. return (int)$value;
  117. }
  118. /**
  119. * 获取类型名称
  120. */
  121. public function getModelNameAttr()
  122. {
  123. $id = $this->getData('model');
  124. return Db::table('device_mold')->where('id', $id)->value('name');
  125. }
  126. /**
  127. * 获取部门名称(文本)
  128. */
  129. public function getOnlineTimeAttr($value)
  130. {
  131. if($value){
  132. return date('Y-m-d H:i:s',$value);
  133. }else{
  134. return '-';
  135. }
  136. }
  137. /**
  138. * 获取告警状态文本
  139. */
  140. public function getAlarmStateTextAttr($value)
  141. {
  142. $alarm_state = $this->getData('alarm_state');
  143. return $alarm_state ? '告警' : '正常';
  144. }
  145. /**
  146. * 根据部门搜索
  147. */
  148. public function searchDepartmentIdAttr($query, $value, $data)
  149. {
  150. if ($value) {
  151. $id = end($value);
  152. return $query->where('department_id', '=', $id);
  153. }
  154. }
  155. /**
  156. * 根据number搜索
  157. */
  158. public function searchNumberAttr($query, $value, $data)
  159. {
  160. return $query->where('number', 'like', '%'.$value.'%');
  161. }
  162. /**
  163. * 根据name搜索
  164. */
  165. public function searchNameAttr($query, $value, $data)
  166. {
  167. return $query->where('name', 'like', '%'.$value.'%');
  168. }
  169. /**
  170. * 根据model搜索
  171. */
  172. public function searchModelAttr($query, $value, $data)
  173. {
  174. return $query->where('model', 'like', '%'.$value.'%');
  175. }
  176. /**
  177. * 根据name搜索
  178. */
  179. public function searchIsUsedAttr($query, $value, $data)
  180. {
  181. return $query->where('is_used', $value);
  182. }
  183. }