Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yohobuywap-node
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Plain Diff
Browse Files
Authored by
王水玲
9 years ago
Commit
b39f9ff99e4f78e95b0ec0b1065773e3ff1cf4f1
2 parents
ffdd4454
2f958148
Merge branch 'release/4.6' of git.yoho.cn:fe/yohobuywap-node into release/4.6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
47 deletions
app.js
apps/product/controllers/outlet.js
apps/product/models/outlet.js
doraemon/middleware/set-pageinfo.js
app.js
View file @
b39f9ff
...
...
@@ -83,10 +83,13 @@ try {
const
user
=
require
(
'./doraemon/middleware/user'
);
const
setChannel
=
require
(
'./doraemon/middleware/set-channel'
);
const
errorHanlder
=
require
(
'./doraemon/middleware/error-handler'
);
const
setPageInfo
=
require
(
'./doraemon/middleware/set-pageinfo'
);
// YOHO 前置中间件
app
.
use
(
user
());
app
.
use
(
setChannel
());
app
.
use
(
setPageInfo
());
require
(
'./dispatch'
)(
app
);
...
...
apps/product/controllers/outlet.js
View file @
b39f9ff
...
...
@@ -8,32 +8,40 @@
const
outletModel
=
require
(
'../models/outlet'
);
const
headerModel
=
require
(
'../../../doraemon/models/header'
);
const
renderData
=
{
module
:
'product'
};
const
yhChannelEmpty
=
0
;
const
willEndActivity
=
{
type
:
2
,
template
:
'outlet/will-end'
,
page
:
'outlet-will-end'
}
const
willStartActivity
=
{
type
:
3
,
template
:
'outlet/will-start'
,
page
:
'outlet-will-start'
}
// 奥莱首页控制器
exports
.
index
=
(
req
,
res
)
=>
{
exports
.
index
=
(
req
,
res
,
next
)
=>
{
let
headerData
=
headerModel
.
setNav
({
navTitle
:
'OUTLET'
,
navBtn
:
false
});
let
categoryId
=
req
.
query
.
category_id
;
let
yhChannel
=
req
.
query
.
yh_channel
||
0
;
let
yhChannel
=
req
.
query
.
yh_channel
||
yhChannelEmpty
;
let
contentcode
=
req
.
query
.
content_code
;
outletModel
.
getContent
(
categoryId
,
yhChannel
,
contentcode
).
then
(
result
=>
{
res
.
render
(
'outlet'
,
Object
.
assign
({
page
:
'outlet'
,
pageHeader
:
headerData
},
renderData
,
result
));
});
},
result
));
}).
catch
(
next
);
};
// 奥莱活动详情页
exports
.
activityDetail
=
(
req
,
res
)
=>
{
exports
.
activityDetail
=
(
req
,
res
,
next
)
=>
{
outletModel
.
getActivity
(
req
.
query
.
id
).
then
(
result
=>
{
let
headerData
=
headerModel
.
setNav
({
navTitle
:
result
.
activityTitle
,
...
...
@@ -44,30 +52,42 @@ exports.activityDetail = (req, res) => {
page
:
'outlet-detail'
,
pageHeader
:
headerData
,
pageFooter
:
true
},
renderData
,
result
));
});
},
result
));
}).
catch
(
next
);
};
// 奥莱活动频道列表页
exports
.
activityList
=
(
req
,
res
)
=>
{
exports
.
activityList
=
(
req
,
res
,
next
)
=>
{
let
headerData
=
headerModel
.
setNav
({
navTitle
:
'OUTLET'
,
navBtn
:
false
});
let
categoryId
=
req
.
query
.
category_id
;
let
type
=
req
.
query
.
type
||
2
;
let
template
=
parseInt
(
type
,
10
)
===
2
?
'outlet/will-end'
:
'outlet/will-start'
;
let
page
=
parseInt
(
type
,
10
)
===
2
?
'outlet-will-end'
:
'outlet-will-start'
;
let
type
=
req
.
query
.
type
||
willEndActivity
.
type
;
let
template
;
let
page
;
if
(
!
categoryId
)
{
throw
new
Error
(
'No parent_id for OUTLET channel page!'
);
}
// 根据请求的类型确定要渲染的是即将结束页面还是上线预告页面
if
(
parseInt
(
type
,
10
)
===
willEndActivity
.
type
)
{
template
=
willEndActivity
.
template
;
page
=
willEndActivity
.
page
;
}
else
{
template
=
willStartActivity
.
template
;
page
=
willStartActivity
.
page
;
}
outletModel
.
getRecentActivity
(
type
,
categoryId
).
then
(
result
=>
{
res
.
render
(
template
,
Object
.
assign
({
page
:
page
,
pageHeader
:
headerData
,
pageFooter
:
true
},
renderData
,
result
));
});
},
result
));
}).
catch
(
next
);
};
...
...
apps/product/models/outlet.js
View file @
b39f9ff
...
...
@@ -31,7 +31,7 @@ const dateFormate = (str) =>{
};
// 为了活动卡片特殊样式,将折扣信息拆分开来
const
transDiscountToArr
=
(
discount
)
=>
{
const
_
transDiscountToArr
=
(
discount
)
=>
{
return
discount
.
replace
(
/
(?:\d
+
[
.
\d]?)([\u
4e00-
\u
9fa5
]{1})
/g
,
function
(
fullMatch
,
capture
)
{
if
(
capture
)
{
const
arr
=
[];
...
...
@@ -52,7 +52,7 @@ const transDiscountToArr = (discount) => {
* @param {String} contentcode 内容码
* @return {Promise}
*/
const
getOutletResource
=
(
channel
,
contentcode
)
=>
{
const
_
getOutletResource
=
(
channel
,
contentcode
)
=>
{
const
params
=
{
content_code
:
contentcode
||
'c19ffa03f053f4cac3690b22c8da26b7'
,
limit
:
25
,
...
...
@@ -63,7 +63,7 @@ const getOutletResource = (channel, contentcode) => {
if
(
result
&&
result
.
code
===
200
)
{
return
resourcesProcess
(
result
.
data
.
list
);
}
else
{
log
.
error
(
'
奥莱资源位接口返回状态码 不是 200'
);
log
.
error
(
'
the response code of outlet "operations/api/v5/resource/home" is NOT 200'
,
result
);
return
[];
}
});
...
...
@@ -74,7 +74,7 @@ const getOutletResource = (channel, contentcode) => {
* @param {[Object]} 原始导航数据
* @return {Object} 转换后的数据
*/
const
convertNavData
=
(
list
)
=>
{
const
_
convertNavData
=
(
list
)
=>
{
const
formatData
=
[];
list
=
list
||
[];
...
...
@@ -95,20 +95,19 @@ const convertNavData = (list) => {
* @param {String} 导航类型id
* @return {Promise}
*/
const
getNavData
=
(
categoryId
)
=>
{
const
_
getNavData
=
(
categoryId
)
=>
{
const
params
=
{
v
:
7
,
parent_id
:
categoryId
};
return
serviceApi
.
get
(
'operations/api/v6/category/getCategory'
,
sign
.
apiSign
(
params
)).
then
(
result
=>
{
if
(
result
&&
result
.
code
===
200
)
{
let
data
=
convertNavData
(
result
.
data
);
let
data
=
_
convertNavData
(
result
.
data
);
data
.
category
=
categoryId
;
return
data
;
}
else
{
log
.
error
(
'
奥莱导航接口返回状态码 不是
200'
,
result
);
log
.
error
(
'
the response code of "operations/api/v6/category/getCategory" is NOT
200'
,
result
);
return
[];
}
});
...
...
@@ -119,7 +118,7 @@ const getNavData = (categoryId) => {
* @param {Object} data 原始数据
* @return {Object} 转换后的数据
*/
const
convertActicityData
=
(
data
)
=>
{
const
_
convertActicityData
=
(
data
)
=>
{
const
formatData
=
[];
let
discountArr
=
[],
...
...
@@ -130,11 +129,11 @@ const convertActicityData = (data) => {
_
.
forEach
(
data
,
(
item
)
=>
{
discountArr
=
item
.
promotionName
.
split
(
'~'
);
if
(
discountArr
.
length
===
1
)
{
discountNum
=
transDiscountToArr
(
discountArr
[
0
])[
0
];
discountText
=
transDiscountToArr
(
discountArr
[
0
])[
1
];
discountNum
=
_transDiscountToArr
(
discountArr
[
0
])[
0
];
discountText
=
_transDiscountToArr
(
discountArr
[
0
])[
1
];
}
else
{
discountNum
=
discountArr
[
0
]
+
'~'
+
transDiscountToArr
(
discountArr
[
1
])[
0
];
discountText
=
transDiscountToArr
(
discountArr
[
1
])[
1
];
discountNum
=
discountArr
[
0
]
+
'~'
+
_transDiscountToArr
(
discountArr
[
1
])[
0
];
discountText
=
_transDiscountToArr
(
discountArr
[
1
])[
1
];
}
...
...
@@ -159,21 +158,21 @@ const convertActicityData = (data) => {
* @param {String} id 活动id
* @return {Promise} 调用接口的Promise
*/
const
getActivityDetail
=
(
id
)
=>
{
const
_
getActivityDetail
=
(
id
)
=>
{
var
params
=
{
method
:
'app.outlets.activityGet'
,
sort
:
1
,
platform
:
3
,
sort
:
1
,
// 接口规定传1
platform
:
3
,
// h5平台代号
id
:
id
,
type
:
0
type
:
0
// 接口规定传0
};
return
api
.
get
(
''
,
sign
.
apiSign
(
params
)).
then
(
res
=>
{
if
(
res
.
code
===
200
)
{
return
convertActicityData
(
res
.
data
);
return
_
convertActicityData
(
res
.
data
);
}
else
{
log
.
error
(
'
获取奥莱活动详情页接口返回状态码 不是
200'
,
res
);
log
.
error
(
'
the response code of "app.outlets.activityGet" is NOT
200'
,
res
);
return
{};
}
});
...
...
@@ -184,14 +183,14 @@ const getActivityDetail = (id) => {
* @param {Object} data 请求接口所需的参数
* @return {Promise} 调用接口的Promise
*/
const
getHomeActivity
=
(
data
)
=>
{
const
_
getHomeActivity
=
(
data
)
=>
{
var
params
=
{
method
:
'app.outlets.activityGet'
,
platform
:
3
platform
:
3
// h5平台代号
};
return
api
.
get
(
''
,
sign
.
apiSign
(
_
.
assign
(
params
,
data
))).
then
(
res
=>
{
return
convertActicityData
(
res
.
data
);
return
_
convertActicityData
(
res
.
data
);
});
};
...
...
@@ -202,13 +201,13 @@ const getHomeActivity = (data) => {
* @param {Strting} code 内容码
* @return {Promise} 调用接口的Promise
*/
exports
.
getContent
=
(
categoryId
,
channel
,
code
)
=>
{
const
getContent
=
(
categoryId
,
channel
,
code
)
=>
{
let
params
=
{
type
:
0
,
type
:
0
,
// 获取全部奥莱活动列表, 不区分是否将开始或结束
yh_channel
:
channel
};
const
p
=
[
getNavData
(
categoryId
),
getOutletResource
(
channel
,
code
),
getHomeActivity
(
params
)];
const
p
=
[
_getNavData
(
categoryId
),
_getOutletResource
(
channel
,
code
),
_
getHomeActivity
(
params
)];
return
Promise
.
all
(
p
).
then
(
data
=>
{
...
...
@@ -225,13 +224,13 @@ exports.getContent = (categoryId, channel, code) => {
* @param {String} id 活动id
* @return {Promise} 调用接口的Promise
*/
exports
.
getActivity
=
(
id
)
=>
{
return
getActivityDetail
(
id
).
then
(
res
=>
{
const
getActivity
=
(
id
)
=>
{
return
_getActivityDetail
(
id
).
then
(
res
=>
{
return
{
activity
:
res
,
productPool
:
res
[
0
]
&&
res
[
0
].
productPoolId
||
''
,
activityTitle
:
res
[
0
]
&&
res
[
0
].
title
||
'OUTLET'
,
saleType
:
4
saleType
:
4
// 促销类型, 奥莱为4
};
});
};
...
...
@@ -242,12 +241,12 @@ exports.getActivity = (id) => {
* @param {String} categoryId 父级菜单id,用于标明当前页面是奥莱页面
* @return {Object} 活动列表数据
*/
exports
.
getRecentActivity
=
(
type
,
categoryId
)
=>
{
const
getRecentActivity
=
(
type
,
categoryId
)
=>
{
var
params
=
{
type
:
type
};
return
Promise
.
all
([
getNavData
(
categoryId
),
getHomeActivity
(
params
)]).
then
(
res
=>
{
return
Promise
.
all
([
_getNavData
(
categoryId
),
_
getHomeActivity
(
params
)]).
then
(
res
=>
{
return
{
nav
:
res
[
0
]
||
[],
...
...
@@ -255,3 +254,9 @@ exports.getRecentActivity = (type, categoryId) => {
};
});
};
module
.
exports
=
{
getContent
:
getContent
,
getActivity
:
getActivity
,
getRecentActivity
:
getRecentActivity
};
...
...
doraemon/middleware/set-pageinfo.js
0 → 100644
View file @
b39f9ff
/**
* 设置页面的module,page默认值
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/6/22
*/
'use strict'
;
module
.
exports
=
()
=>
{
return
(
req
,
res
,
next
)
=>
{
if
(
!
req
.
xhr
)
{
const
arr
=
req
.
path
.
substring
(
1
).
split
(
'/'
);
Object
.
assign
(
res
.
locals
,
{
module
:
arr
[
0
],
page
:
arr
[
1
]
});
}
next
();
};
};
...
...
Please
register
or
login
to post a comment