Authored by 郝肖肖

获取店铺优惠券列表

... ... @@ -520,14 +520,16 @@ const userCoupon = (req, res, next) => {
* @param next
*/
const getShopCouponsList = (req, res, next) => {
let uid = req.body.uid || req.user.uid;
let shopId = req.body.shopId;
let uid = req.query.uid || req.user.uid;
let shopId = req.query.shopId;
let param = {};
if (uid) {
param.uid = uid;
}
param.shop_id = shopId;
listModel.shopCouponsList(param).then(result => {
res.json(result);
}).catch(next);
... ... @@ -543,5 +545,6 @@ module.exports = {
shopFav,
baseShopFav,
shopCategory,
userCoupon
userCoupon,
getShopCouponsList
};
... ...
... ... @@ -809,6 +809,40 @@ const getShopCategory = (params) => {
});
};
/**
* 获取店铺优惠券列表
* @param {[int]} shop_id 店铺id
* @param {[uid]} uid 当前用户id,空则不传
* @return {[array]}
*/
const shopCouponsList = (params) => {
return api.get('', Object.assign({
method: 'shop.coupons.list'
}, params)).then(result => {
let shopCoupons = [];
let couPonstatus;
if (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 shopCoupons;
});
};
module.exports = {
getBaseShopData,
getShopData,
... ... @@ -824,5 +858,6 @@ module.exports = {
receiveCoupon,
getShopFav,
searchProductBySkn,
getBrandFavStatus
getBrandFavStatus,
shopCouponsList
};
... ...
... ... @@ -125,7 +125,8 @@ router.get('/index/shopAppCookie', list.shopAppCookie);
router.get('/index/shopFav', list.shopFav);
router.get('/index/baseShopFav', list.baseShopFav);
router.get('/index/category', list.shopCategory);
router.get('/index/userCoupon', list.userCoupon);
router.post('/index/userCoupon', list.userCoupon);
router.get('/index/getShopCouponsList', list.getShopCouponsList);
// 店铺介绍
router.get('/index/intro', list.shopIntro);
... ...
<div class="coupon-content">
<div class="swiper-wrapper">
{{#if shopCouponsOne}}
{{#each shopCoupons}}
<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>
{{#if status}}
<div class='coupon-right receive-btn'>
立即领取
</div>
{{^}}
<div class='coupon-right receive-btn'>
已领取
</div>
{{/if}}
</div><!--/coupon-big-->
{{/each}}
{{^}}
{{#each shopCoupons}}
<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>
{{#if status}}
<div class='coupon-right receive-btn'>
立即领取
</div>
{{^}}
<div class='coupon-right receive-btn'>
已领取
</div>
{{/if}}
</div><!--/coupon-small-->
{{/each}}
{{/if}}
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -2,9 +2,41 @@ var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
tip = require('../../plugin/tip');
var appVersion = window.queryString.app_version || window.queryString.appVersion;
require('../../common');
$('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() {
var shopCoupon = {};
shopCoupon = {
common: {
appVersion: window.queryString.app_version || window.queryString.appVersion,
uid: window.queryString.uid,
couponTemplate: require('product/shop/shop-coupon.hbs')
},
init: function() {
this.getShopCouponsList();
},
getShopCouponsList: function() {
var that = this;
$.ajax({
method: 'POST',
url: location.protocol + '//m.yohobuy.com/product/index/getShopCouponsList',
data: {
uid: that.common.uid
},
xhrFields: {
withCredentials: true
},
success: function(result) {
// $('.product-list').html(that.common.couponTemplate(result));
that.userCoupon();
}
});
},
userCoupon: function() {
var $self = this;
$('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function() {
var that = this,
code = $(this).data('id') || '';
... ... @@ -19,8 +51,8 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
url: location.protocol + '//m.yohobuy.com/product/index/userCoupon',
data: {
couponID: code,
app_version: appVersion,
uid: window.queryString.uid
app_version: $self.common.appVersion,
uid: $self.common.uid
},
xhrFields: {
withCredentials: true
... ... @@ -48,9 +80,13 @@ $('.coupon-content .receive-btn').closest('.swiper-slide').on('click', function(
that.isCouponClick = true;
}
});
});
});
}
};
$(function() {
shopCoupon.init();
new Swiper('.coupon-content', {
slideElement: '.coupon-small',
slidesPerView: 'auto',
... ...