Authored by shuaiguo

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

Feature/new pro fes

新品节

See merge request !105
  1 +/*
  2 +* 新品节活动API controller
  3 +* 2019.08.27
  4 +*/
  5 +
  6 +const INVALID_PARAMS = '参数错误';
  7 +const NewProFesModel = require('../models/new-pro-fes');
  8 +
  9 +const NewProFesController = {
  10 + /**
  11 + * 获取购买者列表
  12 + * @param req
  13 + * @param res
  14 + * @param next
  15 + * @returns {*}
  16 + */
  17 + getBuyerList(req, res, next) {
  18 + let { activityId } = req.query;
  19 +
  20 + if (!activityId) {
  21 + return res.json({
  22 + code: 400,
  23 + message: INVALID_PARAMS
  24 + });
  25 + }
  26 +
  27 + return req.ctx(NewProFesModel).getBuyerList(activityId).then(result => {
  28 + return res.json(result);
  29 + }).catch(next);
  30 + },
  31 +
  32 + /**
  33 + * 获取活动信息
  34 + * @param req
  35 + * @param res
  36 + * @param next
  37 + * @returns {*}
  38 + */
  39 + getActivityInfo(req, res, next) {
  40 + let { activityId } = req.query;
  41 +
  42 + if (!activityId) {
  43 + return res.json({
  44 + code: 400,
  45 + message: INVALID_PARAMS
  46 + });
  47 + }
  48 +
  49 + return req.ctx(NewProFesModel).getActivityInfo(activityId).then(result => {
  50 + return res.json(result);
  51 + }).catch(next);
  52 + },
  53 +
  54 + /**
  55 + * 点赞
  56 + * @param req
  57 + * @param res
  58 + * @param next
  59 + * @returns {*}
  60 + */
  61 + sendStar(req, res, next) {
  62 + let { uid, session_key, app_version, client_type, activityId } = req.body;
  63 +
  64 + if (!uid || !activityId || !session_key || !app_version || !client_type) {
  65 + return res.json({
  66 + code: 400,
  67 + message: INVALID_PARAMS
  68 + });
  69 + }
  70 +
  71 + let data = {
  72 + uid: uid,
  73 + sessionKey: session_key,
  74 + appVersion: client_type === 'miniapp' ? global.yoho.appVersion : app_version,
  75 + appSessionType: client_type,
  76 + activityId
  77 + };
  78 +
  79 + return req.ctx(NewProFesModel).sendStar(data).then(result => {
  80 + return res.json(result);
  81 + }).catch(next);
  82 + },
  83 +
  84 + /**
  85 + * 获取商品池信息
  86 + * @param req
  87 + * @param res
  88 + * @param next
  89 + * @returns {*}
  90 + */
  91 + getProductPool(req, res, next) {
  92 + let { productPool, order = 'pools_sort_desc' } = req.query;
  93 +
  94 + if (!productPool) {
  95 + return res.json({
  96 + code: 400,
  97 + message: INVALID_PARAMS
  98 + });
  99 + }
  100 +
  101 + return req.ctx(NewProFesModel).getProductPool(productPool, order).then(result => {
  102 + return res.json(result);
  103 + }).catch(next);
  104 + },
  105 +
  106 + /**
  107 + * 通过SKN获取商品信息
  108 + * @param req
  109 + * @param res
  110 + * @param next
  111 + */
  112 + getProductBySkn(req, res, next) {
  113 + let { productSkn } = req.query;
  114 +
  115 + if (!productSkn) {
  116 + return res.json({
  117 + code: 400,
  118 + message: INVALID_PARAMS
  119 + });
  120 + }
  121 +
  122 + let skns = productSkn.split(',');
  123 +
  124 + return req.ctx(NewProFesModel).getProductBySkn(skns.join(',')).then(result => {
  125 + return res.json(result);
  126 + }).catch(next);
  127 + },
  128 +
  129 + sendCoupon(req, res, next) {
  130 + let { uid, app, token } = req.body;
  131 +
  132 + if (!uid || !token || !app) {
  133 + return res.json({
  134 + code: 400,
  135 + message: INVALID_PARAMS
  136 + });
  137 + }
  138 +
  139 + try {
  140 + app = JSON.parse(app);
  141 + } catch (e) {
  142 + return res.json({
  143 + code: 400,
  144 + message: INVALID_PARAMS
  145 + });
  146 + }
  147 +
  148 + let data = {
  149 + uid: uid,
  150 + sessionKey: app.session_key,
  151 + appVersion: app.client_type === 'miniapp' ? global.yoho.appVersion : app.app_version,
  152 + appSessionType: app.client_type,
  153 + token
  154 + };
  155 +
  156 + return req.ctx(NewProFesModel).sendCoupon(data).then(result => {
  157 + res.json(result);
  158 + }).catch(next);
  159 + }
  160 +};
  161 +
  162 +module.exports = NewProFesController;
  1 +/**
  2 + * 新品节活动API MODEL
  3 + * 2019-08-27
  4 + */
  5 +
  6 +class newProFesModel extends global.yoho.BaseModel {
  7 + constructor(ctx) {
  8 + super(ctx);
  9 + }
  10 +
  11 + /**
  12 + * 获取购买者列表
  13 + */
  14 + getBuyerList(activityId) {
  15 + return this.get({
  16 + url: '',
  17 + data: {
  18 + method: 'app.newArrActivity.userList',
  19 + activityId: activityId
  20 + }
  21 + });
  22 + }
  23 +
  24 + /**
  25 + * 获取新品节活动信息
  26 + * @param activityId
  27 + */
  28 + getActivityInfo(activityId) {
  29 + return this.get({
  30 + url: '',
  31 + data: {
  32 + method: 'app.newArrActivity.info',
  33 + activityId: activityId
  34 + }
  35 + });
  36 + }
  37 +
  38 + /**
  39 + * 点赞
  40 + * @param data
  41 + */
  42 + sendStar(data) {
  43 + let uid = {
  44 + toString: () => {
  45 + return parseInt(data.uid, 10);
  46 + },
  47 + sessionKey: data.sessionKey,
  48 + appVersion: data.appVersion,
  49 + appSessionType: data.appSessionType
  50 + };
  51 +
  52 + delete data.sessionKey;
  53 + delete data.appVersion;
  54 + delete data.appSessionType;
  55 +
  56 + return this.get({
  57 + url: '',
  58 + data: {
  59 + method: 'app.newArrActivity.star',
  60 + uid: uid,
  61 + activityId: data.activityId
  62 + }
  63 + });
  64 + }
  65 +
  66 + /**
  67 + * 获取商品池列表
  68 + * @param productPool
  69 + * @returns {*}
  70 + */
  71 + getProductPool(productPool, order) {
  72 + return this.get({
  73 + url: '',
  74 + data: {
  75 + method: 'app.search.pool.productList',
  76 + productPool: productPool,
  77 + order: order
  78 + }
  79 + });
  80 + }
  81 +
  82 + /**
  83 + * 通过商品skn取商品列表
  84 + * @param skns
  85 + * @returns {*}
  86 + */
  87 + getProductBySkn(skns) {
  88 + return this.get({
  89 + url: '',
  90 + data: {
  91 + method: 'h5.product.batch',
  92 + productSkn: skns
  93 + }
  94 + });
  95 + }
  96 +
  97 + /**
  98 + * 领券
  99 + */
  100 + sendCoupon(obj) {
  101 + let uid = {
  102 + toString: () => {
  103 + return parseInt(obj.uid, 10);
  104 + },
  105 + sessionKey: obj.sessionKey,
  106 + appVersion: obj.appVersion,
  107 + appSessionType: obj.appSessionType
  108 + };
  109 +
  110 + delete obj.sessionKey;
  111 + delete obj.appVersion;
  112 + delete obj.appSessionType;
  113 +
  114 + return this.get({
  115 + data: {
  116 + method: 'app.coupons.couponSend',
  117 + uid: uid,
  118 + coupon_send_token: obj.token
  119 + }
  120 + });
  121 + }
  122 +}
  123 +
  124 +module.exports = newProFesModel;
@@ -22,6 +22,7 @@ const mutilpartMiddleware = multipart(); @@ -22,6 +22,7 @@ const mutilpartMiddleware = multipart();
22 const yohoActivitys = require('./controllers/yoho-activitys'); 22 const yohoActivitys = require('./controllers/yoho-activitys');
23 const dailyCheckIn = require('./controllers/daily-check-in'); 23 const dailyCheckIn = require('./controllers/daily-check-in');
24 const share = require('./controllers/share'); 24 const share = require('./controllers/share');
  25 +const NewProFesController = require('./controllers/new-pro-fes');
25 26
26 router.get('/gettoken', qiniu.getToken); 27 router.get('/gettoken', qiniu.getToken);
27 router.get('/share/getSignPackage', wechat.getSignPackage); 28 router.get('/share/getSignPackage', wechat.getSignPackage);
@@ -108,4 +109,12 @@ router.get('/activity/checkIn/getUserInfo', dailyCheckIn.getUserInfo); // 获 @@ -108,4 +109,12 @@ router.get('/activity/checkIn/getUserInfo', dailyCheckIn.getUserInfo); // 获
108 109
109 router.get('/share/collect', share.collect); // 分享 110 router.get('/share/collect', share.collect); // 分享
110 router.get('/share/preshare', share.preshare); // 分享 111 router.get('/share/preshare', share.preshare); // 分享
  112 +
  113 +router.get('/newProFes/getBuyerList', NewProFesController.getBuyerList); // 获取新品节购买用户列表
  114 +router.get('/newProFes/getActivityInfo', NewProFesController.getActivityInfo); // 获取新品节活动信息
  115 +router.post('/newProFes/sendStar', NewProFesController.sendStar); // 点赞
  116 +router.get('/newProFes/getProductPool', NewProFesController.getProductPool); // 获取商品池列表
  117 +router.get('/newProFes/getProductBySkn', NewProFesController.getProductBySkn); // 获取商品列表
  118 +router.post('/newProFes/sendCoupon', NewProFesController.sendCoupon); // 领券
  119 +
111 module.exports = router; 120 module.exports = router;
@@ -183,7 +183,7 @@ const userController = { @@ -183,7 +183,7 @@ const userController = {
183 183
184 // console.log('WECHAT_LOGIN_URL:', WECHAT_LOGIN_URL); 184 // console.log('WECHAT_LOGIN_URL:', WECHAT_LOGIN_URL);
185 // console.log('referer', referer, referer.indexOf('yoho.cn')); 185 // console.log('referer', referer, referer.indexOf('yoho.cn'));
186 - if (referer && (referer.indexOf('yoho.cn') >= 0)) { 186 + if (referer && (referer.indexOf('yoho.cn') >= 0 || referer.indexOf('yohobuy.com') >= 0)) {
187 _.set(req.session, 'user.wechatReferer', referer); 187 _.set(req.session, 'user.wechatReferer', referer);
188 _.set(req.session, 'user.wechatState', state); 188 _.set(req.session, 'user.wechatState', state);
189 189
@@ -13,7 +13,7 @@ const isTest = process.env.NODE_ENV === 'test3'; @@ -13,7 +13,7 @@ const isTest = process.env.NODE_ENV === 'test3';
13 module.exports = { 13 module.exports = {
14 app: 'h5', 14 app: 'h5',
15 appName: 'yoho-activity-platform', 15 appName: 'yoho-activity-platform',
16 - appVersion: '6.6.0', // 调用api的版本 16 + appVersion: '6.8.9', // 调用api的版本
17 port: 6006, 17 port: 6006,
18 siteUrl: '//action.yoho.cn', 18 siteUrl: '//action.yoho.cn',
19 assetUrl: `/yoho-activity-platform/${pkg.version}/`, 19 assetUrl: `/yoho-activity-platform/${pkg.version}/`,