shop.js 1.44 KB

'use strict';

const mRoot = '../models';
const shopModel = require(`${mRoot}/shop-service`);
const tdk = require('../../../utils/getTDK');

exports.index = (req, res, next) => {
    let domain = req.query.domain;

    if (!domain) {
        return next();
    }

    Promise.all([
        tdk('shop', req.query.shopId, req),
        shopModel.getShopInfoAsync(domain, req.yoho.channel, req.query)
    ]).then(result => {
        let TDKObj = result[0],
            shopObj = result[1];

        if (TDKObj && TDKObj[0]) {
            req.tdk = {
                title: TDKObj[1],
                keywords: TDKObj[2],
                description: TDKObj[3]
            };
        }

        // 数据异常,重定向
        if (shopObj.redirect) {
            return res.redirect(shopObj.redirect);
        }

        if (shopObj.templateType === 2) { // 经典模板
            Object.assign(shopObj, {page: 'shop'});

            // 店铺装修为空则不cache
            if (!shopObj.shopTopBanner) {
                res.set('Cache-Control', 'no-cache');
            }

            res.render('list/shop-index', shopObj);
        } else { // 基础模版
            Object.assign(shopObj, {page: 'list'});

            // 基础店铺装修为空则不cache
            if (!shopObj.brand || !shopObj.brand.shopBanner) {
                res.set('Cache-Control', 'no-cache');
            }

            res.render('list/brand', shopObj);
        }
    });
};