...
|
...
|
@@ -6,36 +6,80 @@ |
|
|
*/
|
|
|
'use strict';
|
|
|
|
|
|
const brandApi = require('./brand-api');
|
|
|
const BrandApi = require('./brand-api');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
/**
|
|
|
* 处理品牌一览品牌列表数据
|
|
|
* @param origin
|
|
|
* @returns {Array}
|
|
|
*/
|
|
|
const handleBrandList = origin => {
|
|
|
let dest = {
|
|
|
brandList: [],
|
|
|
indexList: []
|
|
|
};
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
// 标记是否有数字,有数字先暂存
|
|
|
let hasNum = false;
|
|
|
let numTemp = {};
|
|
|
/**
|
|
|
* 处理品牌一览品牌列表数据
|
|
|
* @param origin
|
|
|
* @returns {Array}
|
|
|
*/
|
|
|
handleBrandList(origin) {
|
|
|
let dest = {
|
|
|
brandList: [],
|
|
|
indexList: []
|
|
|
};
|
|
|
|
|
|
// 标记是否有数字,有数字先暂存
|
|
|
let hasNum = false;
|
|
|
let numTemp = {};
|
|
|
|
|
|
_.forEach(origin, (value, key) => {
|
|
|
let brands = [];
|
|
|
|
|
|
if (_.size(value) <= 0) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (key === '0~9') {
|
|
|
hasNum = true;
|
|
|
numTemp = origin[key];
|
|
|
} else {
|
|
|
_.forEach(value, (subValue) => {
|
|
|
brands.push({
|
|
|
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
|
|
|
logo: subValue.brand_ico,
|
|
|
domain: subValue.brand_domain,
|
|
|
shopId: subValue.shop_id,
|
|
|
shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
|
|
|
isRedShop: subValue.is_red_shop,
|
|
|
shopTemplateType: subValue.shop_template_type
|
|
|
});
|
|
|
});
|
|
|
|
|
|
_.forEach(origin, (value, key) => {
|
|
|
let brands = [];
|
|
|
dest.brandList.push({
|
|
|
index: key,
|
|
|
brands: brands
|
|
|
});
|
|
|
|
|
|
if (_.size(value) <= 0) {
|
|
|
return;
|
|
|
}
|
|
|
dest.indexList.push({
|
|
|
index: key,
|
|
|
name: key === '0~9' ? '0' : key
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (key === '0~9') {
|
|
|
hasNum = true;
|
|
|
numTemp = origin[key];
|
|
|
} else {
|
|
|
_.forEach(value, (subValue) => {
|
|
|
});
|
|
|
|
|
|
// 商品列表排序一次
|
|
|
_.sortBy(dest.brandList, o => {
|
|
|
return o.index.charCodeAt();
|
|
|
});
|
|
|
|
|
|
// 字母列表排序一次
|
|
|
_.sortBy(dest.indexList, o => {
|
|
|
return o.index.charCodeAt();
|
|
|
});
|
|
|
|
|
|
// 如果有数字,单独处理
|
|
|
if (hasNum) {
|
|
|
let brands = [];
|
|
|
|
|
|
_.forEach(numTemp, (subValue) => {
|
|
|
brands.push({
|
|
|
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
|
|
|
logo: subValue.brand_ico,
|
...
|
...
|
@@ -46,85 +90,52 @@ const handleBrandList = origin => { |
|
|
shopTemplateType: subValue.shop_template_type
|
|
|
});
|
|
|
});
|
|
|
|
|
|
dest.brandList.push({
|
|
|
index: key,
|
|
|
index: '0~9',
|
|
|
brands: brands
|
|
|
});
|
|
|
|
|
|
dest.indexList.push({
|
|
|
index: key,
|
|
|
name: key === '0~9' ? '0' : key
|
|
|
index: '0_9',
|
|
|
name: '0'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// 商品列表排序一次
|
|
|
_.sortBy(dest.brandList, o => {
|
|
|
return o.index.charCodeAt();
|
|
|
});
|
|
|
|
|
|
// 字母列表排序一次
|
|
|
_.sortBy(dest.indexList, o => {
|
|
|
return o.index.charCodeAt();
|
|
|
});
|
|
|
|
|
|
// 如果有数字,单独处理
|
|
|
if (hasNum) {
|
|
|
let brands = [];
|
|
|
|
|
|
_.forEach(numTemp, (subValue) => {
|
|
|
brands.push({
|
|
|
name: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
|
|
|
logo: subValue.brand_ico,
|
|
|
domain: subValue.brand_domain,
|
|
|
shopId: subValue.shop_id,
|
|
|
shopName: subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name,
|
|
|
isRedShop: subValue.is_red_shop,
|
|
|
shopTemplateType: subValue.shop_template_type
|
|
|
});
|
|
|
});
|
|
|
dest.brandList.push({
|
|
|
index: '0~9',
|
|
|
brands: brands
|
|
|
});
|
|
|
return dest;
|
|
|
}
|
|
|
|
|
|
dest.indexList.push({
|
|
|
index: '0_9',
|
|
|
name: '0'
|
|
|
/**
|
|
|
* 获取品牌列表页数据
|
|
|
* @param params
|
|
|
*/
|
|
|
getBrandListData(params) {
|
|
|
let finalResult = {};
|
|
|
let brandData = new BrandApi(this.ctx);
|
|
|
let that = this;
|
|
|
|
|
|
return brandData.getBrandListOriginData(params).then(result => {
|
|
|
if (result && result.data) {
|
|
|
Object.assign(finalResult, that.handleBrandList(result.data.all_list));
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return dest;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取品牌列表页数据
|
|
|
* @param params
|
|
|
*/
|
|
|
const getBrandListData = params => {
|
|
|
let finalResult = {};
|
|
|
/**
|
|
|
* 获取全部分类数据
|
|
|
* @param params
|
|
|
* @returns {*|Promise.<TResult>}
|
|
|
*/
|
|
|
getCateListData(params) {
|
|
|
let brandData = new BrandApi(this.ctx);
|
|
|
|
|
|
return brandApi.getBrandListOriginData(params).then(result => {
|
|
|
if (result && result.data) {
|
|
|
Object.assign(finalResult, handleBrandList(result.data.all_list));
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取全部分类数据
|
|
|
* @param params
|
|
|
* @returns {*|Promise.<TResult>}
|
|
|
*/
|
|
|
const getCateListData = params => {
|
|
|
return brandApi.getCateListData(params);
|
|
|
return brandData.getCateListData(params);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
/* module.exports = {
|
|
|
getBrandListData,
|
|
|
getCateListData
|
|
|
}; |
|
|
}; */ |
...
|
...
|
|