Authored by zhangxiaoru

逻辑修改

@@ -5,9 +5,10 @@ const shareBuyModel = require('../models/share-buy'), @@ -5,9 +5,10 @@ const shareBuyModel = require('../models/share-buy'),
5 5
6 exports.index = (req, res, next) => { 6 exports.index = (req, res, next) => {
7 let activityId = req.query.activity_id || 2023, 7 let activityId = req.query.activity_id || 2023,
8 - isApp = req.yoho.isApp; 8 + isApp = req.yoho.isApp,
  9 + uid = req.user.uid;
9 10
10 - req.ctx(shareBuyModel).shareIndex(activityId, isApp).then(data => { 11 + req.ctx(shareBuyModel).shareIndex(activityId, isApp, uid).then(data => {
11 res.render('share-buy/share-buy', { 12 res.render('share-buy/share-buy', {
12 pageHeader: headerModel.setNav({ 13 pageHeader: headerModel.setNav({
13 navTitle: '分享购' 14 navTitle: '分享购'
@@ -20,30 +21,25 @@ exports.index = (req, res, next) => { @@ -20,30 +21,25 @@ exports.index = (req, res, next) => {
20 newsFlash: data.newsFlash, 21 newsFlash: data.newsFlash,
21 rebeatUrl: data.rebeatUrl, 22 rebeatUrl: data.rebeatUrl,
22 strategyUrl: data.strategyUrl, 23 strategyUrl: data.strategyUrl,
23 - banner: data.banner 24 + banner: data.banner,
  25 + isStudent: data.isStudent
24 }); 26 });
25 27
26 }).catch(next); 28 }).catch(next);
27 }; 29 };
28 30
29 exports.detail = (req, res, next) => { 31 exports.detail = (req, res, next) => {
30 - let uid = req.user.uid,  
31 - param = { 32 + let param = {
32 counum: req.query.counum, 33 counum: req.query.counum,
33 couponType: req.query.couponType, 34 couponType: req.query.couponType,
34 detailDes: req.query.detailDes, 35 detailDes: req.query.detailDes,
35 - couponId: req.query.couponId 36 + couponId: req.query.couponId,
  37 + useCode: req.query.useCode
36 }, 38 },
37 isApp = req.yoho.isApp, 39 isApp = req.yoho.isApp,
38 registerUrl; 40 registerUrl;
39 41
40 - if (isApp) {  
41 - registerUrl = 'http://m.yohobuy.com/activity/student/register?sharebuy=openbuy:yohobuy={"action":"go.h5","params":{"islogin":"N","type":"13","url":"http://m.yohobuy.com/activity/student/register"}}';  
42 - } else {  
43 - registerUrl = 'http://m.yohobuy.com/activity/student/register';  
44 - }  
45 -  
46 - req.ctx(shareBuyModel).shareDetail(uid, param, isApp).then(data => { 42 + req.ctx(shareBuyModel).shareDetail(param, isApp).then(data => {
47 43
48 res.render('share-buy/share-detail', { 44 res.render('share-buy/share-detail', {
49 pageHeader: headerModel.setNav({ 45 pageHeader: headerModel.setNav({
@@ -11,72 +11,84 @@ module.exports = class extends global.yoho.BaseModel { @@ -11,72 +11,84 @@ module.exports = class extends global.yoho.BaseModel {
11 /** 11 /**
12 * 首页数据 12 * 首页数据
13 */ 13 */
14 - shareIndex(activityId, isApp) {  
15 -  
16 - return api.all([this._CouponInfo(activityId), this._redeatList(), this._banner()]).then(result => {  
17 - const indexData = {  
18 - newsFlash: []  
19 - };  
20 -  
21 - const rebeatUrl = '//m.yohobuy.com/activity/share-buy/my-rebeat',  
22 - strategyUrl = 'http://activity.yoho.cn/feature/115.html?share_id=2023&title=分享购攻略';  
23 -  
24 - if (result[0] && result[0].data && result[0].data.userCouponBoList) {  
25 - _.forEach(result[0].data.userCouponBoList, function(val) {  
26 -  
27 - if (val.sortNames) {  
28 - val.couponDescribe = '限' + val.sortNames + '使用';  
29 - val.detailDes = '限品类: ' + val.sortNames;  
30 - } else if (val.brandNames) {  
31 - val.couponDescribe = '限' + val.brandNames + '使用';  
32 - val.detailDes = '限品牌: ' + val.brandNames;  
33 - } else if (val.shareCoupon === '全场通用') {  
34 - val.couponDescribe = '任意商品使用';  
35 - val.detailDes = val.shareCoupon;  
36 - } else if (val.shopNames) {  
37 - val.couponDescribe = '限' + val.shopNames + '使用';  
38 - val.detailDes = val.shareCoupon;  
39 - }  
40 -  
41 -  
42 - val.detailUrl = helpers.urlFormat('/activity/share-buy/detail', {  
43 - counum: val.couponValue,  
44 - couponType: val.shareCouponType,  
45 - detailDes: val.detailDes,  
46 - couponId: val.couponId 14 + shareIndex(activityId, isApp, uid) {
  15 +
  16 + return api.all([this._CouponInfo(activityId), this._redeatList(), this._banner(),
  17 + this._checkStudent(uid)]).then(result => {
  18 +
  19 + const indexData = {
  20 + newsFlash: []
  21 + };
  22 +
  23 + const rebeatUrl = '//m.yohobuy.com/activity/share-buy/my-rebeat',
  24 + strategyUrl = 'http://activity.yoho.cn/feature/115.html?share_id=2023&title=分享购攻略';
  25 +
  26 + if (result[3]) {
  27 + indexData.isStudent = parseInt(result[3].isStudent, 10) === 1 ? true : false;
  28 + }
  29 +
  30 + if (result[0] && result[0].data && result[0].data.userCouponBoList) {
  31 + _.forEach(result[0].data.userCouponBoList, function(val) {
  32 +
  33 + if (val.sortNames) {
  34 + val.couponDescribe = '限' + val.sortNames + '使用';
  35 + val.detailDes = '限品类: ' + val.sortNames;
  36 + } else if (val.brandNames) {
  37 + val.couponDescribe = '限' + val.brandNames + '使用';
  38 + val.detailDes = '限品牌: ' + val.brandNames;
  39 + } else if (val.shareCoupon === '全场通用') {
  40 + val.couponDescribe = '任意商品使用';
  41 + val.detailDes = val.shareCoupon;
  42 + } else if (val.shopNames) {
  43 + val.couponDescribe = '限' + val.shopNames + '使用';
  44 + val.detailDes = val.shareCoupon;
  45 + }
  46 +
  47 + val.detailUrl = helpers.urlFormat('/activity/share-buy/detail', {
  48 + counum: val.couponValue,
  49 + couponType: val.shareCouponType,
  50 + detailDes: val.detailDes,
  51 + couponId: val.couponId,
  52 + useCode: uid.toString()
  53 + });
  54 +
  55 + if (isApp) {
  56 + val.detailUrl = val.detailUrl +
  57 + '&openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"http:' + val.detailUrl +
  58 + '","params":{"counum":"' + val.couponValue + '","couponType":"' + val.shareCouponType +
  59 + '","detailDes":"' + val.detailDes + '","couponId":"' + val.couponId + '","useCode":"' +
  60 + uid + '"}}}';
  61 + }
  62 +
  63 + if (!indexData.isStudent) {
  64 + val.detailUrl = '';
  65 + }
47 }); 66 });
48 67
49 - if (isApp) {  
50 - val.detailUrl = val.detailUrl +  
51 - '&openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"http:' + val.detailUrl +  
52 - '","params":{"counum":"' + val.couponValue + '","couponType":"' + val.shareCouponType +  
53 - '","detailDes":"' + val.detailDes + '","couponId":"' + val.couponId + '"}}}';  
54 - }  
55 - });  
56 -  
57 - indexData.userCouponBoList = result[0].data.userCouponBoList;  
58 - } 68 + indexData.userCouponBoList = result[0].data.userCouponBoList;
  69 + }
59 70
60 - if (result[1] && result[1].data && result[1].data.detail) {  
61 - _.forEach(result[1].data.detail, function(data) {  
62 - indexData.newsFlash.push({  
63 - flashDetail: '用户' + data.nickName + ' 今日返利' + data.coinNum + '个有货币' 71 + if (result[1] && result[1].data && result[1].data.detail) {
  72 + _.forEach(result[1].data.detail, function(data) {
  73 + indexData.newsFlash.push({
  74 + flashDetail: '用户' + data.nickName + ' 今日返利' + data.coinNum + '个有货币'
  75 + });
64 }); 76 });
65 - });  
66 - } 77 + }
67 78
68 - if (result[2]) {  
69 - indexData.banner = result[2].data[0].src;  
70 - } 79 + if (result[2]) {
  80 + indexData.banner = result[2].data[0].src;
  81 + }
71 82
72 - indexData.rebeatUrl = isApp ? rebeatUrl +  
73 - '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"http:' + rebeatUrl + '"}}' : rebeatUrl; 83 + indexData.rebeatUrl = isApp ? rebeatUrl +
  84 + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"http:' + rebeatUrl + '"}}' :
  85 + rebeatUrl;
74 86
75 - indexData.strategyUrl = isApp ? strategyUrl +  
76 - '&openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + strategyUrl + '"}}' : strategyUrl; 87 + indexData.strategyUrl = isApp ? strategyUrl +
  88 + '&openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + strategyUrl + '"}}' : strategyUrl;
77 89
78 - return indexData;  
79 - }); 90 + return indexData;
  91 + });
80 } 92 }
81 93
82 /** 94 /**
@@ -129,35 +141,13 @@ module.exports = class extends global.yoho.BaseModel { @@ -129,35 +141,13 @@ module.exports = class extends global.yoho.BaseModel {
129 }); 141 });
130 } 142 }
131 143
132 - shareDetail(uid, param, isApp) {  
133 - return api.all([this._couponDetail(uid, param, isApp), this._checkStudent(uid)]).then(result => {  
134 - let finalData;  
135 -  
136 - if (result[0]) {  
137 - finalData = _.assign(finalData, result[0]);  
138 - }  
139 -  
140 - if (result[1]) {  
141 - finalData = _.assign(finalData, {  
142 - isStudent: parseInt(result[1].isStudent, 10) === 1 ? true : false  
143 - });  
144 - }  
145 -  
146 - if (!finalData.isStudent) {  
147 - finalData.couponCode = '*******';  
148 - }  
149 -  
150 - return finalData;  
151 - });  
152 - }  
153 -  
154 /** 144 /**
155 * 优惠劵详情数据 145 * 优惠劵详情数据
156 */ 146 */
157 - _couponDetail(uid, param, isApp) { 147 + shareDetail(param, isApp) {
158 return api.get('', { 148 return api.get('', {
159 method: 'app.activity.getActivityCouponCode', 149 method: 'app.activity.getActivityCouponCode',
160 - uid: uid, 150 + uid: param.useCode,
161 coupon_id: param.couponId 151 coupon_id: param.couponId
162 }, { 152 }, {
163 code: 200 153 code: 200
@@ -200,7 +190,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -200,7 +190,7 @@ module.exports = class extends global.yoho.BaseModel {
200 190
201 let resu = {}; 191 let resu = {};
202 192
203 - if (result && result.data) { 193 + if (result && result.data && result.code === 200) {
204 resu = result.data; 194 resu = result.data;
205 } 195 }
206 196
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <img src="{{image banner 750 366}}"><img> 3 <img src="{{image banner 750 366}}"><img>
4 </div> 4 </div>
5 5
6 - <div class="coupon-list"> 6 + <div class="coupon-list" data-student="{{isStudent}}">
7 {{# userCouponBoList}} 7 {{# userCouponBoList}}
8 <div class="coupon-group"> 8 <div class="coupon-group">
9 <div class="coupon-left"> 9 <div class="coupon-left">
@@ -14,7 +14,11 @@ @@ -14,7 +14,11 @@
14 <p class="coupon-type">{{shareCouponType}}</p> 14 <p class="coupon-type">{{shareCouponType}}</p>
15 </div> 15 </div>
16 <div class="coupon-right"> 16 <div class="coupon-right">
17 - <a href="{{detailUrl}}">立即参与</a> 17 + {{#if detailUrl}}
  18 + <a href="{{detailUrl}}" class="join">立即参与</a>
  19 + {{else}}
  20 + <span class="join">立即参与</span>
  21 + {{/if}}
18 <p class="coupon-mold">{{shareCoupon}}</p> 22 <p class="coupon-mold">{{shareCoupon}}</p>
19 <p class="coupon-limit">{{couponDescribe}}</p> 23 <p class="coupon-limit">{{couponDescribe}}</p>
20 </div> 24 </div>
1 <div class="share-detail-page" > 1 <div class="share-detail-page" >
2 {{# detailData}} 2 {{# detailData}}
3 - <div class="coupon-detail" data-student="{{isStudent}}" data-app="{{isApp}}"> 3 + <div class="coupon-detail" data-app="{{isApp}}">
4 <div class="countdown"> 4 <div class="countdown">
5 <div class="title">距离活动时间还剩:</div> 5 <div class="title">距离活动时间还剩:</div>
6 {{#if finish}} 6 {{#if finish}}
@@ -62,11 +62,3 @@ @@ -62,11 +62,3 @@
62 </div> 62 </div>
63 {{/ detailData}} 63 {{/ detailData}}
64 </div> 64 </div>
65 -{{#unless detailData.isStudent}}  
66 -<div class="share-dialog-tip">  
67 - <div class="tip-box">  
68 - <div class="tip-center">完成学生认证即可参与活动哦~</div>  
69 - <a class="tip-btn" href="{{registerUrl}}">去认证</a>  
70 - </div>  
71 -</div>  
72 -{{/unless}}  
1 'use strict'; 1 'use strict';
2 require('activity/share-buy.page.css'); 2 require('activity/share-buy.page.css');
3 3
4 -let $ = require('yoho-jquery'); 4 +let $ = require('yoho-jquery'),
  5 + dialog = require('plugin/dialog'),
  6 + yoho = require('yoho-app');
5 7
6 let $news = $('.news'), 8 let $news = $('.news'),
7 newsLiL = $news.find('li').length, 9 newsLiL = $news.find('li').length,
@@ -38,3 +40,24 @@ if (newsLiL > 1) { @@ -38,3 +40,24 @@ if (newsLiL > 1) {
38 40
39 setInterval(Marquee, 100); 41 setInterval(Marquee, 100);
40 } 42 }
  43 +
  44 +$('.join').click(function() {
  45 + if ($('.coupon-list').data('student') === false) {
  46 +
  47 + dialog.showDialog({
  48 + dialogText: '完成学生认证即可参与活动哦~',
  49 + fast: true,
  50 + hasFooter: {
  51 + rightBtnText: '去认证'
  52 + }
  53 + }, function() {
  54 + if (yoho.isApp) {
  55 +
  56 + location.href = 'http://m.yohobuy.com/activity/student/register' +
  57 + '?openbuy:yohobuy={"action":"go.h5","params":{"islogin":"N","type":"13","url":"http://m.yohobuy.com/activity/student/register"}}';
  58 + } else {
  59 + location.href = '//m.yohobuy.com/activity/student/register';
  60 + }
  61 + }, null, true);
  62 + }
  63 +});
@@ -73,7 +73,7 @@ @@ -73,7 +73,7 @@
73 white-space: nowrap; 73 white-space: nowrap;
74 } 74 }
75 75
76 - a { 76 + .join {
77 float: right; 77 float: right;
78 margin: 55px 35px 0 0; 78 margin: 55px 35px 0 0;
79 display: block; 79 display: block;