MaintenanceMapper.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace catchAdmin\hydraulic\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\system\model\SysDictData;
  5. use catchAdmin\permissions\model\DataRangScopeTrait;
  6. use \think\facade\Db;
  7. class maintenancemapper extends Model
  8. {
  9. use DataRangScopeTrait;
  10. // 表名
  11. public $name = 'maintenance_mapper';
  12. // 数据库字段映射
  13. public $field = array(
  14. 'id',
  15. // 设备类型
  16. 'device_type',
  17. // 唯一值
  18. 'value',
  19. // 名称
  20. 'name',
  21. 'fan_model',
  22. // 创建人ID
  23. 'creator_id',
  24. // 创建时间
  25. 'created_at',
  26. // 更新时间
  27. 'updated_at',
  28. // 软删除
  29. 'deleted_at',
  30. );
  31. /**
  32. * 获取列表
  33. */
  34. public function getList()
  35. {
  36. $res = $this->dataRange()
  37. ->catchSearch()
  38. ->append(['device_type_name','creator_name','fan_model_name'])
  39. ->order($this->aliasField('id'), 'desc')
  40. ->paginate();
  41. return $res;
  42. }
  43. /**
  44. * 名称搜索
  45. */
  46. public function searchNameAttr($query, $value, $data)
  47. {
  48. return $query->where('name', 'like', '%'.$value.'%');
  49. }
  50. /**
  51. * 设备类型搜索
  52. */
  53. public function searchDeviceTypeAttr($query, $value, $data)
  54. {
  55. return $query->where('device_type', '=', $value);
  56. }
  57. /**
  58. * 设备类型名称
  59. */
  60. public function getDeviceTypeNameAttr(){
  61. $value=$this->getData('device_type');
  62. return (new SysDictData())->getValueByCode('Maintenance', $value) ?: '';
  63. }
  64. public function getFanModelAttr()
  65. {
  66. $value = $this->getData('fan_model');
  67. return $value?intval($value):null;
  68. }
  69. public function getFanModelNameAttr()
  70. {
  71. $value = $this->getData('fan_model');
  72. $where[] = ['device_type','=',4];
  73. $where[] = ['id','=',$value];
  74. $name = Db::name('device_mold')->where($where)->value('name');
  75. return $name;
  76. }
  77. }