优惠券问题修复
This commit is contained in:
@@ -254,7 +254,7 @@ function tabChange(index) {
|
|||||||
querForm.value.statusActiveIndex = index;
|
querForm.value.statusActiveIndex = index;
|
||||||
list.page = 1;
|
list.page = 1;
|
||||||
list.status = 'nomore';
|
list.status = 'nomore';
|
||||||
getCouponList();
|
formatCoupon();
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeSelCoupon(item) {
|
function changeSelCoupon(item) {
|
||||||
@@ -277,6 +277,7 @@ function changeSelCoupon(item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const couponSel = ref({
|
const couponSel = ref({
|
||||||
id: ''
|
id: ''
|
||||||
});
|
});
|
||||||
@@ -286,7 +287,12 @@ const goodsCouponSel = ref({
|
|||||||
const quansSelArr = computed(() => {
|
const quansSelArr = computed(() => {
|
||||||
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
|
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
|
||||||
});
|
});
|
||||||
|
watch(()=>couponSel.value.id,(newval)=>{
|
||||||
|
formatCoupon()
|
||||||
|
})
|
||||||
|
watch(()=>goodsCouponSel.value.id,(newval)=>{
|
||||||
|
formatCoupon()
|
||||||
|
})
|
||||||
function isActive(item) {
|
function isActive(item) {
|
||||||
if (querForm.value.statusActiveIndex) {
|
if (querForm.value.statusActiveIndex) {
|
||||||
return couponSel.value.id == item.id;
|
return couponSel.value.id == item.id;
|
||||||
@@ -295,6 +301,88 @@ function isActive(item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const couponList=ref([])
|
||||||
|
function formatCoupon(){
|
||||||
|
|
||||||
|
let canUseGoodsCoupon = [];
|
||||||
|
let canUseDiscountCoupon = [];
|
||||||
|
|
||||||
|
let noUseGoodsCoupon = [];
|
||||||
|
let noUseDiscountCoupon = [];
|
||||||
|
const user = uni.cache.get('shopUserInfo');
|
||||||
|
let shopInfo = uni.cache.get('shopInfo') || {};
|
||||||
|
if (!shopInfo.isMemberPrice) {
|
||||||
|
shopInfo = {};
|
||||||
|
}
|
||||||
|
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
|
||||||
|
const dinnerType = cartStore.dinnerType;
|
||||||
|
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
|
||||||
|
const shopId = uni.cache.get('shopId');
|
||||||
|
for (let i = 0; i < couponList.value.length; i++) {
|
||||||
|
const coupon = couponList.value[i];
|
||||||
|
const canuseResult = UTILS.returnCouponCanUse({
|
||||||
|
canDikouGoodsArr,
|
||||||
|
coupon,
|
||||||
|
goodsOrderPrice,
|
||||||
|
user,
|
||||||
|
selCoupon: quansSelArr.value,
|
||||||
|
shopInfo
|
||||||
|
});
|
||||||
|
const { canUse, reason } = canuseResult;
|
||||||
|
if (coupon.type == 2) {
|
||||||
|
if (canUse || goodsCouponSel.value.id == coupon.id) {
|
||||||
|
canUseGoodsCoupon.push(coupon);
|
||||||
|
} else {
|
||||||
|
noUseGoodsCoupon.push({
|
||||||
|
...coupon,
|
||||||
|
canuseResult
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (canUse || couponSel.value.id == coupon.id) {
|
||||||
|
canUseDiscountCoupon.push(coupon);
|
||||||
|
} else {
|
||||||
|
noUseDiscountCoupon.push({
|
||||||
|
...coupon,
|
||||||
|
canuseResult
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//商品券
|
||||||
|
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
|
||||||
|
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
discount,
|
||||||
|
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
||||||
|
};
|
||||||
|
});
|
||||||
|
//非商品券
|
||||||
|
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
|
||||||
|
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
discount,
|
||||||
|
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (querForm.value.statusActiveIndex == 0) {
|
||||||
|
list.noCanUseCoupons = noUseGoodsCoupon;
|
||||||
|
list.canUseCoupons = canUseGoodsCoupon;
|
||||||
|
} else {
|
||||||
|
list.noCanUseCoupons = noUseDiscountCoupon;
|
||||||
|
list.canUseCoupons = canUseDiscountCoupon;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
|
||||||
|
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
|
||||||
|
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
|
||||||
|
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
|
||||||
|
}
|
||||||
|
|
||||||
// 获取优惠券列表
|
// 获取优惠券列表
|
||||||
async function getCouponList() {
|
async function getCouponList() {
|
||||||
try {
|
try {
|
||||||
@@ -305,83 +393,9 @@ async function getCouponList() {
|
|||||||
const res = await findCoupon({
|
const res = await findCoupon({
|
||||||
shopUserId: uni.cache.get('shopUserInfo').id
|
shopUserId: uni.cache.get('shopUserInfo').id
|
||||||
});
|
});
|
||||||
|
couponList.value=res
|
||||||
|
formatCoupon()
|
||||||
|
|
||||||
let canUseGoodsCoupon = [];
|
|
||||||
let canUseDiscountCoupon = [];
|
|
||||||
|
|
||||||
let noUseGoodsCoupon = [];
|
|
||||||
let noUseDiscountCoupon = [];
|
|
||||||
const user = uni.cache.get('shopUserInfo');
|
|
||||||
let shopInfo = uni.cache.get('shopInfo') || {};
|
|
||||||
if (!shopInfo.isMemberPrice) {
|
|
||||||
shopInfo = {};
|
|
||||||
}
|
|
||||||
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
|
|
||||||
const dinnerType = cartStore.dinnerType;
|
|
||||||
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
|
|
||||||
const shopId = uni.cache.get('shopId');
|
|
||||||
for (let i = 0; i < res.length; i++) {
|
|
||||||
const coupon = res[i];
|
|
||||||
const canuseResult = UTILS.returnCouponCanUse({
|
|
||||||
canDikouGoodsArr,
|
|
||||||
coupon,
|
|
||||||
goodsOrderPrice,
|
|
||||||
user,
|
|
||||||
selCoupon: quansSelArr.value,
|
|
||||||
shopInfo
|
|
||||||
});
|
|
||||||
const { canUse, reason } = canuseResult;
|
|
||||||
if (coupon.type == 2) {
|
|
||||||
if (canUse || goodsCouponSel.value.id == coupon.id) {
|
|
||||||
canUseGoodsCoupon.push(coupon);
|
|
||||||
} else {
|
|
||||||
noUseGoodsCoupon.push({
|
|
||||||
...coupon,
|
|
||||||
canuseResult
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (canUse || couponSel.value.id == coupon.id) {
|
|
||||||
canUseDiscountCoupon.push(coupon);
|
|
||||||
} else {
|
|
||||||
noUseDiscountCoupon.push({
|
|
||||||
...coupon,
|
|
||||||
canuseResult
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//商品券
|
|
||||||
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
|
|
||||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
discount,
|
|
||||||
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
|
||||||
};
|
|
||||||
});
|
|
||||||
//非商品券
|
|
||||||
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
|
|
||||||
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
discount,
|
|
||||||
discountAmount: discount ? discount.discountPrice : v.discountAmount
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
if (querForm.value.statusActiveIndex == 0) {
|
|
||||||
list.noCanUseCoupons = noUseGoodsCoupon;
|
|
||||||
list.canUseCoupons = canUseGoodsCoupon;
|
|
||||||
} else {
|
|
||||||
list.noCanUseCoupons = noUseDiscountCoupon;
|
|
||||||
list.canUseCoupons = canUseDiscountCoupon;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
|
|
||||||
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
|
|
||||||
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
|
|
||||||
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
@@ -490,6 +504,7 @@ onLoad(() => {
|
|||||||
watch(
|
watch(
|
||||||
() => quansSelArr.value,
|
() => quansSelArr.value,
|
||||||
(newval) => {
|
(newval) => {
|
||||||
|
// getCouponList()
|
||||||
const user = uni.cache.get('shopUserInfo');
|
const user = uni.cache.get('shopUserInfo');
|
||||||
let shopInfo = uni.cache.get('shopInfo') || {};
|
let shopInfo = uni.cache.get('shopInfo') || {};
|
||||||
if (!shopInfo.isMemberPrice) {
|
if (!shopInfo.isMemberPrice) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export function returnGoodsPrice(goods, user, shopInfo) {
|
|||||||
if (goods.discount_sale_amount * 1 > 0) {
|
if (goods.discount_sale_amount * 1 > 0) {
|
||||||
return goods.discount_sale_amount;
|
return goods.discount_sale_amount;
|
||||||
}
|
}
|
||||||
|
console.log('returnGoodsPrice:shopInfo',shopInfo);
|
||||||
if(shopInfo&&!shopInfo.isMemberPrice){
|
if(shopInfo&&!shopInfo.isMemberPrice){
|
||||||
return goods.salePrice;
|
return goods.salePrice;
|
||||||
}
|
}
|
||||||
@@ -151,6 +152,18 @@ export function returnCouponCanUse(args) {
|
|||||||
return pre + returnGoodsPrice(cur, user,shopInfo) * cur.num;
|
return pre + returnGoodsPrice(cur, user,shopInfo) * cur.num;
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
if(user.isVip&&!coupon.vipPriceShare){
|
||||||
|
return {
|
||||||
|
canUse: false,
|
||||||
|
reason: "非会员可用"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if(selCoupon.length>0&&!selCoupon[0].otherCouponShare){
|
||||||
|
return {
|
||||||
|
canUse: false,
|
||||||
|
reason: "当前选中的券不可与其他券同享"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// 没有符合条件的商品
|
// 没有符合条件的商品
|
||||||
if (!isDikouAll && canCalcGoodsArr.length === 0) {
|
if (!isDikouAll && canCalcGoodsArr.length === 0) {
|
||||||
@@ -264,18 +277,19 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user,sh
|
|||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
* @param goodsOrderPrice 商品订单金额
|
* @param goodsOrderPrice 商品订单金额
|
||||||
* @param selCoupon 已选择的优惠券列表
|
* @param selCoupon 已选择的优惠券列表
|
||||||
|
* @param shopInfo 店铺信息
|
||||||
*/
|
*/
|
||||||
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon) {
|
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon,shopInfo) {
|
||||||
const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user);
|
const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user);
|
||||||
console.log('canDikouGoodsArr', canDikouGoodsArr);
|
console.log('canDikouGoodsArr', canDikouGoodsArr);
|
||||||
if (coupon.type == 2) {
|
if (coupon.type == 2) {
|
||||||
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
|
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo);
|
||||||
}
|
}
|
||||||
if (coupon.type == 6) {
|
if (coupon.type == 6) {
|
||||||
return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
|
return returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopInfo);
|
||||||
}
|
}
|
||||||
if (coupon.type == 4) {
|
if (coupon.type == 4) {
|
||||||
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice);
|
return returnSecoendDiscount(canDikouGoodsArr, coupon, user, shopInfo);
|
||||||
}
|
}
|
||||||
if (coupon.type == 3) {
|
if (coupon.type == 3) {
|
||||||
return returnCouponZhekouDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice, selCoupon);
|
return returnCouponZhekouDiscount(canDikouGoodsArr, coupon, user, goodsOrderPrice, selCoupon);
|
||||||
@@ -331,8 +345,9 @@ export function returnCouponZhekouDiscount(
|
|||||||
* @param canDikouGoodsArr 可抵扣商品列表
|
* @param canDikouGoodsArr 可抵扣商品列表
|
||||||
* @param coupon 优惠券
|
* @param coupon 优惠券
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
|
* @param shopInfo 店铺信息
|
||||||
*/
|
*/
|
||||||
export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user) {
|
export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user,shopInfo) {
|
||||||
const {
|
const {
|
||||||
useFoods,
|
useFoods,
|
||||||
discountNum,
|
discountNum,
|
||||||
@@ -362,7 +377,7 @@ export function returnCouponProductDiscount(canDikouGoodsArr, coupon, user) {
|
|||||||
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
|
discountGoodsArr = discountSelGoodsArr.slice(0, discountNum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user);
|
const result = calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user,shopInfo);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user