Plugins.php 5.6 KB
Newer Older
G
1.3.0  
gongfuxiang 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
devil_gong 已提交
5
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
G
1.3.0  
gongfuxiang 已提交
6 7 8 9 10
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
11
namespace app\index\controller;
G
1.3.0  
gongfuxiang 已提交
12

G
gongfuxiang 已提交
13 14
use app\service\PluginsService;

G
1.3.0  
gongfuxiang 已提交
15
/**
16
 * 应用调用入口
G
1.3.0  
gongfuxiang 已提交
17 18 19 20 21
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
22
class Plugins extends Common
G
1.3.0  
gongfuxiang 已提交
23 24
{
    /**
25 26 27 28 29 30 31 32 33 34 35 36 37 38
     * 构造方法
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-11-30
     * @desc    description
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * [Index 首页]
G
1.3.0  
gongfuxiang 已提交
39 40 41
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
42
     * @datetime 2017-02-22T16:50:32+0800
G
1.3.0  
gongfuxiang 已提交
43 44 45 46
     */
    public function Index()
    {
        // 参数
D
devil 已提交
47
        $params = $this->GetClassVars();
D
devil_gong 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

        // 请求参数校验
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'pluginsname',
                'error_msg'         => '应用名称有误',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'pluginscontrol',
                'error_msg'         => '应用控制器有误',
            ],
            [
                'checked_type'      => 'empty',
                'key_name'          => 'pluginsaction',
                'error_msg'         => '应用操作方法有误',
            ],
        ];
        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            if(IS_AJAX)
            {
72
                return DataReturn($ret, -5000);
D
devil_gong 已提交
73 74
            } else {
                $this->assign('msg', $ret);
G
gongfuxiang 已提交
75
                return $this->fetch('public/tips_error');
D
devil_gong 已提交
76 77 78 79
            }
        }

        // 应用名称/控制器/方法
D
devil 已提交
80 81 82 83
        $pluginsname = $params['data_request']['pluginsname'];
        $pluginscontrol = strtolower($params['data_request']['pluginscontrol']);
        $pluginsaction = strtolower($params['data_request']['pluginsaction']);
        unset($params['data_request']['pluginsname'], $params['data_request']['pluginscontrol'], $params['data_request']['pluginsaction']);
G
1.3.0  
gongfuxiang 已提交
84 85

        // 视图初始化
86
        $this->PluginsViewInit($pluginsname, $pluginscontrol, $pluginsaction);
G
1.3.0  
gongfuxiang 已提交
87

88 89
        // 编辑器文件存放地址定义
        $this->assign('editor_path_type', 'plugins_'.$pluginsname);
G
1.3.0  
gongfuxiang 已提交
90

D
devil 已提交
91 92 93
        // 调用
        $ret = PluginsService::PluginsControlCall($pluginsname, $pluginscontrol, $pluginsaction, 'index', $params);
        if($ret['code'] == 0)
D
devil_gong 已提交
94
        {
D
devil 已提交
95
            return $ret['data'];
D
devil_gong 已提交
96 97
        }

D
devil 已提交
98 99
        // 调用失败
        if(IS_AJAX)
G
gongfuxiang 已提交
100
        {
D
devil 已提交
101 102 103 104
            return $ret;
        } else {
            $this->assign('msg', $ret['msg']);
            return $this->fetch('public/tips_error');
G
gongfuxiang 已提交
105 106 107
        }
    }

D
devil 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    /**
     * 获取类属性数据
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-07
     * @desc    description
     */
    public function GetClassVars()
    {
        $data = [];
        $vers = get_class_vars(get_class());
        foreach($vers as $k=>$v)
        {
            if(property_exists($this, $k))
            {
                $data[$k] = $this->$k;
            }
        }
        return $data;
    }

G
1.3.0  
gongfuxiang 已提交
130 131 132 133 134 135
    /**
     * 视图初始化
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-02-07T22:46:29+0800
D
devil_gong 已提交
136 137 138
     * @param    [string]                   $plugins_name       [应用名称]
     * @param    [string]                   $plugins_control    [控制器名称]
     * @param    [string]                   $plugins_action     [方法]
G
1.3.0  
gongfuxiang 已提交
139
     */
140
    public function PluginsViewInit($plugins_name, $plugins_control, $plugins_action)
G
1.3.0  
gongfuxiang 已提交
141
    {
D
钱包  
devil_gong 已提交
142 143 144 145 146
        // 应用名称/控制器/方法
        $this->assign('plugins_name', $plugins_name);
        $this->assign('plugins_control', $plugins_control);
        $this->assign('plugins_action', $plugins_action);

G
1.3.0  
gongfuxiang 已提交
147
        // 当前操作名称
148
        $module_name = 'plugins';
G
1.3.0  
gongfuxiang 已提交
149

D
devil_gong 已提交
150 151 152
        // 模块组
        $group = 'index';

G
1.3.0  
gongfuxiang 已提交
153
        // 控制器静态文件状态css,js
D
devil_gong 已提交
154
        $module_css = $module_name.DS.'css'.DS.$plugins_name.DS.$group.DS.$plugins_control;
D
devil_gong 已提交
155
        $module_css .= file_exists(ROOT_PATH.'static'.DS.$module_css.'.'.$plugins_action.'.css') ? '.'.$plugins_action.'.css' : '.css';
G
1.3.0  
gongfuxiang 已提交
156 157
        $this->assign('module_css', file_exists(ROOT_PATH.'static'.DS.$module_css) ? $module_css : '');

D
devil_gong 已提交
158
        $module_js = $module_name.DS.'js'.DS.$plugins_name.DS.$group.DS.$plugins_control;
D
devil_gong 已提交
159
        $module_js .= file_exists(ROOT_PATH.'static'.DS.$module_js.'.'.$plugins_action.'.js') ? '.'.$plugins_action.'.js' : '.js';
G
1.3.0  
gongfuxiang 已提交
160
        $this->assign('module_js', file_exists(ROOT_PATH.'static'.DS.$module_js) ? $module_js : '');
D
devil_gong 已提交
161 162 163 164 165 166

        // 应用公共css,js
        $plugins_css = $module_name.DS.'css'.DS.$plugins_name.DS.$group.DS.'common.css';
        $this->assign('plugins_css', file_exists(ROOT_PATH.'static'.DS.$plugins_css) ? $plugins_css : '');
        $plugins_js = $module_name.DS.'js'.DS.$plugins_name.DS.$group.DS.'common.js';
        $this->assign('plugins_js', file_exists(ROOT_PATH.'static'.DS.$plugins_js) ? $plugins_js : '');
G
1.3.0  
gongfuxiang 已提交
167 168 169
    }
}
?>