jk-GitHub-coder hace 3 años
padre
commit
2df4d3995b

+ 3 - 3
YijiaRestful/src/main/java/com/platform/yijia/controller/CouponController.java

@@ -278,7 +278,7 @@ public class CouponController {
                         int couponSuccessNum =0;                                           //用户优惠券领取成功张数 couponSuccess
                         for(int i=0; i<ids.size(); i++){
                             Integer couponId = Integer.valueOf(ids.get(i));
-                            couponParam.setId(couponId);
+                            couponParam.setCouponId(couponId);
                             //领取成功的张数与该领取方式在当前页最多领取的张数
                             if(couponSuccessNum <= couponIssueList.get(0).getGiveLimit()) {
                                 Coupon coupon = couponService.selectCouponTemplateInfo(couponParam);
@@ -290,7 +290,7 @@ public class CouponController {
                                         uc.setIssueId(couponIssueId);
                                         uc.setStationId(stationId);
                                         uc.setUnionId(unionId);
-                                        uc.setCouponId(coupon.getId());
+                                        uc.setCouponId(coupon.getCouponId());
                                         //获取该用户优惠券累计的张数
                                         int userCouponCountSum = couponService.selectUserCouponCount(uc);
                                         uc.setCouponIsUsed("0");
@@ -306,7 +306,7 @@ public class CouponController {
                                                 userCouponParam.setCouponNo(s1);                //优惠券编码
                                                 userCouponParam.setUnionId(unionId);            //用户unionId
                                                 userCouponParam.setIssueId(couponIssueId);      //领取方式ID
-                                                userCouponParam.setCouponId(coupon.getId());    //优惠券ID
+                                                userCouponParam.setCouponId(coupon.getCouponId());    //优惠券模板ID
                                                 userCouponParam.setStationId(stationId);        //油站ID
                                                 userCouponParam.setCouponIsEffective("1");      //优惠券是否有效
                                                 userCouponParam.setGetCouponTime(new Date());   //优惠券领取时间

+ 41 - 1
YijiaRestful/src/main/java/com/platform/yijia/controller/PayController.java

@@ -59,6 +59,8 @@ public class PayController {
     private GzhNewsTemplateService gzhNewsTemplateService;
     @Resource
     private  CustomerManagerService customerManagerService;
+    @Resource
+    private CouponService couponService;
     @Value("${yijia.path.global-prefix}")
     private String globalPrefix;
     @Value("${yijia.domainName}")
@@ -156,6 +158,7 @@ public class PayController {
      */
     @RequestMapping(value = "/getJhPayInfo", consumes = "application/json", method = RequestMethod.POST)
     @ResponseBody
+    @Transactional
     public String getJhPayInfo(@RequestBody PayInfoRequest payInfoRequest){
         Gson gson =new Gson();
         ResultData resultData =null;
@@ -185,11 +188,48 @@ public class PayController {
                 PayOrder payOrder=payOrderService.selectOrderInfoByOrdNo(ordNo);
                 if(payOrder!=null ){
                     if(payOrder.getStatus() !=null && payOrder.getStatus().equals("0")){
+                        //是否开启优惠券功能
+                        if(stationInfos.getCouponEnabledFlag() !=null && stationInfos.getCouponEnabledFlag().equals("1")){
+                            Integer id = payInfoRequest.getId();
+                            if(id !=null){
+                                UserCoupon userCoupon = new UserCoupon();
+                                userCoupon.setId(id);
+                                UserCoupon ucResult = couponService.selectUserCouponInfo(userCoupon);
+                                if(ucResult !=null){
+                                    PayOrder p =new PayOrder();
+                                    BigDecimal couponAmt = ucResult.getCouponAmt();     //优惠券优惠参数
+                                    String couponType = ucResult.getCouponType();       //优惠券类型
+                                    Double amt = payOrder.getAmt();
+                                    Double discountAmt = payOrder.getDiscountAmt();
+                                    BigDecimal amtNew = new BigDecimal(amt.toString());
+                                    BigDecimal discountAmtNew = new BigDecimal(discountAmt.toString());
+                                    switch (couponType){
+                                        case "1":
+                                            amtNew = new BigDecimal(amt.toString()).subtract(couponAmt);
+                                            discountAmtNew = new BigDecimal(discountAmt.toString()).add(couponAmt);
+                                            break;
+                                        case "2":
+                                            amtNew = new BigDecimal(amt.toString()).multiply(couponAmt);
+                                            BigDecimal divide = new BigDecimal("100").subtract(couponAmt).divide(new BigDecimal("100"));
+                                            discountAmtNew = new BigDecimal(amt.toString()).multiply(divide);
+                                            break;
+                                    }
+                                    amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
+                                    discountAmtNew = discountAmtNew.signum() == -1 ? new BigDecimal("0.01") : discountAmtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
+                                    p.setAmt(Double.valueOf(amtNew.toString()));
+                                    p.setDiscountAmt(Double.valueOf(discountAmtNew.toString()));
+                                    p.setDiscountCoupon(id.toString());
+                                    payOrderService.getUpdatePayOrder(p);
+                                }
+                            }
+                        }
+
                         //将业务参数存放在 JSON 对象中
                         JSONObject reqData = new JSONObject();
+                        PayOrder payOrderNew=payOrderService.selectOrderInfoByOrdNo(ordNo);
                         reqData.put("ordNo", payOrder.getOrderNo()); //商户订单号
                         //reqData.put("subMechId", ""); //子商户号
-                        reqData.put("amt", payOrder.getAmt()); //订单总金额
+                        reqData.put("amt", payOrderNew.getAmt()); //订单总金额
                         //reqData.put("amt", "0.01");
                         //reqData.put("discountAmt", ""); //参与优惠金额
                         //reqData.put("unDiscountAmt", ""); //不参与优惠金额

+ 243 - 209
YijiaRestful/src/main/java/com/platform/yijia/controller/PayOrderController.java

@@ -163,6 +163,7 @@ public class PayOrderController {
 //                            }
                             //payOrder.setDiscountAmt(Double.valueOf(payOrderResultInfo.getDzkDiscountAmt()));
                         }
+                        resultMap.put("dzkDiscountPrice", payOrderResultInfo.getDzkDiscountPrice());
                         resultMap.put("cardEnabledFlag", payOrderResultInfo.getCardEnabledFlag());
                         resultMap.put("oilsCardFlag", payOrderResultInfo.getOilsCardFlag());
                         resultMap.put("discountAmt", payOrderResultInfo.getDiscountAmt());    //优惠金额
@@ -176,6 +177,9 @@ public class PayOrderController {
                             resultMap.put("sellDiscountAmt", payOrderResultInfo.getSellDiscountAmt());
                         }
                         payOrder.setDriverOilPrice(Double.valueOf(payOrderResultInfo.getDiscountPrice()));
+                        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
+                            payOrder.setDriverOilPrice(Double.valueOf(payOrderResultInfo.getDzkDiscountPrice()));
+                        }
                         resultMap.put("receivableAmt", payOrderResultInfo.getReceivableAmt());           //应收价格
                         resultMap.put("oilLiters", payOrderResultInfo.getOilLiters());
                         resultMap.put("amt_dzk", payOrderResultInfo.getDzkAmt());
@@ -825,11 +829,14 @@ public class PayOrderController {
             payOrderResultInfo.setBalance(map.get("balance"));
             payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
             payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
-//            payOrderResultInfo.setStationId(Integer.valueOf(params.get("stationId").toString()));
-//            payOrderResultInfo.setOilName(params.get("oilName").toString());
-//            payOrderResultInfo.setUnionId(params.get("unionId").toString());
-//            payOrderResultInfo.setAllDiscountType("2");
-//            payOrderResultInfo.setUserCouponsList(this.getUserCouponAscList(payOrderResultInfo));
+
+            String dzkAmt = payOrderResultInfo.getDzkAmt();
+            if(oilLiters.toString().equals("0.00")){
+                payOrderResultInfo.setDzkDiscountPrice(oilPrice.toString());
+            }else {
+                BigDecimal dzkDiscountPrice = new BigDecimal(dzkAmt).divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                payOrderResultInfo.setDzkDiscountPrice(dzkDiscountPrice.toString());
+            }
         }
         return  payOrderResultInfo;
     }
@@ -1019,11 +1026,13 @@ public class PayOrderController {
             payOrderResultInfo.setBalance(map.get("balance"));
             payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
             payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
-//            payOrderResultInfo.setStationId(Integer.valueOf(params.get("stationId").toString()));
-//            payOrderResultInfo.setOilName(params.get("oilName").toString());
-//            payOrderResultInfo.setUnionId(params.get("unionId").toString());
-//            payOrderResultInfo.setAllDiscountType("2");
-//            payOrderResultInfo.setUserCouponsList(this.getUserCouponAscList(payOrderResultInfo));
+            String dzkAmt = payOrderResultInfo.getDzkAmt();
+            if(oilLiters.toString().equals("0.00")){
+                payOrderResultInfo.setDzkDiscountPrice(oilPrice.toString());
+            }else {
+                BigDecimal dzkDiscountPrice = new BigDecimal(dzkAmt).divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                payOrderResultInfo.setDzkDiscountPrice(dzkDiscountPrice.toString());
+            }
         }
         return  payOrderResultInfo;
     }
@@ -1158,11 +1167,13 @@ public class PayOrderController {
             payOrderResultInfo.setBalance(map.get("balance"));
             payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
             payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
-//            payOrderResultInfo.setStationId(Integer.valueOf(params.get("stationId").toString()));
-//            payOrderResultInfo.setOilName(params.get("oilName").toString());
-//            payOrderResultInfo.setUnionId(params.get("unionId").toString());
-//            payOrderResultInfo.setAllDiscountType("2");
-//            payOrderResultInfo.setUserCouponsList(this.getUserCouponAscList(payOrderResultInfo));
+            String dzkAmt = payOrderResultInfo.getDzkAmt();
+            if(oilLiters.toString().equals("0.00")){
+                payOrderResultInfo.setDzkDiscountPrice(oilPrice.toString());
+            }else {
+                BigDecimal dzkDiscountPrice = new BigDecimal(dzkAmt).divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                payOrderResultInfo.setDzkDiscountPrice(dzkDiscountPrice.toString());
+            }
         }
         return  payOrderResultInfo;
     }
@@ -1301,11 +1312,13 @@ public class PayOrderController {
             payOrderResultInfo.setBalance(map.get("balance"));
             payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
             payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
-//            payOrderResultInfo.setOilName(params.get("oilName").toString());
-//            payOrderResultInfo.setUnionId(params.get("unionId").toString());
-//            payOrderResultInfo.setAllDiscountType("2");
-//            payOrderResultInfo.setStationId(Integer.valueOf(params.get("stationId").toString()));
-//            payOrderResultInfo.setUserCouponsList(this.getUserCouponAscList(payOrderResultInfo));
+            String dzkAmt = payOrderResultInfo.getDzkAmt();
+            if(oilLiters.toString().equals("0.00")){
+                payOrderResultInfo.setDzkDiscountPrice(oilPrice.toString());
+            }else {
+                BigDecimal dzkDiscountPrice = new BigDecimal(dzkAmt).divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                payOrderResultInfo.setDzkDiscountPrice(dzkDiscountPrice.toString());
+            }
         }
         return payOrderResultInfo;
     }
@@ -1419,11 +1432,13 @@ public class PayOrderController {
             payOrderResultInfo.setBalance(map.get("balance"));
             payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
             payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
-//            payOrderResultInfo.setOilName(params.get("oilName").toString());
-//            payOrderResultInfo.setUnionId(params.get("unionId").toString());
-//            payOrderResultInfo.setAllDiscountType("1");
-//            payOrderResultInfo.setStationId(Integer.valueOf(params.get("stationId").toString()));
-//            payOrderResultInfo.setUserCouponsList(this.getUserCouponAscList(payOrderResultInfo));
+            String dzkAmt = payOrderResultInfo.getDzkAmt();
+            if(oilLiters.toString().equals("0.00")){
+                payOrderResultInfo.setDzkDiscountPrice(oilPrice.toString());
+            }else {
+                BigDecimal dzkDiscountPrice = new BigDecimal(dzkAmt).divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                payOrderResultInfo.setDzkDiscountPrice(dzkDiscountPrice.toString());
+            }
         }
         return  payOrderResultInfo;
     }
@@ -1447,6 +1462,7 @@ public class PayOrderController {
             userCoupon.setExpireFlag("0");                  // SQL 条件判断 过期标志: 1 代表使用的优惠券已过期查询参数; 0 代表未过期有效的优惠券
             userCoupon.setNoVerificationVerFlag("0");       //SQL 条件判断 查询没有异业券的参数标识: 0代表只有加油券 1代表只有异业券
             userCoupon.setCurrentTime(new Date());
+            userCoupon.setOilName(p.getOilName());
             userCouponsList = couponService.selectUserCoupons(userCoupon);
             //循环计算优惠券金额 并排序
             if(userCouponsList !=null && userCouponsList.size()>0){
@@ -1506,6 +1522,7 @@ public class PayOrderController {
                                 }
                             }
                         }
+                        uc.setCouponNo("");
                         uc.setCouponReckonAmt(couponReckonAmt);
                     }
                 }
@@ -1533,22 +1550,26 @@ public class PayOrderController {
         String discountPrice = c.getDiscountPrice();
         BigDecimal couponAmt = uc.getCouponAmt();
         String receivableAmt = p.getReceivableAmt();
+        String dzkDiscountPrice = p.getDzkDiscountPrice();
 
         BigDecimal dzkAmtNew = new BigDecimal(dzkAmt);
         BigDecimal amtNew = new BigDecimal(amt);
         BigDecimal discountPriceNew = new BigDecimal(discountPrice);
         BigDecimal discountAmtNew = new BigDecimal(discountAmt);
         BigDecimal dzkDiscountAmtNew = new BigDecimal(dzkDiscountAmt);
+        BigDecimal dzkDiscountPriceNew = new BigDecimal(dzkDiscountPrice);
 
-                //根据优惠券类型计算金额
+        //根据优惠券类型计算金额
         switch (uc.getCouponType()){
             case "1":       //现金券
                 if(p.getAllDiscountType().equals("1")){
                     //表示等级
                     if(uc.getIsGradeFlag().equals("1")){
                         amtNew = new BigDecimal(amt).subtract(couponAmt);
-                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew;
-                        discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        if(!oilLiters.equals("0.00")){
+                            discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        }
                         couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
                         discountAmtNew = discountAmtNew.add(couponAmt);
                         couponReckonAmt.setDiscountAmt(discountAmtNew.toString());
@@ -1560,24 +1581,30 @@ public class PayOrderController {
                     if(uc.getIsMarketFlag().equals("1")){
                         //优惠券后的优惠金额
                         amtNew = new BigDecimal(amt).subtract(couponAmt);
-                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew;
+                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
                         //优惠券后的优惠价格
-                        discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        if(!oilLiters.equals("0.00")){
+                            discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        }
                         discountAmtNew = discountAmtNew.add(couponAmt);
                         couponReckonAmt.setDiscountAmt(discountAmtNew.toString());
                         couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
                         couponReckonAmt.setAmt(amtNew.toString());
                     }
                 }
-                if(uc.getIsCardFlag().equals("1")){
-                    //与电子卡共享
-                    dzkAmtNew = new BigDecimal(dzkAmt).subtract(couponAmt);
-                    dzkAmtNew = dzkAmtNew.signum() == -1 ? new BigDecimal("0.01") : dzkAmtNew;
-                    discountPriceNew = dzkAmtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
-                    dzkDiscountAmtNew = dzkDiscountAmtNew.add(couponAmt);
-                    couponReckonAmt.setDzkDiscountAmt(dzkDiscountAmtNew.toString());
-                    couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
-                    couponReckonAmt.setDzkAmt(dzkAmtNew.toString());
+                if(p.getCardEnabledFlag().equals("1")){
+                    if(uc.getIsCardFlag().equals("1")){
+                        //与电子卡共享
+                        dzkAmtNew = new BigDecimal(dzkAmt).subtract(couponAmt);
+                        dzkAmtNew = dzkAmtNew.signum() == -1 ? new BigDecimal("0.01") : dzkAmtNew.setScale(2, BigDecimal.ROUND_HALF_UP);
+                        dzkDiscountAmtNew = dzkDiscountAmtNew.add(couponAmt);
+                        couponReckonAmt.setDzkDiscountAmt(dzkDiscountAmtNew.toString());
+                        couponReckonAmt.setDzkAmt(dzkAmtNew.toString());
+                        if(!oilLiters.equals("0.00")){
+                            dzkDiscountPriceNew = dzkAmtNew.divide(new BigDecimal(oilLiters), 2 ,BigDecimal.ROUND_HALF_UP);
+                        }
+                        couponReckonAmt.setDzkDiscountPrice(dzkDiscountPriceNew.toString());
+                    }
                 }
                 break;
             case "2":       //折扣券
@@ -1586,8 +1613,10 @@ public class PayOrderController {
                     if(uc.getIsGradeFlag().equals("1")){
                         //表示与等级共享
                         amtNew = new BigDecimal(amt).multiply(couponAmt).divide(new BigDecimal("100"));
-                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew;
-                        discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        if(!oilLiters.equals("0.00")){
+                            discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        }
                         discountAmtNew = new BigDecimal(receivableAmt).subtract(amtNew);
                         couponReckonAmt.setDiscountAmt(discountAmtNew.toString());
                         couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
@@ -1600,26 +1629,31 @@ public class PayOrderController {
                     if(uc.getIsMarketFlag().equals("1")){
                         //优惠券后的优惠金额
                         amtNew = new BigDecimal(amt).multiply(couponAmt).divide(new BigDecimal("100"));
-                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew;
+                        amtNew = amtNew.signum() == -1 ? new BigDecimal("0.01") : amtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
                         //优惠券后的优惠价格
-                        discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        if(!oilLiters.equals("0.00")){
+                            discountPriceNew = amtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
+                        }
                         discountAmtNew = new BigDecimal(receivableAmt).subtract(amtNew);
                         couponReckonAmt.setDiscountAmt(discountAmtNew.toString());
                         couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
                         couponReckonAmt.setAmt(amtNew.toString());
                     }
                 }
-                if(uc.getIsCardFlag().equals("1")){
-                    //与电子卡共享
-                    dzkAmtNew = new BigDecimal(dzkAmt).multiply(couponAmt).divide(new BigDecimal("100"));
-                    dzkAmtNew = dzkAmtNew.signum() == -1 ? new BigDecimal("0.01") : dzkAmtNew;
-                    discountPriceNew = dzkAmtNew.divide(new BigDecimal(oilLiters), 2, BigDecimal.ROUND_HALF_UP);
-                    dzkDiscountAmtNew = new BigDecimal(receivableAmt).subtract(dzkAmtNew);
-                    couponReckonAmt.setDzkDiscountAmt(dzkDiscountAmtNew.toString());
-                    couponReckonAmt.setDiscountPrice(discountPriceNew.toString());
-                    couponReckonAmt.setDzkAmt(dzkAmtNew.toString());
+                if(p.getCardEnabledFlag().equals("1")){
+                    if(uc.getIsCardFlag().equals("1")){
+                        //与电子卡共享
+                        dzkAmtNew = new BigDecimal(dzkAmt).multiply(couponAmt).divide(new BigDecimal("100"));
+                        dzkAmtNew = dzkAmtNew.signum() == -1 ? new BigDecimal("0.01") : dzkAmtNew.setScale(2,BigDecimal.ROUND_HALF_UP);
+                        dzkDiscountAmtNew = new BigDecimal(receivableAmt).subtract(dzkAmtNew);
+                        couponReckonAmt.setDzkDiscountAmt(dzkDiscountAmtNew.toString());
+                        couponReckonAmt.setDzkAmt(dzkAmtNew.toString());
+                        if(!oilLiters.equals("0.00")){
+                            dzkDiscountPriceNew = dzkAmtNew.divide(new BigDecimal(oilLiters), 2 ,BigDecimal.ROUND_HALF_UP);
+                        }
+                        couponReckonAmt.setDzkDiscountPrice(dzkDiscountPriceNew.toString());
+                    }
                 }
-
                 break;
         }
         return couponReckonAmt;
@@ -1628,26 +1662,26 @@ public class PayOrderController {
 
 
     //获取客户所拥有的优惠券
-    public List<UserCoupon> getUserCoupon(String unionId, Integer stationId){
-        List<UserCoupon> userCouponsList = new ArrayList<>();
-        StationInfo stationInfo = new StationInfo();
-        stationInfo.setStationId(stationId);
-        StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
-        if(stationInfos !=null && stationInfos.getCouponEnabledFlag() !=null && stationInfos.getCouponEnabledFlag().equals("1")){
-            UserCoupon userCoupon = new UserCoupon();
-            userCoupon.setStationId(stationId);
-            if(stationInfos.getCouponFlag() !=null && stationInfos.getCouponFlag().equals("1")){
-                userCoupon.setStationId(stationInfos.getGroupId());
-            }
-            userCoupon.setUnionId(unionId);
-            userCoupon.setCouponIsUsed("0");
-            userCoupon.setExpireFlag("0");                  // SQL 条件判断 过期标志: 1 代表使用的优惠券已过期查询参数; 0 代表未过期有效的优惠券
-            userCoupon.setNoVerificationVerFlag("0");       //SQL 条件判断 查询没有异业券的参数标识: 0代表只有加油券 1代表只有异业券
-            userCoupon.setCurrentTime(new Date());
-            userCouponsList = couponService.selectUserCoupons(userCoupon);
-        }
-        return userCouponsList;
-    }
+//    public List<UserCoupon> getUserCoupon(String unionId, Integer stationId){
+//        List<UserCoupon> userCouponsList = new ArrayList<>();
+//        StationInfo stationInfo = new StationInfo();
+//        stationInfo.setStationId(stationId);
+//        StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
+//        if(stationInfos !=null && stationInfos.getCouponEnabledFlag() !=null && stationInfos.getCouponEnabledFlag().equals("1")){
+//            UserCoupon userCoupon = new UserCoupon();
+//            userCoupon.setStationId(stationId);
+//            if(stationInfos.getCouponFlag() !=null && stationInfos.getCouponFlag().equals("1")){
+//                userCoupon.setStationId(stationInfos.getGroupId());
+//            }
+//            userCoupon.setUnionId(unionId);
+//            userCoupon.setCouponIsUsed("0");
+//            userCoupon.setExpireFlag("0");                  // SQL 条件判断 过期标志: 1 代表使用的优惠券已过期查询参数; 0 代表未过期有效的优惠券
+//            userCoupon.setNoVerificationVerFlag("0");       //SQL 条件判断 查询没有异业券的参数标识: 0代表只有加油券 1代表只有异业券
+//            userCoupon.setCurrentTime(new Date());
+//            userCouponsList = couponService.selectUserCoupons(userCoupon);
+//        }
+//        return userCouponsList;
+//    }
 
 
     //获取支付后
@@ -1754,142 +1788,142 @@ public class PayOrderController {
         return boo;
     }
 
-    /***
-     * 计算使用优惠券金额
-     * @param ordNo
-     * @param id
-     * @return
-     */
-    @RequestMapping(value = "/calculateCouponDiscount", method = RequestMethod.GET)
-    @ResponseBody
-    public String calculateCouponDiscount(@RequestParam String ordNo, @RequestParam Integer id){
-        Gson gson =new Gson();
-        ResultData resultData =null;
-        PayOrder payOrder = new PayOrder();
-        payOrder.setOrderNo(ordNo);
-        Map<String, Object> infoMap = payOrderService.getOrderInfoAndUserInfoByOrderNo(payOrder);
-        StationInfo stationInfo = new StationInfo();
-        stationInfo.setStationId(Integer.valueOf(infoMap.get("stationId").toString()));
-        StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
-        if(stationInfos !=null && stationInfos.getCouponEnabledFlag().equals("1")){
-            Map<String ,Object> resultMap = new HashMap<>();                //返回结果集
-            if(infoMap !=null){
-                UserCoupon u = new UserCoupon();
-                if(id !=null){
-                    u.setId(id);
-                    UserCoupon couponInfo = couponService.selectUserCouponInfo(u);
-                    if(couponInfo !=null){
-                        String oilName = infoMap.get("oilName").toString();
-                        String oilNames = couponInfo.getOilName();
-                        //判断该油品是否能用该张张优惠券
-                        boolean contains = oilNames.contains(oilName);
-                        if(contains){
-                            String status = couponInfo.getStatus();
-                            //该优惠券是否有效
-                            if(status !=null && status.equals("1")) {
-                                PayOrderResultInfo p = new PayOrderResultInfo();
-                                BigDecimal receivableAmt = new BigDecimal(infoMap.get("receivableAmt").toString());  //应收金额
-                                BigDecimal couponThresholdAmt = couponInfo.getCouponThresholdAmt();                  //门槛金额
-                                p.setReceivableAmt(receivableAmt.toString());
-                                //判断该订单是否满足该优惠券门槛金额要求
-                                if(!(receivableAmt.compareTo(couponThresholdAmt) == -1)){
-                                    String isMarketFlag = couponInfo.getIsMarketFlag();
-                                    String isCardFlag = couponInfo.getIsCardFlag();
-                                    String isGradeFlag = couponInfo.getIsGradeFlag();
-                                    BigDecimal amt = new BigDecimal(infoMap.get("amt").toString());                      //实收金额
-                                    p.setAmt(amt.toString());
-                                    BigDecimal dzkAmt = new BigDecimal(infoMap.get("dzkAmt").toString());                //电子卡金额
-                                    p.setDzkAmt(dzkAmt.toString());
-                                    BigDecimal oilPrice = new BigDecimal(infoMap.get("oilPirce").toString());            //油品价格
-                                    BigDecimal orderLiters = new BigDecimal(infoMap.get("orderLiters").toString());      //电子卡金额
-                                    p.setOilLiters(orderLiters.toString());
-                                    BigDecimal couponAmt = couponInfo.getCouponAmt();                                       //优惠券金额:金额 比例值
-                                    String couponType = couponInfo.getCouponType();                                         //优惠劵类型 1现金劵,2折扣券,3兑换券
-                                    String cardEnabledFlag = stationInfos.getCardEnabledFlag();                             //是否开启电子卡
-                                    //计算优惠券优惠后金额
-                                    CalCouponAmtInfo cal = new CalCouponAmtInfo();
-                                    cal.setReceivableAmt(receivableAmt);
-                                    cal.setAmt(amt);
-                                    cal.setCardEnabledFlag(cardEnabledFlag);
-                                    cal.setCouponAmt(couponAmt);
-                                    cal.setCouponType(couponType);
-                                    cal.setDzkAmt(dzkAmt);
-                                    cal.setIsCardFlag(isCardFlag);
-                                    cal.setIsGradeFlag(isGradeFlag);
-                                    cal.setIsMarketFlag(isMarketFlag);
-                                    //使用优惠券时返回结果
-                                    PayOrderResultInfo resultCalCoupon = calCouponAmt(cal);
-                                    //查询优惠券使用时间
-                                    String availableControl = couponInfo.getAvailableControl();         //时间类型选择
-                                    switch (availableControl){
-                                        case "0":
-                                            p.setAmt(resultCalCoupon.getAmt());
-                                            p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
-                                            p.setDzkAmt(resultCalCoupon.getDzkAmt());
-                                            p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
-                                            break;
-                                        case "1":
-                                            boolean activityDay = this.isActivityDay("1", couponInfo.getCycleDays());
-                                            if(activityDay){
-                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
-                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
-                                                p.setAmt(resultCalCoupon.getAmt());
-                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
-                                            }
-                                            break;
-                                        case "2":
-                                            boolean activityDay2 = this.isActivityDay("2", couponInfo.getCycleDays());
-                                            if(activityDay2){
-                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
-                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
-                                                p.setAmt(resultCalCoupon.getAmt());
-                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
-                                            }
-                                            break;
-                                        case "3":
-                                            boolean activityDay3 = this.isActivityDay("3", couponInfo.getCycleDays());
-                                            if(activityDay3){
-                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
-                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
-                                                p.setAmt(resultCalCoupon.getAmt());
-                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
-                                            }
-                                    }
-                                    BigDecimal discountPrice = oilPrice;
-                                    if(!orderLiters.toString().equals("0.00")){
-                                        //.setScale(2, BigDecimal.ROUND_HALF_UP)
-                                        discountPrice = (new BigDecimal(p.getAmt()).divide(orderLiters, 2, BigDecimal.ROUND_HALF_UP));
-                                    }
-                                    resultMap.put("discountPrice", discountPrice.toString());
-                                    resultMap.put("discountAmt", p.getDiscountAmt());               //优惠金额
-                                    resultMap.put("amt", p.getAmt());                               //实收价格
-                                    resultMap.put("receivableAmt", p.getReceivableAmt());           //应收价格
-                                    resultMap.put("oilLiters", p.getOilLiters());
-                                    resultMap.put("amt_dzk", p.getDzkAmt());
-                                    resultMap.put("discountAmt_dzk", p.getDzkDiscountAmt());          //电子卡优惠金额
-                                    resultMap.put("ordNo", ordNo);
-                                    resultData = ResultData.success(resultMap);
-                                }else{
-                                    resultData = ResultData.error(CodeMsg.COUPON_NOT_COUPONTHRESHOLDAMT);
-                                }
-                            }else {
-                                resultData = ResultData.error(CodeMsg.COUPON_LOSE_EFFECTIVE);
-                            }
-                        }else {
-                            resultData = ResultData.error(CodeMsg.COUPON_NOT_CONTATINS_OILNAME);
-                        }
-                    }else {
-                        resultData = ResultData.error(CodeMsg.NO_COUPON);
-                    }
-                }
-            }else {
-                resultData = ResultData.error(CodeMsg.NO_ORDER);
-            }
-        }else {
-            resultData = ResultData.error(CodeMsg.NO_ENABLE_COUPON);
-        }
-        return gson.toJson(resultData);
-    }
+//    /***
+//     * 计算使用优惠券金额
+//     * @param ordNo
+//     * @param id
+//     * @return
+//     */
+//    @RequestMapping(value = "/calculateCouponDiscount", method = RequestMethod.GET)
+//    @ResponseBody
+//    public String calculateCouponDiscount(@RequestParam String ordNo, @RequestParam Integer id){
+//        Gson gson =new Gson();
+//        ResultData resultData =null;
+//        PayOrder payOrder = new PayOrder();
+//        payOrder.setOrderNo(ordNo);
+//        Map<String, Object> infoMap = payOrderService.getOrderInfoAndUserInfoByOrderNo(payOrder);
+//        StationInfo stationInfo = new StationInfo();
+//        stationInfo.setStationId(Integer.valueOf(infoMap.get("stationId").toString()));
+//        StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
+//        if(stationInfos !=null && stationInfos.getCouponEnabledFlag().equals("1")){
+//            Map<String ,Object> resultMap = new HashMap<>();                //返回结果集
+//            if(infoMap !=null){
+//                UserCoupon u = new UserCoupon();
+//                if(id !=null){
+//                    u.setId(id);
+//                    UserCoupon couponInfo = couponService.selectUserCouponInfo(u);
+//                    if(couponInfo !=null){
+//                        String oilName = infoMap.get("oilName").toString();
+//                        String oilNames = couponInfo.getOilName();
+//                        //判断该油品是否能用该张张优惠券
+//                        boolean contains = oilNames.contains(oilName);
+//                        if(contains){
+//                            String status = couponInfo.getStatus();
+//                            //该优惠券是否有效
+//                            if(status !=null && status.equals("1")) {
+//                                PayOrderResultInfo p = new PayOrderResultInfo();
+//                                BigDecimal receivableAmt = new BigDecimal(infoMap.get("receivableAmt").toString());  //应收金额
+//                                BigDecimal couponThresholdAmt = couponInfo.getCouponThresholdAmt();                  //门槛金额
+//                                p.setReceivableAmt(receivableAmt.toString());
+//                                //判断该订单是否满足该优惠券门槛金额要求
+//                                if(!(receivableAmt.compareTo(couponThresholdAmt) == -1)){
+//                                    String isMarketFlag = couponInfo.getIsMarketFlag();
+//                                    String isCardFlag = couponInfo.getIsCardFlag();
+//                                    String isGradeFlag = couponInfo.getIsGradeFlag();
+//                                    BigDecimal amt = new BigDecimal(infoMap.get("amt").toString());                      //实收金额
+//                                    p.setAmt(amt.toString());
+//                                    BigDecimal dzkAmt = new BigDecimal(infoMap.get("dzkAmt").toString());                //电子卡金额
+//                                    p.setDzkAmt(dzkAmt.toString());
+//                                    BigDecimal oilPrice = new BigDecimal(infoMap.get("oilPirce").toString());            //油品价格
+//                                    BigDecimal orderLiters = new BigDecimal(infoMap.get("orderLiters").toString());      //电子卡金额
+//                                    p.setOilLiters(orderLiters.toString());
+//                                    BigDecimal couponAmt = couponInfo.getCouponAmt();                                       //优惠券金额:金额 比例值
+//                                    String couponType = couponInfo.getCouponType();                                         //优惠劵类型 1现金劵,2折扣券,3兑换券
+//                                    String cardEnabledFlag = stationInfos.getCardEnabledFlag();                             //是否开启电子卡
+//                                    //计算优惠券优惠后金额
+//                                    CalCouponAmtInfo cal = new CalCouponAmtInfo();
+//                                    cal.setReceivableAmt(receivableAmt);
+//                                    cal.setAmt(amt);
+//                                    cal.setCardEnabledFlag(cardEnabledFlag);
+//                                    cal.setCouponAmt(couponAmt);
+//                                    cal.setCouponType(couponType);
+//                                    cal.setDzkAmt(dzkAmt);
+//                                    cal.setIsCardFlag(isCardFlag);
+//                                    cal.setIsGradeFlag(isGradeFlag);
+//                                    cal.setIsMarketFlag(isMarketFlag);
+//                                    //使用优惠券时返回结果
+//                                    PayOrderResultInfo resultCalCoupon = calCouponAmt(cal);
+//                                    //查询优惠券使用时间
+//                                    String availableControl = couponInfo.getAvailableControl();         //时间类型选择
+//                                    switch (availableControl){
+//                                        case "0":
+//                                            p.setAmt(resultCalCoupon.getAmt());
+//                                            p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
+//                                            p.setDzkAmt(resultCalCoupon.getDzkAmt());
+//                                            p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
+//                                            break;
+//                                        case "1":
+//                                            boolean activityDay = this.isActivityDay("1", couponInfo.getCycleDays());
+//                                            if(activityDay){
+//                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
+//                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
+//                                                p.setAmt(resultCalCoupon.getAmt());
+//                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
+//                                            }
+//                                            break;
+//                                        case "2":
+//                                            boolean activityDay2 = this.isActivityDay("2", couponInfo.getCycleDays());
+//                                            if(activityDay2){
+//                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
+//                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
+//                                                p.setAmt(resultCalCoupon.getAmt());
+//                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
+//                                            }
+//                                            break;
+//                                        case "3":
+//                                            boolean activityDay3 = this.isActivityDay("3", couponInfo.getCycleDays());
+//                                            if(activityDay3){
+//                                                p.setDzkAmt(resultCalCoupon.getDzkAmt());
+//                                                p.setDzkDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getDzkAmt())).toString());
+//                                                p.setAmt(resultCalCoupon.getAmt());
+//                                                p.setDiscountAmt(receivableAmt.subtract(new BigDecimal(resultCalCoupon.getAmt())).toString());
+//                                            }
+//                                    }
+//                                    BigDecimal discountPrice = oilPrice;
+//                                    if(!orderLiters.toString().equals("0.00")){
+//                                        //.setScale(2, BigDecimal.ROUND_HALF_UP)
+//                                        discountPrice = (new BigDecimal(p.getAmt()).divide(orderLiters, 2, BigDecimal.ROUND_HALF_UP));
+//                                    }
+//                                    resultMap.put("discountPrice", discountPrice.toString());
+//                                    resultMap.put("discountAmt", p.getDiscountAmt());               //优惠金额
+//                                    resultMap.put("amt", p.getAmt());                               //实收价格
+//                                    resultMap.put("receivableAmt", p.getReceivableAmt());           //应收价格
+//                                    resultMap.put("oilLiters", p.getOilLiters());
+//                                    resultMap.put("amt_dzk", p.getDzkAmt());
+//                                    resultMap.put("discountAmt_dzk", p.getDzkDiscountAmt());          //电子卡优惠金额
+//                                    resultMap.put("ordNo", ordNo);
+//                                    resultData = ResultData.success(resultMap);
+//                                }else{
+//                                    resultData = ResultData.error(CodeMsg.COUPON_NOT_COUPONTHRESHOLDAMT);
+//                                }
+//                            }else {
+//                                resultData = ResultData.error(CodeMsg.COUPON_LOSE_EFFECTIVE);
+//                            }
+//                        }else {
+//                            resultData = ResultData.error(CodeMsg.COUPON_NOT_CONTATINS_OILNAME);
+//                        }
+//                    }else {
+//                        resultData = ResultData.error(CodeMsg.NO_COUPON);
+//                    }
+//                }
+//            }else {
+//                resultData = ResultData.error(CodeMsg.NO_ORDER);
+//            }
+//        }else {
+//            resultData = ResultData.error(CodeMsg.NO_ENABLE_COUPON);
+//        }
+//        return gson.toJson(resultData);
+//    }
 
 
 

+ 9 - 0
YijiaRestful/src/main/java/com/platform/yijia/param/request/PayInfoRequest.java

@@ -3,6 +3,7 @@ package com.platform.yijia.param.request;
 public class PayInfoRequest {
 
     //订单信息
+    private Integer id;         //优惠券ID
     private String openId;//openId
     private String oilGun;//油枪
     private String oilName;//油品
@@ -17,6 +18,14 @@ public class PayInfoRequest {
     private String payType;
     private String payChannelType;      //支付通道类型
 
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
     public String getPayChannelType() {
         return payChannelType;
     }

+ 1 - 1
YijiaRestful/src/main/java/com/platform/yijia/pojo/Coupon.java

@@ -12,7 +12,7 @@ import java.util.List;
  */
 @Data
 public class Coupon {
-    private Integer id;                     //优惠券ID;
+    private Integer couponId;               //优惠券模板ID;
     private Integer stationId;              //油站ID
     private String couponName;              //优惠券名称;
     private String couponType;              //优惠券类型: 1现金劵,2折扣券,3兑换券;

+ 8 - 7
YijiaRestful/src/main/java/com/platform/yijia/pojo/CouponReckonAmt.java

@@ -5,11 +5,12 @@ import lombok.Data;
 @Data
 public class CouponReckonAmt {
 
-    private String oilLiters;       //加油金额
-    private String oilPrice;        //原单价
-    private String discountPrice;   //优惠单价
-    private String amt;             //实收金额
-    private String discountAmt;     //优惠金额
-    private String dzkAmt;          //电子卡金额
-    private String dzkDiscountAmt;     //优惠金额//当前时间优惠券是否可用
+    private String oilLiters;           //加油金额
+    private String oilPrice;            //原单价
+    private String discountPrice;       //优惠单价
+    private String amt;                 //实收金额
+    private String discountAmt;         //优惠金额
+    private String dzkDiscountPrice;    //电子卡优惠单价
+    private String dzkAmt;              //电子卡金额
+    private String dzkDiscountAmt;      //优惠金额//当前时间优惠券是否可用
 }

+ 1 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/PayOrderResultInfo.java

@@ -23,6 +23,7 @@ public class PayOrderResultInfo {
     private String discountAmt;     //优惠金额
     private String dzkAmt;          //电子卡金额
     private String dzkDiscountAmt;     //优惠金额
+    private String dzkDiscountPrice;    //电子卡优惠单价
 
     private String cardEnabledFlag;    //是否开电子卡功能
 

+ 7 - 5
YijiaRestful/src/main/resources/mapper/CouponMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.platform.yijia.dao.CouponMapper">
     <!--优惠券-->
   <resultMap id="BaseResultMap"                type="com.platform.yijia.pojo.Coupon">
-    <id     column="id"                       jdbcType="INTEGER"   property="id" />
+    <id     column="id"                       jdbcType="INTEGER"   property="couponId" />
     <result column="station_id"               jdbcType="INTEGER"   property="stationId" />
     <result column="coupon_name"              jdbcType="VARCHAR"   property="couponName" />
     <result column="coupon_type"              jdbcType="VARCHAR"   property="couponType" />
@@ -161,13 +161,13 @@
       </sql>
 
     <!--查询优惠券模板信息-->
-    <select id="selectCouponTemplateInfo" parameterType="com.platform.yijia.pojo.Coupon" resultMap="CouponIssueBaseResultMap">
+    <select id="selectCouponTemplateInfo" parameterType="com.platform.yijia.pojo.Coupon" resultMap="BaseResultMap">
         SELECT
             <include refid="Coupon_Base_Column_List"/>
         FROM     coupon_info     AS  T2
         <where>
-            <if test="id !=null">
-                T2.id = #{id}
+            <if test="couponId !=null">
+                T2.id = #{couponId}
             </if>
         </where>
     </select>
@@ -212,7 +212,6 @@
     <!--获取油站所分发的加油券-->
     <select id="selectStaGrantCouponList" parameterType="com.platform.yijia.pojo.Coupon" resultMap="BaseResultMap">
         SELECT
-            T1.id,
             T2.id                                AS coupon_issue_id,
             T2.issue_name,
             T2.issue_type,
@@ -476,6 +475,9 @@
       <if test="unionId !=null and unionId !=''">
        AND T1.union_id = #{unionId}
       </if>
+        <if test="oilName !=null and oilName !=''">
+            AND FIND_IN_SET(#{oilName}, T2.oil_name)
+        </if>
       <choose>
           <when test="expireFlag !=null and expireFlag == '0'.toString()">
               AND T1.coupon_effective_time &gt;= #{currentTime}