HydEquipment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. public function getList()
  71. {
  72. $res = $this->dataRange()
  73. ->catchSearch()
  74. ->append(['classification','equ_type_name', 'list','status1','check_status1'])
  75. ->order($this->aliasField('id'), 'desc')
  76. ->paginate();
  77. return $res;
  78. }
  79. public function getEquipmentTypeAttr()
  80. {
  81. $id = $this->getData('equipment_type');
  82. return intval($id);
  83. }
  84. public function getStatusAttr()
  85. {
  86. $id = $this->getData('status');
  87. return intval($id);
  88. }
  89. public function getCheckStatusAttr()
  90. {
  91. $id = $this->getData('check_status');
  92. return intval($id);
  93. }
  94. public function getClassificationAttr()
  95. {
  96. $id = $this->getData('equipment_type');
  97. $eq = new EquipmentType();
  98. $name = $eq->getParentNamebyChildId($id);
  99. return $name;
  100. }
  101. public function getEquTypeNameAttr()
  102. {
  103. $id = $this->getData('equipment_type');
  104. $name = EquipmentType::where('id',$id)->value('name');
  105. return $name;
  106. }
  107. public function getCheckStatus1Attr()
  108. {
  109. $id = $this->getData('check_status');
  110. $Dict = new SysDictData();
  111. $value = $Dict->getValueByCode('Check',$id);
  112. return $value;
  113. }
  114. public function getStatus1Attr()
  115. {
  116. $id = $this->getData('status');
  117. $Dict = new SysDictData();
  118. $value = $Dict->getValueByCode('ToolStatus',$id);
  119. return $value;
  120. }
  121. public function getCheckLastTimeAttr()
  122. {
  123. $time = $this->getData('check_last_time');
  124. return $time?date('Y-m-d',$time):'';
  125. }
  126. public function getCheckNextTimeAttr()
  127. {
  128. $time = $this->getData('check_next_time');
  129. return $time?date('Y-m-d',$time):'';
  130. }
  131. public function getListAttr()
  132. {
  133. $id = $this->getData('id');
  134. $type_id = $this->getData('equipment_type');
  135. if($type_id==2)
  136. {
  137. return Hydraulic::where('eq_id',$id)->find();
  138. }
  139. if($type_id==3||$type_id==4)
  140. {
  141. return Wrench::where('eq_id',$id)->find();
  142. }
  143. else
  144. {
  145. return null;
  146. }
  147. }
  148. }