ControlManage.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace catchAdmin\alarm\model;
  3. use catcher\base\CatchModel as Model;
  4. use catchAdmin\permissions\model\Users;
  5. use catchAdmin\permissions\model\DataRangScopeTrait;
  6. use catchAdmin\system\model\SysDictData;
  7. use think\facade\Db;
  8. class ControlManage extends Model
  9. {
  10. use DataRangScopeTrait;
  11. // 表名
  12. public $name = 'control_manage';
  13. // 数据库字段映射
  14. public $field = array(
  15. 'id',
  16. // 布控类型
  17. 'name',
  18. 'type',
  19. 'state',
  20. // 布控开始时间
  21. 'start_time',
  22. // 布控结束时间
  23. 'end_time',
  24. // 布控对象
  25. 'control_obj',
  26. // 区域类型
  27. 'area_type',
  28. 'bw_type',
  29. 'bw_ids',
  30. 'revoke_time',
  31. 'revoke_res',
  32. 'phone',
  33. 'remark',
  34. // 创建人ID
  35. 'creator_id',
  36. // 创建时间
  37. 'created_at',
  38. // 更新时间
  39. 'updated_at',
  40. // 软删除
  41. 'deleted_at',
  42. );
  43. /**
  44. * 列表
  45. */
  46. public function getList()
  47. {
  48. $res=$this->dataRange()
  49. ->catchSearch()
  50. ->append(['type_text','rfid_type_text','state_text','timeRange','stations','bw_names','creator'])
  51. ->order($this->aliasField('id'), 'desc')
  52. ->paginate();
  53. return $res;
  54. }
  55. //根据姓名搜索
  56. public function searchNameAttr($query, $value, $data)
  57. {
  58. return $query->where('name', 'like', '%' . $value . '%');
  59. }
  60. public function getCreatorAttr($value){
  61. $val= $this->getData('creator_id');
  62. return Db::table('users')->where('id',$val)->value('realname');
  63. }
  64. public function getTimeRangeAttr($value){
  65. $start_time = $this->getData('start_time');
  66. $end_time = $this->getData('end_time');
  67. return [date('Y-m-d H:i:s',$start_time),date('Y-m-d H:i:s',$end_time)];
  68. }
  69. public function getStateTextAttr($value){
  70. $state = $this->getData('state');
  71. return (new SysDictData())->getValueByCode('ControlStateEnum', $state) ?: '';
  72. }
  73. public function getStationsAttr($value){
  74. $obj = $this->getData('control_obj');
  75. return $obj;
  76. }
  77. public function getBwNamesAttr($value){
  78. $ids = $this->getData('bw_ids');
  79. $idArr=explode(',',$ids);
  80. $name='';
  81. foreach($idArr as $val){
  82. $name.=','.Db::table('bw_list')->where('id',$val)->value('name');
  83. }
  84. return trim($name,',');
  85. }
  86. public function getTypeTextAttr($value){
  87. $type = $this->getData('type');
  88. if($type=='1'){
  89. return '车辆布控';
  90. }elseif($type=='2'){
  91. return '区域布控';
  92. }else{
  93. return '未知';
  94. }
  95. }
  96. public function getStartTimeAttr($value){
  97. return $value?date('Y-m-d H:i:s',$value):'';
  98. }
  99. public function getEndTimeAttr($value){
  100. return $value?date('Y-m-d H:i:s',$value):'';
  101. }
  102. public function getRevokeTimeAttr($value){
  103. return $value?date('Y-m-d H:i:s',$value):'';
  104. }
  105. }