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

D
devil_gong 已提交
13
use think\Controller;
G
1.3.0  
gongfuxiang 已提交
14 15
use app\service\PluginsService;
/**
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
 */
D
devil_gong 已提交
22
class Hook extends Controller
G
1.3.0  
gongfuxiang 已提交
23
{
G
gongfuxiang 已提交
24 25 26 27 28 29 30 31
    /**
     * 应用响应入口
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-02-09T14:25:44+0800
     * @param    [array]                    $params [输入参数]
     */
G
1.3.0  
gongfuxiang 已提交
32 33
    public function run($params = [])
    {
G
gongfuxiang 已提交
34
        // 是否控制器钩子
35
        if(isset($params['is_control']) && $params['is_control'] === true && !empty($params['hook_name']))
G
1.3.0  
gongfuxiang 已提交
36
        {
37
            return DataReturn('无需处理', 0);
G
1.3.0  
gongfuxiang 已提交
38 39 40

        // 默认返回视图
        } else {
G
gongfuxiang 已提交
41
            return $this->html($params);
G
1.3.0  
gongfuxiang 已提交
42 43 44 45 46 47 48 49 50
        }
    }

    /**
     * 视图
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-02-06T16:16:34+0800
G
gongfuxiang 已提交
51
     * @param    [array]          $params [输入参数]
G
1.3.0  
gongfuxiang 已提交
52
     */
G
gongfuxiang 已提交
53
    public function html($params = [])
G
1.3.0  
gongfuxiang 已提交
54
    {
G
gongfuxiang 已提交
55 56 57 58 59 60
        // 当前模块/控制器/方法
        $module_name = strtolower(request()->module());
        $controller_name = strtolower(request()->controller());
        $action_name = strtolower(request()->action());

        // 获取应用数据
61
        $ret = PluginsService::PluginsData('commontopmaxpicture', ['images']);
G
1.3.0  
gongfuxiang 已提交
62 63
        if($ret['code'] == 0)
        {
D
devil_gong 已提交
64 65 66 67 68 69
            // 图片是否为空
            if(empty($ret['data']['images']))
            {
                return '';
            }

G
gongfuxiang 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
            // 有效时间
            if(!empty($ret['data']['time_start']))
            {
                // 是否已开始
                if(strtotime($ret['data']['time_start']) > time())
                {
                    return '';
                }
            }
            if(!empty($ret['data']['time_end']))
            {
                // 是否已结束
                if(strtotime($ret['data']['time_end']) < time())
                {
                    return '';
                }
            }

            // 非全局
            if($ret['data']['is_overall'] != 1)
            {
                // 非首页则空
                if($module_name.$controller_name.$action_name != 'indexindexindex')
                {
                    return '';
                }
            }

D
devil_gong 已提交
98 99
            $this->assign('data', $ret['data']);
            return $this->fetch('../../../plugins/view/commontopmaxpicture/index/content');
G
1.3.0  
gongfuxiang 已提交
100
        } else {
D
devil_gong 已提交
101
            return $ret['msg'];
G
1.3.0  
gongfuxiang 已提交
102 103 104 105
        }
    }
}
?>