Authored by 李靖

Merge branch 'master' into feature/newHome

Too many changes to show.

To preserve performance only 26 of 26+ files are displayed.

... ... @@ -155,3 +155,4 @@ nbproject/*
.devhost
.happypack/*
.scannerwork
package-lock.json
... ...
... ... @@ -176,13 +176,13 @@ class BuyNowController {
// 是否开发票
if (req.body.invoice && req.body.invoice === 'true') {
let invoicePayableType = _.parseInt(req.body.invoice_payable_type);
let invoicePayableType = _.parseInt(req.body.invoice_payable_type) || 1;
let invoicesTitlePersonal = req.body.invoices_title_personal ? req.body.invoices_title_personal : '个人';
params.invoice = true;
params.invoices_type = req.body.invoices_type; // 发票类型:纸质 1,电子 2
params.receiverMobile = req.body.receiverMobile; // 接收人电话
params.invoice_payable_type = req.body.invoice_payable_type; // 区分个人或企业发票
params.invoice_payable_type = invoicePayableType; // 区分个人或企业发票
if (invoicePayableType === 1) {
// 开个人发票
... ...
... ... @@ -53,6 +53,14 @@ exports.orderEnsure = (req, res, next) => {
}
let orderPromise;
let params = {
uid: uid,
cartType: cartType,
orderInfo: orderInfo,
sku: sku,
skn: skn,
buyNumber: buyNumber,
};
if (req.query.cartType === 'bundle') {
if (!req.cookies._cartType) {
... ... @@ -60,9 +68,11 @@ exports.orderEnsure = (req, res, next) => {
}
let activityInfo = JSON.parse(req.cookies['activity-info']);
orderPromise = cartModel.cartPay(uid, cartType, orderInfo, null, sku, skn, buyNumber, activityInfo);
orderPromise = cartModel.cartPay(_.assign(params, {
activityInfo: activityInfo
}));
} else {
orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber);
orderPromise = cartModel.cartPay(params);
}
let allPromise = [
... ... @@ -152,16 +162,27 @@ exports.orderCompute = (req, res, next) => {
let type = req.body.type;
if (type !== 'tickets') {
let params = {
uid: uid,
cart_type: cartType,
delivery_way: deliveryId,
payment_type: paymentType,
coupon_code: couponCode,
use_yoho_coin: yohoCoin,
};
if (req.body.cartType === 'bundle') {
let activityInfo = JSON.parse(req.cookies['activity-info']);
cartModel.orderCompute(uid, cartType, deliveryId, paymentType,
couponCode, yohoCoin, null, activityInfo).then(result => {
cartModel.orderCompute(_.assign(params, {
activityInfo: activityInfo
})).then(result => {
res.json(result);
}).catch(next);
} else {
cartModel.orderCompute(uid, cartType, deliveryId, paymentType,
couponCode, yohoCoin, skuList).then(result => {
cartModel.orderCompute(_.assign(params, {
product_sku_list: skuList
})).then(result => {
res.json(result);
}).catch(next);
}
... ... @@ -204,14 +225,14 @@ exports.orderSub = (req, res, next) => {
// 是否有发票数据
if (orderInfo && orderInfo.invoice) {
let invoicePayableType = _.parseInt(orderInfo.invoice_payable_type);
let invoicePayableType = _.parseInt(orderInfo.invoice_payable_type) || 1;
let invoicesTitlePersonal = orderInfo.invoices_title_personal ? orderInfo.invoices_title_personal : '个人';
invoices = {
invoices_type_id: 12, // 发票类型写死【明细】
invoices_type: orderInfo.invoices_type, // 区分电子发票还是纸质发票
receiverMobile: orderInfo.receiverMobile, // 电话
invoice_payable_type: orderInfo.invoice_payable_type // 区分个人或企业发票
invoice_payable_type: invoicePayableType // 区分个人或企业发票
};
if (invoicePayableType === 1) {
... ... @@ -233,11 +254,19 @@ exports.orderSub = (req, res, next) => {
return co(function* () {
let result;
// 接口需要的其他参数
let otherParams = {
isPrintPrice: isPrintPrice,
unionKey: unionInfo.unionKey, // 友盟数据
let params = {
uid: uid,
address_id: addressId,
delivery_time: deliveryTimeId,
delivery_way: deliveryId,
invoices: invoices,
payment_id: paymentTypeId,
payment_type: paymentType,
remark: msg,
coupon_code: couponCode,
use_yoho_coin: yohoCoin,
is_print_price: isPrintPrice,
qhy_union: unionInfo.unionKey, // 友盟数据
userAgent: unionInfo.userAgent,
isWechat: req.yoho.isWechat,
ip: req.yoho.clientIp,
... ... @@ -248,13 +277,16 @@ exports.orderSub = (req, res, next) => {
if (req.body.cartType === 'bundle') {
let activityInfo = JSON.parse(req.cookies['activity-info']);
result = yield cartModel.orderSub(uid, addressId, 'bundle', deliveryTimeId,
deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
yohoCoin, null, times, activityInfo, otherParams);
result = yield cartModel.orderSub(_.assign(params, {
cart_type: 'bundle',
times: times,
activityInfo: activityInfo
}));
} else {
result = yield cartModel.orderSub(uid, addressId, cartType, deliveryTimeId,
deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
yohoCoin, skuList, null, null, otherParams);
result = yield cartModel.orderSub(_.assign(params, {
cart_type: cartType,
product_sku_list: skuList
}));
}
// 提交成功清除Cookie
... ...
... ... @@ -3,11 +3,11 @@
* @Author: Targaryen
* @Date: 2017-01-04 15:17:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-20 20:42:55
*/
'use strict';
const _ = require('lodash');
const mRoot = '../models';
const payModel = require(`${mRoot}/pay`);
const payTool = payModel.payTool;
... ... @@ -56,6 +56,12 @@ const payCenter = (req, res, next) => {
sessionKey: sessionKey
});
let attribute = _.parseInt(_.get(orderDetail, 'attribute'));
if (attribute === 9 || attribute === 11) {
return res.redirect('/home/orders');
}
/* 判断订单是否已付款, 已付款跳到订单详情页 */
if (orderDetail.payment_status === 'Y') {
logger.info(`payCenter: orderCode-${orderCode} already paied`);
... ... @@ -148,6 +154,15 @@ const pay = (req, res, next) => {
});
}
let attribute = _.parseInt(_.get(orderDetail, 'data.attribute'));
if (attribute === 9 || attribute === 11) {
return res.json({
code: 400,
message: '此订单只能通过 APP 支付'
});
}
if (orderDetail.data.is_cancel === 'Y') {
let url = helpers.urlFormat('/home/orders/detail', { order_code: orderCode });
... ...
... ... @@ -112,6 +112,7 @@ exports.ensure = (req, res, next) => {
}),
width750: true,
localCss: true,
userMobile: view.phoneNum,
cartToken: crypto.encryption(SLAT, [sku, activityId].join(''))
}, view));
})().catch(next);
... ... @@ -195,11 +196,8 @@ exports.submit = (req, res, next) => {
const options = {
sku_type: 'S',
buy_number: 1,
invoices_title: req.body.invoicesTitle || '',
invoices_type_id: req.body.invoicesTypeId || '',
use_yoho_coin: parseFloat(req.body.useYohoCoin) || 0,
remark: req.body.remark || '',
address_id: addressId,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
... ... @@ -211,6 +209,27 @@ exports.submit = (req, res, next) => {
ip: req.ip || ''
};
if (req.body.invoice === 'true') {
let invoicesTitlePersonal = req.body.invoices_title_personal ? req.body.invoices_title_personal : '个人';
let invoicePayableType = _.parseInt(req.body.invoice_payable_type);
_.assign(options, {
invoices_type: 2,
invoices_type_id: 12,
invoice_payable_type: invoicePayableType,
receiverMobile: req.body.receiverMobile || '',
});
if (invoicePayableType === 1) {
// 开个人发票
options.invoices_title = invoicesTitlePersonal;
} else {
// 开公司发票
options.invoices_title = req.body.invoices_title;
options.buyerTaxNumber = req.body.buyerTaxNumber;
}
}
return seckillModel.submit(options)
.then(result => {
res.clearCookie('order-info');
... ...
... ... @@ -22,50 +22,59 @@ const payModel = require('../models/pay');
* @param bool $isAjax 是否是异步请求
* @return array 接口返回的数据
*/
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, activityInfo) => {
exports.cartPay = (params) => {
let result = {};
let skuList = [];
let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
let isLimitGoods = params.skn && params.sku && params.buyNumber; // 存在sku, skn 和buyNumber时为限购商品
let orderComputeAPI = null;
if (isLimitGoods) {
skuList.push({
type: 'limitcode',
limitproductcode: limitProductCode,
buy_number: buyNumber,
skn,
sku
limitproductcode: params.limitProductCode,
buy_number: params.buyNumber,
skn: params.skn,
sku: params.sku
});
result.isLimit = true;
}
// cookie保存的数据
if (orderInfo && !_.isEmpty(orderInfo)) {
orderInfo.paymentType = orderInfo.paymentType ? orderInfo.paymentType : '';
orderComputeAPI = shoppingAPI.orderComputeAPI(
uid,
cartType,
orderInfo.deliveryId,
orderInfo.paymentType,
orderInfo.couponCode,
orderInfo.yohoCoin, skuList, activityInfo
);
if (params.orderInfo && !_.isEmpty(params.orderInfo)) {
params.orderInfo.paymentType = params.orderInfo.paymentType ? params.orderInfo.paymentType : '';
orderComputeAPI = shoppingAPI.orderComputeAPI({
uid: params.uid,
cart_type: params.cartType,
delivery_way: params.orderInfo.deliveryId,
payment_type: params.orderInfo.paymentType,
coupon_code: params.orderInfo.couponCode,
use_yoho_coin: params.orderInfo.yohoCoin,
product_sku_list: skuList,
activityInfo: params.activityInfo
});
}
// 区分套餐量贩和普通商品
let cartPayAPI;
let cartPayAPIParams = {
uid: params.uid,
cart_type: params.cartType,
product_sku_list: skuList
};
if (activityInfo) {
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList, activityInfo);
if (params.activityInfo) {
cartPayAPI = shoppingAPI.cartPayAPI(_.assign(cartPayAPIParams, {
activityInfo: params.activityInfo
}));
} else {
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList);
cartPayAPI = shoppingAPI.cartPayAPI(cartPayAPIParams);
}
return Promise.all([
cartPayAPI, // 0. 订单数据
orderComputeAPI,
shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券
shoppingAPI.getValidCouponCount(params.uid) // 2. 有效优惠券
]).then(res => {
let pay = res[0];
let orderCompute = _.get(res[1], 'data', {});
... ... @@ -87,10 +96,10 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
result = Object.assign(
result,
paymentProcess.tranformPayment(pay.data, orderInfo, cartType, skuList, orderCompute),
paymentProcess.tranformPayment(pay.data, params.orderInfo, params.cartType, skuList, orderCompute),
{
coupon: paymentProcess.coupon(validCouponCount, orderInfo, orderCompute)
coupon: paymentProcess.coupon(validCouponCount, params.orderInfo, orderCompute)
}
);
... ... @@ -110,9 +119,8 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
exports.orderCompute = (uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => {
return shoppingAPI.orderComputeAPI(uid, cartType, deliveryWay, paymentType,
couponCode, yohoCoin, skuList, activityInfo).then(result => {
exports.orderCompute = (params) => {
return shoppingAPI.orderComputeAPI(params).then(result => {
if (result && result.data) {
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
... ... @@ -162,40 +170,36 @@ exports.ticketsOrderCompute = (uid, productSku, buyNumber, yohoCoin) => {
* @param otherParams 其他参数
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark,
couponCode, yohoCoin, skuList, times, activityInfo, otherParams) => {
if (!otherParams.unionKey) {
otherParams.unionKey = '';
exports.orderSub = (params) => {
if (!params.qhy_union) {
params.qhy_union = '';
}
if (!otherParams.userAgent) {
otherParams.userAgent = null;
if (!params.userAgent) {
params.userAgent = null;
}
if (!times) {
times = 1;
if (!params.times) {
params.times = 1;
}
if (!activityInfo) {
activityInfo = null;
if (!params.activityInfo) {
params.activityInfo = null;
}
if (!addressId) {
if (!params.address_id) {
return Promise.resolve({code: 401, message: '配送地址不能为空'});
}
if (!deliveryTime) {
if (!params.delivery_time) {
return Promise.resolve({code: 402, message: '请选择配送时间'});
}
if (!deliveryWay) {
if (!params.delivery_way) {
return Promise.resolve({code: 403, message: '请选择配送方式'});
}
return shoppingAPI.orderSub(uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType,
remark, couponCode, yohoCoin, skuList, times, activityInfo, otherParams).then(orderSubRes => {
return shoppingAPI.orderSub(params).then(orderSubRes => {
let finalResult = {};
if (orderSubRes && orderSubRes.data && orderSubRes.data.is_hint === 'Y') {
... ... @@ -330,24 +334,23 @@ exports.jitDetailData = (uid, cartType, skuList, orderCode, sessionKey,
if (deliveryId) {
// 购物车选择改变字段,重新运算订单数据
return shoppingAPI.orderComputeAPI(
uid,
cartType,
deliveryId,
paymentType,
couponCode,
yohoCoin,
skuList
).then(result => {
return shoppingAPI.orderComputeAPI({
uid: uid,
cart_type: cartType,
delivery_way: deliveryId,
payment_type: paymentType,
coupon_code: couponCode,
use_yoho_coin: yohoCoin,
product_sku_list: skuList
}).then(result => {
return paymentProcess.transformJit(_.get(result, 'data.package_list', []));
});
} else {
return shoppingAPI.cartPayAPI(
uid,
cartType,
0,
skuList
).then(result => {
return shoppingAPI.cartPayAPI({
uid: uid,
cart_type: cartType,
product_sku_list: skuList
}).then(result => {
return paymentProcess.transformJit(_.get(result, 'data.shopping_cart_data.package_list', []));
});
}
... ...
... ... @@ -11,28 +11,28 @@ const api = global.yoho.API;
* @param string $skuList 购买限购商品时需要传递的参数
* @return see doc
*/
exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
exports.cartPayAPI = (params) => {
if (!params.activityInfo) {
params.activityInfo = null;
}
let param = {
method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
enable_red_envelopes: 0, // h5不返回红包
cart_type: cartType,
yoho_coin_mode: isUseYohoCoin,
uid: uid
cart_type: params.cart_type,
yoho_coin_mode: params.yoho_coin_mode,
uid: params.uid
};
// 购买限购商品时需要传递product_sku_list参数
if (!_.isEmpty(skuList)) {
param.product_sku_list = JSON.stringify(skuList);
if (!_.isEmpty(params.product_sku_list)) {
param.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套装和量贩商品时数据处理
if (activityInfo) {
param.activity_id = activityInfo.activity_id;
param.product_sku_list = JSON.stringify(activityInfo.product_sku_list);
if (params.activityInfo) {
param.activity_id = params.activityInfo.activity_id;
param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', param, {cache: false});
... ... @@ -56,38 +56,34 @@ exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
* 2. 除非同时调用app.Shopping.payment 与该接口,用改接口的data值替换app.Shopping.payment相关值,
* 显示调用utils/payment-process.js@tranformPayment(他会帮你调yohoCoinCompute)处理payment的data;
*/
exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
}
let param = {
method: activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
cart_type: cartType,
delivery_way: deliveWay,
payment_type: paymentType,
uid: uid
exports.orderComputeAPI = (params) => {
let finalParams = {
method: params.activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
cart_type: params.cart_type,
delivery_way: params.delivery_way,
payment_type: params.payment_type,
uid: params.uid
};
if (couponCode) {
param.coupon_code = couponCode;
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
if (yohoCoin) {
param.use_yoho_coin = yohoCoin;
if (params.use_yoho_coin) {
finalParams.use_yoho_coin = params.use_yoho_coin;
}
if (!_.isEmpty(skuList) && !activityInfo) {
param.product_sku_list = JSON.stringify(skuList);
if (!_.isEmpty(params.product_sku_list) && !params.activityInfo) {
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套餐商品需要的数据
if (activityInfo) {
param.activity_id = activityInfo.activity_id;
param.product_sku_list = JSON.stringify(activityInfo.product_sku_list);
if (params.activityInfo) {
finalParams.activity_id = params.activityInfo.activity_id;
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', param, {code: 200});
return api.get('', finalParams, {code: 200});
};
/**
... ... @@ -147,97 +143,91 @@ exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) =
* @param @param otherParams 其他参数
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark, couponCode,
yohoCoin, skuList, times, activityInfo, otherParams) => {
if (!activityInfo) {
activityInfo = null;
}
let params = {
method: activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
address_id: addressId,
cart_type: cartType,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_id: paymentId,
payment_type: paymentType,
remark: remark,
uid: uid,
udid: otherParams.udid,
is_print_price: otherParams.isPrintPrice
exports.orderSub = (params) => {
let finalParams = {
method: params.activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
address_id: params.address_id,
cart_type: params.cart_type,
delivery_time: params.delivery_time,
delivery_way: params.delivery_way,
payment_id: params.payment_id,
payment_type: params.payment_type,
remark: params.remark,
uid: params.uid,
udid: params.udid,
is_print_price: params.is_print_price
};
/* tar add 161130 结算优化 */
if (times === 2 || times === '2') {
params.is_continue_buy = 'Y';
if (params.times === 2 || params.times === '2') {
finalParams.is_continue_buy = 'Y';
} else {
params.is_continue_buy = 'N';
finalParams.is_continue_buy = 'N';
}
// 发票内容写死明细
if (invoices.invoices_type_id) {
params.invoice_content = 12;
if (params.invoices.invoices_type_id) {
finalParams.invoice_content = 12;
}
// 发票类型 纸质 1 ,电子 2
if (invoices.invoices_type) {
params.invoices_type = invoices.invoices_type;
if (params.invoices.invoices_type) {
finalParams.invoices_type = params.invoices.invoices_type;
}
// 发票类型:个人 1, 企业 2
if (invoices.invoice_payable_type) {
params.invoice_payable_type = invoices.invoice_payable_type;
if (params.invoices.invoice_payable_type) {
finalParams.invoice_payable_type = params.invoices.invoice_payable_type;
}
// 收票人手机号码
if (invoices.receiverMobile) {
params.receiverMobile = invoices.receiverMobile;
if (params.invoices.receiverMobile) {
finalParams.receiverMobile = params.invoices.receiverMobile;
}
// 发票抬头
if (invoices.invoices_title) {
params.invoices_title = invoices.invoices_title;
if (params.invoices.invoices_title) {
finalParams.invoices_title = params.invoices.invoices_title;
}
// 购买方纳税人识别号,需要开具电子发票且发票抬头为单位信息时为必填项
if (invoices.buyerTaxNumber) {
params.buyerTaxNumber = invoices.buyerTaxNumber;
if (params.invoices.buyerTaxNumber) {
finalParams.buyerTaxNumber = params.invoices.buyerTaxNumber;
}
if (couponCode) {
params.coupon_code = couponCode;
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
if (yohoCoin) {
params.use_yoho_coin = yohoCoin;
if (params.use_yoho_coin) {
finalParams.use_yoho_coin = params.use_yoho_coin;
}
// 购买限购商品时需要传递product_sku_list参数
if (skuList && !activityInfo) {
params.product_sku_list = JSON.stringify(skuList);
if (params.product_sku_list && !params.activityInfo) {
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套餐商品需要的数据
if (activityInfo) {
params.activity_id = activityInfo.activity_id;
params.product_sku_list = JSON.stringify(activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
if (params.activityInfo) {
finalParams.activity_id = params.activityInfo.activity_id;
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
}
// 友盟有关信息的传递
if (otherParams.unionKey) {
params.qhy_union = otherParams.unionKey;
if (params.qhy_union) {
finalParams.qhy_union = params.qhy_union;
}
// 是否是微信商城
if (otherParams.isWechat) {
params.client_type = 'wechat';
if (params.isWechat) {
finalParams.client_type = 'wechat';
}
return api.post('', params, {
return api.post('', finalParams, {
headers: {
'X-Forwarded-For': otherParams.ip || '',
'User-Agent': otherParams.userAgent
'X-Forwarded-For': params.ip || '',
'User-Agent': params.userAgent
}
});
};
... ...
... ... @@ -34,6 +34,11 @@
<span {{#if isSupportMessage}}data-message="{{isSupportMessage}}"{{/if}}>{{name}}</span>
<i class="right iconfont {{#if recommend}}icon-cb-radio{{else}}icon-radio{{/if}}" data-id="{{id}}" data-payment-type="{{paymentType}}"></i>
</li>
{{^}}
<li class="no-support">
<span class="tip" title="{{isSupportMessage}}" data-message="{{isSupportMessage}}">{{name}}({{isSupportMessage}})</span>
<i class="right iconfont icon-radio"></i>
</li>
{{/if}}
{{/each}}
</ul>
... ... @@ -50,7 +55,7 @@
<ul class="dispatch-mode">
{{#each dispatchMode}}
<li class="{{#if isSelected}}chosed{{/if}}{{#if is_support_message}} no-support{{/if}}" data-id="{{id}}">
<span>{{name}}:运费¥{{cost}} {{#if is_support_message}}({{is_support_message}}){{/if}}</span>
<span class="tip">{{name}}:运费¥{{cost}} {{#if is_support_message}}({{is_support_message}}){{/if}}</span>
<i class="right iconfont {{#if isSelected}}icon-cb-radio{{else}}icon-radio{{/if}}" data-id="{{id}}"></i>
</li>
{{/each}}
... ...
... ... @@ -18,7 +18,7 @@ const qs = require('querystring');
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let index = (req, res, next) => {
exports.index = (req, res, next) => {
let responseData = {
module: 'channel',
page: 'brand',
... ... @@ -44,7 +44,7 @@ let index = (req, res, next) => {
channel
};
indexModel.getBrandByChannel(param.channel).then(result => {
req.ctx(indexModel).getBrandByChannel(param.channel).then(result => {
res.render('brand/index', Object.assign(responseData, result, {
params: {
yhChannel: channel
... ... @@ -54,7 +54,7 @@ let index = (req, res, next) => {
};
// 301到新路由
let indexRedirect = (req, res) => {
exports.indexRedirect = (req, res) => {
let param = qs.stringify(req.query);
if (param) {
... ... @@ -63,10 +63,10 @@ let indexRedirect = (req, res) => {
res.redirect(301, `/${req.yoho.channel}-brands/${param}`);
};
let brandList = (req, res, next) => {
exports.brandList = (req, res, next) => {
var channel = req.query.channel || '1';
indexModel.getBrandListByChannel(channel).then(result => {
req.ctx(indexModel).getBrandListByChannel(channel).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -77,7 +77,7 @@ let brandList = (req, res, next) => {
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let search = (req, res, next) => {
exports.search = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '品牌一览'
});
... ... @@ -97,7 +97,7 @@ let search = (req, res, next) => {
channel: req.query.channel || '1'
};
indexModel.branchSearch(param).then(result => {
req.ctx(indexModel).branchSearch(param).then(result => {
res.render('brand/search', Object.assign(responseData, result));
}).catch(next);
... ... @@ -106,7 +106,7 @@ let search = (req, res, next) => {
/**
* 添加品牌搜索记录
*/
let addBrandSearch = (req, res, next) => {
exports.addBrandSearch = (req, res, next) => {
let uid = req.user.uid;
... ... @@ -123,7 +123,7 @@ let addBrandSearch = (req, res, next) => {
records
};
indexModel.addSearchHistory(param).then((result) => {
req.ctx(indexModel).addSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
... ... @@ -131,7 +131,7 @@ let addBrandSearch = (req, res, next) => {
/**
* 删除品牌搜索记录
*/
let delBrandHistory = (req, res, next) => {
exports.delBrandHistory = (req, res, next) => {
let param = {
... ... @@ -139,7 +139,7 @@ let delBrandHistory = (req, res, next) => {
};
indexModel.delBrandSearchHistory(param).then((result) => {
req.ctx(indexModel).delBrandSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
... ... @@ -147,7 +147,7 @@ let delBrandHistory = (req, res, next) => {
/**
* [品牌搜索异步数据]
*/
let searchAsync = (req, res, next) => {
exports.searchAsync = (req, res, next) => {
let uid = req.user.uid;
... ... @@ -162,7 +162,7 @@ let searchAsync = (req, res, next) => {
});
}
return indexModel.branchSearchHistoryAsync(uid).then((result) => {
return req.ctx(indexModel).branchSearchHistoryAsync(uid).then((result) => {
return res.json({
code: 200,
data: {
... ... @@ -171,13 +171,3 @@ let searchAsync = (req, res, next) => {
});
});
};
module.exports = {
index,
search,
brandList,
delBrandHistory,
addBrandSearch,
searchAsync,
indexRedirect
};
... ...
... ... @@ -10,7 +10,7 @@ let index = (req, res, next) => {
// 唤起 APP 的路径
res.locals.appPath = 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.attention","params":{"actiontype":"0"}}';
cateModel.getCateData(req.yoho.channel).then((result) => {
req.ctx(cateModel).getCateData(req.yoho.channel).then((result) => {
res.render('cate', {
module: 'channel',
page: 'cate',
... ...
... ... @@ -4,14 +4,14 @@
'use strict';
const customModel = require('../models/custom');
let index = (req, res, next) => {
exports.index = (req, res, next) => {
let contentCode = req.params.id;
if (!contentCode) {
return next();
}
customModel.getResourceData(contentCode).then(result => {
req.ctx(customModel).getResourceData(contentCode).then(result => {
res.render('custom', {
module: 'channel',
page: 'custom',
... ... @@ -21,7 +21,7 @@ let index = (req, res, next) => {
}).catch(next);
};
let zhihui = (req, res) => {
exports.zhihui = (req, res) => {
res.render('zhihui', {
module: 'channel',
page: 'custom',
... ... @@ -29,8 +29,3 @@ let zhihui = (req, res) => {
downloadLink: 'http://union.yoho.cn/union/downapp.html?union_type=100000000000081'
});
};
module.exports = {
index,
zhihui
};
... ...
... ... @@ -28,10 +28,9 @@ let _renderData = {
* @return {[type]}
*/
let _channelPage = (req, res, data) => {
return channelModel.getChannelData({
return req.ctx(channelModel).getChannelData({
gender: data.gender,
uid: req.user.uid,
limit: 6// 首屏先获取前6个楼层,其余用ajax获取
uid: req.user.uid
}).then(result => {
_renderData.homeHeader.defaultTerms = result.defaultTerms;
... ... @@ -40,7 +39,7 @@ let _channelPage = (req, res, data) => {
}
if (result && result.content && result.content.length) {
result.content.length = 6;
result.content.length = 6; // 首屏先获取前6个楼层,其余用ajax获取
}
// result.content = [{
... ... @@ -74,9 +73,9 @@ let _channelPage = (req, res, data) => {
/**
* 获取首页频道其余楼层
*/
let getResourceContent = (req, res, next) => {
exports.getResourceContent = (req, res, next) => {
return channelModel.getChannelResource({
return req.ctx(channelModel).getChannelResource({
gender: req.query.gender,
uid: req.user.uid,
}).then(result => {
... ... @@ -95,8 +94,8 @@ let getResourceContent = (req, res, next) => {
/**
* 频道选择页
*/
let index = (req, res, next) => {
channelModel.getChannelSwitchData().then((result) => {
exports.index = (req, res, next) => {
req.ctx(channelModel).getChannelSwitchData().then((result) => {
res.render('channel-index', {
module: 'channel',
page: 'index',
... ... @@ -119,7 +118,7 @@ let index = (req, res, next) => {
* @param {Function} next
* @return {Function}
*/
let switchChannel = (req, res, next) => {
exports.switchChannel = (req, res, next) => {
let channel = req.yoho.channel;
// 如果查询字符串设置了 go 参数,跳转到 cookie 中设置的频道页
... ... @@ -135,7 +134,7 @@ let switchChannel = (req, res, next) => {
/**
* 男生首页
*/
let boys = (req, res, next) => {
exports.boys = (req, res, next) => {
_channelPage(req, res, {
gender: 'boys',
... ... @@ -148,7 +147,7 @@ let boys = (req, res, next) => {
/**
* 女生首页
*/
let girls = (req, res, next) => {
exports.girls = (req, res, next) => {
_channelPage(req, res, {
gender: 'girls',
... ... @@ -162,7 +161,7 @@ let girls = (req, res, next) => {
* 潮童首页
*/
let kids = (req, res, next) => {
exports.kids = (req, res, next) => {
_channelPage(req, res, {
gender: 'kids',
... ... @@ -175,7 +174,7 @@ let kids = (req, res, next) => {
/**
* 创意生活首页
*/
let lifestyle = (req, res, next) => {
exports.lifestyle = (req, res, next) => {
_channelPage(req, res, {
gender: 'lifestyle',
... ... @@ -191,10 +190,10 @@ let lifestyle = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let bottomBanner = (req, res, next) => {
exports.bottomBanner = (req, res, next) => {
let gender = req.query.gender || 'boys';
channelModel.getBottomBannerData(gender).then(result => {
req.ctx(channelModel).getBottomBannerData(gender).then(result => {
res.send(result);
}).catch(next);
};
... ... @@ -202,8 +201,8 @@ let bottomBanner = (req, res, next) => {
/**
* 店铺推荐收藏状态人数
*/
let shopRecom = (req, res, next) => {
channelModel.shopRecom({
exports.shopRecom = (req, res, next) => {
req.ctx(channelModel).shopRecom({
shopIds: req.body.shopIds || '',
uid: req.user.uid || 0,
}).then(result => {
... ... @@ -214,7 +213,7 @@ let shopRecom = (req, res, next) => {
/**
* 获取用户vip信息
*/
let userVip = (req, res, next) => {
exports.userVip = (req, res, next) => {
let uid = req.user.uid;
if (!uid) {
... ... @@ -223,7 +222,7 @@ let userVip = (req, res, next) => {
msg: '未登录'
});
} else {
homeModel.getGradeGrade(uid, req.query.channel || 1).then(result => {
req.ctx(homeModel).getGradeGrade(uid, req.query.channel || 1).then(result => {
if (result.code === 200) {
res.json({
code: 200,
... ... @@ -237,18 +236,4 @@ let userVip = (req, res, next) => {
}
}).catch(next);
}
};
module.exports = {
switchChannel,
index,
boys,
girls,
kids,
lifestyle,
bottomBanner,
shopRecom,
userVip,
getResourceContent
};
... ...
... ... @@ -25,542 +25,433 @@ let CODE_TOPPOS_KIDS = '713784f93f52bb1a7b93916b2bb15510';
/* 创意生活频道取品牌广告及热门品牌数据的位置码 */
let CODE_TOPPOS_LIFESTYLE = 'f1aa914fd23cbcda71a87de6f5416c75';
/**
* 获取频道接口
*/
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const _packageAd = (params) => {
return service.get('/operations/api/v5/resource/get', {
content_code: params.contentCode,
gender: 1,
limit: 1000,
page: 1
}, {
cache: true
});
};
/**
* 获取频道接口
*/
_packageAd(params) {
return service.get('/operations/api/v5/resource/get', {
content_code: params.contentCode,
gender: 1,
limit: 1000,
page: 1
}, {
cache: true
});
}
const _packageList = (channel) => {
return api.get('', {
method: 'app.brand.allBrandList',
yh_channel: channel
}, {
cache: true,
code: 200
});
};
_packageList(channel) {
return api.get('', {
method: 'app.brand.allBrandList',
yh_channel: channel
}, {
cache: true,
code: 200
});
}
const getBrandByChannel = (channel) => {
let params = {};
getBrandByChannel(channel) {
let params = {};
/* 根据频道调用接口 */
switch (channel) {
case '1': // 男生
params = {
contentCode: CODE_TOPPOS_BOYS
};
break;
case '2': // 女生
params = {
contentCode: CODE_TOPPOS_GIRLS
};
break;
case '3': // 潮童
params = {
contentCode: CODE_TOPPOS_KIDS
};
break;
case '4': // 创意生活
params = {
contentCode: CODE_TOPPOS_LIFESTYLE
/* 根据频道调用接口 */
switch (channel) {
case '1': // 男生
params = {
contentCode: CODE_TOPPOS_BOYS
};
break;
case '2': // 女生
params = {
contentCode: CODE_TOPPOS_GIRLS
};
break;
case '3': // 潮童
params = {
contentCode: CODE_TOPPOS_KIDS
};
break;
case '4': // 创意生活
params = {
contentCode: CODE_TOPPOS_LIFESTYLE
};
break;
default:
channel = 1;
break;
}
return this._packageAd(params).then(result => {
let resu = {
channel: {
channels: [{
name: 'Boy',
channelName: 'boys'
}, {
name: 'Girl',
channelName: 'girls'
}, {
name: 'Kid',
channelName: 'kids'
}, {
name: 'Lifestyle',
channelName: 'lifestyle'
}],
topData: {
bannerTop: {},
hotBrandsScroll: {}
},
searchUrl: helpers.urlFormat('/brands/search', null),
brandPage: true,
brandType: '全部品牌',
secondBrandType: '新入驻品牌',
thirdBrandType: '热门品牌'
}
};
break;
default:
channel = 1;
break;
}
return _packageAd(params).then(result => {
let resu = {
channel: {
channels: [{
name: 'Boy',
channelName: 'boys'
}, {
name: 'Girl',
channelName: 'girls'
}, {
name: 'Kid',
channelName: 'kids'
}, {
name: 'Lifestyle',
channelName: 'lifestyle'
}],
topData: {
bannerTop: {},
hotBrandsScroll: {}
},
searchUrl: helpers.urlFormat('/brands/search', null),
brandPage: true,
brandType: '全部品牌',
secondBrandType: '新入驻品牌',
thirdBrandType: '热门品牌'
}
};
resu.channel.channels[channel - 1].active = true;
if (result && result.data) {
if (result.data[0] && result.data[0].data) {
// 轮播图资源位
let adList = result.data[0].data;
let build = [];
adList.forEach(ad => {
build.push({
img: helpers.image(ad.src, 640, 240),
url: ad.url
resu.channel.channels[channel - 1].active = true;
if (result && result.data) {
if (result.data[0] && result.data[0].data) {
// 轮播图资源位
let adList = result.data[0].data;
let build = [];
adList.forEach(ad => {
build.push({
img: helpers.image(ad.src, 640, 240),
url: ad.url
});
});
});
resu.channel.topData.bannerTop.list = build;
}
resu.channel.topData.bannerTop.list = build;
}
if (result.data[1] && result.data[1].data) {
// 推荐品牌资源位
let brandList = result.data[1].data.list || [];
let brand = [];
if (result.data[1] && result.data[1].data) {
// 推荐品牌资源位
let brandList = result.data[1].data.list || [];
let brand = [];
brandList.forEach(ad => {
brand.push({
img: helpers.image(ad.src, 140, 140),
url: ad.url,
textCn: ad.title
brandList.forEach(ad => {
brand.push({
img: helpers.image(ad.src, 140, 140),
url: ad.url,
textCn: ad.title
});
});
});
resu.channel.topData.hotBrandsScroll.name = result.data[1].data.title.title;
resu.channel.topData.hotBrandsScroll.list = brand;
resu.channel.topData.hotBrandsScroll.name = result.data[1].data.title.title;
resu.channel.topData.hotBrandsScroll.list = brand;
}
}
}
return resu;
});
};
return resu;
});
}
const _urlJump = (key, row) => {
_urlJump(key, row) {
return {
1: helpers.urlFormat('', {from: 'search', query: row.brand_name}, 'search'),
2: helpers.urlFormat('/product/shop', {domain: row.brand_domain}),
3: helpers.urlFormat('/product/global/list/', {brand: row.global_brand_id})
}[key];
};
return {
1: helpers.urlFormat('', {from: 'search', query: row.brand_name}, 'search'),
2: helpers.urlFormat('/product/shop', {domain: row.brand_domain}),
3: helpers.urlFormat('/product/global/list/', {brand: row.global_brand_id})
}[key];
}
const getBrandListByChannel = (channel) => {
return _packageList(channel).then(result => {
let resu = {
brandList: [],
newBrandWall: [],
recommandBrandWall: []
};
getBrandListByChannel(channel) {
return this._packageList(channel).then(result => {
let resu = {
brandList: [],
newBrandWall: [],
recommandBrandWall: []
};
if (!result || !result.data) {
return resu;
}
if (!result || !result.data) {
return resu;
}
/* 按字母'A-Z'分组的品牌列表 */
let allList = result.data.all_list;
/* 按字母'A-Z'分组的品牌列表 */
let allList = result.data.all_list;
for (let key in allList) {
if (key) {
let obj = {
title: key,
list: []
};
for (let key in allList) {
if (key) {
let obj = {
title: key,
list: []
};
allList[key].forEach(row => {
allList[key].forEach(row => {
obj.list.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: _urlJump(parseInt(row.type, 10), row)
obj.list.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: this._urlJump(parseInt(row.type, 10), row)
});
});
});
resu.brandList.push(obj);
resu.brandList.push(obj);
}
}
}
// 新入驻品牌
let newList = result.data.new_list;
// 新入驻品牌
let newList = result.data.new_list;
for (let key in newList) {
if (key) {
let obj = {
list: []
};
for (let key in newList) {
if (key) {
let obj = {
list: []
};
obj.list.push({
brandName: newList[key].brand_name,
url: _urlJump(parseInt(newList[key].type, 10), newList[key]),
img: helpers.image(newList[key].brand_ico, 186, 115),
});
resu.newBrandWall.push(obj);
obj.list.push({
brandName: newList[key].brand_name,
url: this._urlJump(parseInt(newList[key].type, 10), newList[key]),
img: helpers.image(newList[key].brand_ico, 186, 115),
});
resu.newBrandWall.push(obj);
}
}
}
// 推荐品牌
let hotList = result.data.hot_list;
// 推荐品牌
let hotList = result.data.hot_list;
for (let key in hotList) {
if (key) {
let obj = {
list: []
};
for (let key in hotList) {
if (key) {
let obj = {
list: []
};
obj.list.push({
brandName: hotList[key].brand_name,
url: _urlJump(parseInt(hotList[key].type, 10), hotList[key]),
img: helpers.image(hotList[key].brand_ico, 186, 115),
});
resu.recommandBrandWall.push(obj);
obj.list.push({
brandName: hotList[key].brand_name,
url: this._urlJump(parseInt(hotList[key].type, 10), hotList[key]),
img: helpers.image(hotList[key].brand_ico, 186, 115),
});
resu.recommandBrandWall.push(obj);
}
}
}
return resu;
});
};
/**
* 获取搜索的品牌列表
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const getBrandForSearch = (channel) => {
return api.get('', {
method: 'app.brand.allBrandList',
yh_channel: channel || 1
}, {
cache: true,
code: 200
}).then(result => {
return result;
});
};
/**
* 品牌搜索历史
* @param int $uid
* @author sefon 2016-5-17 12:12:28
* @return array
*/
const branchSearchHistory = (params) => {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: params.uid,
records: params.records || ''
}, {
code: 200
}).then(result => {
return result;
});
};
const addSearchHistory = (param) => {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: param.uid,
records: param.records
}, {
code: 200
});
};
/**
* 热搜品牌
* @author sefon 2016-5-17 12:20:26
* @return array
*/
const branchSearchHot = () => {
return api.get('', {
method: 'app.search.hotBrands'
}, {
cache: true,
code: 200
}).then(result => {
return result;
});
};
// /**
// * 获取搜索的品牌列表
// *
// * @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
// * @return array
// */
// const branchSearch = (params) => {
// return api.all([
// getBrandForSearch(params.channel),
// branchSearchHistory(params),
// branchSearchHot(),
// ]).then(result => {
// let resu = {
// brandPage: true,
// showDownloadApp: true,
// pageFooter: true,
// hot: [],
// history: [],
// brandList: []
// };
// if (result && result[0] && result[0].data) {
// let brandList = result[0].data.brands;
// let obj = {};
// for (let key in brandList) {
// let build = [];
// brandList[key].forEach(row => {
// build.push({
// name: row.brand_name,
// isHot: row.is_hot === 'Y' ? true : false,
// isNew: row.is_show_new === 'Y' ? true : false,
// url: helpers.urlFormat('', null, row.brand_domain),
// brandId: row.id,
// brandDomain: row.brand_domain,
// searchName: row.brand_name_en + row.brand_name_cn
// });
// obj[key] = build;
// });
// }
// resu.brandList = JSON.stringify(obj);
// }
// if (result && result[2] && result[2].data) {
// let hotList = result[2].data;
// for (let key in hotList) {
// let obj = {};
// obj = Object.assign(obj, {name: hotList[key].brandName});
// resu.hot.push(obj);
// }
// }
// if (result && result[1] && result[1].data) {
// let hisList = result[1].data;
// let obj = [];
return resu;
});
}
// let build = {
/**
* 获取搜索的品牌列表
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
getBrandForSearch(channel) {
return api.get('', {
method: 'app.brand.allBrandList',
yh_channel: channel || 1
}, {
cache: true,
code: 200
}).then(result => {
return result;
});
}
// list: []
/**
* 品牌搜索历史
* @param int $uid
* @author sefon 2016-5-17 12:12:28
* @return array
*/
branchSearchHistory(params) {
return api.get('', {
method: 'app.search.hotBrandRecords',
uid: params.uid,
records: params.records || ''
}, {
code: 200
}).then(result => {
return result;
});
}
// };
addSearchHistory(param) {
// for (let key in hisList) {
return api.get('', {
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
method: 'app.search.hotBrandRecords',
uid: param.uid,
records: param.records
// }
}, {
code: 200
});
}
// build.list = obj;
/**
* 热搜品牌
* @author sefon 2016-5-17 12:20:26
* @return array
*/
branchSearchHot() {
return api.get('', {
method: 'app.search.hotBrands'
// resu.history = build;
}, {
cache: true,
code: 200
}).then(result => {
// }
return result;
// return resu;
});
}
// });
// };
/**
* 获取搜索的品牌列表 pagecache重构
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
const branchSearch = (params) => {
return api.all([
/**
* 获取搜索的品牌列表 pagecache重构
*
* @param int $channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
* @return array
*/
branchSearch(params) {
return api.all([
getBrandForSearch(params.channel),
this.getBrandForSearch(params.channel),
// branchSearchHistory(params),
branchSearchHot(),
// branchSearchHistory(params),
this.branchSearchHot(),
]).then(result => {
]).then(result => {
let resu = {
brandPage: true,
pageFooter: true,
hot: [],
history: [],
brandList: []
};
let resu = {
brandPage: true,
pageFooter: true,
hot: [],
history: [],
brandList: []
};
if (result && result[0] && result[0].data) {
if (result && result[0] && result[0].data) {
let brandList = result[0].data.all_list;
let brandList = result[0].data.all_list;
let obj = {};
let obj = {};
for (let key in brandList) {
if (key) {
let build = [];
for (let key in brandList) {
if (key) {
let build = [];
brandList[key].forEach(row => {
build.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: _urlJump(parseInt(row.type, 10), row),
brandId: row.id,
brandDomain: row.brand_domain,
searchName: row.brand_name_en + row.brand_name_cn
brandList[key].forEach(row => {
build.push({
name: row.brand_name,
isHot: row.is_hot === 'Y' ? true : false,
isNew: row.is_show_new === 'Y' ? true : false,
url: this._urlJump(parseInt(row.type, 10), row),
brandId: row.id,
brandDomain: row.brand_domain,
searchName: row.brand_name_en + row.brand_name_cn
});
obj[key] = build;
});
obj[key] = build;
});
}
}
resu.brandList = JSON.stringify(obj);
}
resu.brandList = JSON.stringify(obj);
}
if (result && result[1] && result[1].data) {
if (result && result[1] && result[1].data) {
let hotList = result[1].data;
let hotList = result[1].data;
for (let key in hotList) {
if (key) {
let obj = {};
for (let key in hotList) {
if (key) {
let obj = {};
obj = Object.assign(obj, {
name: hotList[key].brandName
});
resu.hot.push(obj);
obj = Object.assign(obj, {
name: hotList[key].brandName
});
resu.hot.push(obj);
}
}
}
}
// if (result && result[1] && result[1].data) {
// if (result && result[1] && result[1].data) {
// let hisList = result[1].data;
// let hisList = result[1].data;
// let obj = [];
// let obj = [];
// let build = {
// let build = {
// list: []
// list: []
// };
// };
// for (let key in hisList) {
// for (let key in hisList) {
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
// obj.push({
// name: hisList[key].searchTerms,
// searchTime: hisList[key].searchTime
// });
// }
// }
// build.list = obj;
// build.list = obj;
// resu.history = build;
// resu.history = build;
// }
// }
return resu;
return resu;
});
};
});
}
const delBrandSearchHistory = (param) => {
delBrandSearchHistory(param) {
return api.get('', {
method: 'app.search.clearHotBrandRecords',
uid: param.uid
return api.get('', {
method: 'app.search.clearHotBrandRecords',
uid: param.uid
}, {
code: 200
}).then(result => {
}, {
code: 200
}).then(result => {
return result;
return result;
});
};
});
}
/**
* [异步获取用户最近搜索词]
*/
const branchSearchHistoryAsync = (uid) => {
return branchSearchHistory({
uid
}).then((result) => {
let hisList = result.data;
/**
* [异步获取用户最近搜索词]
*/
branchSearchHistoryAsync(uid) {
return this.branchSearchHistory({
uid
}).then((result) => {
let hisList = result.data;
let obj = [];
let obj = [];
let build = {
let build = {
list: []
list: []
};
};
for (let key in hisList) {
if (key) {
obj.push({
name: hisList[key].searchTerms,
searchTime: hisList[key].searchTime
});
for (let key in hisList) {
if (key) {
obj.push({
name: hisList[key].searchTerms,
searchTime: hisList[key].searchTime
});
}
}
}
build.list = obj;
return build;
});
};
build.list = obj;
module.exports = {
getBrandByChannel,
getBrandListByChannel,
branchSearch,
delBrandSearchHistory,
addSearchHistory,
branchSearchHistoryAsync
return build;
});
}
};
... ...
... ... @@ -16,78 +16,80 @@ const genderMap = {
lifestyle: '1,2,3'
};
let _processCateData = (list, channel) => {
let nav = ['boys', 'girls', 'kids', 'lifestyle'];
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
nav = _.map(nav, function(item) {
return {
name: _.capitalize(item),
channel: item,
focus: item === channel
};
});
_processCateData(list, channel) {
let nav = ['boys', 'girls', 'kids', 'lifestyle'];
_.map(list, function(item, key) {
item.focus = key === channel;
nav = _.map(nav, function(item) {
return {
name: _.capitalize(item),
channel: item,
focus: item === channel
};
});
_.map(item, function(firstItem) {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
if (firstItem.sub && firstItem.sub.length) {
_.map(firstItem.sub, function(secondItem) {
secondItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(secondItem, 'relation_parameter.sort'),
sort_name: secondItem.category_name,
gender: genderMap[key] || ''
}), 'list');
});
_.map(list, function(item, key) {
item.focus = key === channel;
_.map(item, function(firstItem) {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
if (firstItem.sub && firstItem.sub.length) {
_.map(firstItem.sub, function(secondItem) {
secondItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(secondItem, 'relation_parameter.sort'),
sort_name: secondItem.category_name,
gender: genderMap[key] || ''
}), 'list');
});
firstItem.sub.unshift({
category_name: `全部${firstItem.category_name}`,
url: helpers.urlFormat('/', utils.mapSort({
firstItem.sub.unshift({
category_name: `全部${firstItem.category_name}`,
url: helpers.urlFormat('/', utils.mapSort({
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || ''
}), 'list')
});
} else {
firstItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || ''
}), 'list')
});
} else {
firstItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || ''
}), 'list');
}
}), 'list');
}
});
});
});
return {
nav,
list
};
};
let getCateData = (channel) => {
return api.get('', {
method: 'app.sort.get'
}, {
cache: true
}).then((result) => {
return {
nav,
list
};
}
if (!result || !result.code || result.code !== 200 || !result.data) {
return [];
}
getCateData(channel) {
return api.get('', {
method: 'app.sort.get'
}, {
cache: true
}).then((result) => {
// 统一频道名称
result.data.boys = result.data.boy;
result.data.girls = result.data.girl;
_.unset(result.data, 'boy');
_.unset(result.data, 'girl');
if (!result || !result.code || result.code !== 200 || !result.data) {
return [];
}
return result.data;
}).then((list) => {
return _processCateData(list, channel);
});
};
// 统一频道名称
result.data.boys = result.data.boy;
result.data.girls = result.data.girl;
_.unset(result.data, 'boy');
_.unset(result.data, 'girl');
module.exports = {
getCateData
return result.data;
}).then((list) => {
return this._processCateData(list, channel);
});
}
};
... ...
... ... @@ -56,281 +56,279 @@ const channelList = [{
entitle: 'LIFESTYLE'
}];
/**
* 获取二级菜单顶部颜色
* @param {[string]} choosed
* @return {[string]}
*/
const _getSidebarColor = (choosed) => {
let color = false;
if (choosed === 'girls') {
color = '#FF88AE';
} else if (choosed === 'kids') {
color = '#7ad9f9';
} else if (choosed === 'lifestyle') {
color = '#4f4138';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return color;
};
/**
* 处理侧边栏数据
* @param {[array]} list
* @return {[array]}
*/
const _processSideBar = (list, choosed) => {
const formatData = [];
let offset = 0; // 分割数组用到的游标
list = list || [];
_.forEach(list, (item, i) => {
if (item.sub) {
item.sub.unshift({
sort_name: item.sort_name,
sort_name_en: item.sort_name_en,
back: true,
isSelect: false,
bgColor: _getSidebarColor(choosed)
});
}
// 如果有分隔符,分割数组
if (item.separative_sign === 'Y') {
formatData.push(list.slice(offset, i));
offset = i;
/**
* 获取二级菜单顶部颜色
* @param {[string]} choosed
* @return {[string]}
*/
_getSidebarColor(choosed) {
let color = false;
if (choosed === 'girls') {
color = '#FF88AE';
} else if (choosed === 'kids') {
color = '#7ad9f9';
} else if (choosed === 'lifestyle') {
color = '#4f4138';
}
});
// 数组被分割剩余的部分
formatData.push(list.slice(offset));
return formatData;
};
/**
* 获取频道页面资源位
* @param {[object]} gender
* @return {[type]}
*/
const getChannelResource = (params) => {
params.gender = params.gender || 'boys';
params.limit = params.limit || 30;
params = Object.assign(params, {
gender: genderData[params.gender] || '1,2,3',
content_code: contentCode[params.gender], // eslint-disable-line
page: 1
});
if (!params.uid) {
params.new_device = true; // eslint-disable-line
return color;
}
params.new_device = true;
return api.get('operations/api/v5/resource/home', params, {
cache: true
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
/**
* 处理侧边栏数据
* @param {[array]} list
* @return {[array]}
*/
_processSideBar(list, choosed) {
const formatData = [];
let offset = 0; // 分割数组用到的游标
list = list || [];
_.forEach(list, (item, i) => {
if (item.sub) {
item.sub.unshift({
sort_name: item.sort_name,
sort_name_en: item.sort_name_en,
back: true,
isSelect: false,
bgColor: this._getSidebarColor(choosed)
});
}
return resourcesProcess(result.data.list);
} else {
logger.error('index resouce is not 200');
return result;
}
});
};
/**
* 获取左侧边栏数据
* @param {[string]} choosed
* @return {[object]}
*/
const _getLeftNav = (choosed) => {
choosed = choosed || 'all';
return api.get('operations/api/v6/category/getCategory', {}, {
cache: true
}).then(result => {
// console.log(result)
if (result && result.code === 200) {
return _processSideBar(result.data, choosed);
} else {
logger.error('sidebar code is not 200');
return result;
}
});
};
// 如果有分隔符,分割数组
if (item.separative_sign === 'Y') {
formatData.push(list.slice(offset, i));
offset = i;
}
});
/**
* 获取热门搜索
**/
const _getSearchIndex = (params) => {
let channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
if (params.gender && channels[params.gender]) {
params.yh_channel = channels[params.gender];
delete params.gender;
// 数组被分割剩余的部分
formatData.push(list.slice(offset));
return formatData;
}
return API.get('', _.assign({
method: 'app.search.getTerms'
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('Hot Search return code is not 200');
return {};
/**
* 获取频道页面资源位
* @param {[object]} gender
* @return {[type]}
*/
getChannelResource(params) {
params.gender = params.gender || 'boys';
params.limit = params.limit || 100;
params = Object.assign(params, {
gender: genderData[params.gender] || '1,2,3',
content_code: contentCode[params.gender], // eslint-disable-line
page: 1
});
if (!params.uid) {
params.new_device = true; // eslint-disable-line
}
});
};
/**
* 获取频道选择页数据
* @return {[type]}
*/
const _getChannelList = () => {
return api.get('operations/api/v5/entrance/getEntrance', {}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
const list = {};
list.channelList = [];
list.yohood = {};
result.data.list = result.data.list || [];
_.forEach(result.data.list, function(item) {
let id = _.toNumber(item.id);
const channel = channelList[id - 1];
if (channel) {
list.channelList.push(channel);
}
params.new_device = true;
if (id === 5) {
list.yohood.showYohood = true;
list.yohood.yohoodHref = 'http://www.yohood.cn';
return api.get('operations/api/v5/resource/home', params, {
cache: true
}).then(result => {
if (result && result.code === 200 && result.data && result.data.list) {
for (let item of result.data.list) {
item.template_name === 'single_image' &&
item.data.length === 1 &&
(item.singleOne = true);
}
return resourcesProcess(result.data.list);
} else {
logger.error('index resouce is not 200');
return result;
}
});
}
if (id === 6) {
list.double11 = {};
list.double11.href = item.url;
}
});
/**
* 获取左侧边栏数据
* @param {[string]} choosed
* @return {[object]}
*/
_getLeftNav(choosed) {
choosed = choosed || 'all';
return Object.keys(list).length ? list : {
channelList: channelList
};
} else {
logger.error('channel select code is not 200');
return {
channelList: channelList
};
}
});
};
return api.get('operations/api/v6/category/getCategory', {}, {
cache: true
}).then(result => {
// console.log(result)
if (result && result.code === 200) {
return this._processSideBar(result.data, choosed);
} else {
logger.error('sidebar code is not 200');
return result;
}
});
}
/**
* 获取频道选择页 背景
* @return {[type]}
*/
const _getChannelBg = () => {
return api.get('operations/api/v5/resource/get', {
content_code: contentCode.index
}, {
cache: true
}).then(result => {
if (result && result.code === 200) {
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
} else {
logger.error('channel select background code is not 200');
return {
src: ''
};
/**
* 获取热门搜索
**/
_getSearchIndex(params) {
let channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
if (params.gender && channels[params.gender]) {
params.yh_channel = channels[params.gender];
delete params.gender;
}
});
};
/**
* 获取频道选择页面数据
* @param {[string]} gender
* @return {[type]}
*/
let getChannelSwitchData = () => {
return Promise.all([_getChannelList(), _getChannelBg()]);
};
/**
* 获取频道页面数据
* @param {[object]} params
* @return {[object]}
*/
let getChannelData = (params) => {
var channelData = {};
let navGender = _.cloneDeep(params.gender);
return Promise.all([getChannelResource(params), _getLeftNav(navGender), _getSearchIndex({
gender: navGender,
uid: params.uid,
})]).then((data) => {
channelData.content = data[0] || []; // 资源位数据
channelData.sideNav = data[1] || []; // 侧边栏数据
channelData.defaultTerms = (data[2] && data[2].defaultTerms && data[2].defaultTerms.length) ?
data[2].defaultTerms[0].content : '搜索商品、品牌';
return channelData;
});
};
return API.get('', _.assign({
method: 'app.search.getTerms'
}, params), {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('Hot Search return code is not 200');
return {};
}
});
}
/**
* 获取频道页底部 bannel 数据
* @param {[string]} gender
* @return {[type]}
*/
let getBottomBannerData = (gender) => {
gender = gender || 'boys';
/**
* 获取频道选择页数据
* @return {[type]}
*/
_getChannelList() {
return api.get('operations/api/v5/entrance/getEntrance', {}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
const list = {};
list.channelList = [];
list.yohood = {};
result.data.list = result.data.list || [];
_.forEach(result.data.list, function(item) {
let id = _.toNumber(item.id);
const channel = channelList[id - 1];
if (channel) {
list.channelList.push(channel);
}
if (id === 5) {
list.yohood.showYohood = true;
list.yohood.yohoodHref = 'http://www.yohood.cn';
}
if (id === 6) {
list.double11 = {};
list.double11.href = item.url;
}
});
return Object.keys(list).length ? list : {
channelList: channelList
};
} else {
logger.error('channel select code is not 200');
return {
channelList: channelList
};
}
});
}
if (gender === 'boys' || gender === 'girls') {
/**
* 获取频道选择页 背景
* @return {[type]}
*/
_getChannelBg() {
return api.get('operations/api/v5/resource/get', {
content_code: bottomBannerCode[gender] // eslint-disable-line
content_code: contentCode.index
}, {
cache: true
}).then(result => {
if (result && result.code === 200) {
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
} else {
logger.error('channel select background code is not 200');
return {
src: ''
};
}
});
}
return Promise.resolve({
code: 400,
data: '',
message: '参数错误'
});
};
/**
* 获取店铺推荐收藏和人数
*/
let shopRecom = (params) => {
return API.get('', {
method: 'app.shops.floorNewInfo',
shop_ids: params.shopIds,
uid: params.uid,
});
};
/**
* 获取频道选择页面数据
* @param {[string]} gender
* @return {[type]}
*/
getChannelSwitchData() {
return Promise.all([this._getChannelList(), this._getChannelBg()]);
}
module.exports = {
getChannelData,
getChannelResource,
getChannelSwitchData,
getBottomBannerData,
shopRecom,
/**
* 获取频道页面数据
* @param {[object]} params
* @return {[object]}
*/
getChannelData(params) {
var channelData = {};
let navGender = _.cloneDeep(params.gender);
return Promise.all([this.getChannelResource(params), this._getLeftNav(navGender), this._getSearchIndex({
gender: navGender,
uid: params.uid,
})]).then((data) => {
channelData.content = data[0] || []; // 资源位数据
channelData.sideNav = data[1] || []; // 侧边栏数据
channelData.defaultTerms = (data[2] && data[2].defaultTerms && data[2].defaultTerms.length) ?
data[2].defaultTerms[0].content : '搜索商品、品牌';
return channelData;
});
}
/**
* 获取频道页底部 bannel 数据
* @param {[string]} gender
* @return {[type]}
*/
getBottomBannerData(gender) {
gender = gender || 'boys';
if (gender === 'boys' || gender === 'girls') {
return api.get('operations/api/v5/resource/get', {
content_code: bottomBannerCode[gender] // eslint-disable-line
}, {
cache: true
});
}
return Promise.resolve({
code: 400,
data: '',
message: '参数错误'
});
}
/**
* 获取店铺推荐收藏和人数
*/
shopRecom(params) {
return API.get('', {
method: 'app.shops.floorNewInfo',
shop_ids: params.shopIds,
uid: params.uid,
});
}
};
... ...
... ... @@ -9,17 +9,19 @@ const utils = '../../../utils';
const resourcesProcess = require(`${utils}/resources-process`);
const service = global.yoho.ServiceAPI;
const getResourceData = (code) => {
return service.get('operations/api/v5/resource/get', {
content_code: code
}, {
cache: true,
code: 200
}).then(result => {
return resourcesProcess(result.data);
});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
module.exports = {
getResourceData
getResourceData(code) {
return service.get('operations/api/v5/resource/get', {
content_code: code
}, {
cache: true,
code: 200
}).then(result => {
return resourcesProcess(result.data);
});
}
};
... ...
... ... @@ -16,7 +16,7 @@ let channels = {
lifestyle: 4
};
const index = (req, res, next) => {
exports.index = (req, res, next) => {
let categoryTab = req.query.tab || '';
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
let brandCode;
... ... @@ -29,7 +29,7 @@ const index = (req, res, next) => {
brandCode = '84313c4b293a1c0aea985aa16a42a6b5';
}
brandModel.indexData(gender, brandCode, req.yoho.channel, appType).then(result => {
req.ctx(brandModel).indexData(gender, brandCode, req.yoho.channel, appType).then(result => {
res.render('brand/brand', {
module: 'guang',
... ... @@ -51,7 +51,7 @@ const index = (req, res, next) => {
}).catch(next);
};
const brandList = (req, res, next) => {
exports.brandList = (req, res, next) => {
let code;
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
... ... @@ -61,7 +61,7 @@ const brandList = (req, res, next) => {
code = '84313c4b293a1c0aea985aa16a42a6b5';
}
brandModel.brandListData(code, gender).then(result => {
req.ctx(brandModel).brandListData(code, gender).then(result => {
res.render('brand/brand-list', {
layout: false,
localCss: true,
... ... @@ -69,8 +69,3 @@ const brandList = (req, res, next) => {
});
}).catch(next);
};
module.exports = {
index,
brandList
};
... ...
... ... @@ -33,7 +33,7 @@ const praiseArticle = (req, res, next) => {
}
/* 执行点赞或取消操作 */
return optModel.praiseArticle(udid, id, opt).then((data) => {
return req.ctx(optModel).praiseArticle(udid, id, opt).then((data) => {
res.json(data);
}).catch(next);
};
... ... @@ -73,7 +73,7 @@ const collectArticle = (req, res, next) => {
}
/* 执行收藏或取消操作 */
return optModel.collectArticle(uid, id, opt).then(data => {
return req.ctx(optModel).collectArticle(uid, id, opt).then(data => {
if (!data) {
res.json({
code: 400,
... ... @@ -121,7 +121,7 @@ const favoriteBrand = (req, res, next) => {
}
// 执行收藏或取消操作
return brandModel.favoriteBrand(uid, id, opt, isBrand).then(data => {
return req.ctx(brandModel).favoriteBrand(uid, id, opt, isBrand).then(data => {
if (!data) {
res.json({
code: 400,
... ...
... ... @@ -61,7 +61,7 @@ exports.index = (req, res, next) => {
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"url":"http://guang.m.yohobuy.com${req.path}","param":${JSON.stringify(req.query)}}}`;
plusstarModel.getAllChannels({
req.ctx(plusstarModel).getAllChannels({
gender: gender,
app_type: 0
}).then(data => {
... ... @@ -69,7 +69,7 @@ exports.index = (req, res, next) => {
let focus = _.find(result.channel, d => d.focus) || {};
let code = focus.code || '';
return plusstarModel.getResourcesData({
return req.ctx(plusstarModel).getResourcesData({
content_code: code,
yh_channel: 1
}, {
... ... @@ -122,7 +122,7 @@ exports.userSkn = (req, res, next) => {
param.content_code = req.body.code || '';
param.yh_channel = req.body.yh_channel || 1;
plusstarModel.getFashionPrefer(param, {
req.ctx(plusstarModel).getFashionPrefer(param, {
isApp: isApp
}).then(result => {
let preferSkns = result.data || [];
... ... @@ -151,7 +151,7 @@ exports.resourcesTemplate = (req, res, next) => {
param.yh_channel = req.query.yh_channel || 1;
plusstarModel.getResourcesData(param, {
req.ctx(plusstarModel).getResourcesData(param, {
isApp: isApp
}).then(result => {
res.render('plusstar/resources-template', {
... ... @@ -174,7 +174,7 @@ exports.resourcesGoodsList = (req, res, next) => {
productSkn: productSkn.split(',')
};
plusstarModel.getProductBatch(param, {
req.ctx(plusstarModel).getProductBatch(param, {
isApp: isApp,
showSimilar: true
}).then(result => {
... ...
... ... @@ -23,7 +23,7 @@ let yhChannel = {
girl: 2
};
const getListData = (req, res, next) => {
exports.getListData = (req, res, next) => {
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || '1,3';
let recom = '4';
let all = '1';
... ... @@ -34,7 +34,7 @@ const getListData = (req, res, next) => {
let originalBrand = '3';
if (type === '2') {
plustarModel.getBrandsData(gender, starBrand, originalBrand, channel, isRecommend).then((result) => {
req.ctx(plustarModel).getBrandsData(gender, starBrand, originalBrand, channel, isRecommend).then((result) => {
_.forEach(result, r => {
let list = r.list || [];
... ... @@ -61,7 +61,7 @@ const getListData = (req, res, next) => {
});
}).catch(next);
} else {
plustarModel.getListData(gender, recom, all).then((result) => {
req.ctx(plustarModel).getListData(gender, recom, all).then((result) => {
_.forEach(result, r => {
let list = r.list || [];
let head3 = _.take(list, 3);
... ... @@ -85,7 +85,7 @@ const getListData = (req, res, next) => {
}
};
const getDetailData = (req, res, next) => {
exports.getDetailData = (req, res, next) => {
let uid = req.user.uid || req.query.uid;
let id = req.query.id;
let udid = req.sessionID || 'yoho';
... ... @@ -101,7 +101,7 @@ const getDetailData = (req, res, next) => {
uid = req.user.uid;
}
plustarModel.getDetailData(id, uid, udid, gender, isApp).then((result) => {
req.ctx(plustarModel).getDetailData(id, uid, udid, gender, isApp).then((result) => {
result.brand_intro = htmlProcess.removeHtml(result.brand_intro);
if (!isApp & !isWeixin) {
... ... @@ -133,7 +133,7 @@ const getDetailData = (req, res, next) => {
/**
* [品牌详情异步数据]
*/
const getDetailDataAsync = (req, res, next) => {
exports.getDetailDataAsync = (req, res, next) => {
let uid;
let udid = req.sessionID || 'yoho';
let brandId = req.body.brand_id || 0;
... ... @@ -150,16 +150,10 @@ const getDetailDataAsync = (req, res, next) => {
if (!brandId) {
return res.json({code: 400, message: '参数错误'});
}
plustarModel.getDetailDataAsync(brandId, uid, udid, isApp).then((result) => {
req.ctx(plustarModel).getDetailDataAsync(brandId, uid, udid, isApp).then((result) => {
res.json({
isLike: result.isLike,
infos: result.infos
});
}).catch(next);
};
module.exports = {
getListData,
getDetailData,
getDetailDataAsync
};
... ...
... ... @@ -45,12 +45,12 @@ const _processPublicData = (req, title) => {
* @param {[object]} res
* @return {[type]}
*/
let index = (req, res, next) => {
exports.index = (req, res, next) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[0].cur = true;
starModel.getIndexData().then((result) => {
req.ctx(starModel).getIndexData().then((result) => {
md5Str = result.md5;
res.render('star/index', _.assign({
page: 'star',
... ... @@ -67,8 +67,8 @@ let index = (req, res, next) => {
}).catch(next);
};
let getIndexHtml = (req, res, next) => {
starModel.getIndexData().then((result) => {
exports.getIndexHtml = (req, res, next) => {
req.ctx(starModel).getIndexData().then((result) => {
if (md5Str !== result.md5) {
md5Str = result.md5;
... ... @@ -93,8 +93,8 @@ let getIndexHtml = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let special = (req, res, next) => {
starModel.getSpecialData().then((result) => {
exports.special = (req, res, next) => {
req.ctx(starModel).getSpecialData().then((result) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[1].cur = true;
... ... @@ -115,7 +115,7 @@ let special = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let collocation = (req, res) => {
exports.collocation = (req, res) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[2].cur = true;
... ... @@ -134,11 +134,11 @@ let collocation = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let collocationList = (req, res, next) => {
exports.collocationList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0; // 客户端访问,不能使用 cookie
starModel.getCollocationListData(params, uid).then((result) => {
req.ctx(starModel).getCollocationListData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -154,14 +154,14 @@ let collocationList = (req, res, next) => {
* @param {[type]} res [description]
* @return {[type]}
*/
let setFavorite = (req, res, next) => {
exports.setFavorite = (req, res, next) => {
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
let params = {
articleId: req.body.articleId,
type: req.body.type
};
starModel.setFavorite(params, uid).then((result) => {
req.ctx(starModel).setFavorite(params, uid).then((result) => {
if (result.code === 400) {
if (req.body.pageType === '1') {
let urlEncode = '\/guang\/star\/collocation';
... ... @@ -185,7 +185,7 @@ let setFavorite = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let detail = (req, res) => {
exports.detail = (req, res) => {
res.render('star/detail', _.assign({
isStarDetailPage: true,
page: 'detail-list'
... ... @@ -198,11 +198,11 @@ let detail = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let detailList = (req, res, next) => {
exports.detailList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
starModel.getDetailData(params, uid).then((result) => {
req.ctx(starModel).getDetailData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -211,14 +211,3 @@ let detailList = (req, res, next) => {
}));
}).catch(next);
};
module.exports = {
index,
getIndexHtml,
special,
collocation,
collocationList,
setFavorite,
detail,
detailList
};
... ...
... ... @@ -26,279 +26,280 @@ const channelNav = {
girls: 'WOMEN女士'
};
const handleBrandList = origin => {
let dest = {
ListData: [],
indexList: []
};
let keyList = [];
// 标记是否有数字,有数字先暂存
let hasNum = false;
let numTemp = {};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_.forEach(origin, (value, key) => {
handleBrandList(origin) {
let dest = {
ListData: [],
indexList: []
};
if (_.size(value) <= 0) {
return;
}
let keyList = [];
_.forEach(value, function(subValue) {
subValue.brandUrl = helpers.urlFormat('/', {
query: subValue.brand_domain,
app_type: 1
}, 'search');
subValue.name = subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name;
subValue.domain = subValue.brand_domain;
});
// 标记是否有数字,有数字先暂存
let hasNum = false;
let numTemp = {};
if (key === '0~9') {
hasNum = true;
numTemp = origin[key];
} else {
_.forEach(origin, (value, key) => {
keyList.push(key);
}
if (_.size(value) <= 0) {
return;
}
});
_.forEach(value, function(subValue) {
subValue.brandUrl = helpers.urlFormat('/', {
query: subValue.brand_domain,
app_type: 1
}, 'search');
subValue.name = subValue.brand_name_en || subValue.brand_name_cn || subValue.brand_name;
subValue.domain = subValue.brand_domain;
});
keyList.sort();
if (key === '0~9') {
hasNum = true;
numTemp = origin[key];
} else {
_.forEach(keyList, function(key) {
let keyName = key;
keyList.push(key);
}
dest.ListData.push({
index: keyName,
brands: origin[key]
});
dest.indexList.push({
index: keyName,
name: key === '0~9' ? '0' : key
});
});
keyList.sort();
// 如果有数字,单独处理
if (hasNum) {
_.forEach(keyList, function(key) {
let keyName = key;
dest.ListData.push({
index: '0~9',
brands: numTemp
});
dest.ListData.push({
index: keyName,
brands: origin[key]
});
dest.indexList.push({
index: '0_9',
name: '0'
dest.indexList.push({
index: keyName,
name: key === '0~9' ? '0' : key
});
});
}
return dest;
};
// 如果有数字,单独处理
if (hasNum) {
const _getChannelData = (params) => {
let gender = params - 1 || 0;
return api.get('', {
method: 'app.blk.getAllChannels'
}, {
cache: true,
code: 200
}).then(result => {
let channel = [];
if (gender === 3 && result.data.length === 3) {
// 1:男,2:女,3:童装,4:创意生活
// 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
gender = 2;
}
dest.ListData.push({
index: '0~9',
brands: numTemp
});
_.forEach(result.data, (res, index) => {
channel.push({
id: res.channel_id,
mame: res.channel_name,
code: res.content_code,
focus: index === gender ? true : false
dest.indexList.push({
index: '0_9',
name: '0'
});
});
}
return channel;
});
};
return dest;
}
_getChannelData(params) {
let gender = params - 1 || 0;
return api.get('', {
method: 'app.blk.getAllChannels'
}, {
cache: true,
code: 200
}).then(result => {
let channel = [];
if (gender === 3 && result.data.length === 3) {
// 1:男,2:女,3:童装,4:创意生活
// 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
gender = 2;
}
_.forEach(result.data, (res, index) => {
channel.push({
id: res.channel_id,
mame: res.channel_name,
code: res.content_code,
focus: index === gender ? true : false
});
});
const _getResourcesData = (contentCode) => {
if (!contentCode) {
return [];
return channel;
});
}
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, {
cache: true,
code: 200
}).then(result => {
return result && result.data ? result.data : [];
});
};
const _getBrandListOriginData = (channel) => {
let finalResult = {};
return api.get('', {
method: 'app.brand.newBrandList',
yh_channel: yhChannel[channel].channel,
app_type: 1
}, {
code: 200,
cache: true
}).then(result => {
if (result.data && result.data.all_list) {
return Object.assign(finalResult, handleBrandList(result.data.all_list));
} else {
return {};
_getResourcesData(contentCode) {
if (!contentCode) {
return [];
}
});
};
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, {
cache: true,
code: 200
}).then(result => {
return result && result.data ? result.data : [];
});
}
// 全部分类数据
const _processCateData = (list, channel, appType) => {
let nav = ['MEN男士', 'WOMEN女士'];
_getBrandListOriginData(channel) {
let finalResult = {};
return api.get('', {
method: 'app.brand.newBrandList',
yh_channel: yhChannel[channel].channel,
app_type: 1
}, {
code: 200,
cache: true
}).then(result => {
if (result.data && result.data.all_list) {
return Object.assign(finalResult, this.handleBrandList(result.data.all_list));
} else {
return {};
}
});
}
nav = _.map(nav, function(item) {
return {
name: item,
channel: item,
focus: item === channelNav[channel]
};
});
_.forEach(list, function(item, key) {
item.focus = key === channelNav[channel];
_.forEach(item, function(firstItem) {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
if (firstItem.sub && firstItem.sub.length) {
_.forEach(firstItem.sub, function(secondItem) {
secondItem.url = helpers.urlFormat('/', {
sort: _.get(secondItem, 'relation_parameter.sort'),
sort_name: secondItem.category_name,
gender: genderMap[key] || '',
app_type: appType
}, 'list');
});
// 全部分类数据
_processCateData(list, channel, appType) {
let nav = ['MEN男士', 'WOMEN女士'];
firstItem.sub.unshift({
category_name: `全部${firstItem.category_name}`,
url: helpers.urlFormat('/', {
nav = _.map(nav, function(item) {
return {
name: item,
channel: item,
focus: item === channelNav[channel]
};
});
_.forEach(list, function(item, key) {
item.focus = key === channelNav[channel];
_.forEach(item, function(firstItem) {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
if (firstItem.sub && firstItem.sub.length) {
_.forEach(firstItem.sub, function(secondItem) {
secondItem.url = helpers.urlFormat('/', {
sort: _.get(secondItem, 'relation_parameter.sort'),
sort_name: secondItem.category_name,
gender: genderMap[key] || '',
app_type: appType
}, 'list');
});
firstItem.sub.unshift({
category_name: `全部${firstItem.category_name}`,
url: helpers.urlFormat('/', {
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || '',
app_type: appType
}, 'list')
});
} else {
firstItem.url = helpers.urlFormat('/', {
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || '',
app_type: appType
}, 'list')
});
} else {
firstItem.url = helpers.urlFormat('/', {
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || '',
app_type: appType
}, 'list');
}
}, 'list');
}
});
});
});
return {
nav,
list
};
};
return {
nav,
list
};
}
const _getCateData = (channel, appType) => {
return api.get('', {
method: 'app.sort.get',
app_type: 1
}, {
cache: true
}).then((result) => {
if (!result.code || result.code !== 200 || !result.data) {
return [];
}
_getCateData(channel, appType) {
return api.get('', {
method: 'app.sort.get',
app_type: 1
}, {
cache: true
}).then((result) => {
if (!result.code || result.code !== 200 || !result.data) {
return [];
}
return result.data;
}).then((list) => {
return _processCateData(list, channel, appType);
});
};
return result.data;
}).then((list) => {
return this._processCateData(list, channel, appType);
});
}
const indexData = (gender, brandCode, channel, appType) => {
return Promise.all([
_getChannelData(gender),
_getResourcesData(brandCode),
_getBrandListOriginData(gender),
_getCateData(channel, appType)
]).then(result => {
let brandList = {};
let list = {};
let categoryData = {};
if (result[0]) {
categoryData.channel = result[0];
list.channel = result[0];
}
indexData(gender, brandCode, channel, appType) {
return Promise.all([
this._getChannelData(gender),
this._getResourcesData(brandCode),
this._getBrandListOriginData(gender),
this._getCateData(channel, appType)
]).then(result => {
let brandList = {};
let list = {};
let categoryData = {};
if (result[0]) {
categoryData.channel = result[0];
list.channel = result[0];
}
if (result[1]) {
if (result[1]) {
_.forEach(result[1], function(data) {
if (data.focus_type === '1') {
brandList.bannerTop = data;
} else if (data.focus_type === '2') {
brandList.focusData = data.data;
}
});
}
_.forEach(result[1], function(data) {
if (data.focus_type === '1') {
brandList.bannerTop = data;
} else if (data.focus_type === '2') {
brandList.focusData = data.data;
}
});
}
if (result[2]) {
if (result[2]) {
brandList.listData = result[2].ListData;
brandList.indexList = result[2].indexList;
}
brandList.listData = result[2].ListData;
brandList.indexList = result[2].indexList;
}
if (result[3]) {
if (result[3]) {
list.categoryData = result[3];
}
list.brandList = brandList;
list.categoryData = result[3];
}
return list;
});
};
list.brandList = brandList;
const brandListData = (code, gender) => {
return Promise.all([_getResourcesData(code), _getBrandListOriginData(gender)]).then(result => {
let brandList = {};
let list = {};
if (result[0]) {
_.forEach(result[0], function(data) {
if (data.focus_type === '1') {
brandList.bannerTop = data;
} else if (data.focus_type === '2') {
brandList.focusData = data.data;
}
});
}
return list;
});
}
if (result[1]) {
brandList.listData = result[1].ListData;
brandList.indexList = result[1].indexList;
}
brandListData(code, gender) {
return Promise.all([this._getResourcesData(code), this._getBrandListOriginData(gender)]).then(result => {
let brandList = {};
let list = {};
if (result[0]) {
_.forEach(result[0], function(data) {
if (data.focus_type === '1') {
brandList.bannerTop = data;
} else if (data.focus_type === '2') {
brandList.focusData = data.data;
}
});
}
list.brandList = brandList;
return list;
});
};
if (result[1]) {
brandList.listData = result[1].ListData;
brandList.indexList = result[1].indexList;
}
module.exports = {
indexData,
brandListData
list.brandList = brandList;
return list;
});
}
};
... ...
... ... @@ -6,31 +6,33 @@
'use strict';
const api = global.yoho.API;
/**
* [收藏品牌或者商品]
* @param {[int]} uid [用户ID]
* @param {[int]} id [品牌ID]
* @param {Boolean} isBrand [是品牌还是商品]
* @param {string} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const favoriteBrand = (uid, id, opt, isBrand) => {
let param = {
uid: uid,
type: isBrand ? 'brand' : 'product'
};
if (opt === 'ok') {
param.id = id;
param.method = 'app.favorite.add';
} else {
param.fav_id = id;
param.method = 'app.favorite.cancel';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return api.post('', param);
};
/**
* [收藏品牌或者商品]
* @param {[int]} uid [用户ID]
* @param {[int]} id [品牌ID]
* @param {Boolean} isBrand [是品牌还是商品]
* @param {string} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
favoriteBrand(uid, id, opt, isBrand) {
let param = {
uid: uid,
type: isBrand ? 'brand' : 'product'
};
module.exports = {
favoriteBrand
if (opt === 'ok') {
param.id = id;
param.method = 'app.favorite.add';
} else {
param.fav_id = id;
param.method = 'app.favorite.cancel';
}
return api.post('', param);
}
};
... ...
... ... @@ -7,75 +7,75 @@
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
/**
* [逛资讯点赞/取消赞]
* @param {[int]} udid [唯一客户端标识]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const praiseArticle = (udid, id, opt) => {
let param = {
article_id: id,
udid: udid
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* [逛资讯点赞/取消赞]
* @param {[int]} udid [唯一客户端标识]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
praiseArticle(udid, id, opt) {
let param = {
article_id: id,
udid: udid
};
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v2/praise/cancel', param);
} else {
return serviceAPI.get('guang/api/v2/praise/setPraise', param);
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v2/praise/cancel', param);
} else {
return serviceAPI.get('guang/api/v2/praise/setPraise', param);
}
}
};
/**
* [逛资讯收藏/取消收藏 (APP里调用)]
* @param {[int]} uid [用户id]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
const collectArticle = (uid, id, opt) => {
let param = {
article_id: id,
uid: uid
};
/**
* [逛资讯收藏/取消收藏 (APP里调用)]
* @param {[int]} uid [用户id]
* @param {[int]} id [唯一资讯的ID]
* @param {[string]} opt [操作(ok:表示确定,cancel:表示取消)]
* @return {[array]}
*/
collectArticle(uid, id, opt) {
let param = {
article_id: id,
uid: uid
};
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', param);
} else {
return serviceAPI.get('guang/api/v1/favorite/setFavorite', param);
if (opt === 'cancel') {
return serviceAPI.get('guang/api/v1/favorite/cancelFavorite', param);
} else {
return serviceAPI.get('guang/api/v1/favorite/setFavorite', param);
}
}
};
// 品牌收藏
// 品牌收藏
const favoriteBrand = (uid, id, opt) => {
let param;
favoriteBrand(uid, id, opt) {
let param;
if (opt === 'ok') {
param = {
id: id,
uid: uid,
type: 'brand'
};
} else {
param = {
fav_id: id,
uid: uid,
type: 'brand'
};
}
if (opt === 'ok') {
param = {
id: id,
uid: uid,
type: 'brand'
};
} else {
param = {
fav_id: id,
uid: uid,
type: 'brand'
};
}
if (opt === 'ok') {
return api.get('app.favorite.add', param);
} else {
return api.get('app.favorite.cancel', param);
if (opt === 'ok') {
return api.get('app.favorite.add', param);
} else {
return api.get('app.favorite.cancel', param);
}
}
};
module.exports = {
praiseArticle,
collectArticle,
favoriteBrand
};
... ...
... ... @@ -4,196 +4,194 @@ const serviceAPI = global.yoho.ServiceAPI;
const _ = require('lodash');
const productProcess = require('../../../utils/product-process');
/**
* 获取潮流优选tab
* @return {[array]}
*/
const getAllChannels = (params) => {
let gender = params.gender - 1 || 0;
return api.get('', {
method: 'app.blk.getAllChannels',
app_type: params.app_type
}, {
cache: true
}).then(result => {
let data = {channel: []};
if (result.code !== 200) {
return data;
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
if (gender === 3 && result.data.length === 3) {
// 1:男,2:女,3:童装,4:创意生活
// 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
gender = 2;
}
/**
* 获取潮流优选tab
* @return {[array]}
*/
getAllChannels(params) {
let gender = params.gender - 1 || 0;
return api.get('', {
method: 'app.blk.getAllChannels',
app_type: params.app_type
}, {
cache: true
}).then(result => {
let data = {channel: []};
if (result.code !== 200) {
return data;
}
_.forEach(result.data, (res, index) => {
data.channel.push({
id: res.channel_id,
mame: res.channel_name,
code: res.content_code,
focus: index === gender ? true : false
if (gender === 3 && result.data.length === 3) {
// 1:男,2:女,3:童装,4:创意生活
// 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
gender = 2;
}
_.forEach(result.data, (res, index) => {
data.channel.push({
id: res.channel_id,
mame: res.channel_name,
code: res.content_code,
focus: index === gender ? true : false
});
});
});
return data;
});
};
return data;
});
}
/**
* 通过skn查询商品详情
* @param {[string || array]} productSkn 商品skn
* @return {[array]}
*/
const getProductBatch = (param, options) => {
param.productSkn = _.isArray(param.productSkn) ? param.productSkn : [param.productSkn];
return api.get('', {
method: 'h5.product.batch',
productSkn: param.productSkn.join(','),
yh_channel: param.yh_channel,
page: param.page,
limit: param.limit
}, {
cache: true
}).then(result => {
let data = {};
if (result && result.data) {
data = {
page_total: result.data.page_total,
product_list: productProcess.processProductList(result.data.product_list, options)
};
}
return data;
});
};
/**
* 通过skn查询商品详情
* @param {[string || array]} productSkn 商品skn
* @return {[array]}
*/
getProductBatch(param, options) {
param.productSkn = _.isArray(param.productSkn) ? param.productSkn : [param.productSkn];
return api.get('', {
method: 'h5.product.batch',
productSkn: param.productSkn.join(','),
yh_channel: param.yh_channel,
page: param.page,
limit: param.limit
}, {
cache: true
}).then(result => {
let data = {};
if (result && result.data) {
data = {
page_total: result.data.page_total,
product_list: productProcess.processProductList(result.data.product_list, options)
};
}
return data;
});
}
/**
* 商品推荐获取
* @param {[int]} yh_channel 当前频道
* @param {[int]} uid 用户id
* @return {[array]}
*/
const getFashionPrefer = (params) => {
return api.get('', Object.assign({
method: 'h5.product.fashionPrefer'
}, params));
};
/**
* 商品推荐获取
* @param {[int]} yh_channel 当前频道
* @param {[int]} uid 用户id
* @return {[array]}
*/
getFashionPrefer(params) {
return api.get('', Object.assign({
method: 'h5.product.fashionPrefer'
}, params));
}
/**
* 获取资源位数据
* @param {[string]} content_code
* @return {[array]}
*/
const getResources = (params, options) => {
params = params || {};
/**
* 获取资源位数据
* @param {[string]} content_code
* @return {[array]}
*/
getResources(params, options) {
params = params || {};
if (options.isApp) {
params.platform = 'iphone';
}
return serviceAPI.get('operations/api/v5/resource/get', params, {
cache: true
}).then(result => {
let data = {
goods: {},
recommend: {}
};
let list = {};
let productSkns = [];
if (result && result.code !== 200) {
return data;
if (options.isApp) {
params.platform = 'iphone';
}
return serviceAPI.get('operations/api/v5/resource/get', params, {
cache: true
}).then(result => {
let data = {
goods: {},
recommend: {}
};
let list = {};
let productSkns = [];
_.forEach(result.data, (res) => {
list = {};
switch (res.template_name) {
case 'focus':
list = {
data: res.data
};
if (res.focus_type * 1 === 1) {
data.focus1 = list;
data.focus1.id = res.template_id;
} else {
data.focus2 = list;
data.focus2.id = res.template_id;
}
break;
case 'title_image' :
if (typeof data[res.template_name] === 'undefined') {
data[res.template_name] = [];
}
list = {
id: res.template_id,
title: res.data.title,
moreUrl: res.data.more_url,
moreName: res.data.more_name,
image: res.data.image
};
data.title_image.push(list);
break;
case 'titleFloor':
list = {
name: res.data.title.name,
moreUrl: res.data.title.more_url,
moreName: res.data.title.more_name
};
if (res.data.title.name === '热门商品') {
data.goods.title = list;
data.goods.id = res.template_id;
} else if (res.data.title.name === '热门品类') {
data.recommend.title = list;
data.recommend.id = res.template_id;
}
break;
case 'recommend_content_five':
data.recommend.data = res.data.list;
break;
case 'goods':
_.forEach(res.data, (skn) => {
productSkns.push(skn.id);
});
data[res.template_name].productSkns = productSkns;
break;
default:
break;
if (result && result.code !== 200) {
return data;
}
});
return data;
});
};
_.forEach(result.data, (res) => {
list = {};
switch (res.template_name) {
case 'focus':
list = {
data: res.data
};
if (res.focus_type * 1 === 1) {
data.focus1 = list;
data.focus1.id = res.template_id;
} else {
data.focus2 = list;
data.focus2.id = res.template_id;
}
break;
case 'title_image' :
if (typeof data[res.template_name] === 'undefined') {
data[res.template_name] = [];
}
list = {
id: res.template_id,
title: res.data.title,
moreUrl: res.data.more_url,
moreName: res.data.more_name,
image: res.data.image
};
data.title_image.push(list);
break;
case 'titleFloor':
list = {
name: res.data.title.name,
moreUrl: res.data.title.more_url,
moreName: res.data.title.more_name
};
if (res.data.title.name === '热门商品') {
data.goods.title = list;
data.goods.id = res.template_id;
} else if (res.data.title.name === '热门品类') {
data.recommend.title = list;
data.recommend.id = res.template_id;
}
break;
case 'recommend_content_five':
data.recommend.data = res.data.list;
break;
case 'goods':
_.forEach(res.data, (skn) => {
productSkns.push(skn.id);
});
data[res.template_name].productSkns = productSkns;
break;
default:
break;
}
});
const getResourcesData = (params, options) => {
return api.all([
getResources(params, options),
getFashionPrefer(params)
]).then(result => {
let skns = result[0] && result[0].goods && result[0].goods.productSkns || [];
let preferSkns = result[1] && result[1].data || [];
return data;
});
}
if (result[0] && result[0].goods && result[0].goods.productSkns) {
result[0].goods.productSkns = _.uniq(skns.concat(preferSkns));
}
getResourcesData(params, options) {
return api.all([
this.getResources(params, options),
this.getFashionPrefer(params)
]).then(result => {
let skns = result[0] && result[0].goods && result[0].goods.productSkns || [];
let preferSkns = result[1] && result[1].data || [];
return result[0];
});
};
if (result[0] && result[0].goods && result[0].goods.productSkns) {
result[0].goods.productSkns = _.uniq(skns.concat(preferSkns));
}
module.exports = {
getAllChannels,
getResources,
getFashionPrefer,
getProductBatch,
getResourcesData
return result[0];
});
}
};
... ...
... ... @@ -9,355 +9,353 @@ const helpers = global.yoho.helpers;
const htmlProcess = require(`${global.utils}/html-process`);
const imageProcess = require(`${global.utils}/image`);
const formaData = (data, gender) => {
let build = [];
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_.forEach(data, function(val) {
// 多张图
if (val.data[1]) {
let imgs = [];
formaData(data, gender) {
let build = [];
_.forEach(val.data, function(list) {
let obj = {};
_.forEach(data, function(val) {
// 多张图
if (val.data[1]) {
let imgs = [];
obj = _.assign(obj, {
url: '/guang/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
});
_.forEach(val.data, function(list) {
let obj = {};
imgs.push(obj);
});
obj = _.assign(obj, {
url: '/guang/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
});
build.push({
imgs: imgs
});
}
imgs.push(obj);
});
// 单张图
if (val.data[0] && !val.data[1]) {
_.forEach(val.data, function(list) {
build.push({
url: '/guang/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
imgs: imgs
});
});
}
});
return build;
};
}
const getContentData = (gender, type, channel, isRecommend) => {
let param = {
gender: gender,
brand_type: type,
yh_channel: channel
};
// 单张图
if (val.data[0] && !val.data[1]) {
_.forEach(val.data, function(list) {
build.push({
url: '/guang/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
});
});
}
});
if (isRecommend) {
param.is_recommend = isRecommend;
return build;
}
return serviceAPI.get('guang/api/v3/plustar/getlist', param, {cache: true}).then((result) => {
if (result && result.code === 200) {
return formaData(result.data.data.list[0].data, gender);
} else {
logger.error('list data return code is not 200');
return {};
getContentData(gender, type, channel, isRecommend) {
let param = {
gender: gender,
brand_type: type,
yh_channel: channel
};
if (isRecommend) {
param.is_recommend = isRecommend;
}
});
};
const getListData = (gender, recom, all) => {
return Promise.all([getContentData(gender, recom), getContentData(gender, all)]).then((result) => {
let ps = [];
return serviceAPI.get('guang/api/v3/plustar/getlist', param, {cache: true}).then((result) => {
if (result && result.code === 200) {
return this.formaData(result.data.data.list[0].data, gender);
} else {
logger.error('list data return code is not 200');
return {};
}
});
}
if (result[0]) {
ps.push({
focus: true,
name: '设计师',
list: result[0]
});
}
getListData(gender, recom, all) {
return Promise.all([this.getContentData(gender, recom), this.getContentData(gender, all)]).then((result) => {
let ps = [];
if (result[1]) {
ps.push({
name: '经典潮牌',
list: result[1]
});
}
return ps;
});
};
if (result[0]) {
ps.push({
focus: true,
name: '设计师',
list: result[0]
});
}
const getBrandsData = (gender, starBrand, originalBrand, channel, isRecommend) => {
return Promise.all([
getContentData(gender, starBrand, isRecommend, channel),
getContentData(gender, originalBrand, isRecommend, channel)
]).then((result) => {
let ps = [];
if (result[1]) {
ps.push({
focus: true,
name: '原创潮牌',
list: result[1]
});
}
if (result[1]) {
ps.push({
name: '经典潮牌',
list: result[1]
});
}
return ps;
});
}
if (result[0]) {
ps.push({
name: '明星潮品',
list: result[0]
});
}
return ps;
});
};
getBrandsData(gender, starBrand, originalBrand, channel, isRecommend) {
return Promise.all([
this.getContentData(gender, starBrand, isRecommend, channel),
this.getContentData(gender, originalBrand, isRecommend, channel)
]).then((result) => {
let ps = [];
if (result[1]) {
ps.push({
focus: true,
name: '原创潮牌',
list: result[1]
});
}
// 新品到着
const getNewProduct = (brandId, gender, url, isApp) => {
if (result[0]) {
ps.push({
name: '明星潮品',
list: result[0]
});
}
return ps;
});
}
return api.get('', {
method: 'app.search.li',
brand: brandId,
gender: gender,
limit: 6,
order: 's_t_desc',
page: 1
}, {cache: true}).then((result) => {
// 新品到着
getNewProduct(brandId, gender, url, isApp) {
if (result && result.code === 200) {
return api.get('', {
method: 'app.search.li',
brand: brandId,
gender: gender,
limit: 6,
order: 's_t_desc',
page: 1
}, {cache: true}).then((result) => {
let newArrival = {
naList: []
};
if (result && result.code === 200) {
if (result.data.product_list) {
_.forEach(result.data.product_list, function(list, index) {
let obj = {};
let price;
let newArrival = {
naList: []
};
if (index <= 5) {
let tag = [];
if (result.data.product_list) {
_.forEach(result.data.product_list, function(list, index) {
let obj = {};
let price;
if (!list.product_skn) {
return false;
}
if (index <= 5) {
let tag = [];
if (list.market_price === list.sales_price) {
list.market_price = false;
}
tag.push({
is_new: list.is_new === 'Y',
is_discount: list.is_discount === 'Y',
is_limited: list.is_limited === 'Y',
is_yohood: list.is_yohood === 'Y',
is_advance: list.is_advance === 'Y'
});
_.forEach(tag, function(data) {
if (data.is_discount === true && list.is_soon_soldOut === true) {
data.is_new = true;
data.is_discount = false;
} else if (data.is_discount === true &&
(data.is_new === true || data.is_limited === true ||
data.is_yohood === true || data.is_advance === true)) {
data.is_discount = false;
} else if (data.is_yohood === true && data.is_new === true) {
data.is_new = false;
if (!list.product_skn) {
return false;
}
});
if (list.market_price && list.market_price !== false) {
price = list.market_price + '.00';
}
if (list.market_price === list.sales_price) {
list.market_price = false;
}
tag.push({
is_new: list.is_new === 'Y',
is_discount: list.is_discount === 'Y',
is_limited: list.is_limited === 'Y',
is_yohood: list.is_yohood === 'Y',
is_advance: list.is_advance === 'Y'
});
newArrival.moreUrl = url;
_.forEach(tag, function(data) {
if (data.is_discount === true && list.is_soon_soldOut === true) {
data.is_new = true;
data.is_discount = false;
} else if (data.is_discount === true &&
(data.is_new === true || data.is_limited === true ||
data.is_yohood === true || data.is_advance === true)) {
data.is_discount = false;
} else if (data.is_yohood === true && data.is_new === true) {
data.is_new = false;
}
});
if (list.cn_alphabet) {
list.cn_alphabet = productNameProcess(list.cn_alphabet);
}
if (list.market_price && list.market_price !== false) {
price = list.market_price + '.00';
}
let productUrl = '//m.yohobuy.com/product/' + list.product_skn + '.html'; // 商品url改版
newArrival.moreUrl = url;
if (isApp) {
productUrl += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${list.product_skn}"}}`; // eslint-disable-line
}
if (list.cn_alphabet) {
list.cn_alphabet = productNameProcess(list.cn_alphabet);
}
let productUrl = '//m.yohobuy.com/product/' + list.product_skn + '.html'; // 商品url改版
if (isApp) {
productUrl += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${list.product_skn}"}}`; // eslint-disable-line
}
obj = _.assign(obj, {
id: list.product_skn,
product_id: list.product_id,
thumb: helpers.image(list.default_images, 235, 314),
name: list.product_name,
salePrice: list.sales_price + '.00',
studentPrice: list.sales_price * 0.9,
is_soon_sold_out: list.is_soon_sold_out === 'Y',
isShowSaleTagDis: list.sales_price * 2 < list.market_price,
url: productUrl,
tags: tag
});
if (price) {
obj = _.assign(obj, {
price: price
id: list.product_skn,
product_id: list.product_id,
thumb: helpers.image(list.default_images, 235, 314),
name: list.product_name,
salePrice: list.sales_price + '.00',
studentPrice: list.sales_price * 0.9,
is_soon_sold_out: list.is_soon_sold_out === 'Y',
isShowSaleTagDis: list.sales_price * 2 < list.market_price,
url: productUrl,
tags: tag
});
}
obj = _.assign(obj, {
similar: true
});
if (price) {
obj = _.assign(obj, {
price: price
});
}
newArrival.naList.push(obj);
obj = _.assign(obj, {
similar: true
});
}
});
newArrival.naList.push(obj);
}
});
}
return newArrival;
} else {
logger.error('new data return code is not 200');
return {};
}
});
};
}
return newArrival;
} else {
logger.error('new data return code is not 200');
return {};
}
});
}
// 相关资讯--不能加cache,否则点赞有缓存.
const getRelatedEditorial = (brandId, uid, udid, isApp) => {
// 相关资讯--不能加cache,否则点赞有缓存.
getRelatedEditorial(brandId, uid, udid, isApp) {
return serviceAPI.get('guang/service/v1/article/getArticleByBrand', {
brand_id: brandId,
uid: uid,
udid: udid,
limit: 3
}).then((result) => {
if (result && result.code === 200) {
return serviceAPI.get('guang/service/v1/article/getArticleByBrand', {
brand_id: brandId,
uid: uid,
udid: udid,
limit: 3
}).then((result) => {
if (result && result.code === 200) {
let list = [];
let list = [];
_.forEach(result.data, function(data) {
if (isApp) {
data.url = data.url + '';
}
_.forEach(result.data, function(data) {
if (isApp) {
data.url = data.url + '';
}
list.push({
id: data.id,
url: isApp ? `${helpers.https(data.url)}&openby:yohobuy={"action":"go.h5","params":{"param":{"id":"${data.id}"},"shareparam":{"id":"${data.id}"},"share":"/guang/api/v1/share/guang","id":${data.id},"type":1,"url":"http:${helpers.urlFormat('/info/index', null, 'guang')}","islogin":"N"}}` : data.url, // eslint-disable-line
title: data.title,
text: data.intro,
img: helpers.image(data.src, 640, 640),
publishTime: data.publish_time,
like: data.like,
pageView: data.views_num
list.push({
id: data.id,
url: isApp ? `${helpers.https(data.url)}&openby:yohobuy={"action":"go.h5","params":{"param":{"id":"${data.id}"},"shareparam":{"id":"${data.id}"},"share":"/guang/api/v1/share/guang","id":${data.id},"type":1,"url":"http:${helpers.urlFormat('/info/index', null, 'guang')}","islogin":"N"}}` : data.url, // eslint-disable-line
title: data.title,
text: data.intro,
img: helpers.image(data.src, 640, 640),
publishTime: data.publish_time,
like: data.like,
pageView: data.views_num
});
});
});
return list;
} else {
logger.error('editorial data return code is not 200');
return {};
}
});
};
return list;
} else {
logger.error('editorial data return code is not 200');
return {};
}
});
}
// 是否收藏
const isCollection = (brandId, uid) => {
// 是否收藏
isCollection(brandId, uid) {
let param = {
brandId: brandId
};
let param = {
brandId: brandId
};
if (uid) {
param.uid = uid;
}
if (uid) {
param.uid = uid;
}
return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', param).then((result) => {
return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', param).then((result) => {
if (result && result.code === 200) {
if (result && result.code === 200) {
let isLike = true;
let isLike = true;
return isLike;
} else {
let isLike = false;
return isLike;
} else {
let isLike = false;
return isLike;
}
});
};
return isLike;
}
});
}
// 品牌详情
const getDetailData = (id, uid, udid, gender, isApp) => {
// 品牌详情
getDetailData(id, uid, udid, gender, isApp) {
return serviceAPI.get('guang/api/v1/plustar/getbrandinfo', {
id: id
}, {cache: true}).then((result) => {
if (result && result.code === 200) {
let list = result.data || [];
let jumpToApp;
return serviceAPI.get('guang/api/v1/plustar/getbrandinfo', {
id: id
}, {cache: true}).then((result) => {
if (result && result.code === 200) {
let list = result.data || [];
let jumpToApp;
let url;
let url;
let brandId = list.brand_id;
let brandDomain = list.brand_domain;
let isDifferent = list.is_different;
let brandId = list.brand_id;
let brandDomain = list.brand_domain;
let isDifferent = list.is_different;
if (isApp) {
url = '?openby:yohobuy={"action":"go.brand","params":{"brand_id":"' + brandId + '","is_different":"' + isDifferent + '"}}'; // eslint-disable-line
uid = parseInt(uid, 10);
} else {
url = '//' + brandDomain + '.m.yohobuy.com';
}
if (isApp) {
url = '?openby:yohobuy={"action":"go.brand","params":{"brand_id":"' + brandId + '","is_different":"' + isDifferent + '"}}'; // eslint-disable-line
uid = parseInt(uid, 10);
} else {
url = '//' + brandDomain + '.m.yohobuy.com';
}
if (isApp && !uid) {
jumpToApp = 1;
}
if (isApp && !uid) {
jumpToApp = 1;
}
list.brand_ico = imageProcess.getSourceUrl(list.brand_ico, 'brandLogo');
list.brand_ico = imageProcess.getSourceUrl(list.brand_ico, 'brandLogo');
return getNewProduct(brandId, gender, url, isApp).then((data) => {
return this.getNewProduct(brandId, gender, url, isApp).then((data) => {
return _.assign(list, {
isLike: false,
newArrival: data,
jumpToApp: jumpToApp,
shareLink: '//guang.m.yohobuy.com/plustar/brandinfo?id=' + id,
shareTitle: list.brand_name,
shareImg: list.brand_ico,
shareDesc: htmlProcess.removeHtml(list.brand_intro)
return _.assign(list, {
isLike: false,
newArrival: data,
jumpToApp: jumpToApp,
shareLink: '//guang.m.yohobuy.com/plustar/brandinfo?id=' + id,
shareTitle: list.brand_name,
shareImg: list.brand_ico,
shareDesc: htmlProcess.removeHtml(list.brand_intro)
});
});
});
} else {
logger.error('detail data return code is not 200');
return {};
}
});
};
/**
* [品牌详情异步数据]
*/
const getDetailDataAsync = (brandId, uid, udid, isApp) => {
return Promise.all([
isCollection(brandId, uid),
getRelatedEditorial(brandId, uid, udid, isApp)
]).then((result) => {
return {
isLike: result[0],
infos: result[1]
};
});
};
} else {
logger.error('detail data return code is not 200');
return {};
}
});
}
module.exports = {
getListData,
getContentData,
getDetailData,
getDetailDataAsync,
getBrandsData
/**
* [品牌详情异步数据]
*/
getDetailDataAsync(brandId, uid, udid, isApp) {
return Promise.all([
this.isCollection(brandId, uid),
this.getRelatedEditorial(brandId, uid, udid, isApp)
]).then((result) => {
return {
isLike: result[0],
infos: result[1]
};
});
}
};
... ...