Authored by huangyi

Merge branch 'feature/yohood' of http://git.yoho.cn/fe/yoho-activity-platform into feature/yohood

@@ -13,8 +13,8 @@ const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content'; @@ -13,8 +13,8 @@ const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content';
13 const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user'; 13 const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user';
14 14
15 const MINUTE_TIMES = 60; 15 const MINUTE_TIMES = 60;
16 -const PRODUCT_CACHE_TIMES = MINUTE_TIMES * 5; // 商品(列表&详情)缓存时间  
17 -const RECENT_CODE_CACHE_TIME = MINUTE_TIMES; // 最近获取记录缓存时间 16 +const PRODUCT_CACHE_TIMES = MINUTE_TIMES / 6; // 商品(列表&详情)缓存时间
  17 +const RECENT_CODE_CACHE_TIME = MINUTE_TIMES / 12; // 最近获取记录缓存时间
18 const MAX_JOIN_TIMES = 5; // 最大活动参与次数 18 const MAX_JOIN_TIMES = 5; // 最大活动参与次数
19 const MAX_RECOMEND_NUM = 10; // 最大推荐活动数目 19 const MAX_RECOMEND_NUM = 10; // 最大推荐活动数目
20 const PAGE_SIZE = 10; 20 const PAGE_SIZE = 10;
@@ -303,7 +303,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -303,7 +303,7 @@ module.exports = class extends global.yoho.BaseModel {
303 303
304 let info = await Promise.all([ 304 let info = await Promise.all([
305 mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT} 305 mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
306 - where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: MINUTE_TIMES / 2}), 306 + where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: PRODUCT_CACHE_TIMES}),
307 this.getUserJoinNum(actPrizeId, true).then(result => { 307 this.getUserJoinNum(actPrizeId, true).then(result => {
308 return result.data; 308 return result.data;
309 }) 309 })
@@ -199,6 +199,52 @@ const yohood = { @@ -199,6 +199,52 @@ const yohood = {
199 return req.ctx(YohoodModel).getShopProductsByShopId(shopId).then(result => { 199 return req.ctx(YohoodModel).getShopProductsByShopId(shopId).then(result => {
200 return res.json(result); 200 return res.json(result);
201 }); 201 });
  202 + },
  203 +
  204 + async getCoupon(req, res) {
  205 + let {uid, couponId} = req.query;
  206 +
  207 + console.log(uid, couponId);
  208 +
  209 + if (!uid || !couponId) {
  210 + return res.json({
  211 + code: 400,
  212 + message: INVALID_PARAMS
  213 + });
  214 + }
  215 +
  216 + let couponInfo = await req.ctx(YohoodModel).getCouponInfo(couponId);
  217 +
  218 + let couponDetail = await req.ctx(YohoodModel).getCouponDetail(uid, couponId);
  219 +
  220 + // console.log('couponDetail:', couponDetail);
  221 + // console.log('couponInfo', couponInfo.data[0].coupon_num);
  222 +
  223 + if (couponDetail.code === 200 && couponDetail.data.length > 0) {
  224 + return res.json(couponDetail);
  225 + } else if (couponInfo.data[0].coupon_num > 0) {
  226 + let getCoupon = await req.ctx(YohoodModel).getOfflineStoreCoupon(uid, couponId);
  227 +
  228 + // console.log('getCoupon:', getCoupon);
  229 + if (getCoupon.code === 200) {
  230 + couponDetail = await req.ctx(YohoodModel).getCouponDetail(uid, couponId);
  231 +
  232 + return res.json(couponDetail);
  233 + } else if (getCoupon.code === 201) {
  234 + return res.json(couponDetail);
  235 + } else {
  236 + return res.json({
  237 + code: 203,
  238 + message: '领券失败'
  239 + });
  240 + }
  241 +
  242 + } else {
  243 + return res.json({
  244 + code: 204,
  245 + message: '券已领完'
  246 + });
  247 + }
202 } 248 }
203 }; 249 };
204 250
@@ -2,6 +2,8 @@ @@ -2,6 +2,8 @@
2 * Created by qiujun on 2018/7/19. 2 * Created by qiujun on 2018/7/19.
3 */ 3 */
4 4
  5 +const service = global.yoho.StoreAPI;
  6 +
5 class YohoodModel extends global.yoho.BaseModel { 7 class YohoodModel extends global.yoho.BaseModel {
6 constructor(ctx) { 8 constructor(ctx) {
7 super(ctx); 9 super(ctx);
@@ -36,6 +38,40 @@ class YohoodModel extends global.yoho.BaseModel { @@ -36,6 +38,40 @@ class YohoodModel extends global.yoho.BaseModel {
36 } 38 }
37 }); 39 });
38 } 40 }
  41 +
  42 + /**
  43 + * 获取线下店优惠券
  44 + * @param uid
  45 + * @param couponId
  46 + */
  47 + async getOfflineStoreCoupon(uid, couponId) {
  48 + return await service.get('coupon/sendCoupon.do', {
  49 + uid: uid,
  50 + couponId: couponId
  51 + });
  52 + }
  53 +
  54 + /**
  55 + * 获取用户下的券信息
  56 + * @param uid
  57 + * @param couponId
  58 + */
  59 + async getCouponDetail(uid, couponId) {
  60 + return await service.get('coupon/getCouponDetail.do', {
  61 + uid: uid,
  62 + couponId: couponId
  63 + });
  64 + }
  65 +
  66 + /**
  67 + * 获取券信息
  68 + * @param couponId
  69 + */
  70 + async getCouponInfo(couponId) {
  71 + return await service.get('coupon/getCoupon.do', {
  72 + couponId: couponId
  73 + });
  74 + }
39 } 75 }
40 76
41 77
@@ -44,6 +44,7 @@ router.get('/yohood/getNewsDetail', yohood.getNewsDetail); @@ -44,6 +44,7 @@ router.get('/yohood/getNewsDetail', yohood.getNewsDetail);
44 router.get('/yohood/getRecommend', yohood.getRecommend); 44 router.get('/yohood/getRecommend', yohood.getRecommend);
45 router.get('/yohood/getResource', yohood.getYohoBuyResource); 45 router.get('/yohood/getResource', yohood.getYohoBuyResource);
46 router.get('/yohood/getShopProduct', yohood.getYohoBuyShopProduct); 46 router.get('/yohood/getShopProduct', yohood.getYohoBuyShopProduct);
  47 +router.get('/yohood/getCoupon', yohood.getCoupon);
47 48
48 // coupon 49 // coupon
49 router.get('/coupon/getCouponList', coupon.couponList); 50 router.get('/coupon/getCouponList', coupon.couponList);
@@ -51,4 +52,5 @@ router.get('/coupon/getCouponSendFlags', coupon.couponSendFlag); @@ -51,4 +52,5 @@ router.get('/coupon/getCouponSendFlags', coupon.couponSendFlag);
51 router.post('/coupon/couponGet', coupon.couponGet); 52 router.post('/coupon/couponGet', coupon.couponGet);
52 router.get('/coupon/couponUserOwner', coupon.couponUserOwner); 53 router.get('/coupon/couponUserOwner', coupon.couponUserOwner);
53 54
  55 +
54 module.exports = router; 56 module.exports = router;
@@ -25,6 +25,7 @@ module.exports = { @@ -25,6 +25,7 @@ module.exports = {
25 25
26 singleApi: 'http://api.yoho.cn/', 26 singleApi: 'http://api.yoho.cn/',
27 api: 'http://api.yoho.cn/', 27 api: 'http://api.yoho.cn/',
  28 + store: 'http://192.168.102.47:8080/portal-gateway/wechat/',
28 service: 'http://service.yoho.cn/', 29 service: 'http://service.yoho.cn/',
29 serviceNotify: 'http://service.yoho.cn/', 30 serviceNotify: 'http://service.yoho.cn/',
30 platformApi: 'http://172.16.6.210:8088/', 31 platformApi: 'http://172.16.6.210:8088/',
@@ -128,6 +129,7 @@ if (isProduction) { @@ -128,6 +129,7 @@ if (isProduction) {
128 assetUrl: `/yoho-activity-platform/${pkg.version}/`, 129 assetUrl: `/yoho-activity-platform/${pkg.version}/`,
129 domains: { 130 domains: {
130 api: 'http://api.yoho.yohoops.org/', 131 api: 'http://api.yoho.yohoops.org/',
  132 + store: 'https://openstore.yohobuy.com',
131 service: 'http://api.yoho.yohoops.org/', 133 service: 'http://api.yoho.yohoops.org/',
132 global: 'http://api-global.yohobuy.com', 134 global: 'http://api-global.yohobuy.com',
133 liveApi: 'http://api.live.yoho.cn/', 135 liveApi: 'http://api.live.yoho.cn/',
@@ -184,7 +186,7 @@ if (isProduction) { @@ -184,7 +186,7 @@ if (isProduction) {
184 api: process.env.TEST_API || 'http://api-test1.yohops.com:9999/', 186 api: process.env.TEST_API || 'http://api-test1.yohops.com:9999/',
185 service: process.env.TEST_SERVICE || 'http://service-test1.yohops.com:9999/', 187 service: process.env.TEST_SERVICE || 'http://service-test1.yohops.com:9999/',
186 global: process.env.TEST_GLOBAL || 'http://global-test-soa.yohops.com:9999/', 188 global: process.env.TEST_GLOBAL || 'http://global-test-soa.yohops.com:9999/',
187 - store: process.env.TEST_STORE || 'http://192.168.102.210:8080/portal-gateway/', 189 + store: process.env.TEST_STORE || 'http://192.168.102.210:8080/portal-gateway/wechat/',
188 liveApi: process.env.TEST_LIVE || 'http://testapi.live.yohops.com:9999/', 190 liveApi: process.env.TEST_LIVE || 'http://testapi.live.yohops.com:9999/',
189 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/', 191 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/',
190 platformApi: 'http://192.168.102.48:8088/' 192 platformApi: 'http://192.168.102.48:8088/'