HydEquipment.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace catchAdmin\hydraulic\model;
  3. use catchAdmin\equipment\model\EquipmentType;
  4. use catcher\base\CatchModel as Model;
  5. use catchAdmin\permissions\model\DataRangScopeTrait;
  6. use catchAdmin\permissions\model\Department as ModelDepartment;
  7. use catchAdmin\system\model\SysDictData;
  8. use Department;
  9. class HydEquipment extends Model
  10. {
  11. use DataRangScopeTrait;
  12. // 表名
  13. public $name = 'hydraulic_equipment';
  14. // 数据库字段映射
  15. public $field = array(
  16. 'id',
  17. // 物料号
  18. 'material_number',
  19. // 设备类别
  20. 'equipment_type',
  21. // 工具名称
  22. 'name',
  23. // 设备型号
  24. 'equipment_model',
  25. // 发放单位
  26. 'issue_unit',
  27. // 固定资产编号
  28. 'fixed_asset_number',
  29. // 类固定资产编号
  30. 'fixed_asset_number2',
  31. // 序列号
  32. 'serial_number',
  33. // 出厂编号
  34. 'factory_number',
  35. // 上次校验时间
  36. 'check_last_time',
  37. // 下次校验时间
  38. 'check_next_time',
  39. // 校验状态
  40. 'check_status',
  41. // 状态
  42. 'longitude',
  43. 'latitude',
  44. 'address',
  45. 'status',
  46. // 创建人ID
  47. 'creator_id',
  48. // 创建时间
  49. 'created_at',
  50. // 更新时间
  51. 'updated_at',
  52. // 软删除
  53. 'deleted_at',
  54. );
  55. //物料号搜索
  56. public function searchMaterialNumberAttr($query, $value, $data)
  57. {
  58. return $query->where('material_number', 'like', '%' . $value . '%');
  59. }
  60. //设备类别搜索
  61. public function searchEquipmentTypeAttr($query, $value, $data)
  62. {
  63. return $query->where('equipment_type', '=', $value);
  64. }
  65. //名称
  66. public function searchNameAttr($query, $value, $data)
  67. {
  68. return $query->where('name', 'like', '%' . $value . '%');
  69. }
  70. //设备序列号以及设备资产编号
  71. public function searchNumberAttr($query, $value, $data)
  72. {
  73. return $query->where('serial_number|fixed_asset_number|fixed_asset_number2', 'like', '%' . $value . '%');
  74. }
  75. //根据pid 查询当前子类的设备
  76. public function searchPidAttr($query, $value, $data)
  77. {
  78. $eqtype = new EquipmentType();
  79. $list = $eqtype->getIdbyPid($value);
  80. $ids = [];
  81. foreach ($list as $key => $value) {
  82. $ids[] = $value['id'];
  83. }
  84. return $query->where('equipment_type', 'in', $ids);
  85. }
  86. public function getList()
  87. {
  88. $res = $this->dataRange()
  89. ->catchSearch()
  90. ->append(['classification', 'equ_type_name', 'list', 'status1', 'check_status1'])
  91. ->order($this->aliasField('id'), 'desc')
  92. ->paginate();
  93. return $res;
  94. }
  95. public function getEquipmentTypeAttr()
  96. {
  97. $id = $this->getData('equipment_type');
  98. return intval($id);
  99. }
  100. public function getStatusAttr()
  101. {
  102. $id = $this->getData('status');
  103. return intval($id);
  104. }
  105. public function getCheckStatusAttr()
  106. {
  107. $id = $this->getData('check_status');
  108. return intval($id);
  109. }
  110. public function getClassificationAttr()
  111. {
  112. $id = $this->getData('equipment_type');
  113. $eq = new EquipmentType();
  114. $name = $eq->getParentNamebyChildId($id);
  115. return $name;
  116. }
  117. public function getEquTypeNameAttr()
  118. {
  119. $id = $this->getData('equipment_type');
  120. $name = EquipmentType::where('id', $id)->value('name');
  121. return $name;
  122. }
  123. public function getCheckStatus1Attr()
  124. {
  125. $id = $this->getData('check_status');
  126. $Dict = new SysDictData();
  127. $value = $Dict->getValueByCode('Check', $id);
  128. return $value;
  129. }
  130. public function getStatus1Attr()
  131. {
  132. $id = $this->getData('status');
  133. $Dict = new SysDictData();
  134. $value = $Dict->getValueByCode('ToolStatus', $id);
  135. return $value;
  136. }
  137. public function getCheckLastTimeAttr()
  138. {
  139. $time = $this->getData('check_last_time');
  140. return $time ? date('Y-m-d', $time) : '';
  141. }
  142. public function getCheckNextTimeAttr()
  143. {
  144. $time = $this->getData('check_next_time');
  145. return $time ? date('Y-m-d', $time) : '';
  146. }
  147. public function getListAttr()
  148. {
  149. $id = $this->getData('id');
  150. $type_id = $this->getData('equipment_type');
  151. $data = null;
  152. if ($type_id == 2) {
  153. $data = Hydraulic::where('eq_id', $id)->find()->toArray();
  154. $data["department_name"] = ModelDepartment::where('id', $data['department_id'])->value('department_name');
  155. $sysdict = new SysDictData();
  156. $data['alarm_state_name'] = $sysdict->getValueByCode('AlarmType', $data['alarm_state']);
  157. return $data;
  158. }
  159. if ($type_id == 3 || $type_id == 4) {
  160. $data = Wrench::where('eq_id', $id)->find()->toArray();
  161. $data["department_name"] = ModelDepartment::where('id', $data['department_id'])->value('department_name');
  162. $sysdict = new SysDictData();
  163. $data['alarm_state_name'] = $sysdict->getValueByCode('AlarmType', $data['alarm_state']);
  164. return $data;
  165. } else {
  166. return null;
  167. }
  168. }
  169. }