|
|
/*
|
|
|
* 新品节活动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; |
...
|
...
|
|