Hook.php 8.7 KB
Newer Older
D
devil_gong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?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\commonrightnavigation;

use app\service\PluginsService;
use app\service\BuyService;

/**
G
优化  
gongfuxiang 已提交
17
 * 右侧快捷导航 - 钩子入口
D
devil_gong 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class Hook
{
    /**
     * 应用响应入口
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-02-09T14:25:44+0800
     * @param    [array]                    $params [输入参数]
     */
    public function run($params = [])
    {
        // 是否控制器钩子
        // is_control 当前为控制器业务处理
        // hook_name 钩子名称
        if(isset($params['is_control']) && $params['is_control'] === true && !empty($params['hook_name']))
        {
            // 参数一   描述
            // 参数二   0 为处理成功, 负数为失败
            // 参数三   返回数据
            return DataReturn('返回描述', 0);

        // 默认返回视图
        } else {
            if(!empty($params['hook_name']))
            {
                switch($params['hook_name'])
                {
G
gongfuxiang 已提交
51 52
                    case 'plugins_css' :
                        $ret = __MY_ROOT_PUBLIC__.'static/plugins/css/commonrightnavigation/style.css';
D
devil_gong 已提交
53 54
                        break;

G
gongfuxiang 已提交
55 56
                    case 'plugins_js' :
                        $ret = __MY_ROOT_PUBLIC__.'static/plugins/js/commonrightnavigation/style.js';
D
devil_gong 已提交
57 58
                        break;

G
gongfuxiang 已提交
59 60
                    case 'plugins_view_common_bottom' :
                        $ret = $this->html($params);
D
devil_gong 已提交
61 62 63 64 65 66 67 68 69 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111
                        break;

                    default :
                        $ret = '';
                }
                return $ret;
            } else {
                return '';
            }
        }
    }

    /**
     * 视图
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-02-06T16:16:34+0800
     * @param    [array]          $params [输入参数]
     */
    public function html($params = [])
    {
        // 当前模块/控制器/方法
        $module_name = strtolower(request()->module());
        $controller_name = strtolower(request()->controller());
        $action_name = strtolower(request()->action());

        // 获取应用数据
        $ret = PluginsService::PluginsData('commonrightnavigation', ['alipay_mini_qrcode_images', 'alipay_fuwu_qrcode_images', 'weixin_mini_qrcode_images', 'weixin_fuwu_qrcode_images']);

        // html拼接
        $html = '<div class="commonrightnavigation-right-nav">';
        $content = '';
        if($ret['code'] == 0)
        {
            // 非全局
            if($ret['data']['is_overall'] != 1)
            {
                // 非首页则空
                if($module_name.$controller_name.$action_name != 'indexindexindex')
                {
                    return '';
                }
            }

            // 是否新窗口打开
            $is_new_window_open = (isset($ret['data']['is_new_window_open']) && $ret['data']['is_new_window_open'] == 1) ? 'target="_blank"' : '';

            // 购物车总数
            $cart_total = BuyService::UserCartTotal(['user'=>$params['user']]);

G
gongfuxiang 已提交
112 113 114
            // 是否需要登录
            $login_event = empty($params['user']) ? 'login-event' : '';

D
devil_gong 已提交
115 116
            // 内容
            $content .= '<!-- 用户中心 -->
G
gongfuxiang 已提交
117
                <a href="'.(empty($params['user']) ? 'javascript:;' : MyUrl('index/user/index')).'" '.$is_new_window_open.' class="user-content '.$login_event.'">
D
devil_gong 已提交
118
                    <div class="base-nav user-center">
G
gongfuxiang 已提交
119
                        <img src="'.(!empty($user['avatar']) ? $params['user']['avatar'] : config('shopxo.attachment_host').'/static/index/default/images/default-user-avatar.jpg').'" class="user-avatar" />
D
devil_gong 已提交
120 121 122 123 124 125 126 127
                        <div class="mui-mbar-tab-tip am-animation-slide-left">
                            用户中心
                            <div class="mui-mbar-arr mui-mbar-tab-tip-arr">◆</div>
                        </div>
                    </div>
                </a>

                <!-- 我的足迹 -->
G
gongfuxiang 已提交
128
                <a href="'.(empty($params['user']) ? 'javascript:;' : MyUrl('index/usergoodsbrowse/index')).'" '.$is_new_window_open.' class="browse-content '.$login_event.'">
D
devil_gong 已提交
129 130 131 132 133 134 135 136 137 138
                    <div class="base-nav browse">
                        <i class="am-icon-lastfm"></i>
                        <div class="mui-mbar-tab-tip am-animation-slide-left">
                            我的足迹
                            <div class="mui-mbar-arr mui-mbar-tab-tip-arr">◆</div>
                        </div>
                    </div>
                </a>

                <!-- 我的收藏 -->
G
gongfuxiang 已提交
139
                <a href="'.(empty($params['user']) ? 'javascript:;' : MyUrl('index/userfavor/goods')).'" '.$is_new_window_open.' class="favor-content '.$login_event.'">
D
devil_gong 已提交
140 141 142 143 144 145 146 147 148 149
                    <div class="base-nav favor">
                        <i class="am-icon-star-o"></i>
                        <div class="mui-mbar-tab-tip am-animation-slide-left">
                            我的收藏
                            <div class="mui-mbar-arr mui-mbar-tab-tip-arr">◆</div>
                        </div>
                    </div>
                </a>

                <!-- 购物车 -->
G
gongfuxiang 已提交
150
                <a href="'.(empty($params['user']) ? 'javascript:;' : MyUrl('index/cart/index')).'" '.$is_new_window_open.' class="cart-content '.$login_event.'">
D
devil_gong 已提交
151 152 153 154
                    <div class="base-nav cart">
                        <i class="am-icon-opencart"></i>
                        <div class="cart-text">
                            购物车
G
优化  
gongfuxiang 已提交
155
                            <div class="cart-count common-cart-total am-badge am-badge-danger">'.($cart_total > 9 ? '9+' : $cart_total).'</div>
D
devil_gong 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
                        </div>
                    </div>
                </a>';

            $qrcode = '';
            if(!empty($ret['data']['alipay_mini_qrcode_images']))
            {
                $qrcode .= '<li>
                                <p>支付宝小程序</p>
                                <img src="'.$ret['data']['alipay_mini_qrcode_images'].'" alt="支付宝小程序" /> 
                            </li>';
            }
            if(!empty($ret['data']['alipay_fuwu_qrcode_images']))
            {
                $qrcode .= '<li>
                                <p>支付宝生活号</p>
                                <img src="'.$ret['data']['alipay_fuwu_qrcode_images'].'" alt="支付宝生活号" /> 
                            </li>';
            }
            if(!empty($ret['data']['weixin_mini_qrcode_images']))
            {
                $qrcode .= '<li>
                                <p>微信小程序</p>
                                <img src="'.$ret['data']['weixin_mini_qrcode_images'].'" alt="微信小程序" /> 
                            </li>';
            }
            if(!empty($ret['data']['weixin_fuwu_qrcode_images']))
            {
                $qrcode .= '<li>
                                <p>微信公众号</p>
                                <img src="'.$ret['data']['weixin_fuwu_qrcode_images'].'" alt="微信公众号" /> 
                            </li>';
            }
            if(!empty($qrcode))
            {
                $content .= '<!-- 二维码 -->
G
gongfuxiang 已提交
192
                    <div class="base-nav qrcode-content">
D
devil_gong 已提交
193
                        <i class="am-icon-qrcode"></i>
G
gongfuxiang 已提交
194
                        <div class="mui-mbar-popup qrcode-items am-animation-slide-left">
D
devil_gong 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
                            <ul>'.$qrcode.'</ul>
                        </div>
                    </div>';
            }

            $content .= '<!-- 回顶部 -->
                <div class="base-nav go-top" data-am-smooth-scroll id="plugins-commonrightnavigation">
                    <i class="am-icon-arrow-up"></i>
                    <div class="mui-mbar-tab-tip am-animation-slide-left">
                        返回顶部
                        <div class="mui-mbar-arr mui-mbar-tab-tip-arr">◆</div>
                    </div>
                </div>';

        } else {
            $content = $ret['msg'];
        }
        $html .= $content;
        $html .= '</div>';

        return $html;
    }
}
?>