BwList.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace catchAdmin\alarm\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\DataRangScopeTrait;
  5. use catchAdmin\system\model\SysDictData;
  6. class BwList extends Model
  7. {
  8. use DataRangScopeTrait;
  9. // 表名
  10. public $name = 'bw_list';
  11. // 数据库字段映射
  12. public $field = array(
  13. 'id',
  14. // 名称
  15. 'name',
  16. // 名单类型(0-黑名单,1-白名单)
  17. 'type',
  18. // 标签类型
  19. 'rfid_type',
  20. // 启用停用(0-停用,1-启用)
  21. 'state',
  22. // 备注
  23. 'remark',
  24. // 创建人ID
  25. 'creator_id',
  26. // 创建时间
  27. 'created_at',
  28. // 更新时间
  29. 'updated_at',
  30. // 软删除
  31. 'deleted_at',
  32. );
  33. /**
  34. * 列表
  35. */
  36. public function getList()
  37. {
  38. $res=$this->dataRange()
  39. ->catchSearch()
  40. ->append(['type_text','rfid_type_text'])
  41. ->order($this->aliasField('id'), 'desc')
  42. ->paginate();
  43. return $res;
  44. }
  45. //根据姓名搜索
  46. public function searchNameAttr($query, $value, $data)
  47. {
  48. return $query->where('name', 'like', '%' . $value . '%');
  49. }
  50. public function searchTypeAttr($query, $value, $data)
  51. {
  52. return $query->where('type', $value );
  53. }
  54. public function searchStateAttr($query, $value, $data)
  55. {
  56. return $query->where('state', $value );
  57. }
  58. public function getTypeAttr($value){
  59. return (string)$value;
  60. }
  61. public function getTypeTextAttr($value){
  62. $type = $this->getData('type');
  63. return $type ?'白名单': '黑名单';
  64. }
  65. public function getRfidTypeTextAttr($value){
  66. $rfid_type = $this->getData('rfid_type');
  67. return (new SysDictData())->getValueByCode('RFID_TYPE_OPTION', $rfid_type) ?: '';
  68. }
  69. }