MaintenanceMapper.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace catchAdmin\hydraulic\model;
  3. use catchAdmin\api\Listen;
  4. use catcher\base\CatchModel as Model;
  5. use catchAdmin\system\model\SysDictData;
  6. use catchAdmin\permissions\model\DataRangScopeTrait;
  7. use \think\facade\Db;
  8. class maintenancemapper extends Model
  9. {
  10. use Listen;
  11. use DataRangScopeTrait;
  12. // 表名
  13. public $name = 'maintenance_mapper';
  14. // 数据库字段映射
  15. public $field = array(
  16. 'id',
  17. // 设备类型
  18. 'device_type',
  19. // 唯一值
  20. 'value',
  21. // 名称
  22. 'name',
  23. //部件
  24. 'parts',
  25. //风机型号
  26. 'fan_model',
  27. // 创建人ID
  28. 'creator_id',
  29. // 创建时间
  30. 'created_at',
  31. // 更新时间
  32. 'updated_at',
  33. // 软删除
  34. 'deleted_at',
  35. );
  36. /**
  37. * 获取列表
  38. */
  39. public function getList()
  40. {
  41. $res = $this->dataRange()
  42. ->catchSearch()
  43. ->append(['device_type_name', 'creator_name', 'fan_model_name'])
  44. ->order($this->aliasField('id'), 'desc')
  45. ->paginate();
  46. return $res;
  47. }
  48. /**
  49. * 名称搜索
  50. */
  51. public function searchNameAttr($query, $value, $data)
  52. {
  53. return $query->where('name', 'like', '%' . $value . '%');
  54. }
  55. /**
  56. * 设备类型搜索
  57. */
  58. public function searchDeviceTypeAttr($query, $value, $data)
  59. {
  60. return $query->where('device_type', '=', $value);
  61. }
  62. /**
  63. * 设备类型名称
  64. */
  65. public function getDeviceTypeNameAttr()
  66. {
  67. $value = $this->getData('device_type');
  68. return (new SysDictData())->getValueByCode('Maintenance', $value) ?: '';
  69. }
  70. public function getFanModelAttr()
  71. {
  72. $value = $this->getData('fan_model');
  73. return $value ? intval($value) : null;
  74. }
  75. public function getFanModelNameAttr()
  76. {
  77. $value = $this->getData('fan_model');
  78. $where[] = ['device_type', '=', 4];
  79. $where[] = ['id', '=', $value];
  80. $name = Db::name('device_mold')->where($where)->value('name');
  81. return $name;
  82. }
  83. //下发数据 工作部件/工作位置
  84. public function addContent(&$obj)
  85. {
  86. //var_dump($obj);
  87. $data = null;
  88. $content = null;
  89. if ($obj->device_type == 1) {
  90. $data = [
  91. 'id' => $obj->id,
  92. 'name' => $obj['name'],
  93. ];
  94. $content['data'] = $data;
  95. $content['type'] = 'WorkingParts';
  96. } else if ($obj->device_type == 2) {
  97. $data = [
  98. 'id' => $obj->id,
  99. 'fmodel' => Db::name('device_mold')->where('id', $obj->fan_model)->value('name'),
  100. 'name' => $obj['name'],
  101. 'Parts' => $this->where('device_type', 1)->where('value', $obj->parts)->value('name')
  102. ];
  103. $content['data'] = $data;
  104. $content['type'] = 'WorkingPosition';
  105. } else {
  106. $content['is_filter'] = true;
  107. }
  108. return $content;
  109. }
  110. }