Authored by 毕凯

Merge branch 'hotfix/shopCoupon' into 'release/6.0'

店铺优惠券整理



See merge request !772
... ... @@ -10,7 +10,6 @@ const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header');
const listModel = require(`${mRoot}/list`);
const _ = require('lodash');
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const productProcess = require(`${utils}/product-process`);
const searchModel = require(`${mRoot}/search`);
... ... @@ -496,87 +495,6 @@ const shopCategory = (req, res, next) => {
};
/**
* 用戶領券
* @param req
* @param res
* @param next
*/
const 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.body.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) {
listModel.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);
}
};
/**
* 获取店铺优惠券列表
* @param req
* @param res
* @param next
*/
const 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 || req.query.uid;
let shopId = parseInt(req.query.shopId, 10);
let param = {};
if (shopId) {
if (uid) {
param.uid = uid;
}
param.shop_id = shopId;
listModel.shopCouponsList(param).then(result => {
res.json(result);
}).catch(next);
} else {
res.json([]);
}
};
/**
* 获取品牌优惠券列表
* @param req
* @param res
... ... @@ -589,7 +507,7 @@ const getBrandCouponsList = (req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
let uid = req.user.uid || req.query.uid;
let uid = req.user.uid;
let brandId = parseInt(req.query.brandId, 10);
let param = {};
... ... @@ -618,7 +536,5 @@ module.exports = {
shopFav,
baseShopFav,
shopCategory,
userCoupon,
getShopCouponsList,
getBrandCouponsList
};
... ...
... ... @@ -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);
}
}
};
... ...
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const api = global.yoho.API;
/**
... ... @@ -30,3 +32,57 @@ exports.getCoupon = (uid, couponId) => {
return api.post('', param);
};
/**
* [获取店铺优惠券列表]
* @param {[type]} params [参数]
* @return {[type]} []
*/
exports.shopCouponsList = (params) => {
return api.get('', Object.assign({
method: 'shop.coupons.list'
}, params), {
cache: params.uid ? false : 180
}).then(result => {
let shopCoupons = [];
let couPonstatus;
if (result && result.data) {
_.forEach(result.data, value => {
couPonstatus = parseInt(value.status, 10);
if (couPonstatus === 1 || couPonstatus === 3) {
shopCoupons.push({
validity: value.couponValidity,
id: crypto.encryption('', value.coupon_id + ''),
name: value.coupon_name,
pic: value.coupon_pic,
money: parseInt(value.money, 10),
status: couPonstatus === 1
});
}
});
}
return {
couponsOne: shopCoupons.length <= 1,
coupons: shopCoupons
};
});
};
/**
* 用戶領券
* @param uid
* @param couponId
* @returns {*|Promise.<TResult>}
*/
exports.receiveCoupon = (uid, couponId) => {
return api.get('', {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}).then(result => {
return result;
});
};
... ...
... ... @@ -273,22 +273,6 @@ const getBrandFavStatus = (params) => {
};
/**
* 用戶領券
* @param uid
* @param couponId
* @returns {*|Promise.<TResult>}
*/
const receiveCoupon = (uid, couponId) => {
return api.get('', {
method: 'app.promotion.getCoupon',
couponId: couponId,
uid: uid
}).then(result => {
return result;
});
};
/**
* 获取店铺下面的所有品牌
* @param {int} shopId 店铺id
*/
... ... @@ -799,42 +783,6 @@ const getShopCategory = (params) => {
};
/**
* 获取店铺优惠券列表
* @return {[array]}
* @param params
*/
const shopCouponsList = (params) => {
return api.get('', Object.assign({
method: 'shop.coupons.list'
}, params)).then(result => {
let shopCoupons = [];
let couPonstatus;
if (result && result.data) {
_.forEach(result.data, value => {
couPonstatus = parseInt(value.status, 10);
if (couPonstatus === 1 || couPonstatus === 3) {
shopCoupons.push({
validity: value.couponValidity,
id: crypto.encryption('', value.coupon_id + ''),
name: value.coupon_name,
pic: value.coupon_pic,
money: parseInt(value.money, 10),
status: couPonstatus === 1
});
}
});
}
return {
couponsOne: shopCoupons.length <= 1,
coupons: shopCoupons
};
});
};
/**
* 获取品牌优惠券列表
* @param {[int]} brand_id 品牌id
* @param {[int]} uid 当前用户id,空则不传
... ... @@ -884,8 +832,6 @@ module.exports = {
getShopIntro,
getShopBrands,
getShopCategory,
receiveCoupon,
shopCouponsList,
brandCouponsList,
getShopFav,
getBrandFavStatus,
... ...
... ... @@ -159,8 +159,6 @@ router.get('/index/shopAppCookie', list.shopAppCookie);
router.get('/index/shopFav', list.shopFav);
router.get('/index/category', list.shopCategory);
router.post('/index/userCoupon', list.userCoupon);
router.get('/index/getShopCouponsList', list.getShopCouponsList);
router.get('/index/getBrandCouponsList', list.getBrandCouponsList);
// 店铺重构
... ... @@ -168,6 +166,8 @@ router.get('/shop', newShop.entry); // 统一店铺入口
router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller
router.get('/index/brandFav', newShop.brandFav);
router.get('/new/shop/hotlist', newShop.shopHotList);
router.get('/index/getShopCouponsList', newShop.getShopCouponsList);
router.post('/index/userCoupon', newShop.userCoupon);
router.get('/red-shop', newShop.redShop);
... ...
... ... @@ -27,7 +27,9 @@
{{/ shopInfo}}
<!-- 优惠卷 -->
<div class="coupon-group"></div>
<div class="coupon-group">
{{> reds-shop/coupon}}
</div>
<!-- /基础店铺页面 -->
{{!--筛选tab--}}
... ...
... ... @@ -41,7 +41,9 @@
<div class="tab-panels">
{{!--shop-tab: 首页--}}
<div id="red-index" class="tab-panel red-shop-index active">
<div class="shop-coupon coupon-group"></div>
<div class="shop-coupon coupon-group">
{{> reds-shop/coupon}}
</div>
{{> reds-shop/modules}}
<div id="indexGoodsContainer" class="goods-container">
<div class="default-goods container clearfix"></div>
... ...
{{#couponData}}
<div class="coupon-content">
<div class="swiper-wrapper">
{{#if couponsOne}}
{{#each coupons}}
<div class="swiper-slide coupon-big" data-id = "{{id}}">
<div class='coupon-left'>
<span class="coupon-left-price">
<span class="coupon-sign">¥</span>
<span class="coupon-price">{{money}}</span>
</span>
<span class="coupon-left-name">
{{name}}
</span>
</div>
<div class='coupon-right receive-btn'>
立即领取
</div>
</div><!--/coupon-big-->
{{/each}}
{{^}}
{{#each coupons}}
<div class="swiper-slide coupon-small" data-id = "{{id}}">
<div class='coupon-left'>
<span class="coupon-left-price">
<span class="coupon-sign">¥</span>
<span class="coupon-price">{{money}}</span>
</span>
<span class="coupon-left-name">
{{name}}
</span>
</div>
<div class='coupon-right receive-btn'>
立即领取
</div>
</div><!--/coupon-small-->
{{/each}}
{{/if}}
</div>
</div>
{{/couponData}}
\ No newline at end of file
... ...
... ... @@ -9,7 +9,6 @@ let shopCoupon = {};
shopCoupon = {
common: {
appVersion: window.queryString.app_version || window.queryString.appVersion,
uid: window.queryString.uid,
shopId: parseInt($('.shop-id').val() || $('.shopId').val(), 10) || null,
couponTemplate: require('product/shop/coupon.hbs')
},
... ... @@ -36,8 +35,7 @@ shopCoupon = {
method: 'GET',
url: _url,
data: {
shopId: that.common.shopId,
uid: that.common.uid
shopId: that.common.shopId
},
xhrFields: {
withCredentials: true
... ...
... ... @@ -47,6 +47,7 @@
line-height: 1.2em;
align-items: center;
display: flex;
transform: scale(0.88);
}
}
... ... @@ -101,6 +102,7 @@
line-height: 1.2em;
align-items: center;
display: flex;
transform: scale(0.88);
}
}
}
... ...