HydEquipment.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. public function getList()
  51. {
  52. $res = $this->dataRange()
  53. ->catchSearch()
  54. ->append(['classification','equ_type_name', 'list','status1','check_status1'])
  55. ->order($this->aliasField('id'), 'desc')
  56. ->paginate();
  57. return $res;
  58. }
  59. public function getEquipmentTypeAttr()
  60. {
  61. $id = $this->getData('equipment_type');
  62. return intval($id);
  63. }
  64. public function getStatusAttr()
  65. {
  66. $id = $this->getData('status');
  67. return intval($id);
  68. }
  69. public function getCheckStatusAttr()
  70. {
  71. $id = $this->getData('check_status');
  72. return intval($id);
  73. }
  74. public function getClassificationAttr()
  75. {
  76. $id = $this->getData('equipment_type');
  77. $eq = new EquipmentType();
  78. $name = $eq->getParentNamebyChildId($id);
  79. return $name;
  80. }
  81. public function getEquTypeNameAttr()
  82. {
  83. $id = $this->getData('equipment_type');
  84. $name = EquipmentType::where('id',$id)->value('name');
  85. return $name;
  86. }
  87. public function getCheckStatus1Attr()
  88. {
  89. $id = $this->getData('check_status');
  90. $Dict = new SysDictData();
  91. $value = $Dict->getValueByCode('Check',$id);
  92. return $value;
  93. }
  94. public function getStatus1Attr()
  95. {
  96. $id = $this->getData('status');
  97. $Dict = new SysDictData();
  98. $value = $Dict->getValueByCode('ToolStatus',$id);
  99. return $value;
  100. }
  101. public function getCheckLastTimeAttr()
  102. {
  103. $time = $this->getData('check_last_time');
  104. return $time?date('Y-m-d',$time):'';
  105. }
  106. public function getCheckNextTimeAttr()
  107. {
  108. $time = $this->getData('check_next_time');
  109. return $time?date('Y-m-d',$time):'';
  110. }
  111. public function getListAttr()
  112. {
  113. $id = $this->getData('id');
  114. $type_id = $this->getData('equipment_type');
  115. if($type_id==2)
  116. {
  117. return Hydraulic::where('eq_id',$id)->find();
  118. }
  119. if($type_id==3||$type_id==4)
  120. {
  121. return Wrench::where('eq_id',$id)->find();
  122. }
  123. else
  124. {
  125. return null;
  126. }
  127. }
  128. }