Authored by 郝肖肖

'product-ctx'

'use strict';
const serviceApi = global.yoho.ServiceAPI;
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
const Promise = require('bluebird');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');
const productProcess = require(`${global.utils}/product-process`);
const stdntMrktModel = require('../models/student-market');
const userAcquireStatus = (uid, couponIds) => {
if (couponIds !== '') {
return api.get('', {
method: 'app.coupons.userAcquireStatus',
uid: uid,
couponIds: couponIds
});
}
};
/**
* 查询商品
* @param id
* @returns {*}
*/
const _getRelatedData = (idList) => {
if (idList !== '') {
return api.get('', {
productSkn: idList,
method: 'h5.product.batch'
}).then((result) => {
let goods = [];
if (result && result.data && result.data.product_list && result.code === 200) {
_.forEach(result.data.product_list, function(val) {
if (!val.student_price) {
val.student_price = val.vip2_price;
}
});
goods = productProcess.processProductList(result.data.product_list);
return goods;
} else {
return {};
}
});
}
};
exports.index = (req, res, next) => {
let code = 'c9b9639ce2884b768cfbc5cf9e68a53f';
let uid = req.__USER__.uid;
... ... @@ -60,10 +14,7 @@ exports.index = (req, res, next) => {
'?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' +
req.__USER__.http + '//m.yohobuy.com/activity/student-market"}}}';
return serviceApi.get('operations/api/v5/resource/get', {
content_code: code,
platform: 'iphone'
}).then((result) => {
return req.ctx(stdntMrktModel).index(code).then(result => {
let coupons = {},
activities,
... ... @@ -132,8 +83,8 @@ exports.index = (req, res, next) => {
}
return Promise.all([
userAcquireStatus(uid, couponids.join(',')),
_getRelatedData(idList.join(','))])
req.ctx(stdntMrktModel).userAcquireStatus(uid, couponids.join(',')),
req.ctx(stdntMrktModel)._getRelatedData(idList.join(','))])
.then(datas => {
coupons.data = _.get(coupons, 'data', []).map((item)=>{
item.status = 1;
... ... @@ -195,7 +146,7 @@ exports.index = (req, res, next) => {
* 新版学生营销页面
*/
exports.newIndex = (req, res, next) => {
stdntMrktModel.getStudentGoods({
req.ctx(stdntMrktModel).getStudentGoods({
limit: req.query.limit || '60',
stocknumber: req.query.stocknumber || '1'
}).then(result => {
... ...
... ... @@ -59,9 +59,8 @@ exports.index = (req, res, next) => {
}
vipDayModel.getGoods(cate)
req.ctx(vipDayModel).getGoods(cate)
.then(result => {
// console.log(result.data)
if (result.code !== 200) {
return Promise.reject('error');
}
... ... @@ -86,7 +85,7 @@ exports.crazyWheel = (req, res, next) => {
return res.redirect('/activity/vip-day');
}
vipDayModel.getJoinNum(1).then(result => {
req.ctx(vipDayModel).getJoinNum(1).then(result => {
let joins = result && result.data || 0;
res.render('vip-day/crazy-wheel', {
... ... @@ -107,8 +106,8 @@ exports.crazyLuck = (req, res, next) => {
res.locals.width750 = true;
co(function* () {
let coins = yield vipDayModel.getCoins(uid);
let joinNum = yield vipDayModel.getJoinNum(2);
let coins = yield req.ctx(vipDayModel).getCoins(uid);
let joinNum = yield req.ctx(vipDayModel).getJoinNum(2);
coins = (coins && coins.data && coins.data.total) || 0;
joinNum = (joinNum && joinNum.data) || 0;
... ... @@ -130,7 +129,7 @@ exports.crazyLuck = (req, res, next) => {
exports.signin = (req, res, next) => {
let uid = req.user.uid;
return vipDayModel.signin(uid)
return req.ctx(vipDayModel).signin(uid)
.then(function(result) {
res.json(result);
})
... ... @@ -148,7 +147,7 @@ exports.saveMsg = (req, res, next) => {
})
.then(nick_name => {
// 2. save message
return vipDayModel.saveMsg(uid, nick_name, content);
return req.ctx(vipDayModel).saveMsg(uid, nick_name, content);
})
.then(result => {
if (result.code === 200 && result.data === 1) {
... ... @@ -164,7 +163,7 @@ exports.saveMsg = (req, res, next) => {
exports.fetchMsg = (req, res, next) => {
let uid = req.user.uid || req.query.uid || 0;
vipDayModel.queryLeaveWordsList(uid).then(result => {
req.ctx(vipDayModel).queryLeaveWordsList(uid).then(result => {
return res.json(result);
}).catch(next);
};
... ... @@ -174,7 +173,7 @@ exports.wheelResult = (req, res, next) => {
let uid = req.user.uid;
let prize_type = 2;
return vipDayModel.addPrizeLog(uid, prize_type).then(result => {
return req.ctx(vipDayModel).addPrizeLog(uid, prize_type).then(result => {
return res.json(result);
}).catch(next);
... ... @@ -188,7 +187,7 @@ exports.luckResult = (req, res, next) => {
let handle = co(function* (uid) {
// 查询用户 有货币
let r1 = yield vipDayModel.getCoins(uid);
let r1 = yield req.ctx(vipDayModel).getCoins(uid);
if (r1.code !== 200) {
return {
... ... @@ -205,7 +204,7 @@ exports.luckResult = (req, res, next) => {
}
// 得出 中奖结果
let result = yield vipDayModel.addPrizeLog(uid, prize_type);
let result = yield req.ctx(vipDayModel).addPrizeLog(uid, prize_type);
if (result.code !== 200) {
return result;
... ... @@ -224,7 +223,7 @@ exports.luckResultCollect = (req, res, next) => {
let uid = req.user.uid;
let prize_type = 1;
return vipDayModel.queryPrizeLog(uid, prize_type).then(result => {
return req.ctx(vipDayModel).queryPrizeLog(uid, prize_type).then(result => {
if (result.code === 200 && result.data) {
result.data = result.data.filter(award => award.prizeValue);
}
... ...
... ... @@ -19,7 +19,7 @@ function humanNum_wan(num) {
exports.checkIsStudent = (req, res, next) => {
let uid = req.user.uid || req.query.uid;
vipDayModel.checkIsStudent(uid).then(result => {
req.ctx(vipDayModel).checkIsStudent(uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -73,13 +73,13 @@ exports.index = (req, res, next) => {
// 获取学生信息
if (uid) {
let result = yield vipDayModel.checkIsStudent(uid);
let result = yield req.ctx(vipDayModel).checkIsStudent(uid);
result.data && Number(result.data.isStudent) === 1 && (isStudent = true);
}
// 获取商品信息
let goodList = yield vipDayModel.getGoods(cate);
let goodList = yield req.ctx(vipDayModel).getGoods(cate);
res.render('vip-day/vip-day1028/index', {
title: '会员日活动',
... ... @@ -101,7 +101,7 @@ exports.crazyWheel = (req, res, next) => {
res.locals.page = 'vipday-wheel10';
res.locals.width750 = true;
vipDayModel.getJoinNum(1).then(result => {
req.ctx(vipDayModel).getJoinNum(1).then(result => {
let joins = result && result.data || 0;
res.render('vip-day/vip-day1028/crazy-wheel', {
... ... @@ -122,8 +122,8 @@ exports.crazyLuck = (req, res, next) => {
res.locals.width750 = true;
co(function*() {
let coins = yield vipDayModel.getCoins(uid);
let joinNum = yield vipDayModel.getJoinNum(2);
let coins = yield req.ctx(vipDayModel).getCoins(uid);
let joinNum = yield req.ctx(vipDayModel).getJoinNum(2);
coins = (coins && coins.data && coins.data.total) || 0;
joinNum = (joinNum && joinNum.data) || 0;
... ... @@ -145,7 +145,7 @@ exports.crazyLuck = (req, res, next) => {
exports.signin = (req, res, next) => {
let uid = req.user.uid;
return vipDayModel.signin(uid)
return req.ctx(vipDayModel).signin(uid)
.then(function(result) {
res.json(result);
})
... ... @@ -156,7 +156,7 @@ exports.wheelResult = (req, res, next) => {
let uid = req.user.uid || req.query.uid;
let prize_type = 3;
return vipDayModel.addPrizeLog(uid, prize_type).then(result => {
return req.ctx(vipDayModel).addPrizeLog(uid, prize_type).then(result => {
return res.json(result);
}).catch(next);
... ... @@ -170,7 +170,7 @@ exports.luckResult = (req, res, next) => {
let handle = co(function*(uid) {
// 查询用户 有货币
let r1 = yield vipDayModel.getCoins(uid);
let r1 = yield req.ctx(vipDayModel).getCoins(uid);
if (r1.code !== 200) {
return {
... ... @@ -187,7 +187,7 @@ exports.luckResult = (req, res, next) => {
}
// 得出 中奖结果
let result = yield vipDayModel.addPrizeLog(uid, prize_type);
let result = yield req.ctx(vipDayModel).addPrizeLog(uid, prize_type);
if (result.code !== 200) {
return result;
... ... @@ -206,7 +206,7 @@ exports.luckResultCollect = (req, res, next) => {
let uid = req.user.uid;
let prize_type = 3;
return vipDayModel.queryPrizeLog(uid, prize_type).then(result => {
return req.ctx(vipDayModel).queryPrizeLog(uid, prize_type).then(result => {
if (result.code === 200 && result.data) {
result.data = result.data.filter(award => award.prizeValue);
}
... ...
... ... @@ -2,70 +2,73 @@
const _ = require('lodash');
const helpers = global.yoho.helpers;
const _getProductBySkns = function(productObj, extraParams) {
return this.get({
data: {
productSkn: productObj.defaultSkns,
method: 'h5.product.batch'
},
param: {
cache: true
}
}).then((result) => {
productObj.defaultPros = [];
if (result && result.data && result.data.product_list && result.code === 200) {
result.data.product_list.forEach(function(val) {
var obj = {
producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${extraParams.from_page_name}","from_page_param":"${extraParams.from_page_param}"}}`, // eslint-disable-line
productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'),
productname: val.product_name,
vipprice: val.vip_price,
saleprice: val.sales_price,
marketprice: val.sales_price === val.market_price ? '' : val.market_price,
brandname: val.brand_name,
product_skn: val.product_skn
};
if (val.shop_id) {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type || "1"},"is_red_shop":${val.is_red_shop || 1}}}`; // eslint-disable-line
} else {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line
}
productObj.defaultPros.push(obj);
});
}
});
};
/**
* 获取店铺组店铺数据
*/
const _getShopGroup = (shopRawData) => {
return this.get({
data: {
method: 'app.shops.batchGetShops',
shop_ids: shopRawData.defaultShopIds
}
}).then(result => {
let renderData = _.get(result, 'data', []);
class featureModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_.forEach(renderData, shop => {
let displayStyle = _.get(shopRawData, 'displayStyle', '0');
_getProductBySkns(productObj, extraParams) {
return this.get({
data: {
productSkn: productObj.defaultSkns,
method: 'h5.product.batch'
},
param: {
cache: true
}
}).then((result) => {
productObj.defaultPros = [];
if (result && result.data && result.data.product_list && result.code === 200) {
result.data.product_list.forEach(function(val) {
var obj = {
producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${extraParams.from_page_name}","from_page_param":"${extraParams.from_page_param}"}}`, // eslint-disable-line
productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'), // eslint-disable-line
productname: val.product_name,
vipprice: val.vip_price,
saleprice: val.sales_price,
marketprice: val.sales_price === val.market_price ? '' : val.market_price,
brandname: val.brand_name,
product_skn: val.product_skn
};
if (val.shop_id) {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${val.shop_id},"shop_template_type":${val.shop_template_type || "1"},"is_red_shop":${val.is_red_shop || 1}}}`; // eslint-disable-line
} else {
obj.brandurl = `//m.yohobuy.com/product/shop?domain=${val.brand_domain}&openby:yohobuy={"action":"go.brand","params":{"brand_id":${val.brand_id}}}`; // eslint-disable-line
}
shop.picture = displayStyle === '0' ? shop.pic_popular : shop.shop_logo;
shop.href = `//m.yohobuy.com/product/shop?domain=${shop.shop_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${shop.shops_id},"shop_template_type":${shop.shop_template_type || "1"},"is_red_shop":${shop.is_red_shop || 1}}}`; // eslint-disable-line
productObj.defaultPros.push(obj);
});
}
});
}
shopRawData.renderData = renderData;
});
};
/**
* 获取店铺组店铺数据
*/
_getShopGroup(shopRawData) {
return this.get({
data: {
method: 'app.shops.batchGetShops',
shop_ids: shopRawData.defaultShopIds
}
}).then(result => {
let renderData = _.get(result, 'data', []);
class featureModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
_.forEach(renderData, shop => {
let displayStyle = _.get(shopRawData, 'displayStyle', '0');
shop.picture = displayStyle === '0' ? shop.pic_popular : shop.shop_logo;
shop.href = `//m.yohobuy.com/product/shop?domain=${shop.shop_domain}&openby:yohobuy={"action":"go.shop","params":{"shop_id":${shop.shops_id},"shop_template_type":${shop.shop_template_type || "1"},"is_red_shop":${shop.is_red_shop || 1}}}`; // eslint-disable-line
});
shopRawData.renderData = renderData;
});
}
index(params) {
let that = this;
return Promise.coroutine(function*() {
if (!params.code) {
return Promise.resolve({});
... ... @@ -76,7 +79,7 @@ class featureModel extends global.yoho.BaseModel {
let shopGroups = [];
if (params.type === 'preview') { // 开发/预览模式
data = yield this.get({
data = yield that.get({
data: {
method: 'app.activity.template.ignoreCache',
activity_id: params.code
... ... @@ -87,7 +90,7 @@ class featureModel extends global.yoho.BaseModel {
});
} else {
// 生产模式
data = yield this.get({
data = yield that.get({
data: {
method: 'app.activity.template',
activity_id: params.code
... ... @@ -105,7 +108,7 @@ class featureModel extends global.yoho.BaseModel {
data.floors.forEach(function(f) {
if (f.component && f.component[0] &&
f.component[0].type === 'productGroup' && f.component[0].defaultSkns) {
sknsArr.push(_getProductBySkns(f.component[0], {
sknsArr.push(that._getProductBySkns(f.component[0], {
from_page_name: params.from_page_name,
from_page_param: params.from_page_param
}));
... ... @@ -125,7 +128,7 @@ class featureModel extends global.yoho.BaseModel {
// 新增店铺组
if (_.get(f, 'component[0].type') === 'shopGroup') {
shopGroups.push(_getShopGroup(f.component[0]));
shopGroups.push(that._getShopGroup(f.component[0]));
}
if (_.get(f, 'type') === 'bottombar') {
... ...
... ... @@ -10,19 +10,72 @@
const utils = '../../../utils';
const productProcess = require(`${utils}/product-process`);
const api = global.yoho.API;
const _ = require('lodash');
const serviceAPI = global.yoho.ServiceAPI;
const getStudentGoods = (params) => {
return api.get('', {
method: 'app.student.aggBrand',
limit: params.limit,
stocknumber: params.stocknumber,
}).then(result => {
return productProcess.processProductList(_.get(result, 'data.product_list', []));
});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
index(code) {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: code,
platform: 'iphone'
}
});
}
getStudentGoods(params) {
return this.get({
data: {
method: 'app.student.aggBrand',
limit: params.limit,
stocknumber: params.stocknumber,
}
}).then(result => {
return productProcess.processProductList(_.get(result, 'data.product_list', []));
});
}
userAcquireStatus(uid, couponIds) {
return this.get({
data: {
method: 'app.coupons.userAcquireStatus',
uid: uid,
couponIds: couponIds
}
});
}
/**
* 查询商品
* @param id
* @returns {*}
*/
_getRelatedData(idList) {
return this.get({
data: {
productSkn: idList,
method: 'h5.product.batch'
}
}).then(result => {
if (result && result.data && result.data.product_list && result.code === 200) {
_.forEach(result.data.product_list, function(val) {
if (!val.student_price) {
val.student_price = val.vip2_price;
}
});
module.exports = {
getStudentGoods
return productProcess.processProductList(result.data.product_list);
} else {
return {};
}
});
}
};
... ...
... ... @@ -2,125 +2,154 @@
'use strict';
const url = require('url');
const _ = require('lodash');
const API = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const utils = require(global.utils + '/product-process');
const helpers = global.yoho.helpers;
// 签到
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md
exports.signin = (uid)=> {
return serviceAPI.post('/activity/UserdaySigninController/signin', {uid});
};
// 写留言
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BF%9D%E5%AD%98%E7%94%A8%E6%88%B7%E7%95%99%E8%A8%80.md
exports.saveMsg = (uid, nick_name, content) => {
return serviceAPI.post('/activity/UserdayLeaveWordsController/addLeaveWords', {
uid,
nick_name,
content
});
};
exports.queryLeaveWordsList = (uid) => {
return serviceAPI.get('/activity/UserdayLeaveWordsController/queryLeaveWordsList', {uid});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 签到
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md
signin(uid) {
return this.get({
api: serviceAPI,
url: '/activity/UserdaySigninController/signin',
data: {uid}
});
}
// 写留言
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BF%9D%E5%AD%98%E7%94%A8%E6%88%B7%E7%95%99%E8%A8%80.md
saveMsg(uid, nick_name, content) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayLeaveWordsController/addLeaveWords',
data: {
uid,
nick_name,
content
}
});
}
queryLeaveWordsList(uid) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayLeaveWordsController/queryLeaveWordsList',
data: {
uid
}
});
}
// 拼手气大转盘 抽奖
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md
addPrizeLog(uid, prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/addPrizeLog',
data: {
uid,
prize_type
}
});
}
// 查询 中奖纪录
queryPrizeLog(uid, prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/queryPrizeLog',
data: {
uid,
prize_type
}
});
}
// 拼手气大转盘 抽奖
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md
exports.addPrizeLog = (uid, prize_type) => {
// 获取用户的有货币
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81
getCoins(uid) {
return this.get({
data: {
method: 'app.yohocoin.total',
uid
}
});
}
// 获取抽奖人数
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md
getJoinNum(prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/queryPrizeLogNum',
data: {
prize_type
}
});
}
return serviceAPI.post('/activity/UserdayPrizeLogController/addPrizeLog', {
uid,
prize_type
});
};
/**
* cate [object Object]
*/
getGoods(cate) {
let skns = '';
let cates = Object.keys(cate);
// 查询 中奖纪录
exports.queryPrizeLog = (uid, prize_type) => {
_.forEach(cate, function(val) {
skns = skns.concat(',').concat(val.join(','));
});
return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLog', {
uid,
prize_type
});
};
skns = skns.slice(1);
return this.get({
data: {
method: 'h5.product.batch',
productSkn: skns
}
}).then(result => {
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
}
let productList = utils.processProductList(result.data.product_list);
let data = {};
// 获取用户的有货币
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81
exports.getCoins = uid => {
return API.get('', {
method: 'app.yohocoin.total',
uid
});
};
productList.forEach(product=> {
let skn = product.productSkn;
let imgSrc = url.parse(product.defaultImages || '');
// 获取抽奖人数
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md
exports.getJoinNum = prize_type => {
product.defaultImages = ['//', imgSrc.hostname, imgSrc.pathname].join('');
return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLogNum', {
prize_type,
});
};
product.url = helpers.appUrlFormat(product.url, 'go.productDetail', {
product_skn: skn
});
/**
* cate [object Object]
*/
exports.getGoods = cate => {
let skns = '';
let cates = Object.keys(cate);
for (let c of cates) {
let index = cate[c].indexOf(skn);
_.forEach(cate, function(val) {
skns = skns.concat(',').concat(val.join(','));
});
if (index !== -1) {
cate[c].splice(index, 1);
skns = skns.slice(1);
data[c] || (data[c] = []);
data[c].push(product);
break;
}
}
});
return API.get('', {
method: 'h5.product.batch',
productSkn: skns
}).then(result => {
if (result.code !== 200) {
return {
code: result.code,
message: result.message
code: 200,
data
};
}
let productList = utils.processProductList(result.data.product_list);
let data = {};
productList.forEach(product=> {
let skn = product.productSkn;
let imgSrc = url.parse(product.defaultImages || '');
product.defaultImages = ['//', imgSrc.hostname, imgSrc.pathname].join('');
product.url = helpers.appUrlFormat(product.url, 'go.productDetail', {
product_skn: skn
});
for (let c of cates) {
let index = cate[c].indexOf(skn);
if (index !== -1) {
cate[c].splice(index, 1);
data[c] || (data[c] = []);
data[c].push(product);
break;
}
}
});
return {
code: 200,
data
};
});
}
};
... ...
... ... @@ -2,122 +2,152 @@
'use strict';
const url = require('url');
const _ = require('lodash');
const API = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const utils = require(global.utils + '/product-process');
const helpers = global.yoho.helpers;
// 签到
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md
exports.signin = (uid)=> {
return serviceAPI.post('/activity/UserdaySigninController/signin', {uid});
};
exports.queryLeaveWordsList = (uid) => {
return serviceAPI.get('/activity/UserdayLeaveWordsController/queryLeaveWordsList', {uid});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
// 签到
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E4%BC%9A%E5%91%98%E6%97%A5%E7%AD%BE%E5%88%B0.md
signin(uid) {
return this.get({
api: serviceAPI,
url: '/activity/UserdaySigninController/signin',
data: {
uid: uid
}
});
}
queryLeaveWordsList(uid) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayLeaveWordsController/queryLeaveWordsList',
data: {
uid: uid
}
});
}
// 拼手气大转盘 抽奖
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md
addPrizeLog(uid, prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/addPrizeLog',
data: {
uid,
prize_type
}
});
}
// 查询 中奖纪录
queryPrizeLog(uid, prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/queryPrizeLog',
data: {
uid,
prize_type
}
});
}
// 拼手气大转盘 抽奖
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%8B%BC%E6%89%8B%E6%B0%94%E5%A4%A7%E8%BD%AC%E7%9B%98%E6%8A%BD%E5%A5%96.md
exports.addPrizeLog = (uid, prize_type) => {
// 获取用户的有货币
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81
getCoins(uid) {
return this.get({
data: {
method: 'app.yohocoin.total',
uid
}
});
}
// 获取抽奖人数
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md
getJoinNum(prize_type) {
return this.get({
api: serviceAPI,
url: '/activity/UserdayPrizeLogController/queryPrizeLogNum',
data: {
prize_type
}
});
}
return serviceAPI.post('/activity/UserdayPrizeLogController/addPrizeLog', {
uid,
prize_type
});
};
/**
* cate [object Object]
*/
getGoods(cate) {
let skns = '';
let cates = Object.keys(cate);
// 查询 中奖纪录
exports.queryPrizeLog = (uid, prize_type) => {
_.forEach(cate, function(val) {
skns = skns.concat(',').concat(val.join(','));
});
return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLog', {
uid,
prize_type
});
};
skns = skns.slice(1);
return this.get({
data: {
method: 'h5.product.batch',
productSkn: skns
}
}).then(result => {
if (result.code !== 200) {
return {
code: result.code,
message: result.message
};
}
let productList = utils.processProductList(result.data.product_list);
let data = {};
// 获取用户的有货币
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/tree/master/%E6%9C%89%E8%B4%A7%E5%B8%81
exports.getCoins = uid => {
return API.get('', {
method: 'app.yohocoin.total',
uid
});
};
productList.forEach(product=> {
let skn = product.product_skn;
let imgSrc = url.parse(product.default_images || '');
// 获取抽奖人数
// doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E4%BC%9A%E5%91%98%E6%97%A5%E6%B4%BB%E5%8A%A8/%E6%9F%A5%E8%AF%A2%E5%8F%82%E4%B8%8E%E6%8A%BD%E5%A5%96%E4%BA%BA%E6%95%B0.md
exports.getJoinNum = prize_type => {
product.default_images = ['//', imgSrc.hostname, imgSrc.pathname].join('');
return serviceAPI.get('/activity/UserdayPrizeLogController/queryPrizeLogNum', {
prize_type,
});
};
product.url = helpers.appUrlFormat(product.url, 'go.productDetail', {
product_skn: skn
});
/**
* cate [object Object]
*/
exports.getGoods = cate => {
let skns = '';
let cates = Object.keys(cate);
for (let c of cates) {
let index = cate[c].indexOf(skn);
_.forEach(cate, function(val) {
skns = skns.concat(',').concat(val.join(','));
});
if (index !== -1) {
cate[c].splice(index, 1);
skns = skns.slice(1);
data[c] || (data[c] = []);
data[c].push(product);
break;
}
}
});
return API.get('', {
method: 'h5.product.batch',
productSkn: skns
}).then(result => {
if (result.code !== 200) {
return {
code: result.code,
message: result.message
code: 200,
data
};
}
let productList = utils.processProductList(result.data.product_list);
let data = {};
productList.forEach(product=> {
let skn = product.product_skn;
let imgSrc = url.parse(product.default_images || '');
product.default_images = ['//', imgSrc.hostname, imgSrc.pathname].join('');
product.url = helpers.appUrlFormat(product.url, 'go.productDetail', {
product_skn: skn
});
for (let c of cates) {
let index = cate[c].indexOf(skn);
if (index !== -1) {
cate[c].splice(index, 1);
data[c] || (data[c] = []);
data[c].push(product);
break;
}
});
}
// 判断是否学生
checkIsStudent(uid) {
return this.get({
data: {
method: 'app.student.checkIsStudent',
uid: uid,
}
});
return {
code: 200,
data
};
});
};
// 判断是否学生
exports.checkIsStudent = uid => {
return API.get('', {
method: 'app.student.checkIsStudent',
uid: uid,
});
}
};
... ...
/**
* 新品到着 models
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/7/28
*/
'use strict';
const utils = '../../../utils';
const logger = global.yoho.logger;
const _ = require('lodash');
const contentCode = require('../../../config/content-code');
const resourcesProcess = require(`${utils}/resources-process`);
const searchProcess = require(`${utils}/search-process`);
const productProcess = require(`${utils}/product-process`);
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* TODO: remove
* 商品搜索接口请求
* @param {[object]} params
* @return {[array]}
*/
_searchGoods(params) {
let method = 'app.search.newProduct';
// 排除基本筛选项默认值为0的对象
for (let str in params) {
if (str !== 'order' && params[str] === '0' || params[str] === null) {
delete params[str];
}
}
params.yh_channel = searchProcess.getChannelType(params.channel);
delete params.channel;
params = _.assign({
limit: '60'
}, params);
params.order = params.order === '0' ? 's_t_desc' : 's_t_asc';
return api.get('', _.assign({
method: method
}, params), {
cache: true
});
}
/**
* 获取新品到着的焦点图资源数据
*/
getNewFocus(channel) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode.new[channel]
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return resourcesProcess(result.data);
} else {
logger.error('get newGoods banner return code is not 200');
return [];
}
});
}
/**
* TODO remove
* 获取商品数据
*/
getSearchData(params) {
return this._searchGoods(params).then((result) => {
if (result && result.code === 200) {
let newList = {};
newList.list = productProcess.processProductList(result.data.product_list || [], {
showTags: true,
showSimilar: true
});
if (parseInt(params.page, 10) === 1) {
newList.total = result.data.total;
}
return newList;
} else {
logger.error('get product search api return code is not 200');
return [];
}
});
}
/**
* TODO remove
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
getFilterData(params) {
return this._searchGoods(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || []);
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
}
/**
* method=app.newproduct.recshop 推荐店铺
* http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md
*/
indexData(uid, channel, limit, page) {
let yh_channel = searchProcess.getChannelType(channel);
limit = limit || 20;
page = page || 1;
let params = {
method: 'app.newproduct.recshop',
yh_channel,
contentCode: contentCode.newV2[channel],
limit,
page,
uid
};
return api.get('', params, {cache: true})
.then(result=> {
let shopData = _.get(result, 'data', {});
return shopData;
})
.catch(() => {});
}
/**
* method=app.newproduct.recbrand 推荐品牌
* http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md
*/
recbrand(uid, channel, limit, page) {
let yh_channel = searchProcess.getChannelType(channel);
limit = limit || 20;
page = page || 1;
let params = {
method: 'app.newproduct.recbrand',
yh_channel,
limit,
page,
uid
};
return api.get('', params, {cache: true})
.then(result => {
let data = _.get(result, 'data', {});
return data;
})
.catch(() => {});
}
newGoodsAPI(params) {
let method = 'app.newproduct.reclist';
// 排除基本筛选项默认值为0的对象
for (let str in params) {
if ((str !== 'order' && params[str] === '0') || params[str] === null) {
delete params[str];
}
}
params.yh_channel = searchProcess.getChannelType(params.channel);
delete params.channel;
params = _.assign({
limit: '60'
}, params);
return api.get('', _.assign({
method: method
}, params), {
cache: true
});
}
/**
* method:app.newproduct.reclist 新品上架
* http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/BigData/新品到着.md
*/
reclist(uid, channel, searchOptions) {
let params = Object.assign({}, {uid, channel}, searchOptions);
return this.newGoodsAPI(params).then(result => {
if (result && result.code === 200) {
let newList = {
channel: channel
};
newList.list = productProcess.processProductList(result.data.product_list || [], {showTags: true});
if (parseInt(params.page, 10) === 1) {
newList.total = result.data.total;
newList.pageTotal = result.data.page_total;
}
return newList;
} else {
logger.error('get product search api return code is not 200');
return [];
}
});
}
reclistFilter(uid, channel) {
let params = Object.assign({}, {uid, channel});
return this.newGoodsAPI(params).then(result => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || []);
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
}
filterDataApi(params) {
return this._searchGoods(params);
}
};