DeviceMold.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * @Descripttion:
  4. * @version: 1.0.0
  5. * @Author: likang
  6. * @Date: 2022-05-27 13:34:31
  7. * @LastEditors: likang
  8. * @LastEditTime: 2022-06-25 16:36:52
  9. */
  10. namespace catchAdmin\hydraulic\model;
  11. use catcher\base\CatchModel as Model;
  12. use catchAdmin\system\model\SysDictData;
  13. use catchAdmin\permissions\model\DataRangScopeTrait;
  14. use \think\facade\Db;
  15. class DeviceMold extends Model
  16. {
  17. use DataRangScopeTrait;
  18. // 表名
  19. public $name = 'device_mold';
  20. // 数据库字段映射
  21. public $field = array(
  22. 'id',
  23. // 设备类型
  24. 'device_type',
  25. // 设备型号
  26. 'name',
  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'])
  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. $value=$this->getData('device_type');
  67. return (new SysDictData())->getValueByCode('DeviceType', $value) ?: '';
  68. }
  69. /**
  70. * 获取导入用户(文本)
  71. */
  72. public function getCreatorNameAttr($value)
  73. {
  74. $uid = $this->creator_id;
  75. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  76. }
  77. }