NavigationService.php 37.2 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1 2 3 4
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
5
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
D
v1.2.0  
devil_gong 已提交
6
// +----------------------------------------------------------------------
D
2.0  
Devil 已提交
7
// | Licensed ( https://opensource.org/licenses/mit-license.php )
D
v1.2.0  
devil_gong 已提交
8 9 10 11 12
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;

D
Devil 已提交
13
use think\facade\Db;
D
devil 已提交
14 15 16 17
use app\service\BuyService;
use app\service\MessageService;
use app\service\OrderService;
use app\service\GoodsService;
D
devil 已提交
18
use app\service\GoodsBrowseService;
D
devil 已提交
19 20
use app\service\GoodsFavorService;
use app\service\IntegralService;
D
v1.2.0  
devil_gong 已提交
21 22 23 24 25 26 27 28 29 30 31

/**
 * 导航服务层
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2016-12-01T21:51:08+0800
 */
class NavigationService
{
    /**
D
devil_gong 已提交
32
     * 获取导航
D
v1.2.0  
devil_gong 已提交
33 34 35 36 37 38 39
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-08-29
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
D
devil_gong 已提交
40
    public static function Nav($params = [])
D
v1.2.0  
devil_gong 已提交
41 42
    {
        // 读取缓存数据
D
Devil 已提交
43 44
        $header = MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'));
        $footer = MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'));
D
v1.2.0  
devil_gong 已提交
45 46

        // 缓存没数据则从数据库重新读取,顶部菜单
D
Devil 已提交
47
        if($header === null || MyEnv('app_debug'))
D
v1.2.0  
devil_gong 已提交
48
        {
D
devil 已提交
49
            // 获取导航数据
D
devil 已提交
50
            $header = self::NavDataAll('header');
D
v1.2.0  
devil_gong 已提交
51 52 53
        }

        // 底部导航
D
Devil 已提交
54
        if($footer === null || MyEnv('app_debug'))
D
v1.2.0  
devil_gong 已提交
55
        {
D
devil 已提交
56 57
            // 获取导航数据
            $footer = self::NavDataAll('footer');
D
v1.2.0  
devil_gong 已提交
58 59
        }

D
devil 已提交
60 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
        // 中间大导航添加首页导航
        array_unshift($header, [
            'id'                    => 0,
            'pid'                   => 0,
            'name'                  => '首页',
            'url'                   => __MY_URL__,
            'data_type'             => 'system',
            'is_show'               => 1,
            'is_new_window_open'    => 0,
            'items'                 => [],
        ]);

        // 选中处理
        if(!empty($header))
        {
            foreach($header as &$v)
            {
                $v['active'] = ($v['url'] == __MY_VIEW_URL__) ? 1 : 0;
                if($v['active'] == 0 && !empty($v['items']))
                {
                    $status = false;
                    foreach($v['items'] as &$vs)
                    {
                        if($vs['url'] == __MY_VIEW_URL__)
                        {
                            $vs['active'] = 1;
                            $status = true;
                        } else {
                            $vs['active'] = 0;
                        }
                    }

                    // 当子元素被选中则父级也选中
                    if($status)
                    {
                        $v['active'] = 1;
                    }
                }
            }
        }
D
devil_gong 已提交
100

D
v1.2.0  
devil_gong 已提交
101 102 103 104 105 106
        return [
            'header' => $header,
            'footer' => $footer,
        ];
    }

D
devil 已提交
107 108 109 110 111 112 113 114 115 116 117 118
    /**
     * 获取导航数据
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-15
     * @desc    description
     * @param   [string]          $nav_type [导航类型(header, footer)]
     */
    public static function NavDataAll($nav_type)
    {
        // 获取导航数据
D
devil 已提交
119
        $field = 'id,pid,name,url,value,data_type,is_new_window_open';
D
devil 已提交
120
        $order_by = 'sort asc,id asc';
D
Devil 已提交
121
        $data = self::NavDataDealWith(Db::name('Navigation')->field($field)->where(array('nav_type'=>$nav_type, 'is_show'=>1, 'pid'=>0))->order($order_by)->select()->toArray());
D
devil 已提交
122 123 124 125 126
        if(!empty($data))
        {
            // 获取子数据
            $items = [];
            $ids = array_column($data, 'id');
D
Devil 已提交
127
            $items_data = self::NavDataDealWith(Db::name('Navigation')->field($field)->where(array('nav_type'=>$nav_type, 'is_show'=>1, 'pid'=>$ids))->order($order_by)->select()->toArray());
D
devil 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
            if(!empty($items_data))
            {
                foreach($items_data as $it)
                {
                    $items[$it['pid']][] = $it;
                }
            }

            // 数据组合
            foreach($data as &$v)
            {
                $v['items'] = isset($items[$v['id']]) ? $items[$v['id']] : [];
            }
        }

        // 大导航钩子
        $hook_name = 'plugins_service_navigation_'.$nav_type.'_handle';
D
Devil 已提交
145
        MyEventTrigger($hook_name, [
D
devil 已提交
146 147 148 149 150 151 152
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
            $nav_type       => &$data,
        ]);

D
Devil 已提交
153 154 155 156 157 158
        // 没数据则赋空数组值
        if(empty($data))
        {
            $data = [];
        }

D
devil 已提交
159
        // 缓存
D
Devil 已提交
160
        MyCache(MyConfig('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180);
D
devil 已提交
161 162 163
        return $data;
    }

D
v1.2.0  
devil_gong 已提交
164 165 166 167 168 169 170 171 172
    /**
     * [NavDataDealWith 导航数据处理]
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-02-05T21:36:46+0800
     * @param    [array]      $data [需要处理的数据]
     * @return   [array]            [处理好的数据]
     */
173
    public static function NavDataDealWith($data)
D
v1.2.0  
devil_gong 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    {
        if(!empty($data) && is_array($data))
        {
            foreach($data as $k=>$v)
            {
                // url处理
                switch($v['data_type'])
                {
                    // 文章分类
                    case 'article':
                        $v['url'] = MyUrl('index/article/index', ['id'=>$v['value']]);
                        break;

                    // 自定义页面
                    case 'customview':
                        $v['url'] = MyUrl('index/customview/index', ['id'=>$v['value']]);
                        break;

                    // 商品分类
                    case 'goods_category':
                        $v['url'] = MyUrl('index/search/index', ['category_id'=>$v['value']]);
                        break;
                }
                $data[$k] = $v;
            }
        }
        return $data;
    }

    /**
     * 获取导航列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-18
     * @desc    description
D
devil 已提交
210
     * @param   [array]          $params  [输入参数]
D
v1.2.0  
devil_gong 已提交
211
     */
212
    public static function NavList($params = [])
D
v1.2.0  
devil_gong 已提交
213
    {
D
devil 已提交
214 215
        // 基础参数
        $field = '*';
D
devil 已提交
216
        $where = empty($params['where']) ? [] : $params['where'];
D
devil 已提交
217 218 219
        $order_by = empty($params['order_by']) ? 'sort asc,id asc' : $params['order_by'];

        // 获取数据
D
devil 已提交
220 221
        $where1 = $where;
        $where1[] = ['pid', '=', 0];
D
Devil 已提交
222
        $data = self::NavigationHandle(self::NavDataDealWith(Db::name('Navigation')->field($field)->where($where1)->order($order_by)->select()->toArray()));
D
devil 已提交
223
        $result = [];
D
devil 已提交
224
        if(!empty($data))
D
v1.2.0  
devil_gong 已提交
225
        {
D
devil 已提交
226
            // 子级数据组合
D
devil 已提交
227 228
            $where2 = $where;
            $where2[] = ['pid', 'in', array_column($data, 'id')];
D
Devil 已提交
229
            $items_data = self::NavigationHandle(self::NavDataDealWith(Db::name('Navigation')->field($field)->where($where2)->order($order_by)->select()->toArray()));
D
devil 已提交
230
            $items_group = [];
D
devil 已提交
231 232
            if(!empty($items_data))
            {
D
devil 已提交
233
                foreach($items_data as $tv)
D
devil 已提交
234
                {
D
devil 已提交
235
                    $items_group[$tv['pid']][] = $tv;
D
devil 已提交
236 237 238
                }
            }

D
devil 已提交
239
            // 数据集合
D
devil 已提交
240
            if(!empty($items_group))
D
devil 已提交
241
            {
D
devil 已提交
242
                foreach($data as $dv)
D
devil 已提交
243
                {
D
devil 已提交
244 245 246 247 248 249 250 251
                    if(array_key_exists($dv['id'], $items_group))
                    {
                        $dv['is_sub_data'] = 1;
                        $result[] = $dv;
                        $result = array_merge($result, $items_group[$dv['id']]);
                    } else {
                        $result[] = $dv;
                    }
D
devil 已提交
252
                }
D
devil 已提交
253 254
            } else {
                $result = $data;
D
devil 已提交
255
            }
D
v1.2.0  
devil_gong 已提交
256
        }
D
devil 已提交
257 258

        return DataReturn('处理成功', 0, $result);
D
devil 已提交
259
    }
D
v1.2.0  
devil_gong 已提交
260

D
devil 已提交
261 262 263 264 265 266 267 268 269 270 271 272
    /**
     * 数据处理
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-06-15
     * @desc    description
     * @param   [array]          $data [导航数据]
     */
    public static function NavigationHandle($data)
    {
        if(!empty($data) && is_array($data))
D
v1.2.0  
devil_gong 已提交
273
        {
D
Devil 已提交
274
            $nav_type_list = MyConst('common_nav_type_list');
D
v1.2.0  
devil_gong 已提交
275 276
            foreach($data as &$v)
            {
D
devil 已提交
277 278 279 280 281 282
                // 数据类型
                $v['data_type_text'] = isset($nav_type_list[$v['data_type']]) ? $nav_type_list[$v['data_type']]['name'] : '';

                // 时间
                $v['add_time'] = date('Y-m-d H:i:s', $v['add_time']);
                $v['upd_time'] = empty($v['upd_time']) ? '' : date('Y-m-d H:i:s', $v['upd_time']);
D
v1.2.0  
devil_gong 已提交
283 284 285 286 287 288 289 290 291 292 293 294 295 296
            }
        }
        return $data;
    }

    /**
     * 获取一级导航列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-18
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
297
    public static function LevelOneNav($params = [])
D
v1.2.0  
devil_gong 已提交
298 299 300 301 302 303
    {
        if(empty($params['nav_type']))
        {
            return [];
        }

D
Devil 已提交
304
        return Db::name('Navigation')->field('id,name')->where(['is_show'=>1, 'pid'=>0, 'nav_type'=>$params['nav_type']])->select()->toArray();
D
v1.2.0  
devil_gong 已提交
305 306 307 308 309 310 311 312
    }

    /**
     * 导航保存
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-07T21:58:19+0800
D
devil 已提交
313
     * @param    [array]          $params [输入参数]
D
v1.2.0  
devil_gong 已提交
314
     */
315
    public static function NavSave($params = [])
D
v1.2.0  
devil_gong 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    {
        if(empty($params['data_type']))
        {
            return DataReturn('操作类型有误', -1);
        }

        // 请求类型
        $p = [
            [
                'checked_type'      => 'length',
                'key_name'          => 'sort',
                'checked_data'      => '4',
                'error_msg'         => '顺序 0~255 之间的数值',
            ],
            [
                'checked_type'      => 'in',
                'key_name'          => 'is_show',
                'checked_data'      => [0,1],
                'error_msg'         => '是否显示范围值有误',
            ],
            [
                'checked_type'      => 'in',
                'key_name'          => 'is_new_window_open',
                'checked_data'      => [0,1],
                'error_msg'         => '是否新窗口打开范围值有误',
D
Devil 已提交
341 342 343 344 345 346 347
            ],
            [
                'checked_type'      => 'in',
                'key_name'          => 'nav_type',
                'checked_data'      => ['header', 'footer'],
                'error_msg'         => '数据类型有误',
            ],
D
v1.2.0  
devil_gong 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
        ];
        switch($params['data_type'])
        {
            // 自定义导航
            case 'custom':
                $p = [
                    [
                        'checked_type'      => 'length',
                        'key_name'          => 'name',
                        'checked_data'      => '2,16',
                        'error_msg'         => '导航名称格式 2~16 个字符',
                    ],
                    [
                        'checked_type'      => 'fun',
                        'key_name'          => 'url',
                        'checked_data'      => 'CheckUrl',
                        'error_msg'         => 'url格式有误',
                    ],
                ];
                break;

            // 文章分类导航
            case 'article':
                $p = [
                    [
                        'checked_type'      => 'length',
                        'key_name'          => 'name',
                        'checked_data'      => '2,16',
                        'is_checked'        => 1,
                        'error_msg'         => '导航名称格式 2~16 个字符',
                    ],
                    [
                        'checked_type'      => 'empty',
                        'key_name'          => 'value',
                        'error_msg'         => '文章选择有误',
                    ],
                ];
                break;

            // 自定义页面导航
            case 'customview':
                $p = [
                    [
                        'checked_type'      => 'length',
                        'key_name'          => 'name',
                        'checked_data'      => '2,16',
                        'is_checked'        => 1,
                        'error_msg'         => '导航名称格式 2~16 个字符',
                    ],
                    [
                        'checked_type'      => 'empty',
                        'key_name'          => 'value',
                        'error_msg'         => '自定义页面选择有误',
                    ],
                ];
                break;

            // 商品分类导航
            case 'goods_category':
                $p = [
                    [
                        'checked_type'      => 'length',
                        'key_name'          => 'name',
D
devil_gong 已提交
411
                        'checked_data'      => '2,16',
D
v1.2.0  
devil_gong 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
                        'is_checked'        => 1,
                        'error_msg'         => '导航名称格式 2~16 个字符',
                    ],
                    [
                        'checked_type'      => 'empty',
                        'key_name'          => 'value',
                        'error_msg'         => '商品分类选择有误',
                    ],
                ];
                break;

            // 没找到
            default :
                return DataReturn('操作类型有误', -1);
        }

        // 参数
        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            return DataReturn($ret, -1);
        }

        // 保存数据
436
        return self::NacDataSave($params); 
D
v1.2.0  
devil_gong 已提交
437 438 439 440 441 442 443 444
    }

    /**
     * 导航数据保存
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2017-02-05T20:12:30+0800
D
devil 已提交
445
     * @param    [array]          $params [输入参数]
D
v1.2.0  
devil_gong 已提交
446
     */
447
    public static function NacDataSave($params = [])
D
v1.2.0  
devil_gong 已提交
448
    {
D
Devil 已提交
449 450 451
        // 缓存 key
        $cache_key = MyConfig('shopxo.cache_common_home_nav_'.$params['nav_type'].'_key');

D
v1.2.0  
devil_gong 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
        // 非自定义导航数据处理
        if(empty($params['name']))
        {
            switch($params['data_type'])
            {
                // 文章分类导航
                case 'article':
                    $temp_name = Db::name('Article')->where(['id'=>$params['value']])->value('title');
                    break;

                // 自定义页面导航
                case 'customview':
                    $temp_name = Db::name('CustomView')->where(['id'=>$params['value']])->value('title');
                    break;

                // 商品分类导航
                case 'goods_category':
                    $temp_name = Db::name('GoodsCategory')->where(['id'=>$params['value']])->value('name');
                    break;
            }
            // 只截取16个字符
D
Devil 已提交
473
            $params['name'] = mb_substr($temp_name, 0, 16, MyConfig('shopxo.default_charset'));
D
v1.2.0  
devil_gong 已提交
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
        }

        // 数据
        $data = [
            'pid'                   => isset($params['pid']) ? intval($params['pid']) : 0,
            'value'                 => isset($params['value']) ? intval($params['value']) : 0,
            'name'                  => $params['name'],
            'url'                   => isset($params['url']) ? $params['url'] : '',
            'nav_type'              => $params['nav_type'],
            'data_type'             => $params['data_type'],
            'sort'                  => intval($params['sort']),
            'is_show'               => intval($params['is_show']),
            'is_new_window_open'    => intval($params['is_new_window_open']),
        ];

        // id为空则表示是新增
        if(empty($params['id']))
        {
            $data['add_time'] = time();
            if(Db::name('Navigation')->insertGetId($data) > 0)
            {
                // 清除缓存
D
Devil 已提交
496
                MyCache($cache_key, null);
D
v1.2.0  
devil_gong 已提交
497 498 499 500 501 502 503 504 505 506
                
                return DataReturn('新增成功', 0);
            } else {
                return DataReturn('新增失败', -100);
            }
        } else {
            $data['upd_time'] = time();
            if(Db::name('Navigation')->where(['id'=>intval($params['id'])])->update($data))
            {
                // 清除缓存
D
Devil 已提交
507
                MyCache($cache_key, null);
D
v1.2.0  
devil_gong 已提交
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524

                return DataReturn('编辑成功', 0);
            } else {
                return DataReturn('编辑失败或数据未改变', -100);
            }
        }
    }

    /**
     * 导航删除
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2018-12-18
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
525
    public static function NavDelete($params = [])
D
v1.2.0  
devil_gong 已提交
526
    {
D
devil 已提交
527 528
        // 参数是否有误
        if(empty($params['ids']))
D
v1.2.0  
devil_gong 已提交
529
        {
D
devil 已提交
530 531 532 533 534 535
            return DataReturn('操作id有误', -1);
        }
        // 是否数组
        if(!is_array($params['ids']))
        {
            $params['ids'] = explode(',', $params['ids']);
D
v1.2.0  
devil_gong 已提交
536 537 538 539 540 541
        }

        // 启动事务
        Db::startTrans();

        // 删除操作
D
devil 已提交
542
        if(Db::name('Navigation')->where(['id'=>$params['ids']])->delete() !== false && Db::name('Navigation')->where(['pid'=>$params['ids']])->delete() !== false)
D
v1.2.0  
devil_gong 已提交
543 544 545 546 547
        {
            // 提交事务
            Db::commit();

            // 清除缓存
D
Devil 已提交
548 549
            MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null);
            MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null);
D
v1.2.0  
devil_gong 已提交
550 551 552 553 554 555

            return DataReturn('删除成功');
        }

        // 回滚事务
        Db::rollback();
D
devil 已提交
556
        return DataReturn('删除失败', -100);
D
v1.2.0  
devil_gong 已提交
557 558 559 560 561 562 563 564 565 566
    }

    /**
     * 状态更新
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  0.0.1
     * @datetime 2016-12-06T21:31:53+0800
     * @param    [array]          $params [输入参数]
     */
567
    public static function NavStatusUpdate($params = [])
D
v1.2.0  
devil_gong 已提交
568 569 570 571 572 573 574 575
    {
        // 请求参数
        $p = [
            [
                'checked_type'      => 'empty',
                'key_name'          => 'id',
                'error_msg'         => '操作id有误',
            ],
D
devil 已提交
576 577 578 579 580
            [
                'checked_type'      => 'empty',
                'key_name'          => 'field',
                'error_msg'         => '未指定操作字段',
            ],
D
v1.2.0  
devil_gong 已提交
581 582 583 584 585 586 587 588 589 590 591 592 593 594
            [
                'checked_type'      => 'in',
                'key_name'          => 'state',
                'checked_data'      => [0,1],
                'error_msg'         => '状态有误',
            ],
        ];
        $ret = ParamsChecked($params, $p);
        if($ret !== true)
        {
            return DataReturn($ret, -1);
        }

        // 数据更新
D
devil 已提交
595
        if(Db::name('Navigation')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()]))
D
v1.2.0  
devil_gong 已提交
596 597
        {
            // 清除缓存
D
Devil 已提交
598 599
            MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null);
            MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null);
D
v1.2.0  
devil_gong 已提交
600 601 602

            return DataReturn('编辑成功');
        }
D
devil 已提交
603
        return DataReturn('编辑失败', -100);
D
v1.2.0  
devil_gong 已提交
604
    }
D
devil_gong 已提交
605 606 607 608 609 610 611 612

    /**
     * 获取前端顶部右侧导航
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
D
devil 已提交
613
     * @param   [array]           $params [输入信息]
D
devil_gong 已提交
614 615 616 617 618 619 620 621 622 623 624 625 626
     */
    public static function HomeHavTopRight($params = [])
    {
        $common_cart_total = 0;
        $common_message_total = -1;
        if(!empty($params['user']))
        {
            // 购物车商品总数
            $common_cart_total = BuyService::UserCartTotal(['user'=>$params['user']]);

            // 未读消息总数
            $message_params = ['user'=>$params['user'], 'is_more'=>1, 'is_read'=>0, 'user_type'=>'user'];
            $common_message_total = MessageService::UserMessageTotal($message_params);
D
devil 已提交
627
            $common_message_total = ($common_message_total <= 0) ? -1 : $common_message_total;
D
devil_gong 已提交
628 629 630 631 632 633 634 635 636 637 638 639 640
        }
        
        // 列表
        $data = [
            [
                'name'      => '个人中心',
                'is_login'  => 1,
                'badge'     => null,
                'icon'      => 'am-icon-user',
                'url'       => MyUrl('index/user/index'),
                'items'     => [],
            ],
            [
D
钱包  
devil_gong 已提交
641
                'name'      => '我的商城',
D
devil_gong 已提交
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
                'is_login'  => 1,
                'badge'     => null,
                'icon'      => 'am-icon-cube',
                'url'       => '',
                'items'     => [
                    [
                        'name'  => '我的订单',
                        'url'   => MyUrl('index/order/index'),
                    ],
                ],
            ],
            [
                'name'      => '我的收藏',
                'is_login'  => 1,
                'badge'     => null,
                'icon'      => 'am-icon-heart',
                'url'       => '',
                'items'     => [
                    [
                        'name'  => '商品收藏',
D
devil 已提交
662
                        'url'   => MyUrl('index/usergoodsfavor/index'),
D
devil_gong 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
                    ],
                ],
            ],
            [
                'name'      => '购物车',
                'is_login'  => 1,
                'badge'     => $common_cart_total,
                'icon'      => 'am-icon-shopping-cart',
                'url'       => MyUrl('index/cart/index'),
                'items'     => [],
            ],
            [
                'name'      => '消息',
                'is_login'  => 1,
                'badge'     => $common_message_total,
                'icon'      => 'am-icon-bell',
                'url'       => MyUrl('index/message/index'),
                'items'     => [],
            ],
        ];

        // 顶部小导航右侧钩子
        $hook_name = 'plugins_service_header_navigation_top_right_handle';
D
Devil 已提交
686
        MyEventTrigger($hook_name, [
D
devil_gong 已提交
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }

    /**
     * 用户中心资料修改展示字段
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
D
devil 已提交
703
     * @param   [array]           $params [输入信息]
D
devil_gong 已提交
704 705 706
     */
    public static function UsersPersonalShowFieldList($params = [])
    {
G
gongfuxiang 已提交
707 708 709 710
        // is_ext       扩展数据 1, key不存在用户字段中可使用该扩展
        // name         显示名称
        // value        扩展自定义值
        // tips         html提示操作内容
D
devil_gong 已提交
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
        $data = [
            'avatar'            =>  [
                'name' => '头像',
                'tips' => '<a href="javascript:;" data-am-modal="{target:\'#user-avatar-popup\'}">修改</a>'
            ],
            'nickname'          =>  [
                'name' => '昵称'
            ],
            'gender_text'       =>  [
                'name' => '性别'
            ],
            'birthday_text'     =>  [
                'name' => '生日'
            ],
            'mobile_security'   =>  [
                'name' => '手机号码',
                'tips' => '<a href="'.MyUrl('index/safety/mobileinfo').'">修改</a>'
            ],
            'email_security'    =>  [
                'name' => '电子邮箱',
                'tips' => '<a href="'.MyUrl('index/safety/emailinfo').'">修改</a>'
            ],
            'add_time_text'     =>  [
                'name' => '注册时间'
            ],
            'upd_time_text'     =>  [
G
gongfuxiang 已提交
737
                'name' => '更新时间'
D
devil_gong 已提交
738 739 740 741 742
            ],
        ];

        // 用户中心资料修改展示字段钩子
        $hook_name = 'plugins_service_users_personal_show_field_list_handle';
D
Devil 已提交
743
        MyEventTrigger($hook_name, [
D
devil_gong 已提交
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }

    /**
     * 用户安全项列表
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
D
devil 已提交
760
     * @param   [array]           $params [输入信息]
D
devil_gong 已提交
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
     */
    public static function UsersSafetyPanelList($params = [])
    {
        $data = [
            [
                'title'     =>  '登录密码',
                'msg'       =>  '互联网存在被盗风险,建议您定期更改密码以保护安全。',
                'url'       =>  MyUrl('index/safety/loginpwdinfo'),
                'type'      =>  'loginpwd',
            ],
            [
                'title'     =>  '手机号码',
                'no_msg'    =>  '您还没有绑定手机号码',
                'ok_msg'    =>  '已绑定手机 #accounts#',
                'tips'      =>  '可用于登录,密码找回,账户安全管理校验,接受账户提醒通知。',
                'url'       =>  MyUrl('index/safety/mobileinfo'),
                'type'      =>  'mobile',
            ],
            [
                'title'     =>  '电子邮箱',
                'no_msg'    =>  '您还没有绑定电子邮箱',
                'ok_msg'    =>  '已绑定电子邮箱 #accounts#',
                'tips'      =>  '可用于登录,密码找回,账户安全管理校验,接受账户提醒邮件。',
                'url'       =>  MyUrl('index/safety/emailinfo'),
                'type'      =>  'email',
            ],
        ];

        // 用户安全项列表钩子
        $hook_name = 'plugins_service_users_safety_panel_list_handle';
D
Devil 已提交
791
        MyEventTrigger($hook_name, [
D
devil_gong 已提交
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }

    /**
     * 用户中心左侧菜单
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
D
devil 已提交
808
     * @param   [array]           $params [输入信息]
D
devil_gong 已提交
809 810 811
     */
    public static function UsersCenterLeftList($params = [])
    {
D
devil_gong 已提交
812 813 814
        // name        名称
        // url         页面地址
        // is_show     是否显示(0否, 1是)
D
Devil 已提交
815
        // contains    包含的子页面(包括自身) 如用户中心(index 组, user 控制器, index 方法 [ indexuserindex ])
D
devil_gong 已提交
816 817
        // icon        icon类
        // item        二级数据
G
gongfuxiang 已提交
818
        // is_system   是否系统内置菜单(0否, 1是)扩展数据可空或0
D
devil_gong 已提交
819 820

        // 菜单列表
D
devil_gong 已提交
821
        $data = [
D
钱包  
devil_gong 已提交
822
            'center' => [
D
devil_gong 已提交
823
                'name'      =>  '个人中心',
D
devil_gong 已提交
824
                'url'       =>  MyUrl('index/user/index'),
D
devil_gong 已提交
825
                'is_show'   =>  1,
D
Devil 已提交
826
                'contains'  =>  ['indexuserindex'],
D
devil_gong 已提交
827
                'icon'      =>  'am-icon-home',
G
gongfuxiang 已提交
828
                'is_system' =>  1,
D
devil_gong 已提交
829
            ],
D
钱包  
devil_gong 已提交
830 831
            'business' => [
                'name'      =>  '业务管理',
D
devil_gong 已提交
832 833
                'is_show'   =>  1,
                'icon'      =>  'am-icon-cube',
G
gongfuxiang 已提交
834
                'is_system' =>  1,
D
devil_gong 已提交
835 836 837
                'item'      =>  [
                    [
                        'name'      =>  '订单管理',
D
devil_gong 已提交
838
                        'url'       =>  MyUrl('index/order/index'),
D
devil_gong 已提交
839
                        'is_show'   =>  1,
D
Devil 已提交
840
                        'contains'  =>  ['indexorderindex', 'indexorderdetail', 'indexordercomments'],
D
devil_gong 已提交
841
                        'icon'      =>  'am-icon-th-list',
G
gongfuxiang 已提交
842
                        'is_system' =>  1,
D
devil_gong 已提交
843
                    ],
D
devil_gong 已提交
844 845 846 847
                    [
                        'name'      =>  '订单售后',
                        'url'       =>  MyUrl('index/orderaftersale/index'),
                        'is_show'   =>  1,
D
devil 已提交
848
                        'contains'  =>  ['indexorderaftersaleindex', 'indexorderaftersaledetail'],
D
devil_gong 已提交
849
                        'icon'      =>  'am-icon-puzzle-piece',
G
gongfuxiang 已提交
850
                        'is_system' =>  1,
D
devil_gong 已提交
851
                    ],
D
devil_gong 已提交
852
                    [
D
Devil 已提交
853
                        'name'      =>  '商品收藏',
D
devil 已提交
854 855
                        'url'       =>  MyUrl('index/usergoodsfavor/index'),
                        'contains'  =>  ['indexusergoodsfavorindex'],
D
devil_gong 已提交
856 857
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-heart-o',
G
gongfuxiang 已提交
858
                        'is_system' =>  1,
D
devil_gong 已提交
859 860 861
                    ],
                ]
            ],
G
gongfuxiang 已提交
862 863 864 865 866 867 868 869 870
            'property' => [
                'name'      =>  '财产中心',
                'is_show'   =>  1,
                'icon'      =>  'am-icon-trophy',
                'is_system' =>  1,
                'item'      =>  [
                    [
                        'name'      =>  '我的积分',
                        'url'       =>  MyUrl('index/userintegral/index'),
D
Devil 已提交
871
                        'contains'  =>  ['indexuserintegralindex'],
G
gongfuxiang 已提交
872 873 874 875 876 877
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-fire',
                        'is_system' =>  1,
                    ],
                ]
            ],
D
钱包  
devil_gong 已提交
878
            'base' => [
D
devil_gong 已提交
879 880 881
                'name'      =>  '资料管理',
                'is_show'   =>  1,
                'icon'      =>  'am-icon-user',
G
gongfuxiang 已提交
882
                'is_system' =>  1,
D
devil_gong 已提交
883 884 885
                'item'      =>  [
                    [
                        'name'      =>  '个人资料',
D
devil_gong 已提交
886
                        'url'       =>  MyUrl('index/personal/index'),
D
Devil 已提交
887
                        'contains'  =>  ['indexpersonalindex', 'indexpersonalsaveinfo'],
D
devil_gong 已提交
888 889
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-gear',
G
gongfuxiang 已提交
890
                        'is_system' =>  1,
D
devil_gong 已提交
891 892 893
                    ],
                    [
                        'name'      =>  '我的地址',
D
devil_gong 已提交
894
                        'url'       =>  MyUrl('index/useraddress/index'),
D
Devil 已提交
895
                        'contains'  =>  ['indexuseraddressindex', 'indexuseraddresssaveinfo'],
D
devil_gong 已提交
896 897
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-street-view',
G
gongfuxiang 已提交
898
                        'is_system' =>  1,
D
devil_gong 已提交
899 900 901
                    ],
                    [
                        'name'      =>  '安全设置',
D
devil_gong 已提交
902
                        'url'       =>  MyUrl('index/safety/index'),
D
Devil 已提交
903
                        'contains'  =>  ['indexsafetyindex', 'indexsafetyloginpwdinfo', 'indexsafetymobileinfo', 'indexsafetynewmobileinfo', 'indexsafetyemailinfo', 'indexsafetynewemailinfo'],
D
devil_gong 已提交
904 905
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-user-secret',
G
gongfuxiang 已提交
906
                        'is_system' =>  1,
D
devil_gong 已提交
907 908 909
                    ],
                    [
                        'name'      =>  '我的消息',
D
devil_gong 已提交
910
                        'url'       =>  MyUrl('index/message/index'),
D
Devil 已提交
911
                        'contains'  =>  ['indexmessageindex'],
D
devil_gong 已提交
912 913
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-bell-o',
G
gongfuxiang 已提交
914
                        'is_system' =>  1,
D
devil_gong 已提交
915 916 917
                    ],
                    [
                        'name'      =>  '我的足迹',
D
devil_gong 已提交
918
                        'url'       =>  MyUrl('index/usergoodsbrowse/index'),
D
Devil 已提交
919
                        'contains'  =>  ['indexusergoodsbrowseindex'],
D
devil_gong 已提交
920 921
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-lastfm',
G
gongfuxiang 已提交
922
                        'is_system' =>  1,
D
devil_gong 已提交
923 924 925
                    ],
                    [
                        'name'      =>  '问答/留言',
D
devil_gong 已提交
926
                        'url'       =>  MyUrl('index/answer/index'),
D
Devil 已提交
927
                        'contains'  =>  ['indexanswerindex'],
D
devil_gong 已提交
928 929
                        'is_show'   =>  1,
                        'icon'      =>  'am-icon-question',
G
gongfuxiang 已提交
930
                        'is_system' =>  1,
D
devil_gong 已提交
931 932 933
                    ],
                ]
            ],
D
钱包  
devil_gong 已提交
934
            'logout' => [
D
devil_gong 已提交
935 936
                'name'      =>  '安全退出',
                'url'       =>  MyUrl('index/user/logout'),
D
Devil 已提交
937
                'contains'  =>  ['indexuserlogout'],
D
devil_gong 已提交
938 939
                'is_show'   =>  1,
                'icon'      =>  'am-icon-power-off',
G
gongfuxiang 已提交
940
                'is_system' =>  1,
D
devil_gong 已提交
941
            ],
D
devil_gong 已提交
942 943 944 945
        ];

        // 用户中心左侧菜单钩子
        $hook_name = 'plugins_service_users_center_left_menu_handle';
D
Devil 已提交
946
        MyEventTrigger($hook_name, [
D
devil_gong 已提交
947 948 949 950 951 952 953 954
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }
D
devil_gong 已提交
955 956 957 958 959 960 961 962

    /**
     * 获取网站底部导航
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
D
devil 已提交
963
     * @param   [array]           $params [输入信息]
D
devil_gong 已提交
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
     */
    public static function BottomNavigation($params = [])
    {
        $common_cart_total = 0;
        if(!empty($params['user']))
        {
            // 购物车商品总数
            $common_cart_total = BuyService::UserCartTotal(['user'=>$params['user']]);
        }
        
        // 列表
        $data = [
            [
                'name'      => '首页',
                'is_login'  => 0,
                'badge'     => null,
                'icon'      => 'nav-icon-home',
                'only_tag'  => 'indexindex',
                'url'       => __MY_URL__,
            ],
            [
                'name'      => '分类',
                'is_login'  => 0,
                'badge'     => null,
                'icon'      => 'nav-icon-category',
                'only_tag'  => 'categoryindex',
                'url'       => MyUrl('index/category/index'),
            ],
            [
                'name'      => '购物车',
                'is_login'  => 1,
                'badge'     => $common_cart_total,
                'icon'      => 'nav-icon-cart',
                'only_tag'  => 'cartindex',
                'url'       => MyUrl('index/cart/index'),
            ],
            [
                'name'      => '我的',
                'is_login'  => 1,
                'badge'     => null,
                'icon'      => 'nav-icon-user',
                'only_tag'  => 'userindex',
                'url'       => MyUrl('index/user/index'),
            ],
        ];

        // 网站底部导航
        $hook_name = 'plugins_service_bottom_navigation_handle';
D
Devil 已提交
1012
        MyEventTrigger($hook_name, [
D
devil_gong 已提交
1013 1014 1015 1016 1017 1018 1019 1020
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }
D
devil 已提交
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032

    /**
     * 用户中心基础信息中 mini 导航
     * @author   Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2019-03-15
     * @desc    description
     * @param   [array]           $params [输入信息]
     */
    public static function UserCenterMiniNavigation($params = [])
    {
D
devil 已提交
1033 1034 1035 1036 1037
        $user_order_count = 0;
        $user_goods_favor_count = 0;
        $user_goods_browse_count = 0;
        $user_integral = 0;
        if(!empty($params['user']))
D
devil 已提交
1038 1039 1040 1041 1042
        {
            // 订单总数
            $where = ['user_id'=>$params['user']['id'], 'is_delete_time'=>0, 'user_is_delete_time'=>0];
            $user_order_count = OrderService::OrderTotal($where);

D
devil 已提交
1043
            // 商品收藏/我的足迹总数
D
devil 已提交
1044
            $where = ['user_id'=>$params['user']['id']];
D
devil 已提交
1045
            $user_goods_favor_count = GoodsFavorService::GoodsFavorTotal($where);
D
devil 已提交
1046
            $user_goods_browse_count = GoodsBrowseService::GoodsBrowseTotal($where);
D
devil 已提交
1047 1048

            // 用户积分
D
Devil 已提交
1049 1050
            $integral = IntegralService::UserIntegral($params['user']['id']);
            $user_integral = (!empty($integral) && !empty($integral['integral'])) ? $integral['integral'] : 0;
D
devil 已提交
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
        }
        
        // 列表
        $data = [
            [
                'name'      => '订单总数',
                'value'     => $user_order_count,
                'url'       => MyUrl('index/order/index'),
            ],
            [
                'name'      => '商品收藏',
                'value'     => $user_goods_favor_count,
D
devil 已提交
1063
                'url'       => MyUrl('index/usergoodsfavor/index'),
D
devil 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
            ],
            [
                'name'      => '我的足迹',
                'value'     => $user_goods_browse_count,
                'url'       => MyUrl('index/usergoodsbrowse/index'),
            ],
            [
                'name'      => '我的积分',
                'value'     => $user_integral,
                'url'       => MyUrl('index/userintegral/index'),
            ],
        ];

        // 用户中心基础信息中mini导航
        $hook_name = 'plugins_service_user_center_mini_navigation_handle';
D
Devil 已提交
1079
        MyEventTrigger($hook_name, [
D
devil 已提交
1080 1081 1082 1083 1084 1085 1086 1087
            'hook_name'     => $hook_name,
            'is_backend'    => true,
            'params'        => &$params,
            'data'          => &$data,
        ]);

        return $data;
    }
D
v1.2.0  
devil_gong 已提交
1088 1089
}
?>