ControlManage.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. 'bw_ids',
  27. 'revoke_time',
  28. 'revoke_res',
  29. 'phone',
  30. 'remark',
  31. // 创建人ID
  32. 'creator_id',
  33. // 创建时间
  34. 'created_at',
  35. // 更新时间
  36. 'updated_at',
  37. // 软删除
  38. 'deleted_at',
  39. );
  40. /**
  41. * 列表
  42. */
  43. public function getList()
  44. {
  45. $res=$this->dataRange()
  46. ->catchSearch()
  47. ->append(['type_text','rfid_type_text','state_text','timeRange'])
  48. ->order($this->aliasField('id'), 'desc')
  49. ->paginate();
  50. return $res;
  51. }
  52. //根据姓名搜索
  53. public function searchNameAttr($query, $value, $data)
  54. {
  55. return $query->where('name', 'like', '%' . $value . '%');
  56. }
  57. public function getTimeRangeAttr($value){
  58. $start_time = $this->getData('start_time');
  59. $end_time = $this->getData('end_time');
  60. return [date('Y-m-d H:i:s',$start_time),date('Y-m-d H:i:s',$end_time)];
  61. }
  62. public function getStateTextAttr($value){
  63. $state = $this->getData('state');
  64. return (new SysDictData())->getValueByCode('ControlStateEnum', $state) ?: '';
  65. }
  66. public function getTypeTextAttr($value){
  67. $type = $this->getData('type');
  68. if($type=='1'){
  69. return '车辆布控';
  70. }elseif($type=='2'){
  71. return '区域布控';
  72. }else{
  73. return '未知';
  74. }
  75. }
  76. public function getStartTimeAttr($value){
  77. return $value?date('Y-m-d H:i:s',$value):'';
  78. }
  79. public function getEndTimeAttr($value){
  80. return $value?date('Y-m-d H:i:s',$value):'';
  81. }
  82. }