DeviceMold.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 DeviceMold extends Model
  8. {
  9. use DataRangScopeTrait;
  10. // 表名
  11. public $name = 'device_mold';
  12. // 数据库字段映射
  13. public $field = array(
  14. 'id',
  15. // 设备类型
  16. 'device_type',
  17. // 设备型号
  18. 'name',
  19. // 创建人ID
  20. 'creator_id',
  21. // 创建时间
  22. 'created_at',
  23. // 更新时间
  24. 'updated_at',
  25. // 软删除
  26. 'deleted_at',
  27. );
  28. /**
  29. * 获取列表
  30. */
  31. public function getList()
  32. {
  33. $res = $this->dataRange()
  34. ->catchSearch()
  35. ->append(['device_type_name','creator_name'])
  36. ->order($this->aliasField('id'), 'desc')
  37. ->paginate();
  38. return $res;
  39. }
  40. /**
  41. * 名称搜索
  42. */
  43. public function searchNameAttr($query, $value, $data)
  44. {
  45. return $query->where('name', 'like', '%'.$value.'%');
  46. }
  47. /**
  48. * 设备类型搜索
  49. */
  50. public function searchDeviceTypeAttr($query, $value, $data)
  51. {
  52. return $query->where('device_type', '=', $value);
  53. }
  54. /**
  55. * 设备类型名称
  56. */
  57. public function getDeviceTypeNameAttr(){
  58. $value=$this->getData('device_type');
  59. return (new SysDictData())->getValueByCode('DeviceType', $value) ?: '';
  60. }
  61. /**
  62. * 获取导入用户(文本)
  63. */
  64. public function getCreatorNameAttr($value)
  65. {
  66. $uid = $this->creator_id;
  67. return Db::table('users')->where('id', $uid)->value('username') ?: '';
  68. }
  69. }