|
@@ -1,5 +1,4 @@
|
|
|
package com.platform.yijia.controller;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.platform.yijia.dao.PayOrderMapper;
|
|
|
import com.platform.yijia.param.request.PayOrderRequest;
|
|
@@ -7,19 +6,14 @@ import com.platform.yijia.pojo.*;
|
|
|
import com.platform.yijia.service.*;
|
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
|
import com.platform.yijia.utils.ResultData;
|
|
|
-import com.platform.yijia.utils.weixinapp.WxPushUtil;
|
|
|
-import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.ibatis.javassist.util.HotSwapAgent;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import javax.annotation.Resource;
|
|
|
-import javax.naming.ldap.HasControls;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Controller
|
|
@@ -40,6 +34,8 @@ public class PayOrderController {
|
|
|
private ElectronicMembershipCardService electronicMembershipCardService;
|
|
|
@Resource
|
|
|
private CustomerManagerService customerManagerService;
|
|
|
+ @Resource
|
|
|
+ private SysDictDataService sysDictDataService;
|
|
|
|
|
|
//小程序支付生成订单
|
|
|
@RequestMapping(value = "/AddPayOrderInfoNew", consumes = "application/json", method = RequestMethod.POST)
|
|
@@ -47,181 +43,112 @@ public class PayOrderController {
|
|
|
@Transactional
|
|
|
public String AddPayOrderInfoNew(@RequestBody PayOrderRequest payOrderRequest){
|
|
|
logger.info("获取订单前端传来参数openId:"+ payOrderRequest.getOpenId());
|
|
|
- logger.info("获取订单前端传来参数userType:"+ payOrderRequest.getUserType());
|
|
|
Gson gson =new Gson();
|
|
|
ResultData resultData =null;
|
|
|
- AppUserInfo appUserInfo =new AppUserInfo();
|
|
|
- appUserInfo.setUserType(payOrderRequest.getUserType()); //订单类型 是小程序还是公众号
|
|
|
- if(payOrderRequest.getUserType().equals("1")){
|
|
|
- appUserInfo.setBlogOpenid(payOrderRequest.getOpenId()); //1 是公众号
|
|
|
- }else if(payOrderRequest.getUserType().equals("2")){
|
|
|
- appUserInfo.setMinaOpenid(payOrderRequest.getOpenId()); //2是小程序
|
|
|
- }
|
|
|
- List<AppUserInfo> appUserInfoList =appUserInfoService.Authentication(appUserInfo);
|
|
|
- Map<String ,Object> resultMap = new HashMap<>(); //返回结果集
|
|
|
- //判断登录人员是否验证成功
|
|
|
- if(appUserInfoList!=null && appUserInfoList.size()>0){
|
|
|
- PayOrder payOrder = new PayOrder();
|
|
|
- payOrder.setConsumer(appUserInfoList.get(0).getBlogNickName()); //昵称
|
|
|
- payOrder.setConsumerId(appUserInfoList.get(0).getUserId()); //用户id
|
|
|
- Random random = new Random();
|
|
|
- String result="";
|
|
|
- for(int i=0;i<6;i++){
|
|
|
- result+=random.nextInt(10);
|
|
|
- }
|
|
|
- String ordNo=System.nanoTime()+result;
|
|
|
- payOrder.setOrderNo(ordNo); //订单号
|
|
|
- logger.info("生成的订单号:" + 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())){
|
|
|
- String userType = payOrderRequest.getUserType(); //支付方式:02公众号,03小程序',
|
|
|
- switch (userType){
|
|
|
- case "1":
|
|
|
- payOrder.setPayWay("02");
|
|
|
- break;
|
|
|
- case "2":
|
|
|
- payOrder.setPayWay("03");
|
|
|
- break;
|
|
|
- }
|
|
|
+ AppUserInfo appUserInfo =new AppUserInfo(); //查询客户信息传递参数
|
|
|
+ PayOrder payOrder = new PayOrder(); //生成订单参数
|
|
|
+ if(StringUtils.isNotBlank(payOrderRequest.getUserType()) && StringUtils.isNotBlank(payOrderRequest.getOpenId()) && StringUtils.isNotBlank(payOrderRequest.getOilName()) &&
|
|
|
+ StringUtils.isNotBlank(payOrderRequest.getOilGun()) && payOrderRequest.getReceivableAmt() !=null && StringUtils.isNotBlank(payOrderRequest.getOrderType())){
|
|
|
+ appUserInfo.setUserType(payOrderRequest.getUserType());
|
|
|
+ switch (payOrderRequest.getUserType()){
|
|
|
+ case "1": //公众号
|
|
|
+ appUserInfo.setBlogOpenid(payOrderRequest.getOpenId());
|
|
|
+ break;
|
|
|
+ case "2": //小程序
|
|
|
+ appUserInfo.setMinaOpenid(payOrderRequest.getOpenId());
|
|
|
+ break;
|
|
|
+ case "3": //支付宝公众号
|
|
|
+ appUserInfo.setALiId(payOrderRequest.getOpenId());
|
|
|
+ break;
|
|
|
+ case "4": //支付宝小程序
|
|
|
+ appUserInfo.setALiId(payOrderRequest.getOpenId());
|
|
|
+ break;
|
|
|
}
|
|
|
- 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<Map> mapResultList = payOrderMapper.selectPersonelName(params); //使用list原因:一个枪号对应多个加油员场景
|
|
|
- logger.info("加油员信息:"+ mapResultList.toString());
|
|
|
- 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() +",";
|
|
|
- }
|
|
|
+ AppUserInfo appUserInfos = appUserInfoService.getAppUserInfo(appUserInfo);
|
|
|
+ Map<String ,Object> resultMap = new HashMap<>(); //返回结果集
|
|
|
+ if(appUserInfos !=null){
|
|
|
+ payOrderRequest.setCustomerPhone(appUserInfos.getMobilePhone()); //客户手机号; 注:此处存放手机号用于获取客户信息参数查询
|
|
|
+ payOrderRequest.setUnionId(appUserInfos.getUnionId()); //客户UnionId;注:此处存放unionId用于获取客户电子卡参数查询
|
|
|
+ payOrder.setConsumer(appUserInfos.getBlogNickName()); //昵称
|
|
|
+ payOrder.setConsumerId(appUserInfos.getUserId()); //用户id
|
|
|
+ Random random = new Random();
|
|
|
+ String result="";
|
|
|
+ for(int i=0;i<6;i++){
|
|
|
+ result+=random.nextInt(10);
|
|
|
}
|
|
|
- if(oilPersonnel !=""){
|
|
|
- payOrder.setOilPersonnel(oilPersonnel.substring(0, oilPersonnel.length()-1)); //加油员
|
|
|
+ String ordNo=System.nanoTime()+result;
|
|
|
+ payOrder.setOrderNo(ordNo); //订单号
|
|
|
+ logger.info("生成的订单号:" + 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.setScore(payOrderRequest.getScore()); //积分
|
|
|
+ payOrder.setStationId(payOrderRequest.getStationId()); //油站id
|
|
|
+ payOrder.setStatus("0"); //创建订单 未支付状态 0
|
|
|
+ payOrder.setCreatedDate(new Date()); //创建时间
|
|
|
+ payOrder.setOrderType(payOrderRequest.getOrderType()); //订单类型
|
|
|
+ payOrder.setOilGun(payOrderRequest.getOilGun()); //油枪号
|
|
|
+ payOrder.setReceivableAmt(payOrderRequest.getReceivableAmt()); //订单应收金额
|
|
|
+ String oilName =payOrderRequest.getOilName();
|
|
|
+ //获取该油品所属哪一类
|
|
|
+ Oil oil = new Oil();
|
|
|
+ oil.setOilName(oilName);
|
|
|
+ Oil oilInfo = sysDictDataService.selectOilType(oil);
|
|
|
+ payOrder.setOilType(oilInfo.getOilsType()); //油品类型
|
|
|
+ payOrderRequest.setCardOilsType(oilInfo.getOilsType()); //电子卡类型;注:用于获取客户电子卡参数查询
|
|
|
+ payOrder.setOilName(oilName); //油品名称
|
|
|
+ StationInfo stationInfo = new StationInfo();
|
|
|
+ stationInfo.setStationId(payOrderRequest.getStationId());
|
|
|
+ StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
|
|
|
+ if(stationInfos !=null){
|
|
|
+ payOrder.setStationName(stationInfos.getStationName());
|
|
|
+ //获取油站图片和名称
|
|
|
+ resultMap.put("stationPic", stationInfos.getStationPic());
|
|
|
+ resultMap.put("stationName", stationInfos.getStationName());
|
|
|
}
|
|
|
- }
|
|
|
- String orderType = payOrderRequest.getOrderType(); //获取订单类型
|
|
|
- logger.info("订单类型:" + orderType);
|
|
|
- if(orderType.equals("1")){ //订单类型是油品时计算
|
|
|
- //resultMap = this.calculateAmt(payOrderRequest); //计算油价 加油升数 优惠金额 实收金额 优惠价格
|
|
|
- resultMap = this.calculateAmtNew(payOrderRequest); //计算油价 加油升数 优惠金额 实收金额 优惠价格
|
|
|
- payOrder.setOilPirce(resultMap.get("oilPrice").toString());
|
|
|
- payOrder.setOrderLiters(resultMap.get("oilLiters").toString());
|
|
|
- payOrder.setDiscountAmt(Double.valueOf(resultMap.get("discountAmt").toString()));
|
|
|
- payOrder.setAmt(Double.valueOf(resultMap.get("amt").toString()));
|
|
|
- String stationCardEnabledFlag = electronicMembershipCardService.getStationCardEnabledFlag(payOrderRequest.getStationId());
|
|
|
- logger.info("油站是否开启电子会员卡功能: " +stationCardEnabledFlag);
|
|
|
- //查询油站是否开启电子会员卡功能
|
|
|
- if(stationCardEnabledFlag.equals("1")){
|
|
|
-
|
|
|
- CustomerCardSetting customerCardSetting = new CustomerCardSetting();
|
|
|
- customerCardSetting.setStationId(payOrderRequest.getStationId());
|
|
|
- List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
|
|
|
- if(cardRechargeSettingList !=null && cardRechargeSettingList.size()>0){
|
|
|
- String isMarket = cardRechargeSettingList.get(0).getIsMarket(); //是否叠加营销方案
|
|
|
- String isGradeSetting = cardRechargeSettingList.get(0).getIsGradeSetting(); //是否叠加等级直降
|
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
- paramsMap.put("stationId", payOrderRequest.getStationId());
|
|
|
- paramsMap.put("oilName", payOrderRequest.getOilName());
|
|
|
- paramsMap.put("receivableAmt", payOrderRequest.getReceivableAmt());
|
|
|
- //获取油品价格
|
|
|
- StationOilPrice stationOilPrice = new StationOilPrice();
|
|
|
- stationOilPrice.setStationId(payOrderRequest.getStationId());
|
|
|
- stationOilPrice.setOilName(payOrderRequest.getOilName());
|
|
|
- StationOilPrice oilPriceInfo = stationService.getStationOilPrice(stationOilPrice);
|
|
|
- String oilPrice = oilPriceInfo.getOilPrice();
|
|
|
- paramsMap.put("oilPrice", oilPrice);
|
|
|
- paramsMap.put("mobilePhone", appUserInfoList.get(0).getMobilePhone());
|
|
|
- paramsMap.put("minaOpenid", appUserInfoList.get(0).getMinaOpenid());
|
|
|
-
|
|
|
- if (StringUtils.isNotBlank(isMarket) && isMarket.equals("0")){
|
|
|
- if(StringUtils.isNotBlank(isGradeSetting) && isGradeSetting.equals("0")){
|
|
|
- //如果营销和等级都设置叠加
|
|
|
- resultMap.put("amt_dzk", resultMap.get("amt").toString());
|
|
|
- }else {
|
|
|
- //如果营销叠加电子卡不叠加:则用总的实际所有的支付金额+等级优惠的金额
|
|
|
- Map<String, Object> map = this.calcuteDengJiZhiJiang(paramsMap);
|
|
|
- String string = map.get("discountAmt").toString();
|
|
|
- BigDecimal amt_dzk = new BigDecimal(resultMap.get("amt").toString()).add(new BigDecimal(string));
|
|
|
- resultMap.put("amt_dzk",amt_dzk.doubleValue());
|
|
|
- }
|
|
|
- }else {
|
|
|
- //如果不叠加营销,只叠加等级优惠
|
|
|
- if(StringUtils.isNotBlank(isGradeSetting) && isGradeSetting.equals("0")){
|
|
|
- Map<String, Object> map = this.calcuteDengJiZhiJiang(paramsMap);
|
|
|
- String string = map.get("discountAmt").toString();
|
|
|
- BigDecimal amt_dzk = new BigDecimal(payOrderRequest.getReceivableAmt()).subtract(new BigDecimal(string));
|
|
|
- resultMap.put("amt_dzk", amt_dzk);
|
|
|
-
|
|
|
- }else {
|
|
|
- //如果既不叠加营销优惠也不叠加等级优惠
|
|
|
- resultMap.put("amt_dzk", payOrderRequest.getReceivableAmt());
|
|
|
-
|
|
|
- }
|
|
|
+ //根据油站和油枪获取加油员
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ params.put("oliGunNo", payOrderRequest.getOilGun());
|
|
|
+ params.put("stationId", payOrderRequest.getStationId());
|
|
|
+ List<Map> mapResultList = payOrderMapper.selectPersonelName(params); //使用list原因:一个枪号对应多个加油员场景
|
|
|
+ logger.info("加油员信息:"+ mapResultList.toString());
|
|
|
+ if(mapResultList != null && mapResultList.size() > 0){
|
|
|
+ String oilPersonnel = "";
|
|
|
+ for (Map per : mapResultList){
|
|
|
+ if(per.containsKey("personelName") && per.get("personelName").toString() !=null && per.get("personelName").toString() !=""){
|
|
|
+ oilPersonnel += per.get("personelName").toString() +",";
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- //获取用户电子卡余额
|
|
|
- Map<String, String> map = this.selectCardBalance(payOrderRequest.getStationId(), payOrderRequest.getOilName(), appUserInfoList.get(0).getUnionId());
|
|
|
- resultMap.put("balance", map.get("balance")); //电子卡余额
|
|
|
- resultMap.put("cardOilsType", map.get("cardOilsType")); //电子卡类型1.汽油; 2.柴油
|
|
|
-
|
|
|
+ if(oilPersonnel !=""){
|
|
|
+ payOrder.setOilPersonnel(oilPersonnel.substring(0, oilPersonnel.length()-1)); //加油员
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ payOrder.setOilPersonnel("");
|
|
|
}
|
|
|
- }
|
|
|
- payOrder.setReceivableAmt(payOrderRequest.getReceivableAmt()); //订单应收金额
|
|
|
- String oilName =payOrderRequest.getOilName();
|
|
|
- payOrder.setOilName(oilName); //油品名称
|
|
|
- switch (oilName){
|
|
|
- case "92#":
|
|
|
- payOrder.setOilType("2");
|
|
|
- break;
|
|
|
- case "95#":
|
|
|
- payOrder.setOilType("2");
|
|
|
- break;
|
|
|
- case "98#":
|
|
|
- payOrder.setOilType("2");
|
|
|
- break;
|
|
|
- case "0#":
|
|
|
- payOrder.setOilType("1");
|
|
|
- break;
|
|
|
- case "-10#":
|
|
|
- payOrder.setOilType("1");
|
|
|
- break;
|
|
|
- case "-20#":
|
|
|
- payOrder.setOilType("1");
|
|
|
- break;
|
|
|
- }
|
|
|
- payOrder.setOrderType(orderType);
|
|
|
- StationInfo stationInfo = new StationInfo();
|
|
|
- stationInfo.setStationId(payOrderRequest.getStationId());
|
|
|
- StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
|
|
|
- if(stationInfos !=null){
|
|
|
- payOrder.setStationName(stationInfos.getStationName());
|
|
|
- //获取油站图片和名称
|
|
|
- resultMap.put("stationPic", stationInfos.getStationPic());
|
|
|
- resultMap.put("stationName", stationInfos.getStationName());
|
|
|
- }
|
|
|
- //payOrder.setPayType("wx"); //支付类型
|
|
|
- switch (orderType){
|
|
|
- case "1": //油品
|
|
|
- payOrderMapper.insertSelective(payOrder);
|
|
|
+ String orderType = payOrderRequest.getOrderType(); //获取订单类型
|
|
|
+ logger.info("订单类型:" + orderType);
|
|
|
+ if(orderType.equals("1")){ //订单类型是油品时计算
|
|
|
+ PayOrderResultInfo payOrderResultInfo = this.calculateAmt(payOrderRequest); //计算订单金额 价格 加油升数 等等
|
|
|
+ payOrder.setOilPirce(payOrderResultInfo.getOilPrice());
|
|
|
+ payOrder.setOrderLiters(payOrderResultInfo.getOilLiters());
|
|
|
+ payOrder.setDiscountAmt(Double.valueOf(payOrderResultInfo.getDiscountAmt()));
|
|
|
+ payOrder.setAmt(Double.valueOf(payOrderResultInfo.getAmt()));
|
|
|
+ resultMap.put("discountAmt", payOrderResultInfo.getDiscountAmt()); //优惠价格
|
|
|
+ resultMap.put("amt", payOrderResultInfo.getAmt()); //实收价格
|
|
|
+ resultMap.put("receivableAmt", payOrderResultInfo.getReceivableAmt()); //应收价格
|
|
|
+ resultMap.put("oilLiters", payOrderResultInfo.getOilLiters());
|
|
|
+ resultMap.put("discountPrice", payOrderResultInfo.getDiscountPrice());
|
|
|
+ resultMap.put("amt_dzk", payOrderResultInfo.getDzkAmt());
|
|
|
+ resultMap.put("balance", payOrderResultInfo.getBalance()); //电子卡余额
|
|
|
+ resultMap.put("cardOilsType", payOrderResultInfo.getCardOilsType()); //电子卡类型1.汽油; 2.柴油
|
|
|
resultMap.put("ordNo", ordNo);
|
|
|
- break;
|
|
|
- case "2": //非油品
|
|
|
+ logger.info("返回前端的结果:" +resultMap.toString());
|
|
|
+ payOrderMapper.insertSelective(payOrder);
|
|
|
+ }else {
|
|
|
payOrder.setAmt(Double.valueOf(payOrderRequest.getReceivableAmt())); //非油品金额
|
|
|
payOrder.setDiscountAmt(Double.valueOf(0)); //优惠金额
|
|
|
payOrder.setOilPirce(payOrderRequest.getReceivableAmt().toString()); //非油品价格
|
|
@@ -231,41 +158,369 @@ public class PayOrderController {
|
|
|
resultMap.put("receivableAmt", payOrderRequest.getReceivableAmt()); //应收价格
|
|
|
resultMap.put("oilLiters", "0");
|
|
|
resultMap.put("discountPrice", "0");
|
|
|
- payOrderMapper.insertSelective(payOrder);
|
|
|
resultMap.put("ordNo", ordNo);
|
|
|
- break;
|
|
|
+ payOrderMapper.insertSelective(payOrder);
|
|
|
+ }
|
|
|
+ resultData = ResultData.success(resultMap);
|
|
|
+ }else {
|
|
|
+ //登录人验证失败
|
|
|
+ resultData=ResultData.error(CodeMsg.USER_NOT_EXSIST);
|
|
|
}
|
|
|
- resultData = ResultData.success(resultMap);
|
|
|
- }else{
|
|
|
- //登录人验证失败
|
|
|
- resultData=ResultData.error(CodeMsg.USER_NOT_EXSIST);
|
|
|
+ }else {
|
|
|
+ resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
|
|
|
}
|
|
|
return gson.toJson(resultData);
|
|
|
}
|
|
|
|
|
|
- //查询用户电子会员卡余额
|
|
|
- public Map<String, String> selectCardBalance(Integer stationId, String oilName, String unionId) {
|
|
|
- String cardOilsType ="";
|
|
|
- switch (oilName){
|
|
|
- case "92#":
|
|
|
- cardOilsType ="1";
|
|
|
- break;
|
|
|
- case "95#":
|
|
|
- cardOilsType ="1";
|
|
|
- break;
|
|
|
- case "98#":
|
|
|
- cardOilsType ="1";
|
|
|
+
|
|
|
+ //根据营销方案计算订单金额
|
|
|
+ public PayOrderResultInfo calculateAmt(PayOrderRequest payOrderRequest){
|
|
|
+ PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
|
|
|
+ Integer stationId = payOrderRequest.getStationId(); //油站ID
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(payOrderRequest.getReceivableAmt()); //应收金额 用户输入的金额
|
|
|
+ String oilName = payOrderRequest.getOilName(); //油品名称
|
|
|
+ String openId = payOrderRequest.getOpenId(); //用户的openId
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("oilName", oilName);
|
|
|
+ map.put("stationId", stationId);
|
|
|
+ Map<String, Object> result = stationService.selectStationOilPriceAndDiscountSetting(map);
|
|
|
+ String oilPrice = result.get("oilPrice").toString();
|
|
|
+ String discountSetting = result.get("discountSetting").toString();
|
|
|
+ String cardEnabledFlag = result.get("cardEnabledFlag").toString();
|
|
|
+
|
|
|
+ Map<String ,Object> params = new HashMap<String, Object>();
|
|
|
+ params.put("stationId", stationId);
|
|
|
+ params.put("oilName", oilName);
|
|
|
+ params.put("receivableAmt", receivableAmt);
|
|
|
+ params.put("oilPrice", oilPrice);
|
|
|
+ params.put("mobilePhone", payOrderRequest.getCustomerPhone());
|
|
|
+ params.put("minaOpenid", openId);
|
|
|
+ params.put("cardEnabledFlag", cardEnabledFlag);
|
|
|
+ params.put("unionId", payOrderRequest.getUnionId());
|
|
|
+ params.put("cardOilsType", payOrderRequest.getCardOilsType());
|
|
|
+ switch (discountSetting){
|
|
|
+ case "0": //不执营销方案时 计算等级优惠
|
|
|
+ payOrderResultInfo = this.calculateGradeDiscount(params);
|
|
|
break;
|
|
|
- case "0#":
|
|
|
- cardOilsType ="2";
|
|
|
+ case "1": //满减方案
|
|
|
+ payOrderResultInfo = this.calculateManJianDiscount(params);
|
|
|
break;
|
|
|
- case "-10#":
|
|
|
- cardOilsType ="2";
|
|
|
+ case "2": //立减方案
|
|
|
+ payOrderResultInfo = this.calculateLiJianDiscount(params);
|
|
|
break;
|
|
|
- case "-20#":
|
|
|
- cardOilsType ="2";
|
|
|
+ case "3": //独立直降
|
|
|
+ payOrderResultInfo = this.calculateZhiJiangDiscount(params);
|
|
|
break;
|
|
|
}
|
|
|
+ return payOrderResultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算直降
|
|
|
+ public PayOrderResultInfo calculateZhiJiangDiscount(Map<String ,Object> params){
|
|
|
+ BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString()); //油品价格
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(params.get("receivableAmt").toString()); //应收金额
|
|
|
+ BigDecimal oilLiters = new BigDecimal("0.00"); //加油升数
|
|
|
+ BigDecimal discountAmt = new BigDecimal(0); //优惠金额
|
|
|
+ BigDecimal amt = new BigDecimal(0);
|
|
|
+ BigDecimal discountPrice = oilPrice;
|
|
|
+ BigDecimal gradeDiscountAmt = new BigDecimal(0); //等级优惠金额
|
|
|
+ //加油升数
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if(!oilLiters.toString().substring(oilLiters.toString().indexOf(".") + 1).equals("00")){
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_UP);
|
|
|
+ }
|
|
|
+ PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
|
|
|
+ params.put("discountPlanType", "3");
|
|
|
+ List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
|
|
|
+ if(customerMarkertPlanList !=null && customerMarkertPlanList.size() >0){
|
|
|
+ BigDecimal discountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("discountAmt").toString()); //条件金额
|
|
|
+ BigDecimal gasoilDiscountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("gasoilDiscountAmt").toString());
|
|
|
+ String discountTerm = customerMarkertPlanList.get(0).get("discountTerm").toString();
|
|
|
+ switch (discountTerm){
|
|
|
+ case "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);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "2": //按加油金额
|
|
|
+ if(receivableAmt.compareTo(discountAmt_b) ==1 || receivableAmt.compareTo(discountAmt_b) ==0){
|
|
|
+ discountAmt = oilLiters.multiply(gasoilDiscountAmt_b);
|
|
|
+ discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
|
|
|
+ if(vipDiscountyPlus.equals("1")){
|
|
|
+ PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
|
|
|
+ discountAmt = discountAmt.add(new BigDecimal(payOrderResultInfoGrade.getDiscountAmt()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ amt = receivableAmt.subtract(discountAmt); //应收金额
|
|
|
+ discountPrice = oilLiters.equals(new BigDecimal("0.00")) ? discountPrice : amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP); //优惠价格
|
|
|
+ payOrderResultInfo.setAmt(amt.toString());
|
|
|
+ payOrderResultInfo.setDiscountAmt(discountAmt.toString());
|
|
|
+ payOrderResultInfo.setDiscountPrice(discountPrice.toString());
|
|
|
+ payOrderResultInfo.setOilLiters(oilLiters.toString());
|
|
|
+ payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
|
|
|
+ payOrderResultInfo.setOilPrice(oilPrice.toString());
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
|
|
|
+ if(params.get("cardEnabledFlag").toString().equals("1")){
|
|
|
+ CustomerCardSetting customerCardSetting = new CustomerCardSetting();
|
|
|
+ customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
|
|
|
+ List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
|
|
|
+ if(cardRechargeSettingList !=null && cardRechargeSettingList.size() >0){
|
|
|
+ String isGradeSetting = cardRechargeSettingList.get(0).getIsGradeSetting(); //是否叠加等级方案
|
|
|
+ String isMarket = cardRechargeSettingList.get(0).getIsMarket(); //等候否叠加营销方案
|
|
|
+ if(isMarket.equals("1")){
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ }else {
|
|
|
+ //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额+等级优惠金额
|
|
|
+ BigDecimal subtract = amt.add(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ //如果电子卡设置不执行营销方案执行等级优惠 则 电子卡支付金额 =应收金额-等级优惠金额
|
|
|
+ BigDecimal subtract = receivableAmt.subtract(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }else {
|
|
|
+ payOrderResultInfo.setDzkAmt(receivableAmt.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询客户余额和卡的类型
|
|
|
+ Map<String, String> map = this.selectCardBalance(Integer.valueOf(params.get("stationId").toString()), params.get("cardOilsType").toString(), params.get("unionId").toString());
|
|
|
+ payOrderResultInfo.setBalance(map.get("balance"));
|
|
|
+ payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
|
|
|
+ }
|
|
|
+ return payOrderResultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算立减
|
|
|
+ public PayOrderResultInfo calculateLiJianDiscount(Map<String ,Object> params){
|
|
|
+ BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString()); //油品价格
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(params.get("receivableAmt").toString()); //应收金额
|
|
|
+ BigDecimal oilLiters = new BigDecimal("0.00"); //加油升数
|
|
|
+ BigDecimal discountAmt = new BigDecimal(0); //优惠金额
|
|
|
+ BigDecimal amt = new BigDecimal(0);
|
|
|
+ BigDecimal discountPrice = oilPrice;
|
|
|
+ BigDecimal gradeDiscountAmt = new BigDecimal(0); //等级优惠金额
|
|
|
+ //加油升数
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if(!oilLiters.toString().substring(oilLiters.toString().indexOf(".") + 1).equals("00")){
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_UP);
|
|
|
+ }
|
|
|
+ PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
|
|
|
+ params.put("discountPlanType", "2");
|
|
|
+ List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
|
|
|
+ if(customerMarkertPlanList !=null && customerMarkertPlanList.size() >0){
|
|
|
+ BigDecimal discountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("discountAmt").toString()); //条件金额
|
|
|
+ BigDecimal gasoilDiscountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("gasoilDiscountAmt").toString()); //享受的优惠
|
|
|
+ if(receivableAmt.compareTo(discountAmt_b) == 1 || receivableAmt.compareTo(discountAmt_b) == 0){
|
|
|
+ discountAmt = gasoilDiscountAmt_b;
|
|
|
+ }
|
|
|
+ String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
|
|
|
+ if(vipDiscountyPlus.equals("1")){
|
|
|
+ PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
|
|
|
+ gradeDiscountAmt = new BigDecimal(payOrderResultInfoGrade.getDiscountAmt());
|
|
|
+ discountAmt = discountAmt.add(gradeDiscountAmt);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ amt = receivableAmt.subtract(discountAmt); //应收金额
|
|
|
+ discountPrice = oilLiters.equals(new BigDecimal("0.00")) ? discountPrice : amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP); //优惠价格
|
|
|
+ payOrderResultInfo.setAmt(amt.toString());
|
|
|
+ payOrderResultInfo.setDiscountAmt(discountAmt.toString());
|
|
|
+ payOrderResultInfo.setDiscountPrice(discountPrice.toString());
|
|
|
+ payOrderResultInfo.setOilLiters(oilLiters.toString());
|
|
|
+ payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
|
|
|
+ payOrderResultInfo.setOilPrice(oilPrice.toString());
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
|
|
|
+ if(params.get("cardEnabledFlag").toString().equals("1")){
|
|
|
+ CustomerCardSetting customerCardSetting = new CustomerCardSetting();
|
|
|
+ customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
|
|
|
+ List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
|
|
|
+ if(cardRechargeSettingList !=null && cardRechargeSettingList.size() >0){
|
|
|
+ String isGradeSetting = cardRechargeSettingList.get(0).getIsGradeSetting(); //是否叠加等级方案
|
|
|
+ String isMarket = cardRechargeSettingList.get(0).getIsMarket(); //等候否叠加营销方案
|
|
|
+ if(isMarket.equals("1")){
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ }else {
|
|
|
+ //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额+等级优惠金额
|
|
|
+ BigDecimal subtract = amt.add(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ //如果电子卡设置不执行营销方案执行等级优惠 则 电子卡支付金额 =应收金额-等级优惠金额
|
|
|
+ BigDecimal subtract = receivableAmt.subtract(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }else {
|
|
|
+ payOrderResultInfo.setDzkAmt(receivableAmt.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询客户余额和卡的类型
|
|
|
+ Map<String, String> map = this.selectCardBalance(Integer.valueOf(params.get("stationId").toString()), params.get("cardOilsType").toString(), params.get("unionId").toString());
|
|
|
+ payOrderResultInfo.setBalance(map.get("balance"));
|
|
|
+ payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
|
|
|
+ }
|
|
|
+ return payOrderResultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算满减
|
|
|
+ public PayOrderResultInfo calculateManJianDiscount(Map<String ,Object> params){
|
|
|
+
|
|
|
+ BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString()); //油品价格
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(params.get("receivableAmt").toString()); //应收金额
|
|
|
+ BigDecimal oilLiters = new BigDecimal("0.00"); //加油升数
|
|
|
+ BigDecimal discountAmt = new BigDecimal(0); //优惠金额
|
|
|
+ BigDecimal amt = new BigDecimal(0);
|
|
|
+ BigDecimal discountPrice = oilPrice;
|
|
|
+ BigDecimal gradeDiscountAmt = new BigDecimal(0); //等级优惠金额
|
|
|
+ //加油升数
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if(!oilLiters.toString().substring(oilLiters.toString().indexOf(".") + 1).equals("00")){
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_UP);
|
|
|
+ }
|
|
|
+ PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
|
|
|
+ params.put("discountPlanType", "1");
|
|
|
+ List<Map> customerMarkertPlanList = customerGradeServices.getCustomerMarkertPlanList(params);
|
|
|
+ if(customerMarkertPlanList !=null && customerMarkertPlanList.size() >0){
|
|
|
+ BigDecimal discountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("discountAmt").toString()); //条件金额
|
|
|
+ BigDecimal gasoilDiscountAmt_b = new BigDecimal(customerMarkertPlanList.get(0).get("gasoilDiscountAmt").toString()); //享受的优惠
|
|
|
+ if(receivableAmt.compareTo(discountAmt_b) == 1 || receivableAmt.compareTo(discountAmt_b) == 0){
|
|
|
+ discountAmt = receivableAmt.divide(discountAmt_b, 2, BigDecimal.ROUND_HALF_UP).multiply(gasoilDiscountAmt_b); //优惠金额
|
|
|
+ discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ //是否共享会员等级优惠叠加: 1 代表是; 2 代表否;
|
|
|
+ String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
|
|
|
+ if(vipDiscountyPlus.equals("1")){
|
|
|
+ PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
|
|
|
+ discountAmt = discountAmt.add(new BigDecimal(payOrderResultInfoGrade.getDiscountAmt()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ amt = receivableAmt.subtract(discountAmt); //应收金额
|
|
|
+ discountPrice = oilLiters.equals(new BigDecimal("0.00")) ? discountPrice : amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP); //优惠价格
|
|
|
+ payOrderResultInfo.setAmt(amt.toString());
|
|
|
+ payOrderResultInfo.setDiscountAmt(discountAmt.toString());
|
|
|
+ payOrderResultInfo.setDiscountPrice(discountPrice.toString());
|
|
|
+ payOrderResultInfo.setOilLiters(oilLiters.toString());
|
|
|
+ payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
|
|
|
+ payOrderResultInfo.setOilPrice(oilPrice.toString());
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
|
|
|
+ if(params.get("cardEnabledFlag").toString().equals("1")){
|
|
|
+ CustomerCardSetting customerCardSetting = new CustomerCardSetting();
|
|
|
+ customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
|
|
|
+ List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
|
|
|
+ if(cardRechargeSettingList !=null && cardRechargeSettingList.size() >0){
|
|
|
+ String isGradeSetting = cardRechargeSettingList.get(0).getIsGradeSetting(); //是否叠加等级方案
|
|
|
+ String isMarket = cardRechargeSettingList.get(0).getIsMarket(); //等候否叠加营销方案
|
|
|
+ if(isMarket.equals("1")){
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ }else {
|
|
|
+ //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额+等级优惠金额
|
|
|
+ BigDecimal subtract = amt.add(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ //如果电子卡设置不执行营销方案执行等级优惠 则 电子卡支付金额 =应收金额-等级优惠金额
|
|
|
+ BigDecimal subtract = receivableAmt.subtract(gradeDiscountAmt);
|
|
|
+ payOrderResultInfo.setDzkAmt(subtract.toString());
|
|
|
+ }else {
|
|
|
+ payOrderResultInfo.setDzkAmt(receivableAmt.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询客户余额和卡的类型
|
|
|
+ Map<String, String> map = this.selectCardBalance(Integer.valueOf(params.get("stationId").toString()), params.get("cardOilsType").toString(), params.get("unionId").toString());
|
|
|
+ payOrderResultInfo.setBalance(map.get("balance"));
|
|
|
+ payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
|
|
|
+ }
|
|
|
+ return payOrderResultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算等级优惠
|
|
|
+ public PayOrderResultInfo calculateGradeDiscount(Map<String ,Object> params){
|
|
|
+ String oilName = params.get("oilName").toString();
|
|
|
+ String stationId = params.get("stationId").toString();
|
|
|
+ BigDecimal oilPrice = new BigDecimal(params.get("oilPrice").toString()); //油品价格
|
|
|
+ BigDecimal receivableAmt = new BigDecimal(params.get("receivableAmt").toString()); //应收金额
|
|
|
+ BigDecimal oilLiters = new BigDecimal("0.00"); //加油升数
|
|
|
+ BigDecimal discountAmt = new BigDecimal(0); //优惠金额
|
|
|
+ BigDecimal amt = new BigDecimal(0);
|
|
|
+ BigDecimal discountPrice = oilPrice;
|
|
|
+ PayOrderResultInfo payOrderResultInfo = new PayOrderResultInfo();
|
|
|
+
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if(!oilLiters.toString().substring(oilLiters.toString().indexOf(".") + 1).equals("00")){
|
|
|
+ oilLiters = receivableAmt.divide(oilPrice,2, BigDecimal.ROUND_UP);
|
|
|
+ }
|
|
|
+ //当前客户是否已存在当前油站客户信息中
|
|
|
+ CustomerManage customerManage = new CustomerManage();
|
|
|
+ customerManage.setPhoneNumber(params.get("mobilePhone").toString());
|
|
|
+ customerManage.setOilName(oilName);
|
|
|
+ customerManage.setStationId(Integer.valueOf(stationId));
|
|
|
+ CustomerManage customerManageInfo = customerManagerService.getCustomerManageInfo(customerManage);
|
|
|
+ if(customerManageInfo !=null){
|
|
|
+ //当前客户所加油的订单已存在等级时
|
|
|
+ double amtSum = customerManageInfo.getAmt().doubleValue(); //当前客户已累计的金额
|
|
|
+ List<Map> cList = customerGradeServices.getCustomerGradeListOrderByDesc(params); //获取油站的等级优惠方案 倒叙查询规则
|
|
|
+ if(cList !=null && cList.size() >0){ //当前油站设置等级方案时
|
|
|
+ for(Map m : cList){
|
|
|
+ if(amtSum >= Double.valueOf(m.get("memberConditStart").toString())){
|
|
|
+ discountAmt = oilLiters.multiply(new BigDecimal(m.get("discountAmt").toString()));
|
|
|
+ discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ //当前客户所加油的订单不存在等级时
|
|
|
+ List<Map> customerGradeList = customerGradeServices.getCustomerGradeList(params); //升序查询 取第一条
|
|
|
+ if(customerGradeList !=null && customerGradeList.size() >0){
|
|
|
+ discountAmt = oilLiters.multiply(new BigDecimal(customerGradeList.get(0).get("discountAmt").toString()));
|
|
|
+ discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ amt = receivableAmt.subtract(discountAmt); //应收金额
|
|
|
+ discountPrice = oilLiters.equals(new BigDecimal("0.00")) ? discountPrice : amt.divide(oilLiters, 2, BigDecimal.ROUND_HALF_UP); //优惠价格
|
|
|
+ payOrderResultInfo.setAmt(amt.toString());
|
|
|
+ payOrderResultInfo.setDiscountAmt(discountAmt.toString());
|
|
|
+ payOrderResultInfo.setDiscountPrice(discountPrice.toString());
|
|
|
+ payOrderResultInfo.setOilLiters(oilLiters.toString());
|
|
|
+ payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
|
|
|
+ payOrderResultInfo.setOilPrice(oilPrice.toString());
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
|
|
|
+ if(params.get("cardEnabledFlag").toString().equals("1")){
|
|
|
+ CustomerCardSetting customerCardSetting = new CustomerCardSetting();
|
|
|
+ customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
|
|
|
+ List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
|
|
|
+ if(cardRechargeSettingList !=null && cardRechargeSettingList.size() >0){
|
|
|
+ String isGradeSetting = cardRechargeSettingList.get(0).getIsGradeSetting();
|
|
|
+ if(isGradeSetting.equals("1")){
|
|
|
+ payOrderResultInfo.setDzkAmt(amt.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询客户余额和卡的类型
|
|
|
+ Map<String, String> map = this.selectCardBalance(Integer.valueOf(params.get("stationId").toString()), params.get("cardOilsType").toString(), params.get("unionId").toString());
|
|
|
+ payOrderResultInfo.setBalance(map.get("balance"));
|
|
|
+ payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
|
|
|
+ }
|
|
|
+ return payOrderResultInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询用户电子会员卡余额
|
|
|
+ public Map<String, String> selectCardBalance(Integer stationId, String cardOilsType, String unionId) {
|
|
|
CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
|
|
|
customerElectronicCard.setCardOilsType(cardOilsType);
|
|
|
customerElectronicCard.setStationId(stationId);
|
|
@@ -283,224 +538,6 @@ public class PayOrderController {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- /***
|
|
|
- * 计算订单金额
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String ,Object> calculateAmt(PayOrderRequest payOrderRequest){
|
|
|
- Map<String ,Object> resultMap = new HashMap<>();
|
|
|
- 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();
|
|
|
- //String stationNanme = oilPriceInfo.getStationNanme();
|
|
|
- BigDecimal oilLiters = null;
|
|
|
- BigDecimal discountAmt =null;
|
|
|
- BigDecimal discountPrice = null;
|
|
|
- BigDecimal amt = null;
|
|
|
-
|
|
|
- //resultMap.put("stationName", stationNanme);
|
|
|
- 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_UP);
|
|
|
- discountAmt = oilLiters.multiply(new BigDecimal(customerGradeInfo.get(0).get("gasoilDiscountLitre").toString()));
|
|
|
- discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_UP);
|
|
|
- amt = receivableAmt_b.subtract(discountAmt);
|
|
|
- discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_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_UP); //加油升数
|
|
|
- discountAmt = oilLiters.multiply(new BigDecimal(customerGradeList.get(0).get("gasoilDiscountLitre").toString()));
|
|
|
- discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_UP);
|
|
|
- amt = receivableAmt_b.subtract(discountAmt);
|
|
|
- discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_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_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_UP).multiply(gasoilDiscountAmt_b); //优惠金额
|
|
|
- discountAmt = discountAmt.setScale(2, BigDecimal.ROUND_UP);
|
|
|
- amt = receivableAmt_b.subtract(discountAmt); //实收金额
|
|
|
- oilLiters = receivableAmt_b.divide(new BigDecimal(oilPrice),2, BigDecimal.ROUND_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_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_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_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_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_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_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_UP);
|
|
|
- amt = receivableAmt_b.subtract(discountAmt);
|
|
|
- discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_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_UP);
|
|
|
- amt = receivableAmt_b.subtract(discountAmt);
|
|
|
- discountPrice = amt.divide(oilLiters, 2, BigDecimal.ROUND_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_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_UP);
|
|
|
- resultMap.put("oilLiters", oilLiters.doubleValue());
|
|
|
- resultMap.put("discountPrice", oilPrice);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- //resultData = ResultData.success(resultMap);
|
|
|
- }
|
|
|
- return resultMap;
|
|
|
- }
|
|
|
|
|
|
/*
|
|
|
* ===========================计算订单金额======================================
|