IndexController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use app\weixin\model\Member;
  13. use cmf\controller\AdminBaseController;
  14. use think\Db;
  15. use app\admin\model\AdminMenuModel;
  16. class IndexController extends AdminBaseController
  17. {
  18. public function initialize()
  19. {
  20. $adminSettings = cmf_get_option('admin_settings');
  21. if (empty($adminSettings['admin_password']) || $this->request->path() == $adminSettings['admin_password']) {
  22. $adminId = cmf_get_current_admin_id();
  23. if (empty($adminId)) {
  24. session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码
  25. }
  26. }
  27. parent::initialize();
  28. }
  29. /**
  30. * 后台首页
  31. */
  32. public function index()
  33. {
  34. $content = hook_one('admin_index_index_view');
  35. if (!empty($content)) {
  36. return $content;
  37. }
  38. $adminMenuModel = new AdminMenuModel();
  39. $menus = cache('admin_menus_' . cmf_get_current_admin_id(), '', null, 'admin_menus');
  40. if (empty($menus)) {
  41. $menus = $adminMenuModel->menuTree();
  42. cache('admin_menus_' . cmf_get_current_admin_id(), $menus, null, 'admin_menus');
  43. }
  44. $userType = Db::name('user')->where(['id'=> cmf_get_current_admin_id()])->value('user_type');
  45. if($menus){
  46. foreach ($menus as $key => &$item){
  47. if(preg_match("/shop/", $item['id']) || $item['id'] == '129admin' || ($userType==1 && $item['id'] == '163admin') || ($userType==3 && $item['id'] == '49admin')){
  48. // if(preg_match("/shop/", $item['id']) || ($userType==1 && $item['id'] == '163admin')){
  49. unset($menus[$key]);
  50. }
  51. }
  52. }
  53. $this->assign("menus", $menus);
  54. $result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select();
  55. $menusTmp = array();
  56. foreach ($result as $item){
  57. //去掉/ _ 全部小写。作为索引。
  58. $indexTmp = $item['app'].$item['controller'].$item['action'];
  59. $indexTmp = preg_replace("/[\\/|_]/","",$indexTmp);
  60. $indexTmp = strtolower($indexTmp);
  61. $menusTmp[$indexTmp] = $item;
  62. }
  63. $this->assign("menus_js_var",json_encode($menusTmp));
  64. return $this->fetch();
  65. }
  66. }