Authored by shuaiguo

Merge branch 'feature/new-pro-fes' into 'master'

Feature/new pro fes

新品节

See merge request !105
/*
* 新品节活动API controller
* 2019.08.27
*/
const INVALID_PARAMS = '参数错误';
const NewProFesModel = require('../models/new-pro-fes');
const NewProFesController = {
/**
* 获取购买者列表
* @param req
* @param res
* @param next
* @returns {*}
*/
getBuyerList(req, res, next) {
let { activityId } = req.query;
if (!activityId) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
return req.ctx(NewProFesModel).getBuyerList(activityId).then(result => {
return res.json(result);
}).catch(next);
},
/**
* 获取活动信息
* @param req
* @param res
* @param next
* @returns {*}
*/
getActivityInfo(req, res, next) {
let { activityId } = req.query;
if (!activityId) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
return req.ctx(NewProFesModel).getActivityInfo(activityId).then(result => {
return res.json(result);
}).catch(next);
},
/**
* 点赞
* @param req
* @param res
* @param next
* @returns {*}
*/
sendStar(req, res, next) {
let { uid, session_key, app_version, client_type, activityId } = req.body;
if (!uid || !activityId || !session_key || !app_version || !client_type) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
let data = {
uid: uid,
sessionKey: session_key,
appVersion: client_type === 'miniapp' ? global.yoho.appVersion : app_version,
appSessionType: client_type,
activityId
};
return req.ctx(NewProFesModel).sendStar(data).then(result => {
return res.json(result);
}).catch(next);
},
/**
* 获取商品池信息
* @param req
* @param res
* @param next
* @returns {*}
*/
getProductPool(req, res, next) {
let { productPool, order = 'pools_sort_desc' } = req.query;
if (!productPool) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
return req.ctx(NewProFesModel).getProductPool(productPool, order).then(result => {
return res.json(result);
}).catch(next);
},
/**
* 通过SKN获取商品信息
* @param req
* @param res
* @param next
*/
getProductBySkn(req, res, next) {
let { productSkn } = req.query;
if (!productSkn) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
let skns = productSkn.split(',');
return req.ctx(NewProFesModel).getProductBySkn(skns.join(',')).then(result => {
return res.json(result);
}).catch(next);
},
sendCoupon(req, res, next) {
let { uid, app, token } = req.body;
if (!uid || !token || !app) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
try {
app = JSON.parse(app);
} catch (e) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
let data = {
uid: uid,
sessionKey: app.session_key,
appVersion: app.client_type === 'miniapp' ? global.yoho.appVersion : app.app_version,
appSessionType: app.client_type,
token
};
return req.ctx(NewProFesModel).sendCoupon(data).then(result => {
res.json(result);
}).catch(next);
}
};
module.exports = NewProFesController;
... ...
/**
* 新品节活动API MODEL
* 2019-08-27
*/
class newProFesModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取购买者列表
*/
getBuyerList(activityId) {
return this.get({
url: '',
data: {
method: 'app.newArrActivity.userList',
activityId: activityId
}
});
}
/**
* 获取新品节活动信息
* @param activityId
*/
getActivityInfo(activityId) {
return this.get({
url: '',
data: {
method: 'app.newArrActivity.info',
activityId: activityId
}
});
}
/**
* 点赞
* @param data
*/
sendStar(data) {
let uid = {
toString: () => {
return parseInt(data.uid, 10);
},
sessionKey: data.sessionKey,
appVersion: data.appVersion,
appSessionType: data.appSessionType
};
delete data.sessionKey;
delete data.appVersion;
delete data.appSessionType;
return this.get({
url: '',
data: {
method: 'app.newArrActivity.star',
uid: uid,
activityId: data.activityId
}
});
}
/**
* 获取商品池列表
* @param productPool
* @returns {*}
*/
getProductPool(productPool, order) {
return this.get({
url: '',
data: {
method: 'app.search.pool.productList',
productPool: productPool,
order: order
}
});
}
/**
* 通过商品skn取商品列表
* @param skns
* @returns {*}
*/
getProductBySkn(skns) {
return this.get({
url: '',
data: {
method: 'h5.product.batch',
productSkn: skns
}
});
}
/**
* 领券
*/
sendCoupon(obj) {
let uid = {
toString: () => {
return parseInt(obj.uid, 10);
},
sessionKey: obj.sessionKey,
appVersion: obj.appVersion,
appSessionType: obj.appSessionType
};
delete obj.sessionKey;
delete obj.appVersion;
delete obj.appSessionType;
return this.get({
data: {
method: 'app.coupons.couponSend',
uid: uid,
coupon_send_token: obj.token
}
});
}
}
module.exports = newProFesModel;
... ...
... ... @@ -22,6 +22,7 @@ const mutilpartMiddleware = multipart();
const yohoActivitys = require('./controllers/yoho-activitys');
const dailyCheckIn = require('./controllers/daily-check-in');
const share = require('./controllers/share');
const NewProFesController = require('./controllers/new-pro-fes');
router.get('/gettoken', qiniu.getToken);
router.get('/share/getSignPackage', wechat.getSignPackage);
... ... @@ -108,4 +109,12 @@ router.get('/activity/checkIn/getUserInfo', dailyCheckIn.getUserInfo); // 获
router.get('/share/collect', share.collect); // 分享
router.get('/share/preshare', share.preshare); // 分享
router.get('/newProFes/getBuyerList', NewProFesController.getBuyerList); // 获取新品节购买用户列表
router.get('/newProFes/getActivityInfo', NewProFesController.getActivityInfo); // 获取新品节活动信息
router.post('/newProFes/sendStar', NewProFesController.sendStar); // 点赞
router.get('/newProFes/getProductPool', NewProFesController.getProductPool); // 获取商品池列表
router.get('/newProFes/getProductBySkn', NewProFesController.getProductBySkn); // 获取商品列表
router.post('/newProFes/sendCoupon', NewProFesController.sendCoupon); // 领券
module.exports = router;
... ...
... ... @@ -183,7 +183,7 @@ const userController = {
// console.log('WECHAT_LOGIN_URL:', WECHAT_LOGIN_URL);
// console.log('referer', referer, referer.indexOf('yoho.cn'));
if (referer && (referer.indexOf('yoho.cn') >= 0)) {
if (referer && (referer.indexOf('yoho.cn') >= 0 || referer.indexOf('yohobuy.com') >= 0)) {
_.set(req.session, 'user.wechatReferer', referer);
_.set(req.session, 'user.wechatState', state);
... ...
... ... @@ -13,7 +13,7 @@ const isTest = process.env.NODE_ENV === 'test3';
module.exports = {
app: 'h5',
appName: 'yoho-activity-platform',
appVersion: '6.6.0', // 调用api的版本
appVersion: '6.8.9', // 调用api的版本
port: 6006,
siteUrl: '//action.yoho.cn',
assetUrl: `/yoho-activity-platform/${pkg.version}/`,
... ...