brand-api.js 1.48 KB
'use strict';

const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const Promise = require('bluebird');
const co = Promise.coroutine;

const api = new API();

module.exports.getBannerInfoAsync = function(bid, isUrl) {
    isUrl;
    return api.get('', sign.apiSign({
        method: 'web.brand.banner',
        brand_id: bid
    }));
};

function getBrandLogoByDomainAsync(domain) {
    return api.get('', sign.apiSign({
        domain: domain,
        method: 'web.brand.byDomain'
    }));
}

module.exports.getBrandByDomainAsync = function(domain) {
    return co(function*() {
        let brandInfo = yield getBrandLogoByDomainAsync(domain);

        let result = {};

        if (brandInfo.data && brandInfo.code === 200) {
            result.brandId = brandInfo.data.id || '';
            result.node = brandInfo.data.static_content_code || false;
            result.brandBanner = brandInfo.data.brand_banner || '';
            result.brandNameEn = brandInfo.data.brand_name_en || '';
            result.brandNameCn = brandInfo.data.brand_name_cn || '';
            result.brandAbout = brandInfo.data.brand_intro || '';
            result.shopTemplateType = brandInfo.data.shop_template_type ?
                parseInt(brandInfo.data.shop_template_type) : '';
            result.type = brandInfo.data.type ? +brandInfo.data.type : 0;
            result.shopId = brandInfo.data.shop_id || '';

        }
        return result;
    })();
};