Hydraulic.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. 'effective_time',
  62. 'effective_period',
  63. 'check_time',
  64. );
  65. /**
  66. * 获取列表
  67. */
  68. public function getList()
  69. {
  70. $res = $this->dataRange()
  71. ->catchSearch()
  72. ->append(['depart_name', 'alarm_state_text','creator_user','model_name'])
  73. ->order($this->aliasField('id'), 'desc')
  74. ->paginate();
  75. return $res;
  76. }
  77. /**
  78. * 获取轨迹地图列表定位不分页 只查询有定位时间的
  79. */
  80. public function queryLocationList()
  81. {
  82. $res = $this->dataRange()
  83. ->catchSearch()
  84. ->select();
  85. return $res;
  86. }
  87. /**
  88. * 获取导入用户(文本)
  89. */
  90. public function getCreatorUserAttr($value)
  91. {
  92. $uid = $this->creator_id;
  93. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  94. }
  95. /**
  96. * 使用状态
  97. */
  98. public function getIsUsedAttr($value)
  99. {
  100. if($value!=0){
  101. return true;
  102. }else{
  103. return false;
  104. }
  105. }
  106. /**
  107. * 获取部门名称(文本)
  108. */
  109. public function getDepartNameAttr()
  110. {
  111. $id = $this->getData('department_id');
  112. return Db::table('departments')->where('id', $id)->value('department_name');
  113. }
  114. /**
  115. * 获取类型名称
  116. */
  117. public function getModelAttr($value)
  118. {
  119. return (int)$value;
  120. }
  121. /**
  122. * 获取类型名称
  123. */
  124. public function getModelNameAttr()
  125. {
  126. $id = $this->getData('model');
  127. return Db::table('device_mold')->where('id', $id)->value('name');
  128. }
  129. /**
  130. * 获取部门名称(文本)
  131. */
  132. public function getOnlineTimeAttr($value)
  133. {
  134. if($value){
  135. return date('Y-m-d H:i:s',$value);
  136. }else{
  137. return '-';
  138. }
  139. }
  140. /**
  141. * 获取告警状态文本
  142. */
  143. public function getAlarmStateTextAttr($value)
  144. {
  145. $alarm_state = $this->getData('alarm_state');
  146. return $alarm_state ? '告警' : '正常';
  147. }
  148. /**
  149. * 根据部门搜索
  150. */
  151. public function searchDepartmentIdAttr($query, $value, $data)
  152. {
  153. if ($value) {
  154. $id = end($value);
  155. return $query->where('department_id', '=', $id);
  156. }
  157. }
  158. /**
  159. * 根据number搜索
  160. */
  161. public function searchNumberAttr($query, $value, $data)
  162. {
  163. return $query->where('number', 'like', '%'.$value.'%');
  164. }
  165. /**
  166. * 根据name搜索
  167. */
  168. public function searchNameAttr($query, $value, $data)
  169. {
  170. return $query->where('name', 'like', '%'.$value.'%');
  171. }
  172. /**
  173. * 根据model搜索
  174. */
  175. public function searchModelAttr($query, $value, $data)
  176. {
  177. return $query->where('model', 'like', '%'.$value.'%');
  178. }
  179. /**
  180. * 根据name搜索
  181. */
  182. public function searchIsUsedAttr($query, $value, $data)
  183. {
  184. return $query->where('is_used', $value);
  185. }
  186. }