1
0

Base.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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'])) {
  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. $this->assign('MAC_VERSION',config('version')['code']);
  34. }
  35. public function check_auth($c,$a)
  36. {
  37. $c = strtolower($c);
  38. $a = strtolower($a);
  39. $auths = $this->_admin['admin_auth'] . ',index/index,index/welcome,index/logout,';
  40. $cur = ','.$c.'/'.$a.',';
  41. if($this->_admin['admin_id'] =='1'){
  42. return true;
  43. }
  44. elseif(strpos($auths,$cur)===false){
  45. return false;
  46. }
  47. else{
  48. return true;
  49. }
  50. }
  51. public function _cache_clear()
  52. {
  53. if(ENTRANCE=='admin') {
  54. //播放器配置缓存
  55. $vodplayer = config('vodplayer');
  56. $voddowner = config('voddowner');
  57. $vodserver = config('vodserver');
  58. $player = [];
  59. foreach ($vodplayer as $k => $v) {
  60. $player[$k] = [
  61. 'show' => (string)$v['show'],
  62. 'des' => (string)$v['des'],
  63. 'ps' => (string)$v['ps'],
  64. 'parse' => (string)$v['parse'],
  65. ];
  66. }
  67. $downer = [];
  68. foreach ($voddowner as $k => $v) {
  69. $downer[$k] = [
  70. 'show' => (string)$v['show'],
  71. 'des' => (string)$v['des'],
  72. 'ps' => (string)$v['ps'],
  73. 'parse' => (string)$v['parse'],
  74. ];
  75. }
  76. $server = [];
  77. foreach ($vodserver as $k => $v) {
  78. $server[$k] = [
  79. 'show' => (string)$v['show'],
  80. 'des' => (string)$v['des']
  81. ];
  82. }
  83. $content = 'MacPlayerConfig.player_list=' . json_encode($player) . ',MacPlayerConfig.downer_list=' . json_encode($downer) . ',MacPlayerConfig.server_list=' . json_encode($server) . ';';
  84. $path = './static/js/playerconfig.js';
  85. if (!file_exists($path)) {
  86. $path .= '.bak';
  87. }
  88. $fc = @file_get_contents($path);
  89. if(!empty($fc)){
  90. $jsb = mac_get_body($fc, '//缓存开始', '//缓存结束');
  91. $fc = str_replace($jsb, "\r\n" . $content . "\r\n", $fc);
  92. @fwrite(fopen('./static/js/playerconfig.js', 'wb'), $fc);
  93. }
  94. }
  95. Dir::delDir(RUNTIME_PATH.'cache/');
  96. Dir::delDir(RUNTIME_PATH.'log/');
  97. Dir::delDir(RUNTIME_PATH.'temp/');
  98. Cache::clear();
  99. return true;
  100. }
  101. }