ControlManage.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. 'is_sent',
  33. 'sent_limit',
  34. 'phone',
  35. 'remark',
  36. // 创建人ID
  37. 'creator_id',
  38. // 创建时间
  39. 'created_at',
  40. // 更新时间
  41. 'updated_at',
  42. // 软删除
  43. 'deleted_at',
  44. );
  45. /**
  46. * 列表
  47. */
  48. public function getList()
  49. {
  50. $res=$this->dataRange()
  51. ->catchSearch()
  52. ->append(['type_text','rfid_type_text','state_text','timeRange','stations','bw_names','creator','is_sent_text','sent_limit_text'])
  53. ->order($this->aliasField('id'), 'desc')
  54. ->paginate();
  55. return $res;
  56. }
  57. //根据姓名搜索
  58. public function searchNameAttr($query, $value, $data)
  59. {
  60. return $query->where('name', 'like', '%' . $value . '%');
  61. }
  62. public function getIsSentTextAttr($value){
  63. $val= $this->getData('is_sent');
  64. return $val?'推送':'不推送';
  65. }
  66. public function getSentLimitTextAttr($value){
  67. $val= $this->getData('sent_limit');
  68. return (new SysDictData())->getValueByCode('SentLimitOption', $val) ?: '';
  69. }
  70. public function getCreatorAttr($value){
  71. $val= $this->getData('creator_id');
  72. return Db::table('users')->where('id',$val)->value('realname');
  73. }
  74. public function getTimeRangeAttr($value){
  75. $start_time = $this->getData('start_time');
  76. $end_time = $this->getData('end_time');
  77. return [date('Y-m-d H:i:s',$start_time),date('Y-m-d H:i:s',$end_time)];
  78. }
  79. public function getStateTextAttr($value){
  80. $state = $this->getData('state');
  81. return (new SysDictData())->getValueByCode('ControlStateEnum', $state) ?: '';
  82. }
  83. public function getStationsAttr($value){
  84. $obj = $this->getData('control_obj');
  85. return $obj;
  86. }
  87. public function getBwNamesAttr($value){
  88. $ids = $this->getData('bw_ids');
  89. $idArr=explode(',',$ids);
  90. $name='';
  91. foreach($idArr as $val){
  92. $name.=','.Db::table('bw_list')->where('id',$val)->value('name');
  93. }
  94. return trim($name,',');
  95. }
  96. public function getTypeTextAttr($value){
  97. $type = $this->getData('type');
  98. if($type=='1'){
  99. return '车辆布控';
  100. }elseif($type=='2'){
  101. return '区域布控';
  102. }else{
  103. return '未知';
  104. }
  105. }
  106. public function getStartTimeAttr($value){
  107. return $value?date('Y-m-d H:i:s',$value):'';
  108. }
  109. public function getEndTimeAttr($value){
  110. return $value?date('Y-m-d H:i:s',$value):'';
  111. }
  112. public function getRevokeTimeAttr($value){
  113. return $value?date('Y-m-d H:i:s',$value):'';
  114. }
  115. }