Hydraulic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. 'remark',
  38. // 创建人ID
  39. 'creator_id',
  40. // 创建时间
  41. 'created_at',
  42. // 更新时间
  43. 'updated_at',
  44. // 软删除
  45. 'deleted_at',
  46. );
  47. /**
  48. * 获取列表
  49. */
  50. public function getList()
  51. {
  52. $res = $this->dataRange()
  53. ->catchSearch()
  54. ->append(['depart_name', 'alarm_state_text','creator_user','model_name'])
  55. ->order($this->aliasField('id'), 'desc')
  56. ->paginate();
  57. return $res;
  58. }
  59. /**
  60. * 获取轨迹地图列表定位不分页 只查询有定位时间的
  61. */
  62. public function queryLocationList()
  63. {
  64. $res = $this->dataRange()
  65. ->catchSearch()
  66. ->select();
  67. return $res;
  68. }
  69. /**
  70. * 获取导入用户(文本)
  71. */
  72. public function getCreatorUserAttr($value)
  73. {
  74. $uid = $this->creator_id;
  75. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  76. }
  77. /**
  78. * 获取部门名称(文本)
  79. */
  80. public function getDepartNameAttr()
  81. {
  82. $id = $this->getData('department_id');
  83. return Db::table('departments')->where('id', $id)->value('department_name');
  84. }
  85. /**
  86. * 获取部门名称(文本)
  87. */
  88. public function getOnlineTimeAttr($value)
  89. {
  90. if($value){
  91. return date('Y-m-d H:i:s',$value);
  92. }else{
  93. return '-';
  94. }
  95. }
  96. /**
  97. * 获取告警状态文本
  98. */
  99. public function getAlarmStateTextAttr($value)
  100. {
  101. $alarm_state = $this->getData('alarm_state');
  102. return $alarm_state ? '告警' : '正常';
  103. }
  104. /**
  105. * 根据部门搜索
  106. */
  107. public function searchDepartmentIdAttr($query, $value, $data)
  108. {
  109. if ($value) {
  110. $id = end($value);
  111. return $query->where('department_id', '=', $id);
  112. }
  113. }
  114. /**
  115. * 根据类型搜索
  116. */
  117. public function searchTypeAttr($query, $value, $data)
  118. {
  119. return $query->where('type', '=', $value);
  120. }
  121. /**
  122. * 根据number搜索
  123. */
  124. public function searchNumberAttr($query, $value, $data)
  125. {
  126. return $query->where('number', 'like', '%'.$value.'%');
  127. }
  128. /**
  129. * 根据name搜索
  130. */
  131. public function searchNameAttr($query, $value, $data)
  132. {
  133. return $query->where('name', 'like', '%'.$value.'%');
  134. }
  135. /**
  136. * 根据model搜索
  137. */
  138. public function searchModelAttr($query, $value, $data)
  139. {
  140. return $query->where('model', 'like', '%'.$value.'%');
  141. }
  142. /**
  143. * 根据name搜索
  144. */
  145. public function searchIsUsedAttr($query, $value, $data)
  146. {
  147. return $query->where('is_used', $value);
  148. }
  149. }