HydEquipment.php 4.6 KB

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