Base.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. use app\common\controller\All;
  5. use think\Cache;
  6. use app\common\util\Dir;
  7. class Base extends All
  8. {
  9. var $_admin;
  10. var $_pagesize;
  11. var $_makesize;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. //判断用户登录状态
  16. if(in_array($this->_cl,['Index']) && in_array($this->_ac,['login','logout'])) {
  17. }
  18. elseif(ENTRANCE=='api' && in_array($this->_cl,['Timming']) && in_array($this->_ac,['index'])){
  19. }
  20. else {
  21. $res = model('Admin')->checkLogin();
  22. if ($res['code'] > 1) {
  23. return $this->redirect('index/login');
  24. }
  25. $this->_admin = $res['info'];
  26. $this->_pagesize = $GLOBALS['config']['app']['pagesize'];
  27. $this->_makesize = $GLOBALS['config']['app']['makesize'];
  28. if($this->_cl!='Update' && !$this->check_auth($this->_cl,$this->_ac)){
  29. return $this->error(lang('permission_denied'));
  30. }
  31. }
  32. $this->assign('cl',$this->_cl);
  33. }
  34. public function check_auth($c,$a)
  35. {
  36. $c = strtolower($c);
  37. $a = strtolower($a);
  38. $auths = $this->_admin['admin_auth'] . ',index/index,index/welcome,';
  39. $cur = ','.$c.'/'.$a.',';
  40. if($this->_admin['admin_id'] =='1'){
  41. return true;
  42. }
  43. elseif(strpos($auths,$cur)===false){
  44. return false;
  45. }
  46. else{
  47. return true;
  48. }
  49. }
  50. public function _cache_clear()
  51. {
  52. //播放器配置缓存
  53. $vodplayer = config('vodplayer');
  54. $voddowner = config('voddowner');
  55. $vodserver = config('vodserver');
  56. $player = [];
  57. foreach($vodplayer as $k=>$v){
  58. $player[$k] = [
  59. 'show'=>(string)$v['show'],
  60. 'des'=>(string)$v['des'],
  61. 'ps'=>(string)$v['ps'],
  62. 'parse'=>(string)$v['parse'],
  63. ];
  64. }
  65. $downer = [];
  66. foreach($voddowner as $k=>$v){
  67. $downer[$k] = [
  68. 'show'=>(string)$v['show'],
  69. 'des'=>(string)$v['des'],
  70. 'ps'=>(string)$v['ps'],
  71. 'parse'=>(string)$v['parse'],
  72. ];
  73. }
  74. $server = [];
  75. foreach($vodserver as $k=>$v){
  76. $server[$k] = [
  77. 'show'=>(string)$v['show'],
  78. 'des'=>(string)$v['des']
  79. ];
  80. }
  81. $content = 'MacPlayerConfig.player_list='.json_encode($player) . ',MacPlayerConfig.downer_list='.json_encode($downer) . ',MacPlayerConfig.server_list='.json_encode($server) .';';
  82. $path = './static/js/playerconfig.js';
  83. if(!file_exists($path)){ $path .= '.bak'; }
  84. $fc = @file_get_contents( $path );
  85. $jsb = mac_get_body($fc,'//缓存开始','//缓存结束');
  86. $fc = str_replace($jsb,"\r\n".$content."\r\n",$fc);
  87. @fwrite(fopen('./static/js/playerconfig.js','wb'),$fc);
  88. Dir::delDir(RUNTIME_PATH.'cache/');
  89. Dir::delDir(RUNTIME_PATH.'log/');
  90. Dir::delDir(RUNTIME_PATH.'temp/');
  91. Cache::clear();
  92. return true;
  93. }
  94. }