...
|
...
|
@@ -6,6 +6,7 @@ |
|
|
'use strict';
|
|
|
const Promise = require('bluebird');
|
|
|
const _ = require('lodash');
|
|
|
const md5 = require('md5');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const MeGiftAPi = require('./me-gift-api');
|
|
|
const setPager = require(`${global.utils}/pager`).setPager;
|
...
|
...
|
@@ -137,24 +138,56 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
// 发验手机证码
|
|
|
smsBind(params) {
|
|
|
return this.meGiftAPi.checkIsCanBind(params.area, params.mobile).then(res => {
|
|
|
if (_.get(res, 'data.isCanBind') === 'N') {
|
|
|
return {
|
|
|
code: 401,
|
|
|
message: '<p>绑定失败,该手机号已被绑定</p><p>请更换手机号</p>'
|
|
|
};
|
|
|
return this.meGiftAPi.smsbind(params.area, params.mobile, params.id, params.captcha);
|
|
|
}
|
|
|
|
|
|
// 验证手机号
|
|
|
checkMobile(params, uid) {
|
|
|
let {fcode, ccode} = params;
|
|
|
|
|
|
if (fcode && ccode) {
|
|
|
if (md5(`${ccode}_${uid}`) === fcode) {
|
|
|
return Promise.resolve({code: 200});
|
|
|
} else {
|
|
|
return Promise.resolve({code: 400, message: '信息校验失败,请刷新后重试'});
|
|
|
}
|
|
|
return this.meGiftAPi.smsbind(params.area, params.mobile, params.id, params.captcha);
|
|
|
});
|
|
|
} else {
|
|
|
return this.meGiftAPi.changeMobileCheck(params.area, params.mobile, params.code);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 修改绑定的手机号
|
|
|
changeMobile(params, uid) {
|
|
|
return this.meGiftAPi.changeMobile(params.area, params.mobile, params.code, uid).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
_.set(this.ctx, 'req.session.USER_MOBILE', params.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'));
|
|
|
|
|
|
return this.checkMobile(params, uid).then(res => {
|
|
|
if (res.code !== 200) {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
let data = res.data || {};
|
|
|
|
|
|
if (data.isRegister === 'Y') {
|
|
|
let ccode = Math.floor(Math.random() * 1000000000000);
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
data: {
|
|
|
ccode: ccode,
|
|
|
fcode: md5(`${ccode}_${uid}`),
|
|
|
reCheckType: data.isBind === 'N' ? 1 : 2
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
return res;
|
|
|
|
|
|
return this.meGiftAPi.changeMobile(params.area, params.mobile, params.code, uid).then(result => {
|
|
|
if (result.code === 200) {
|
|
|
result.data = {};
|
|
|
_.set(this.ctx, 'req.session.USER_MOBILE',
|
|
|
params.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2'));
|
|
|
}
|
|
|
return result;
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
|