HydEquipment.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. 'status',
  41. // 创建人ID
  42. 'creator_id',
  43. // 创建时间
  44. 'created_at',
  45. // 更新时间
  46. 'updated_at',
  47. // 软删除
  48. 'deleted_at',
  49. );
  50. //物料号搜索
  51. public function searchMaterialNumberAttr($query, $value, $data)
  52. {
  53. return $query->where('material_number', 'like', '%'.$value.'%');
  54. }
  55. //设备类别搜索
  56. public function searchEquipmentTypeAttr($query, $value, $data)
  57. {
  58. return $query->where('equipment_type', '=', $value);
  59. }
  60. //名称
  61. public function searchNameAttr($query, $value, $data)
  62. {
  63. return $query->where('name', 'like', '%'.$value.'%');
  64. }
  65. //设备序列号以及设备资产编号
  66. public function searchNumberAttr($query, $value, $data)
  67. {
  68. return $query->where('serial_number|fixed_asset_number|fixed_asset_number2', 'like', '%'.$value.'%');
  69. }
  70. //根据pid 查询当前子类的设备
  71. public function searchPidAttr($query, $value, $data)
  72. {
  73. $eqtype =new EquipmentType();
  74. $list =$eqtype->getIdbyPid($value);
  75. $ids=[];
  76. foreach($list as $key =>$value)
  77. {
  78. $ids[] = $value['id'];
  79. }
  80. return $query->where('equipment_type', 'in', $ids);
  81. }
  82. public function getList()
  83. {
  84. $res = $this->dataRange()
  85. ->catchSearch()
  86. ->append(['classification','equ_type_name', 'list','status1','check_status1'])
  87. ->order($this->aliasField('id'), 'desc')
  88. ->paginate();
  89. return $res;
  90. }
  91. public function getEquipmentTypeAttr()
  92. {
  93. $id = $this->getData('equipment_type');
  94. return intval($id);
  95. }
  96. public function getStatusAttr()
  97. {
  98. $id = $this->getData('status');
  99. return intval($id);
  100. }
  101. public function getCheckStatusAttr()
  102. {
  103. $id = $this->getData('check_status');
  104. return intval($id);
  105. }
  106. public function getClassificationAttr()
  107. {
  108. $id = $this->getData('equipment_type');
  109. $eq = new EquipmentType();
  110. $name = $eq->getParentNamebyChildId($id);
  111. return $name;
  112. }
  113. public function getEquTypeNameAttr()
  114. {
  115. $id = $this->getData('equipment_type');
  116. $name = EquipmentType::where('id',$id)->value('name');
  117. return $name;
  118. }
  119. public function getCheckStatus1Attr()
  120. {
  121. $id = $this->getData('check_status');
  122. $Dict = new SysDictData();
  123. $value = $Dict->getValueByCode('Check',$id);
  124. return $value;
  125. }
  126. public function getStatus1Attr()
  127. {
  128. $id = $this->getData('status');
  129. $Dict = new SysDictData();
  130. $value = $Dict->getValueByCode('ToolStatus',$id);
  131. return $value;
  132. }
  133. public function getCheckLastTimeAttr()
  134. {
  135. $time = $this->getData('check_last_time');
  136. return $time?date('Y-m-d',$time):'';
  137. }
  138. public function getCheckNextTimeAttr()
  139. {
  140. $time = $this->getData('check_next_time');
  141. return $time?date('Y-m-d',$time):'';
  142. }
  143. public function getListAttr()
  144. {
  145. $id = $this->getData('id');
  146. $type_id = $this->getData('equipment_type');
  147. if($type_id==2)
  148. {
  149. return Hydraulic::where('eq_id',$id)->find();
  150. }
  151. if($type_id==3||$type_id==4)
  152. {
  153. return Wrench::where('eq_id',$id)->find();
  154. }
  155. else
  156. {
  157. return null;
  158. }
  159. }
  160. }