ControlManage.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ControlManage extends Model
  7. {
  8. use DataRangScopeTrait;
  9. // 表名
  10. public $name = 'control_manage';
  11. // 数据库字段映射
  12. public $field = array(
  13. 'id',
  14. // 布控类型
  15. 'name',
  16. 'type',
  17. 'state',
  18. // 布控开始时间
  19. 'start_time',
  20. // 布控结束时间
  21. 'end_time',
  22. // 布控对象
  23. 'control_obj',
  24. // 区域类型
  25. 'area_type',
  26. 'revoke_time',
  27. 'revoke_res',
  28. 'phone',
  29. 'remark',
  30. // 创建人ID
  31. 'creator_id',
  32. // 创建时间
  33. 'created_at',
  34. // 更新时间
  35. 'updated_at',
  36. // 软删除
  37. 'deleted_at',
  38. );
  39. /**
  40. * 列表
  41. */
  42. public function getList()
  43. {
  44. $res=$this->dataRange()
  45. ->catchSearch()
  46. ->append(['type_text','rfid_type_text','state_text','timeRange'])
  47. ->order($this->aliasField('id'), 'desc')
  48. ->paginate();
  49. return $res;
  50. }
  51. //根据姓名搜索
  52. public function searchNameAttr($query, $value, $data)
  53. {
  54. return $query->where('name', 'like', '%' . $value . '%');
  55. }
  56. public function getTimeRangeAttr($value){
  57. $start_time = $this->getData('start_time');
  58. $end_time = $this->getData('end_time');
  59. return [date('Y-m-d H:i:s',$start_time),date('Y-m-d H:i:s',$end_time)];
  60. }
  61. public function getStateTextAttr($value){
  62. $state = $this->getData('state');
  63. return (new SysDictData())->getValueByCode('ControlStateEnum', $state) ?: '';
  64. }
  65. public function getTypeTextAttr($value){
  66. $type = $this->getData('type');
  67. if($type=='1'){
  68. return '车辆布控';
  69. }elseif($type=='2'){
  70. return '区域布控';
  71. }else{
  72. return '未知';
  73. }
  74. }
  75. public function getStartTimeAttr($value){
  76. return $value?date('Y-m-d H:i:s',$value):'';
  77. }
  78. public function getEndTimeAttr($value){
  79. return $value?date('Y-m-d H:i:s',$value):'';
  80. }
  81. }