jk-GitHub-coder 4 år sedan
förälder
incheckning
7dae130709

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

@@ -182,7 +182,7 @@ public class ElectronicMembershipCardController {
             //将业务参数存放在 JSON 对象中
             JSONObject reqData = new JSONObject();
             Map<String, String> resultMap = stationService.getStationAppIdAndAppSecret(stationId);
-            if(resultMap !=null && resultMap.containsKey("appId") && resultMap.containsKey("mno")){
+            if(resultMap !=null && resultMap.containsKey("gzhAppId") && resultMap.containsKey("mno")){
                 logger.info("==============================电子会员卡(储蓄卡)充值功能调用随行付接口================================");
                 try {
                     if(userType.equals("1")){

+ 239 - 1
YijiaRestful/src/main/java/com/platform/yijia/controller/PayOrderController.java

@@ -4,8 +4,11 @@ import com.google.gson.Gson;
 import com.platform.yijia.param.request.PayOrderRequest;
 import com.platform.yijia.pojo.AppUserInfo;
 import com.platform.yijia.pojo.PayOrder;
+import com.platform.yijia.pojo.StationOilPrice;
 import com.platform.yijia.service.AppUserInfoService;
+import com.platform.yijia.service.CustomerGradeServices;
 import com.platform.yijia.service.PayOrderService;
+import com.platform.yijia.service.StationService;
 import com.platform.yijia.utils.CodeMsg;
 import com.platform.yijia.utils.ResultData;
 import org.apache.commons.lang3.StringUtils;
@@ -14,7 +17,11 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
+import javax.naming.ldap.HasControls;
+import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Controller
 @RequestMapping("/demo")
@@ -24,6 +31,10 @@ public class PayOrderController {
     private PayOrderService payOrderService;
     @Resource
     private AppUserInfoService appUserInfoService;
+    @Resource
+    private StationService stationService;
+    @Resource
+    private CustomerGradeServices customerGradeServices;
 
     //一键支付,生成订单
     @RequestMapping(value = "/AddPayOrderInfo", consumes = "application/json", method = RequestMethod.POST)
@@ -59,13 +70,240 @@ public class PayOrderController {
             }else {
                 resultData=ResultData.success(ordNo);
             }
-
+            //接口修订
+//            Map<String, Object> stringObjectMap = payOrderService.AddPayOrderInfoNew(payOrderRequest, payOrder);
+//            resultData = ResultData.success(stringObjectMap);
         }else{
             //登录人验证失败
             resultData=ResultData.error(CodeMsg.USER_NOT_EXSIST);
         }
         return gson.toJson(resultData);
     }
+
+    /***
+     * 计算订单金额
+     * @return
+     */
+    @RequestMapping(value = "/calculateAmt", consumes = "application/json", method = RequestMethod.POST)
+    @ResponseBody
+    public String calculateAmt(@RequestBody PayOrderRequest payOrderRequest){
+        Gson gson =new Gson();
+        ResultData resultData =null;
+        if(payOrderRequest.getReceivableAmt() !=null){  //应收金额
+            Double receivableAmt = payOrderRequest.getReceivableAmt();  //应收金额 用户输入的金额
+            Integer stationId = payOrderRequest.getStationId();         //油站ID
+            String oilGun = payOrderRequest.getOilGun();                //油枪号
+            String oilName = payOrderRequest.getOilName();          //油品名称
+            String openId = payOrderRequest.getOpenId();        //用户的openId
+            String mobilePhone = payOrderRequest.getCustomerPhone();        //客户手机号
+
+            //获取油品价格
+            StationOilPrice stationOilPrice = new StationOilPrice();
+            stationOilPrice.setStationId(stationId);
+            stationOilPrice.setOilName(oilName);
+            StationOilPrice oilPriceInfo = stationService.getStationOilPrice(stationOilPrice);
+            String oilPrice = oilPriceInfo.getOilPrice();
+            BigDecimal oilLiters = null;
+            BigDecimal discountAmt =null;
+            BigDecimal discountPrice = null;
+            BigDecimal amt = null;
+
+            Map<String ,Object> resultMap = new HashMap<>();
+            resultMap.put("oilPrice", oilPrice);        //油品价格
+            resultMap.put("receivableAmt", receivableAmt);        //应收价格
+
+            //该油站的优惠方式
+            String stationDiscountWay = stationService.getStationDiscountWay(stationId.toString());
+            Map<String ,Object> params = new HashMap<String, Object>();
+            params.put("stationId", stationId);
+            params.put("oilName", oilName);
+            BigDecimal receivableAmt_b = new BigDecimal(receivableAmt); //传入的应收金额
+            switch (stationDiscountWay){
+                case "1":       //1.等级直降
+                    //查询等级直降的优惠方式
+                    params.put("mobilePhone", mobilePhone);
+                    params.put("minaOpenid", openId);
+                    //查询客户等级信息
+                    List<Map<String, Object>> customerGradeInfo = customerGradeServices.getCustomerGradeInfo(params);
+                    if(customerGradeInfo != null && customerGradeInfo.size() >0){   //已存在客户等级信息
+                        //使用客户已存在的等级计算优惠
+                        oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);
+                        discountAmt = oilLiters.multiply(new BigDecimal(customerGradeInfo.get(0).get("gasoilDiscountLitre").toString()));
+                        discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                        amt = receivableAmt_b.subtract(discountAmt);
+                        discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                        resultMap.put("discountAmt", discountAmt.doubleValue());
+                        resultMap.put("amt", amt.doubleValue());
+                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                        resultMap.put("discountPrice", discountPrice.doubleValue());
+                    }else {
+                        //不存在客户等级信息时,查询油站的客户等级直降优惠(查询结果根据会员成长值条件做升序查询)
+                        List<Map> customerGradeList = customerGradeServices.getCustomerGradeList(params);
+                        //如果存在
+                        if(customerGradeList !=null && customerGradeList.size() >0){
+                            //用户第一次购买 取等级最低初始会员的优惠条件计算
+                            oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                            discountAmt = oilLiters.multiply(new BigDecimal(customerGradeList.get(0).get("gasoilDiscountLitre").toString()));
+                            discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                            amt = receivableAmt_b.subtract(discountAmt);
+                            discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("discountAmt", discountAmt.doubleValue());
+                            resultMap.put("amt", amt.doubleValue());
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", discountPrice.doubleValue());
+                        }else {
+                            //不存在
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                    }
+                    break;
+                case "2":       //2.满减
+                    params.put("discountPlanType", "1");
+                    //营销方案
+                    List<Map> customerMarkertPlanList_1 = customerGradeServices.getCustomerMarkertPlanList(params);
+                    //有优惠规则
+                    if(customerMarkertPlanList_1 !=null && customerMarkertPlanList_1.size() >0){
+                        boolean flag = true;
+                        for (Map m : customerMarkertPlanList_1){
+                            //如果当前应收金额大于条件金额
+                            BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                            if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());   //每满多少优惠多少的金额
+                                discountAmt = receivableAmt_b.divide(discountAmt_b, 2, BigDecimal.ROUND_HALF_UP).multiply(gasoilDiscountAmt_b);  //优惠金额
+                                discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                amt = receivableAmt_b.subtract(discountAmt);   //实收金额
+                                oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                discountPrice = amt.divide(oilLiters);        //优惠价格
+                                resultMap.put("discountAmt", discountAmt.doubleValue());
+                                resultMap.put("amt", amt.doubleValue());
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", discountPrice.doubleValue());
+                                flag = false;
+                                break;
+                            }
+                        }
+                        if(flag){
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                    }else {
+                        //没有优惠规则
+                        resultMap.put("discountAmt", 0);
+                        resultMap.put("amt", receivableAmt.doubleValue());
+                        oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                        resultMap.put("discountPrice", oilPrice);
+                    }
+                    break;
+                case "3":       //3.立减
+                    params.put("discountPlanType", "2");
+                    //营销方案
+                    List<Map> customerMarkertPlanList_2 = customerGradeServices.getCustomerMarkertPlanList(params);
+                    if(customerMarkertPlanList_2 !=null && customerMarkertPlanList_2.size() >0){
+                        boolean flag = true;
+                        for (Map m : customerMarkertPlanList_2){
+                            //如果当前应收金额大于条件金额
+                            BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                            if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());   //每满多少优惠多少的金额
+                                discountAmt = gasoilDiscountAmt_b;  //优惠金额
+                                amt = receivableAmt_b.subtract(gasoilDiscountAmt_b);   //实收金额
+                                oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                discountPrice = amt.divide(oilLiters);        //优惠价格
+                                resultMap.put("discountAmt", discountAmt.doubleValue());
+                                resultMap.put("amt", amt.doubleValue());
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", discountPrice.doubleValue());
+                                flag = false;
+                                break;
+                            }
+                        }
+                        if(flag){   //用户加油金额不符合优惠条件
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                    }else {
+                        //没有优惠规则
+                        resultMap.put("discountAmt", 0);
+                        resultMap.put("amt", receivableAmt.doubleValue());
+                        oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                        resultMap.put("discountPrice", oilPrice);
+                    }
+                    break;
+                case "4":       //4.独立直降
+                    params.put("discountPlanType", "3");
+                    //营销方案
+                    List<Map> customerMarkertPlanList_3 = customerGradeServices.getCustomerMarkertPlanList(params);
+                    if(customerMarkertPlanList_3 !=null && customerMarkertPlanList_3.size() >0){
+                        boolean flag= true;
+                        for(Map m : customerMarkertPlanList_3){
+                            BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                            BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());
+                            oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                            if(m.get("discountTerm").toString().equals("1")){   //按升数优惠
+                                if(oilLiters.compareTo(discountAmt_b) ==1 || oilLiters.compareTo(discountAmt_b) ==0){
+                                    //计算
+                                    discountAmt = oilLiters.multiply(gasoilDiscountAmt_b);
+                                    discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                    amt = receivableAmt_b.subtract(discountAmt);
+                                    discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);        //优惠价格
+                                    resultMap.put("discountAmt", discountAmt.doubleValue());
+                                    resultMap.put("amt", amt.doubleValue());
+                                    resultMap.put("oilLiters", oilLiters.doubleValue());
+                                    resultMap.put("discountPrice", discountPrice.doubleValue());
+                                    flag =false;
+                                    break;
+                                }
+                            }else if(m.get("discountTerm").toString().equals("2")){     //按金额优惠
+                                if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                    discountAmt = oilLiters.multiply(gasoilDiscountAmt_b);
+                                    discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                    amt = receivableAmt_b.subtract(discountAmt);
+                                    discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);        //优惠价格
+                                    resultMap.put("discountAmt", discountAmt.doubleValue());
+                                    resultMap.put("amt", amt.doubleValue());
+                                    resultMap.put("oilLiters", oilLiters.doubleValue());
+                                    resultMap.put("discountPrice", discountPrice.doubleValue());
+                                    flag =false;
+                                    break;
+                                }
+                            }
+                        }
+                        if(flag){
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                    }else {
+                        //没有优惠规则
+                        resultMap.put("discountAmt", 0);
+                        resultMap.put("amt", receivableAmt.doubleValue());
+                        oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                        resultMap.put("discountPrice", oilPrice);
+                    }
+                    break;
+            }
+            resultData = ResultData.success(resultMap);
+        }
+        return gson.toJson(resultData);
+    }
+
+
+
     /**
      * 根据订单号获取订单信息
      * produces="application/json;charset=UTF-8",consumes = "application/json",

+ 5 - 1
YijiaRestful/src/main/java/com/platform/yijia/dao/StationOilPriceMapper.java

@@ -6,6 +6,10 @@ import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
 public interface StationOilPriceMapper {
+
+    //查询油站油品价格
+    StationOilPrice getStationOilPrice(StationOilPrice stationOilPrice);
+
     /**
      * This method was generated by MyBatis Generator.
      * This method corresponds to the database table station_oil_price
@@ -93,4 +97,4 @@ public interface StationOilPriceMapper {
      * @mbg.generated
      */
     int updateByPrimaryKey(StationOilPrice record);
-}
+}

+ 3 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/PayOrderService.java

@@ -13,6 +13,9 @@ public interface PayOrderService {
     //订单信息数据落地
      String AddPayOrderInfo(PayOrderRequest payOrderRequest, PayOrder payOrder);
 
+     //订单信息数据落地
+     Map<String, Object> AddPayOrderInfoNew(PayOrderRequest payOrderRequest, PayOrder payOrder);
+
      //根据订单号查询订单信息
      List<PayOrder> getPayOrderList(String orderNo);
 

+ 4 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/StationService.java

@@ -4,6 +4,7 @@ import com.platform.yijia.param.request.StationRequest;
 import com.platform.yijia.param.response.StationInfoResponse;
 import com.platform.yijia.param.response.StationInfoVo;
 import com.platform.yijia.pojo.StationInfo;
+import com.platform.yijia.pojo.StationOilPrice;
 import com.platform.yijia.pojo.StationPic;
 
 import java.util.List;
@@ -37,4 +38,7 @@ public interface StationService {
 
     //获取小程序APPID和APPSECRET
     Map<String, String> getStationAppIdAndAppSecret(Integer stationId);
+
+    //查询油站油品价格
+    StationOilPrice getStationOilPrice(StationOilPrice stationOilPrice);
 }

+ 343 - 4
YijiaRestful/src/main/java/com/platform/yijia/service/impl/PayOrderServiceImpl.java

@@ -3,12 +3,10 @@ package com.platform.yijia.service.impl;
 import com.platform.yijia.dao.CustomerGradeMapper;
 import com.platform.yijia.dao.PayOrderMapper;
 import com.platform.yijia.param.request.PayOrderRequest;
-import com.platform.yijia.pojo.AppUserInfo;
-import com.platform.yijia.pojo.CustomerManage;
-import com.platform.yijia.pojo.PayOrder;
+import com.platform.yijia.pojo.*;
 
-import com.platform.yijia.pojo.PayOrderExample;
 import com.platform.yijia.service.AppUserInfoService;
+import com.platform.yijia.service.CustomerGradeServices;
 import com.platform.yijia.service.PayOrderService;
 import com.platform.yijia.service.StationService;
 import org.apache.commons.lang3.StringUtils;
@@ -33,6 +31,8 @@ public class PayOrderServiceImpl implements PayOrderService {
     private AppUserInfoService appUserInfoService;
     @Resource
     private StationService stationService;
+    @Resource
+    private CustomerGradeServices customerGradeServices;
 
     /*
      * 添加订单信息
@@ -113,6 +113,10 @@ public class PayOrderServiceImpl implements PayOrderService {
                 //实收金额 优惠金额
                 payOrder.setAmt(Double.valueOf(payOrderRequest.getAmt()));
                 payOrder.setDiscountAmt(payOrderRequest.getDiscountAmt());
+
+
+
+
                 String oilName = payOrderRequest.getOilName();
                 payOrder.setOilName(oilName);      //油品名称
                 //根据油品名称存储油品类型 1.柴油 2 汽油
@@ -170,6 +174,341 @@ public class PayOrderServiceImpl implements PayOrderService {
         return ordNo;
     }
 
+
+
+    /*
+     * 添加订单信息
+     * @param payOrderRequest
+     * @param payOrder
+     * @return
+     */
+    @Override
+    @Transactional
+    public Map<String, Object> AddPayOrderInfoNew(PayOrderRequest payOrderRequest, PayOrder payOrder) {
+        Map<String ,Object> resultMap = new HashMap<>();
+        //订单规则 时间+6位随机数
+        Random random = new Random();
+        String result="";
+        for(int i=0;i<6;i++){
+            result+=random.nextInt(10);
+        }
+        //System.out.println("随机生成6位数result :"+result);
+        String ordNo=System.nanoTime()+result;
+        payOrder.setOrderNo(ordNo);
+        payOrder.setDiscountCouponAmt(payOrderRequest.getDiscountCouponAmt());  //优惠劵金额
+        payOrder.setDiscountCoupon(payOrderRequest.getDiscountCoupon());        //优惠券
+        payOrder.setCarNo(payOrderRequest.getCarNo());  //车牌号、
+        payOrder.setCustomerGrade(payOrderRequest.getCustomerGrade());    //客户电话
+        payOrder.setMemberNo(payOrderRequest.getMemberNo());     //会员卡号
+        payOrder.setMemberAmt(payOrderRequest.getMemberAmt());    //会员支付金额
+        //payOrder.setPrintCount(payOrderRequest.getPrintCount());    //小票数量
+        payOrder.setScore(payOrderRequest.getScore());      //积分
+        payOrder.setStationId(payOrderRequest.getStationId());  //油站id
+        payOrder.setStatus("0");         //创建订单 未支付状态 0
+        if(StringUtils.isNotBlank(payOrderRequest.getUserType())&& payOrderRequest.getUserType().equals("1")){
+            payOrder.setPayWay("02");        //支付方式:02公众号,03小程序',
+            payOrder.setPayType("wx");      //支付类型
+        }else if(StringUtils.isNotBlank(payOrderRequest.getUserType())&& payOrderRequest.getUserType().equals("2")){
+            payOrder.setPayWay("03");
+            payOrder.setPayType("wx");      //支付类型
+        }
+        payOrder.setCreatedDate(new Date());                    //创建时间
+        payOrder.setOrderType(payOrderRequest.getOrderType());  //订单类型
+        payOrder.setOilGun(payOrderRequest.getOilGun());        //油枪号
+
+        //根据油站和油枪获取加油员和油品价格 油站名称
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("oliGunNo", payOrderRequest.getOilGun());
+        params.put("stationId", payOrderRequest.getStationId());
+        String oilPersonnel = "";
+        //使用list原因:一个枪号对应多个加油员场景
+        List<Map> mapResultList = payOrderMapper.selectPersonelName(params);
+        if(mapResultList != null && mapResultList.size() > 0){
+            for (Map per : mapResultList){
+                if(per.containsKey("personelName") && per.get("personelName").toString() !=null && per.get("personelName").toString() !=""){
+                    oilPersonnel += per.get("personelName").toString() +",";
+                }
+            }
+            if(oilPersonnel !=""){
+                payOrder.setOilPersonnel(oilPersonnel.substring(0, oilPersonnel.length()-1));   //加油员
+            }
+            if(mapResultList.get(0).containsKey("stationName") && mapResultList.get(0).get("stationName").toString() !="" && mapResultList.get(0).get("stationName").toString() !=null ){
+                payOrder.setStationName(mapResultList.get(0).get("stationName").toString());        //油站名称
+            }
+        }
+
+        //订单类型等于1时表示油品
+        if(payOrderRequest.getOrderType().equals("1")){
+            Double receivableAmt = payOrderRequest.getReceivableAmt();  //获取应收金额
+            payOrder.setReceivableAmt(receivableAmt);
+            if(receivableAmt != null){
+                Integer stationId = payOrderRequest.getStationId();         //油站ID
+                //String oilGun = payOrderRequest.getOilGun();                //油枪号
+                String oilName = payOrderRequest.getOilName();          //油品名称
+                String openId = payOrderRequest.getOpenId();        //用户的openId
+                String mobilePhone = payOrderRequest.getCustomerPhone();        //客户手机号
+
+                //获取油品价格
+                StationOilPrice stationOilPrice = new StationOilPrice();
+                stationOilPrice.setStationId(stationId);
+                stationOilPrice.setOilName(oilName);
+                StationOilPrice oilPriceInfo = stationService.getStationOilPrice(stationOilPrice);
+                String oilPrice = oilPriceInfo.getOilPrice();
+                BigDecimal oilLiters = null;
+                BigDecimal discountAmt =null;
+                BigDecimal discountPrice = null;
+                BigDecimal amt = null;
+
+                resultMap.put("oilPrice", oilPrice);        //油品价格
+                resultMap.put("receivableAmt", receivableAmt);        //应收价格
+
+                //该油站的优惠方式
+                String stationDiscountWay = stationService.getStationDiscountWay(stationId.toString());
+                //Map<String ,Object> params_1 = new HashMap<String, Object>();
+                params.put("stationId", stationId);
+                params.put("oilName", oilName);
+                BigDecimal receivableAmt_b = new BigDecimal(receivableAmt); //传入的应收金额
+                switch (stationDiscountWay){
+                    case "1":       //1.等级直降
+                        //查询等级直降的优惠方式
+                        params.put("mobilePhone", mobilePhone);
+                        params.put("minaOpenid", openId);
+                        //查询客户等级信息
+                        List<Map<String, Object>> customerGradeInfo = customerGradeServices.getCustomerGradeInfo(params);
+                        if(customerGradeInfo != null && customerGradeInfo.size() >0){   //已存在客户等级信息
+                            //使用客户已存在的等级计算优惠
+                            oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);
+                            discountAmt = oilLiters.multiply(new BigDecimal(customerGradeInfo.get(0).get("gasoilDiscountLitre").toString()));
+                            discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                            amt = receivableAmt_b.subtract(discountAmt);
+                            discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("discountAmt", discountAmt.doubleValue());
+                            resultMap.put("amt", amt.doubleValue());
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", discountPrice.doubleValue());
+                        }else {
+                            //不存在客户等级信息时,查询油站的客户等级直降优惠(查询结果根据会员成长值条件做升序查询)
+                            List<Map> customerGradeList = customerGradeServices.getCustomerGradeList(params);
+                            //如果存在
+                            if(customerGradeList !=null && customerGradeList.size() >0){
+                                //用户第一次购买 取等级最低初始会员的优惠条件计算
+                                oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                discountAmt = oilLiters.multiply(new BigDecimal(customerGradeList.get(0).get("gasoilDiscountLitre").toString()));
+                                discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                amt = receivableAmt_b.subtract(discountAmt);
+                                discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);
+                                resultMap.put("discountAmt", discountAmt.doubleValue());
+                                resultMap.put("amt", amt.doubleValue());
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", discountPrice.doubleValue());
+                            }else {
+                                //不存在
+                                resultMap.put("discountAmt", 0);
+                                resultMap.put("amt", receivableAmt.doubleValue());
+                                oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", oilPrice);
+                            }
+                        }
+                        break;
+                    case "2":       //2.满减
+                        params.put("discountPlanType", "1");
+                        //营销方案
+                        List<Map> customerMarkertPlanList_1 = customerGradeServices.getCustomerMarkertPlanList(params);
+                        //有优惠规则
+                        if(customerMarkertPlanList_1 !=null && customerMarkertPlanList_1.size() >0){
+                            boolean flag = true;
+                            for (Map m : customerMarkertPlanList_1){
+                                //如果当前应收金额大于条件金额
+                                BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                                if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                    BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());   //每满多少优惠多少的金额
+                                    discountAmt = receivableAmt_b.divide(discountAmt_b, 2, BigDecimal.ROUND_HALF_UP).multiply(gasoilDiscountAmt_b);  //优惠金额
+                                    discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                    amt = receivableAmt_b.subtract(discountAmt);   //实收金额
+                                    oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                    discountPrice = amt.divide(oilLiters);        //优惠价格
+                                    resultMap.put("discountAmt", discountAmt.doubleValue());
+                                    resultMap.put("amt", amt.doubleValue());
+                                    resultMap.put("oilLiters", oilLiters.doubleValue());
+                                    resultMap.put("discountPrice", discountPrice.doubleValue());
+                                    flag = false;
+                                    break;
+                                }
+                            }
+                            if(flag){
+                                resultMap.put("discountAmt", 0);
+                                resultMap.put("amt", receivableAmt.doubleValue());
+                                oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_HALF_UP);
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", oilPrice);
+                            }
+                        }else {
+                            //没有优惠规则
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                        break;
+                    case "3":       //3.立减
+                        params.put("discountPlanType", "2");
+                        //营销方案
+                        List<Map> customerMarkertPlanList_2 = customerGradeServices.getCustomerMarkertPlanList(params);
+                        if(customerMarkertPlanList_2 !=null && customerMarkertPlanList_2.size() >0){
+                            boolean flag = true;
+                            for (Map m : customerMarkertPlanList_2){
+                                //如果当前应收金额大于条件金额
+                                BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                                if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                    BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());   //每满多少优惠多少的金额
+                                    discountAmt = gasoilDiscountAmt_b;  //优惠金额
+                                    amt = receivableAmt_b.subtract(gasoilDiscountAmt_b);   //实收金额
+                                    oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                    discountPrice = amt.divide(oilLiters);        //优惠价格
+                                    resultMap.put("discountAmt", discountAmt.doubleValue());
+                                    resultMap.put("amt", amt.doubleValue());
+                                    resultMap.put("oilLiters", oilLiters.doubleValue());
+                                    resultMap.put("discountPrice", discountPrice.doubleValue());
+                                    flag = false;
+                                    break;
+                                }
+                            }
+                            if(flag){   //用户加油金额不符合优惠条件
+                                resultMap.put("discountAmt", 0);
+                                resultMap.put("amt", receivableAmt.doubleValue());
+                                oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", oilPrice);
+                            }
+                        }else {
+                            //没有优惠规则
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                        break;
+                    case "4":       //4.独立直降
+                        params.put("discountPlanType", "3");
+                        //营销方案
+                        List<Map> customerMarkertPlanList_3 = customerGradeServices.getCustomerMarkertPlanList(params);
+                        if(customerMarkertPlanList_3 !=null && customerMarkertPlanList_3.size() >0){
+                            boolean flag= true;
+                            for(Map m : customerMarkertPlanList_3){
+                                BigDecimal discountAmt_b = new BigDecimal(m.get("discountAmt").toString());   //条件金额
+                                BigDecimal gasoilDiscountAmt_b = new BigDecimal(m.get("gasoilDiscountAmt").toString());
+                                oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);   //加油升数
+                                if(m.get("discountTerm").toString().equals("1")){   //按升数优惠
+                                    if(oilLiters.compareTo(discountAmt_b) ==1 || oilLiters.compareTo(discountAmt_b) ==0){
+                                        //计算
+                                        discountAmt = oilLiters.multiply(gasoilDiscountAmt_b);
+                                        discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                        amt = receivableAmt_b.subtract(discountAmt);
+                                        discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);        //优惠价格
+                                        resultMap.put("discountAmt", discountAmt.doubleValue());
+                                        resultMap.put("amt", amt.doubleValue());
+                                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                                        resultMap.put("discountPrice", discountPrice.doubleValue());
+                                        flag =false;
+                                        break;
+                                    }
+                                }else if(m.get("discountTerm").toString().equals("2")){     //按金额优惠
+                                    if(receivableAmt_b.compareTo(discountAmt_b) ==1 || receivableAmt_b.compareTo(discountAmt_b) ==0){
+                                        discountAmt = oilLiters.multiply(gasoilDiscountAmt_b);
+                                        discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+                                        amt = receivableAmt_b.subtract(discountAmt);
+                                        discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP);        //优惠价格
+                                        resultMap.put("discountAmt", discountAmt.doubleValue());
+                                        resultMap.put("amt", amt.doubleValue());
+                                        resultMap.put("oilLiters", oilLiters.doubleValue());
+                                        resultMap.put("discountPrice", discountPrice.doubleValue());
+                                        flag =false;
+                                        break;
+                                    }
+                                }
+                            }
+                            if(flag){
+                                resultMap.put("discountAmt", 0);
+                                resultMap.put("amt", receivableAmt.doubleValue());
+                                oilLiters = new BigDecimal(receivableAmt).divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                                resultMap.put("oilLiters", oilLiters.doubleValue());
+                                resultMap.put("discountPrice", oilPrice);
+                            }
+                        }else {
+                            //没有优惠规则
+                            resultMap.put("discountAmt", 0);
+                            resultMap.put("amt", receivableAmt.doubleValue());
+                            oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice), 2, BigDecimal.ROUND_HALF_UP);
+                            resultMap.put("oilLiters", oilLiters.doubleValue());
+                            resultMap.put("discountPrice", oilPrice);
+                        }
+                        break;
+                }
+
+                payOrder.setOilPirce(oilPrice);
+                payOrder.setOrderLiters(resultMap.get("oilLiters").toString());
+                payOrder.setDiscountAmt(Double.valueOf(resultMap.get("discountAmt").toString()));
+                payOrder.setAmt(Double.valueOf(resultMap.get("amt").toString()));
+                payOrder.setWxAmt(Double.valueOf(resultMap.get("amt").toString()));    //微信支付金额
+                payOrder.setOilName(oilName);      //油品名称
+                //根据油品名称存储油品类型 1.柴油 2 汽油
+                switch (oilName){
+                    case "92#":
+                        payOrder.setOilType("2");
+                        break;
+                    case "95#":
+                        payOrder.setOilType("2");
+                        break;
+                    case "97#":
+                        payOrder.setOilType("2");
+                        break;
+                    case "0#":
+                        payOrder.setOilType("1");
+                        break;
+                    case "-10#":
+                        payOrder.setOilType("1");
+                        break;
+                    case "-20#":
+                        payOrder.setOilType("1");
+                        break;
+                }
+                //数据落地
+                payOrderMapper.insertSelective(payOrder);
+                //根据订单号查询出订单
+                PayOrderExample example=new PayOrderExample();
+                example.or().andOrderNoEqualTo(ordNo);
+                //根据订单号查询返回列表,最好是返回对象
+                List<PayOrder> payOrderList= payOrderMapper.selectByExample(example);
+                //返回订单号
+                ordNo= payOrderList.get(0).getOrderNo();
+                resultMap.put("ordNo", ordNo);
+            }
+        }else if(payOrderRequest.getOrderType().equals("2")){       //订单类型等于2时表示非油品
+            String oilName = payOrderRequest.getOilName();
+            payOrder.setOilName(oilName);      //非油品名称
+            Map<String, String> m = stationService.getStationAppIdAndAppSecret(payOrderRequest.getStationId());
+            if(m.containsKey("stationName") && m.get("stationName") !=null){
+                payOrder.setStationName(m.get("stationName"));
+            }
+            payOrder.setReceivableAmt(payOrderRequest.getReceivableAmt());  //非油品应收金额
+            payOrder.setAmt(Double.valueOf(payOrderRequest.getAmt()));  //非油品金额
+            //数据落地
+            payOrderMapper.insertSelective(payOrder);
+            //根据订单号查询出订单
+            PayOrderExample example=new PayOrderExample();
+            example.or().andOrderNoEqualTo(ordNo);
+            //根据订单号查询返回列表,最好是返回对象
+            List<PayOrder> payOrderList= payOrderMapper.selectByExample(example);
+            //返回订单号
+            ordNo= payOrderList.get(0).getOrderNo();
+            resultMap.put("ordNo", ordNo);
+        }
+        return resultMap;
+    }
+
     /*
      * 计算加油升数
      * @param str1

+ 10 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/StationServiceImpl.java

@@ -1,10 +1,12 @@
 package com.platform.yijia.service.impl;
 import com.platform.yijia.dao.StationInfoMapper;
+import com.platform.yijia.dao.StationOilPriceMapper;
 import com.platform.yijia.param.request.StationRequest;
 import com.platform.yijia.param.response.StationInfoResponse;
 import com.platform.yijia.param.response.StationInfoVo;
 import com.platform.yijia.pojo.StationInfo;
 import com.platform.yijia.pojo.StationInfoExample;
+import com.platform.yijia.pojo.StationOilPrice;
 import com.platform.yijia.pojo.StationPic;
 import com.platform.yijia.service.StationService;
 import com.platform.yijia.utils.MapHelper;
@@ -23,6 +25,14 @@ public class StationServiceImpl implements StationService {
     @Resource
     private StationInfoMapper stationInfoMapper;
 
+    @Resource
+    private StationOilPriceMapper stationOilPriceMapper;
+
+    //查询油站油品价格
+    @Override
+    public StationOilPrice getStationOilPrice(StationOilPrice stationOilPrice) {
+        return stationOilPriceMapper.getStationOilPrice(stationOilPrice);
+    }
 
     //获取油站公告
     @Override

+ 27 - 4
YijiaRestful/src/main/resources/mapper/StationOilPriceMapper.xml

@@ -13,6 +13,29 @@
     <result column="station_nanme" jdbcType="VARCHAR" property="stationNanme" />
     <result column="date" jdbcType="TIMESTAMP" property="date" />
   </resultMap>
+
+  <!--查询油站油品价格-->
+  <select id="getStationOilPrice" resultMap="BaseResultMap" parameterType="com.platform.yijia.pojo.StationOilPrice">
+    SELECT
+        oil_price_id,
+        oil_name,
+        oil_price,
+        station_id,
+        station_nanme,
+        date
+    FROM
+        station_oil_price
+    <where>
+      <if test="stationId !=null">
+        station_id = #{stationId}
+      </if>
+      <if test="oilName !=null and oilName !=''">
+        AND oil_name = #{oilName}
+      </if>
+    </where>
+  </select>
+
+
   <sql id="Example_Where_Clause">
     <!--
       WARNING - @mbg.generated
@@ -109,7 +132,7 @@
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
     -->
-    select 
+    select
     <include refid="Base_Column_List" />
     from station_oil_price
     where oil_price_id = #{oilPriceId,jdbcType=INTEGER}
@@ -137,10 +160,10 @@
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
     -->
-    insert into station_oil_price (oil_price_id, oil_name, oil_price, 
+    insert into station_oil_price (oil_price_id, oil_name, oil_price,
       station_id, station_nanme, date
       )
-    values (#{oilPriceId,jdbcType=INTEGER}, #{oilName,jdbcType=VARCHAR}, #{oilPrice,jdbcType=VARCHAR}, 
+    values (#{oilPriceId,jdbcType=INTEGER}, #{oilName,jdbcType=VARCHAR}, #{oilPrice,jdbcType=VARCHAR},
       #{stationId,jdbcType=INTEGER}, #{stationNanme,jdbcType=VARCHAR}, #{date,jdbcType=TIMESTAMP}
       )
   </insert>
@@ -285,4 +308,4 @@
       date = #{date,jdbcType=TIMESTAMP}
     where oil_price_id = #{oilPriceId,jdbcType=INTEGER}
   </update>
-</mapper>
+</mapper>

+ 14 - 4
YijiaRestful/src/test/java/com/palatform/yijia/test.java

@@ -2,14 +2,24 @@ package com.palatform.yijia;
 
 import org.apache.commons.codec.digest.DigestUtils;
 
+import java.math.BigDecimal;
+
 public class test {
 
     public static void main(String[] args) {
-        byte[] digesta = {0, 1, 0, 1};
-        byte[] digestb = {0, 0, 0, 1};
-        boolean equal = test.isEqual(digesta, digestb);
-        System.out.println(equal);
+//        byte[] digesta = {0, 1, 0, 1};
+//        byte[] digestb = {0, 0, 0, 1};
+//        boolean equal = test.isEqual(digesta, digestb);
+//        System.out.println(equal);
         //DigestUtils.sha1();
+
+        BigDecimal receivableAmt_b =new BigDecimal(200);
+        BigDecimal discountAmt_b = new BigDecimal(13);
+        BigDecimal gasoilDiscountAmt_b = new BigDecimal(13.56);
+
+        BigDecimal discountAmt = receivableAmt_b.divide(discountAmt_b, 2, BigDecimal.ROUND_HALF_UP).multiply(gasoilDiscountAmt_b);
+        discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
+        System.out.println(discountAmt);
     }