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
410ebee31ba1dd38a1de571ba72db62b3e675e78
2 parents
9eedeb3d
764132ee
Merge branch 'release/1019'
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
29 deletions
apps/product/controllers/favorite.js
apps/product/models/detail-service.js
apps/product/router.js
public/js/product/detail.page.js
apps/product/controllers/favorite.js
View file @
410ebee
...
...
@@ -17,10 +17,10 @@ const changeFavoriteBrand = (req, res, next) => {
if
(
uid
&&
brandId
)
{
brandService
.
changeAsync
(
uid
,
brandId
).
then
(
result
=>
{
res
.
json
(
result
);
re
turn
re
s
.
json
(
result
);
}).
catch
(
next
);
}
else
if
(
!
uid
)
{
res
.
json
({
re
turn
re
s
.
json
({
code
:
403
,
message
:
'用户ID不存在'
,
data
:
{
...
...
@@ -28,13 +28,29 @@ const changeFavoriteBrand = (req, res, next) => {
}
});
}
else
{
res
.
json
({
re
turn
re
s
.
json
({
code
:
400
,
message
:
'操作失败'
});
}
};
const
isFavoriteBrand
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
||
''
;
let
brandId
=
req
.
query
.
brandId
;
if
(
uid
&&
brandId
)
{
brandService
.
isFavoriteAsync
(
uid
,
brandId
).
then
(
result
=>
{
return
res
.
json
(
result
);
}).
catch
(
next
);
}
else
{
return
res
.
json
({
code
:
400
,
message
:
'状态失败'
});
}
};
const
collectProduct
=
(
req
,
res
,
next
)
=>
{
let
uid
=
req
.
user
.
uid
||
''
;
let
pid
=
req
.
body
.
productId
;
...
...
@@ -43,8 +59,7 @@ const collectProduct = (req, res, next) => {
if
(
uid
&&
pid
)
{
switch
(
type
)
{
case
'add'
:
{
productService
.
createAsync
(
uid
,
pid
)
productService
.
createAsync
(
uid
,
pid
)
.
then
(
result
=>
{
if
(
result
.
code
===
413
)
{
result
.
message
=
'该商品已经收藏'
;
...
...
@@ -53,22 +68,17 @@ const collectProduct = (req, res, next) => {
res
.
json
(
result
);
})
.
catch
(
next
);
break
;
}
break
;
case
'cancel'
:
{
productService
.
deleteAsync
(
uid
,
pid
)
productService
.
deleteAsync
(
uid
,
pid
)
.
then
(
result
=>
res
.
json
(
result
))
.
catch
(
next
);
break
;
}
break
;
default
:
{
res
.
json
({
code
:
400
,
message
:
'错误类型'
});
}
res
.
json
({
code
:
400
,
message
:
'错误类型'
});
}
}
else
if
(
!
uid
)
{
res
.
json
({
...
...
@@ -117,5 +127,6 @@ const collectShop = (req, res, next) => {
module
.
exports
=
{
changeFavoriteBrand
,
collectProduct
,
collectShop
collectShop
,
isFavoriteBrand
};
...
...
apps/product/models/detail-service.js
View file @
410ebee
...
...
@@ -67,7 +67,7 @@ const _getProductIntroAsync = (productId, productSkn) => {
* pid : product id
* bid : brand id
*/
const
_getProductFavoriteDataAsync
=
(
uid
,
pid
,
bid
)
=>
{
const
_getProductFavoriteDataAsync
=
(
uid
,
pid
)
=>
{
return
co
(
function
*
()
{
let
result
=
{
product
:
false
,
...
...
@@ -84,23 +84,14 @@ const _getProductFavoriteDataAsync = (uid, pid, bid) => {
requestApi
.
product
=
favoriteProductService
.
isFavoriteAsync
(
uid
,
pid
);
}
if
(
bid
)
{
requestApi
.
brand
=
favoriteBrandService
.
isFavoriteAsync
(
uid
,
bid
);
}
let
requestData
=
yield
Promise
.
props
(
requestApi
);
let
productData
=
requestData
.
product
;
let
brandData
=
requestData
.
brand
;
if
(
productData
)
{
result
.
product
=
productData
.
code
===
200
&&
productData
.
data
?
true
:
false
;
}
if
(
brandData
)
{
result
.
brand
=
brandData
.
code
&&
brandData
.
code
===
200
?
true
:
false
;
}
return
result
;
})();
};
...
...
@@ -1076,7 +1067,7 @@ const _detailDataPkg = (origin, uid, vipLevel, cookies) => {
let
requestApi
=
{
addition
:
_getProductAdditionInfoAsync
(
origin
),
// 预处理所有的数据
fav
:
_getProductFavoriteDataAsync
(
uid
,
result
.
productI
d
,
brandId
),
// 处理收藏喜欢数据
fav
:
_getProductFavoriteDataAsync
(
uid
,
result
.
productI
),
// 处理收藏喜欢数据
promotion
:
productAPI
.
getPromotionAsync
(
result
.
skn
)
// 打折信息
};
...
...
apps/product/router.js
View file @
410ebee
...
...
@@ -61,6 +61,7 @@ router.post('/index/favoriteBrand', favorite.changeFavoriteBrand);// 收藏品
router
.
post
(
'/item/togglecollect'
,
favorite
.
collectProduct
);
// 收藏商品
router
.
get
(
'/detail/header'
,
detail
.
productHeader
);
// 价格数据重新获取接口
router
.
get
(
'/detail/return'
,
detail
.
detailReturn
);
// 特殊商品退换货
router
.
get
(
'/index/isfav'
,
favorite
.
isFavoriteBrand
);
// 品牌收藏状态
// 搜索
router
.
get
(
'/search/index'
,
search
.
index
);
...
...
public/js/product/detail.page.js
View file @
410ebee
...
...
@@ -809,6 +809,20 @@ window.fetchReturn = fetchReturn;
$
(
'.main'
).
html
(
result
);
bindEvent
.
fire
();
});
$
.
ajax
({
type
:
'GET'
,
url
:
'/product/index/isfav'
,
dataType
:
'html'
,
data
:
{
brandId
:
$
(
'#brand-favour'
).
data
(
'id'
)
}
}).
then
(
function
(
result
)
{
if
(
result
.
code
===
200
)
{
$
(
'#brand-favour'
).
toggleClass
(
'coled'
);
}
});
}());
// 数据懒加载
...
...
Please
register
or
login
to post a comment