Hydraulic.php 4.8 KB

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