Flange.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace catchAdmin\flange\model;
  3. use catcher\base\CatchModel as Model;
  4. use catcher\traits\db\BaseOptionsTrait;
  5. use catcher\traits\db\ScopeTrait;
  6. use think\facade\Db;
  7. class Flange extends Model
  8. {
  9. use BaseOptionsTrait, ScopeTrait;
  10. // 表名
  11. public $name = 'flange';
  12. // 数据库字段映射
  13. public $field = array(
  14. 'id',
  15. // 编号
  16. 'number',
  17. // 型号
  18. 'model',
  19. // 所属部门
  20. 'department_id',
  21. // 名称
  22. 'name',
  23. // 使用状态 1已使用 -1未使用 -2废弃
  24. 'is_used',
  25. // 品牌
  26. 'brand',
  27. // 供应商
  28. 'supplier',
  29. // 出厂日期
  30. 'out_date',
  31. // 注释
  32. 'remark',
  33. // 扭矩
  34. 'torque',
  35. // 压力
  36. 'stress',
  37. // 紧固方案
  38. 'fastening_scheme',
  39. // 风机id
  40. 'fan_id',
  41. // 安装位置
  42. 'install_position',
  43. // 紧固信息
  44. 'fastening_information',
  45. // 维护信息
  46. 'maintenance_information',
  47. // 创建人ID
  48. 'creator_id',
  49. // 创建时间
  50. 'created_at',
  51. // 更新时间
  52. 'updated_at',
  53. // 软删除
  54. 'deleted_at',
  55. // 螺丝尺寸
  56. 'bolt_size',
  57. // 螺丝数量
  58. 'bolt_number',
  59. // 螺丝尺寸
  60. 'wind_id',
  61. // 扳手
  62. 'wrench',
  63. // 外径
  64. 'outside',
  65. );
  66. public function getList()
  67. {
  68. return $this->catchSearch()
  69. ->append(['depart_name','model_type','wind_name','fan_number'])
  70. ->field('*')
  71. ->catchOrder()
  72. ->creator()
  73. ->paginate();
  74. }
  75. public function getDepartNameAttr($value)
  76. {
  77. $id=$this->department_id;
  78. return Db::table('departments')->where('id', $id)->value('department_name');
  79. }
  80. public function getModelTypeAttr()
  81. {
  82. return Db::name('device_mold')->where('device_type',2)->where('id',$this->model)->value('name');
  83. }
  84. public function getModelAttr()
  85. {
  86. return (int) $this->getData('model');
  87. }
  88. public function getDepartmentIdAttr()
  89. {
  90. return (int) $this->getData('department_id');
  91. }
  92. public function getFanIdAttr()
  93. {
  94. return (int) $this->getData('fan_id');
  95. }
  96. public function setWrenchAttr($value)
  97. {
  98. $str = implode(',',$value);
  99. return $str;
  100. }
  101. public function getWrenchAttr()
  102. {
  103. $str =null;
  104. if(!empty($this->getData('wrench')))
  105. {
  106. $str =array_map('intval',explode(',', $this->getData('wrench')));
  107. }
  108. return $str;
  109. }
  110. /**
  111. *获取风场名称
  112. */
  113. public function getWindNameAttr()
  114. {
  115. $fan_id = $this->getData('fan_id');
  116. $wind_id = Db::name('fan')->where("id",$fan_id)->value("wind_id");
  117. $name = Db::name("wind")->where('id',$wind_id)->value('name');
  118. return $name;
  119. }
  120. //获取风机编号
  121. public function getFanNumberAttr()
  122. {
  123. $fan_id = $this->getData('fan_id');
  124. $number = Db::name('fan')->where("id",$fan_id)->value("number");
  125. return $number;
  126. }
  127. //紧固方案
  128. public function setFasteningSchemeAttr($value)
  129. {
  130. $str = implode(',',$value);
  131. return $str;
  132. }
  133. public function getFasteningSchemeAttr()
  134. {
  135. $str =null;
  136. if(!empty($this->getData('fastening_scheme')))
  137. {
  138. $str =array_map('intval',explode(',', $this->getData('fastening_scheme')));
  139. }
  140. return $str;
  141. }
  142. //搜索部门
  143. public function searchDepartmentIdAttr($query, $value, $data)
  144. {
  145. return $query->where('department_id', '=', $value);
  146. }
  147. //搜索编号
  148. public function searchNumberAttr($query, $value, $data)
  149. {
  150. return $query->where('number', '=', $value);
  151. }
  152. //搜索名称
  153. public function searchNameAttr($query, $value, $data)
  154. {
  155. return $query->where('name', '=', $value);
  156. }
  157. //搜索模型
  158. public function searchModelAttr($query, $value, $data)
  159. {
  160. return $query->where('model', '=', $value);
  161. }
  162. }