| 
					
				 | 
			
			
				@@ -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 
			 |