收银台
This commit is contained in:
parent
67793a651b
commit
0f2503f73a
@ -66,6 +66,8 @@ public class CardCoupon extends Model<CardCoupon> {
|
|||||||
private Integer zkStartAmount;
|
private Integer zkStartAmount;
|
||||||
//折扣卷满多少元的终
|
//折扣卷满多少元的终
|
||||||
private Integer zkEndAmount;
|
private Integer zkEndAmount;
|
||||||
|
//折扣最大优惠金额
|
||||||
|
private Double zkMaxAmount;
|
||||||
//适用会员等级 可多选
|
//适用会员等级 可多选
|
||||||
private String membershipLevel;
|
private String membershipLevel;
|
||||||
//生效日期类型1.领取后多少天内有效 2指定具体使用日期
|
//生效日期类型1.领取后多少天内有效 2指定具体使用日期
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
main.mt_user_id AS mtUserId
|
main.mt_user_id AS mtUserId
|
||||||
FROM
|
FROM
|
||||||
card_coupon_user main
|
card_coupon_user main
|
||||||
LEFT JOIN card_coupon cc ON main.card_coupon_id = cc.id
|
INNER JOIN card_coupon cc ON main.card_coupon_id = cc.id
|
||||||
WHERE
|
WHERE
|
||||||
main.store_id = #{storeId}
|
main.store_id = #{storeId}
|
||||||
AND main.mt_user_id = #{userId}
|
AND main.mt_user_id = #{userId}
|
||||||
|
@ -44,5 +44,15 @@ public interface CardCouponUserService extends IService<CardCouponUser> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
IPage<CardCouponUserVo> queryPage(Page page,CardCouponUserVo cardCouponUserVo);
|
IPage<CardCouponUserVo> queryPage(Page page,CardCouponUserVo cardCouponUserVo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查某用户某些优惠券的使用记录
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 17:31 2024/9/25
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param couponIdList 优惠券idList
|
||||||
|
* @return java.util.List<com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser>
|
||||||
|
**/
|
||||||
|
List<CardCouponUser> selectListByUsed(Integer userId,List<Integer> couponIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,5 +145,24 @@ public class CardCouponUserServiceImpl extends ServiceImpl<CardCouponUserMapper,
|
|||||||
}
|
}
|
||||||
return cardCouponUserVoIPage;
|
return cardCouponUserVoIPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查某用户某些优惠券的使用记录
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param couponIdList 优惠券idList
|
||||||
|
* @return java.util.List<com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser>
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 17:31 2024/9/25
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public List<CardCouponUser> selectListByUsed(Integer userId, List<Integer> couponIdList) {
|
||||||
|
LambdaQueryWrapper<CardCouponUser> queryWrapper = new LambdaQueryWrapper<CardCouponUser>()
|
||||||
|
.eq(CardCouponUser::getMtUserId,userId)
|
||||||
|
.in(CardCouponUser::getCardCouponId,couponIdList)
|
||||||
|
//已核销的
|
||||||
|
.eq(CardCouponUser::getStatus,"1");
|
||||||
|
return this.list(queryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package com.fuint.pay.service.impl;
|
|||||||
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateField;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
|
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
|
||||||
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule;
|
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule;
|
||||||
@ -13,6 +15,8 @@ import com.fuint.business.marketingActivity.activePrice.service.ActivePriceServi
|
|||||||
import com.fuint.business.marketingActivity.activePrice.service.ActiveSubPriceService;
|
import com.fuint.business.marketingActivity.activePrice.service.ActiveSubPriceService;
|
||||||
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
|
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
|
||||||
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
|
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
|
||||||
|
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCoupon;
|
||||||
|
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser;
|
||||||
import com.fuint.business.marketingActivity.cardCoupon.service.CardCouponUserService;
|
import com.fuint.business.marketingActivity.cardCoupon.service.CardCouponUserService;
|
||||||
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponVO;
|
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponVO;
|
||||||
import com.fuint.business.userGroup.entity.UserDiscount;
|
import com.fuint.business.userGroup.entity.UserDiscount;
|
||||||
@ -27,6 +31,7 @@ import com.fuint.pay.service.PayCenterService;
|
|||||||
import com.fuint.pay.util.CheckUtil;
|
import com.fuint.pay.util.CheckUtil;
|
||||||
import com.fuint.pay.vo.ActivityVO;
|
import com.fuint.pay.vo.ActivityVO;
|
||||||
import com.fuint.pay.vo.CouponVO;
|
import com.fuint.pay.vo.CouponVO;
|
||||||
|
import com.fuint.pay.vo.GoodsVO;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -166,11 +171,13 @@ public class PayCenterServiceImpl implements PayCenterService {
|
|||||||
List<String> actTypeList = Arrays.asList("1,2".split(StrUtil.COMMA));
|
List<String> actTypeList = Arrays.asList("1,2".split(StrUtil.COMMA));
|
||||||
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
|
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
|
||||||
filteredList.stream().map(ActivePriceRuleRespVO::getId).collect(Collectors.toList()),null,actTypeList);
|
filteredList.stream().map(ActivePriceRuleRespVO::getId).collect(Collectors.toList()),null,actTypeList);
|
||||||
filteredList = filteredList.stream()
|
if(!recordAllList.isEmpty()){
|
||||||
//过滤掉超过每日参加次数限制的
|
filteredList = filteredList.stream()
|
||||||
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList, "day"))
|
//过滤掉超过每日参加次数限制的
|
||||||
//过滤掉超过累计参加次数限制的
|
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList, "day"))
|
||||||
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
|
//过滤掉超过累计参加次数限制的
|
||||||
|
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
|
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
|
||||||
List<ActivityVO> rtnList = new ArrayList<>();
|
List<ActivityVO> rtnList = new ArrayList<>();
|
||||||
if(!filteredList.isEmpty()){
|
if(!filteredList.isEmpty()){
|
||||||
@ -227,13 +234,15 @@ public class PayCenterServiceImpl implements PayCenterService {
|
|||||||
List<String> actTypeList = Arrays.asList("3".split(StrUtil.COMMA));
|
List<String> actTypeList = Arrays.asList("3".split(StrUtil.COMMA));
|
||||||
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
|
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
|
||||||
null,filteredList.stream().map(ActiveSubPriceRespVO::getId).collect(Collectors.toList()),actTypeList);
|
null,filteredList.stream().map(ActiveSubPriceRespVO::getId).collect(Collectors.toList()),actTypeList);
|
||||||
filteredList = filteredList.stream()
|
if(!recordAllList.isEmpty()){
|
||||||
//过滤掉超过每日参加次数限制的
|
filteredList = filteredList.stream()
|
||||||
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList,"day"))
|
//过滤掉超过每日参加次数限制的
|
||||||
//过滤掉超过每月参加次数限制的
|
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList,"day"))
|
||||||
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getMonthLimitNum(),nowDate,recordAllList,"month"))
|
//过滤掉超过每月参加次数限制的
|
||||||
//过滤掉超过累计参加次数限制的
|
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getMonthLimitNum(),nowDate,recordAllList,"month"))
|
||||||
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
|
//过滤掉超过累计参加次数限制的
|
||||||
|
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
|
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
|
||||||
List<ActivityVO> rtnList = new ArrayList<>();
|
List<ActivityVO> rtnList = new ArrayList<>();
|
||||||
if(!filteredList.isEmpty()){
|
if(!filteredList.isEmpty()){
|
||||||
@ -350,26 +359,58 @@ public class PayCenterServiceImpl implements PayCenterService {
|
|||||||
Integer storeId = nowAccountInfo.getStoreId();
|
Integer storeId = nowAccountInfo.getStoreId();
|
||||||
int userId = Integer.parseInt(map.get("userId"));
|
int userId = Integer.parseInt(map.get("userId"));
|
||||||
//油号id
|
//油号id
|
||||||
Integer oilId = Integer.valueOf(map.get("oilId"));
|
Integer oilId = Integer.valueOf(map.getOrDefault("oilId","99999"));
|
||||||
//油单价
|
|
||||||
Double oilPrice = Double.valueOf(map.get("oilPrice"));
|
|
||||||
//加油金额(不含商品金额)
|
//加油金额(不含商品金额)
|
||||||
Double oilAmount = Double.valueOf(map.get("oilAmount"));
|
Double oilAmount = Double.valueOf(map.getOrDefault("oilAmount","0"));
|
||||||
//订单总额(含商品金额)
|
|
||||||
Double orderAmount = Double.valueOf(map.get("orderAmount"));
|
|
||||||
//油升数
|
//油升数
|
||||||
Double oilLiter = Double.valueOf(map.get("oilLiter"));
|
Double oilLiter = Double.valueOf(map.getOrDefault("oilLiter","0"));
|
||||||
|
//选择的商品
|
||||||
|
List<GoodsVO> goodsList = new ArrayList<>();
|
||||||
|
String goodsStr = map.getOrDefault("goods","");
|
||||||
|
if(StringUtils.isNotEmpty(goodsStr)){
|
||||||
|
JSONArray goodsArray = JSONUtil.parseArray(map.get("goods"));
|
||||||
|
goodsList = goodsArray.toList(GoodsVO.class);
|
||||||
|
}
|
||||||
/*1.先查满足条件的所有生效中的优惠券*/
|
/*1.先查满足条件的所有生效中的优惠券*/
|
||||||
List<CardCouponVO> couponVOList = cardCouponUserService.selectAllList(storeId, userId, nowDate);
|
List<CardCouponVO> couponVOList = cardCouponUserService.selectAllList(storeId, userId, nowDate);
|
||||||
/*2.进行初步过滤,这里只过滤优惠券硬性的限制*/
|
/*2.进行初步过滤,这里只过滤优惠券硬性的限制*/
|
||||||
|
List<GoodsVO> finalGoodsList = goodsList;
|
||||||
List<CardCouponVO> filteredList = couponVOList.stream()
|
List<CardCouponVO> filteredList = couponVOList.stream()
|
||||||
//当前时间在 适用时间段内 或者 当前时间不在 不适用时间段内的
|
//当前时间在 适用时间段内 或者 当前时间不在 不适用时间段内的
|
||||||
.filter(rule -> this.checkTimeCouponPrex(rule,nowDate)).collect(Collectors.toList());
|
.filter(rule -> this.checkTimeCouponPrex(rule,nowDate))
|
||||||
// //是否满足最低消费金额
|
//如果是油品券,需要过滤出当前油品可用的
|
||||||
// .filter(rule-> rule.getConsumeAmount() <=oilAmount)
|
.filter(rule -> checkUtil.checkOilCoupon(rule,oilId))
|
||||||
// //适用当前支付方式的
|
//如果是油品券,需要过滤出达到满减条件的
|
||||||
// .filter(rule-> rule.getUsePaymentWay().contains(payWay))
|
.filter(rule -> checkUtil.checkMaxCoupon(rule,oilAmount,oilLiter))
|
||||||
|
//如果是单品立减券,需要过滤出当前选择的商品可用且满足最低消费金额的
|
||||||
|
.filter(rule-> checkUtil.checkGoodsCoupon(rule, finalGoodsList)).collect(Collectors.toList());
|
||||||
|
if(filteredList.isEmpty()){
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
/*3.再次过滤,这里过滤掉用户已经超出参加次数限制的*/
|
||||||
|
List<Integer> filteredCoupIdList = filteredList.stream().map(CardCoupon::getId).collect(Collectors.toList());
|
||||||
|
//查出本用户这些优惠券的使用记录
|
||||||
|
List<CardCouponUser> usedList = cardCouponUserService.selectListByUsed(userId,filteredCoupIdList);
|
||||||
|
if(!usedList.isEmpty()){
|
||||||
|
//过滤
|
||||||
|
filteredList = filteredList.stream()
|
||||||
|
//过滤掉使用次数限制的
|
||||||
|
.filter(rule->checkUtil.checkUseNumCoupon(rule.getId(),rule.getLimitTotalDay(), rule.getLimitTotalNum(), nowDate,usedList)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
/*4.得到用户最终可以使用的优惠券,计算优惠金额并转换成统一的对象*/
|
||||||
List<CouponVO> rtnList = new ArrayList<>();
|
List<CouponVO> rtnList = new ArrayList<>();
|
||||||
|
if(!filteredList.isEmpty()){
|
||||||
|
for(CardCouponVO rule:filteredList){
|
||||||
|
CouponVO couponVO = new CouponVO();
|
||||||
|
couponVO.setId(rule.getDataId());
|
||||||
|
couponVO.setCouponId(rule.getId());
|
||||||
|
couponVO.setName(rule.getName());
|
||||||
|
couponVO.setUseWithOther(rule.getUseWithOther());
|
||||||
|
//计算优惠金额
|
||||||
|
couponVO.setDisAmount(checkUtil.computeDisAmountCoupon(rule,oilAmount,oilLiter));
|
||||||
|
rtnList.add(couponVO);
|
||||||
|
}
|
||||||
|
}
|
||||||
return rtnList;
|
return rtnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,14 +8,18 @@ import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord
|
|||||||
import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule;
|
import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule;
|
||||||
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
|
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
|
||||||
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
|
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
|
||||||
|
import com.fuint.business.marketingActivity.cardCoupon.entity.CardCouponUser;
|
||||||
|
import com.fuint.business.marketingActivity.cardCoupon.vo.CardCouponVO;
|
||||||
import com.fuint.business.userGroup.entity.UserDiscount;
|
import com.fuint.business.userGroup.entity.UserDiscount;
|
||||||
import com.fuint.common.util.StringUtils;
|
import com.fuint.common.util.StringUtils;
|
||||||
|
import com.fuint.pay.vo.GoodsVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -234,6 +238,127 @@ public class CheckUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 判断当前加油的油号是否符合优惠券预设的油号----优惠券专用
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:42 2024/9/21
|
||||||
|
* @param couponVO 优惠券对象
|
||||||
|
* @param oilId 当前加油选择的油号id
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
public Boolean checkOilCoupon(CardCouponVO couponVO, Integer oilId){
|
||||||
|
//代金券、折扣券、油品立减券才需要判断油品是否满足
|
||||||
|
List<String> couponTypeList = Arrays.asList("1","3","4");
|
||||||
|
if(couponTypeList.contains(couponVO.getType())){
|
||||||
|
if("1".equals(couponVO.getOilLimit())){
|
||||||
|
//不限制油品,符合
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
//限制油品
|
||||||
|
if(StringUtils.isNotEmpty(couponVO.getOilNumber())){
|
||||||
|
List<String> oilIdList = Arrays.asList(couponVO.getOilNumber().split(StrUtil.COMMA));
|
||||||
|
return oilIdList.contains(oilId.toString());
|
||||||
|
}else{
|
||||||
|
//没有配置可用油号,不满足
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//其他券不需要判断油品
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 判断当前加油金额或者加油升数是否达到满减条件----优惠券专用
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:42 2024/9/21
|
||||||
|
* @param couponVO 优惠券对象
|
||||||
|
* @param oilAmount 加油金额
|
||||||
|
* @param oilLiter 加油升数
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
public Boolean checkMaxCoupon(CardCouponVO couponVO, Double oilAmount,Double oilLiter){
|
||||||
|
//代金券、折扣券、油品立减券才需要判断加油升数、加油金额是否达到满减条件
|
||||||
|
List<String> couponTypeList = Arrays.asList("1","3","4");
|
||||||
|
if(couponTypeList.contains(couponVO.getType())){
|
||||||
|
Double thisValue;
|
||||||
|
if("1".equals(couponVO.getUseType())){
|
||||||
|
//加油金额
|
||||||
|
thisValue = oilAmount;
|
||||||
|
}else if("2".equals(couponVO.getUseType())){
|
||||||
|
//加油升数
|
||||||
|
thisValue = oilLiter;
|
||||||
|
}else {
|
||||||
|
//超出预设值范围,不满足
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if("1".equals(couponVO.getType())){
|
||||||
|
//代金券
|
||||||
|
return checkMaxCouponChild(null,couponVO.getReachAmount(),thisValue);
|
||||||
|
}else if("3".equals(couponVO.getType())){
|
||||||
|
//折扣券
|
||||||
|
return checkMaxCouponChild(couponVO.getZkStartAmount().doubleValue(),couponVO.getZkEndAmount().doubleValue(),thisValue);
|
||||||
|
}else if("4".equals(couponVO.getType())){
|
||||||
|
//油品立减券
|
||||||
|
return checkMaxCouponChild(null,couponVO.getReachAmount(),thisValue);
|
||||||
|
}else{
|
||||||
|
//超出预设值范围,不可用
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//其他券不需要判断,默认满足
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断加油金额或者加油升数是否符合某区间范围
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 16:45 2024/9/25
|
||||||
|
* @param min 最小值,可能为null
|
||||||
|
* @param max 最大值,一定有值
|
||||||
|
* @param thisValue 加油金额或加油升数,一定有值
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
public Boolean checkMaxCouponChild(Double min,Double max,Double thisValue){
|
||||||
|
if(null==min){
|
||||||
|
return thisValue>=max;
|
||||||
|
}else {
|
||||||
|
return isBetween(thisValue,min,max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前订单选择的商品是否满足优惠券的使用规则----优惠券专用
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:42 2024/9/21
|
||||||
|
* @param couponVO 优惠券对象
|
||||||
|
* @param goodsList 选择的商品列表
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
public Boolean checkGoodsCoupon(CardCouponVO couponVO, List<GoodsVO> goodsList){
|
||||||
|
if("5".equals(couponVO.getType()) || goodsList.isEmpty()){
|
||||||
|
//单品立减券
|
||||||
|
if(StringUtils.isNotEmpty(couponVO.getProductIds())){
|
||||||
|
//限制使用的商品id
|
||||||
|
List<String> ruleGoodsList = Arrays.asList(couponVO.getProductIds().split(StrUtil.COMMA));
|
||||||
|
//过滤出符合条件的本订单的商品
|
||||||
|
List<GoodsVO> filteredList = goodsList.stream().filter(goods->ruleGoodsList.contains(goods.getId())).collect(Collectors.toList());
|
||||||
|
//计算符合条件的商品订单总金额
|
||||||
|
double orderAmount =0.0;
|
||||||
|
if(!filteredList.isEmpty()){
|
||||||
|
orderAmount = filteredList.stream().mapToDouble(GoodsVO::getAmount).sum();
|
||||||
|
}
|
||||||
|
return orderAmount>=couponVO.getReachAmount();
|
||||||
|
}else{
|
||||||
|
//未设置可用商品,不符合
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
//其他券或者本订单未选择商品不需要判断商品
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,6 +404,55 @@ public class CheckUtil {
|
|||||||
return maxNum>nowNum;
|
return maxNum>nowNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前优惠券每多少天使用了多少次 是否满足优惠券设置的限制条件
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:51 2024/9/21
|
||||||
|
* @param coupId 优惠券id
|
||||||
|
* @param dayNum 多少天内
|
||||||
|
* @param maxNum 最大次数限制
|
||||||
|
* @param nowDate 结算日期
|
||||||
|
* @param recordAllList 所有使用记录
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
public Boolean checkUseNumCoupon(Integer coupId, Integer dayNum, Integer maxNum, Date nowDate, List<CardCouponUser> recordAllList){
|
||||||
|
if(0==dayNum){
|
||||||
|
//每多少天 设置为0,代表不显示
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int nowNum = 0;
|
||||||
|
//开始时间是结算时间 向前推 dayNum 天
|
||||||
|
LocalDateTime startTime = DateUtil.offsetDay(nowDate,-3).toLocalDateTime();
|
||||||
|
//结束时间为结算的时间
|
||||||
|
LocalDateTime endTime = DateUtil.date(nowDate).toLocalDateTime();
|
||||||
|
//优惠券使用时间过滤出近 dayNum 天内使用的次数
|
||||||
|
nowNum = (int) recordAllList.stream()
|
||||||
|
.filter(item->item.getCardCouponId().equals(coupId))
|
||||||
|
.filter(item->checkDateTimeIsIn(item.getUseTime(),startTime,endTime))
|
||||||
|
.count();
|
||||||
|
return maxNum>nowNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断一个时间是否在一个时间区间内
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 18:09 2024/9/25
|
||||||
|
* @param useDate 使用时间
|
||||||
|
* @param startTime 时间区间起始
|
||||||
|
* @param endTime 时间区间结束
|
||||||
|
* @return java.lang.Boolean
|
||||||
|
**/
|
||||||
|
private Boolean checkDateTimeIsIn(Date useDate,LocalDateTime startTime,LocalDateTime endTime){
|
||||||
|
LocalDateTime userDateTime = DateUtil.date(useDate).toLocalDateTime();
|
||||||
|
if(userDateTime.isAfter(startTime) && userDateTime.isBefore(endTime)){
|
||||||
|
return true;
|
||||||
|
}else if(userDateTime.equals(startTime ) || userDateTime.equals(endTime)){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据活动优惠规则,计算优惠金额,,四舍五入保留2位小数--分时优惠和限时特价使用
|
* 根据活动优惠规则,计算优惠金额,,四舍五入保留2位小数--分时优惠和限时特价使用
|
||||||
* @author vinjor-M
|
* @author vinjor-M
|
||||||
@ -399,6 +573,48 @@ public class CheckUtil {
|
|||||||
return Double.valueOf(df.format(disAmount));
|
return Double.valueOf(df.format(disAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据优惠券优惠规则,计算优惠金额,,四舍五入保留2位小数--优惠券专用
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 16:35 2024/9/21
|
||||||
|
* @param coupon 优惠券
|
||||||
|
* @param oilAmount 加油总价
|
||||||
|
* @param oilLiter 加油升数
|
||||||
|
* @return java.lang.Double
|
||||||
|
**/
|
||||||
|
public Double computeDisAmountCoupon(CardCouponVO coupon, Double oilAmount, Double oilLiter){
|
||||||
|
//默认优惠后总价等于原来的总价
|
||||||
|
Double newOilAmount = oilAmount;
|
||||||
|
//优惠金额
|
||||||
|
Double disAmount = 0.0;
|
||||||
|
DecimalFormat df = new DecimalFormat("#.00");
|
||||||
|
try {
|
||||||
|
//1 按加油金额,否则 按加油升数
|
||||||
|
Double thisValue = "1".equals(coupon.getUseType())?oilAmount:oilLiter;
|
||||||
|
if("1".equals(coupon.getType())){
|
||||||
|
//代金券-直接拿优惠金额
|
||||||
|
disAmount = coupon.getReduceAmount();
|
||||||
|
}else if("3".equals(coupon.getType())){
|
||||||
|
//折扣券,打折
|
||||||
|
newOilAmount = newOilAmount*coupon.getZkData();
|
||||||
|
disAmount = oilAmount - newOilAmount;
|
||||||
|
if(disAmount>coupon.getZkMaxAmount()){
|
||||||
|
//超出折扣最大优惠金额
|
||||||
|
disAmount = coupon.getZkMaxAmount();
|
||||||
|
}
|
||||||
|
}else if("4".equals(coupon.getType())){
|
||||||
|
//油品立减券,每满多少升减多少钱
|
||||||
|
//计算能除尽多少次,就减多少次
|
||||||
|
int thisInt = (int) (thisValue / coupon.getLjOilNum());
|
||||||
|
//计算优惠金额
|
||||||
|
disAmount = thisInt * coupon.getLjOilAmount();
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("优惠券优惠金额计算失败:"+e.getMessage(),e);
|
||||||
|
}
|
||||||
|
return Double.valueOf(df.format(disAmount));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从一个日期里面获取时间,00:00格式
|
* 从一个日期里面获取时间,00:00格式
|
||||||
* @author vinjor-M
|
* @author vinjor-M
|
||||||
@ -512,7 +728,7 @@ public class CheckUtil {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
**/
|
**/
|
||||||
private static boolean isBetween(double value, double min, double max) {
|
private static boolean isBetween(double value, double min, double max) {
|
||||||
return value > min && value < max;
|
return value >= min && value <= max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,8 +11,14 @@ import java.io.Serializable;
|
|||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
public class CouponVO implements Serializable {
|
public class CouponVO implements Serializable {
|
||||||
/** 优惠券id */
|
/** 优惠券和用户关联表的id */
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
/** 优惠券id */
|
||||||
|
private Integer couponId;
|
||||||
/** 优惠券名称 */
|
/** 优惠券名称 */
|
||||||
private String name;
|
private String name;
|
||||||
|
/**是否可与其他优惠一起使用1可以0不可以*/
|
||||||
|
private String useWithOther;
|
||||||
|
/** 优惠金额 */
|
||||||
|
private Double disAmount;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.fuint.pay.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单选择的商品
|
||||||
|
* @author vinjor-M
|
||||||
|
* @date 14:42 2024/9/25
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
public class GoodsVO {
|
||||||
|
/** 商品id */
|
||||||
|
private String id;
|
||||||
|
/** 商品数量 */
|
||||||
|
private Integer num;
|
||||||
|
/** 商品单价 */
|
||||||
|
private Double price;
|
||||||
|
/** 总金额 */
|
||||||
|
private Double amount;
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
# \u57FA\u672C\u914D\u7F6E
|
# \u57FA\u672C\u914D\u7F6E
|
||||||
server.port=8080
|
server.port=8080
|
||||||
env.profile=dev
|
env.profile=dev
|
||||||
env.properties.path=D:/workspaces/oil-stations/fuintBackend/configure/
|
env.properties.path=D:/my_project/oil-station/fuintBackend/configure/
|
||||||
#env.properties.path=F:/work/oilSystem/fuintBackend/configure/
|
#env.properties.path=F:/work/oilSystem/fuintBackend/configure/
|
||||||
#env.properties.path=D:/oil/new-oil/oilSystem/fuintBackend/configure/
|
#env.properties.path=D:/oil/new-oil/oilSystem/fuintBackend/configure/
|
||||||
#env.properties.path=D:/work/oilSystem/fuintBackend/configure/
|
#env.properties.path=D:/work/oilSystem/fuintBackend/configure/
|
||||||
|
@ -1 +1 @@
|
|||||||
mvn install:install-file -Dfile=D:\Code\yuzhan\oil-station\fuintBackend\lib\yly_sdk_2.2.jar -DgroupId=yly_sdk -DartifactId=yly_sdk -Dversion=2.2 -Dpackaging=jar
|
mvn install:install-file -Dfile=D:\Code\yuzhan\oil-station\fuintBackend\lib\yly_sdk_2.2.jar -DgroupId=yly_sdk -DartifactId=yly_sdk -Dversion=2.2 -Dpackaging=jar
|
@ -65,7 +65,7 @@
|
|||||||
<div class="d-b">
|
<div class="d-b">
|
||||||
|
|
||||||
<el-checkbox v-model="checkAll">活动优惠 <i class="el-icon-arrow-down"></i></el-checkbox>
|
<el-checkbox v-model="checkAll">活动优惠 <i class="el-icon-arrow-down"></i></el-checkbox>
|
||||||
<div class="or_num">-¥0.00</div>
|
<div class="or_num"></div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 下拉列表插入-->
|
<!-- 下拉列表插入-->
|
||||||
<div v-if="checkAll == true">
|
<div v-if="checkAll == true">
|
||||||
@ -83,22 +83,19 @@
|
|||||||
<div class="d-b">
|
<div class="d-b">
|
||||||
|
|
||||||
<el-checkbox v-model="checkAll">优惠券 <i class="el-icon-arrow-down"></i></el-checkbox>
|
<el-checkbox v-model="checkAll">优惠券 <i class="el-icon-arrow-down"></i></el-checkbox>
|
||||||
<div class="or_num">-¥0.00</div>
|
<div class="or_num"></div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 下拉列表插入-->
|
<!-- 下拉列表插入-->
|
||||||
<div v-if="checkAll == true">
|
<div v-if="checkAll == true">
|
||||||
|
<div v-if="couponList.length>0">
|
||||||
<div class="x-d-b">
|
<el-radio-group style="width: 100%" v-model="chooseAct">
|
||||||
<el-checkbox v-model="checkAll1">优惠券1</el-checkbox>
|
<div class="x-d-b" v-for="(item,index) in activityList">
|
||||||
<div class="or_num">-¥0.00</div>
|
<el-radio :label="item.id">{{null==item.ruleName?item.actName:item.ruleName}}<div class="or_num">-¥{{item.disAmount}}</div></el-radio>
|
||||||
|
</div>
|
||||||
|
</el-radio-group>
|
||||||
</div>
|
</div>
|
||||||
<div class="x-d-b">
|
<div v-if="couponList.length==0">
|
||||||
<el-checkbox v-model="checkAll2">优惠券2</el-checkbox>
|
暂无可用优惠券
|
||||||
<div class="or_num">-¥0.00</div>
|
|
||||||
</div>
|
|
||||||
<div class="x-d-b">
|
|
||||||
<el-checkbox v-model="checkAll3">优惠券3</el-checkbox>
|
|
||||||
<div class="or_num">-¥0.00</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -544,8 +541,12 @@ export default {
|
|||||||
},
|
},
|
||||||
//可参加的活动
|
//可参加的活动
|
||||||
activityList:[],
|
activityList:[],
|
||||||
|
//可用优惠券
|
||||||
|
couponList:[],
|
||||||
//选中的活动 actId_ruleId
|
//选中的活动 actId_ruleId
|
||||||
chooseAct:"",
|
chooseAct:"",
|
||||||
|
//选中的优惠券
|
||||||
|
chooseCoupon:"",
|
||||||
//支付方式--默认支付宝
|
//支付方式--默认支付宝
|
||||||
payWay: "ALIPAY",
|
payWay: "ALIPAY",
|
||||||
//订单总金额
|
//订单总金额
|
||||||
@ -655,6 +656,17 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
orderAmount: {
|
||||||
|
handler(newVal) {
|
||||||
|
console.log("订单总金额发生变化", newVal);
|
||||||
|
//查询可用优惠活动
|
||||||
|
this.getActivity()
|
||||||
|
//查可用优惠券
|
||||||
|
this.getCoupon()
|
||||||
|
},
|
||||||
|
deep: true,
|
||||||
|
immediate: true,
|
||||||
|
},
|
||||||
//监听子弹窗成功 提交了 然后再隐藏子元素标签
|
//监听子弹窗成功 提交了 然后再隐藏子元素标签
|
||||||
oilGunClearing: {
|
oilGunClearing: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
@ -667,8 +679,6 @@ export default {
|
|||||||
this.orderAmount = this.getGoodsNum
|
this.orderAmount = this.getGoodsNum
|
||||||
}
|
}
|
||||||
this.refuelingAmount = false
|
this.refuelingAmount = false
|
||||||
//查询可用优惠活动
|
|
||||||
this.getActivity()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//监听商品总金额发生变化
|
//监听商品总金额发生变化
|
||||||
@ -994,21 +1004,38 @@ export default {
|
|||||||
*/
|
*/
|
||||||
getCoupon(){
|
getCoupon(){
|
||||||
//组装请求参数
|
//组装请求参数
|
||||||
if(this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId") && this.chooseVipUser.hasOwnProperty("id")){
|
if(this.chooseVipUser.hasOwnProperty("id") && (this.goodsList.length>0 || (this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId")))){
|
||||||
// 保留两位小数
|
//已选择会员且(选了商品或者加了油)
|
||||||
let oilLiter = (this.oilGunClearing.amount / this.oilGunClearing.oilPrice).toFixed(2)
|
|
||||||
//油枪已结算,且已选择会员
|
|
||||||
let dataObj = {
|
let dataObj = {
|
||||||
userId: this.chooseVipUser.id,
|
userId: this.chooseVipUser.id
|
||||||
oilId: this.oilGunClearing.oilNameId,
|
}
|
||||||
oilPrice:this.oilGunClearing.oilPrice,
|
if(this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId")){
|
||||||
oilAmount: this.oilGunClearing.amount,
|
//加油油枪有值
|
||||||
orderAmount: this.orderAmount,
|
dataObj['oilId'] = this.oilGunClearing.oilNameId
|
||||||
oilLiter: oilLiter
|
dataObj['oilAmount'] = this.oilGunClearing.amount
|
||||||
|
dataObj['oilLiter'] = this.oilLiter
|
||||||
|
}
|
||||||
|
if(this.goodsList.length>0){
|
||||||
|
let goodsArray = []
|
||||||
|
for (let i = 0; i < this.goodsList.length; i++) {
|
||||||
|
let thisGoods = this.goodsList[i]
|
||||||
|
let goods = {
|
||||||
|
id: thisGoods.id,
|
||||||
|
num:thisGoods.num,
|
||||||
|
price:thisGoods.retailPrice,
|
||||||
|
amount:thisGoods.retailPrice * thisGoods.num
|
||||||
|
}
|
||||||
|
goodsArray.push(goods)
|
||||||
|
dataObj['goods'] = JSON.stringify(goodsArray)
|
||||||
|
}
|
||||||
|
console.log(dataObj)
|
||||||
}
|
}
|
||||||
getCouponList(dataObj).then(res => {
|
getCouponList(dataObj).then(res => {
|
||||||
console.log("返回结果",res)
|
console.log("返回的可用的优惠券",res)
|
||||||
|
this.couponList = res.data
|
||||||
})
|
})
|
||||||
|
}else{
|
||||||
|
this.couponList=[]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
copyToClipboard(textToCopy) {
|
copyToClipboard(textToCopy) {
|
||||||
|
Loading…
Reference in New Issue
Block a user