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,36 +5,72 @@ @@ -5,36 +5,72 @@
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 + }
  18 +
  19 + // 获取学校省份列表
  20 + getProvince() {
  21 + return this.get({
  22 + data: {
  23 + method: 'app.studentMarket.getAddressList'
  24 + },
  25 + param: {
  26 + cache: true
  27 + }
  28 + });
  29 + }
15 30
16 -// 获取学生个人信息  
17 -const _studentInfo = (params) => {  
18 - return api.get('', { 31 + // 获取学校列表
  32 + getSchool(code) {
  33 + return this.get({
  34 + data: {
  35 + method: 'app.studentMarket.getSchoolInfoList',
  36 + areaCode: code
  37 + }
  38 + });
  39 + }
  40 +
  41 + // 获取学生个人信息
  42 + _studentInfo(params) {
  43 + return this.get({
  44 + data: {
19 method: 'app.passport.getUserBase', 45 method: 'app.passport.getUserBase',
20 uid: params.shareUid 46 uid: params.shareUid
21 - }, {code: 200});  
22 -}; 47 + },
  48 + param: {
  49 + code: 200
  50 + }
  51 + });
  52 + }
23 53
24 -// 判断哪个学校认证的  
25 -const _getCollege = (params) => {  
26 - return api.get('', { 54 + // 判断哪个学校认证的
  55 + _getCollege(params) {
  56 + return this.get({
  57 + data: {
27 method: 'app.student.getCollegeByUid', 58 method: 'app.student.getCollegeByUid',
28 uid: params.uid 59 uid: params.uid
29 - }, {code: 200});  
30 -}; 60 + },
  61 + param: {
  62 + code: 200
  63 + }
  64 + });
  65 + }
31 66
32 -const checkStudent = (params) => {  
33 - return api.get('', { 67 + checkStudent(params) {
  68 + return this.get({
  69 + data: {
34 method: 'app.student.checkIsStudent', 70 method: 'app.student.checkIsStudent',
35 uid: params.uid 71 uid: params.uid
  72 + }
36 }).then(result => { 73 }).then(result => {
37 -  
38 let resu = {}; 74 let resu = {};
39 75
40 if (result && result.data) { 76 if (result && result.data) {
@@ -44,9 +80,9 @@ const checkStudent = (params) => { @@ -44,9 +80,9 @@ const checkStudent = (params) => {
44 return resu; 80 return resu;
45 81
46 }); 82 });
47 -}; 83 + }
48 84
49 -const moreGoods = (params) => { 85 + moreGoods(params) {
50 let apiData = { 86 let apiData = {
51 method: 'app.student.vip', 87 method: 'app.student.vip',
52 uid: params.uid, 88 uid: params.uid,
@@ -59,7 +95,13 @@ const moreGoods = (params) => { @@ -59,7 +95,13 @@ const moreGoods = (params) => {
59 order: 's_n_desc' 95 order: 's_n_desc'
60 }); 96 });
61 } 97 }
62 - return api.get('', apiData, {code: 200}).then(result => { 98 +
  99 + return this.get({
  100 + data: apiData,
  101 + param: {
  102 + code: 200
  103 + }
  104 + }).then(result => {
63 let resu = { 105 let resu = {
64 goods: [] 106 goods: []
65 }; 107 };
@@ -72,11 +114,10 @@ const moreGoods = (params) => { @@ -72,11 +114,10 @@ const moreGoods = (params) => {
72 114
73 return resu; 115 return resu;
74 }); 116 });
75 -};  
76 -  
77 -// 获取学生状态  
78 -const _studentState = (params) => { 117 + }
79 118
  119 + // 获取学生状态
  120 + _studentState(params) {
80 let resu = { 121 let resu = {
81 studentState: {} 122 studentState: {}
82 }; 123 };
@@ -89,10 +130,10 @@ const _studentState = (params) => { @@ -89,10 +130,10 @@ const _studentState = (params) => {
89 return resu; 130 return resu;
90 } else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') { 131 } else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') {
91 // 已登录,为分享链接,验证是否已认证 132 // 已登录,为分享链接,验证是否已认证
92 - return service.all([  
93 - _studentInfo(params),  
94 - checkStudent(params),  
95 - _getCollege(params) 133 + return Promise.all([
  134 + this._studentInfo(params),
  135 + this.checkStudent(params),
  136 + this._getCollege(params)
96 ]).then(result => { 137 ]).then(result => {
97 if (result && result[1] === 1) { 138 if (result && result[1] === 1) {
98 resu.studentState = { 139 resu.studentState = {
@@ -112,9 +153,9 @@ const _studentState = (params) => { @@ -112,9 +153,9 @@ const _studentState = (params) => {
112 }); 153 });
113 } else { 154 } else {
114 // 已登录,为原链接,验证是否已认证 155 // 已登录,为原链接,验证是否已认证
115 - return service.all([  
116 - _getCollege(params),  
117 - checkStudent(params) 156 + return Promise.all([
  157 + this._getCollege(params),
  158 + this.checkStudent(params)
118 ]).then(result => { 159 ]).then(result => {
119 160
120 // 已认证 161 // 已认证
@@ -134,36 +175,46 @@ const _studentState = (params) => { @@ -134,36 +175,46 @@ const _studentState = (params) => {
134 return resu; 175 return resu;
135 }); 176 });
136 } 177 }
137 -}; 178 + }
138 179
139 -// 获取学生认证总数  
140 -const _studentTotal = () => {  
141 - return api.get('', { 180 + // 获取学生认证总数
  181 + _studentTotal() {
  182 + return this.get({
  183 + data: {
142 method: 'app.student.verifiedStudentTotal' 184 method: 'app.student.verifiedStudentTotal'
  185 + }
143 }); 186 });
144 -}; 187 + }
145 188
146 -// 获取学校认证总数  
147 -const _schoolTotal = () => {  
148 - return api.get('', { 189 + // 获取学校认证总数
  190 + _schoolTotal() {
  191 + return this.get({
  192 + data: {
149 method: 'app.student.getCollegeTotal' 193 method: 'app.student.getCollegeTotal'
  194 + }
150 }); 195 });
151 -}; 196 + }
152 197
153 -// 资源位  
154 -const _resource = () => {  
155 - return service.get('/operations/api/v5/resource/get', { 198 + // 资源位
  199 + _resource() {
  200 + return this.get({
  201 + api: serviceAPI,
  202 + url: '/operations/api/v5/resource/get',
  203 + data: {
156 content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad', 204 content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad',
  205 + }
157 }); 206 });
158 -}; 207 + }
159 208
160 -// 获取分享记录  
161 -const _shareLog = (params) => { 209 + // 获取分享记录
  210 + _shareLog(params) {
162 211
163 if (params.uid) { 212 if (params.uid) {
164 - return api.get('', { 213 + return this.get({
  214 + data: {
165 method: 'app.student.getShareLog', 215 method: 'app.student.getShareLog',
166 shareUid: params.uid 216 shareUid: params.uid
  217 + }
167 }); 218 });
168 } else { 219 } else {
169 let resu = ''; 220 let resu = '';
@@ -171,18 +222,20 @@ const _shareLog = (params) => { @@ -171,18 +222,20 @@ const _shareLog = (params) => {
171 return Promise.resolve(resu); 222 return Promise.resolve(resu);
172 } 223 }
173 224
174 -}; 225 + }
175 226
176 -// 获取学校认证人数  
177 -const getSchoolNum = (params) => {  
178 - return api.get('', { 227 + // 获取学校认证人数
  228 + getSchoolNum(params) {
  229 + return this.get({
  230 + data: {
179 method: 'app.student.verifiedStudentTotalByCollege', 231 method: 'app.student.verifiedStudentTotalByCollege',
180 college_name: params.schoolName 232 college_name: params.schoolName
181 - }, { 233 + },
  234 + param: {
182 cache: true, 235 cache: true,
183 code: 200 236 code: 200
  237 + }
184 }).then(result => { 238 }).then(result => {
185 -  
186 let obj = { 239 let obj = {
187 num: result.data, 240 num: result.data,
188 name: params.schoolName 241 name: params.schoolName
@@ -192,17 +245,16 @@ const getSchoolNum = (params) => { @@ -192,17 +245,16 @@ const getSchoolNum = (params) => {
192 245
193 return result; 246 return result;
194 }); 247 });
195 -}; 248 + }
196 249
197 -const index = (params) => {  
198 - return service.all([  
199 - _studentTotal(),  
200 - _schoolTotal(),  
201 - _shareLog(params),  
202 - _studentState(params),  
203 - _resource(), 250 + index(params) {
  251 + return Promise.all([
  252 + this._studentTotal(),
  253 + this._schoolTotal(),
  254 + this._shareLog(params),
  255 + this._studentState(params),
  256 + this._resource(),
204 ]).then(result => { 257 ]).then(result => {
205 -  
206 let resu = { 258 let resu = {
207 shareLog: [], 259 shareLog: [],
208 picList: [], 260 picList: [],
@@ -292,12 +344,5 @@ const index = (params) => { @@ -292,12 +344,5 @@ const index = (params) => {
292 } 344 }
293 return resu; 345 return resu;
294 }); 346 });
295 -  
296 -};  
297 -  
298 -module.exports = {  
299 - index,  
300 - getSchoolNum,  
301 - checkStudent,  
302 - moreGoods 347 + }
303 }; 348 };