作者 lihan
1 个管道 的构建 通过 耗费 3 秒

赠送积分和角色管理

@@ -42,11 +42,6 @@ class IndexController extends HomeBaseController @@ -42,11 +42,6 @@ class IndexController extends HomeBaseController
42 ]); 42 ]);
43 } 43 }
44 44
45 - //强制绑定手机页面  
46 - public function login() {  
47 - return $this->fetch();  
48 - }  
49 -  
50 /** 45 /**
51 * 易连云打印机demo 46 * 易连云打印机demo
52 */ 47 */
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: yhbr
  5 + * Date: 2018/11/10
  6 + * Time: 9:50
  7 + */
  8 +
  9 +namespace app\login\controller;
  10 +
  11 +
  12 +use cmf\controller\NoneBaseController;
  13 +
  14 +class LoginController extends NoneBaseController
  15 +{
  16 +
  17 + //强制绑定手机页面
  18 + public function login() {
  19 + return $this->fetch();
  20 + }
  21 +
  22 +}
@@ -60,12 +60,12 @@ class HomeBaseController extends BaseController @@ -60,12 +60,12 @@ class HomeBaseController extends BaseController
60 } 60 }
61 } 61 }
62 }else { 62 }else {
63 - if(Db::name('user')->where(['id'=>session('user.id')])->value('mobile') == null) {  
64 - $this->redirect(url('index/Index/login'));  
65 - } 63 + echo session('user.id');
66 } 64 }
67 }else { 65 }else {
68 - $this->error('请从微信浏览器打开'); 66 + if(Db::name('user')->where(['id'=>session('user.id')])->value('mobile') == null) {
  67 + $this->redirect(url('login/Login/login'));
  68 + }
69 } 69 }
70 70
71 71
  1 +<?php
  2 +// +----------------------------------------------------------------------
  3 +// | bronet [ 以客户为中心 以奋斗者为本 ]
  4 +// +----------------------------------------------------------------------
  5 +// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
  6 +// +----------------------------------------------------------------------
  7 +// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8 +// +---------------------------------------------------------------------
  9 +// | Author: Dean <zxxjjforever@163.com>
  10 +// +----------------------------------------------------------------------
  11 +namespace cmf\controller;
  12 +
  13 +use app\user\model\UserModel;
  14 +use think\Db;
  15 +use app\admin\model\ThemeModel;
  16 +use think\View;
  17 +
  18 +class NoneBaseController extends BaseController
  19 +{
  20 +
  21 + public function _initialize()
  22 + {
  23 +
  24 + parent::_initialize(); // TODO: Change the autogenerated stub
  25 + // 监听home_init
  26 + hook('home_init');
  27 + parent::_initialize();
  28 + $siteInfo = cmf_get_site_info();
  29 + View::share('site_info', $siteInfo);
  30 + }
  31 +
  32 + public function _initializeView()
  33 + {
  34 + $cmfThemePath = config('cmf_theme_path');
  35 + $cmfDefaultTheme = cmf_get_current_theme();
  36 +
  37 + $themePath = "{$cmfThemePath}{$cmfDefaultTheme}";
  38 +
  39 + $root = cmf_get_root();
  40 + //使cdn设置生效
  41 + $cdnSettings = cmf_get_option('cdn_settings');
  42 + if (empty($cdnSettings['cdn_static_root'])) {
  43 + $viewReplaceStr = [
  44 + '__ROOT__' => $root,
  45 + '__TMPL__' => "{$root}/{$themePath}",
  46 + '__STATIC__' => "{$root}/static",
  47 + '__WEB_ROOT__' => $root
  48 + ];
  49 + } else {
  50 + $cdnStaticRoot = rtrim($cdnSettings['cdn_static_root'], '/');
  51 + $viewReplaceStr = [
  52 + '__ROOT__' => $root,
  53 + '__TMPL__' => "{$cdnStaticRoot}/{$themePath}",
  54 + '__STATIC__' => "{$cdnStaticRoot}/static",
  55 + '__WEB_ROOT__' => $cdnStaticRoot
  56 + ];
  57 + }
  58 +
  59 + $viewReplaceStr = array_merge(config('view_replace_str'), $viewReplaceStr);
  60 + config('template.view_base', "{$themePath}/");
  61 + config('view_replace_str', $viewReplaceStr);
  62 +
  63 + $themeErrorTmpl = "{$themePath}/error.html";
  64 + if (file_exists_case($themeErrorTmpl)) {
  65 + config('dispatch_error_tmpl', $themeErrorTmpl);
  66 + }
  67 +
  68 + $themeSuccessTmpl = "{$themePath}/success.html";
  69 + if (file_exists_case($themeSuccessTmpl)) {
  70 + config('dispatch_success_tmpl', $themeSuccessTmpl);
  71 + }
  72 +
  73 +
  74 + }
  75 +
  76 + /**
  77 + * 加载模板输出
  78 + * @access protected
  79 + * @param string $template 模板文件名
  80 + * @param array $vars 模板输出变量
  81 + * @param array $replace 模板替换
  82 + * @param array $config 模板参数
  83 + * @return mixed
  84 + */
  85 + protected function fetch($template = '', $vars = [], $replace = [], $config = [])
  86 + {
  87 + $template = $this->parseTemplate($template);
  88 + $more = $this->getThemeFileMore($template);
  89 + $this->assign('theme_vars', $more['vars']);
  90 + $this->assign('theme_widgets', $more['widgets']);
  91 + return parent::fetch($template, $vars, $replace, $config);
  92 + }
  93 +
  94 + /**
  95 + * 自动定位模板文件
  96 + * @access private
  97 + * @param string $template 模板文件规则
  98 + * @return string
  99 + */
  100 + private function parseTemplate($template)
  101 + {
  102 + // 分析模板文件规则
  103 + $request = $this->request;
  104 + // 获取视图根目录
  105 + if (strpos($template, '@')) {
  106 + // 跨模块调用
  107 + list($module, $template) = explode('@', $template);
  108 + }
  109 +
  110 + $viewBase = config('template.view_base');
  111 +
  112 + if ($viewBase) {
  113 + // 基础视图目录
  114 + $module = isset($module) ? $module : $request->module();
  115 + $path = $viewBase . ($module ? $module . DS : '');
  116 + } else {
  117 + $path = isset($module) ? APP_PATH . $module . DS . 'view' . DS : config('template.view_path');
  118 + }
  119 +
  120 + $depr = config('template.view_depr');
  121 + if (0 !== strpos($template, '/')) {
  122 + $template = str_replace(['/', ':'], $depr, $template);
  123 + $controller = cmf_parse_name($request->controller());
  124 + if ($controller) {
  125 + if ('' == $template) {
  126 + // 如果模板文件名为空 按照默认规则定位
  127 + $template = str_replace('.', DS, $controller) . $depr . $request->action();
  128 + } elseif (false === strpos($template, $depr)) {
  129 + $template = str_replace('.', DS, $controller) . $depr . $template;
  130 + }
  131 + }
  132 + } else {
  133 + $template = str_replace(['/', ':'], $depr, substr($template, 1));
  134 + }
  135 + return $path . ltrim($template, '/') . '.' . ltrim(config('template.view_suffix'), '.');
  136 + }
  137 +
  138 + /**
  139 + * 获取模板文件变量
  140 + * @param string $file
  141 + * @param string $theme
  142 + * @return array
  143 + */
  144 + private function getThemeFileMore($file, $theme = "")
  145 + {
  146 +
  147 + //TODO 增加缓存
  148 + $theme = empty($theme) ? cmf_get_current_theme() : $theme;
  149 +
  150 + // 调试模式下自动更新模板
  151 + if (APP_DEBUG) {
  152 + $themeModel = new ThemeModel();
  153 + $themeModel->updateTheme($theme);
  154 + }
  155 +
  156 + $themePath = config('cmf_theme_path');
  157 + $file = str_replace('\\', '/', $file);
  158 + $file = str_replace('//', '/', $file);
  159 + $file = str_replace(['.html', '.php', $themePath . $theme . "/"], '', $file);
  160 +
  161 + $files = Db::name('theme_file')->field('more')->where(['theme' => $theme])->where(function ($query) use ($file) {
  162 + $query->where(['is_public' => 1])->whereOr(['file' => $file]);
  163 + })->select();
  164 +
  165 + $vars = [];
  166 + $widgets = [];
  167 + foreach ($files as $file) {
  168 + $oldMore = json_decode($file['more'], true);
  169 + if (!empty($oldMore['vars'])) {
  170 + foreach ($oldMore['vars'] as $varName => $var) {
  171 + $vars[$varName] = $var['value'];
  172 + }
  173 + }
  174 +
  175 + if (!empty($oldMore['widgets'])) {
  176 + foreach ($oldMore['widgets'] as $widgetName => $widget) {
  177 +
  178 + $widgetVars = [];
  179 + if (!empty($widget['vars'])) {
  180 + foreach ($widget['vars'] as $varName => $var) {
  181 + $widgetVars[$varName] = $var['value'];
  182 + }
  183 + }
  184 +
  185 + $widget['vars'] = $widgetVars;
  186 + $widgets[$widgetName] = $widget;
  187 + }
  188 + }
  189 + }
  190 +
  191 + return ['vars' => $vars, 'widgets' => $widgets];
  192 + }
  193 +
  194 + public function checkUserLogin()
  195 + {
  196 + $userId = cmf_get_current_user_id();
  197 + if (empty($userId)) {
  198 + $this->error("用户尚未登录", url("user/login/index"));
  199 + }
  200 + }
  201 +
  202 +}