Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuy-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
1
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
周少峰
8 years ago
Commit
7ff4c7b145ef4a22ab82357af15f2b17e7ade99f
2 parents
6ce609ca
a7eb304f
Merge branch 'feature/homeCtx' into gray
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
1032 additions
and
575 deletions
apps/home/controllers/account.js
apps/home/controllers/address.js
apps/home/controllers/currency.js
apps/home/controllers/general-tabs.js
apps/home/controllers/gift.js
apps/home/controllers/message.js
apps/home/controllers/redenvelopes.js
apps/home/controllers/user.js
apps/home/models/account-api.js
apps/home/models/account-service.js
apps/home/models/address-api.js
apps/home/models/address-service.js
apps/home/models/currency-api.js
apps/home/models/currency-model.js
apps/home/models/general-tabs-service.js
apps/home/models/gift-service.js
apps/home/models/message.js
apps/home/models/redenvelopes-api.js
apps/home/models/redenvelopes-model.js
apps/home/models/user-api.js
apps/home/models/user-service.js
apps/home/controllers/account.js
View file @
7ff4c7b
...
...
@@ -6,7 +6,7 @@
'use strict'
;
const
mRoot
=
'../models'
;
const
account
Service
=
require
(
`
$
{
mRoot
}
/account-service`
)
; /
/
user
页
model
const
account
Model
=
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
);
};
...
...
apps/home/controllers/address.js
View file @
7ff4c7b
...
...
@@ -6,7 +6,7 @@
'use strict'
;
const
mRoot
=
'../models'
;
const
address
Service
=
require
(
`
$
{
mRoot
}
/address-service`
)
; /
/
user
页
model
const
address
Model
=
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
);
};
...
...
apps/home/controllers/currency.js
View file @
7ff4c7b
...
...
@@ -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
});
...
...
apps/home/controllers/general-tabs.js
View file @
7ff4c7b
'use strict'
;
const
_
=
require
(
'lodash'
);
const
header
Service
=
require
(
'../models/general-tabs-service'
);
const
header
Model
=
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
};
...
...
apps/home/controllers/gift.js
View file @
7ff4c7b
...
...
@@ -6,7 +6,7 @@
'use strict'
;
const
mRoot
=
'../models'
;
const
gift
Service
=
require
(
`
$
{
mRoot
}
/gift-service`
)
; /
/
user
页
model
const
gift
Model
=
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
);
};
...
...
apps/home/controllers/message.js
View file @
7ff4c7b
...
...
@@ -5,7 +5,7 @@
*/
'use strict'
;
const
message
=
require
(
'../models/message'
);
const
message
Model
=
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
);
};
...
...
apps/home/controllers/redenvelopes.js
View file @
7ff4c7b
/**
* 个人中心 我的红包
*/
'use strict'
;
const
redenvelopesModel
=
require
(
'../models/redenvelopes-model'
);
const
index
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
;
re
denvelopesModel
.
redenvelopesList
(
uid
).
then
(
result
=>
{
re
q
.
ctx
(
redenvelopesModel
)
.
redenvelopesList
(
uid
).
then
(
result
=>
{
res
.
render
(
'redenvelopes'
,
{
meRedEnvelopes
:
result
});
...
...
apps/home/controllers/user.js
View file @
7ff4c7b
...
...
@@ -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
);
...
...
apps/home/models/account-api.js
View file @
7ff4c7b
...
...
@@ -5,111 +5,186 @@
*/
'use strict'
;
const
api
=
global
.
yoho
.
API
;
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
const
getVerifyInfo
=
uid
=>
{
return
api
.
get
(
''
,
{
getVerifyInfo
(
uid
)
{
let
data
=
{
method
:
'web.passport.getUserVerifyInfo'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
checkEmailCode
(
code
)
{
const
checkEmailCode
=
code
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.checkCodeValid'
,
code
:
code
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
modifyVerifyEmail
(
code
)
{
const
modifyVerifyEmail
=
code
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.changeVerifyEmail'
,
code
:
code
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
verifyPwd
(
uid
,
password
)
{
const
verifyPwd
=
(
uid
,
password
)
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.verifyUserPwd'
,
uid
:
uid
,
password
:
password
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
checkVerifyMsg
(
area
,
mobile
,
code
)
{
const
checkVerifyMsg
=
(
area
,
mobile
,
code
)
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.checkcode'
,
area
:
area
,
mobile
:
mobile
,
code
:
code
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 邮箱身份验证--发送邮件
* @param type $email
* @param type $callback 成功后跳转链接
* @return type
*/
const
sendVerifyEmailForNext
=
(
email
,
callback
)
=>
{
return
api
.
get
(
''
,
{
sendVerifyEmailForNext
(
email
,
callback
)
{
let
data
=
{
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
(
''
,
{
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
*/
const
checkVerifyEmail
=
(
uid
,
email
)
=>
{
return
api
.
get
(
''
,
{
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
*/
const
sendVerifyEmail
=
(
uid
,
email
)
=>
{
return
api
.
get
(
''
,
{
sendVerifyEmail
(
uid
,
email
)
{
let
data
=
{
method
:
'web.passport.verifyEmail'
,
uid
:
uid
,
email
:
email
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
* 修改手机号前校验
...
...
@@ -117,59 +192,71 @@ const sendVerifyEmail = (uid, email) => {
* @param type $area
* @return type
*/
const
checkVerifyMobile
=
(
uid
,
mobile
,
area
)
=>
{
return
api
.
get
(
''
,
{
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
*/
const
modifyPwd
=
(
uid
,
newPwd
)
=>
{
return
api
.
get
(
''
,
{
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
*/
const
sendMobileMsg
=
(
uid
,
mobile
,
area
)
=>
{
return
api
.
get
(
''
,
{
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
};
...
...
apps/home/models/account-service.js
View file @
7ff4c7b
...
...
@@ -11,11 +11,15 @@ 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
)
{
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
// 时间转换为时间戳
datetimeToUnix
(
datetime
)
{
let
tmpDatetime
=
datetime
.
replace
(
/:/g
,
'-'
);
tmpDatetime
=
tmpDatetime
.
replace
(
/ /g
,
'-'
);
...
...
@@ -24,14 +28,14 @@ function datetimeToUnix(datetime) {
let
now
=
new
Date
(
Date
.
UTC
(
arr
[
0
],
arr
[
1
]
-
1
,
arr
[
2
],
arr
[
3
]
-
8
,
arr
[
4
],
arr
[
5
]));
return
parseInt
(
now
.
getTime
()
/
1000
,
10
);
}
}
/**
/**
* 根据输入的mobile获取area
* @param type $mobile
* @return int
*/
function
handleMobile
(
mobile
)
{
handleMobile
(
mobile
)
{
let
res
=
{};
// 国际号
...
...
@@ -45,15 +49,15 @@ function handleMobile(mobile) {
res
.
mobile
=
mobile
;
}
return
res
;
}
}
/**
/**
* 获得标题文案
* @param type ischeckMobile
* @param type ischeckEmail
* @param type checkType
*/
function
getTitles
(
ischeckMobile
,
ischeckEmail
,
checkType
)
{
getTitles
(
ischeckMobile
,
ischeckEmail
,
checkType
)
{
let
subTitle
,
enTitle
,
pageKey
;
...
...
@@ -76,9 +80,10 @@ function getTitles(ischeckMobile, ischeckEmail, checkType) {
enTitle
:
enTitle
,
pageKey
:
pageKey
};
}
}
/**
/**
* 第一部页面form结构-step1
* @param type $data 用户验证相关信息
* @param type $ischeckMobile
...
...
@@ -86,7 +91,7 @@ function getTitles(ischeckMobile, ischeckEmail, checkType) {
* @param type $firstCheck
* @return string
*/
const
getFormDataStep1
=
(
data
,
ischeckMobile
,
ischeckEmail
,
firstCheck
)
=>
{
getFormDataStep1
(
data
,
ischeckMobile
,
ischeckEmail
,
firstCheck
)
{
// 都没验证
let
formData1
=
[
{
...
...
@@ -148,16 +153,16 @@ const getFormDataStep1 = (data, ischeckMobile, ischeckEmail, firstCheck) => {
checkEmailFlag
:
checkEmailFlag
,
checkMobileFlag
:
checkMobileFlag
};
};
}
/**
/**
* 第二步-formData
* @param type $ischeckEmail
* @param type $ischeckMobile
* @param type $checkType
* @return array
*/
const
getFormDataStep2
=
(
ischeckEmail
,
ischeckMobile
,
checkType
)
=>
{
getFormDataStep2
(
ischeckEmail
,
ischeckMobile
,
checkType
)
{
let
formData
=
[];
switch
(
checkType
)
{
...
...
@@ -203,18 +208,21 @@ const getFormDataStep2 = (ischeckEmail, ischeckMobile, checkType) => {
}
return
{
formData
:
formData
};
};
}
/**
/**
* 个人中心-判断身份验证状态
* @param type uid
* @param type checkType
* @param type step page步骤
* @return type
*/
const
auditCheckStatus
=
(
uid
,
checkType
,
step
)
=>
{
auditCheckStatus
(
uid
,
checkType
,
step
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
res
=
yield
accountApi
.
getVerifyInfo
(
uid
),
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
let
res
=
yield
accountDataModel
.
getVerifyInfo
(
uid
),
ret
=
{
status
:
false
};
if
(
res
.
data
)
{
...
...
@@ -223,12 +231,12 @@ const auditCheckStatus = (uid, checkType, step) => {
ischeckEmail
=
(
data
.
emailVerify
===
'N'
)
?
false
:
true
;
let
firstCheck
=
''
,
// 优先验证标识
titleInfo
=
getTitles
(
ischeckMobile
,
ischeckEmail
,
checkType
),
titleInfo
=
that
.
getTitles
(
ischeckMobile
,
ischeckEmail
,
checkType
),
formJson
=
{};
if
(
ischeckMobile
&&
ischeckEmail
)
{
firstCheck
=
(
datetimeToUnix
(
data
.
mobileVerifyTime
)
<=
datetimeToUnix
(
data
.
emailVerifyTime
))
?
'mobile'
:
'email'
;
firstCheck
=
(
that
.
datetimeToUnix
(
data
.
mobileVerifyTime
)
<=
that
.
datetimeToUnix
(
data
.
emailVerifyTime
))
?
'mobile'
:
'email'
;
}
let
verifyType
=
1
,
...
...
@@ -236,7 +244,7 @@ const auditCheckStatus = (uid, checkType, step) => {
checkMobileFlag
=
false
;
if
(
step
===
1
)
{
formJson
=
getFormDataStep1
(
data
,
ischeckMobile
,
ischeckEmail
,
firstCheck
);
formJson
=
that
.
getFormDataStep1
(
data
,
ischeckMobile
,
ischeckEmail
,
firstCheck
);
verifyType
=
formJson
.
verifyType
;
checkEmailFlag
=
formJson
.
checkEmailFlag
;
checkMobileFlag
=
formJson
.
checkMobileFlag
;
...
...
@@ -244,7 +252,7 @@ const auditCheckStatus = (uid, checkType, step) => {
delete
formJson
.
checkEmailFlag
;
delete
formJson
.
checkMobileFlag
;
}
else
if
(
step
===
2
)
{
formJson
=
getFormDataStep2
(
ischeckEmail
,
ischeckMobile
,
checkType
);
formJson
=
that
.
getFormDataStep2
(
ischeckEmail
,
ischeckMobile
,
checkType
);
}
ret
=
{
...
...
@@ -265,16 +273,16 @@ const auditCheckStatus = (uid, checkType, step) => {
return
ret
;
})();
};
}
/**
/**
* 校验进入第二步
* @param type $checkCode
* @param type $uid
* @param type MaxTime
* @return boolean
*/
const
checkCode
=
(
ckCode
,
uid
,
time
)
=>
{
checkCode
(
ckCode
,
uid
,
time
)
{
time
=
parseInt
(
`
0
$
{
time
}
`
,
10
)
||
86400000
;
try
{
...
...
@@ -296,15 +304,18 @@ const checkCode = (ckCode, uid, time) => {
return
false
;
}
};
}
/**
/**
* 个人中心-账号安全-index
*
*/
const
getAccountInfo
=
(
uid
)
=>
{
getAccountInfo
(
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
let
resq
=
[{
icon
:
'ok'
,
type
:
'登录密码'
,
...
...
@@ -324,7 +335,7 @@ const getAccountInfo = (uid) => {
url
:
helpers
.
urlFormat
(
'/home/account/mobile'
)
}];
let
verifyResult
=
yield
accountApi
.
getVerifyInfo
(
uid
);
let
verifyResult
=
yield
accountDataModel
.
getVerifyInfo
(
uid
);
if
(
verifyResult
.
data
)
{
let
verifyData
=
verifyResult
.
data
;
...
...
@@ -342,14 +353,15 @@ const getAccountInfo = (uid) => {
return
resq
;
})();
};
}
/**
/**
* 个人中心-修改密码身份验证-page1/2/3
*/
const
userPwd
=
(
params
)
=>
{
return
co
(
function
*
()
{
userPwd
(
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
step
=
params
.
step
?
parseInt
(
params
.
step
,
10
)
:
1
,
ckCode
=
params
.
checkCode
||
''
,
success
=
params
.
success
||
false
,
...
...
@@ -358,7 +370,7 @@ const userPwd = (params) => {
// 第二步验证信息校验
if
(
step
===
2
&&
ckCode
!==
''
)
{
let
checkFlag
=
checkCode
(
ckCode
,
uid
);
let
checkFlag
=
that
.
checkCode
(
ckCode
,
uid
);
if
(
!
checkFlag
)
{
// res.redirect(helpers.urlFormat('/home/account/userpwd', {step: 1}));
...
...
@@ -371,7 +383,7 @@ const userPwd = (params) => {
}
// 验证信息
let
verifyInfo
=
yield
auditCheckStatus
(
uid
,
'userpwd'
,
step
);
let
verifyInfo
=
yield
that
.
auditCheckStatus
(
uid
,
'userpwd'
,
step
);
if
(
!
verifyInfo
.
status
)
{
return
{
...
...
@@ -427,12 +439,14 @@ const userPwd = (params) => {
meValidatePage
:
true
};
})();
};
}
/**
/**
* 个人中心-邮箱验证身份-page1/2/3
*/
const
userEmail
=
(
params
)
=>
{
userEmail
(
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
step
=
params
.
step
?
parseInt
(
params
.
step
,
10
)
:
1
,
...
...
@@ -443,7 +457,7 @@ const userEmail = (params) => {
// 第二步验证信息校验
if
(
step
===
2
)
{
let
checkFlag
=
checkCode
(
ckCode
,
uid
);
let
checkFlag
=
that
.
checkCode
(
ckCode
,
uid
);
if
(
!
checkFlag
)
{
// res.redirect(helpers.urlFormat('/home/account/email', {step: 1}));
...
...
@@ -456,7 +470,7 @@ const userEmail = (params) => {
}
// 验证信息
let
verifyInfo
=
yield
auditCheckStatus
(
uid
,
'email'
,
step
);
let
verifyInfo
=
yield
that
.
auditCheckStatus
(
uid
,
'email'
,
step
);
if
(
!
verifyInfo
.
status
)
{
return
{
...
...
@@ -512,12 +526,14 @@ const userEmail = (params) => {
meValidatePage
:
true
};
})();
};
}
/**
/**
* 个人中心-手机验证身份-page1/2/3
*/
const
userMobile
=
(
params
)
=>
{
userMobile
(
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
step
=
params
.
step
?
parseInt
(
params
.
step
,
10
)
:
1
,
ckCode
=
params
.
checkCode
||
''
,
...
...
@@ -527,7 +543,7 @@ const userMobile = (params) => {
// 第二步验证信息校验
if
(
step
===
2
)
{
let
checkFlag
=
checkCode
(
ckCode
,
uid
);
let
checkFlag
=
that
.
checkCode
(
ckCode
,
uid
);
if
(
!
checkFlag
)
{
// res.redirect(helpers.urlFormat('/home/account/mobile', {step: 1}));
...
...
@@ -540,7 +556,7 @@ const userMobile = (params) => {
}
// 验证信息
let
verifyInfo
=
yield
auditCheckStatus
(
uid
,
'mobile'
,
step
);
let
verifyInfo
=
yield
that
.
auditCheckStatus
(
uid
,
'mobile'
,
step
);
if
(
!
verifyInfo
.
status
)
{
return
{
...
...
@@ -597,12 +613,14 @@ const userMobile = (params) => {
meValidatePage
:
true
};
})();
};
}
/**
/**
* 个人中心-邮箱验证身份-邮件发送成功过渡页
*/
const
sendEmailSuccess
=
(
params
)
=>
{
sendEmailSuccess
(
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
checkType
=
params
.
checkType
||
'userpwd'
,
uid
=
params
.
uid
,
...
...
@@ -611,7 +629,7 @@ const sendEmailSuccess = (params) => {
type
=
params
.
email
||
1
;
// 1:身份验证 2:修改邮箱
// 验证信息
let
verifyInfo
=
yield
auditCheckStatus
(
uid
,
checkType
);
let
verifyInfo
=
yield
that
.
auditCheckStatus
(
uid
,
checkType
);
if
(
!
verifyInfo
.
status
)
{
return
{
...
...
@@ -654,18 +672,21 @@ const sendEmailSuccess = (params) => {
return
resqData
;
})();
};
}
/**
/**
* 点击邮箱验证链接方法--修改验证邮箱
*/
const
mailResult
=
(
params
)
=>
{
mailResult
(
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
code
=
params
.
code
;
let
check
=
yield
accountApi
.
checkEmailCode
(
code
);
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
let
check
=
yield
accountDataModel
.
checkEmailCode
(
code
);
if
(
check
.
code
===
200
)
{
let
data
=
yield
accountApi
.
modifyVerifyEmail
(
code
);
let
data
=
yield
accountDataModel
.
modifyVerifyEmail
(
code
);
if
(
data
.
code
===
200
)
{
// res.redirect(helpers.urlFormat('/home/account/email',
...
...
@@ -686,17 +707,20 @@ const mailResult = (params) => {
params
:
{
step
:
3
,
success
:
false
}
};
})();
};
}
/**
/**
* 身份验证-登录密码验证Ajax
*/
const
verifyPassword
=
(
req
)
=>
{
verifyPassword
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
password
=
_
.
trim
(
req
.
body
.
password
||
''
),
uid
=
req
.
user
.
uid
;
uid
=
req
.
user
.
uid
,
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
let
resqData
=
yield
accountApi
.
verifyPwd
(
uid
,
password
);
let
resqData
=
yield
accountDataModel
.
verifyPwd
(
uid
,
password
);
if
(
resqData
.
code
===
200
)
{
let
ckCode
=
crypto
.
encryption
(
'yoho9646abcdefgh'
,
uid
+
'_'
+
Date
.
parse
(
new
Date
())
+
...
...
@@ -706,27 +730,30 @@ const verifyPassword = (req) => {
}
return
resqData
;
})();
};
}
/**
/**
* 分-验证密码正确性-ajax
*/
const
checkPassword
=
(
req
)
=>
{
checkPassword
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
password
=
_
.
trim
(
req
.
body
.
password
||
''
),
uid
=
req
.
user
.
uid
,
resqData
=
{
code
:
400
};
resqData
=
{
code
:
400
},
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
resqData
=
yield
accountApi
.
verifyPwd
(
uid
,
password
);
resqData
=
yield
accountDataModel
.
verifyPwd
(
uid
,
password
);
return
resqData
;
})();
};
}
/**
/**
* 分-验证图形验证码-ajax
*/
const
checkVerifyCode
=
(
req
)
=>
{
checkVerifyCode
(
req
)
{
return
co
(
function
*
()
{
let
captchaCode
=
_
.
trim
(
req
.
body
.
verifyCode
||
''
).
toLowerCase
(),
resqData
=
{};
...
...
@@ -741,12 +768,14 @@ const checkVerifyCode = (req) => {
return
resqData
;
})();
};
}
/**
/**
* 手机身份验证-校验手机号
*/
const
identityMobile
=
(
req
)
=>
{
identityMobile
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
mobile
=
req
.
body
.
mobile
||
''
,
resqData
=
{
code
:
400
},
...
...
@@ -754,9 +783,10 @@ const identityMobile = (req) => {
check
=
false
,
userId
;
let
mobileInfo
=
handleMobile
(
mobile
);
let
mobileInfo
=
that
.
handleMobile
(
mobile
),
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
let
userInfo
=
yield
userApi
.
getUserInfoByMobile
(
mobileInfo
.
area
,
mobile
);
let
userInfo
=
yield
accountDataModel
.
getUserInfoByMobile
(
mobileInfo
.
area
,
mobile
);
userId
=
'uid'
in
userInfo
.
data
?
userInfo
.
data
.
uid
:
0
;
if
(
userId
===
uid
)
{
...
...
@@ -778,20 +808,24 @@ const identityMobile = (req) => {
}
return
resqData
;
})();
};
}
/**
/**
* 向验证手机号发送短信-ajax
*/
const
sendMobileMsg
=
(
req
,
uid
)
=>
{
sendMobileMsg
(
req
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
mobile
=
req
.
body
.
mobile
||
''
,
_code
=
req
.
body
.
checkCode
,
resqData
=
{
code
:
400
};
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
// 发送验证码前置数据校验
if
(
!
_code
)
{
let
verifyInfo
=
yield
accountApi
.
getVerifyInfo
(
uid
);
let
verifyInfo
=
yield
accountDataModel
.
getVerifyInfo
(
uid
);
mobile
=
_
.
get
(
verifyInfo
,
'data.mobile'
,
''
);
if
(
!
mobile
)
{
...
...
@@ -799,32 +833,36 @@ const sendMobileMsg = (req, uid) => {
message
:
'数据验证错误'
});
}
}
else
if
(
!
checkCode
(
_code
,
uid
))
{
}
else
if
(
!
that
.
checkCode
(
_code
,
uid
))
{
return
Object
.
assign
(
resqData
,
{
message
:
'数据验证错误'
});
}
let
mobileInfo
=
handleMobile
(
mobile
);
let
mobileInfo
=
that
.
handleMobile
(
mobile
);
resqData
=
yield
accountApi
.
sendMobileMsg
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
resqData
=
yield
accountDataModel
.
sendMobileMsg
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
return
resqData
;
})();
};
}
/**
/**
* 校验短信验证码-ajax
*/
const
checkMobileMsg
=
(
req
,
uid
)
=>
{
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
accountApi
.
getVerifyInfo
(
uid
);
let
verifyInfo
=
yield
accountDataModel
.
getVerifyInfo
(
uid
);
mobile
=
_
.
get
(
verifyInfo
,
'data.mobile'
,
''
);
if
(
!
mobile
)
{
...
...
@@ -832,7 +870,7 @@ const checkMobileMsg = (req, uid) => {
message
:
'数据验证错误'
});
}
}
else
if
(
!
checkCode
(
_code
,
uid
))
{
}
else
if
(
!
that
.
checkCode
(
_code
,
uid
))
{
return
Object
.
assign
(
resqData
,
{
message
:
'数据验证错误'
});
...
...
@@ -852,9 +890,9 @@ const checkMobileMsg = (req, uid) => {
});
return
resqData
;
}
let
mobileInfo
=
handleMobile
(
mobile
);
let
mobileInfo
=
that
.
handleMobile
(
mobile
);
resqData
=
yield
accountApi
.
checkVerifyMsg
(
mobileInfo
.
area
,
mobileInfo
.
mobile
,
code
);
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'
);
...
...
@@ -867,19 +905,22 @@ const checkMobileMsg = (req, uid) => {
}
return
resqData
;
})();
};
}
/**
/**
* 身份验证时,发送邮件-ajax
*/
const
sendEmail
=
(
req
)
=>
{
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
verifyInfo
=
yield
accountApi
.
getVerifyInfo
(
uid
);
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
),
verifyInfo
=
yield
accountDataModel
.
getVerifyInfo
(
uid
);
email
=
_
.
get
(
verifyInfo
,
'data.email'
,
''
);
if
(
!
email
)
{
...
...
@@ -894,61 +935,73 @@ const sendEmail = (req) => {
let
callback
=
'home/account/'
+
checkType
+
'?step=2&checkCode='
+
encodeURIComponent
(
ckCode
);
// callback拼接于邮箱域名处;
resqData
=
yield
accountApi
.
sendVerifyEmailForNext
(
email
,
callback
);
resqData
=
yield
accountDataModel
.
sendVerifyEmailForNext
(
email
,
callback
);
return
resqData
;
})();
};
}
/**
/**
* 分-修改邮箱前,校验邮箱-ajax
*/
const
checkEmail
=
(
req
)
=>
{
checkEmail
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
uid
=
req
.
user
.
uid
,
email
=
req
.
body
.
email
||
''
,
resqData
=
{
code
:
400
};
resqData
=
yield
accountApi
.
checkVerifyEmail
(
uid
,
email
);
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
resqData
=
yield
accountDataModel
.
checkVerifyEmail
(
uid
,
email
);
return
resqData
;
})();
};
}
/**
/**
* 修改密码
*/
const
modifyPwd
=
(
req
,
params
)
=>
{
modifyPwd
(
req
,
params
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
uid
=
params
.
uid
,
newPwd
=
params
.
newPwd
||
''
,
_code
=
params
.
checkCode
;
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
// 前置数据校验
if
(
!
_code
||
!
checkCode
(
_code
,
uid
,
600000
))
{
if
(
!
_code
||
!
that
.
checkCode
(
_code
,
uid
,
600000
))
{
return
{
code
:
400
,
message
:
'数据验证错误'
};
}
let
resqData
=
yield
accountApi
.
modifyPwd
(
uid
,
newPwd
);
let
resqData
=
yield
accountDataModel
.
modifyPwd
(
uid
,
newPwd
);
return
resqData
;
})();
};
}
/**
/**
* 修改验证手机号
*/
const
modifyMobile
=
(
req
,
uid
)
=>
{
modifyMobile
(
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
);
// 校验验证码前置数据校验
// 校验checkCode,有效时间10分钟(checkCode在调改接口前获取,考虑网络延时,服务器间的时间差,设置10分钟)
if
(
!
_code
||
!
checkCode
(
_code
,
uid
,
600000
))
{
if
(
!
_code
||
!
that
.
checkCode
(
_code
,
uid
,
600000
))
{
return
Object
.
assign
(
resqData
,
{
message
:
'数据验证错误'
});
...
...
@@ -970,12 +1023,12 @@ const modifyMobile = (req, uid) => {
};
return
resqData
;
}
let
mobileInfo
=
handleMobile
(
mobile
);
let
mobileInfo
=
that
.
handleMobile
(
mobile
);
let
checkFlag
=
yield
accountApi
.
checkVerifyMobile
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
let
checkFlag
=
yield
accountDataModel
.
checkVerifyMobile
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
if
(
checkFlag
.
code
===
200
)
{
resqData
=
yield
accountApi
.
modifyVerifyMobile
(
uid
,
mobileInfo
.
area
,
mobileInfo
.
mobile
);
resqData
=
yield
accountDataModel
.
modifyVerifyMobile
(
uid
,
mobileInfo
.
area
,
mobileInfo
.
mobile
);
}
else
{
resqData
=
{
code
:
checkFlag
.
data
,
...
...
@@ -985,67 +1038,57 @@ const modifyMobile = (req, uid) => {
}
return
resqData
;
})();
};
}
/**
/**
* 分-检查手机号是否可修改-ajax
*/
const
checkMobile
=
(
params
,
uid
)
=>
{
checkMobile
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
mobile
=
params
.
mobile
||
''
,
resqData
=
{
code
:
400
};
let
mobileInfo
=
handleMobile
(
mobile
);
let
mobileInfo
=
that
.
handleMobile
(
mobile
),
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
resqData
=
yield
accountApi
.
checkVerifyMobile
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
resqData
=
yield
accountDataModel
.
checkVerifyMobile
(
uid
,
mobileInfo
.
mobile
,
mobileInfo
.
area
);
return
resqData
;
})();
};
}
/**
/**
* 修改验证邮箱校验并发送邮件-ajax
*
*/
const
modifyEmail
=
(
req
)
=>
{
modifyEmail
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
uid
=
req
.
user
.
uid
,
email
=
req
.
body
.
email
||
''
,
_code
=
req
.
body
.
checkCode
,
resqData
=
{
code
:
400
};
let
accountDataModel
=
new
AccountApi
(
that
.
ctx
);
// 前置数据校验
if
(
!
_code
||
!
checkCode
(
_code
,
uid
,
600000
))
{
if
(
!
_code
||
!
that
.
checkCode
(
_code
,
uid
,
600000
))
{
return
Object
.
assign
(
resqData
,
{
message
:
'数据验证错误'
});
}
let
check
=
yield
accountApi
.
checkVerifyEmail
(
uid
,
email
);
let
check
=
yield
accountDataModel
.
checkVerifyEmail
(
uid
,
email
);
if
(
check
.
code
===
200
)
{
resqData
=
yield
accountApi
.
sendVerifyEmail
(
uid
,
email
);
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
};
...
...
apps/home/models/address-api.js
View file @
7ff4c7b
...
...
@@ -5,27 +5,36 @@
*/
'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
)
=>
{
addressData
(
uid
,
lmt
)
{
let
limit
=
lmt
?
lmt
:
10
;
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'app.address.gethidden'
,
uid
:
uid
,
limit
:
limit
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 保存地址数据
*
* @param int $uid 用户ID
...
...
@@ -39,43 +48,65 @@ exports.addressData = (uid, lmt) => {
* @param string $zip_code 邮编
* @return array 地址接口返回的数据
*/
exports
.
saveAddressData
=
(
params
)
=>
{
saveAddressData
(
params
)
{
if
(
params
.
id
!==
null
)
{
params
.
method
=
'app.address.update'
;
// 修改
}
else
{
delete
params
.
id
;
params
.
method
=
'app.address.add'
;
// 添加
}
return
api
.
get
(
''
,
params
);
return
this
.
get
({
data
:
params
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 删除地址
*
* @param int $uid 用户ID
* @param int $id 地址唯一标识符id
* @return array 接口返回的数据
*/
exports
.
deleteAddress
=
(
uid
,
id
)
=>
{
return
api
.
get
(
''
,
{
deleteAddress
(
uid
,
id
)
{
let
data
=
{
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 接口返回的数据
*/
exports
.
setDefaultAddress
=
(
uid
,
id
)
=>
{
return
api
.
get
(
''
,
{
setDefaultAddress
(
uid
,
id
)
{
let
data
=
{
method
:
'app.address.setdefault'
,
uid
:
uid
,
id
:
id
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
};
...
...
apps/home/models/address-service.js
View file @
7ff4c7b
...
...
@@ -3,11 +3,16 @@
* @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'
);
'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
);
}
/*
* 个人中心-地址管理列表
...
...
@@ -16,10 +21,13 @@
* @return array|mixed 处理之后的返回数据
*
*/
const
getAddressList
=
(
uid
,
limit
)
=>
{
getAddressList
(
uid
,
limit
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
addressDataModel
=
new
AddressApi
(
that
.
ctx
);
let
result
=
[],
addressData
=
yield
addressApi
.
addressData
(
uid
,
limit
);
addressData
=
yield
addressDataModel
.
addressData
(
uid
,
limit
);
if
(
addressData
.
data
)
{
let
addressList
=
addressData
.
data
;
...
...
@@ -39,15 +47,17 @@
}
return
result
;
})();
};
}
/**
* 地址管理列表
*/
exports
.
getAddressInfo
=
(
uid
)
=>
{
getAddressInfo
(
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
resq
=
{},
addressList
=
yield
getAddressList
(
uid
);
addressList
=
yield
that
.
getAddressList
(
uid
);
resq
.
address
=
{
submitId
:
'address-info'
,
...
...
@@ -99,17 +109,21 @@
return
resq
;
})();
};
}
/**
/**
* 编辑修改地址
*/
exports
.
editAddress
=
(
params
,
uid
)
=>
{
editAddress
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
id
=
params
.
id
,
respData
=
{};
let
addressDataModel
=
new
AddressApi
(
that
.
ctx
);
let
data
=
yield
addressApi
.
addressData
(
uid
);
let
data
=
yield
addressDataModel
.
addressData
(
uid
);
respData
.
code
=
data
.
code
;
...
...
@@ -134,12 +148,14 @@
return
respData
;
})();
};
}
/**
/**
* 添加保存地址
*/
exports
.
saveAddress
=
(
params
,
uid
)
=>
{
saveAddress
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
query
=
{
uid
:
uid
,
...
...
@@ -151,6 +167,7 @@
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
===
''
||
...
...
@@ -161,30 +178,39 @@
message
:
'请填写完整的省市区信息'
};
}
let
respData
=
yield
addressApi
.
saveAddressData
(
query
);
let
respData
=
yield
addressDataModel
.
saveAddressData
(
query
);
return
respData
;
})();
};
}
/**
/**
* 删除地址
*/
exports
.
delAddress
=
(
params
,
uid
)
=>
{
delAddress
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
respData
=
yield
addressApi
.
deleteAddress
(
uid
,
params
.
id
);
let
addressDataModel
=
new
AddressApi
(
that
.
ctx
);
let
respData
=
yield
addressDataModel
.
deleteAddress
(
uid
,
params
.
id
);
return
respData
;
})();
};
}
/**
/**
* 设置默认地址
*/
exports
.
defaultAddress
=
(
params
,
uid
)
=>
{
defaultAddress
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
respData
=
yield
addressApi
.
setDefaultAddress
(
uid
,
params
.
id
);
let
addressDataModel
=
new
AddressApi
(
that
.
ctx
);
let
respData
=
yield
addressDataModel
.
setDefaultAddress
(
uid
,
params
.
id
);
return
respData
;
})();
};
}
};
...
...
apps/home/models/currency-api.js
View file @
7ff4c7b
...
...
@@ -2,42 +2,59 @@
* @author: weiqingting<qingting.wei@yoho.cn>
*/
'use strict'
;
const
api
=
global
.
yoho
.
API
;
const
yohoCoinList
=
(
uid
,
condition
)
=>
{
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
yohoCoinList
(
uid
,
condition
)
{
condition
=
condition
||
{};
let
options
=
{
let
data
=
{
method
:
'app.yohocoin.lists'
,
uid
:
uid
,
page
:
1
,
limit
:
15
};
Object
.
assign
(
options
,
condition
);
return
api
.
get
(
''
,
options
);
};
Object
.
assign
(
data
,
condition
);
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
const
yohoCoinTotal
=
uid
=>
{
let
options
=
{
yohoCoinTotal
(
uid
)
{
let
data
=
{
method
:
'app.yoho.yohocoin'
,
uid
:
uid
};
return
api
.
get
(
''
,
options
);
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
const
getProduct
=
(
skn
,
limit
)
=>
{
let
options
=
{
getProduct
(
skn
,
limit
)
{
let
data
=
{
method
:
'h5.product.batch'
,
productSkn
:
skn
,
limit
:
limit
};
return
api
.
get
(
''
,
options
);
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
module
.
exports
=
{
yohoCoinList
,
yohoCoinTotal
,
getProduct
};
...
...
apps/home/models/currency-model.js
View file @
7ff4c7b
...
...
@@ -9,7 +9,7 @@ const co = Promise.coroutine;
const
path
=
require
(
'path'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
_
=
require
(
'lodash'
);
const
c
urrencyApi
=
require
(
'./currency-api'
);
const
C
urrencyApi
=
require
(
'./currency-api'
);
// 使用 product中的分页逻辑
const
pagerPath
=
path
.
join
(
global
.
appRoot
,
'/apps/product/models/public-handler.js'
);
...
...
@@ -17,11 +17,16 @@ const pager = require(pagerPath).handlePagerData;
const
moment
=
require
(
'moment'
);
const
convertUnitTime
=
(
src
)
=>
{
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
convertUnitTime
(
src
)
{
return
moment
.
unix
(
src
).
format
(
'YYYY-MM-DD'
);
};
}
const
currencyTabs
=
(
type
)
=>
{
currencyTabs
(
type
)
{
let
tabs
=
[
'全部明细'
,
'全部收入'
,
'全部支出'
],
result
=
[];
...
...
@@ -33,9 +38,10 @@ const currencyTabs = (type)=>{
});
});
return
result
;
};
}
const
currencyOptions
=
(
condition
)
=>
{
currencyOptions
(
condition
)
{
let
that
=
this
;
let
result
=
[],
paramUrl
=
{};
let
tabs
=
{
90
:
'最近3个月明细'
,
180
:
'最近半年明细'
,
360
:
'最近一年明细'
};
...
...
@@ -43,7 +49,7 @@ const currencyOptions = (condition)=>{
if
(
condition
.
queryType
)
{
paramUrl
.
type
=
condition
.
queryType
;
}
paramUrl
.
beginTime
=
convertUnitTime
(
new
Date
()
/
1000
-
parseInt
(
name
,
10
)
*
3600
*
24
);
paramUrl
.
beginTime
=
that
.
convertUnitTime
(
new
Date
()
/
1000
-
parseInt
(
name
,
10
)
*
3600
*
24
);
result
.
push
({
url
:
helpers
.
urlFormat
(
'/home/currency'
,
paramUrl
),
...
...
@@ -52,15 +58,18 @@ const currencyOptions = (condition)=>{
});
}
return
result
;
};
}
currencyList
(
uid
,
condition
)
{
let
that
=
this
;
const
currencyList
=
(
uid
,
condition
)
=>
{
return
co
(
function
*
()
{
let
result
=
{
list
:
[],
pager
:
[]};
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
))
{
...
...
@@ -77,7 +86,7 @@ const currencyList = (uid, condition)=>{
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
);
let
product
=
yield
currencyDataModel
.
getProduct
(
Number
(
val
.
key
),
1
);
if
(
_
.
get
(
product
,
'code'
)
===
200
&&
!
_
.
isEmpty
(
product
.
data
.
product_list
)
&&
...
...
@@ -108,18 +117,20 @@ const currencyList = (uid, condition)=>{
}
return
result
;
})();
};
}
const
currencyData
=
(
uid
,
prama
)
=>
{
currencyData
(
uid
,
prama
)
{
let
that
=
this
;
let
condition
=
{
page
:
prama
.
page
||
1
,
queryType
:
prama
.
type
||
0
,
beginTime
:
prama
.
beginTime
||
convertUnitTime
(
new
Date
()
/
1000
-
3600
*
24
*
90
)
beginTime
:
prama
.
beginTime
||
that
.
convertUnitTime
(
new
Date
()
/
1000
-
3600
*
24
*
90
)
};
return
co
(
function
*
()
{
let
result
=
{};
let
yohoCoinInfo
=
yield
currencyApi
.
yohoCoinTotal
(
uid
);
let
currencyDataModel
=
new
CurrencyApi
(
that
.
ctx
);
let
yohoCoinInfo
=
yield
currencyDataModel
.
yohoCoinTotal
(
uid
);
if
(
_
.
get
(
yohoCoinInfo
,
'code'
)
===
200
)
{
let
yohoCoinInfoData
=
yohoCoinInfo
.
data
;
...
...
@@ -132,21 +143,19 @@ const currencyData = (uid, prama)=>{
};
}
}
let
currency
=
yield
currencyList
(
uid
,
condition
);
let
currency
=
yield
that
.
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
)
tabs
:
that
.
currencyTabs
(
condition
.
queryType
),
options
:
that
.
currencyOptions
(
condition
)
});
return
result
;
})();
};
}
module
.
exports
=
{
currencyData
};
...
...
apps/home/models/general-tabs-service.js
View file @
7ff4c7b
...
...
@@ -2,20 +2,27 @@
const
_
=
require
(
'lodash'
);
const
u
serApi
=
require
(
'./user-api'
);
const
U
serApi
=
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
)
=>
{
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/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'
},
...
...
@@ -68,10 +75,11 @@ const _homeNav = (switcher) => {
]
}
];
};
}
const
_getActiveNav
=
(
url
,
switcher
,
count
)
=>
{
let
mHomeNav
=
_
.
cloneDeep
(
_homeNav
(
switcher
));
_getActiveNav
(
url
,
switcher
,
count
)
{
let
that
=
this
;
let
mHomeNav
=
_
.
cloneDeep
(
that
.
_homeNav
(
switcher
));
let
activeNav
=
null
;
mHomeNav
=
mHomeNav
.
map
((
item
)
=>
{
...
...
@@ -114,29 +122,37 @@ const _getActiveNav = (url, switcher, count) =>{
homeNav
:
mHomeNav
,
activeNav
:
activeNav
};
};
}
_getAvatar
(
uid
)
{
let
userDataModel
=
new
UserApi
(
this
.
ctx
);
const
_getAvatar
=
(
uid
)
=>
{
return
userApi
.
getUserInfo
(
uid
).
then
((
result
)
=>
{
return
userDataModel
.
getUserInfo
(
uid
).
then
((
result
)
=>
{
return
_
.
get
(
result
,
'data.head_ico'
,
''
)
||
defaultAvatar
;
});
};
}
const
_msgCount
=
(
uid
)
=>
{
return
msgModel
.
unreadTotal
(
uid
).
then
(
result
=>
_
.
get
(
result
,
'data.total'
,
0
));
};
_msgCount
(
uid
)
{
let
msgDataModel
=
new
MsgApi
(
this
.
ctx
);
return
msgDataModel
.
unreadTotal
(
uid
).
then
(
result
=>
_
.
get
(
result
,
'data.total'
,
0
));
}
_getTabsData
(
uid
,
channel
)
{
let
that
=
this
;
const
_getTabsData
=
(
uid
,
channel
)
=>
{
return
Promise
.
props
({
msg
:
_msgCount
(
uid
),
msg
:
that
.
_msgCount
(
uid
),
header
:
headerModel
.
requestHeaderData
(
channel
),
avatar
:
_getAvatar
(
uid
)
avatar
:
that
.
_getAvatar
(
uid
)
});
};
}
getHomeNav
(
uid
,
channel
,
url
,
clientSwitcher
)
{
let
that
=
this
;
const
getHomeNav
=
(
uid
,
channel
,
url
,
clientSwitcher
)
=>
{
return
_getTabsData
(
uid
,
channel
).
then
((
result
)
=>
{
let
navs
=
_getActiveNav
(
url
,
clientSwitcher
,
result
.
msg
);
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 有货首页'
}];
...
...
@@ -172,8 +188,6 @@ const getHomeNav = (uid, channel, url, clientSwitcher) => {
userThumb
:
result
.
avatar
},
result
.
header
);
});
};
}
module
.
exports
=
{
getHomeNav
};
...
...
apps/home/models/gift-service.js
View file @
7ff4c7b
...
...
@@ -7,20 +7,28 @@
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'
);
/**
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
/**
* 礼品卡页面
*/
exports
.
index
=
(
params
,
uid
)
=>
{
index
(
params
,
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
respData
=
{},
type
=
params
.
type
||
''
,
yohoCoinResult
;
let
currencyDataModel
=
new
CurrencyApi
(
that
.
ctx
);
if
(
type
!==
''
)
{
yohoCoinResult
=
yield
currencyApi
.
yohoCoinTotal
(
uid
);
yohoCoinResult
=
yield
currencyDataModel
.
yohoCoinTotal
(
uid
);
let
yohoCoinInfo
=
yohoCoinResult
.
data
;
if
(
yohoCoinInfo
)
{
...
...
@@ -39,21 +47,27 @@ exports.index = (params, uid) => {
return
respData
;
})();
};
}
/**
/**
* 个人中心-兑换礼品卡提交返回信息
*/
exports
.
exchange
=
(
req
,
params
,
uid
)
=>
{
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
||
''
);
let
respData
=
yield
userApi
.
exchangeGift
(
data
,
uid
);
let
respData
=
yield
userDataModel
.
exchangeGift
(
data
,
uid
);
return
respData
;
})();
}
};
...
...
apps/home/models/message.js
View file @
7ff4c7b
...
...
@@ -5,25 +5,36 @@
*/
'use strict'
;
const
api
=
global
.
yoho
.
API
;
const
_
=
require
(
'lodash'
);
const
Promise
=
require
(
'bluebird'
);
const
u
serApi
=
require
(
'./user-api'
);
const
U
serApi
=
require
(
'./user-api'
);
const
setPager
=
require
(
`
$
{
global
.
utils
}
/pager`
)
.setPager
;
const
co
=
Promise
.
coroutine
;
const
getMessageTabList
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
getMessageTabList
(
uid
)
{
let
data
=
{
method
:
'app.inbox.getAllInboxCatInfo'
,
uid
:
uid
},
{
code
:
200
});
};
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
const
getMessageAsync
=
(
uid
,
page
,
size
,
type
)
=>
{
let
params
=
{
getMessageAsync
(
uid
,
page
,
size
,
type
)
{
let
data
=
{
method
:
'app.inbox.getlistnew'
,
uid
:
uid
,
page
:
page
||
1
,
...
...
@@ -31,66 +42,111 @@ const getMessageAsync = (uid, page, size, type) => {
};
if
(
type
)
{
params
.
displayTab
=
type
;
data
.
displayTab
=
type
;
}
return
api
.
get
(
''
,
params
,
{
code
:
200
});
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
}
const
delMessageAsync
=
(
uid
,
id
)
=>
{
return
api
.
get
(
''
,
{
delMessageAsync
(
uid
,
id
)
{
let
data
=
{
method
:
'app.inbox.delmessage'
,
uid
:
uid
,
id
:
id
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
const
readMessageAsync
=
(
uid
,
id
)
=>
{
return
api
.
get
(
''
,
{
readMessageAsync
(
uid
,
id
)
{
let
data
=
{
method
:
'web.inbox.setread'
,
uid
:
uid
,
ids
:
id
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
const
getBirthCouponAsync
=
(
uid
,
couponId
)
=>
{
return
api
.
get
(
''
,
{
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 } 生日券数据
*/
const
getCouponAsync
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
getCouponAsync
(
uid
)
{
let
data
=
{
method
:
'app.promotion.queryBirthCoupon'
,
uid
:
uid
,
couponType
:
4
},
{
code
:
200
})
;
}
;
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
/**
}
/**
* 未读消息
* @function unreadTotal
* @param { Number } uid 用户uid
* @return { Number } 未读消息数量
*/
const
unreadTotal
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
unreadTotal
(
uid
)
{
let
data
=
{
method
:
'app.inbox.getTotal'
,
uid
:
uid
,
is_read
:
'N'
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 获取消息列表
* @function getMessageList
* @param { Number } uid 用户uid
...
...
@@ -98,15 +154,17 @@ const unreadTotal = (uid) => {
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
const
getMessageList
=
(
uid
,
params
,
limit
)
=>
{
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
([
userApi
.
getUserInfo
(
uid
),
getMessageTabList
(
uid
),
getMessageAsync
(
uid
,
page
,
limit
,
type
)
userDataModel
.
getUserInfo
(
uid
),
that
.
getMessageTabList
(
uid
),
that
.
getMessageAsync
(
uid
,
page
,
limit
,
type
)
]).
then
(
result
=>
{
const
msgBaseUrl
=
'/home/message'
;
...
...
@@ -194,9 +252,9 @@ const getMessageList = (uid, params, limit) => {
return
resData
;
});
};
}
/**
/**
* 获取消息内容
* @function getMessageDetail
* @param { Number } uid 用户uid
...
...
@@ -204,15 +262,17 @@ const getMessageList = (uid, params, limit) => {
* @param { Number } limit 每页数目
* @return { Object } 消息列表数据
*/
const
getMessageDetail
=
(
uid
,
params
,
limit
)
=>
{
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
([
userApi
.
getUserInfo
(
uid
),
getMessageAsync
(
uid
,
page
,
limit
,
type
)
userDataModel
.
getUserInfo
(
uid
),
that
.
getMessageAsync
(
uid
,
page
,
limit
,
type
)
]);
let
resData
=
{
backUrl
:
`
/
home
/
message
?
page
=
$
{
page
}
`
,
...
...
@@ -253,7 +313,7 @@ const getMessageDetail = (uid, params, limit) => {
break
;
}
let
couponInfo
=
yield
getCouponAsync
(
uid
);
let
couponInfo
=
yield
that
.
getCouponAsync
(
uid
);
let
coupons
=
[];
if
(
!
_
.
isEmpty
(
couponInfo
.
data
))
{
...
...
@@ -308,19 +368,20 @@ const getMessageDetail = (uid, params, limit) => {
};
return
co
(
process
)();
};
}
/**
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
const
delMessage
=
(
uid
,
mid
)
=>
{
delMessage
(
uid
,
mid
)
{
let
that
=
this
;
let
process
=
function
*
()
{
let
resData
=
{
code
:
400
,
message
:
'删除失败'
};
let
result
=
yield
delMessageAsync
(
uid
,
mid
);
let
result
=
yield
that
.
delMessageAsync
(
uid
,
mid
);
if
(
result
.
code
===
200
)
{
Object
.
assign
(
resData
,
{
...
...
@@ -333,19 +394,20 @@ const delMessage = (uid, mid) => {
};
return
co
(
process
)();
};
}
/**
/**
* 删除用户消息
* @function getMessageDetail
* @param { Number } uid 用户uid
* @param { Number } mid 消息id
* @return { Object } 消息列表数据
*/
const
readMessage
=
(
uid
,
mid
)
=>
{
readMessage
(
uid
,
mid
)
{
let
that
=
this
;
let
process
=
function
*
()
{
let
resData
=
{
code
:
400
,
message
:
'标记失败'
};
let
result
=
yield
readMessageAsync
(
uid
,
mid
);
let
result
=
yield
that
.
readMessageAsync
(
uid
,
mid
);
if
(
result
.
code
===
200
)
{
resData
=
result
;
...
...
@@ -355,17 +417,12 @@ const readMessage = (uid, mid) => {
};
return
co
(
process
)();
};
}
const
pickBirthCoupon
=
(
uid
,
id
)
=>
{
return
getBirthCouponAsync
(
uid
,
id
);
};
pickBirthCoupon
(
uid
,
id
)
{
let
that
=
this
;
module
.
exports
=
{
getMessageList
,
getMessageDetail
,
delMessage
,
readMessage
,
unreadTotal
,
pickBirthCoupon
return
that
.
getBirthCouponAsync
(
uid
,
id
);
}
};
...
...
apps/home/models/redenvelopes-api.js
View file @
7ff4c7b
'use strict'
;
const
api
=
global
.
yoho
.
API
;
/**
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
/**
* 获取红包列表
* $uid 用户ID
*/
const
getRedenvelopes
=
uid
=>
{
let
options
=
{
getRedenvelopes
(
uid
)
{
let
data
=
{
method
:
'app.yoho.redpacketList'
,
uid
:
uid
};
return
api
.
get
(
''
,
options
);
};
return
this
.
get
({
data
:
data
,
params
:
{
code
:
200
}
});
}
/**
/**
* 获取红包列表
* uid 用户ID
*/
const
getRedenvelopesTotal
=
uid
=>
{
let
options
=
{
getRedenvelopesTotal
(
uid
)
{
let
data
=
{
method
:
'app.yoho.redpacketInfo'
,
uid
:
uid
};
return
api
.
get
(
''
,
options
);
};
return
this
.
get
({
data
:
data
,
params
:
{
code
:
200
}
});
}
module
.
exports
=
{
getRedenvelopes
,
getRedenvelopesTotal
};
...
...
apps/home/models/redenvelopes-model.js
View file @
7ff4c7b
...
...
@@ -2,12 +2,21 @@
const
Promise
=
require
(
'bluebird'
);
const
co
=
Promise
.
coroutine
;
const
_
=
require
(
'lodash'
);
const
redenvelopesData
=
require
(
'./redenvelopes-api.js'
);
const
RedenvelopesApi
=
require
(
'./redenvelopes-api.js'
);
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
redenvelopesList
(
uid
)
{
let
that
=
this
;
const
redenvelopesList
=
uid
=>
{
return
co
(
function
*
()
{
let
result
=
{};
let
data
=
yield
redenvelopesData
.
getRedenvelopesTotal
(
uid
);
let
redenvelopesDataModel
=
new
RedenvelopesApi
(
that
.
ctx
);
let
data
=
yield
redenvelopesDataModel
.
getRedenvelopesTotal
(
uid
);
if
(
_
.
get
(
data
,
'code'
)
===
200
&&
_
.
get
(
data
,
'data.redpacket_num'
))
{
result
.
money
=
_
.
get
(
data
,
'data.redpacket_num'
);
...
...
@@ -18,8 +27,6 @@ const redenvelopesList = uid=>{
'3.限有效期内使用,过期清零'
;
return
{
redEnvelopes
:
[
result
]};
})();
};
}
module
.
exports
=
{
redenvelopesList
};
...
...
apps/home/models/user-api.js
View file @
7ff4c7b
...
...
@@ -3,55 +3,107 @@
* @author: gaohongwei<hongwei.gao@yoho.cn>
* @date: 2016/8/16
*/
const
api
=
global
.
yoho
.
API
;
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
const
getUserInfo
=
uid
=>
{
return
api
.
get
(
''
,
{
getUserInfo
(
uid
)
{
let
data
=
{
method
:
'app.passport.profile'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
getUserContactInfo
(
uid
)
{
const
getUserContactInfo
=
uid
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.getUserContacts'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
getProviceCityInfo
(
parentId
)
{
const
getProviceCityInfo
=
(
parentId
)
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'app.address.provinces'
,
id
:
parentId
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
const
getUserHabitsInfo
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
getUserHabitsInfo
(
uid
)
{
let
data
=
{
method
:
'web.passport.getUserHabits'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
getUserLikeBrand
(
uid
)
{
const
getUserLikeBrand
=
(
uid
)
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.passport.getLikeBrand'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
getTipConfig
(
uid
)
{
const
getTipConfig
=
(
uid
)
=>
{
return
api
.
post
(
''
,
{
let
data
=
{
method
:
'app.resources.config.clientInitConfig'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 修改用户联系信息
*/
const
editUserInfo
=
(
userInfo
)
=>
{
return
api
.
get
(
''
,
{
editUserInfo
(
userInfo
)
{
let
data
=
{
method
:
'app.passport.modifyBase'
,
uid
:
userInfo
.
uid
,
nick_name
:
userInfo
.
nickname
,
...
...
@@ -60,14 +112,22 @@ const editUserInfo = (userInfo) => {
profession
:
userInfo
.
profession
,
income
:
userInfo
.
income
,
birthday
:
userInfo
.
birthday
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 修改用户联系信息
*/
const
editUserContactInfo
=
(
contactInfo
)
=>
{
return
api
.
get
(
''
,
{
editUserContactInfo
(
contactInfo
)
{
let
data
=
{
method
:
'web.passport.modifyUserContacts'
,
uid
:
contactInfo
.
uid
,
area_code
:
contactInfo
.
areaCode
,
...
...
@@ -76,47 +136,78 @@ const editUserContactInfo = (contactInfo) => {
qq
:
contactInfo
.
qq
,
full_address
:
contactInfo
.
fullAddress
,
zip_code
:
contactInfo
.
zipCode
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 修改用户购物着装习惯信息
*/
const
editUserHabitsInfo
=
(
habitsInfo
)
=>
{
return
api
.
get
(
''
,
{
editUserHabitsInfo
(
habitsInfo
)
{
let
data
=
{
method
:
'web.passport.modifyUserHabits'
,
uid
:
habitsInfo
.
uid
,
shopping
:
habitsInfo
.
shopping
,
dress
:
habitsInfo
.
dress
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 修改用户喜欢品牌
*/
const
editUserLikeBrand
=
(
uid
,
brand
)
=>
{
return
api
.
get
(
''
,
{
editUserLikeBrand
(
uid
,
brand
)
{
let
data
=
{
method
:
'web.passport.modifyLikeBrand'
,
uid
:
uid
,
brand
:
brand
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 根据手机号获取用户信息[TODO +cache]
* @param string $area
* @param string $mobile
* @return array
*/
const
getUserInfoByMobile
=
(
area
,
mobile
)
=>
{
return
api
.
get
(
''
,
{
getUserInfoByMobile
(
area
,
mobile
)
{
let
data
=
{
method
:
'app.passport.getProfileByMobile'
,
area
:
area
,
mobile
:
mobile
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
/**
/**
* 兑换礼品卡
* @param type $uid
* @param type $giftCardCode1
...
...
@@ -124,64 +215,86 @@ const getUserInfoByMobile = (area, mobile) => {
* @param type $giftCardCode3
* @param type $captchaCode
*/
const
exchangeGift
=
(
params
,
uid
)
=>
{
return
api
.
get
(
''
,
{
exchangeGift
(
params
,
uid
)
{
let
data
=
{
method
:
'web.personCen.giftExchange'
,
uid
:
uid
,
giftCardCode1
:
params
.
giftCardCode1
,
giftCardCode2
:
params
.
giftCardCode2
,
giftCardCode3
:
params
.
giftCardCode3
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
const
bind3partyAccount
=
(
uid
,
param
)
=>
{
return
api
.
get
(
''
,
{
bind3partyAccount
(
uid
,
param
)
{
let
data
=
{
method
:
'app.passport.bindOpenId'
,
uid
:
uid
,
open_id
:
param
.
openId
,
source_type
:
param
.
sourceType
,
nickname
:
param
.
nickname
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
cancelBind3partyAccount
(
uid
,
type
)
{
const
cancelBind3partyAccount
=
(
uid
,
type
)
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'app.passport.removeBindOpenId'
,
uid
:
uid
,
source_type
:
type
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
getFavorBrand
()
{
const
getFavorBrand
=
()
=>
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'web.search.favorBrand'
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
const
getCanRemoveBindOpenIdTag
=
(
uid
)
=>
{
getCanRemoveBindOpenIdTag
(
uid
)
{
return
api
.
get
(
''
,
{
let
data
=
{
method
:
'app.passport.isCanRemoveBindOpenId'
,
uid
:
uid
};
return
this
.
get
({
data
:
data
,
param
:
{
code
:
200
}
});
};
}
module
.
exports
=
{
getUserInfo
,
editUserInfo
,
getUserContactInfo
,
editUserContactInfo
,
getProviceCityInfo
,
getUserHabitsInfo
,
editUserHabitsInfo
,
getUserLikeBrand
,
editUserLikeBrand
,
getTipConfig
,
getUserInfoByMobile
,
exchangeGift
,
bind3partyAccount
,
cancelBind3partyAccount
,
getFavorBrand
,
getCanRemoveBindOpenIdTag
};
...
...
apps/home/models/user-service.js
View file @
7ff4c7b
...
...
@@ -9,7 +9,7 @@ const Promise = require('bluebird');
const
co
=
Promise
.
coroutine
;
const
api
=
global
.
yoho
.
API
;
const
_
=
require
(
'lodash'
);
const
u
serApi
=
require
(
'./user-api'
);
const
U
serApi
=
require
(
'./user-api'
);
const
helpers
=
global
.
yoho
.
helpers
;
const
Images
=
require
(
'../../../utils/images'
);
...
...
@@ -135,16 +135,22 @@ const configData = {
'2016/07/05/13/017ec560b82c132ab2fdb22f7cf6f42b83.png?imageView/2/w/100/h/100'
};
const
getDays
=
(
year
,
month
)
=>
{
module
.
exports
=
class
extends
global
.
yoho
.
BaseModel
{
constructor
(
ctx
)
{
super
(
ctx
);
}
getDays
(
year
,
month
)
{
let
m
=
(
month
-
1
)
%
7
%
2
?
30
:
31
,
y400
=
year
%
400
?
28
:
29
,
y100
=
year
%
100
?
29
:
y400
,
y4
=
year
%
4
?
28
:
y100
;
return
month
===
2
?
y4
:
m
;
};
}
const
getBirthday
=
(
birthday
)
=>
{
getBirthday
(
birthday
)
{
let
that
=
this
;
let
year
=
parseInt
(
birthday
.
split
(
'-'
)[
0
],
0
),
month
=
parseInt
(
birthday
.
split
(
'-'
)[
1
],
0
),
day
=
parseInt
(
birthday
.
split
(
'-'
)[
2
],
0
),
...
...
@@ -152,7 +158,7 @@ const getBirthday = (birthday) => {
yearArr
=
[{
value
:
0
,
text
:
'年'
}],
monthArr
=
[{
value
:
0
,
text
:
'月'
}],
dayArr
=
[{
value
:
0
,
text
:
'日'
}],
days
=
getDays
(
year
,
month
);
days
=
that
.
getDays
(
year
,
month
);
for
(
let
i
=
1950
;
i
<=
nowYear
;
i
++
)
{
let
yearJson
=
{
value
:
i
,
text
:
i
};
...
...
@@ -186,15 +192,15 @@ const getBirthday = (birthday) => {
monthArr
:
monthArr
,
dayArr
:
dayArr
};
};
}
const
formatDate
=
(
y
,
m
,
d
)
=>
{
formatDate
(
y
,
m
,
d
)
{
m
=
m
<
10
?
(
'0'
+
m
)
:
m
;
d
=
d
<
10
?
(
'0'
+
d
)
:
d
;
return
y
+
'-'
+
m
+
'-'
+
d
;
};
}
const
getHotBrands
=
(
brandList
)
=>
{
getHotBrands
(
brandList
)
{
let
hotBrands
=
[],
i
=
20
;
...
...
@@ -216,14 +222,18 @@ const getHotBrands = (brandList) => {
}
return
hotBrands
;
};
}
/**
/**
* 联动取地区信息
*/
const
getProviceCityInfo
=
(
parentId
,
checkValue
)
=>
{
getProviceCityInfo
(
parentId
,
checkValue
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
addressInfo
=
yield
userApi
.
getProviceCityInfo
(
parentId
),
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
addressInfo
=
yield
userDataModel
.
getProviceCityInfo
(
parentId
),
res
=
[{
value
:
0
}],
defaultText
;
...
...
@@ -254,20 +264,22 @@ const getProviceCityInfo = (parentId, checkValue) => {
return
res
;
})();
};
}
const
getUserInfo
=
(
uid
)
=>
{
getUserInfo
(
uid
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
result
=
yield
api
.
all
([
userApi
.
getUserInfo
(
uid
),
userApi
.
getTipConfig
(
uid
),
userApi
.
getUserContactInfo
(
uid
),
userApi
.
getUserHabitsInfo
(
uid
),
userApi
.
getUserLikeBrand
(
uid
),
userApi
.
getFavorBrand
(),
userApi
.
getCanRemoveBindOpenIdTag
(
uid
)
userDataModel
.
getUserInfo
(
uid
),
userDataModel
.
getTipConfig
(
uid
),
userDataModel
.
getUserContactInfo
(
uid
),
userDataModel
.
getUserHabitsInfo
(
uid
),
userDataModel
.
getUserLikeBrand
(
uid
),
userDataModel
.
getFavorBrand
(),
userDataModel
.
getCanRemoveBindOpenIdTag
(
uid
)
// searchApi.get('/brand/list.json', {}, {cache: true})
]);
...
...
@@ -322,7 +334,7 @@ const getUserInfo = (uid) => {
}
}
birthdayJson
=
getBirthday
(
birthday
);
birthdayJson
=
that
.
getBirthday
(
birthday
);
yearArr
=
birthdayJson
.
yearArr
;
monthArr
=
birthdayJson
.
monthArr
;
dayArr
=
birthdayJson
.
dayArr
;
...
...
@@ -407,19 +419,19 @@ const getUserInfo = (uid) => {
areaOpts
=
[{
value
:
0
,
text
:
'请选择区县'
}];
if
(
areaCodeStr
.
length
<
2
)
{
proviceOpts
=
yield
getProviceCityInfo
(
0
);
proviceOpts
=
yield
that
.
getProviceCityInfo
(
0
);
}
if
(
areaCodeStr
.
length
>=
2
)
{
proviceOpts
=
yield
getProviceCityInfo
(
0
,
areaCodeStr
.
substr
(
0
,
2
));
proviceOpts
=
yield
that
.
getProviceCityInfo
(
0
,
areaCodeStr
.
substr
(
0
,
2
));
}
if
(
areaCodeStr
.
length
>=
4
)
{
cityOpts
=
yield
getProviceCityInfo
(
areaCodeStr
.
substr
(
0
,
2
),
areaCodeStr
.
substr
(
0
,
4
));
cityOpts
=
yield
that
.
getProviceCityInfo
(
areaCodeStr
.
substr
(
0
,
2
),
areaCodeStr
.
substr
(
0
,
4
));
}
if
(
areaCodeStr
.
length
>=
6
)
{
areaOpts
=
yield
getProviceCityInfo
(
areaCodeStr
.
substr
(
0
,
4
),
areaCodeStr
);
areaOpts
=
yield
that
.
getProviceCityInfo
(
areaCodeStr
.
substr
(
0
,
4
),
areaCodeStr
);
}
finalResult
.
contactInfo
=
{
...
...
@@ -525,7 +537,7 @@ const getUserInfo = (uid) => {
brandList
=
result
[
5
].
data
,
favBrands
=
[];
let
hotBrands
=
getHotBrands
(
brandList
);
let
hotBrands
=
that
.
getHotBrands
(
brandList
);
if
(
likeBrandStr
!==
''
)
{
let
brandArr
=
likeBrandStr
.
split
(
','
);
...
...
@@ -590,16 +602,19 @@ const getUserInfo = (uid) => {
finalResult
.
meEditPage
=
true
;
return
finalResult
;
})();
};
}
const
editUserInfo
=
(
req
,
uid
)
=>
{
editUserInfo
(
req
,
uid
)
{
let
that
=
this
;
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
respData
,
userInfo
=
{
uid
:
uid
,
nickname
:
_
.
trim
(
req
.
body
.
nickname
),
username
:
_
.
trim
(
req
.
body
.
username
),
gender
:
req
.
body
.
gender
||
3
,
birthday
:
req
.
body
.
year
===
''
?
''
:
formatDate
(
req
.
body
.
year
,
req
.
body
.
month
,
req
.
body
.
day
),
birthday
:
req
.
body
.
year
===
''
?
''
:
that
.
formatDate
(
req
.
body
.
year
,
req
.
body
.
month
,
req
.
body
.
day
),
profession
:
req
.
body
.
profession
||
0
,
income
:
req
.
body
.
income
||
0
};
...
...
@@ -611,14 +626,17 @@ const editUserInfo = (req, uid) => {
data
:
''
};
}
else
{
respData
=
userApi
.
editUserInfo
(
userInfo
);
respData
=
userDataModel
.
editUserInfo
(
userInfo
);
}
return
respData
;
};
}
editUserContactInfo
(
req
,
uid
)
{
let
that
=
this
;
const
editUserContactInfo
=
(
req
,
uid
)
=>
{
return
co
(
function
*
()
{
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
contactInfo
=
{},
respData
;
...
...
@@ -640,16 +658,19 @@ const editUserContactInfo = (req, uid) => {
return
respData
;
}
respData
=
yield
userApi
.
editUserContactInfo
(
contactInfo
);
respData
=
yield
userDataModel
.
editUserContactInfo
(
contactInfo
);
return
respData
;
})();
};
}
editUserHabitsInfo
(
req
,
uid
)
{
let
that
=
this
;
const
editUserHabitsInfo
=
(
req
,
uid
)
=>
{
return
co
(
function
*
()
{
let
habitsInfo
=
{},
dressArr
=
[],
respData
;
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
habitsInfo
.
uid
=
uid
;
habitsInfo
.
shopping
=
req
.
body
.
shopping
;
...
...
@@ -670,16 +691,19 @@ const editUserHabitsInfo = (req, uid) => {
return
respData
;
}
respData
=
yield
userApi
.
editUserHabitsInfo
(
habitsInfo
);
respData
=
yield
userDataModel
.
editUserHabitsInfo
(
habitsInfo
);
return
respData
;
})();
};
}
editUserLikeBrand
(
req
,
uid
)
{
let
that
=
this
;
const
editUserLikeBrand
=
(
req
,
uid
)
=>
{
return
co
(
function
*
()
{
let
brand
,
respData
;
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
brand
=
req
.
body
.
brand
;
...
...
@@ -693,16 +717,18 @@ const editUserLikeBrand = (req, uid) => {
return
respData
;
}
respData
=
yield
userApi
.
editUserLikeBrand
(
uid
,
brand
);
respData
=
yield
userDataModel
.
editUserLikeBrand
(
uid
,
brand
);
return
respData
;
})();
};
}
const
isBrandName
=
(
req
)
=>
{
isBrandName
(
req
)
{
let
that
=
this
;
return
co
(
function
*
()
{
let
result
=
yield
userApi
.
getFavorBrand
();
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
result
=
yield
userDataModel
.
getFavorBrand
();
let
brandList
=
result
.
data
,
...
...
@@ -744,12 +770,15 @@ const isBrandName = (req) => {
}
})();
};
}
getProviceList
(
pid
)
{
let
that
=
this
;
const
getProviceList
=
(
pid
)
=>
{
return
co
(
function
*
()
{
let
userDataModel
=
new
UserApi
(
that
.
ctx
);
let
reqData
=
{},
proList
=
yield
userApi
.
getProviceCityInfo
(
pid
),
proList
=
yield
userDataModel
.
getProviceCityInfo
(
pid
),
opts
=
[];
reqData
.
code
=
proList
.
code
;
...
...
@@ -765,26 +794,18 @@ const getProviceList = (pid) => {
}
return
reqData
;
})();
};
}
const
bind3partyAccount
=
(
uid
,
param
)
=>
{
bind3partyAccount
(
uid
,
param
)
{
let
userDataModel
=
new
UserApi
(
this
.
ctx
);
return
userApi
.
bind3partyAccount
(
uid
,
param
);
};
return
userDataModel
.
bind3partyAccount
(
uid
,
param
);
}
const
cancelBind3partyAccount
=
(
uid
,
type
)
=>
{
cancelBind3partyAccount
(
uid
,
type
)
{
let
userDataModel
=
new
UserApi
(
this
.
ctx
);
return
userApi
.
cancelBind3partyAccount
(
uid
,
type
);
};
return
userDataModel
.
cancelBind3partyAccount
(
uid
,
type
);
}
module
.
exports
=
{
getUserInfo
,
editUserInfo
,
editUserContactInfo
,
editUserHabitsInfo
,
editUserLikeBrand
,
getProviceList
,
isBrandName
,
bind3partyAccount
,
cancelBind3partyAccount
};
...
...
Please
register
or
login
to post a comment