...
|
...
|
@@ -6,10 +6,12 @@ |
|
|
const mRoot = '../models';
|
|
|
const utils = '../../../utils';
|
|
|
const shopModel = require(`${mRoot}/shop`);
|
|
|
const couponModel = require(`${mRoot}/coupon`);
|
|
|
const searchModel = require(`${mRoot}/search`);
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const crypto = global.yoho.crypto;
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
const shopPrcs = require(`${utils}/shop-process`);
|
|
|
const co = require('bluebird').coroutine;
|
...
|
...
|
@@ -80,7 +82,7 @@ const shop = { |
|
|
} else if (shopId || req.shopInfo.isShop) { // 非红人店铺的店铺
|
|
|
return shop.list(req, res, next);
|
|
|
} else { // 什么都没有,去首页
|
|
|
return res.redirect(helpers.urlFormat('', {go: '-1'}));
|
|
|
return res.redirect(helpers.urlFormat('', {go: 1}));
|
|
|
}
|
|
|
})().catch(next);
|
|
|
},
|
...
|
...
|
@@ -183,11 +185,12 @@ const shop = { |
|
|
}
|
|
|
|
|
|
co(function* () {
|
|
|
let [bannerData, favCountData, decoratorsData, categoryData] = yield Promise.all([
|
|
|
let [bannerData, favCountData, decoratorsData, categoryData, couponData] = yield Promise.all([
|
|
|
shopModel.getBanner(shopId),
|
|
|
shopModel.favCount(shopId, uid, channel, udid),
|
|
|
shopModel.getShopsdecorator(shopId),
|
|
|
shopModel.getShopCategory(shopId, channel)
|
|
|
shopModel.getShopCategory(shopId, channel),
|
|
|
couponModel.shopCouponsList({shop_id: shopId})
|
|
|
]);
|
|
|
|
|
|
let banner = _.get(bannerData, 'data.banner');
|
...
|
...
|
@@ -228,6 +231,7 @@ const shop = { |
|
|
localCss: true,
|
|
|
module: 'product',
|
|
|
page: 'shop-reds',
|
|
|
couponData,
|
|
|
shopId,
|
|
|
banner, shopInfo, favCount, decorators, category
|
|
|
});
|
...
|
...
|
@@ -251,7 +255,10 @@ const shop = { |
|
|
page: 1
|
|
|
};
|
|
|
|
|
|
let goodsListApi = yield searchModel.getShopGoods(searchParam);
|
|
|
let [goodsListApi, couponData] = yield Promise.all([
|
|
|
searchModel.getShopGoods(searchParam),
|
|
|
couponModel.shopCouponsList({shop_id: shopId})
|
|
|
]);
|
|
|
let goodsList = productProcess.processProductList(_.get(goodsListApi, 'data.product_list', []));
|
|
|
|
|
|
if (shopInfo.isShop) {
|
...
|
...
|
@@ -279,7 +286,8 @@ const shop = { |
|
|
goodsList: goodsList,
|
|
|
shopPage: true,
|
|
|
_noLazy: true,
|
|
|
localCss: true
|
|
|
localCss: true,
|
|
|
couponData
|
|
|
});
|
|
|
|
|
|
})().catch(next);
|
...
|
...
|
@@ -305,6 +313,87 @@ const shop = { |
|
|
page: 'all-brand',
|
|
|
});
|
|
|
}).catch(next);
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 获取店铺优惠券列表
|
|
|
* @param req
|
|
|
* @param res
|
|
|
* @param next
|
|
|
*/
|
|
|
getShopCouponsList(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');
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let shopId = parseInt(req.query.shopId, 10);
|
|
|
let param = {};
|
|
|
|
|
|
if (shopId) {
|
|
|
if (uid) {
|
|
|
param.uid = uid;
|
|
|
}
|
|
|
|
|
|
param.shop_id = shopId;
|
|
|
|
|
|
couponModel.shopCouponsList(param).then(result => {
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
res.json([]);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用戶領券
|
|
|
* @param req
|
|
|
* @param res
|
|
|
* @param next
|
|
|
*/
|
|
|
userCoupon(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.couponID) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let cryptCouponId = crypto.decrypt('', req.body.couponID);
|
|
|
let uid = req.user.uid;
|
|
|
let isApp = req.body.app_version || req.body.appVersion || false;
|
|
|
let data = {};
|
|
|
|
|
|
cryptCouponId = parseInt(cryptCouponId, 10);
|
|
|
uid = parseInt(uid, 10);
|
|
|
|
|
|
if (uid) {
|
|
|
couponModel.receiveCoupon(
|
|
|
uid,
|
|
|
cryptCouponId
|
|
|
).then(result => {
|
|
|
res.json(result);
|
|
|
return;
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
data.code = 4401;// 401错误已经被接口占用
|
|
|
let refer = req.get('referer');
|
|
|
let toUrl = helpers.urlFormat('/signin.html', {refer: refer});
|
|
|
|
|
|
if (isApp) {
|
|
|
toUrl += '&openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + refer +
|
|
|
'","param":{}},"requesturl":{"param":{"method":"app.promotion.getCoupon","couponId":"' +
|
|
|
cryptCouponId + '"},"url":"' + _.get(global, 'yoho.API.ApiUrl', '') + '"},"priority":"Y"}}';
|
|
|
}
|
|
|
|
|
|
data.url = toUrl;
|
|
|
res.json(data);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|