...
|
...
|
@@ -5,299 +5,344 @@ |
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
const service = global.yoho.ServiceAPI;
|
|
|
const api = global.yoho.API;
|
|
|
const serviceAPI = global.yoho.ServiceAPI;
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const utils = '../../../utils';
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
// 获取学生个人信息
|
|
|
const _studentInfo = (params) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.passport.getUserBase',
|
|
|
uid: params.shareUid
|
|
|
}, {code: 200});
|
|
|
};
|
|
|
// 获取学校省份列表
|
|
|
getProvince() {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.studentMarket.getAddressList'
|
|
|
},
|
|
|
param: {
|
|
|
cache: true
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 判断哪个学校认证的
|
|
|
const _getCollege = (params) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.getCollegeByUid',
|
|
|
uid: params.uid
|
|
|
}, {code: 200});
|
|
|
};
|
|
|
// 获取学校列表
|
|
|
getSchool(code) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.studentMarket.getSchoolInfoList',
|
|
|
areaCode: code
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
const checkStudent = (params) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.checkIsStudent',
|
|
|
uid: params.uid
|
|
|
}).then(result => {
|
|
|
// 获取学生个人信息
|
|
|
_studentInfo(params) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.passport.getUserBase',
|
|
|
uid: params.shareUid
|
|
|
},
|
|
|
param: {
|
|
|
code: 200
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let resu = {};
|
|
|
// 判断哪个学校认证的
|
|
|
_getCollege(params) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.getCollegeByUid',
|
|
|
uid: params.uid
|
|
|
},
|
|
|
param: {
|
|
|
code: 200
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (result && result.data) {
|
|
|
resu = result.data.isStudent;
|
|
|
}
|
|
|
checkStudent(params) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.checkIsStudent',
|
|
|
uid: params.uid
|
|
|
}
|
|
|
}).then(result => {
|
|
|
let resu = {};
|
|
|
|
|
|
return resu;
|
|
|
if (result && result.data) {
|
|
|
resu = result.data.isStudent;
|
|
|
}
|
|
|
|
|
|
});
|
|
|
};
|
|
|
return resu;
|
|
|
|
|
|
const moreGoods = (params) => {
|
|
|
let apiData = {
|
|
|
method: 'app.student.vip',
|
|
|
uid: params.uid,
|
|
|
limit: params.limit,
|
|
|
page: params.page
|
|
|
};
|
|
|
|
|
|
if (params.uid === 0) {
|
|
|
Object.assign(apiData, {
|
|
|
order: 's_n_desc'
|
|
|
});
|
|
|
}
|
|
|
return api.get('', apiData, {code: 200}).then(result => {
|
|
|
let resu = {
|
|
|
goods: []
|
|
|
|
|
|
moreGoods(params) {
|
|
|
let apiData = {
|
|
|
method: 'app.student.vip',
|
|
|
uid: params.uid,
|
|
|
limit: params.limit,
|
|
|
page: params.page
|
|
|
};
|
|
|
|
|
|
if (result && result.code === 200 && result.data.product_list) {
|
|
|
resu.goods = productProcess.processProductList(result.data.product_list, {isApp: params.isApp});
|
|
|
} else {
|
|
|
return '';
|
|
|
if (params.uid === 0) {
|
|
|
Object.assign(apiData, {
|
|
|
order: 's_n_desc'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return resu;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
// 获取学生状态
|
|
|
const _studentState = (params) => {
|
|
|
|
|
|
let resu = {
|
|
|
studentState: {}
|
|
|
};
|
|
|
|
|
|
// 未登录状态
|
|
|
if (!params.uid) {
|
|
|
resu.studentState = {
|
|
|
unLogin: true
|
|
|
};
|
|
|
return resu;
|
|
|
} else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') {
|
|
|
// 已登录,为分享链接,验证是否已认证
|
|
|
return service.all([
|
|
|
_studentInfo(params),
|
|
|
checkStudent(params),
|
|
|
_getCollege(params)
|
|
|
]).then(result => {
|
|
|
if (result && result[1] === 1) {
|
|
|
resu.studentState = {
|
|
|
reg: true
|
|
|
};
|
|
|
|
|
|
if (result[2] && result[2].data) {
|
|
|
resu = Object.assign(resu, {schoolName: result[2].data.collegeName || '您认证时未选择学校'});
|
|
|
}
|
|
|
} else if (result && result[0] && result[0].data) {
|
|
|
resu.studentState = {
|
|
|
shareName: result[0].data.nickname || ''
|
|
|
};
|
|
|
return this.get({
|
|
|
data: apiData,
|
|
|
param: {
|
|
|
code: 200
|
|
|
}
|
|
|
}).then(result => {
|
|
|
let resu = {
|
|
|
goods: []
|
|
|
};
|
|
|
|
|
|
return resu;
|
|
|
});
|
|
|
} else {
|
|
|
// 已登录,为原链接,验证是否已认证
|
|
|
return service.all([
|
|
|
_getCollege(params),
|
|
|
checkStudent(params)
|
|
|
]).then(result => {
|
|
|
|
|
|
// 已认证
|
|
|
if (result && result[1] === 1) {
|
|
|
resu.studentState = {
|
|
|
reg: true
|
|
|
};
|
|
|
if (result[0] && result[0].data) {
|
|
|
resu = Object.assign(resu, {schoolName: result[0].data.collegeName || '您认证时未选择学校'});
|
|
|
}
|
|
|
if (result && result.code === 200 && result.data.product_list) {
|
|
|
resu.goods = productProcess.processProductList(result.data.product_list, {isApp: params.isApp});
|
|
|
} else {
|
|
|
// 未认证
|
|
|
resu.studentState = {
|
|
|
unReg: true
|
|
|
};
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
return resu;
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 获取学生认证总数
|
|
|
const _studentTotal = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.verifiedStudentTotal'
|
|
|
});
|
|
|
};
|
|
|
// 获取学生状态
|
|
|
_studentState(params) {
|
|
|
let resu = {
|
|
|
studentState: {}
|
|
|
};
|
|
|
|
|
|
// 获取学校认证总数
|
|
|
const _schoolTotal = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.getCollegeTotal'
|
|
|
});
|
|
|
};
|
|
|
// 未登录状态
|
|
|
if (!params.uid) {
|
|
|
resu.studentState = {
|
|
|
unLogin: true
|
|
|
};
|
|
|
return resu;
|
|
|
} else if (params.shareUid !== 'undefined' && typeof params.shareUid !== 'undefined') {
|
|
|
// 已登录,为分享链接,验证是否已认证
|
|
|
return Promise.all([
|
|
|
this._studentInfo(params),
|
|
|
this.checkStudent(params),
|
|
|
this._getCollege(params)
|
|
|
]).then(result => {
|
|
|
if (result && result[1] === 1) {
|
|
|
resu.studentState = {
|
|
|
reg: true
|
|
|
};
|
|
|
|
|
|
if (result[2] && result[2].data) {
|
|
|
resu = Object.assign(resu, {schoolName: result[2].data.collegeName || '您认证时未选择学校'});
|
|
|
}
|
|
|
} else if (result && result[0] && result[0].data) {
|
|
|
resu.studentState = {
|
|
|
shareName: result[0].data.nickname || ''
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 资源位
|
|
|
const _resource = () => {
|
|
|
return service.get('/operations/api/v5/resource/get', {
|
|
|
content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad',
|
|
|
});
|
|
|
};
|
|
|
return resu;
|
|
|
});
|
|
|
} else {
|
|
|
// 已登录,为原链接,验证是否已认证
|
|
|
return Promise.all([
|
|
|
this._getCollege(params),
|
|
|
this.checkStudent(params)
|
|
|
]).then(result => {
|
|
|
|
|
|
// 已认证
|
|
|
if (result && result[1] === 1) {
|
|
|
resu.studentState = {
|
|
|
reg: true
|
|
|
};
|
|
|
if (result[0] && result[0].data) {
|
|
|
resu = Object.assign(resu, {schoolName: result[0].data.collegeName || '您认证时未选择学校'});
|
|
|
}
|
|
|
} else {
|
|
|
// 未认证
|
|
|
resu.studentState = {
|
|
|
unReg: true
|
|
|
};
|
|
|
}
|
|
|
return resu;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取分享记录
|
|
|
const _shareLog = (params) => {
|
|
|
// 获取学生认证总数
|
|
|
_studentTotal() {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.verifiedStudentTotal'
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (params.uid) {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.getShareLog',
|
|
|
shareUid: params.uid
|
|
|
// 获取学校认证总数
|
|
|
_schoolTotal() {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.getCollegeTotal'
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
let resu = '';
|
|
|
}
|
|
|
|
|
|
return Promise.resolve(resu);
|
|
|
// 资源位
|
|
|
_resource() {
|
|
|
return this.get({
|
|
|
api: serviceAPI,
|
|
|
url: '/operations/api/v5/resource/get',
|
|
|
data: {
|
|
|
content_code: '1cff7f47ca7057ef6ac00cbf2efc37ad',
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
};
|
|
|
// 获取分享记录
|
|
|
_shareLog(params) {
|
|
|
|
|
|
// 获取学校认证人数
|
|
|
const getSchoolNum = (params) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.student.verifiedStudentTotalByCollege',
|
|
|
college_name: params.schoolName
|
|
|
}, {
|
|
|
cache: true,
|
|
|
code: 200
|
|
|
}).then(result => {
|
|
|
|
|
|
let obj = {
|
|
|
num: result.data,
|
|
|
name: params.schoolName
|
|
|
};
|
|
|
if (params.uid) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.getShareLog',
|
|
|
shareUid: params.uid
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
let resu = '';
|
|
|
|
|
|
result.data = obj;
|
|
|
return Promise.resolve(resu);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const index = (params) => {
|
|
|
return service.all([
|
|
|
_studentTotal(),
|
|
|
_schoolTotal(),
|
|
|
_shareLog(params),
|
|
|
_studentState(params),
|
|
|
_resource(),
|
|
|
]).then(result => {
|
|
|
// 获取学校认证人数
|
|
|
getSchoolNum(params) {
|
|
|
return this.get({
|
|
|
data: {
|
|
|
method: 'app.student.verifiedStudentTotalByCollege',
|
|
|
college_name: params.schoolName
|
|
|
},
|
|
|
param: {
|
|
|
cache: true,
|
|
|
code: 200
|
|
|
}
|
|
|
}).then(result => {
|
|
|
let obj = {
|
|
|
num: result.data,
|
|
|
name: params.schoolName
|
|
|
};
|
|
|
|
|
|
let resu = {
|
|
|
shareLog: [],
|
|
|
picList: [],
|
|
|
uid: params.uid
|
|
|
};
|
|
|
result.data = obj;
|
|
|
|
|
|
if (result && result[0] && result[0].data) {
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let studentArr = result[0].data.toString().split('');
|
|
|
index(params) {
|
|
|
return Promise.all([
|
|
|
this._studentTotal(),
|
|
|
this._schoolTotal(),
|
|
|
this._shareLog(params),
|
|
|
this._studentState(params),
|
|
|
this._resource(),
|
|
|
]).then(result => {
|
|
|
let resu = {
|
|
|
shareLog: [],
|
|
|
picList: [],
|
|
|
uid: params.uid
|
|
|
};
|
|
|
|
|
|
resu = Object.assign(resu, {studentArr});
|
|
|
}
|
|
|
if (result && result[0] && result[0].data) {
|
|
|
|
|
|
if (result && result[1] && result[1].data) {
|
|
|
let studentArr = result[0].data.toString().split('');
|
|
|
|
|
|
resu = Object.assign(resu, {totalSchool: result[1].data});
|
|
|
}
|
|
|
resu = Object.assign(resu, {studentArr});
|
|
|
}
|
|
|
|
|
|
let obj = {};
|
|
|
if (result && result[1] && result[1].data) {
|
|
|
|
|
|
if (result && result[2] && result[2].data) {
|
|
|
resu = Object.assign(resu, {totalSchool: result[1].data});
|
|
|
}
|
|
|
|
|
|
_.forEach(result[2].data, function(val) {
|
|
|
let obj = {};
|
|
|
|
|
|
obj = {
|
|
|
reward: val.reward || '',
|
|
|
createTime: helpers.dateFormat('YYYY.MM.DD', val.create_time),
|
|
|
nickName: val.nickName
|
|
|
};
|
|
|
if (result && result[2] && result[2].data) {
|
|
|
|
|
|
resu.shareLog.push(obj);
|
|
|
_.forEach(result[2].data, function(val) {
|
|
|
|
|
|
});
|
|
|
obj = {
|
|
|
reward: val.reward || '',
|
|
|
createTime: helpers.dateFormat('YYYY.MM.DD', val.create_time),
|
|
|
nickName: val.nickName
|
|
|
};
|
|
|
|
|
|
}
|
|
|
resu.shareLog.push(obj);
|
|
|
|
|
|
if (result && result[3]) {
|
|
|
});
|
|
|
|
|
|
resu = Object.assign(resu, result[3]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 图片可配,调用资源位
|
|
|
if (result && result[4] && result[4].data && result[4].data[0] && result[4].data[0].data) {
|
|
|
|
|
|
let pList = result[4].data[0].data;
|
|
|
|
|
|
resu.picList = {
|
|
|
bannerPic: helpers.image(pList[0].src, 750, 701),
|
|
|
title1: helpers.image(pList[9].src, 750, 114),
|
|
|
title2: helpers.image(pList[12].src, 750, 114),
|
|
|
title3: helpers.image(pList[14].src, 750, 114),
|
|
|
title4: helpers.image(pList[15].src, 750, 114),
|
|
|
pri1: helpers.image(pList[1].src, 345, 154),
|
|
|
pri2: helpers.image(pList[3].src, 345, 154),
|
|
|
pri3: helpers.image(pList[5].src, 345, 154),
|
|
|
pri4: helpers.image(pList[7].src, 345, 154),
|
|
|
act1: {
|
|
|
src: helpers.image(pList[10].src, 375, 444),
|
|
|
url: pList[10].url
|
|
|
},
|
|
|
act2: {
|
|
|
src: helpers.image(pList[11].src, 375, 444),
|
|
|
url: pList[11].url
|
|
|
},
|
|
|
invite: helpers.image(pList[16].src, 750, 444),
|
|
|
dia1: {
|
|
|
src: helpers.image(pList[2].src, 560, 567),
|
|
|
url: pList[2].url
|
|
|
},
|
|
|
dia2: {
|
|
|
src: helpers.image(pList[4].src, 560, 567),
|
|
|
url: pList[4].url
|
|
|
},
|
|
|
dia3: {
|
|
|
src: helpers.image(pList[6].src, 560, 697),
|
|
|
url: pList[6].url
|
|
|
},
|
|
|
dia4: {
|
|
|
src: helpers.image(pList[8].src, 560, 488),
|
|
|
url: pList[8].url
|
|
|
},
|
|
|
dia5: {
|
|
|
src: helpers.image(pList[13].src, 560, 416),
|
|
|
url: pList[13].url
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
return resu;
|
|
|
});
|
|
|
if (result && result[3]) {
|
|
|
|
|
|
};
|
|
|
resu = Object.assign(resu, result[3]);
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
index,
|
|
|
getSchoolNum,
|
|
|
checkStudent,
|
|
|
moreGoods
|
|
|
// 图片可配,调用资源位
|
|
|
if (result && result[4] && result[4].data && result[4].data[0] && result[4].data[0].data) {
|
|
|
|
|
|
let pList = result[4].data[0].data;
|
|
|
|
|
|
resu.picList = {
|
|
|
bannerPic: helpers.image(pList[0].src, 750, 701),
|
|
|
title1: helpers.image(pList[9].src, 750, 114),
|
|
|
title2: helpers.image(pList[12].src, 750, 114),
|
|
|
title3: helpers.image(pList[14].src, 750, 114),
|
|
|
title4: helpers.image(pList[15].src, 750, 114),
|
|
|
pri1: helpers.image(pList[1].src, 345, 154),
|
|
|
pri2: helpers.image(pList[3].src, 345, 154),
|
|
|
pri3: helpers.image(pList[5].src, 345, 154),
|
|
|
pri4: helpers.image(pList[7].src, 345, 154),
|
|
|
act1: {
|
|
|
src: helpers.image(pList[10].src, 375, 444),
|
|
|
url: pList[10].url
|
|
|
},
|
|
|
act2: {
|
|
|
src: helpers.image(pList[11].src, 375, 444),
|
|
|
url: pList[11].url
|
|
|
},
|
|
|
invite: helpers.image(pList[16].src, 750, 444),
|
|
|
dia1: {
|
|
|
src: helpers.image(pList[2].src, 560, 567),
|
|
|
url: pList[2].url
|
|
|
},
|
|
|
dia2: {
|
|
|
src: helpers.image(pList[4].src, 560, 567),
|
|
|
url: pList[4].url
|
|
|
},
|
|
|
dia3: {
|
|
|
src: helpers.image(pList[6].src, 560, 697),
|
|
|
url: pList[6].url
|
|
|
},
|
|
|
dia4: {
|
|
|
src: helpers.image(pList[8].src, 560, 488),
|
|
|
url: pList[8].url
|
|
|
},
|
|
|
dia5: {
|
|
|
src: helpers.image(pList[13].src, 560, 416),
|
|
|
url: pList[13].url
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
return resu;
|
|
|
});
|
|
|
}
|
|
|
}; |
...
|
...
|
|