Authored by OF1706

Merge branch 'feature/homeCtx'

Too many changes to show.

To preserve performance only 17 of 17+ files are displayed.

... ... @@ -6,7 +6,7 @@
'use strict';
const mRoot = '../models';
const accountService = require(`${mRoot}/account-service`); // user model
const accountModel = require(`${mRoot}/account-service`); // user model
const helpers = global.yoho.helpers;
/**
... ... @@ -24,7 +24,7 @@ exports.index = (req, res, next) => {
let responseData = {};
// 真实数据输出
accountService.getAccountInfo(uid).then(result => {
req.ctx(accountModel).getAccountInfo(uid).then(result => {
responseData.user = result;
responseData.meAccountPage = true;
responseData.account = {
... ... @@ -54,7 +54,7 @@ exports.userPwd = (req, res, next) => {
params.uid = uid;
// 真实数据输出
accountService.userPwd(params).then(result => {
req.ctx(accountModel).userPwd(params).then(result => {
// 第二步验证没通过,就跳转
if (result.code && result.code === 400) {
res.redirect(helpers.urlFormat(result.url, result.params));
... ... @@ -85,7 +85,7 @@ exports.userEmail = (req, res, next) => {
params.uid = uid;
// 真实数据输出
accountService.userEmail(params).then(result => {
req.ctx(accountModel).userEmail(params).then(result => {
// 第二步验证没通过,就跳转
if (result.code && result.code === 400) {
res.redirect(helpers.urlFormat(result.url, result.params));
... ... @@ -116,7 +116,7 @@ exports.userMobile = (req, res, next) => {
params.uid = uid;
// 真实数据输出
accountService.userMobile(params).then(result => {
req.ctx(accountModel).userMobile(params).then(result => {
// 第二步验证没通过,就跳转
if (result.code && result.code === 400) {
res.redirect(helpers.urlFormat(result.url, result.params));
... ... @@ -133,7 +133,7 @@ exports.userMobile = (req, res, next) => {
*/
exports.checkVerifyCode = (req, res, next) => {
// 真实数据输出
accountService.checkVerifyCode(req).then(result => {
req.ctx(accountModel).checkVerifyCode(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -148,7 +148,7 @@ exports.checkPassword = (req, res, next) => {
req.uid = req.user.uid;
// 真实数据输出
accountService.checkPassword(req).then(result => {
req.ctx(accountModel).checkPassword(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -163,7 +163,7 @@ exports.verifyPassword = (req, res, next) => {
req.uid = req.user.uid;
// 真实数据输出
accountService.verifyPassword(req).then(result => {
req.ctx(accountModel).verifyPassword(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -182,7 +182,7 @@ exports.modifyPwd = (req, res, next) => {
params.uid = uid;
// 真实数据输出
accountService.modifyPwd(req, params).then(result => {
req.ctx(accountModel).modifyPwd(req, params).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -197,7 +197,7 @@ exports.sendEmail = (req, res, next) => {
req.uid = req.user.uid;
// 真实数据输出
accountService.sendEmail(req).then(result => {
req.ctx(accountModel).sendEmail(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -212,7 +212,7 @@ exports.checkEmail = (req, res, next) => {
req.uid = req.user.uid;
// 真实数据输出
accountService.checkEmail(req).then(result => {
req.ctx(accountModel).checkEmail(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -228,7 +228,7 @@ exports.modifyEmail = (req, res, next) => {
req.uid = req.user.uid;
// 真实数据输出
accountService.modifyEmail(req).then(result => {
req.ctx(accountModel).modifyEmail(req).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -252,7 +252,7 @@ exports.sendEmailSuccess = (req, res, next) => {
params.uid = uid;
// 真实数据输出
accountService.sendEmailSuccess(params).then(result => {
req.ctx(accountModel).sendEmailSuccess(params).then(result => {
Object.assign(responseData, result);
res.render('home/account/email', responseData);
}).catch(next);
... ... @@ -265,7 +265,7 @@ exports.sendEmailSuccess = (req, res, next) => {
exports.mailResult = (req, res, next) => {
// 真实数据输出
accountService.mailResult(req.query).then(result => {
req.ctx(accountModel).mailResult(req.query).then(result => {
// 第二步验证没通过,就跳转
if (result.code && result.code === 400) {
res.redirect(helpers.urlFormat(result.url, result.params));
... ... @@ -284,7 +284,7 @@ exports.checkMobile = (req, res, next) => {
}
// 真实数据输出
accountService.checkMobile(req.query, req.user.uid).then(result => {
req.ctx(accountModel).checkMobile(req.query, req.user.uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -299,7 +299,7 @@ exports.checkMobileMsg = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
accountService.checkMobileMsg(req, uid).then(result => {
req.ctx(accountModel).checkMobileMsg(req, uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -314,7 +314,7 @@ exports.sendMobileMsg = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
accountService.sendMobileMsg(req, uid).then(result => {
req.ctx(accountModel).sendMobileMsg(req, uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -329,7 +329,7 @@ exports.modifyMobile = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
accountService.modifyMobile(req, uid).then(result => {
req.ctx(accountModel).modifyMobile(req, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -6,7 +6,7 @@
'use strict';
const mRoot = '../models';
const addressService = require(`${mRoot}/address-service`); // user model
const addressModel = require(`${mRoot}/address-service`); // user model
/**
* 地址管理列表
... ... @@ -20,7 +20,7 @@ exports.index = (req, res, next) => {
};
// 真实数据输出
addressService.getAddressInfo(uid).then(result => {
req.ctx(addressModel).getAddressInfo(uid).then(result => {
responseData.meAddressPage = true;
responseData.address = result.address;
res.render('home/address/address', responseData);
... ... @@ -38,7 +38,7 @@ exports.editAddress = (req, res, next) => {
}
// 真实数据输出
addressService.editAddress(req.query, uid).then(result => {
req.ctx(addressModel).editAddress(req.query, uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -50,7 +50,7 @@ exports.saveAddress = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
addressService.saveAddress(req.body, uid).then(result => {
req.ctx(addressModel).saveAddress(req.body, uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -69,7 +69,7 @@ exports.delAddress = (req, res, next) => {
}
// 真实数据输出
addressService.delAddress(req.query, uid).then(result => {
req.ctx(addressModel).delAddress(req.query, uid).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -88,7 +88,7 @@ exports.defaultAddress = (req, res, next) => {
}
// 真实数据输出
addressService.defaultAddress(req.query, uid).then(result => {
req.ctx(addressModel).defaultAddress(req.query, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -9,7 +9,7 @@ const currencyModel = require('../models/currency-model');
const index = (req, res, next)=>{
let uid = req.user.uid;
currencyModel.currencyData(uid, req.query).then(result => {
req.ctx(currencyModel).currencyData(uid, req.query).then(result => {
res.render('currency', {
content: result
});
... ...
'use strict';
const _ = require('lodash');
const headerService = require('../models/general-tabs-service');
const headerModel = require('../models/general-tabs-service');
const getCommonHeader = (req, res, next) => {
let channel = req.query.channel;
let uid = req.user.uid;
let clientService = _.get(req.app.locals.pc, 'clientService.new', false);
headerService.getHomeNav(uid, channel, req.originalUrl, clientService).then((result)=>{
req.ctx(headerModel).getHomeNav(uid, channel, req.originalUrl, clientService).then((result)=>{
_.merge(res.locals, result);
next();
}).catch(next);
... ... @@ -17,3 +17,5 @@ const getCommonHeader = (req, res, next) => {
module.exports = {
getCommonHeader
};
... ...
... ... @@ -6,7 +6,7 @@
'use strict';
const mRoot = '../models';
const giftService = require(`${mRoot}/gift-service`); // user model
const giftModel = require(`${mRoot}/gift-service`); // user model
/**
* 礼品卡页面
... ... @@ -20,7 +20,7 @@ exports.index = (req, res, next) => {
};
// 真实数据输出
giftService.index(req.query, uid).then(result => {
req.ctx(giftModel).index(req.query, uid).then(result => {
responseData.meGiftPage = true;
Object.assign(responseData, result);
res.render('gift', responseData);
... ... @@ -34,7 +34,7 @@ exports.exchange = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
giftService.exchange(req, req.body, uid).then(result => {
req.ctx(giftModel).exchange(req, req.body, uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -5,7 +5,7 @@
*/
'use strict';
const message = require('../models/message');
const messageModel = require('../models/message');
const index = (req, res, next) => {
let uid = req.user.uid;
... ... @@ -14,7 +14,7 @@ const index = (req, res, next) => {
return next();
}
message.getMessageList(uid, req.query || {}).then(result => {
req.ctx(messageModel).getMessageList(uid, req.query || {}).then(result => {
res.render('message', result);
}).catch(next);
};
... ... @@ -27,7 +27,7 @@ const detail = (req, res, next) => {
return next();
}
message.getMessageDetail(uid, req.query || {}).then(result => {
req.ctx(messageModel).getMessageDetail(uid, req.query || {}).then(result => {
res.render('message-detail', result);
}).catch(next);
};
... ... @@ -40,7 +40,7 @@ const delMsg = (req, res, next) => {
return next();
}
message.delMessage(uid, id).then(result => {
req.ctx(messageModel).delMessage(uid, id).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -53,7 +53,7 @@ const readMsg = (req, res, next) => {
return next();
}
message.delMessage(uid, id).then(result => {
req.ctx(messageModel).delMessage(uid, id).then(result => {
res.json(result);
}).catch(next);
};
... ... @@ -66,7 +66,7 @@ const pickCoupon = (req, res, next) => {
return next();
}
message.pickBirthCoupon(uid, id).then(result => {
req.ctx(messageModel).pickBirthCoupon(uid, id).then(result => {
res.json(result);
}).catch(next);
};
... ...
/**
* 个人中心 我的红包
*/
'use strict';
const redenvelopesModel = require('../models/redenvelopes-model');
const index = (req, res, next)=>{
let uid = req.user.uid;
redenvelopesModel.redenvelopesList(uid).then(result => {
req.ctx(redenvelopesModel).redenvelopesList(uid).then(result => {
res.render('redenvelopes', {
meRedEnvelopes: result
});
... ...
... ... @@ -6,8 +6,7 @@
'use strict';
const mRoot = '../models';
const userService = require(`${mRoot}/user-service`); // user model
// const helpers = global.yoho.helpers;
const userModel = require(`${mRoot}/user-service`); // user model
/**
* 个人中心
... ... @@ -25,7 +24,7 @@ exports.index = (req, res, next) => {
};
// 真实数据输出
userService.getUserInfo(uid).then(result => {
req.ctx(userModel).getUserInfo(uid).then(result => {
responseData.user = result;
res.render('home/user/index', responseData);
}).catch(next);
... ... @@ -43,7 +42,7 @@ exports.editUserInfo = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
userService.editUserInfo(req, uid).then(result => {
req.ctx(userModel).editUserInfo(req, uid).then(result => {
res.json(result);
}).catch(next);
... ... @@ -60,7 +59,7 @@ exports.editUserContactInfo = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
userService.editUserContactInfo(req, uid).then(result => {
req.ctx(userModel).editUserContactInfo(req, uid).then(result => {
res.json(result);
}).catch(next);
... ... @@ -77,7 +76,7 @@ exports.editUserHabitsInfo = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
userService.editUserHabitsInfo(req, uid).then(result => {
req.ctx(userModel).editUserHabitsInfo(req, uid).then(result => {
res.json(result);
}).catch(next);
... ... @@ -95,7 +94,7 @@ exports.editUserLikeBrand = (req, res, next) => {
let uid = req.user.uid;
// 真实数据输出
userService.editUserLikeBrand(req, uid).then(result => {
req.ctx(userModel).editUserLikeBrand(req, uid).then(result => {
res.json(result);
}).catch(next);
... ... @@ -109,7 +108,7 @@ exports.editUserLikeBrand = (req, res, next) => {
*/
exports.isBrandName = (req, res, next) => {
// 真实数据输出
userService.isBrandName(req).then(result => {
req.ctx(userModel).isBrandName(req).then(result => {
res.json(result);
}).catch(next);
... ... @@ -117,7 +116,7 @@ exports.isBrandName = (req, res, next) => {
exports.getProviceList = (req, res, next) => {
// 真实数据输出
userService.getProviceList(req.query.id).then(result => {
req.ctx(userModel).getProviceList(req.query.id).then(result => {
res.json(result);
}).catch(next);
... ...
... ... @@ -5,171 +5,258 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
const getVerifyInfo = uid => {
return api.get('', {
method: 'web.passport.getUserVerifyInfo',
uid: uid
});
getVerifyInfo(uid) {
};
let data = {
method: 'web.passport.getUserVerifyInfo',
uid: uid
};
const checkEmailCode = code => {
return api.get('', {
method: 'web.passport.checkCodeValid',
code: code
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
const modifyVerifyEmail = code => {
return api.get('', {
method: 'web.passport.changeVerifyEmail',
code: code
});
checkEmailCode(code) {
};
let data = {
method: 'web.passport.checkCodeValid',
code: code
};
const verifyPwd = (uid, password) => {
return api.get('', {
method: 'web.passport.verifyUserPwd',
uid: uid,
password: password
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
const checkVerifyMsg = (area, mobile, code) => {
return api.get('', {
method: 'web.passport.checkcode',
area: area,
mobile: mobile,
code: code
});
modifyVerifyEmail(code) {
};
let data = {
method: 'web.passport.changeVerifyEmail',
code: code
};
/**
* 邮箱身份验证--发送邮件
* @param type $email
* @param type $callback 成功后跳转链接
* @return type
*/
const sendVerifyEmailForNext = (email, callback) => {
return api.get('', {
method: 'web.passport.sendVerifyEmailInfo',
email: email,
callback: callback
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
/**
* 修改验证手机号
* @param type $uid
* @param type $area
* @param type $newMobile
* @return type
*/
const modifyVerifyMobile = (uid, area, newMobile) => {
return api.get('', {
method: 'web.passport.changeVerifyMobile',
uid: uid,
area: area,
newMobile: newMobile
});
verifyPwd(uid, password) {
};
let data = {
method: 'web.passport.verifyUserPwd',
uid: uid,
password: password
};
/**
* 修改邮箱前校验
* @param type $uid
* @param type $email
*/
const checkVerifyEmail = (uid, email) => {
return api.get('', {
method: 'web.passport.checkVerifyEmail',
uid: uid,
email: email
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
/**
* 验证邮箱--发送邮件
* @param type $uid
* @param type $email
* @return type
*/
const sendVerifyEmail = (uid, email) => {
return api.get('', {
method: 'web.passport.verifyEmail',
uid: uid,
email: email
});
checkVerifyMsg(area, mobile, code) {
};
let data = {
method: 'web.passport.checkcode',
area: area,
mobile: mobile,
code: code
};
/**
* 修改手机号前校验
* @param type $mobile
* @param type $area
* @return type
*/
const checkVerifyMobile = (uid, mobile, area) => {
return api.get('', {
method: 'web.passport.checkVerifyMobile',
uid: uid,
mobile: mobile,
area: area
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
/**
* 修改密码
* @param type $uid
* @param type $newPwd
* @return type
*/
const modifyPwd = (uid, newPwd) => {
return api.get('', {
method: 'web.passport.changePwd',
uid: uid,
newPassword: newPwd
});
/**
* 邮箱身份验证--发送邮件
* @param type $email
* @param type $callback 成功后跳转链接
* @return type
*/
sendVerifyEmailForNext(email, callback) {
};
let data = {
method: 'web.passport.sendVerifyEmailInfo',
email: email,
callback: callback
};
/**
* 发送验证
* @param type $uid
* @param type $mobile
* @param type $area
* @return type
*/
const sendMobileMsg = (uid, mobile, area) => {
return api.get('', {
method: 'web.passport.sendcode',
uid: uid,
mobile: mobile,
area: area
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
/**
* 修改验证手机号
* @param type $uid
* @param type $area
* @param type $newMobile
* @return type
*/
modifyVerifyMobile(uid, area, newMobile) {
let data = {
method: 'web.passport.changeVerifyMobile',
uid: uid,
area: area,
newMobile: newMobile
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 修改邮箱前校验
* @param type $uid
* @param type $email
*/
checkVerifyEmail(uid, email) {
let data = {
method: 'web.passport.checkVerifyEmail',
uid: uid,
email: email
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 验证邮箱--发送邮件
* @param type $uid
* @param type $email
* @return type
*/
sendVerifyEmail(uid, email) {
let data = {
method: 'web.passport.verifyEmail',
uid: uid,
email: email
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 修改手机号前校验
* @param type $mobile
* @param type $area
* @return type
*/
checkVerifyMobile(uid, mobile, area) {
let data = {
method: 'web.passport.checkVerifyMobile',
uid: uid,
mobile: mobile,
area: area
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 修改密码
* @param type $uid
* @param type $newPwd
* @return type
*/
modifyPwd(uid, newPwd) {
let data = {
method: 'web.passport.changePwd',
uid: uid,
newPassword: newPwd
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 发送验证
* @param type $uid
* @param type $mobile
* @param type $area
* @return type
*/
sendMobileMsg(uid, mobile, area) {
let data = {
method: 'web.passport.sendcode',
uid: uid,
mobile: mobile,
area: area
};
return this.get({
data: data,
param: {
code: 200
}
});
}
module.exports = {
getVerifyInfo,
checkEmailCode,
modifyVerifyEmail,
verifyPwd,
checkVerifyMsg,
sendVerifyEmailForNext,
checkVerifyEmail,
checkVerifyMobile,
sendVerifyEmail,
modifyVerifyMobile,
modifyPwd,
sendMobileMsg
};
... ...
... ... @@ -11,1041 +11,1084 @@ const logger = global.yoho.logger;
const _ = require('lodash');
const crypto = global.yoho.crypto;
const accountApi = require('./account-api');
const userApi = require('./user-api');
const AccountApi = require('./account-api');
// 时间转换为时间戳
function datetimeToUnix(datetime) {
let tmpDatetime = datetime.replace(/:/g, '-');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
tmpDatetime = tmpDatetime.replace(/ /g, '-');
let arr = tmpDatetime.split('-');
// 时间转换为时间戳
datetimeToUnix(datetime) {
let tmpDatetime = datetime.replace(/:/g, '-');
let now = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
tmpDatetime = tmpDatetime.replace(/ /g, '-');
let arr = tmpDatetime.split('-');
return parseInt(now.getTime() / 1000, 10);
}
let now = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
/**
* 根据输入的mobile获取area
* @param type $mobile
* @return int
*/
function handleMobile(mobile) {
let res = {};
// 国际号
if (mobile.indexOf('-') > 0) {
let areaTmp = mobile.split('-');
res.area = areaTmp[0];
res.mobile = areaTmp[1];
} else {
res.area = 86;
res.mobile = mobile;
return parseInt(now.getTime() / 1000, 10);
}
return res;
}
/**
* 获得标题文案
* @param type ischeckMobile
* @param type ischeckEmail
* @param type checkType
*/
function getTitles(ischeckMobile, ischeckEmail, checkType) {
let subTitle,
enTitle,
pageKey;
if (checkType === 'mobile') {
subTitle = ischeckMobile ? '修改手机' : '验证手机';
enTitle = ischeckMobile ? 'CHANGE TELEPHONE' : 'VERIFICATION TELEPHONE';
pageKey = 'mobile';
} else if (checkType === 'userpwd') {
subTitle = '修改密码';
enTitle = 'CHANGE PASSWORD';
pageKey = 'userpwd';
} else {
subTitle = ischeckEmail ? '修改邮箱' : '验证邮箱';
enTitle = ischeckEmail ? 'CHANGE EMAIL' : 'VERIFICATION EMAIL';
pageKey = 'email';
}
return {
subTitle: subTitle,
enTitle: enTitle,
pageKey: pageKey
};
}
/**
* 根据输入的mobile获取area
* @param type $mobile
* @return int
*/
handleMobile(mobile) {
let res = {};
/**
* 第一部页面form结构-step1
* @param type $data 用户验证相关信息
* @param type $ischeckMobile
* @param type $ischeckEmail
* @param type $firstCheck
* @return string
*/
const getFormDataStep1 = (data, ischeckMobile, ischeckEmail, firstCheck) => {
// 都没验证
let formData1 = [
{
inputTxt: '请输入登录密码',
key: 'password',
type: 'password',
name: 'password'
}
];
let formData2 = [
{// 只验证手机号
inputTxt: '已验证的手机号',
isVerify: true,
verifyAccount: data.mobile.slice(0, 3) + '****' + data.mobile.slice(7),
realAccount: data.mobile
}
];
let formData3 = [
{// 只验证邮箱
inputTxt: '已验证邮箱',
isVerify: true,
verifyAccount: data.email.slice(0, 2) + '****' + data.email.slice(6),
realAccount: data.email
// 国际号
if (mobile.indexOf('-') > 0) {
let areaTmp = mobile.split('-');
res.area = areaTmp[0];
res.mobile = areaTmp[1];
} else {
res.area = 86;
res.mobile = mobile;
}
];
let formData,
verifyType,
checkEmailFlag,
checkMobileFlag;
// 只验证手机号
if (ischeckMobile && !ischeckEmail) {
formData = formData2;
verifyType = 3;
checkEmailFlag = false;
checkMobileFlag = true;
} else if (ischeckEmail && !ischeckMobile) { // 只验证邮箱
formData = formData3;
verifyType = 2;
checkEmailFlag = true;
checkMobileFlag = false;
} else if (ischeckMobile && ischeckEmail) { // 都验证
formData = (firstCheck === 'mobile') ? formData2 : formData3;
verifyType = (firstCheck === 'mobile') ? 3 : 2;
checkEmailFlag = (firstCheck === 'mobile') ? false : true;
checkMobileFlag = (firstCheck === 'mobile') ? true : false;
} else { // 没有验证
formData = formData1;
verifyType = 1;
checkEmailFlag = false;
checkMobileFlag = false;
return res;
}
return {
formData: formData,
verifyType: verifyType,
checkEmailFlag: checkEmailFlag,
checkMobileFlag: checkMobileFlag
};
};
/**
* 第二步-formData
* @param type $ischeckEmail
* @param type $ischeckMobile
* @param type $checkType
* @return array
*/
const getFormDataStep2 = (ischeckEmail, ischeckMobile, checkType) => {
let formData = [];
switch (checkType) {
case 'userpwd':
formData = [
{
inputTxt: '输入新密码',
key: 'newPwd',
type: 'password',
name: 'newPwd'
},
{
inputTxt: '确认新密码',
key: 'confirm_password',
type: 'password',
name: 'confirm_password'
}
];
break;
case 'email':
formData = [
{
inputTxt: ischeckEmail ? '新的邮箱' : '我的邮箱',
key: 'email',
type: 'text',
name: 'email'
}
];
break;
case 'mobile':
formData = [
{
inputTxt: ischeckMobile ? '输入新的手机号码' : '请输入手机号码',
key: 'mobilevalue',
type: 'text',
name: 'mobile'
}
];
break;
default:
formData = [];
break;
/**
* 获得标题文案
* @param type ischeckMobile
* @param type ischeckEmail
* @param type checkType
*/
getTitles(ischeckMobile, ischeckEmail, checkType) {
let subTitle,
enTitle,
pageKey;
if (checkType === 'mobile') {
subTitle = ischeckMobile ? '修改手机' : '验证手机';
enTitle = ischeckMobile ? 'CHANGE TELEPHONE' : 'VERIFICATION TELEPHONE';
pageKey = 'mobile';
} else if (checkType === 'userpwd') {
subTitle = '修改密码';
enTitle = 'CHANGE PASSWORD';
pageKey = 'userpwd';
} else {
subTitle = ischeckEmail ? '修改邮箱' : '验证邮箱';
enTitle = ischeckEmail ? 'CHANGE EMAIL' : 'VERIFICATION EMAIL';
pageKey = 'email';
}
return {
subTitle: subTitle,
enTitle: enTitle,
pageKey: pageKey
};
}
return {formData: formData};
};
/**
* 个人中心-判断身份验证状态
* @param type uid
* @param type checkType
* @param type step page步骤
* @return type
*/
const auditCheckStatus = (uid, checkType, step) => {
return co(function*() {
let res = yield accountApi.getVerifyInfo(uid),
ret = {status: false};
if (res.data) {
let data = res.data,
ischeckMobile = (data.mobileVerify === 'N') ? false : true,
ischeckEmail = (data.emailVerify === 'N') ? false : true;
let firstCheck = '', // 优先验证标识
titleInfo = getTitles(ischeckMobile, ischeckEmail, checkType),
formJson = {};
if (ischeckMobile && ischeckEmail) {
firstCheck = (datetimeToUnix(data.mobileVerifyTime) <=
datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
/**
* 第一部页面form结构-step1
* @param type $data 用户验证相关信息
* @param type $ischeckMobile
* @param type $ischeckEmail
* @param type $firstCheck
* @return string
*/
getFormDataStep1(data, ischeckMobile, ischeckEmail, firstCheck) {
// 都没验证
let formData1 = [
{
inputTxt: '请输入登录密码',
key: 'password',
type: 'password',
name: 'password'
}
let verifyType = 1,
checkEmailFlag = false,
checkMobileFlag = false;
if (step === 1) {
formJson = getFormDataStep1(data, ischeckMobile, ischeckEmail, firstCheck);
verifyType = formJson.verifyType;
checkEmailFlag = formJson.checkEmailFlag;
checkMobileFlag = formJson.checkMobileFlag;
delete formJson.verifyType;
delete formJson.checkEmailFlag;
delete formJson.checkMobileFlag;
} else if (step === 2) {
formJson = getFormDataStep2(ischeckEmail, ischeckMobile, checkType);
];
let formData2 = [
{// 只验证手机号
inputTxt: '已验证的手机号',
isVerify: true,
verifyAccount: data.mobile.slice(0, 3) + '****' + data.mobile.slice(7),
realAccount: data.mobile
}
ret = {
status: true,
ischeckMobile: ischeckMobile,
ischeckEmail: ischeckEmail,
email: data.email,
mobile: data.mobile,
subTitle: titleInfo.subTitle,
enTitle: titleInfo.enTitle,
pageKey: titleInfo.pageKey,
formData: formJson.formData,
verifyType: verifyType,
checkEmailFlag: checkEmailFlag,
checkMobileFlag: checkMobileFlag
};
];
let formData3 = [
{// 只验证邮箱
inputTxt: '已验证邮箱',
isVerify: true,
verifyAccount: data.email.slice(0, 2) + '****' + data.email.slice(6),
realAccount: data.email
}
];
let formData,
verifyType,
checkEmailFlag,
checkMobileFlag;
// 只验证手机号
if (ischeckMobile && !ischeckEmail) {
formData = formData2;
verifyType = 3;
checkEmailFlag = false;
checkMobileFlag = true;
} else if (ischeckEmail && !ischeckMobile) { // 只验证邮箱
formData = formData3;
verifyType = 2;
checkEmailFlag = true;
checkMobileFlag = false;
} else if (ischeckMobile && ischeckEmail) { // 都验证
formData = (firstCheck === 'mobile') ? formData2 : formData3;
verifyType = (firstCheck === 'mobile') ? 3 : 2;
checkEmailFlag = (firstCheck === 'mobile') ? false : true;
checkMobileFlag = (firstCheck === 'mobile') ? true : false;
} else { // 没有验证
formData = formData1;
verifyType = 1;
checkEmailFlag = false;
checkMobileFlag = false;
}
return ret;
})();
};
return {
formData: formData,
verifyType: verifyType,
checkEmailFlag: checkEmailFlag,
checkMobileFlag: checkMobileFlag
};
}
/**
* 校验进入第二步
* @param type $checkCode
* @param type $uid
* @param type MaxTime
* @return boolean
*/
const checkCode = (ckCode, uid, time) => {
time = parseInt(`0${time}`, 10) || 86400000;
/**
* 第二步-formData
* @param type $ischeckEmail
* @param type $ischeckMobile
* @param type $checkType
* @return array
*/
getFormDataStep2(ischeckEmail, ischeckMobile, checkType) {
let formData = [];
switch (checkType) {
case 'userpwd':
formData = [
{
inputTxt: '输入新密码',
key: 'newPwd',
type: 'password',
name: 'newPwd'
},
{
inputTxt: '确认新密码',
key: 'confirm_password',
type: 'password',
name: 'confirm_password'
}
];
break;
case 'email':
formData = [
{
inputTxt: ischeckEmail ? '新的邮箱' : '我的邮箱',
key: 'email',
type: 'text',
name: 'email'
}
];
break;
case 'mobile':
formData = [
{
inputTxt: ischeckMobile ? '输入新的手机号码' : '请输入手机号码',
key: 'mobilevalue',
type: 'text',
name: 'mobile'
}
];
break;
default:
formData = [];
break;
}
try {
// checkCode里空格用+替换
let code = decodeURIComponent(ckCode);
let checkStr = crypto.decrypt('yoho9646abcdefgh', code);
return {formData: formData};
}
let checkInfo = checkStr.split('_'),
checkUid = checkInfo[0],
timeDiff = Date.parse(new Date()) - checkInfo[1]; // 时间差,秒 24h 86400000
/**
* 个人中心-判断身份验证状态
* @param type uid
* @param type checkType
* @param type step page步骤
* @return type
*/
auditCheckStatus(uid, checkType, step) {
let that = this;
return co(function*() {
let accountDataModel = new AccountApi(that.ctx);
let res = yield accountDataModel.getVerifyInfo(uid),
ret = {status: false};
if (res.data) {
let data = res.data,
ischeckMobile = (data.mobileVerify === 'N') ? false : true,
ischeckEmail = (data.emailVerify === 'N') ? false : true;
let firstCheck = '', // 优先验证标识
titleInfo = that.getTitles(ischeckMobile, ischeckEmail, checkType),
formJson = {};
if (ischeckMobile && ischeckEmail) {
firstCheck = (that.datetimeToUnix(data.mobileVerifyTime) <=
that.datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
}
if (checkStr.indexOf('completeverify') > 0 && String(checkUid) === String(uid) && timeDiff <= time) {
return true;
} else {
return false;
}
} catch (e) { // eslint-disable-line
logger.error(`account checkCode decrypt error [checkCode]:${ckCode}`);
let verifyType = 1,
checkEmailFlag = false,
checkMobileFlag = false;
if (step === 1) {
formJson = that.getFormDataStep1(data, ischeckMobile, ischeckEmail, firstCheck);
verifyType = formJson.verifyType;
checkEmailFlag = formJson.checkEmailFlag;
checkMobileFlag = formJson.checkMobileFlag;
delete formJson.verifyType;
delete formJson.checkEmailFlag;
delete formJson.checkMobileFlag;
} else if (step === 2) {
formJson = that.getFormDataStep2(ischeckEmail, ischeckMobile, checkType);
}
return false;
ret = {
status: true,
ischeckMobile: ischeckMobile,
ischeckEmail: ischeckEmail,
email: data.email,
mobile: data.mobile,
subTitle: titleInfo.subTitle,
enTitle: titleInfo.enTitle,
pageKey: titleInfo.pageKey,
formData: formJson.formData,
verifyType: verifyType,
checkEmailFlag: checkEmailFlag,
checkMobileFlag: checkMobileFlag
};
}
return ret;
})();
}
};
/**
* 个人中心-账号安全-index
*
*/
const getAccountInfo = (uid) => {
return co(function*() {
let resq = [{
icon: 'ok',
type: '登录密码',
tip: '互联网帐号存在被盗风险,建议您定期更改密码以保护帐号安全。',
red: 'true',
url: helpers.urlFormat('/home/account/userpwd'),
isValid: true
}, {
icon: 'warning',
type: '邮箱验证',
tip: '验证后,可用于找回登录密码。',
url: helpers.urlFormat('/home/account/email')
}, {
icon: 'warning',
type: '手机验证',
tip: '验证后,可用于找回登录密码。',
url: helpers.urlFormat('/home/account/mobile')
}];
let verifyResult = yield accountApi.getVerifyInfo(uid);
if (verifyResult.data) {
let verifyData = verifyResult.data;
resq[1].icon = verifyData.emailVerify === 'N' ? 'warning' : 'ok';
resq[1].tip = verifyData.emailVerify === 'N' ? '验证后,可用于找回登录密码。' :
'您验证的邮箱:' + verifyData.email.slice(0, 2) + '****' + verifyData.email.slice(6);
resq[1].isValid = verifyData.emailVerify === 'N' ? false : true;
resq[2].icon = verifyData.mobileVerify === 'N' ? 'warning' : 'ok';
resq[2].isValid = verifyData.mobileVerify === 'N' ? false : true;
resq[2].tip = verifyData.mobileVerify === 'N' ? '验证后,可用于找回登录密码。' :
'您验证的手机:' + verifyData.mobile.slice(0, 3) + '****' + verifyData.mobile.slice(7);
/**
* 校验进入第二步
* @param type $checkCode
* @param type $uid
* @param type MaxTime
* @return boolean
*/
checkCode(ckCode, uid, time) {
time = parseInt(`0${time}`, 10) || 86400000;
try {
// checkCode里空格用+替换
let code = decodeURIComponent(ckCode);
let checkStr = crypto.decrypt('yoho9646abcdefgh', code);
let checkInfo = checkStr.split('_'),
checkUid = checkInfo[0],
timeDiff = Date.parse(new Date()) - checkInfo[1]; // 时间差,秒 24h 86400000
if (checkStr.indexOf('completeverify') > 0 && String(checkUid) === String(uid) && timeDiff <= time) {
return true;
} else {
return false;
}
} catch (e) { // eslint-disable-line
logger.error(`account checkCode decrypt error [checkCode]:${ckCode}`);
return false;
}
}
return resq;
/**
* 个人中心-账号安全-index
*
*/
getAccountInfo(uid) {
let that = this;
return co(function*() {
let accountDataModel = new AccountApi(that.ctx);
let resq = [{
icon: 'ok',
type: '登录密码',
tip: '互联网帐号存在被盗风险,建议您定期更改密码以保护帐号安全。',
red: 'true',
url: helpers.urlFormat('/home/account/userpwd'),
isValid: true
}, {
icon: 'warning',
type: '邮箱验证',
tip: '验证后,可用于找回登录密码。',
url: helpers.urlFormat('/home/account/email')
}, {
icon: 'warning',
type: '手机验证',
tip: '验证后,可用于找回登录密码。',
url: helpers.urlFormat('/home/account/mobile')
}];
let verifyResult = yield accountDataModel.getVerifyInfo(uid);
if (verifyResult.data) {
let verifyData = verifyResult.data;
resq[1].icon = verifyData.emailVerify === 'N' ? 'warning' : 'ok';
resq[1].tip = verifyData.emailVerify === 'N' ? '验证后,可用于找回登录密码。' :
'您验证的邮箱:' + verifyData.email.slice(0, 2) + '****' + verifyData.email.slice(6);
resq[1].isValid = verifyData.emailVerify === 'N' ? false : true;
resq[2].icon = verifyData.mobileVerify === 'N' ? 'warning' : 'ok';
resq[2].isValid = verifyData.mobileVerify === 'N' ? false : true;
resq[2].tip = verifyData.mobileVerify === 'N' ? '验证后,可用于找回登录密码。' :
'您验证的手机:' + verifyData.mobile.slice(0, 3) + '****' + verifyData.mobile.slice(7);
}
})();
};
return resq;
/**
* 个人中心-修改密码身份验证-page1/2/3
*/
const userPwd = (params) => {
return co(function*() {
})();
}
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
/**
* 个人中心-修改密码身份验证-page1/2/3
*/
userPwd(params) {
let that = this;
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
// 第二步验证信息校验
if (step === 2 && ckCode !== '') {
let checkFlag = that.checkCode(ckCode, uid);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/userpwd', {step: 1}));
return {
code: 400,
url: '/home/account/userpwd',
params: {step: 1}
};
}
}
// 第二步验证信息校验
if (step === 2 && ckCode !== '') {
let checkFlag = checkCode(ckCode, uid);
// 验证信息
let verifyInfo = yield that.auditCheckStatus(uid, 'userpwd', step);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/userpwd', {step: 1}));
if (!verifyInfo.status) {
return {
code: 400,
url: '/home/account/userpwd',
params: {step: 1}
meValidatePage: true
};
}
}
// 验证信息
let verifyInfo = yield auditCheckStatus(uid, 'userpwd', step);
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.修改登录密码'
},
{
progressName: '3.完成'
}
]
};
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success ? 'res-success' : 'res-error';
data.complete = {
resInfo: '恭喜你,您已经成功修改了登录密码!'
};
}
if (!verifyInfo.status) {
return {
userpwd: data,
meValidatePage: true
};
}
})();
}
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.修改登录密码'
},
{
progressName: '3.完成'
/**
* 个人中心-邮箱验证身份-page1/2/3
*/
userEmail(params) {
let that = this;
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
// 第二步验证信息校验
if (step === 2) {
let checkFlag = that.checkCode(ckCode, uid);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/email', {step: 1}));
return {
code: 400,
url: '/home/account/email',
params: {step: 1}
};
}
]
};
}
// 验证信息
let verifyInfo = yield that.auditCheckStatus(uid, 'email', step);
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success ? 'res-success' : 'res-error';
data.complete = {
resInfo: '恭喜你,您已经成功修改了登录密码!'
if (!verifyInfo.status) {
return {
meValidatePage: true
};
}
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
]
};
}
return {
userpwd: data,
meValidatePage: true
};
})();
};
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData,
mobileCode: false
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success === 'true' ? 'res-success' : 'res-error';
data.complete = {
resInfo: success === 'true' ? '恭喜您,您已经成功' + verifyInfo.subTitle +
'!' : '抱歉,' + verifyInfo.subTitle + '失败'
};
}
/**
* 个人中心-邮箱验证身份-page1/2/3
*/
const userEmail = (params) => {
return co(function*() {
return {
email: data,
meValidatePage: true
};
})();
}
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
/**
* 个人中心-手机验证身份-page1/2/3
*/
userMobile(params) {
let that = this;
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
// 第二步验证信息校验
if (step === 2) {
let checkFlag = that.checkCode(ckCode, uid);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/mobile', {step: 1}));
return {
code: 400,
url: '/home/account/mobile',
params: {step: 1}
};
}
}
// 第二步验证信息校验
if (step === 2) {
let checkFlag = checkCode(ckCode, uid);
// 验证信息
let verifyInfo = yield that.auditCheckStatus(uid, 'mobile', step);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/email', {step: 1}));
if (!verifyInfo.status) {
return {
code: 400,
url: '/home/account/email',
params: {step: 1}
meValidatePage: true
};
}
}
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
]
};
// 验证信息
let verifyInfo = yield auditCheckStatus(uid, 'email', step);
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData,
mobileCode: true
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success ? 'res-success' : 'res-error';
data.complete = {
resInfo: '恭喜你,您已成功' + verifyInfo.subTitle +
'!今后您可以使用该手机号+密码进行登录'
};
}
if (!verifyInfo.status) {
return {
mobile: data,
meValidatePage: true
};
}
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
]
};
})();
}
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData,
mobileCode: false
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success === 'true' ? 'res-success' : 'res-error';
data.complete = {
resInfo: success === 'true' ? '恭喜您,您已经成功' + verifyInfo.subTitle +
'!' : '抱歉,' + verifyInfo.subTitle + '失败'
};
}
/**
* 个人中心-邮箱验证身份-邮件发送成功过渡页
*/
sendEmailSuccess(params) {
let that = this;
return {
email: data,
meValidatePage: true
};
})();
};
return co(function*() {
let checkType = params.checkType || 'userpwd',
uid = params.uid,
email = params.email || '',
emailDomain = '',
type = params.email || 1;// 1:身份验证 2:修改邮箱
/**
* 个人中心-手机验证身份-page1/2/3
*/
const userMobile = (params) => {
return co(function*() {
let step = params.step ? parseInt(params.step, 10) : 1,
ckCode = params.checkCode || '',
success = params.success || false,
progress = 'progress' + step,
uid = params.uid;
// 第二步验证信息校验
if (step === 2) {
let checkFlag = checkCode(ckCode, uid);
if (!checkFlag) {
// res.redirect(helpers.urlFormat('/home/account/mobile', {step: 1}));
// 验证信息
let verifyInfo = yield that.auditCheckStatus(uid, checkType);
if (!verifyInfo.status) {
return {
code: 400,
url: '/home/account/mobile',
params: {step: 1}
meValidatePage: true
};
}
}
emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
'mail.google.com' : 'mail.' + email.split('@')[1]);
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
progressCur: (type === 1) ? 'progress1' : 'progress2',
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
],
returnInfo: true,
sendEmail: {
emailInfo: email.slice(0, 2) + '****' + email.slice(6),
emailUrl: emailDomain
}
};
// 验证信息
let verifyInfo = yield auditCheckStatus(uid, 'mobile', step);
if (type === 1) {
data.progress[0].iscur = true;
} else {
data.progress[1].iscur = true;
}
if (!verifyInfo.status) {
return {
meValidatePage: true
};
}
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
verifyType: verifyInfo.verifyType, // verifyType 1:登录密码验证 2:邮箱验证 3:手机验证
progressCur: progress,
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
]
};
let resqData = {meValidatePage: true};
resqData.email = data;
return resqData;
// form变化1-验证身份 2-修改 3-成功
if (step === 1) {
data.progress[0].iscur = true;
data.returnInfo = false;
data.formInfo = {
ischeckEmail: verifyInfo.checkEmailFlag,
formData: verifyInfo.formData,
mobileCode: verifyInfo.checkMobileFlag
};
} else if (step === 2) {
data.progress[1].iscur = true;
data.returnInfo = false;
data.formInfo = {
formData: verifyInfo.formData,
mobileCode: true
};
} else if (step === 3) {
data.progress[2].iscur = true;
data.returnInfo = true;
data.resClass = success ? 'res-success' : 'res-error';
data.complete = {
resInfo: '恭喜你,您已成功' + verifyInfo.subTitle +
'!今后您可以使用该手机号+密码进行登录'
};
}
})();
}
return {
mobile: data,
meValidatePage: true
};
})();
};
/**
* 点击邮箱验证链接方法--修改验证邮箱
*/
mailResult(params) {
let that = this;
return co(function*() {
let code = params.code;
let accountDataModel = new AccountApi(that.ctx);
let check = yield accountDataModel.checkEmailCode(code);
if (check.code === 200) {
let data = yield accountDataModel.modifyVerifyEmail(code);
if (data.code === 200) {
// res.redirect(helpers.urlFormat('/home/account/email',
// {step: 3, success: true}));
return {
code: 400,
url: '/home/account/email',
params: {step: 3, success: true}
};
}
}
/**
* 个人中心-邮箱验证身份-邮件发送成功过渡页
*/
const sendEmailSuccess = (params) => {
return co(function*() {
let checkType = params.checkType || 'userpwd',
uid = params.uid,
email = params.email || '',
emailDomain = '',
type = params.email || 1;// 1:身份验证 2:修改邮箱
// 验证信息
let verifyInfo = yield auditCheckStatus(uid, checkType);
if (!verifyInfo.status) {
// res.redirect(helpers.urlFormat('/home/account/email',
// {step: 3, success: false}));
return {
meValidatePage: true
code: 400,
url: '/home/account/email',
params: {step: 3, success: false}
};
}
emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
'mail.google.com' : 'mail.' + email.split('@')[1]);
let data = {
subTitle: verifyInfo.subTitle,
enTitle: verifyInfo.enTitle,
progressCur: (type === 1) ? 'progress1' : 'progress2',
progress: [
{
progressName: '1.验证身份'
},
{
progressName: '2.' + verifyInfo.subTitle
},
{
progressName: '3.完成'
}
],
returnInfo: true,
sendEmail: {
emailInfo: email.slice(0, 2) + '****' + email.slice(6),
emailUrl: emailDomain
}
};
})();
}
if (type === 1) {
data.progress[0].iscur = true;
} else {
data.progress[1].iscur = true;
}
/**
* 身份验证-登录密码验证Ajax
*/
verifyPassword(req) {
let that = this;
let resqData = {meValidatePage: true};
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.user.uid,
accountDataModel = new AccountApi(that.ctx);
resqData.email = data;
return resqData;
let resqData = yield accountDataModel.verifyPwd(uid, password);
})();
};
if (resqData.code === 200) {
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + password + 'completeverify');
/**
* 点击邮箱验证链接方法--修改验证邮箱
*/
const mailResult = (params) => {
return co(function*() {
let code = params.code;
let check = yield accountApi.checkEmailCode(code);
resqData.data = encodeURIComponent(ckCode);
}
return resqData;
})();
}
if (check.code === 200) {
let data = yield accountApi.modifyVerifyEmail(code);
/**
* 分-验证密码正确性-ajax
*/
checkPassword(req) {
let that = this;
if (data.code === 200) {
// res.redirect(helpers.urlFormat('/home/account/email',
// {step: 3, success: true}));
return {
code: 400,
url: '/home/account/email',
params: {step: 3, success: true}
};
}
}
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.user.uid,
resqData = {code: 400},
accountDataModel = new AccountApi(that.ctx);
// res.redirect(helpers.urlFormat('/home/account/email',
// {step: 3, success: false}));
return {
code: 400,
url: '/home/account/email',
params: {step: 3, success: false}
};
})();
};
resqData = yield accountDataModel.verifyPwd(uid, password);
/**
* 身份验证-登录密码验证Ajax
*/
const verifyPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.user.uid;
return resqData;
})();
}
let resqData = yield accountApi.verifyPwd(uid, password);
/**
* 分-验证图形验证码-ajax
*/
checkVerifyCode(req) {
return co(function*() {
let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
resqData = {};
if (captchaCode && captchaCode !== req.session.captcha) {
resqData.code = 400;
resqData.message = '图形验证码不正确';
} else {
resqData.code = 200;
resqData.message = '';
}
if (resqData.code === 200) {
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + password + 'completeverify');
return resqData;
})();
}
resqData.data = encodeURIComponent(ckCode);
}
return resqData;
})();
};
/**
* 手机身份验证-校验手机号
*/
identityMobile(req) {
let that = this;
/**
* 分-验证密码正确性-ajax
*/
const checkPassword = (req) => {
return co(function*() {
let password = _.trim(req.body.password || ''),
uid = req.user.uid,
resqData = {code: 400};
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400},
uid = req.user.uid,
check = false,
userId;
resqData = yield accountApi.verifyPwd(uid, password);
let mobileInfo = that.handleMobile(mobile),
accountDataModel = new AccountApi(that.ctx);
return resqData;
})();
};
let userInfo = yield accountDataModel.getUserInfoByMobile(mobileInfo.area, mobile);
/**
* 分-验证图形验证码-ajax
*/
const checkVerifyCode = (req) => {
return co(function*() {
let captchaCode = _.trim(req.body.verifyCode || '').toLowerCase(),
resqData = {};
if (captchaCode && captchaCode !== req.session.captcha) {
resqData.code = 400;
resqData.message = '图形验证码不正确';
} else {
resqData.code = 200;
resqData.message = '';
}
userId = 'uid' in userInfo.data ? userInfo.data.uid : 0;
if (userId === uid) {
check = true;
}
return resqData;
})();
};
if (check) {
resqData = {
code: 200,
message: '',
data: ''
};
} else {
resqData = {
code: 400,
message: '手机号错误',
data: ''
};
}
return resqData;
})();
}
/**
* 手机身份验证-校验手机号
*/
const identityMobile = (req) => {
return co(function*() {
let mobile = req.body.mobile || '',
resqData = {code: 400},
uid = req.user.uid,
check = false,
userId;
/**
* 向验证手机号发送短信-ajax
*/
sendMobileMsg(req, uid) {
let that = this;
let mobileInfo = handleMobile(mobile);
return co(function*() {
let mobile = req.body.mobile || '',
_code = req.body.checkCode,
resqData = {code: 400};
let userInfo = yield userApi.getUserInfoByMobile(mobileInfo.area, mobile);
let accountDataModel = new AccountApi(that.ctx);
userId = 'uid' in userInfo.data ? userInfo.data.uid : 0;
if (userId === uid) {
check = true;
}
// 发送验证码前置数据校验
if (!_code) {
let verifyInfo = yield accountDataModel.getVerifyInfo(uid);
if (check) {
resqData = {
code: 200,
message: '',
data: ''
};
} else {
resqData = {
code: 400,
message: '手机号错误',
data: ''
};
}
return resqData;
})();
};
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!that.checkCode(_code, uid)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
/**
* 向验证手机号发送短信-ajax
*/
const sendMobileMsg = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
_code = req.body.checkCode,
resqData = {code: 400};
// 发送验证码前置数据校验
if (!_code) {
let verifyInfo = yield accountApi.getVerifyInfo(uid);
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
let mobileInfo = that.handleMobile(mobile);
resqData = yield accountDataModel.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
}
/**
* 校验短信验证码-ajax
*/
checkMobileMsg(req, uid) {
let that = this;
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
resqData = {code: 400};
let accountDataModel = new AccountApi(that.ctx);
// 校验验证码前置数据校验
if (!_code) {
let verifyInfo = yield accountDataModel.getVerifyInfo(uid);
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!that.checkCode(_code, uid)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!checkCode(_code, uid)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
let mobileInfo = handleMobile(mobile);
if (mobile === '') {
Object.assign(resqData, {
message: '手机号为空',
data: ''
});
return resqData;
}
if (code === '') {
Object.assign(resqData, {
message: '验证码为空',
data: ''
});
return resqData;
}
let mobileInfo = that.handleMobile(mobile);
resqData = yield accountApi.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
resqData = yield accountDataModel.checkVerifyMsg(mobileInfo.area, mobileInfo.mobile, code);
if (resqData.code === 200) {
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' +
mobileInfo.mobile + mobileInfo.area + 'completeverify');
/**
* 校验短信验证码-ajax
*/
const checkMobileMsg = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
resqData = {code: 400};
// 校验验证码前置数据校验
if (!_code) {
let verifyInfo = yield accountApi.getVerifyInfo(uid);
mobile = _.get(verifyInfo, 'data.mobile', '');
if (!mobile) {
Object.assign(resqData, {
code: 200,
data: encodeURIComponent(ckCode)
});
}
return resqData;
})();
}
/**
* 身份验证时,发送邮件-ajax
*/
sendEmail(req) {
let that = this;
return co(function*() {
let uid = req.user.uid,
checkType = req.body.checkType || 'userpwd',
email = req.body.email || '',
resqData = {code: 400};
let accountDataModel = new AccountApi(that.ctx),
verifyInfo = yield accountDataModel.getVerifyInfo(uid);
email = _.get(verifyInfo, 'data.email', '');
if (!email) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
} else if (!checkCode(_code, uid)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
if (mobile === '') {
Object.assign(resqData, {
message: '手机号为空',
data: ''
});
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + email + checkType + 'completeverify');
let callback = 'home/account/' + checkType + '?step=2&checkCode=' +
encodeURIComponent(ckCode); // callback拼接于邮箱域名处;
resqData = yield accountDataModel.sendVerifyEmailForNext(email, callback);
return resqData;
}
if (code === '') {
Object.assign(resqData, {
message: '验证码为空',
data: ''
});
})();
}
/**
* 分-修改邮箱前,校验邮箱-ajax
*/
checkEmail(req) {
let that = this;
return co(function*() {
let uid = req.user.uid,
email = req.body.email || '',
resqData = {code: 400};
let accountDataModel = new AccountApi(that.ctx);
resqData = yield accountDataModel.checkVerifyEmail(uid, email);
return resqData;
}
let mobileInfo = handleMobile(mobile);
})();
}
resqData = yield accountApi.checkVerifyMsg(mobileInfo.area, mobileInfo.mobile, code);
if (resqData.code === 200) {
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) + '_' +
mobileInfo.mobile + mobileInfo.area + 'completeverify');
/**
* 修改密码
*/
modifyPwd(req, params) {
let that = this;
return co(function*() {
let uid = params.uid,
newPwd = params.newPwd || '',
_code = params.checkCode;
Object.assign(resqData, {
code: 200,
data: encodeURIComponent(ckCode)
});
}
return resqData;
})();
};
let accountDataModel = new AccountApi(that.ctx);
/**
* 身份验证时,发送邮件-ajax
*/
const sendEmail = (req) => {
return co(function*() {
let uid = req.user.uid,
checkType = req.body.checkType || 'userpwd',
email = req.body.email || '',
resqData = {code: 400};
let verifyInfo = yield accountApi.getVerifyInfo(uid);
email = _.get(verifyInfo, 'data.email', '');
if (!email) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
// 前置数据校验
if (!_code || !that.checkCode(_code, uid, 600000)) {
return {
code: 400,
message: '数据验证错误'
};
}
let ckCode = crypto.encryption('yoho9646abcdefgh', uid + '_' + Date.parse(new Date()) +
'_' + email + checkType + 'completeverify');
let resqData = yield accountDataModel.modifyPwd(uid, newPwd);
let callback = 'home/account/' + checkType + '?step=2&checkCode=' +
encodeURIComponent(ckCode); // callback拼接于邮箱域名处;
return resqData;
})();
}
resqData = yield accountApi.sendVerifyEmailForNext(email, callback);
return resqData;
})();
};
/**
* 修改验证手机号
*/
modifyMobile(req, uid) {
let that = this;
/**
* 分-修改邮箱前,校验邮箱-ajax
*/
const checkEmail = (req) => {
return co(function*() {
let uid = req.user.uid,
email = req.body.email || '',
resqData = {code: 400};
resqData = yield accountApi.checkVerifyEmail(uid, email);
return resqData;
})();
};
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
resqData = {code: 400};
/**
* 修改密码
*/
const modifyPwd = (req, params) => {
return co(function*() {
let uid = params.uid,
newPwd = params.newPwd || '',
_code = params.checkCode;
// 前置数据校验
if (!_code || !checkCode(_code, uid, 600000)) {
return {
code: 400,
message: '数据验证错误'
};
}
let accountDataModel = new AccountApi(that.ctx);
let resqData = yield accountApi.modifyPwd(uid, newPwd);
// 校验验证码前置数据校验
// 校验checkCode,有效时间10分钟(checkCode在调改接口前获取,考虑网络延时,服务器间的时间差,设置10分钟)
if (!_code || !that.checkCode(_code, uid, 600000)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
return resqData;
})();
};
if (mobile === '') {
resqData = {
code: 400,
message: '手机号为空',
data: ''
};
return resqData;
}
if (code === '') {
resqData = {
code: 400,
message: '验证码为空',
data: ''
};
return resqData;
}
let mobileInfo = that.handleMobile(mobile);
/**
* 修改验证手机号
*/
const modifyMobile = (req, uid) => {
return co(function*() {
let mobile = req.body.mobile || '',
code = req.body.code || '',
_code = req.body.checkCode,
resqData = {code: 400};
// 校验验证码前置数据校验
// 校验checkCode,有效时间10分钟(checkCode在调改接口前获取,考虑网络延时,服务器间的时间差,设置10分钟)
if (!_code || !checkCode(_code, uid, 600000)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
let checkFlag = yield accountDataModel.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
if (mobile === '') {
resqData = {
code: 400,
message: '手机号为空',
data: ''
};
return resqData;
}
if (code === '') {
resqData = {
code: 400,
message: '验证码为空',
data: ''
};
if (checkFlag.code === 200) {
resqData = yield accountDataModel.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile);
} else {
resqData = {
code: checkFlag.data,
message: checkFlag.message,
data: ''
};
}
return resqData;
}
let mobileInfo = handleMobile(mobile);
})();
}
let checkFlag = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
/**
* 分-检查手机号是否可修改-ajax
*/
checkMobile(params, uid) {
let that = this;
if (checkFlag.code === 200) {
resqData = yield accountApi.modifyVerifyMobile(uid, mobileInfo.area, mobileInfo.mobile);
} else {
resqData = {
code: checkFlag.data,
message: checkFlag.message,
data: ''
};
}
return resqData;
})();
};
return co(function*() {
let mobile = params.mobile || '',
resqData = {code: 400};
/**
* 分-检查手机号是否可修改-ajax
*/
const checkMobile = (params, uid) => {
return co(function*() {
let mobile = params.mobile || '',
resqData = {code: 400};
let mobileInfo = that.handleMobile(mobile),
accountDataModel = new AccountApi(that.ctx);
let mobileInfo = handleMobile(mobile);
resqData = yield accountDataModel.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
}
resqData = yield accountApi.checkVerifyMobile(uid, mobileInfo.mobile, mobileInfo.area);
return resqData;
})();
};
/**
* 修改验证邮箱校验并发送邮件-ajax
*
*/
modifyEmail(req) {
let that = this;
/**
* 修改验证邮箱校验并发送邮件-ajax
*
*/
const modifyEmail = (req) => {
return co(function*() {
let uid = req.user.uid,
email = req.body.email || '',
_code = req.body.checkCode,
resqData = {code: 400};
// 前置数据校验
if (!_code || !checkCode(_code, uid, 600000)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
return co(function*() {
let uid = req.user.uid,
email = req.body.email || '',
_code = req.body.checkCode,
resqData = {code: 400};
let check = yield accountApi.checkVerifyEmail(uid, email);
let accountDataModel = new AccountApi(that.ctx);
if (check.code === 200) {
resqData = yield accountApi.sendVerifyEmail(uid, email);
}
return resqData;
})();
};
// 前置数据校验
if (!_code || !that.checkCode(_code, uid, 600000)) {
return Object.assign(resqData, {
message: '数据验证错误'
});
}
let check = yield accountDataModel.checkVerifyEmail(uid, email);
if (check.code === 200) {
resqData = yield accountDataModel.sendVerifyEmail(uid, email);
}
return resqData;
})();
}
module.exports = {
getAccountInfo,
userPwd,
userEmail,
userMobile,
sendEmailSuccess,
mailResult,
verifyPassword,
checkPassword,
checkVerifyCode,
identityMobile,
sendMobileMsg,
checkMobileMsg,
sendEmail,
checkEmail,
checkMobile,
modifyEmail,
modifyMobile,
modifyPwd
};
... ...
... ... @@ -5,77 +5,108 @@
*/
'use strict';
const api = global.yoho.API;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 地址数据
*
* @param int $uid 用户ID
* @param int $limit 分页大小参数(默认10条)
* @return array 地址接口返回的数据
*/
exports.addressData = (uid, lmt) => {
let limit = lmt ? lmt : 10;
/**
* 地址数据
*
* @param int $uid 用户ID
* @param int $limit 分页大小参数(默认10条)
* @return array 地址接口返回的数据
*/
addressData(uid, lmt) {
let limit = lmt ? lmt : 10;
let data = {
method: 'app.address.gethidden',
uid: uid,
limit: limit
};
return api.get('', {
method: 'app.address.gethidden',
uid: uid,
limit: limit
});
return this.get({
data: data,
param: {
code: 200
}
});
};
}
/**
* 保存地址数据
*
* @param int $uid 用户ID
* @param string $address 地址信息
* @param int $area_code 城市码
* @param string $consignee 收货人
* @param string $email 邮箱地址
* @param int $id 地址唯一标识符id
* @param string $mobile 手机号码
* @param string $phone 电话号码
* @param string $zip_code 邮编
* @return array 地址接口返回的数据
*/
saveAddressData(params) {
if (params.id !== null) {
params.method = 'app.address.update';// 修改
} else {
delete params.id;
params.method = 'app.address.add';// 添加
}
return this.get({
data: params,
param: {
code: 200
}
});
/**
* 保存地址数据
*
* @param int $uid 用户ID
* @param string $address 地址信息
* @param int $area_code 城市码
* @param string $consignee 收货人
* @param string $email 邮箱地址
* @param int $id 地址唯一标识符id
* @param string $mobile 手机号码
* @param string $phone 电话号码
* @param string $zip_code 邮编
* @return array 地址接口返回的数据
*/
exports.saveAddressData = (params) => {
if (params.id !== null) {
params.method = 'app.address.update';// 修改
} else {
delete params.id;
params.method = 'app.address.add';// 添加
}
return api.get('', params);
};
/**
* 删除地址
*
* @param int $uid 用户ID
* @param int $id 地址唯一标识符id
* @return array 接口返回的数据
*/
deleteAddress(uid, id) {
let data = {
method: 'app.address.del',
uid: uid,
id: id
};
/**
* 删除地址
*
* @param int $uid 用户ID
* @param int $id 地址唯一标识符id
* @return array 接口返回的数据
*/
exports.deleteAddress = (uid, id) => {
return api.get('', {
method: 'app.address.del',
uid: uid,
id: id
});
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 设置默认地址
*
* @param int $uid 用户ID
* @param int $id 地址唯一标识符id
* @return array 接口返回的数据
*/
setDefaultAddress(uid, id) {
let data = {
method: 'app.address.setdefault',
uid: uid,
id: id
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 设置默认地址
*
* @param int $uid 用户ID
* @param int $id 地址唯一标识符id
* @return array 接口返回的数据
*/
exports.setDefaultAddress = (uid, id) => {
return api.get('', {
method: 'app.address.setdefault',
uid: uid,
id: id
});
};
... ...
... ... @@ -3,188 +3,214 @@
* @author gaohongwei <hongwei.gao@yoho.cn>
* @date: 2016/9/5
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const addressApi = require('./address-api');
/*
* 个人中心-地址管理列表
*
* @param int $uid 用户ID
* @return array|mixed 处理之后的返回数据
*
*/
const getAddressList = (uid, limit) => {
return co(function*() {
let result = [],
addressData = yield addressApi.addressData(uid, limit);
if (addressData.data) {
let addressList = addressData.data;
for (let i = 0; i < addressList.length; i++) {
let phone = _.get(addressList[i], 'phone') === 'null' ? '' : addressList[i].phone;
let zipCode = _.get(addressList[i], 'zip_code') === 'null' ? '' : addressList[i].zip_code;
result.push({
id: addressList[i].address_id || '',
addressee: addressList[i].consignee || '',
address: addressList[i].area + addressList[i].address + ' ' + zipCode,
phone: (addressList[i].mobile || '') + ' ' + phone,
isPreferred: addressList[i].is_default === 'Y' ? 'true' : ''// 默认地址
});
}
}
return result;
})();
};
/**
* 地址管理列表
*/
exports.getAddressInfo = (uid) => {
return co(function*() {
let resq = {},
addressList = yield getAddressList(uid);
resq.address = {
submitId: 'address-info',
addressList: addressList,
data: [{
key: 'addressName',
labelText: '收货人姓名:',
value: '',
tips: '请输入收货人姓名'
}, {
isSelect: true,
labelText: '省份:',
tipsUrl: '/help/?category_id=48',
selects: [{
key: 'province'
},
{
key: 'city'
},
{
key: 'areaCode'
},
{
key: 'streets'
}
]
}, {
key: 'address',
labelText: '地址:',
value: '',
tips: '请填写详细地址'
}, {
key: 'zipCode',
labelText: '邮编:',
value: '',
tips: '请输入收货人所在地邮编号'
}, {
key: 'phone',
labelText: '固定电话:',
value: '',
tips: '请输入你的联系电话,可以为空哦'
}, {
key: 'mobile',
labelText: '手机号码:',
value: '',
tips: '填写手机号便于接收发货和收货通知'
}]
};
return resq;
})();
};
/**
* 编辑修改地址
*/
exports.editAddress = (params, uid) => {
return co(function*() {
let id = params.id,
respData = {};
let data = yield addressApi.addressData(uid);
respData.code = data.code;
// 获取该用户对应的地址id数据
if (data.data) {
let addressList = data.data;
for (let i = 0; i < addressList.length; i++) {
if (addressList[i].address_id === id) {
addressList[i].phone = _.get(addressList[i], 'phone') === 'null' ?
'' : addressList[i].phone;
addressList[i].zip_code = _.get(addressList[i], 'zip_code') === 'null' ?
'' : addressList[i].zip_code;
respData.data = addressList[i];
break;
}
}
}
if (!('data' in respData)) {
respData.message = '无数据返回';
}
return respData;
})();
};
/**
* 添加保存地址
*/
exports.saveAddress = (params, uid) => {
return co(function*() {
let query = {
uid: uid,
address: _.trim(params.address || ''),
area_code: _.trim(params.streets || ''),
consignee: _.trim(params.addressName || ''),
id: params.addrId === '0' ? null : params.addrId,
mobile: _.trim(params.mobile || ''),
phone: _.trim(params.phone || ''),
zip_code: _.trim(params.zipCode || '')
};
if (query.uid === '' || query.address === '' ||
query.area_code.length < 6 || query.consignee === '' ||
query.zip_code === '') {
return {
code: 400,
message: '请填写完整的省市区信息'
};
}
let respData = yield addressApi.saveAddressData(query);
return respData;
})();
};
/**
* 删除地址
*/
exports.delAddress = (params, uid) => {
return co(function*() {
let respData = yield addressApi.deleteAddress(uid, params.id);
return respData;
})();
};
/**
* 设置默认地址
*/
exports.defaultAddress = (params, uid) => {
return co(function*() {
let respData = yield addressApi.setDefaultAddress(uid, params.id);
return respData;
})();
};
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const AddressApi = require('./address-api');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/*
* 个人中心-地址管理列表
*
* @param int $uid 用户ID
* @return array|mixed 处理之后的返回数据
*
*/
getAddressList(uid, limit) {
let that = this;
return co(function*() {
let addressDataModel = new AddressApi(that.ctx);
let result = [],
addressData = yield addressDataModel.addressData(uid, limit);
if (addressData.data) {
let addressList = addressData.data;
for (let i = 0; i < addressList.length; i++) {
let phone = _.get(addressList[i], 'phone') === 'null' ? '' : addressList[i].phone;
let zipCode = _.get(addressList[i], 'zip_code') === 'null' ? '' : addressList[i].zip_code;
result.push({
id: addressList[i].address_id || '',
addressee: addressList[i].consignee || '',
address: addressList[i].area + addressList[i].address + ' ' + zipCode,
phone: (addressList[i].mobile || '') + ' ' + phone,
isPreferred: addressList[i].is_default === 'Y' ? 'true' : ''// 默认地址
});
}
}
return result;
})();
}
/**
* 地址管理列表
*/
getAddressInfo(uid) {
let that = this;
return co(function*() {
let resq = {},
addressList = yield that.getAddressList(uid);
resq.address = {
submitId: 'address-info',
addressList: addressList,
data: [{
key: 'addressName',
labelText: '收货人姓名:',
value: '',
tips: '请输入收货人姓名'
}, {
isSelect: true,
labelText: '省份:',
tipsUrl: '/help/?category_id=48',
selects: [{
key: 'province'
},
{
key: 'city'
},
{
key: 'areaCode'
},
{
key: 'streets'
}
]
}, {
key: 'address',
labelText: '地址:',
value: '',
tips: '请填写详细地址'
}, {
key: 'zipCode',
labelText: '邮编:',
value: '',
tips: '请输入收货人所在地邮编号'
}, {
key: 'phone',
labelText: '固定电话:',
value: '',
tips: '请输入你的联系电话,可以为空哦'
}, {
key: 'mobile',
labelText: '手机号码:',
value: '',
tips: '填写手机号便于接收发货和收货通知'
}]
};
return resq;
})();
}
/**
* 编辑修改地址
*/
editAddress(params, uid) {
let that = this;
return co(function*() {
let id = params.id,
respData = {};
let addressDataModel = new AddressApi(that.ctx);
let data = yield addressDataModel.addressData(uid);
respData.code = data.code;
// 获取该用户对应的地址id数据
if (data.data) {
let addressList = data.data;
for (let i = 0; i < addressList.length; i++) {
if (addressList[i].address_id === id) {
addressList[i].phone = _.get(addressList[i], 'phone') === 'null' ?
'' : addressList[i].phone;
addressList[i].zip_code = _.get(addressList[i], 'zip_code') === 'null' ?
'' : addressList[i].zip_code;
respData.data = addressList[i];
break;
}
}
}
if (!('data' in respData)) {
respData.message = '无数据返回';
}
return respData;
})();
}
/**
* 添加保存地址
*/
saveAddress(params, uid) {
let that = this;
return co(function*() {
let query = {
uid: uid,
address: _.trim(params.address || ''),
area_code: _.trim(params.streets || ''),
consignee: _.trim(params.addressName || ''),
id: params.addrId === '0' ? null : params.addrId,
mobile: _.trim(params.mobile || ''),
phone: _.trim(params.phone || ''),
zip_code: _.trim(params.zipCode || '')
};
let addressDataModel = new AddressApi(that.ctx);
if (query.uid === '' || query.address === '' ||
query.area_code.length < 6 || query.consignee === '' ||
query.zip_code === '') {
return {
code: 400,
message: '请填写完整的省市区信息'
};
}
let respData = yield addressDataModel.saveAddressData(query);
return respData;
})();
}
/**
* 删除地址
*/
delAddress(params, uid) {
let that = this;
return co(function*() {
let addressDataModel = new AddressApi(that.ctx);
let respData = yield addressDataModel.deleteAddress(uid, params.id);
return respData;
})();
}
/**
* 设置默认地址
*/
defaultAddress(params, uid) {
let that = this;
return co(function*() {
let addressDataModel = new AddressApi(that.ctx);
let respData = yield addressDataModel.setDefaultAddress(uid, params.id);
return respData;
})();
}
};
... ...
... ... @@ -2,42 +2,59 @@
* @author: weiqingting<qingting.wei@yoho.cn>
*/
'use strict';
const api = global.yoho.API;
const yohoCoinList = (uid, condition)=>{
condition = condition || {};
let options = {
method: 'app.yohocoin.lists',
uid: uid,
page: 1,
limit: 15
};
Object.assign(options, condition);
return api.get('', options);
};
const yohoCoinTotal = uid=>{
let options = {
method: 'app.yoho.yohocoin',
uid: uid
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return api.get('', options);
};
yohoCoinList(uid, condition) {
condition = condition || {};
let data = {
method: 'app.yohocoin.lists',
uid: uid,
page: 1,
limit: 15
};
const getProduct = (skn, limit)=>{
let options = {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
};
Object.assign(data, condition);
return this.get({
data: data,
param: {
code: 200
}
});
}
return api.get('', options);
};
yohoCoinTotal(uid) {
let data = {
method: 'app.yoho.yohocoin',
uid: uid
};
return this.get({
data: data,
param: {
code: 200
}
});
}
getProduct(skn, limit) {
let data = {
method: 'h5.product.batch',
productSkn: skn,
limit: limit
};
return this.get({
data: data,
param: {
code: 200
}
});
}
module.exports = {
yohoCoinList,
yohoCoinTotal,
getProduct
};
... ...
... ... @@ -9,7 +9,7 @@ const co = Promise.coroutine;
const path = require('path');
const helpers = global.yoho.helpers;
const _ = require('lodash');
const currencyApi = require('./currency-api');
const CurrencyApi = require('./currency-api');
// 使用 product中的分页逻辑
const pagerPath = path.join(global.appRoot, '/apps/product/models/public-handler.js');
... ... @@ -17,136 +17,145 @@ const pager = require(pagerPath).handlePagerData;
const moment = require('moment');
const convertUnitTime = (src) => {
return moment.unix(src).format('YYYY-MM-DD');
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
convertUnitTime(src) {
return moment.unix(src).format('YYYY-MM-DD');
}
const currencyTabs = (type)=>{
let tabs = ['全部明细', '全部收入', '全部支出'],
result = [];
currencyTabs(type) {
let tabs = ['全部明细', '全部收入', '全部支出'],
result = [];
tabs.forEach(function(val, key) {
result.push({
active: key === parseInt(type, 10) ? true : false,
url: helpers.urlFormat('/home/currency', {type: key}),
name: val
tabs.forEach(function(val, key) {
result.push({
active: key === parseInt(type, 10) ? true : false,
url: helpers.urlFormat('/home/currency', {type: key}),
name: val
});
});
});
return result;
};
return result;
}
const currencyOptions = (condition)=>{
let result = [], paramUrl = {};
let tabs = {90: '最近3个月明细', 180: '最近半年明细', 360: '最近一年明细'};
currencyOptions(condition) {
let that = this;
let result = [], paramUrl = {};
let tabs = {90: '最近3个月明细', 180: '最近半年明细', 360: '最近一年明细'};
for (let name in tabs) {
if (condition.queryType) {
paramUrl.type = condition.queryType;
}
paramUrl.beginTime = convertUnitTime(new Date() / 1000 - parseInt(name, 10) * 3600 * 24);
for (let name in tabs) {
if (condition.queryType) {
paramUrl.type = condition.queryType;
}
paramUrl.beginTime = that.convertUnitTime(new Date() / 1000 - parseInt(name, 10) * 3600 * 24);
result.push({
url: helpers.urlFormat('/home/currency', paramUrl),
name: tabs[name],
selected: condition.beginTime && paramUrl.beginTime === condition.beginTime ? true : false
});
result.push({
url: helpers.urlFormat('/home/currency', paramUrl),
name: tabs[name],
selected: condition.beginTime && paramUrl.beginTime === condition.beginTime ? true : false
});
}
return result;
}
return result;
};
const currencyList = (uid, condition)=>{
return co(function*() {
let result = {list: [], pager: []};
currencyList(uid, condition) {
let that = this;
return co(function*() {
let result = {list: [], pager: []};
condition.limit = condition.limit || 15;
condition.limit = condition.limit || 15;
let data = yield currencyApi.yohoCoinList(uid, condition);
let currencyDataModel = new CurrencyApi(that.ctx);
let data = yield currencyDataModel.yohoCoinList(uid, condition);
if (_.get(data, 'code') === 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
if (_.get(data, 'code') === 200 && data.data.coinlist && !_.isEmpty(data.data.coinlist)) {
for (let key = 0; key < data.data.coinlist.length; key++) {
let val = data.data.coinlist[key];
for (let key = 0; key < data.data.coinlist.length; key++) {
let val = data.data.coinlist[key];
result.list[key] = {
date: val.date,
desc: val.message,
isIncome: true
};
result.list[key] = {
date: val.date,
desc: val.message,
isIncome: true
};
// 2:订单取消退还,9:下单使用,10:退货退还
if ([2, 9, 10].indexOf(val.type) > -1 && val.key) {
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val.key});
} else if (Number(val.type) === 14 && val.key) { // 晒单奖励
let product = yield currencyApi.getProduct(Number(val.key), 1);
// 2:订单取消退还,9:下单使用,10:退货退还
if ([2, 9, 10].indexOf(val.type) > -1 && val.key) {
result.list[key].detailUrl = helpers.urlFormat('/home/orders/detail', {orderCode: val.key});
} else if (Number(val.type) === 14 && val.key) { // 晒单奖励
let product = yield currencyDataModel.getProduct(Number(val.key), 1);
if (_.get(product, 'code') === 200 &&
!_.isEmpty(product.data.product_list) &&
!_.isEmpty(product.data.product_list[0].goods_list)) {
let productSkn = _.get(product, 'data.product_list[0].product_skn');
if (_.get(product, 'code') === 200 &&
!_.isEmpty(product.data.product_list) &&
!_.isEmpty(product.data.product_list[0].goods_list)) {
let productSkn = _.get(product, 'data.product_list[0].product_skn');
result.list[key].detailUrl = helpers.getUrlBySkc(productSkn);
result.list[key].detailUrl = helpers.getUrlBySkc(productSkn);
}
}
if (Number(val.num) < 0) {
result.list[key].isIncome = false;
}
result.list[key].value = val.num > 0 ? '+' + val.num : val.num;
}
if (Number(val.num) < 0) {
result.list[key].isIncome = false;
}
result.list[key].value = val.num > 0 ? '+' + val.num : val.num;
}
// 分页
result.pager = Object.assign({
count: data.data.total,
curPage: data.data.page,
totalPages: Math.ceil(data.data.total / condition.limit)
}, pager(data.data.total, {
page: condition.page,
limit: condition.limit,
type: condition.queryType,
beginTime: condition.beginTime
}));
// 分页
result.pager = Object.assign({
count: data.data.total,
curPage: data.data.page,
totalPages: Math.ceil(data.data.total / condition.limit)
}, pager(data.data.total, {
page: condition.page,
limit: condition.limit,
type: condition.queryType,
beginTime: condition.beginTime
}));
}
return result;
})();
};
}
return result;
})();
}
const currencyData = (uid, prama)=>{
let condition = {
page: prama.page || 1,
queryType: prama.type || 0,
beginTime: prama.beginTime || convertUnitTime(new Date() / 1000 - 3600 * 24 * 90)
};
return co(function*() {
let result = {};
let yohoCoinInfo = yield currencyApi.yohoCoinTotal(uid);
if (_.get(yohoCoinInfo, 'code') === 200) {
let yohoCoinInfoData = yohoCoinInfo.data;
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
if (_.get(yohoCoinInfoData, 'nearExpCoinNum') > 0) {
result.tip = {
count: yohoCoinInfoData.nearExpCoinNum,
date: new Date().getFullYear() + '年12月31日'
};
currencyData(uid, prama) {
let that = this;
let condition = {
page: prama.page || 1,
queryType: prama.type || 0,
beginTime: prama.beginTime || that.convertUnitTime(new Date() / 1000 - 3600 * 24 * 90)
};
return co(function*() {
let result = {};
let currencyDataModel = new CurrencyApi(that.ctx);
let yohoCoinInfo = yield currencyDataModel.yohoCoinTotal(uid);
if (_.get(yohoCoinInfo, 'code') === 200) {
let yohoCoinInfoData = yohoCoinInfo.data;
result.myCurrency = yohoCoinInfoData.yohocoin_num ? yohoCoinInfoData.yohocoin_num : 0;
if (_.get(yohoCoinInfoData, 'nearExpCoinNum') > 0) {
result.tip = {
count: yohoCoinInfoData.nearExpCoinNum,
date: new Date().getFullYear() + '年12月31日'
};
}
}
}
let currency = yield currencyList(uid, condition);
Object.assign(result, {
currency: currency.list,
pager: currency.pager,
coinHelperUrl: '//www.yohobuy.com/help/detail?id=105', // yoho币帮助
tabs: currencyTabs(condition.queryType),
options: currencyOptions(condition)
});
let currency = yield that.currencyList(uid, condition);
return result;
})();
Object.assign(result, {
currency: currency.list,
pager: currency.pager,
coinHelperUrl: '//www.yohobuy.com/help/detail?id=105', // yoho币帮助
tabs: that.currencyTabs(condition.queryType),
options: that.currencyOptions(condition)
});
};
return result;
})();
}
module.exports = {
currencyData
};
... ...
... ... @@ -2,178 +2,192 @@
const _ = require('lodash');
const userApi = require('./user-api');
const UserApi = require('./user-api');
const headerModel = require('../../../doraemon/models/header');
const msgModel = require('./message');
const MsgApi = require('./message');
const helpers = global.yoho.helpers;
const defaultAvatar = '//img10.static.yhbimg.com/headimg/' +
'2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
const _homeNav = (switcher) => {
return [
{
title: '交易管理',
subNav: [
{name: '我的订单', href: '/home/orders', catchs: ['/home/orders', '/home/index', '/home/orders/detail']},
{name: '我的收藏', href: '/home/favorite', catchs: ['/home/favorite/reduction']},
{name: '我的有货币', href: '/home/currency'},
{name: '我的红包', href: '/home/redenvelopes'},
{name: '我的优惠券', href: '/home/coupons'},
{name: '我的VIP', href: '/home/vip'}
]
},
{
title: '服务中心',
subNav: [
{name: '我的退/换货', href: '/home/returns'},
{name: '我的咨询', href: '/home/consult'},
{name: '我的评论', href: '/home/comment'},
// {name: '我的投诉', href: '/home/complaints'},
{name: '我的邀请好友', href: '/home/spread'},
{name: '我的信息', href: '/home/message', count: 0},
{
name: '在线客服',
href: switcher ?
'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409' : '/service/client',
isBlank: true
}
]
},
{
title: '个人信息管理',
subNav: [
{name: '编辑个人资料', href: '/home/user'},
{name: '账号安全', href: '/home/account', catchs: [
'/home/account/userpwd',
'/home/account/email',
'/home/account/mobile',
'/home/account/checkverifycode',
'/home/account/checkpassword',
'/home/account/verifypassword',
'/home/account/modifypwd',
'/home/account/sendemail',
'/home/account/checkemail',
'/home/account/modifyemail',
'/home/account/sendemailsuccess',
'/home/account/mailresult',
'/home/account/checkmobile',
'/home/account/checkmobilemsg',
'/home/account/sendmobilemsg',
'/home/account/modifymobile'
]},
{name: '地址管理', href: '/home/address'},
{name: '兑换礼品卡', href: '/home/gift'}
]
}
];
};
const _getActiveNav = (url, switcher, count) =>{
let mHomeNav = _.cloneDeep(_homeNav(switcher));
let activeNav = null;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_homeNav(switcher) {
return [
{
title: '交易管理',
subNav: [
{name: '我的订单', href: '/home/orders',
catchs: ['/home/orders', '/home/index', '/home/orders/detail']},
{name: '我的收藏', href: '/home/favorite', catchs: ['/home/favorite/reduction']},
{name: '我的有货币', href: '/home/currency'},
{name: '我的红包', href: '/home/redenvelopes'},
{name: '我的优惠券', href: '/home/coupons'},
{name: '我的VIP', href: '/home/vip'}
]
},
{
title: '服务中心',
subNav: [
{name: '我的退/换货', href: '/home/returns'},
{name: '我的咨询', href: '/home/consult'},
{name: '我的评论', href: '/home/comment'},
// {name: '我的投诉', href: '/home/complaints'},
{name: '我的邀请好友', href: '/home/spread'},
{name: '我的信息', href: '/home/message', count: 0},
{
name: '在线客服',
href: switcher ?
'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409' : '/service/client',
isBlank: true
}
]
},
{
title: '个人信息管理',
subNav: [
{name: '编辑个人资料', href: '/home/user'},
{name: '账号安全', href: '/home/account', catchs: [
'/home/account/userpwd',
'/home/account/email',
'/home/account/mobile',
'/home/account/checkverifycode',
'/home/account/checkpassword',
'/home/account/verifypassword',
'/home/account/modifypwd',
'/home/account/sendemail',
'/home/account/checkemail',
'/home/account/modifyemail',
'/home/account/sendemailsuccess',
'/home/account/mailresult',
'/home/account/checkmobile',
'/home/account/checkmobilemsg',
'/home/account/sendmobilemsg',
'/home/account/modifymobile'
]},
{name: '地址管理', href: '/home/address'},
{name: '兑换礼品卡', href: '/home/gift'}
]
}
];
}
mHomeNav = mHomeNav.map((item) => {
item.subNav = item.subNav.map((nav) => {
_getActiveNav(url, switcher, count) {
let that = this;
let mHomeNav = _.cloneDeep(that._homeNav(switcher));
let activeNav = null;
let curMatchPath = url;
mHomeNav = mHomeNav.map((item) => {
item.subNav = item.subNav.map((nav) => {
if (!nav.matchQuery && curMatchPath.indexOf('?') >= 0) { // 严格的路径匹配,包含后面的参数
curMatchPath = curMatchPath.substr(0, curMatchPath.indexOf('?'));
}
let curMatchPath = url;
if (curMatchPath === nav.href) {
nav.active = true;
}
if (!nav.matchQuery && curMatchPath.indexOf('?') >= 0) { // 严格的路径匹配,包含后面的参数
curMatchPath = curMatchPath.substr(0, curMatchPath.indexOf('?'));
}
if (nav.name === '我的信息') {
nav.count = +count;
}
if (curMatchPath === nav.href) {
nav.active = true;
}
if (nav.catchs) {
let index = nav.catchs.indexOf(curMatchPath);
if (nav.name === '我的信息') {
nav.count = +count;
}
if (index > -1) {
nav.active = true;
nav.curHref = nav.catchs[index];
if (nav.catchs) {
let index = nav.catchs.indexOf(curMatchPath);
if (index > -1) {
nav.active = true;
nav.curHref = nav.catchs[index];
}
}
}
if (nav.active) {
activeNav = nav;
}
if (nav.active) {
activeNav = nav;
}
nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
return nav;
nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
return nav;
});
return item;
});
return item;
});
return {
homeNav: mHomeNav,
activeNav: activeNav
};
};
return {
homeNav: mHomeNav,
activeNav: activeNav
};
}
const _getAvatar = (uid) => {
return userApi.getUserInfo(uid).then((result) => {
return _.get(result, 'data.head_ico', '') || defaultAvatar;
});
};
_getAvatar(uid) {
let userDataModel = new UserApi(this.ctx);
const _msgCount = (uid) => {
return msgModel.unreadTotal(uid).then(result => _.get(result, 'data.total', 0));
};
return userDataModel.getUserInfo(uid).then((result) => {
return _.get(result, 'data.head_ico', '') || defaultAvatar;
});
}
const _getTabsData = (uid, channel) => {
return Promise.props({
msg: _msgCount(uid),
header: headerModel.requestHeaderData(channel),
avatar: _getAvatar(uid)
});
};
_msgCount(uid) {
let msgDataModel = new MsgApi(this.ctx);
const getHomeNav = (uid, channel, url, clientSwitcher) => {
return _getTabsData(uid, channel).then((result) => {
let navs = _getActiveNav(url, clientSwitcher, result.msg);
return msgDataModel.unreadTotal(uid).then(result => _.get(result, 'data.total', 0));
}
let activeNav = navs.activeNav;
let bread = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}];
_getTabsData(uid, channel) {
let that = this;
if (activeNav) {
bread.push({
name: '个人中心',
href: helpers.urlFormat('/home')
});
return Promise.props({
msg: that._msgCount(uid),
header: headerModel.requestHeaderData(channel),
avatar: that._getAvatar(uid)
});
}
bread.push({
name: activeNav.name
});
getHomeNav(uid, channel, url, clientSwitcher) {
let that = this;
return that._getTabsData(uid, channel).then((result) => {
let navs = that._getActiveNav(url, clientSwitcher, result.msg);
let activeNav = navs.activeNav;
let bread = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}];
if (activeNav) {
bread.push({
name: '个人中心',
href: helpers.urlFormat('/home')
});
// 订单详情
if (activeNav.curHref === '/home/orders/detail') {
Object.assign(_.last(bread), {
href: helpers.urlFormat('/home/orders')
bread.push({
name: activeNav.name
});
// 订单详情
if (activeNav.curHref === '/home/orders/detail') {
Object.assign(_.last(bread), {
href: helpers.urlFormat('/home/orders')
});
bread.push({
name: '订单详情'
});
}
} else {
bread.push({
name: '订单详情'
name: '个人中心'
});
}
} else {
bread.push({
name: '个人中心'
});
}
return Object.assign({
path: bread,
homeNav: navs.homeNav,
userThumb: result.avatar
}, result.header);
});
};
module.exports = {
getHomeNav
return Object.assign({
path: bread,
homeNav: navs.homeNav,
userThumb: result.avatar
}, result.header);
});
}
};
... ...
... ... @@ -7,53 +7,67 @@
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const userApi = require('./user-api');
const currencyApi = require('./currency-api');
const UserApi = require('./user-api');
const CurrencyApi = require('./currency-api');
/**
* 礼品卡页面
*/
exports.index = (params, uid) => {
return co(function*() {
let respData = {},
type = params.type || '',
yohoCoinResult;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 礼品卡页面
*/
index(params, uid) {
let that = this;
if (type !== '') {
yohoCoinResult = yield currencyApi.yohoCoinTotal(uid);
let yohoCoinInfo = yohoCoinResult.data;
return co(function*() {
let respData = {},
type = params.type || '',
yohoCoinResult;
let currencyDataModel = new CurrencyApi(that.ctx);
if (yohoCoinInfo) {
if (type !== '') {
yohoCoinResult = yield currencyDataModel.yohoCoinTotal(uid);
let yohoCoinInfo = yohoCoinResult.data;
if (yohoCoinInfo) {
respData.gift = {
resultInfo: {
success: (Number(type) === 1) ? true : false,
yohoCoin: yohoCoinInfo.yohocoin_num ? yohoCoinInfo.yohocoin_num : 0
}
};
}
} else {
respData.gift = {
resultInfo: {
success: (Number(type) === 1) ? true : false,
yohoCoin: yohoCoinInfo.yohocoin_num ? yohoCoinInfo.yohocoin_num : 0
}
resultInfo: false
};
}
} else {
respData.gift = {
resultInfo: false
};
}
return respData;
})();
};
/**
* 个人中心-兑换礼品卡提交返回信息
*/
exports.exchange = (req, params, uid) => {
return co(function*() {
let data = {};
return respData;
})();
}
/**
* 个人中心-兑换礼品卡提交返回信息
*/
exchange(req, params, uid) {
let that = this;
return co(function*() {
let data = {};
let userDataModel = new UserApi(that.ctx);
data.giftCardCode1 = _.trim(params.giftCardCode1 || '');
data.giftCardCode2 = _.trim(params.giftCardCode2 || '');
data.giftCardCode3 = _.trim(params.giftCardCode3 || '');
data.giftCardCode1 = _.trim(params.giftCardCode1 || '');
data.giftCardCode2 = _.trim(params.giftCardCode2 || '');
data.giftCardCode3 = _.trim(params.giftCardCode3 || '');
let respData = yield userApi.exchangeGift(data, uid);
let respData = yield userDataModel.exchangeGift(data, uid);
return respData;
})();
}
return respData;
})();
};
... ...
... ... @@ -5,367 +5,424 @@
*/
'use strict';
const api = global.yoho.API;
const _ = require('lodash');
const Promise = require('bluebird');
const userApi = require('./user-api');
const UserApi = require('./user-api');
const setPager = require(`${global.utils}/pager`).setPager;
const co = Promise.coroutine;
const getMessageTabList = (uid) => {
return api.get('', {
method: 'app.inbox.getAllInboxCatInfo',
uid: uid
}, {code: 200});
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getMessageTabList(uid) {
const getMessageAsync = (uid, page, size, type) => {
let params = {
method: 'app.inbox.getlistnew',
uid: uid,
page: page || 1,
size: size || 10
};
let data = {
method: 'app.inbox.getAllInboxCatInfo',
uid: uid
};
if (type) {
params.displayTab = type;
return this.get({
data: data,
param: {
code: 200
}
});
}
return api.get('', params, {code: 200});
};
getMessageAsync(uid, page, size, type) {
let data = {
method: 'app.inbox.getlistnew',
uid: uid,
page: page || 1,
size: size || 10
};
const delMessageAsync = (uid, id) => {
return api.get('', {
method: 'app.inbox.delmessage',
uid: uid,
id: id
});
};
if (type) {
data.displayTab = type;
}
const readMessageAsync = (uid, id) => {
return api.get('', {
method: 'web.inbox.setread',
uid: uid,
ids: id
});
};
return this.get({
data: data,
param: {
code: 200
}
});
}
const getBirthCouponAsync = (uid, couponId) => {
return api.get('', {
method: 'app.promotion.getCoupon',
uid: uid,
couponId: couponId
});
};
delMessageAsync(uid, id) {
/**
* 根据用户uid获取生日券id
* @function getCouponAsync
* @param { Number } uid 用户uid
* @return { Object } 生日券数据
*/
const getCouponAsync = (uid) => {
return api.get('', {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
couponType: 4
}, {code: 200});
let data = {
method: 'app.inbox.delmessage',
uid: uid,
id: id
};
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 未读消息
* @function unreadTotal
* @param { Number } uid 用户uid
* @return { Number } 未读消息数量
*/
const unreadTotal = (uid) => {
return api.get('', {
method: 'app.inbox.getTotal',
uid: uid,
is_read: 'N'
});
};
readMessageAsync(uid, id) {
/**
* 获取消息列表
* @function getMessageList
* @param { Number } uid 用户uid
* @param { Object } params url参数
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
const getMessageList = (uid, params, limit) => {
let resData = {};
let page = parseInt(`0${params.page}`, 10) || 1,
type = parseInt(`0${params.type}`, 10);
return Promise.all([
userApi.getUserInfo(uid),
getMessageTabList(uid),
getMessageAsync(uid, page, limit, type)
]).then(result => {
const msgBaseUrl = '/home/message';
resData.userThumb = _.get(result, '[0].data.head_ico', '');
let tabList = [{
name: '全部',
focus: !type,
href: msgBaseUrl
}];
let focusTabName = '';
_.forEach(_.get(result, '[1]data.list', []), value => {
let tab = {
name: `${value.inboxCatName}`,
focus: type === value.id * 1,
href: `${msgBaseUrl}?type=${value.id}`
};
let data = {
method: 'web.inbox.setread',
uid: uid,
ids: id
};
if (value.unReadCount * 1) {
tab.name += ` (${value.unReadCount})`;
return this.get({
data: data,
param: {
code: 200
}
});
}
if (tab.focus) {
focusTabName = value.inboxCatName;
getBirthCouponAsync(uid, couponId) {
let data = {
method: 'app.promotion.getCoupon',
uid: uid,
couponId: couponId
};
return this.get({
data: data,
param: {
code: 200
}
});
}
/**
* 根据用户uid获取生日券id
* @function getCouponAsync
* @param { Number } uid 用户uid
* @return { Object } 生日券数据
*/
getCouponAsync(uid) {
let data = {
method: 'app.promotion.queryBirthCoupon',
uid: uid,
couponType: 4
};
tabList.push(tab);
return this.get({
data: data,
param: {
code: 200
}
});
resData.tabList = tabList;
}
if (result[2].data) {
let data = result[2].data;
let msg = [];
/**
* 未读消息
* @function unreadTotal
* @param { Number } uid 用户uid
* @return { Number } 未读消息数量
*/
unreadTotal(uid) {
let data = {
method: 'app.inbox.getTotal',
uid: uid,
is_read: 'N'
};
_.forEach(_.get(data, 'list', []), value => {
// 信息过滤
if (value.type === '$inboxval' || value.type === 'notice') {
return;
}
return this.get({
data: data,
param: {
code: 200
}
});
}
let href = `/home/message/detail?id=${value.id}&page=${page}`;
/**
* 获取消息列表
* @function getMessageList
* @param { Number } uid 用户uid
* @param { Object } params url参数
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
getMessageList(uid, params, limit) {
let that = this;
let resData = {};
let page = parseInt(`0${params.page}`, 10) || 1,
type = parseInt(`0${params.type}`, 10);
let userDataModel = new UserApi(that.ctx);
return Promise.all([
userDataModel.getUserInfo(uid),
that.getMessageTabList(uid),
that.getMessageAsync(uid, page, limit, type)
]).then(result => {
const msgBaseUrl = '/home/message';
resData.userThumb = _.get(result, '[0].data.head_ico', '');
let tabList = [{
name: '全部',
focus: !type,
href: msgBaseUrl
}];
let focusTabName = '';
_.forEach(_.get(result, '[1]data.list', []), value => {
let tab = {
name: `${value.inboxCatName}`,
focus: type === value.id * 1,
href: `${msgBaseUrl}?type=${value.id}`
};
if (value.unReadCount * 1) {
tab.name += ` (${value.unReadCount})`;
}
href += type ? `&type=${type}` : '';
switch (value.type) {
case 'pullCoupon':
case 'button':
case 'pushCoupon':
break;
default:
if (value.pcLink) {
href = value.pcLink.replace('http:', '');
}
break;
if (tab.focus) {
focusTabName = value.inboxCatName;
}
msg.push({
id: value.id || 0,
href: href,
title: value.title || '',
content: _.get(value, 'body.content', ''),
sender: value.from || '',
time: value.create_date,
isNew: value.is_read === 'Y' ? false : true
});
tabList.push(tab);
});
resData.messages = msg;
resData.tabList = tabList;
let pagerList = setPager(_.get(data, 'page_total', 1),
Object.assign(params, {page: page}));
if (result[2].data) {
let data = result[2].data;
let msg = [];
resData.pager = Object.assign({
count: _.get(data, 'total', 0),
curPage: page,
totalPages: _.get(data, 'page_total', 0)
}, pagerList);
}
_.forEach(_.get(data, 'list', []), value => {
// 信息过滤
if (value.type === '$inboxval' || value.type === 'notice') {
return;
}
if (_.isEmpty(resData.messages)) {
resData.messages = {empty: `您尚未收到任何${focusTabName}消息`};
}
let href = `/home/message/detail?id=${value.id}&page=${page}`;
href += type ? `&type=${type}` : '';
switch (value.type) {
case 'pullCoupon':
case 'button':
case 'pushCoupon':
break;
default:
if (value.pcLink) {
href = value.pcLink.replace('http:', '');
}
break;
}
return resData;
});
};
msg.push({
id: value.id || 0,
href: href,
title: value.title || '',
content: _.get(value, 'body.content', ''),
sender: value.from || '',
time: value.create_date,
isNew: value.is_read === 'Y' ? false : true
});
});
/**
* 获取消息内容
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Object } params url参数
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
const getMessageDetail = (uid, params, limit) => {
let mid = parseInt(`0${params.id}`, 10);
let page = parseInt(`0${params.page}`, 10) || 1;
let type = parseInt(`0${params.type}`, 10);
let process = function*() {
let result = yield Promise.all([
userApi.getUserInfo(uid),
getMessageAsync(uid, page, limit, type)
]);
let resData = {
backUrl: `/home/message?page=${page}`,
userThumb: _.get(result, '[0].data.head_ico', '')
};
let msg = _.find(_.get(result, '[1]data.list', []), {id: mid});
resData.messages = msg;
if (type) {
resData.backUrl += `&type=${type}`;
}
let pagerList = setPager(_.get(data, 'page_total', 1),
Object.assign(params, {page: page}));
resData.pager = Object.assign({
count: _.get(data, 'total', 0),
curPage: page,
totalPages: _.get(data, 'page_total', 0)
}, pagerList);
}
if (_.isEmpty(resData.messages)) {
resData.messages = {empty: `您尚未收到任何${focusTabName}消息`};
}
return resData;
});
}
if (!_.isEmpty(msg)) {
resData.message = {
sender: msg.from, // 消息发言人
title: msg.title, // 消息标题
time: msg.create_date // 消息创建时间
/**
* 获取消息内容
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Object } params url参数
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
getMessageDetail(uid, params, limit) {
let that = this;
let mid = parseInt(`0${params.id}`, 10);
let page = parseInt(`0${params.page}`, 10) || 1;
let type = parseInt(`0${params.type}`, 10);
let userDataModel = new UserApi(that.ctx);
let process = function*() {
let result = yield Promise.all([
userDataModel.getUserInfo(uid),
that.getMessageAsync(uid, page, limit, type)
]);
let resData = {
backUrl: `/home/message?page=${page}`,
userThumb: _.get(result, '[0].data.head_ico', '')
};
let msg = _.find(_.get(result, '[1]data.list', []), {id: mid});
switch (msg.type) {
case 'pullCoupon': // eslint-disable-line
resData.message.birthCoupon = {
text: `${_.get(result, '[0].data.nickname', '')} 有货祝您生日快乐!感谢您对有货的支持,特赠您VIP生日专属礼,即刻享受生日福利吧!`
};
if (_.get(msg, 'body.is_collar', '') === 'Y') {
Object.assign(resData.message.birthCoupon, {
over: true,
overText: '已领取'
});
break;
}
if (type) {
resData.backUrl += `&type=${type}`;
}
if (_.get(msg, 'body.is_over_time', '') === 'Y') {
Object.assign(resData.message.birthCoupon, {
over: true,
overText: '生日券已过期'
});
break;
}
if (!_.isEmpty(msg)) {
resData.message = {
sender: msg.from, // 消息发言人
title: msg.title, // 消息标题
time: msg.create_date // 消息创建时间
};
switch (msg.type) {
case 'pullCoupon': // eslint-disable-line
resData.message.birthCoupon = {
text: `${_.get(result, '[0].data.nickname', '')} 有货祝您生日快乐!感谢您对有货的支持,特赠您VIP生日专属礼,即刻享受生日福利吧!`
};
if (_.get(msg, 'body.is_collar', '') === 'Y') {
Object.assign(resData.message.birthCoupon, {
over: true,
overText: '已领取'
});
break;
}
let couponInfo = yield getCouponAsync(uid);
let coupons = [];
if (_.get(msg, 'body.is_over_time', '') === 'Y') {
Object.assign(resData.message.birthCoupon, {
over: true,
overText: '生日券已过期'
});
break;
}
if (!_.isEmpty(couponInfo.data)) {
_.forEach(couponInfo.data, value => {
let couponInfo = yield that.getCouponAsync(uid);
let coupons = [];
if (!_.isEmpty(couponInfo.data)) {
_.forEach(couponInfo.data, value => {
coupons.push({
id: value.id,
remark: value.couponName || '',
useTime: _.get(msg, 'body.use_time', ''),
pickTime: _.get(msg, 'body.collar_time', ''),
canPick: true
});
});
} else {
// 已过期生日券信息
coupons.push({
id: value.id,
remark: value.couponName || '',
remark: _.get(msg, 'body.name', ''),
useTime: _.get(msg, 'body.use_time', ''),
pickTime: _.get(msg, 'body.collar_time', ''),
canPick: true
pickTime: _.get(msg, 'body.collar_time', '')
});
});
} else {
// 已过期生日券信息
coupons.push({
remark: _.get(msg, 'body.name', ''),
useTime: _.get(msg, 'body.use_time', ''),
pickTime: _.get(msg, 'body.collar_time', '')
});
}
resData.message.coupons = coupons;
break;
case 'button':
// 促销活动
resData.message.sale = {
image: _.get(msg, 'body.image', ''),
content: _.get(msg, 'body.text', ''),
btnLink: _.get(msg, 'body.pc_link', ''),
btnName: _.get(msg, 'body.button_text', '') || '查看详情'
};
break;
case 'pushCoupon':
// 查看优惠券
resData.message.coupons = [{
remark: _.get(msg, 'body.coupon_name', ''),
useTime: _.get(msg, 'body.time', ''),
id: _.get(msg, 'body.inboxId', ''),
price: _.get(msg, 'body.price', ''),
url: '/home/coupons'
}];
break;
default:
// 普通文本
resData.message.text = {
content: _.get(msg, 'body.content', '')
};
break;
}
resData.message.coupons = coupons;
break;
case 'button':
// 促销活动
resData.message.sale = {
image: _.get(msg, 'body.image', ''),
content: _.get(msg, 'body.text', ''),
btnLink: _.get(msg, 'body.pc_link', ''),
btnName: _.get(msg, 'body.button_text', '') || '查看详情'
};
break;
case 'pushCoupon':
// 查看优惠券
resData.message.coupons = [{
remark: _.get(msg, 'body.coupon_name', ''),
useTime: _.get(msg, 'body.time', ''),
id: _.get(msg, 'body.inboxId', ''),
price: _.get(msg, 'body.price', ''),
url: '/home/coupons'
}];
break;
default:
// 普通文本
resData.message.text = {
content: _.get(msg, 'body.content', '')
};
break;
}
}
}
return resData;
};
return resData;
};
return co(process)();
};
return co(process)();
}
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
const delMessage = (uid, mid) => {
let process = function*() {
let resData = {code: 400, message: '删除失败'};
let result = yield delMessageAsync(uid, mid);
if (result.code === 200) {
Object.assign(resData, {
code: 200,
message: '删除成功'
});
}
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
delMessage(uid, mid) {
let that = this;
let process = function*() {
let resData = {code: 400, message: '删除失败'};
let result = yield that.delMessageAsync(uid, mid);
if (result.code === 200) {
Object.assign(resData, {
code: 200,
message: '删除成功'
});
}
return resData;
};
return resData;
};
return co(process)();
};
return co(process)();
}
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
const readMessage = (uid, mid) => {
let process = function*() {
let resData = {code: 400, message: '标记失败'};
let result = yield readMessageAsync(uid, mid);
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
readMessage(uid, mid) {
let that = this;
let process = function*() {
let resData = {code: 400, message: '标记失败'};
let result = yield that.readMessageAsync(uid, mid);
if (result.code === 200) {
resData = result;
}
if (result.code === 200) {
resData = result;
}
return resData;
};
return resData;
};
return co(process)();
}
return co(process)();
};
pickBirthCoupon(uid, id) {
let that = this;
const pickBirthCoupon = (uid, id) => {
return getBirthCouponAsync(uid, id);
return that.getBirthCouponAsync(uid, id);
}
};
module.exports = {
getMessageList,
getMessageDetail,
delMessage,
readMessage,
unreadTotal,
pickBirthCoupon
};
... ...