Authored by zhangxiaoru

添加isStudent

1 'use strict'; 1 'use strict';
2 2
3 const shareBuyModel = require('../models/share-buy'), 3 const shareBuyModel = require('../models/share-buy'),
4 - headerModel = require('../../../doraemon/models/header'); 4 + headerModel = require('../../../doraemon/models/header'),
  5 + co = require('bluebird').coroutine;
5 6
6 exports.index = (req, res, next) => { 7 exports.index = (req, res, next) => {
7 let activityId = req.query.act_id || 2023, 8 let activityId = req.query.act_id || 2023,
8 isApp = req.yoho.isApp, 9 isApp = req.yoho.isApp,
9 uid = req.user.uid; 10 uid = req.user.uid;
10 11
11 - req.ctx(shareBuyModel).shareIndex(activityId, isApp, uid).then(data => { 12 + co(function* () {
  13 + let isStudent = yield req.ctx(shareBuyModel).checkStudent(uid);
  14 + let indexData = yield req.ctx(shareBuyModel).shareIndex(activityId, isApp, uid, isStudent);
  15 +
12 res.render('share-buy/share-buy', { 16 res.render('share-buy/share-buy', {
13 pageHeader: headerModel.setNav({ 17 pageHeader: headerModel.setNav({
14 navTitle: '分享购' 18 navTitle: '分享购'
@@ -17,15 +21,14 @@ exports.index = (req, res, next) => { @@ -17,15 +21,14 @@ exports.index = (req, res, next) => {
17 localCss: true, 21 localCss: true,
18 width750: true, 22 width750: true,
19 title: '分享购', 23 title: '分享购',
20 - userCouponBoList: data.userCouponBoList,  
21 - newsFlash: data.newsFlash,  
22 - rebeatUrl: data.rebeatUrl,  
23 - strategyUrl: data.strategyUrl,  
24 - banner: data.banner,  
25 - isStudent: data.isStudent 24 + userCouponBoList: indexData.userCouponBoList,
  25 + newsFlash: indexData.newsFlash,
  26 + rebeatUrl: indexData.rebeatUrl,
  27 + strategyUrl: indexData.strategyUrl,
  28 + banner: indexData.banner,
  29 + isStudent: indexData.isStudent
26 }); 30 });
27 -  
28 - }).catch(next); 31 + })().catch(next);
29 }; 32 };
30 33
31 exports.detail = (req, res, next) => { 34 exports.detail = (req, res, next) => {
@@ -11,10 +11,10 @@ module.exports = class extends global.yoho.BaseModel { @@ -11,10 +11,10 @@ module.exports = class extends global.yoho.BaseModel {
11 /** 11 /**
12 * 首页数据 12 * 首页数据
13 */ 13 */
14 - shareIndex(activityId, isApp, uid) { 14 + shareIndex(activityId, isApp, uid, isStudent) {
15 15
16 - return api.all([this._CouponInfo(activityId, uid), this._redeatList(), this._banner(),  
17 - this._checkStudent(uid)]).then(result => { 16 + return api.all([this._CouponInfo(activityId, uid, isStudent), this._redeatList(),
  17 + this._banner()]).then(result => {
18 18
19 const indexData = { 19 const indexData = {
20 newsFlash: [] 20 newsFlash: []
@@ -23,9 +23,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -23,9 +23,7 @@ module.exports = class extends global.yoho.BaseModel {
23 const rebeatUrl = '//m.yohobuy.com/activity/share-buy/my-rebeat', 23 const rebeatUrl = '//m.yohobuy.com/activity/share-buy/my-rebeat',
24 strategyUrl = 'http://activity.yoho.cn/feature/115.html?share_id=2023&title=分享购攻略'; 24 strategyUrl = 'http://activity.yoho.cn/feature/115.html?share_id=2023&title=分享购攻略';
25 25
26 - if (result[3]) {  
27 - indexData.isStudent = parseInt(result[3].isStudent, 10) === 1 ? true : false;  
28 - } 26 + indexData.isStudent = isStudent;
29 27
30 if (result[0] && result[0].data && result[0].data.userCouponBoList) { 28 if (result[0] && result[0].data && result[0].data.userCouponBoList) {
31 _.forEach(result[0].data.userCouponBoList, function(val) { 29 _.forEach(result[0].data.userCouponBoList, function(val) {
@@ -104,11 +102,12 @@ module.exports = class extends global.yoho.BaseModel { @@ -104,11 +102,12 @@ module.exports = class extends global.yoho.BaseModel {
104 /** 102 /**
105 * 首页获取优惠券信息 103 * 首页获取优惠券信息
106 */ 104 */
107 - _CouponInfo(activityId, uid) { 105 + _CouponInfo(activityId, uid, isStudent) {
108 return api.get('', { 106 return api.get('', {
109 method: 'app.activity.getActivityCouponInfo', 107 method: 'app.activity.getActivityCouponInfo',
110 activity_id: activityId, 108 activity_id: activityId,
111 - uid: uid 109 + uid: uid,
  110 + isStudent: isStudent
112 }, { 111 }, {
113 code: 200 112 code: 200
114 }).then((result) => { 113 }).then((result) => {
@@ -195,19 +194,19 @@ module.exports = class extends global.yoho.BaseModel { @@ -195,19 +194,19 @@ module.exports = class extends global.yoho.BaseModel {
195 /** 194 /**
196 * 判断是不是学生 195 * 判断是不是学生
197 */ 196 */
198 - _checkStudent(uid) { 197 + checkStudent(uid) {
199 return api.get('', { 198 return api.get('', {
200 method: 'app.student.checkIsStudent', 199 method: 'app.student.checkIsStudent',
201 uid: uid 200 uid: uid
202 }).then(result => { 201 }).then(result => {
203 202
204 - let resu = {}; 203 + let isStudent;
205 204
206 if (result && result.data && result.code === 200) { 205 if (result && result.data && result.code === 200) {
207 - resu = result.data; 206 + isStudent = parseInt(result.data.isStudent, 10) === 1 ? true : false;
208 } 207 }
209 208
210 - return resu; 209 + return isStudent;
211 210
212 }); 211 });
213 } 212 }