From 21e34c8ebe1c1792d54b5b9c7d1933d38493f7a1 Mon Sep 17 00:00:00 2001 From: Vinjor Date: Fri, 27 Sep 2024 10:05:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=93=B6=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PayCenterServiceImpl.java | 18 ++ .../java/com/fuint/pay/util/CheckUtil.java | 59 +++--- .../views/cashier/NewComponents/newHome.vue | 185 +++++++++++++----- 3 files changed, 192 insertions(+), 70 deletions(-) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java index f68d40643..4342f7993 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/service/impl/PayCenterServiceImpl.java @@ -68,6 +68,8 @@ public class PayCenterServiceImpl implements PayCenterService { **/ @Override public Object getActivity(Map map) { + //实际会收钱的支付方式 + List canUsePayWays = Arrays.asList("ALIPAY","WECHAT","UNIONPAY","CASH"); /*1.先把所有用到的值取出来 */ //当前时间,从点击结算的这一刻算 Date nowDate = new Date(); @@ -103,6 +105,10 @@ public class PayCenterServiceImpl implements PayCenterService { String payWay = map.get("payWay"); /*2.查询所有可参加的营销活动 */ List actList = new ArrayList<>(); + if(!canUsePayWays.contains(payWay)){ + //所选支付方式不符合活动参与条件 + return actList; + } try { //2.1 查可参加的分时优惠和限时特价 actList.addAll(this.getFenshiAndTejiaAct(nowDate,userId,gradeId,storeId,labelIdList,oilAmount,oilLiter,oilId,oilPrice,payWay)); @@ -351,6 +357,8 @@ public class PayCenterServiceImpl implements PayCenterService { **/ @Override public Object getCoupon(Map map){ + //实际会收钱的支付方式 + List canUsePayWays = Arrays.asList("ALIPAY","WECHAT","UNIONPAY","CASH"); /*1.先把所有用到的值取出来 */ //当前时间,从点击结算的这一刻算 Date nowDate = new Date(); @@ -364,6 +372,12 @@ public class PayCenterServiceImpl implements PayCenterService { Double oilAmount = Double.valueOf(map.getOrDefault("oilAmount","0")); //油升数 Double oilLiter = Double.valueOf(map.getOrDefault("oilLiter","0")); + //支付方式 + String payWay = map.get("payWay"); + if("after_pay".equals(payWay)){ + //挂账,不可以用优惠券 + return new ArrayList<>(); + } //选择的商品 List goodsList = new ArrayList<>(); String goodsStr = map.getOrDefault("goods",""); @@ -401,6 +415,10 @@ public class PayCenterServiceImpl implements PayCenterService { List rtnList = new ArrayList<>(); if(!filteredList.isEmpty()){ for(CardCouponVO rule:filteredList){ + if("0".equals(rule.getUseWithOther()) && !canUsePayWays.contains(payWay)){ + //不可以与其他优惠同时用,且支付方式不是 实际付钱的,跳过 + break; + } CouponVO couponVO = new CouponVO(); couponVO.setId(rule.getDataId()); couponVO.setCouponId(rule.getId()); diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java index cd0dc80de..e7259cd73 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/pay/util/CheckUtil.java @@ -164,11 +164,11 @@ public class CheckUtil { nowWeek =7; } if(timeSlotList.contains(nowWeek)){ - //周几是符合的,返回不可用 - return false; - }else{ - //周几是不符合的,进而判断时间是否符合 + //周几是符合的,再判断时间是否符合 return checkDayTimeReverse(nowDate,startTime,endTime); + }else{ + //周几是不符合的,直接可用 + return true; } }else{ //活动设置的适用时间类型是每月 @@ -337,23 +337,37 @@ public class CheckUtil { * @return java.lang.Boolean **/ public Boolean checkGoodsCoupon(CardCouponVO couponVO, List goodsList){ - if("5".equals(couponVO.getType()) || goodsList.isEmpty()){ + if("5".equals(couponVO.getType())){ //单品立减券 - if(StringUtils.isNotEmpty(couponVO.getProductIds())){ - //限制使用的商品id - List ruleGoodsList = Arrays.asList(couponVO.getProductIds().split(StrUtil.COMMA)); - //过滤出符合条件的本订单的商品 - List 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{ - //未设置可用商品,不符合 + if(goodsList.isEmpty()){ + //没商品,不可用 return false; } + //符合条件的商品 + List filteredList; + if("1".equals(couponVO.getProductLimit())){ + //不限制使用商品 + filteredList = goodsList; + }else if("2".equals(couponVO.getProductLimit())){ + //自定义商品 + if(StringUtils.isNotEmpty(couponVO.getProductIds())) { + List ruleGoodsList = Arrays.asList(couponVO.getProductIds().split(StrUtil.COMMA)); + //过滤出符合条件的本订单的商品 + filteredList = goodsList.stream().filter(goods -> ruleGoodsList.contains(goods.getId())).collect(Collectors.toList()); + }else{ + //未设置可用商品,不符合 + return false; + } + }else{ + //超出预设值范围,不可用 + return false; + } + //计算符合条件的商品订单总金额 + double orderAmount =0.0; + if(!filteredList.isEmpty()){ + orderAmount = filteredList.stream().mapToDouble(GoodsVO::getAmount).sum(); + } + return orderAmount>=couponVO.getReachAmount(); }else{ //其他券或者本订单未选择商品不需要判断商品 return true; @@ -589,8 +603,6 @@ public class CheckUtil { 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(); @@ -605,9 +617,12 @@ public class CheckUtil { }else if("4".equals(coupon.getType())){ //油品立减券,每满多少升减多少钱 //计算能除尽多少次,就减多少次 - int thisInt = (int) (thisValue / coupon.getLjOilNum()); + int thisInt = (int) (oilLiter / coupon.getLjOilNum()); //计算优惠金额 disAmount = thisInt * coupon.getLjOilAmount(); + }else if("5".equals(coupon.getType())){ + //单品立减券,直接拿优惠金额 + disAmount = coupon.getReduceAmount(); } }catch (Exception e){ log.error("优惠券优惠金额计算失败:"+e.getMessage(),e); @@ -710,7 +725,7 @@ public class CheckUtil { * @return boolean **/ private static boolean checkDayTimeReverse(Date nowDate,String dayStartTime,String dayEndTime){ - String dayStr = DateUtil.date(nowDate).toString(); + String dayStr = DateUtil.formatDate(nowDate); //时间范围区间 Date startTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayStartTime)?(dayStartTime+":00"):"00:00:00")); Date endTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayEndTime)?(dayEndTime+":59"):"23:59:59")); diff --git a/fuintCashierWeb/src/views/cashier/NewComponents/newHome.vue b/fuintCashierWeb/src/views/cashier/NewComponents/newHome.vue index 59a54ad77..32ea33efd 100644 --- a/fuintCashierWeb/src/views/cashier/NewComponents/newHome.vue +++ b/fuintCashierWeb/src/views/cashier/NewComponents/newHome.vue @@ -64,13 +64,13 @@
- 活动优惠 + 活动优惠
-
+
- +
{{null==item.ruleName?item.actName:item.ruleName}}
-¥{{item.disAmount}}
@@ -82,15 +82,15 @@
- 优惠券 + 优惠券
-
+
- -
- {{null==item.ruleName?item.actName:item.ruleName}}
-¥{{item.disAmount}}
+ +
+ {{item.name}}
-¥{{item.disAmount}}
@@ -100,20 +100,20 @@
-
-
-
扫码支付
-
0.00
-
-
-
找零
-
0.00
-
-
-
加油员
-
0.00
-
-
+ + + + + + + + + + + + + +
-
¥0.00
-
优惠合计:¥0.00元
+
¥{{realAmount}}
+
优惠合计:¥{{disTotal}}元
立即结算
@@ -545,15 +545,23 @@ export default { //可用优惠券 couponList:[], //选中的活动 actId_ruleId - chooseAct:"", - //选中的优惠券 - chooseCoupon:"", + chooseActId:"", + //选中的优惠券id + chooseCouponId:"", + //选中的活动对象 + chooseAct:{}, + //选中的优惠券对象 + chooseCoupon:{}, //支付方式--默认支付宝 payWay: "ALIPAY", //订单总金额 - orderAmount:0.0, + orderAmount:0.00, //加油升数 - oilLiter:0, + oilLiter:0.00, + //订单实付金额 + realAmount:0.00, + //优惠合计金额 + disTotal:0.00, openConfirm:false, // 是否支付 isPay:false, @@ -580,16 +588,10 @@ export default { state: '', //挂单数据容器 pendingOrdersList: [], - timeout: null, - boxShow: true, - boxShow1: true, - boxShow2: true, - checkList: [], - checkAll: true, - checkAll1: false, - checkAll2: false, - checkAll3: false, - isIndeterminate: true, + //是否显示可用优惠活动 + showAct: true, + //是否显示可用优惠券 + showCoupon: true, freeTicket:false, freeIndex:0, freeTicketList:[ @@ -658,17 +660,45 @@ export default { flag:1, jishuqi:0, continuePolling: true, // 控制轮询的变量 - } }, watch: { + //监听选择的活动 + chooseActId: { + handler(newVal) { + console.log("选择的活动发生变化", newVal); + //计算优惠金额 + this.getDisTotal() + }, + deep: true, + immediate: true, + }, + //监听选择的优惠券 + chooseCouponId: { + handler(newVal) { + console.log("选择的优惠券发生变化", newVal); + //计算优惠金额 + this.getDisTotal() + }, + deep: true, + immediate: true, + }, + //监听订单总金额 orderAmount: { handler(newVal) { console.log("订单总金额发生变化", newVal); - //查询可用优惠活动 - this.getActivity() - //查可用优惠券 - this.getCoupon() + //计算实付金额 + this.realAmount = (this.orderAmount - this.disTotal).toFixed(2) + }, + deep: true, + immediate: true, + }, + //监听优惠总金额 + disTotal:{ + handler(newVal) { + console.log("优惠总金额发生变化", newVal); + //计算实付金额 + this.realAmount = (this.orderAmount - this.disTotal).toFixed(2) }, deep: true, immediate: true, @@ -685,6 +715,10 @@ export default { this.orderAmount = this.getGoodsNum } this.refuelingAmount = false + //查询可用优惠活动 + this.getActivity() + //查可用优惠券 + this.getCoupon() } }, //监听商品总金额发生变化 @@ -696,6 +730,8 @@ export default { }else { this.orderAmount = newVal } + //刷新可用优惠券 + this.getCoupon() } }, components: { @@ -745,6 +781,48 @@ export default { }, methods: { + /** + * 获取优惠总金额 + * */ + getDisTotal(){ + this.disTotal = 0.00 + if(""!=this.chooseCouponId){ + this.disTotal += this.chooseCoupon.disAmount + } + if(""!=this.chooseActId){ + this.disTotal += this.chooseAct.disAmount + } + this.disTotal = (this.disTotal).toFixed(2) + }, + /** + * 监听活动选择切换 + * */ + handleChangeAct(value){ + this.chooseAct = this.activityList.filter(item=>item.id === value)[0] + if(""!=this.chooseCouponId){ + //判断已选择的优惠券是否可以与其他活动共用 + if("0"==this.chooseCoupon.useWithOther){ + //优惠券不能与本活动共用 + this.chooseCouponId = "" + this.chooseCoupon = {} + } + } + this.getDisTotal() + console.log("选中的活动",this.chooseAct) + }, + /** + * 监听优惠券选择切换 + * */ + handleChangeCoupon(value){ + this.chooseCoupon = this.couponList.filter(item=>item.id === value)[0] + if("0"==this.chooseCoupon.useWithOther){ + //本优惠券不能与其他活动一起用 + this.chooseAct = {} + this.chooseActId = "" + } + this.getDisTotal() + console.log("选中的优惠券",this.chooseCoupon) + }, async collection1() { let actualPayment = 0 let makeChange = 0 @@ -981,6 +1059,7 @@ export default { * @date 2024年9月19日 */ getActivity(){ + this.chooseActId='' //组装请求参数 if(this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId") && this.chooseVipUser.hasOwnProperty("id")){ //油枪已结算,且已选择会员 @@ -1009,11 +1088,13 @@ export default { * @date 2024年9月19日 */ getCoupon(){ + this.chooseCouponId='' //组装请求参数 if(this.chooseVipUser.hasOwnProperty("id") && (this.goodsList.length>0 || (this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId")))){ //已选择会员且(选了商品或者加了油) let dataObj = { - userId: this.chooseVipUser.id + userId: this.chooseVipUser.id, + payWay: this.payWay } if(this.oilGunClearing!='' && this.oilGunClearing.hasOwnProperty("oilNameId")){ //加油油枪有值 @@ -1057,12 +1138,17 @@ export default { restVipUser(){ this.userInfo = false this.chooseVipUser = {} + this.getActivity() + this.getCoupon() }, chooseUser(data){ if (data){ //选择会员 this.userInfo = true this.chooseVipUser = data + //选择会员,查询可用优惠活动和优惠券 + this.getActivity() + this.getCoupon() console.log(this.chooseVipUser,598) } @@ -1293,6 +1379,9 @@ export default { */ setindex(value) { this.payWay = value + //支付方式发生变化,查询可用优惠券和优惠活动 + this.getActivity() + this.getCoupon() }, setRefuelingAmount(item) { this.refuelingAmount = true @@ -1557,18 +1646,18 @@ input { } .x-d-b { - width: 90%; + width: 95%; display: flex; align-items: center; justify-content: space-between; margin: 15px 0px; - margin-left: 10%; + margin-left: 4%; } .d-top { width: 100%; box-sizing: border-box; - padding: 0px 40px; + padding: 0 40px 20px 40px; font-size: 16px; color: #555555; border-bottom: #f6f8f9 4px solid;