Authored by 郭成尧

favorite-product

... ... @@ -6,6 +6,7 @@ const _ = require('lodash');
const detailModel = require('../models/detail');
const newDetailModel = require('../models/new-detail');
const listModel = require('../models/list');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const newDetail = {
... ... @@ -115,6 +116,27 @@ const newDetail = {
result.studentPrice = req.__User__.isStudent && result && result.goodsPrice && result.goodsPrice.studentPrice ? result.goodsPrice.studentPrice : false;
return res.json(result);
}).catch(next);
},
/**
* 商品收藏/取消收藏
*/
favoriteProduct(req, res, next) {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
if (req.body.opt === 'ok') {
listModel.setFavorite(req.body.id, req.user.uid, 'product').then(result => {
return res.json(result);
}).catch(next);
} else {
listModel.setFavoriteCancel(req.body.id, req.user.uid, 'product').then(result => {
return res.json(result);
}).catch(next);
}
}
};
... ...
... ... @@ -176,4 +176,6 @@ router.get('/newsale/selectHotrank', newsale.selectHotrank); // 热销排行榜
router.get('/bundle/detail', bundle.detail); // 套装详情页
router.post('/opt/favoriteProduct', newDetail.favoriteProduct); // 商品收藏、取消收藏
module.exports = router;
... ...