Authored by 郝肖肖

'invite-ctx'

@@ -18,7 +18,7 @@ const secretKey = '5466ee572bcbc75830d044e66ab429bc';// 秘钥 @@ -18,7 +18,7 @@ const secretKey = '5466ee572bcbc75830d044e66ab429bc';// 秘钥
18 判断邀请 好友 类型 18 判断邀请 好友 类型
19 */ 19 */
20 exports.checkType = function(req, res, next) { 20 exports.checkType = function(req, res, next) {
21 - inviteModel.checkType() 21 + req.ctx(inviteModel).checkType()
22 .then(function(result) { 22 .then(function(result) {
23 if (result.code === 200 && result.data) { 23 if (result.code === 200 && result.data) {
24 res.locals.isVipDay = true; 24 res.locals.isVipDay = true;
@@ -40,7 +40,7 @@ exports.index = (req, res, next) => { @@ -40,7 +40,7 @@ exports.index = (req, res, next) => {
40 let uid = req.user.uid || req.query.uid || 0; 40 let uid = req.user.uid || req.query.uid || 0;
41 let renderPage = 'invite/list'; 41 let renderPage = 'invite/list';
42 42
43 - inviteModel.index({ 43 + req.ctx(inviteModel).index({
44 uid: uid, 44 uid: uid,
45 activityId: actId 45 activityId: actId
46 }).then((result) => { 46 }).then((result) => {
@@ -70,9 +70,9 @@ exports.share = (req, res, next) => { @@ -70,9 +70,9 @@ exports.share = (req, res, next) => {
70 let shareUid = req.params[0]; 70 let shareUid = req.params[0];
71 let actId = req.params[1]; 71 let actId = req.params[1];
72 let nums = req.params[2]; 72 let nums = req.params[2];
73 - let shareUrl = inviteModel.createShareUrl(shareUid, actId, nums); 73 + let shareUrl = req.ctx(inviteModel).createShareUrl(shareUid, actId, nums);
74 let callback = 'http://m.yohobuy.com/activity/invite/getwxinfo?url=' + shareUrl; 74 let callback = 'http://m.yohobuy.com/activity/invite/getwxinfo?url=' + shareUrl;
75 - let url = inviteModel.getWxOauthUrl(callback); 75 + let url = req.ctx(inviteModel).getWxOauthUrl(callback);
76 let wxUserInfo = req.cookies.wxUserInfo || {}; 76 let wxUserInfo = req.cookies.wxUserInfo || {};
77 77
78 if (_.isEmpty(wxUserInfo) || _.isEmpty(wxUserInfo.unionid)) { 78 if (_.isEmpty(wxUserInfo) || _.isEmpty(wxUserInfo.unionid)) {
@@ -80,7 +80,7 @@ exports.share = (req, res, next) => { @@ -80,7 +80,7 @@ exports.share = (req, res, next) => {
80 return false; 80 return false;
81 } 81 }
82 82
83 - inviteModel.shareModel({ 83 + req.ctx(inviteModel).shareModel({
84 uid: shareUid, 84 uid: shareUid,
85 activityId: actId, 85 activityId: actId,
86 nums: nums, 86 nums: nums,
@@ -122,7 +122,7 @@ exports.share = (req, res, next) => { @@ -122,7 +122,7 @@ exports.share = (req, res, next) => {
122 exports.sendRegCodeToMobile = (req, res, next) => { 122 exports.sendRegCodeToMobile = (req, res, next) => {
123 let mobile = req.query.mobile || ''; 123 let mobile = req.query.mobile || '';
124 124
125 - inviteModel.sendRegCodeToMobile({ 125 + req.ctx(inviteModel).sendRegCodeToMobile({
126 area: 86, 126 area: 86,
127 mobile: mobile 127 mobile: mobile
128 }).then((result) => { 128 }).then((result) => {
@@ -135,7 +135,7 @@ exports.checkOldUserCoupon = (req, res, next) => { @@ -135,7 +135,7 @@ exports.checkOldUserCoupon = (req, res, next) => {
135 let mobile = req.query.mobile || ''; 135 let mobile = req.query.mobile || '';
136 let actId = req.query.actId || ''; 136 let actId = req.query.actId || '';
137 137
138 - inviteModel.checkOldUserCoupon({ 138 + req.ctx(inviteModel).checkOldUserCoupon({
139 mobile: mobile, 139 mobile: mobile,
140 activityId: actId 140 activityId: actId
141 }).then((result) => { 141 }).then((result) => {
@@ -148,7 +148,7 @@ exports.validRegCode = (req, res, next) => { @@ -148,7 +148,7 @@ exports.validRegCode = (req, res, next) => {
148 let mobile = req.query.mobile || ''; 148 let mobile = req.query.mobile || '';
149 let code = req.query.code || ''; 149 let code = req.query.code || '';
150 150
151 - inviteModel.validRegCode({ 151 + req.ctx(inviteModel).validRegCode({
152 area: 86, 152 area: 86,
153 mobile: mobile, 153 mobile: mobile,
154 code: code 154 code: code
@@ -162,7 +162,7 @@ exports.register = (req, res, next) => { @@ -162,7 +162,7 @@ exports.register = (req, res, next) => {
162 let mobile = req.query.mobile || ''; 162 let mobile = req.query.mobile || '';
163 let activityName = req.query.activityName || 'invite'; 163 let activityName = req.query.activityName || 'invite';
164 164
165 - inviteModel.register({ 165 + req.ctx(inviteModel).register({
166 mobile: mobile, 166 mobile: mobile,
167 activityName: activityName 167 activityName: activityName
168 }).then((result) => { 168 }).then((result) => {
@@ -178,7 +178,7 @@ exports.receiveCoupons = (req, res, next) => { @@ -178,7 +178,7 @@ exports.receiveCoupons = (req, res, next) => {
178 let shareUid = req.query.shareUid; 178 let shareUid = req.query.shareUid;
179 let openId = req.query.openId; 179 let openId = req.query.openId;
180 180
181 - inviteModel.receiveCoupons({ 181 + req.ctx(inviteModel).receiveCoupons({
182 uid: uid, 182 uid: uid,
183 activityId: actId, 183 activityId: actId,
184 nums: nums, 184 nums: nums,
@@ -209,7 +209,7 @@ exports.myCoupons = (req, res, next) => { @@ -209,7 +209,7 @@ exports.myCoupons = (req, res, next) => {
209 return false; 209 return false;
210 } 210 }
211 211
212 - inviteModel.myCoupons({ 212 + req.ctx(inviteModel).myCoupons({
213 uid: uid, 213 uid: uid,
214 shareUid: shareUid, 214 shareUid: shareUid,
215 nums: nums, 215 nums: nums,
@@ -250,7 +250,7 @@ exports.getwxinfo = (req, res, next) => { @@ -250,7 +250,7 @@ exports.getwxinfo = (req, res, next) => {
250 let url = req.query.url; 250 let url = req.query.url;
251 let code = req.query.code; 251 let code = req.query.code;
252 252
253 - inviteModel.getWxUserInfo({ 253 + req.ctx(inviteModel).getWxUserInfo({
254 code: code 254 code: code
255 }).then((result) => { 255 }).then((result) => {
256 if (result === false) { 256 if (result === false) {
@@ -11,10 +11,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -11,10 +11,7 @@ module.exports = class extends global.yoho.BaseModel {
11 return this.get({ 11 return this.get({
12 data: Object.assign({ 12 data: Object.assign({
13 method: 'app.activity.receviceYohoCoin' 13 method: 'app.activity.receviceYohoCoin'
14 - }, params),  
15 - param: {  
16 - cache: true  
17 - } 14 + }, params)
18 }); 15 });
19 } 16 }
20 }; 17 };
@@ -83,9 +83,6 @@ class featureModel extends global.yoho.BaseModel { @@ -83,9 +83,6 @@ class featureModel extends global.yoho.BaseModel {
83 data: { 83 data: {
84 method: 'app.activity.template.ignoreCache', 84 method: 'app.activity.template.ignoreCache',
85 activity_id: params.code 85 activity_id: params.code
86 - },  
87 - param: {  
88 - cache: true  
89 } 86 }
90 }); 87 });
91 } else { 88 } else {
1 'use strict'; 1 'use strict';
2 -const api = global.yoho.API;  
3 const serviceAPI = global.yoho.ServiceAPI; 2 const serviceAPI = global.yoho.ServiceAPI;
4 const _ = require('lodash'); 3 const _ = require('lodash');
5 const rp = require('request-promise'); 4 const rp = require('request-promise');
@@ -10,210 +9,227 @@ const wxCode = { @@ -10,210 +9,227 @@ const wxCode = {
10 wxAppSecret: 'ce21ae4a3f93852279175a167e54509b' 9 wxAppSecret: 'ce21ae4a3f93852279175a167e54509b'
11 }; 10 };
12 11
13 -/**  
14 - * 获取微信授权地址  
15 - * @param callback  
16 - * @returns {string}  
17 - */  
18 -const getWxOauthUrl = (callback) => {  
19 - return 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +  
20 - wxCode.wxAppId + '&redirect_uri=' + callback +  
21 - '&response_type=code&scope=snsapi_userinfo#wechat_redirect';  
22 -};  
23 -  
24 -/**  
25 - * 生成分享url  
26 - * @param shareUid  
27 - * @param actId  
28 - * @param nums  
29 - * @returns {string}  
30 - */  
31 -const createShareUrl = (shareUid, actId, nums) => {  
32 - return 'http://m.yohobuy.com/activity/invite/share_' + shareUid + '_' + actId + '_' + nums + '.html';  
33 -};  
34 -  
35 -/**  
36 - * 根据第三方id,查询绑定信息  
37 - * @param {[string || array]} openIds 第三方id数组  
38 - * @return {[array]}  
39 - */  
40 -const getBindLogByOpenId = (openIds) => {  
41 - openIds = _.isArray(openIds) ? openIds : [openIds];  
42 - return api.get('', {  
43 - method: 'wap.invite.getBindLogByOpenId',  
44 - openIds: openIds.join(',')  
45 - });  
46 -}; 12 +module.exports = class extends global.yoho.BaseModel {
  13 + constructor(ctx) {
  14 + super(ctx);
  15 + }
  16 +
  17 + /**
  18 + * 获取微信授权地址
  19 + * @param callback
  20 + * @returns {string}
  21 + */
  22 + getWxOauthUrl(callback) {
  23 + return 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
  24 + wxCode.wxAppId + '&redirect_uri=' + callback +
  25 + '&response_type=code&scope=snsapi_userinfo#wechat_redirect';
  26 + }
  27 +
  28 + /**
  29 + * 生成分享url
  30 + * @param shareUid
  31 + * @param actId
  32 + * @param nums
  33 + * @returns {string}
  34 + */
  35 + createShareUrl(shareUid, actId, nums) {
  36 + return 'http://m.yohobuy.com/activity/invite/share_' + shareUid + '_' + actId + '_' + nums + '.html';
  37 + }
  38 +
  39 + /**
  40 + * 根据第三方id,查询绑定信息
  41 + * @param {[string || array]} openIds 第三方id数组
  42 + * @return {[array]}
  43 + */
  44 + getBindLogByOpenId(openIds) {
  45 + openIds = _.isArray(openIds) ? openIds : [openIds];
  46 + return this.get({
  47 + data: {
  48 + method: 'wap.invite.getBindLogByOpenId',
  49 + openIds: openIds.join(',')
  50 + }
  51 + });
  52 + }
  53 +
  54 + /**
  55 + * 合并第三方头像和昵称
  56 + * @param {[array]} data 邀请的用户列表,最主要的是openId字段
  57 + * @return {[array]}
  58 + */
  59 + mergeBindLogDate(data) {
  60 + let openIds = [];
  61 + let photo = '//static.yohobuy.com/m/v1/activity/newyear/images/108.png';
  62 +
  63 + // 取5条
  64 + data = _.slice(data, 0, 5);
  65 +
  66 + _.forEach(data, (req) => {
  67 + openIds.push(req.openId);
  68 + });
47 69
48 -/**  
49 - * 合并第三方头像和昵称  
50 - * @param {[array]} data 邀请的用户列表,最主要的是openId字段  
51 - * @return {[array]}  
52 - */  
53 -const mergeBindLogDate = (data) => {  
54 - let openIds = [];  
55 - let photo = '//static.yohobuy.com/m/v1/activity/newyear/images/108.png';  
56 -  
57 - // 取5条  
58 - data = _.slice(data, 0, 5);  
59 -  
60 - _.forEach(data, (req) => {  
61 - openIds.push(req.openId);  
62 - });  
63 -  
64 - return getBindLogByOpenId(openIds).then(result => {  
65 - if (!_.isEmpty(result.data)) {  
66 - _.forEach(data, (req, key) => {  
67 - data[key].img = photo;  
68 - _.forEach(result.data, (bind) => {  
69 - if (req.openId === bind.openId) {  
70 - data[key].img = _.isEmpty(bind.snsHeadimg) ?  
71 - photo : bind.snsHeadimg;  
72 - data[key].nick = bind.snsNick;  
73 - } 70 + return this.getBindLogByOpenId(openIds).then(result => {
  71 + if (!_.isEmpty(result.data)) {
  72 + _.forEach(data, (req, key) => {
  73 + data[key].img = photo;
  74 + _.forEach(result.data, (bind) => {
  75 + if (req.openId === bind.openId) {
  76 + data[key].img = _.isEmpty(bind.snsHeadimg) ?
  77 + photo : bind.snsHeadimg;
  78 + data[key].nick = bind.snsNick;
  79 + }
  80 + });
74 }); 81 });
75 - });  
76 - }  
77 - return data;  
78 - });  
79 -}; 82 + }
  83 + return data;
  84 + });
  85 + }
  86 +
  87 + /**
  88 + * 获取分享页面列表数据
  89 + * @param {[int]} uid 用户id
  90 + * @param {[int]} activityId 活动id
  91 + * @return {[array]}
  92 + */
  93 + index(params) {
  94 + params = params || {};
  95 +
  96 + return this.get({
  97 + data: Object.assign({
  98 + method: 'wap.invite.index'
  99 + }, params)
  100 + }).then((result) => {
  101 + let firstData = {
  102 + isNil: false,
  103 + isEmpty: false,
  104 + isFive: false,
  105 + isGo: false,
  106 + remainData: ['', '', '', '', ''],
  107 + data: []
  108 + };
  109 +
  110 + switch (result.code) {
  111 + case 401:
  112 + // 没有分享记录
  113 + firstData.isNil = true;
  114 + break;
  115 + case 200:
  116 + return this.mergeBindLogDate(result.data).then(data => {
  117 + let len = data.length;
  118 +
  119 + // 判断是否否5条分享
  120 + result.data = data;
  121 +
  122 + if (len === 0) {
  123 + firstData.isEmpty = true;
  124 + } else if (len < 5) {
  125 + firstData.remainData =
  126 + _.slice(firstData.remainData, 0, 5 - len);
  127 + } else {
  128 + firstData.isFive = true;
  129 + firstData.remainData = [];
  130 + }
  131 +
  132 + return Object.assign(firstData, result);
  133 + });
  134 + default:
  135 + // 活动状态不正确
  136 + firstData.isGo = true;
  137 + break;
  138 + }
80 139
81 -/**  
82 - * 获取分享页面列表数据  
83 - * @param {[int]} uid 用户id  
84 - * @param {[int]} activityId 活动id  
85 - * @return {[array]}  
86 - */  
87 -const index = (params) => {  
88 - params = params || {};  
89 -  
90 - return api.get('', Object.assign({  
91 - method: 'wap.invite.index'  
92 - }, params  
93 - )).then((result) => { 140 + return Object.assign(firstData, result);
  141 + });
  142 + }
  143 +
  144 + /**
  145 + * 通过手机号发送验证码
  146 + * @param {[int]} area 区域,中国:86
  147 + * @param {[string]} mobile 手机号
  148 + * @return {[array]}
  149 + */
  150 + sendRegCodeToMobile(params) {
  151 + return this.get({
  152 + data: Object.assign({
  153 + method: 'app.register.sendRegCodeToMobile'
  154 + }, params)
  155 + });
  156 + }
  157 +
  158 + /**
  159 + * 发送已注册用户参与活动的优惠券
  160 + * @param {[string]} mobile 手机号
  161 + * @param {[int]} activityId 活动id
  162 + * @return {[array]}
  163 + */
  164 + checkOldUserCoupon(params) {
  165 + return this.get({
  166 + data: Object.assign({
  167 + method: 'wap.invite.checkOldUserCoupon'
  168 + }, params)
  169 + });
  170 + }
  171 +
  172 + /**
  173 + * 验证手机验证码是否正确
  174 + * @param {[int]} area 区域,中国:86
  175 + * @param {[string]} mobile 手机号
  176 + * @param {[int]} code 验证码
  177 + * @return {[array]}
  178 + */
  179 + validRegCode(params) {
  180 + return this.get({
  181 + data: Object.assign({
  182 + method: 'app.register.validRegCode'
  183 + }, params)
  184 + });
  185 + }
  186 +
  187 + /**
  188 + * 手机账号注册
  189 + * @param {[string]} mobile 手机号
  190 + * @param {[string]} activityName 活动名称
  191 + * @return {[array]}
  192 + */
  193 + register(params) {
  194 + return this.get({
  195 + data: Object.assign({
  196 + method: 'wap.invite.register'
  197 + }, params)
  198 + });
  199 + }
  200 +
  201 + /**
  202 + * 微信好友获取红包方法(即分享出去的地址)
  203 + * @param {[int]} uid 分享用户id
  204 + * @param {[int]} activityId 活动id
  205 + * @param {[int]} nums 发送优惠券的数量
  206 + * @param {[String]} openId 微信的union_id
  207 + * @param {[String]} nickName 微信昵称
  208 + * @param {[String]} headImgUrl 微信头像
  209 + * @returns {[array]}
  210 + */
  211 + shareModel(params) {
94 let firstData = { 212 let firstData = {
95 - isNil: false,  
96 isEmpty: false, 213 isEmpty: false,
97 isFive: false, 214 isFive: false,
98 isGo: false, 215 isGo: false,
99 remainData: ['', '', '', '', ''], 216 remainData: ['', '', '', '', ''],
100 data: [] 217 data: []
101 }; 218 };
102 -  
103 - switch (result.code) {  
104 - case 401:  
105 - // 没有分享记录  
106 - firstData.isNil = true;  
107 - break;  
108 - case 200:  
109 - return mergeBindLogDate(result.data).then(data => {  
110 - let len = data.length;  
111 -  
112 - // 判断是否否5条分享  
113 - result.data = data;  
114 -  
115 - if (len === 0) {  
116 - firstData.isEmpty = true;  
117 - } else if (len < 5) {  
118 - firstData.remainData =  
119 - _.slice(firstData.remainData, 0, 5 - len);  
120 - } else {  
121 - firstData.isFive = true;  
122 - firstData.remainData = [];  
123 - }  
124 -  
125 - return Object.assign(firstData, result);  
126 - });  
127 - default:  
128 - // 活动状态不正确  
129 - firstData.isGo = true;  
130 - break;  
131 - }  
132 -  
133 - return Object.assign(firstData, result);  
134 - });  
135 -};  
136 -  
137 -/**  
138 - * 通过手机号发送验证码  
139 - * @param {[int]} area 区域,中国:86  
140 - * @param {[string]} mobile 手机号  
141 - * @return {[array]}  
142 - */  
143 -const sendRegCodeToMobile = (params) => {  
144 - return api.get('', Object.assign({  
145 - method: 'app.register.sendRegCodeToMobile'  
146 - }, params));  
147 -};  
148 -  
149 -/**  
150 - * 发送已注册用户参与活动的优惠券  
151 - * @param {[string]} mobile 手机号  
152 - * @param {[int]} activityId 活动id  
153 - * @return {[array]}  
154 - */  
155 -const checkOldUserCoupon = (params) => {  
156 - return api.get('', Object.assign({  
157 - method: 'wap.invite.checkOldUserCoupon'  
158 - }, params));  
159 -};  
160 -  
161 -/**  
162 - * 验证手机验证码是否正确  
163 - * @param {[int]} area 区域,中国:86  
164 - * @param {[string]} mobile 手机号  
165 - * @param {[int]} code 验证码  
166 - * @return {[array]}  
167 - */  
168 -const validRegCode = (params) => {  
169 - return api.get('', Object.assign({  
170 - method: 'app.register.validRegCode'  
171 - }, params));  
172 -};  
173 -  
174 -/**  
175 - * 手机账号注册  
176 - * @param {[string]} mobile 手机号  
177 - * @param {[string]} activityName 活动名称  
178 - * @return {[array]}  
179 - */  
180 -const register = (params) => {  
181 - return api.get('', Object.assign({  
182 - method: 'wap.invite.register'  
183 - }, params));  
184 -};  
185 -  
186 -/**  
187 - * 微信好友获取红包方法(即分享出去的地址)  
188 - * @param {[int]} uid 分享用户id  
189 - * @param {[int]} activityId 活动id  
190 - * @param {[int]} nums 发送优惠券的数量  
191 - * @param {[String]} openId 微信的union_id  
192 - * @param {[String]} nickName 微信昵称  
193 - * @param {[String]} headImgUrl 微信头像  
194 - * @returns {[array]}  
195 - */  
196 -const shareModel = (params) => {  
197 - let firstData = {  
198 - isEmpty: false,  
199 - isFive: false,  
200 - isGo: false,  
201 - remainData: ['', '', '', '', ''],  
202 - data: []  
203 - };  
204 - let listData = [];  
205 -  
206 - // 这里面的逻辑就是获取第三方用户的头像和昵称,然后插入数据和更新数据  
207 - return api.get('', Object.assign({  
208 - method: 'wap.invite.share'  
209 - }, params))  
210 - .then((result) => { 219 + let listData = [];
  220 +
  221 + // 这里面的逻辑就是获取第三方用户的头像和昵称,然后插入数据和更新数据
  222 + return this.get({
  223 + data: Object.assign({
  224 + method: 'wap.invite.share'
  225 + }, params)
  226 + }).then((result) => {
211 // list为空,说明不是分享者本人 227 // list为空,说明不是分享者本人
212 if (result.code !== 200 || _.isEmpty(result.data.list)) { 228 if (result.code !== 200 || _.isEmpty(result.data.list)) {
213 return result; 229 return result;
214 } 230 }
215 231
216 - return mergeBindLogDate(result.data.list).then(data => { 232 + return this.mergeBindLogDate(result.data.list).then(data => {
217 let len = data.length; 233 let len = data.length;
218 234
219 // 判断是否满5条分享 235 // 判断是否满5条分享
@@ -237,134 +253,125 @@ const shareModel = (params) => { @@ -237,134 +253,125 @@ const shareModel = (params) => {
237 return result; 253 return result;
238 }); 254 });
239 }); 255 });
240 -}; 256 + }
  257 +
  258 + /**
  259 + * 邀请好友赢福利之后领取优惠券
  260 + * @param {[int]} uid 用户id
  261 + * @param {[int]} activityId 活动id
  262 + * @param {[int]} nums 发送优惠券的数量
  263 + * @param {[int]} shareUid 分享者的uid
  264 + * @param {[string]} openId 微信的union_id
  265 + * @returns {[array]}
  266 + */
  267 + receiveCoupons(params) {
  268 + return this.get({
  269 + data: Object.assign({
  270 + method: 'wap.invite.receiveCoupons'
  271 + }, params)
  272 + });
  273 + }
  274 +
  275 + /**
  276 + * 获取分享列表和用户信息
  277 + * @param {[int]} uid 用户id
  278 + * @param {[int]} shareUid 分享着uid
  279 + * @param {[int]} nums 发送优惠券的数量
  280 + * @param {[int]} amount 金额
  281 + * @param {[int]} activityId 活动id
  282 + * @return {[array]}
  283 + */
  284 + myCoupons(params) {
  285 + let mobile;
  286 + let firstData = {
  287 + isEmpty: false,
  288 + isFive: false,
  289 + isGo: false,
  290 + remainData: ['', '', '', '', ''],
  291 + data: []
  292 + };
  293 + let listData = [];
241 294
242 -/**  
243 - * 邀请好友赢福利之后领取优惠券  
244 - * @param {[int]} uid 用户id  
245 - * @param {[int]} activityId 活动id  
246 - * @param {[int]} nums 发送优惠券的数量  
247 - * @param {[int]} shareUid 分享者的uid  
248 - * @param {[string]} openId 微信的union_id  
249 - * @returns {[array]}  
250 - */  
251 -const receiveCoupons = (params) => {  
252 - return api.get('', Object.assign({  
253 - method: 'wap.invite.receiveCoupons'  
254 - }, params));  
255 -}; 295 + return this.get({
  296 + data: Object.assign({
  297 + method: 'wap.invite.myCoupons'
  298 + }, params)
  299 + }).then((result) => {
256 300
257 -/**  
258 - * 获取分享列表和用户信息  
259 - * @param {[int]} uid 用户id  
260 - * @param {[int]} shareUid 分享着uid  
261 - * @param {[int]} nums 发送优惠券的数量  
262 - * @param {[int]} amount 金额  
263 - * @param {[int]} activityId 活动id  
264 - * @return {[array]}  
265 - */  
266 -const myCoupons = (params) => {  
267 - let mobile;  
268 - let firstData = {  
269 - isEmpty: false,  
270 - isFive: false,  
271 - isGo: false,  
272 - remainData: ['', '', '', '', ''],  
273 - data: []  
274 - };  
275 - let listData = [];  
276 -  
277 - return api.get('', Object.assign({  
278 - method: 'wap.invite.myCoupons'  
279 - }, params)).then((result) => {  
280 -  
281 - if (result.code !== 200) {  
282 - return result;  
283 - }  
284 -  
285 - return mergeBindLogDate(result.data.list).then(data => {  
286 - listData = data;  
287 -  
288 - if (listData.length < 5) {  
289 - firstData.remainData =  
290 - _.slice(firstData.remainData, 0, 5 - listData.length);  
291 - } else {  
292 - firstData.isFive = true;  
293 - firstData.remainData = []; 301 + if (result.code !== 200) {
  302 + return result;
294 } 303 }
295 304
296 - firstData.data = listData;  
297 - result.data.list = firstData; 305 + return this.mergeBindLogDate(result.data.list).then(data => {
  306 + listData = data;
298 307
299 - mobile = result.data.myProfile.mobile;  
300 - result.data.myProfile.encMobile = mobile.replace(mobile.substring(3, 7), '****'); 308 + if (listData.length < 5) {
  309 + firstData.remainData =
  310 + _.slice(firstData.remainData, 0, 5 - listData.length);
  311 + } else {
  312 + firstData.isFive = true;
  313 + firstData.remainData = [];
  314 + }
301 315
302 - // 释放内存  
303 - listData = [];  
304 - return [result.data.list, result.data.myProfile];  
305 - });  
306 - });  
307 -}; 316 + firstData.data = listData;
  317 + result.data.list = firstData;
308 318
309 -/**  
310 - * 授权后获取微信用户信息  
311 - * @return {[array]}  
312 - */  
313 -const getWxUserInfo = (params) => {  
314 - let url1 = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' +  
315 - wxCode.wxAppId + '&secret=' + wxCode.wxAppSecret + '&code=' +  
316 - params.code + '&grant_type=authorization_code';  
317 - let url2 = 'https://api.weixin.qq.com/sns/userinfo?lang=zh_CN';  
318 -  
319 - return rp({  
320 - url: url1,  
321 - qs: {},  
322 - json: true,  
323 - gzip: true,  
324 - timeout: 3000  
325 - }).then((result) => {  
326 - if (_.isEmpty(result.openid)) {  
327 - return false;  
328 - }  
329 -  
330 - url2 = url2 + '&access_token=' + result.access_token +  
331 - '&openid=' + result.openid; 319 + mobile = result.data.myProfile.mobile;
  320 + result.data.myProfile.encMobile = mobile.replace(mobile.substring(3, 7), '****');
  321 +
  322 + // 释放内存
  323 + listData = [];
  324 + return [result.data.list, result.data.myProfile];
  325 + });
  326 + });
  327 + }
  328 +
  329 + /**
  330 + * 授权后获取微信用户信息
  331 + * @return {[array]}
  332 + */
  333 + getWxUserInfo(params) {
  334 + let url1 = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' +
  335 + wxCode.wxAppId + '&secret=' + wxCode.wxAppSecret + '&code=' +
  336 + params.code + '&grant_type=authorization_code';
  337 + let url2 = 'https://api.weixin.qq.com/sns/userinfo?lang=zh_CN';
332 338
333 return rp({ 339 return rp({
334 - url: url2, 340 + url: url1,
335 qs: {}, 341 qs: {},
336 json: true, 342 json: true,
337 gzip: true, 343 gzip: true,
338 timeout: 3000 344 timeout: 3000
339 - }).then((result2) => {  
340 - return result2;  
341 - });  
342 - });  
343 -};  
344 -  
345 -/**  
346 - * 获取 邀请好友赢福利的类型:  
347 - * 1. 普通的要求好友赢福利  
348 - * 2. 会员日的邀请好友 赢福利  
349 - */  
350 -const checkType = () => {  
351 - const url = '/activity/UserdaySigninController/isUserday';  
352 -  
353 - return serviceAPI.get(url, {});  
354 -}; 345 + }).then((result) => {
  346 + if (_.isEmpty(result.openid)) {
  347 + return false;
  348 + }
355 349
356 -module.exports = {  
357 - index,  
358 - checkType,  
359 - shareModel,  
360 - getBindLogByOpenId,  
361 - sendRegCodeToMobile,  
362 - checkOldUserCoupon,  
363 - validRegCode,  
364 - register,  
365 - receiveCoupons,  
366 - myCoupons,  
367 - createShareUrl,  
368 - getWxOauthUrl,  
369 - getWxUserInfo 350 + url2 = url2 + '&access_token=' + result.access_token +
  351 + '&openid=' + result.openid;
  352 +
  353 + return rp({
  354 + url: url2,
  355 + qs: {},
  356 + json: true,
  357 + gzip: true,
  358 + timeout: 3000
  359 + }).then((result2) => {
  360 + return result2;
  361 + });
  362 + });
  363 + }
  364 +
  365 + /**
  366 + * 获取 邀请好友赢福利的类型:
  367 + * 1. 普通的要求好友赢福利
  368 + * 2. 会员日的邀请好友 赢福利
  369 + */
  370 + checkType() {
  371 + return this.get({
  372 + api: serviceAPI,
  373 + url: '/activity/UserdaySigninController/isUserday',
  374 + data: {}
  375 + });
  376 + }
370 }; 377 };