Authored by 郝肖肖

'promotion-ctx'

@@ -8,10 +8,8 @@ @@ -8,10 +8,8 @@
8 8
9 const headerModel = require('../../../doraemon/models/header'); // 头部model 9 const headerModel = require('../../../doraemon/models/header'); // 头部model
10 const indexModel = require('../models/promotion'); 10 const indexModel = require('../models/promotion');
11 -const api = global.yoho.API;  
12 11
13 exports.index = (req, res, next) => { 12 exports.index = (req, res, next) => {
14 -  
15 let responseData = { 13 let responseData = {
16 pageHeader: headerModel.setNav({ 14 pageHeader: headerModel.setNav({
17 navTitle: '邀请同学认证送大礼', 15 navTitle: '邀请同学认证送大礼',
@@ -29,75 +27,54 @@ exports.index = (req, res, next) => { @@ -29,75 +27,54 @@ exports.index = (req, res, next) => {
29 shareUid: req.query.userUid 27 shareUid: req.query.userUid
30 }; 28 };
31 29
32 - indexModel.index(params).then(result => { 30 + req.ctx(indexModel).index(params).then(result => {
33 res.render('promotion', Object.assign(responseData, result)); 31 res.render('promotion', Object.assign(responseData, result));
34 }).catch(next); 32 }).catch(next);
35 33
36 }; 34 };
37 35
38 -// 获取学校省份列表  
39 -const getProvince = () => {  
40 - return api.get('', {  
41 - method: 'app.studentMarket.getAddressList'  
42 - }, {  
43 - cache: true  
44 - });  
45 -};  
46 -  
47 exports.province = (req, res, next) => { 36 exports.province = (req, res, next) => {
48 - getProvince().then((result) => { 37 + req.ctx(indexModel).getProvince().then((result) => {
49 res.json(result); 38 res.json(result);
50 }).catch(next); 39 }).catch(next);
51 }; 40 };
52 41
53 -// 获取学校列表  
54 -const getSchool = code => {  
55 - return api.get('', {  
56 - method: 'app.studentMarket.getSchoolInfoList',  
57 - areaCode: code  
58 - });  
59 -};  
60 -  
61 exports.school = (req, res, next) => { 42 exports.school = (req, res, next) => {
62 -  
63 let code = req.query.code; 43 let code = req.query.code;
64 44
65 - getSchool(code).then((result) => { 45 + req.ctx(indexModel).getSchool(code).then((result) => {
66 res.json(result); 46 res.json(result);
67 }).catch(next); 47 }).catch(next);
68 }; 48 };
69 49
70 exports.checkStudent = (req, res, next) => { 50 exports.checkStudent = (req, res, next) => {
71 -  
72 let params = { 51 let params = {
73 uid: req.user.uid || req.query.uid, 52 uid: req.user.uid || req.query.uid,
74 }; 53 };
75 54
76 - indexModel.checkStudent(params).then((result) => { 55 + req.ctx(indexModel).checkStudent(params).then((result) => {
77 res.json(result); 56 res.json(result);
78 }).catch(next); 57 }).catch(next);
79 }; 58 };
80 59
81 exports.schoolNum = (req, res, next) => { 60 exports.schoolNum = (req, res, next) => {
82 -  
83 let params = { 61 let params = {
84 schoolName: req.query.college_name 62 schoolName: req.query.college_name
85 }; 63 };
86 64
87 - indexModel.getSchoolNum(params).then(result => { 65 + req.ctx(indexModel).getSchoolNum(params).then(result => {
88 res.json(result); 66 res.json(result);
89 }).catch(next); 67 }).catch(next);
90 68
91 }; 69 };
92 70
93 exports.addStudent = (req, res, next) => { 71 exports.addStudent = (req, res, next) => {
94 -  
95 let params = { 72 let params = {
96 uid: req.query.userUid, 73 uid: req.query.userUid,
97 shareUid: req.query.shareUid 74 shareUid: req.query.shareUid
98 }; 75 };
99 76
100 - indexModel.addStudent(params).then(result => { 77 + req.ctx(indexModel).addStudent(params).then(result => {
101 res.json(result); 78 res.json(result);
102 }).catch(next); 79 }).catch(next);
103 80
@@ -111,7 +88,7 @@ exports.moreGoods = (req, res, next) => { @@ -111,7 +88,7 @@ exports.moreGoods = (req, res, next) => {
111 isApp: req.yoho.isApp 88 isApp: req.yoho.isApp
112 }; 89 };
113 90
114 - indexModel.moreGoods(params).then((result) => { 91 + req.ctx(indexModel).moreGoods(params).then((result) => {
115 res.json(result); 92 res.json(result);
116 }).catch(next); 93 }).catch(next);
117 }; 94 };
@@ -5,299 +5,344 @@ @@ -5,299 +5,344 @@
5 */ 5 */
6 6
7 'use strict'; 7 'use strict';
8 -const service = global.yoho.ServiceAPI;  
9 -const api = global.yoho.API; 8 +const serviceAPI = global.yoho.ServiceAPI;
10 const _ = require('lodash'); 9 const _ = require('lodash');
11 const helpers = global.yoho.helpers; 10 const helpers = global.yoho.helpers;
12 const utils = '../../../utils'; 11 const utils = '../../../utils';
13 const productProcess = require(`${utils}/product-process`); 12 const productProcess = require(`${utils}/product-process`);
14 13
  14 +module.exports = class extends global.yoho.BaseModel {
  15 + constructor(ctx) {
  16 + super(ctx);
  17 + }
15 18
16 -// 获取学生个人信息  
17 -const _studentInfo = (params) => {  
18 - return api.get('', {  
19 - method: 'app.passport.getUserBase',  
20 - uid: params.shareUid  
21 - }, {code: 200});  
22 -}; 19 + // 获取学校省份列表
  20 + getProvince() {
  21 + return this.get({
  22 + data: {
  23 + method: 'app.studentMarket.getAddressList'
  24 + },
  25 + param: {
  26 + cache: true
  27 + }
  28 + });
  29 + }
23 30
24 -// 判断哪个学校认证的  
25 -const _getCollege = (params) => {  
26 - return api.get('', {  
27 - method: 'app.student.getCollegeByUid',  
28 - uid: params.uid  
29 - }, {code: 200});  
30 -}; 31 + // 获取学校列表
  32 + getSchool(code) {
  33 + return this.get({
  34 + data: {
  35 + method: 'app.studentMarket.getSchoolInfoList',
  36 + areaCode: code
  37 + }
  38 + });
  39 + }
31 40
32 -const checkStudent = (params) => {  
33 - return api.get('', {  
34 - method: 'app.student.checkIsStudent',  
35 - uid: params.uid  
36 - }).then(result => { 41 + // 获取学生个人信息
  42 + _studentInfo(params) {
  43 + return this.get({
  44 + data: {
  45 + method: 'app.passport.getUserBase',
  46 + uid: params.shareUid
  47 + },
  48 + param: {
  49 + code: 200
  50 + }
  51 + });
  52 + }
37 53
38 - let resu = {}; 54 + // 判断哪个学校认证的
  55 + _getCollege(params) {
  56 + return this.get({
  57 + data: {
  58 + method: 'app.student.getCollegeByUid',
  59 + uid: params.uid
  60 + },
  61 + param: {
  62 + code: 200
  63 + }
  64 + });
  65 + }
39 66
40 - if (result && result.data) {  
41 - resu = result.data.isStudent;  
42 - } 67 + checkStudent(params) {
  68 + return this.get({
  69 + data: {
  70 + method: 'app.student.checkIsStudent',
  71 + uid: params.uid
  72 + }
  73 + }).then(result => {
  74 + let resu = {};
43 75
44 - return resu; 76 + if (result && result.data) {
  77 + resu = result.data.isStudent;
  78 + }
45 79
46 - });  
47 -}; 80 + return resu;
48 81
49 -const moreGoods = (params) => {  
50 - let apiData = {  
51 - method: 'app.student.vip',  
52 - uid: params.uid,  
53 - limit: params.limit,  
54 - page: params.page  
55 - };  
56 -  
57 - if (params.uid === 0) {  
58 - Object.assign(apiData, {  
59 - order: 's_n_desc'  
60 }); 82 });
61 } 83 }
62 - return api.get('', apiData, {code: 200}).then(result => {  
63 - let resu = {  
64 - goods: [] 84 +
  85 + moreGoods(params) {
  86 + let apiData = {
  87 + method: 'app.student.vip',
  88 + uid: params.uid,
  89 + limit: params.limit,
  90 + page: params.page
65 }; 91 };
66 92
67 - if (result && result.code === 200 && result.data.product_list) {  
68 - resu.goods = productProcess.processProductList(result.data.product_list, {isApp: params.isApp});  
69 - } else {  
70 - return ''; 93 + if (params.uid === 0) {
  94 + Object.assign(apiData, {
  95 + order: 's_n_desc'
  96 + });
71 } 97 }
72 98
73 - return resu;  
74 - });  
75 -};  
76 -  
77 -// 获取学生状态  
78 -const _studentState = (params) => {  
79 -  
80 - let resu = {  
81 - studentState: {}  
82 - };  
83 -  
84 - // 未登录状态  
85 - if (!params.uid) {  
86 - resu.studentState = {  
87 - unLogin: true  
88 - };  
89 - return resu;  
90 - } else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') {  
91 - // 已登录,为分享链接,验证是否已认证  
92 - return service.all([  
93 - _studentInfo(params),  
94 - checkStudent(params),  
95 - _getCollege(params)  
96 - ]).then(result => {  
97 - if (result && result[1] === 1) {  
98 - resu.studentState = {  
99 - reg: true  
100 - };  
101 -  
102 - if (result[2] && result[2].data) {  
103 - resu = Object.assign(resu, {schoolName: result[2].data.collegeName || '您认证时未选择学校'});  
104 - }  
105 - } else if (result && result[0] && result[0].data) {  
106 - resu.studentState = {  
107 - shareName: result[0].data.nickname || ''  
108 - }; 99 + return this.get({
  100 + data: apiData,
  101 + param: {
  102 + code: 200
109 } 103 }
  104 + }).then(result => {
  105 + let resu = {
  106 + goods: []
  107 + };
110 108
111 - return resu;  
112 - });  
113 - } else {  
114 - // 已登录,为原链接,验证是否已认证  
115 - return service.all([  
116 - _getCollege(params),  
117 - checkStudent(params)  
118 - ]).then(result => {  
119 -  
120 - // 已认证  
121 - if (result && result[1] === 1) {  
122 - resu.studentState = {  
123 - reg: true  
124 - };  
125 - if (result[0] && result[0].data) {  
126 - resu = Object.assign(resu, {schoolName: result[0].data.collegeName || '您认证时未选择学校'});  
127 - } 109 + if (result && result.code === 200 && result.data.product_list) {
  110 + resu.goods = productProcess.processProductList(result.data.product_list, {isApp: params.isApp});
128 } else { 111 } else {
129 - // 未认证  
130 - resu.studentState = {  
131 - unReg: true  
132 - }; 112 + return '';
133 } 113 }
  114 +
134 return resu; 115 return resu;
135 }); 116 });
136 } 117 }
137 -};  
138 118
139 -// 获取学生认证总数  
140 -const _studentTotal = () => {  
141 - return api.get('', {  
142 - method: 'app.student.verifiedStudentTotal'  
143 - });  
144 -}; 119 + // 获取学生状态
  120 + _studentState(params) {
  121 + let resu = {
  122 + studentState: {}
  123 + };
145 124
146 -// 获取学校认证总数  
147 -const _schoolTotal = () => {  
148 - return api.get('', {  
149 - method: 'app.student.getCollegeTotal'  
150 - });  
151 -}; 125 + // 未登录状态
  126 + if (!params.uid) {
  127 + resu.studentState = {
  128 + unLogin: true
  129 + };
  130 + return resu;
  131 + } else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') {
  132 + // 已登录,为分享链接,验证是否已认证
  133 + return Promise.all([
  134 + this._studentInfo(params),
  135 + this.checkStudent(params),
  136 + this._getCollege(params)
  137 + ]).then(result => {
  138 + if (result && result[1] === 1) {
  139 + resu.studentState = {
  140 + reg: true
  141 + };
  142 +
  143 + if (result[2] && result[2].data) {
  144 + resu = Object.assign(resu, {schoolName: result[2].data.collegeName || '您认证时未选择学校'});
  145 + }
  146 + } else if (result && result[0] && result[0].data) {
  147 + resu.studentState = {
  148 + shareName: result[0].data.nickname || ''
  149 + };
  150 + }
152 151
153 -// 资源位  
154 -const _resource = () => {  
155 - return service.get('/operations/api/v5/resource/get', {  
156 - content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad',  
157 - });  
158 -}; 152 + return resu;
  153 + });
  154 + } else {
  155 + // 已登录,为原链接,验证是否已认证
  156 + return Promise.all([
  157 + this._getCollege(params),
  158 + this.checkStudent(params)
  159 + ]).then(result => {
  160 +
  161 + // 已认证
  162 + if (result && result[1] === 1) {
  163 + resu.studentState = {
  164 + reg: true
  165 + };
  166 + if (result[0] && result[0].data) {
  167 + resu = Object.assign(resu, {schoolName: result[0].data.collegeName || '您认证时未选择学校'});
  168 + }
  169 + } else {
  170 + // 未认证
  171 + resu.studentState = {
  172 + unReg: true
  173 + };
  174 + }
  175 + return resu;
  176 + });
  177 + }
  178 + }
159 179
160 -// 获取分享记录  
161 -const _shareLog = (params) => { 180 + // 获取学生认证总数
  181 + _studentTotal() {
  182 + return this.get({
  183 + data: {
  184 + method: 'app.student.verifiedStudentTotal'
  185 + }
  186 + });
  187 + }
162 188
163 - if (params.uid) {  
164 - return api.get('', {  
165 - method: 'app.student.getShareLog',  
166 - shareUid: params.uid 189 + // 获取学校认证总数
  190 + _schoolTotal() {
  191 + return this.get({
  192 + data: {
  193 + method: 'app.student.getCollegeTotal'
  194 + }
167 }); 195 });
168 - } else {  
169 - let resu = ''; 196 + }
170 197
171 - return Promise.resolve(resu); 198 + // 资源位
  199 + _resource() {
  200 + return this.get({
  201 + api: serviceAPI,
  202 + url: '/operations/api/v5/resource/get',
  203 + data: {
  204 + content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad',
  205 + }
  206 + });
172 } 207 }
173 208
174 -}; 209 + // 获取分享记录
  210 + _shareLog(params) {
175 211
176 -// 获取学校认证人数  
177 -const getSchoolNum = (params) => {  
178 - return api.get('', {  
179 - method: 'app.student.verifiedStudentTotalByCollege',  
180 - college_name: params.schoolName  
181 - }, {  
182 - cache: true,  
183 - code: 200  
184 - }).then(result => {  
185 -  
186 - let obj = {  
187 - num: result.data,  
188 - name: params.schoolName  
189 - }; 212 + if (params.uid) {
  213 + return this.get({
  214 + data: {
  215 + method: 'app.student.getShareLog',
  216 + shareUid: params.uid
  217 + }
  218 + });
  219 + } else {
  220 + let resu = '';
190 221
191 - result.data = obj; 222 + return Promise.resolve(resu);
  223 + }
192 224
193 - return result;  
194 - });  
195 -}; 225 + }
196 226
197 -const index = (params) => {  
198 - return service.all([  
199 - _studentTotal(),  
200 - _schoolTotal(),  
201 - _shareLog(params),  
202 - _studentState(params),  
203 - _resource(),  
204 - ]).then(result => { 227 + // 获取学校认证人数
  228 + getSchoolNum(params) {
  229 + return this.get({
  230 + data: {
  231 + method: 'app.student.verifiedStudentTotalByCollege',
  232 + college_name: params.schoolName
  233 + },
  234 + param: {
  235 + cache: true,
  236 + code: 200
  237 + }
  238 + }).then(result => {
  239 + let obj = {
  240 + num: result.data,
  241 + name: params.schoolName
  242 + };
205 243
206 - let resu = {  
207 - shareLog: [],  
208 - picList: [],  
209 - uid: params.uid  
210 - }; 244 + result.data = obj;
211 245
212 - if (result && result[0] && result[0].data) { 246 + return result;
  247 + });
  248 + }
213 249
214 - let studentArr = result[0].data.toString().split(''); 250 + index(params) {
  251 + return Promise.all([
  252 + this._studentTotal(),
  253 + this._schoolTotal(),
  254 + this._shareLog(params),
  255 + this._studentState(params),
  256 + this._resource(),
  257 + ]).then(result => {
  258 + let resu = {
  259 + shareLog: [],
  260 + picList: [],
  261 + uid: params.uid
  262 + };
215 263
216 - resu = Object.assign(resu, {studentArr});  
217 - } 264 + if (result && result[0] && result[0].data) {
218 265
219 - if (result && result[1] && result[1].data) { 266 + let studentArr = result[0].data.toString().split('');
220 267
221 - resu = Object.assign(resu, {totalSchool: result[1].data});  
222 - } 268 + resu = Object.assign(resu, {studentArr});
  269 + }
223 270
224 - let obj = {}; 271 + if (result && result[1] && result[1].data) {
225 272
226 - if (result && result[2] && result[2].data) { 273 + resu = Object.assign(resu, {totalSchool: result[1].data});
  274 + }
227 275
228 - _.forEach(result[2].data, function(val) { 276 + let obj = {};
229 277
230 - obj = {  
231 - reward: val.reward || '',  
232 - createTime: helpers.dateFormat('YYYY.MM.DD', val.create_time),  
233 - nickName: val.nickName  
234 - }; 278 + if (result && result[2] && result[2].data) {
235 279
236 - resu.shareLog.push(obj); 280 + _.forEach(result[2].data, function(val) {
237 281
238 - }); 282 + obj = {
  283 + reward: val.reward || '',
  284 + createTime: helpers.dateFormat('YYYY.MM.DD', val.create_time),
  285 + nickName: val.nickName
  286 + };
239 287
240 - } 288 + resu.shareLog.push(obj);
241 289
242 - if (result && result[3]) { 290 + });
243 291
244 - resu = Object.assign(resu, result[3]);  
245 - } 292 + }
246 293
247 - // 图片可配,调用资源位  
248 - if (result && result[4] && result[4].data && result[4].data[0] && result[4].data[0].data) {  
249 -  
250 - let pList = result[4].data[0].data;  
251 -  
252 - resu.picList = {  
253 - bannerPic: helpers.image(pList[0].src, 750, 701),  
254 - title1: helpers.image(pList[9].src, 750, 114),  
255 - title2: helpers.image(pList[12].src, 750, 114),  
256 - title3: helpers.image(pList[14].src, 750, 114),  
257 - title4: helpers.image(pList[15].src, 750, 114),  
258 - pri1: helpers.image(pList[1].src, 345, 154),  
259 - pri2: helpers.image(pList[3].src, 345, 154),  
260 - pri3: helpers.image(pList[5].src, 345, 154),  
261 - pri4: helpers.image(pList[7].src, 345, 154),  
262 - act1: {  
263 - src: helpers.image(pList[10].src, 375, 444),  
264 - url: pList[10].url  
265 - },  
266 - act2: {  
267 - src: helpers.image(pList[11].src, 375, 444),  
268 - url: pList[11].url  
269 - },  
270 - invite: helpers.image(pList[16].src, 750, 444),  
271 - dia1: {  
272 - src: helpers.image(pList[2].src, 560, 567),  
273 - url: pList[2].url  
274 - },  
275 - dia2: {  
276 - src: helpers.image(pList[4].src, 560, 567),  
277 - url: pList[4].url  
278 - },  
279 - dia3: {  
280 - src: helpers.image(pList[6].src, 560, 697),  
281 - url: pList[6].url  
282 - },  
283 - dia4: {  
284 - src: helpers.image(pList[8].src, 560, 488),  
285 - url: pList[8].url  
286 - },  
287 - dia5: {  
288 - src: helpers.image(pList[13].src, 560, 416),  
289 - url: pList[13].url  
290 - },  
291 - };  
292 - }  
293 - return resu;  
294 - }); 294 + if (result && result[3]) {
295 295
296 -}; 296 + resu = Object.assign(resu, result[3]);
  297 + }
297 298
298 -module.exports = {  
299 - index,  
300 - getSchoolNum,  
301 - checkStudent,  
302 - moreGoods 299 + // 图片可配,调用资源位
  300 + if (result && result[4] && result[4].data && result[4].data[0] && result[4].data[0].data) {
  301 +
  302 + let pList = result[4].data[0].data;
  303 +
  304 + resu.picList = {
  305 + bannerPic: helpers.image(pList[0].src, 750, 701),
  306 + title1: helpers.image(pList[9].src, 750, 114),
  307 + title2: helpers.image(pList[12].src, 750, 114),
  308 + title3: helpers.image(pList[14].src, 750, 114),
  309 + title4: helpers.image(pList[15].src, 750, 114),
  310 + pri1: helpers.image(pList[1].src, 345, 154),
  311 + pri2: helpers.image(pList[3].src, 345, 154),
  312 + pri3: helpers.image(pList[5].src, 345, 154),
  313 + pri4: helpers.image(pList[7].src, 345, 154),
  314 + act1: {
  315 + src: helpers.image(pList[10].src, 375, 444),
  316 + url: pList[10].url
  317 + },
  318 + act2: {
  319 + src: helpers.image(pList[11].src, 375, 444),
  320 + url: pList[11].url
  321 + },
  322 + invite: helpers.image(pList[16].src, 750, 444),
  323 + dia1: {
  324 + src: helpers.image(pList[2].src, 560, 567),
  325 + url: pList[2].url
  326 + },
  327 + dia2: {
  328 + src: helpers.image(pList[4].src, 560, 567),
  329 + url: pList[4].url
  330 + },
  331 + dia3: {
  332 + src: helpers.image(pList[6].src, 560, 697),
  333 + url: pList[6].url
  334 + },
  335 + dia4: {
  336 + src: helpers.image(pList[8].src, 560, 488),
  337 + url: pList[8].url
  338 + },
  339 + dia5: {
  340 + src: helpers.image(pList[13].src, 560, 416),
  341 + url: pList[13].url
  342 + },
  343 + };
  344 + }
  345 + return resu;
  346 + });
  347 + }
303 }; 348 };