|
|
const FindGoods = require('../models/find-goods');
|
|
|
const _ = require('lodash');
|
|
|
const stringProcess = require('../../../utils/string-process');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
exports.index = function(req, res, next) {
|
|
|
let qcdn = _.get(req.app.locals, 'wap.qcloud_cdn');
|
...
|
...
|
@@ -68,3 +69,95 @@ exports.fetchMore = function(req, res, next) { |
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
|
|
|
exports.userFavGoods = function(req, res, next) {
|
|
|
let qcdn = _.get(req.app.locals, 'wap.qcloud_cdn');
|
|
|
const { page = 1 } = req.query || {};
|
|
|
|
|
|
req.ctx(FindGoods)
|
|
|
.queryUserFavFindgoods({ page })
|
|
|
.then(result => {
|
|
|
if (!result) {
|
|
|
return next();
|
|
|
}
|
|
|
const title =
|
|
|
stringProcess.paramsFilter(req.query.title) || '我喜欢的发现好货';
|
|
|
const shareId = _.parseInt(
|
|
|
stringProcess.paramsFilter(req.query.share_id),
|
|
|
);
|
|
|
|
|
|
// 唤起 APP 的路径
|
|
|
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"param":{"share_id":"${shareId}","title":"${title}"},"share":"/operations/api/v5/webshare/getShare","shareparam":{"share_id":"${shareId}"},"title":"${title}","url":"https://activity.yoho.cn/activity/find/userFavGoods.html"}}`;
|
|
|
|
|
|
const jsSdk = global.yoho.config.jsSdk;
|
|
|
|
|
|
res.render('find-goods/index', {
|
|
|
module: 'activity',
|
|
|
page: 'find-goods',
|
|
|
title: title,
|
|
|
content: result.data,
|
|
|
isFeature: true,
|
|
|
wechatShare: true,
|
|
|
localCss: true,
|
|
|
loadJs: [
|
|
|
{
|
|
|
src: qcdn ?
|
|
|
jsSdk.replace(
|
|
|
/\/\/cdn.yoho.cn/gi,
|
|
|
'//qcdn.yoho.cn',
|
|
|
) :
|
|
|
jsSdk,
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
exports.updateFavGoodsStatus = function(req, res, next) {
|
|
|
let refer = helpers.urlFormat('/signin.html', {
|
|
|
refer: req.headers.referer
|
|
|
});
|
|
|
|
|
|
console.log('-------1---------');
|
|
|
let result = {
|
|
|
code: 400,
|
|
|
message: '未登录',
|
|
|
data: refer
|
|
|
};
|
|
|
|
|
|
/* 判断是不是AJAX请求 */
|
|
|
if (!req.xhr) {
|
|
|
res.jsonp(result);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
/* 判断参数是否有效 */
|
|
|
let goodsId = req.body.goodsId,
|
|
|
status = req.body.status || '1',
|
|
|
uid = req.user.uid;
|
|
|
|
|
|
if (!stringProcess.isNumeric(goodsId) || !stringProcess.isNumeric(uid)) {
|
|
|
res.jsonp(result);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
console.log('------------updateFavGoodsStatus--------');
|
|
|
|
|
|
// 执行收藏或取消操作
|
|
|
return req.ctx(FindGoods).updateFavFindgoods(uid, goodsId, status).then(data => {
|
|
|
if (!data) {
|
|
|
res.jsonp({
|
|
|
code: 400,
|
|
|
message: '操作失败'
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
res.jsonp({
|
|
|
code: 200,
|
|
|
message: data.message,
|
|
|
data: ''
|
|
|
});
|
|
|
}).catch(next);
|
|
|
}; |
...
|
...
|
|