package com.platform.yijia.controller;
import com.google.gson.Gson;
import com.platform.yijia.config.YiJiaRequest;
import com.platform.yijia.dao.PayOrderMapper;
import com.platform.yijia.param.request.PayOrderRequest;
import com.platform.yijia.pojo.*;
import com.platform.yijia.service.*;
import com.platform.yijia.utils.CodeMsg;
import com.platform.yijia.utils.ResultData;
import org.apache.commons.lang3.StringUtils;
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 java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;

@Controller
@YiJiaRequest()
@CrossOrigin
public class PayOrderController {
    private static Logger logger =(Logger) LoggerFactory.getLogger(PayOrderController.class);
    @Resource
    private PayOrderService payOrderService;
    @Resource
    private AppUserInfoService appUserInfoService;
    @Resource
    private StationService stationService;
    @Resource
    private CustomerGradeServices customerGradeServices;
    @Resource
    private PayOrderMapper payOrderMapper;
    @Resource
    private ElectronicMembershipCardService electronicMembershipCardService;
    @Resource
    private  CustomerManagerService customerManagerService;
    @Resource
    private SysDictDataService sysDictDataService;

    //小程序支付生成订单
    @RequestMapping(value = "/AddPayOrderInfoNew", consumes = "application/json", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public String  AddPayOrderInfoNew(@RequestBody PayOrderRequest payOrderRequest){
        logger.info("获取订单前端传来参数openId："+ payOrderRequest.getOpenId());
        Gson gson =new Gson();
        ResultData resultData =null;
        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){
            appUserInfo.setUserType(payOrderRequest.getUserType());
            switch (payOrderRequest.getUserType()){
                case "1":       //小程序
                    appUserInfo.setMinaOpenid(payOrderRequest.getOpenId());
                    break;
                case "2":       //支付宝公众号
                    appUserInfo.setALiId(payOrderRequest.getOpenId());
                    break;
            }
            StationInfo stationInfo = new StationInfo();
            stationInfo.setStationId(payOrderRequest.getStationId());
            StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
            Map<String ,Object> resultMap = new HashMap<>();            //返回结果集
            if(stationInfos !=null){
                payOrder.setStationName(stationInfos.getStationName());
                //获取油站图片和名称
                resultMap.put("stationPic", stationInfos.getStationPic());
                resultMap.put("stationName", stationInfos.getStationName());
                appUserInfo.setStationId(stationInfos.getGroupId());
                AppUserInfo appUserInfos = appUserInfoService.getAppUserInfo(appUserInfo);
                if(appUserInfos !=null){
                    //payOrderRequest存放参数原因：用于其他方法形参
                    payOrderRequest.setCardEnabledFlagGroup(stationInfos.getCardEnabledFlagGroup());        //集团是否开启电子卡
                    payOrderRequest.setCardRuleFlagGroup(stationInfos.getCardRuleFlagGroup());              //集团是否共享
                    payOrderRequest.setIntegralFlagGroup(stationInfos.getIntegralFlagGroup());              //集团是否启用积分功能
                    payOrderRequest.setIntegralRuleFlagGroup(stationInfos.getIntegralRuleFlagGroup());      //集团是否共享
                    payOrderRequest.setCustomerPhone(appUserInfos.getMobilePhone());                        //客户手机号; 注：此处存放手机号用于获取客户信息参数查询
                    payOrderRequest.setUnionId(appUserInfos.getUnionId());                                  //客户UnionId；注：此处存放unionId用于获取客户电子卡参数查询
                    payOrderRequest.setCustomerName(appUserInfos.getBlogNickName());                        //昵称
                    payOrderRequest.setGroupId(stationInfos.getGroupId());                                  //集团ID

                    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);
                    }
                    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 Timestamp(new Date().getTime()));                    //创建时间
                    payOrder.setOrderType(payOrderRequest.getOrderType());  //订单类型
                    payOrder.setOilGun(payOrderRequest.getOilGun());        //油枪号
                    payOrder.setReceivableAmt(Double.valueOf(payOrderRequest.getReceivableAmt()));                //订单应收金额
                    String oilName =payOrderRequest.getOilName();
                    //获取该油品所属哪一类
                    Oil oil = new Oil();
                    oil.setOilName(oilName);
                    oil.setDictType("oil_name");
                    Oil oilInfo = sysDictDataService.selectOilType(oil);
                    payOrder.setOilType(oilInfo.getOilsType());     //油品类型
                    String oilsType = oilInfo.getOilsType();                          //获取订单类型
                    logger.info("订单油品类型：" + oilsType);
                    payOrderRequest.setCardOilsType(oilInfo.getOilsType());                 //电子卡类型；注：用于获取客户电子卡参数查询
                    payOrder.setOilName(oilName);                   //油品名称
                    //根据油站和油枪获取加油员
                    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() +",";
                            }
                        }
                        if(oilPersonnel !=""){
                            payOrder.setOilPersonnel(oilPersonnel.substring(0, oilPersonnel.length()-1));   //加油员
                        }
                    }else {
                        payOrder.setOilPersonnel("");
                    }
                    if(oilsType.equals("3")){                                                  //订单类型是油品时计算
                        payOrder.setOrderType("2");
                        payOrder.setAmt(Double.valueOf(payOrderRequest.getReceivableAmt()));        //非油品金额
                        payOrder.setDiscountAmt(Double.valueOf(0));                                 //优惠金额
                        payOrder.setOilPirce(payOrderRequest.getReceivableAmt());        //非油品价格
                        payOrder.setOrderLiters("0");
                        resultMap.put("oilsCardFlag", "0");
                        resultMap.put("discountAmt", "0");                                          //优惠价格
                        resultMap.put("amt", payOrderRequest.getReceivableAmt());                   //实收价格
                        resultMap.put("receivableAmt", payOrderRequest.getReceivableAmt());         //应收价格
                        resultMap.put("oilLiters", "0");
                        resultMap.put("discountPrice", "0");
                        resultMap.put("ordNo", ordNo);
                        payOrderMapper.insertSelective(payOrder);
                    }else {
                        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()));
                        payOrder.setOrderType("1");
                        resultMap.put("cardEnabledFlag", payOrderResultInfo.getCardEnabledFlag());
                        resultMap.put("oilsCardFlag", payOrderResultInfo.getOilsCardFlag());
                        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("discountAmt_dzk", payOrderResultInfo.getDzkDiscountAmt());   //电子卡优惠金额
                        resultMap.put("balance", payOrderResultInfo.getBalance());               //电子卡余额
                        resultMap.put("cardOilsType", payOrderResultInfo.getCardOilsType());     //电子卡类型1.汽油； 2.柴油
                        resultMap.put("ordNo", ordNo);
                        logger.info("返回前端的结果：" +resultMap.toString());
                        payOrderMapper.insertSelective(payOrder);
                    }
                    resultData = ResultData.success(resultMap);
                }else {
                    //登录人验证失败
                    resultData=ResultData.error(CodeMsg.USER_NOT_EXSIST);
                }
            }else {
                resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
            }
        }else {
            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
        }
        return gson.toJson(resultData);
    }

    //根据营销方案计算订单金额
    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
        String userPhone = payOrderRequest.getCustomerPhone();        //用户手机号
        String customerName = payOrderRequest.getCustomerName();        //用户手机号
        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();  //是否开启电子卡
        String cardRuleFlag = result.get("cardRuleFlag").toString();        //是否共享电子卡储值规则
        String groupId = payOrderRequest.getGroupId().toString();           //集团ID

        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("cardRuleFlag", cardRuleFlag);
        params.put("groupId", groupId);
        params.put("unionId", payOrderRequest.getUnionId());
        params.put("cardOilsType", payOrderRequest.getCardOilsType());
        params.put("customerName", customerName);
        params.put("userPhone", userPhone);
//      integralRuleFlagGroup;   //集团积分规则是否共享
//      integralFlagGroup;       //集团是否开启积分功能
//      cardRuleFlagGroup;       //集团是否共享电子卡充值规则
//      cardEnabledFlagGroup;    //集团是否开启电子卡
        params.put("integralRuleFlagGroup", payOrderRequest.getIntegralRuleFlagGroup());
        params.put("integralFlagGroup", payOrderRequest.getIntegralFlagGroup());
        params.put("cardRuleFlagGroup", payOrderRequest.getCardRuleFlagGroup());
        params.put("cardEnabledFlagGroup", payOrderRequest.getCardEnabledFlagGroup());

        switch (discountSetting){
            case "0":   //不执营销方案时 计算等级优惠
                payOrderResultInfo = this.calculateGradeDiscount(params);
                break;
            case "1":    //满减方案
                payOrderResultInfo = this.calculateManJianDiscount(params);
                break;
            case "2":    //立减方案
                payOrderResultInfo = this.calculateLiJianDiscount(params);
                break;
            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);    //等级优惠金额
        BigDecimal dzkGradeDiscountAmt = new BigDecimal(0);    //计算电子卡金额时所需等级优惠金额值
        BigDecimal dzkDiscountAmt = 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();   //计算结果存放值
        //计算等级优惠
        PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
        gradeDiscountAmt = new BigDecimal(payOrderResultInfoGrade.getDiscountAmt());
        dzkGradeDiscountAmt = gradeDiscountAmt; //同时给电子卡赋值等级优惠金额

        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;
            }
            dzkDiscountAmt = discountAmt;       //赋值电子卡优惠金额
            String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
            //该营销方案是否叠加等级优惠
            if(vipDiscountyPlus.equals("1")){
                //如果叠加等级优惠
                discountAmt = discountAmt.add(gradeDiscountAmt);
            }
        }
        amt = receivableAmt.subtract(discountAmt);  //应收金额
        amt =amt.signum() == -1 ? new BigDecimal("0.01"): amt;
        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.setDzkDiscountAmt(discountAmt.toString());
        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
        payOrderResultInfo.setOilLiters(oilLiters.toString());
        payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
        payOrderResultInfo.setOilPrice(oilPrice.toString());
        payOrderResultInfo.setDzkAmt(amt.toString());
        payOrderResultInfo.setOilsCardFlag("0");
        if(params.get("cardRuleFlagGroup").toString().equals("1")){
            //表示开启共享
            if(params.get("cardEnabledFlagGroup").toString().equals("1")){  //表示开启电子卡功能
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }else {
            //不共享，则查看油站电子卡是否开启
            if(params.get("cardEnabledFlag").toString().equals("1")){
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }
        logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
            CustomerCardSetting customerCardSetting = new CustomerCardSetting();
            customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
            if(params.get("cardRuleFlagGroup").toString().equals("1")){
                customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").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")){
                        //都叠加 电子卡支付金额 = 应收金额 - 营销优惠金额 - 等级优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt).subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;     //如果为负数，则默认设置0.01元
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        BigDecimal dzkDiscountAmtSum = dzkDiscountAmt.add(dzkGradeDiscountAmt); //电子卡总优惠金额
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmtSum.toString());
                    }else {
                        //叠加营销方案不叠加等级优惠： 电子卡支付金额 =实收金额-营销优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmt.toString());
                    }
                }else {
                    if(isGradeSetting.equals("1")){
                        //不叠加营销方案叠加等级优惠：电子卡支付金额 =应收金额-等级优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkGradeDiscountAmt.toString());
                    }else {
                        //都不叠加： 电子卡支付金额 = 应收金额
                        payOrderResultInfo.setDzkAmt(receivableAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt("0");
                    }
                }
            }
            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
            customerElectronicCard.setStationId(Integer.valueOf(params.get("stationId").toString()));
            customerElectronicCard.setCardOilsType(params.get("cardOilsType").toString());
            customerElectronicCard.setUnionId(params.get("unionId").toString());
            customerElectronicCard.setMobilePhone(params.get("userPhone").toString());
            customerElectronicCard.setCustomerName(params.get("customerName").toString());
            //查询客户余额和卡的类型
            Map<String, String> map = this.selectCardBalance(customerElectronicCard, params);
            payOrderResultInfo.setBalance(map.get("balance"));
            payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
            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);    //等级优惠金额
        BigDecimal dzkGradeDiscountAmt = new BigDecimal(0);    //计算电子卡金额时所需等级优惠金额值
        BigDecimal dzkDiscountAmt = 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();

        //计算等级优惠
        PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
        gradeDiscountAmt = new BigDecimal(payOrderResultInfoGrade.getDiscountAmt());
        dzkGradeDiscountAmt = gradeDiscountAmt;     //同时给电子卡赋值等级优惠金额

        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;
            }
            dzkDiscountAmt = discountAmt;
            String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
            if(vipDiscountyPlus.equals("1")){
                //如果叠加等级优惠
                discountAmt = discountAmt.add(gradeDiscountAmt);
            }
        }
        amt = receivableAmt.subtract(discountAmt);  //应收金额
        amt =amt.signum() == -1 ? new BigDecimal("0.01"): amt;
        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.setDzkDiscountAmt(discountAmt.toString());
        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
        payOrderResultInfo.setOilLiters(oilLiters.toString());
        payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
        payOrderResultInfo.setOilPrice(oilPrice.toString());
        payOrderResultInfo.setDzkAmt(amt.toString());
        payOrderResultInfo.setOilsCardFlag("0");
        if(params.get("cardRuleFlagGroup").toString().equals("1")){
            //表示开启共享
            if(params.get("cardEnabledFlagGroup").toString().equals("1")){  //表示开启电子卡功能
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }else {
            //不共享，则查看油站电子卡是否开启
            if(params.get("cardEnabledFlag").toString().equals("1")){
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }
        logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
            CustomerCardSetting customerCardSetting = new CustomerCardSetting();
            customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
            if(params.get("cardRuleFlagGroup").toString().equals("1")){
                customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").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")){
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt).subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        BigDecimal dzkDiscountAmtSum = dzkDiscountAmt.add(dzkGradeDiscountAmt); //电子卡优惠金额
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmtSum.toString());
                    }else {
                        //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额-营销优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmt.toString());
                    }
                }else {
                    if(isGradeSetting.equals("1")){
                        //如果电子卡设置不执行营销方案执行等级优惠 则 电子卡支付金额 =应收金额-等级优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkGradeDiscountAmt.toString());
                    }else {
                        payOrderResultInfo.setDzkAmt(receivableAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt("0");
                    }
                }
            }
            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
            customerElectronicCard.setStationId(Integer.valueOf(params.get("stationId").toString()));
            customerElectronicCard.setCardOilsType(params.get("cardOilsType").toString());
            customerElectronicCard.setUnionId(params.get("unionId").toString());
            customerElectronicCard.setMobilePhone(params.get("userPhone").toString());
            customerElectronicCard.setCustomerName(params.get("customerName").toString());
            //查询客户余额和卡的类型
            Map<String, String> map = this.selectCardBalance(customerElectronicCard, params);
            payOrderResultInfo.setBalance(map.get("balance"));
            payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
            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);    //等级优惠金额
        BigDecimal dzkGradeDiscountAmt = new BigDecimal(0);    //计算电子卡金额时所需等级优惠金额值
        BigDecimal dzkDiscountAmt = 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();
        //计算等级优惠
        PayOrderResultInfo payOrderResultInfoGrade = this.calculateGradeDiscount(params);
        gradeDiscountAmt = new BigDecimal(payOrderResultInfoGrade.getDiscountAmt());
        dzkGradeDiscountAmt = gradeDiscountAmt;
        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);
            }
            dzkDiscountAmt = discountAmt;
            //是否共享会员等级优惠叠加: 1 代表是； 2 代表否；
            String vipDiscountyPlus = customerMarkertPlanList.get(0).get("vipDiscountyPlus").toString();
            if(vipDiscountyPlus.equals("1")){
                //如果叠加等级优惠
                discountAmt = discountAmt.add(gradeDiscountAmt);
            }
        }
        amt = receivableAmt.subtract(discountAmt);  //应收金额
        amt =amt.signum() == -1 ? new BigDecimal("0.01"): amt;
        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.setDzkDiscountAmt(discountAmt.toString());
        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
        payOrderResultInfo.setOilLiters(oilLiters.toString());
        payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
        payOrderResultInfo.setOilPrice(oilPrice.toString());
        payOrderResultInfo.setDzkAmt(amt.toString());
        payOrderResultInfo.setOilsCardFlag("0");
        if(params.get("cardRuleFlagGroup").toString().equals("1")){
            //表示开启共享
            if(params.get("cardEnabledFlagGroup").toString().equals("1")){  //表示开启电子卡功能
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }else {
            //不共享，则查看油站电子卡是否开启
            if(params.get("cardEnabledFlag").toString().equals("1")){
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }
        logger.info("油站是否开启电子会员卡功能: " +params.get("cardEnabledFlag").toString());
        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
            CustomerCardSetting customerCardSetting = new CustomerCardSetting();
            customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
            if(params.get("cardRuleFlagGroup").toString().equals("1")){
                customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").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")){
                        //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额-营销优惠-等级优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt).subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        BigDecimal dzkDiscountAmtSum = dzkDiscountAmt.add(dzkGradeDiscountAmt); //电子卡优惠金额
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmtSum.toString());
                    }else {
                        //如果电子卡设置执行营销方案不执行等级优惠 则 电子卡支付金额 =实收金额-营销优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkDiscountAmt.toString());
                    }
                }else {
                    if(isGradeSetting.equals("1")){
                        //如果电子卡设置不执行营销方案执行等级优惠 则 电子卡支付金额 =应收金额-等级优惠金额
                        BigDecimal dzkAmt = receivableAmt.subtract(dzkGradeDiscountAmt);
                        dzkAmt =dzkAmt.signum() == -1 ? new BigDecimal("0.01"): dzkAmt;
                        payOrderResultInfo.setDzkAmt(dzkAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt(dzkGradeDiscountAmt.toString());
                    }else {
                        payOrderResultInfo.setDzkAmt(receivableAmt.toString());
                        payOrderResultInfo.setDzkDiscountAmt("0");
                    }
                }
            }
            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
            customerElectronicCard.setStationId(Integer.valueOf(params.get("stationId").toString()));
            customerElectronicCard.setCardOilsType(params.get("cardOilsType").toString());
            customerElectronicCard.setUnionId(params.get("unionId").toString());
            customerElectronicCard.setMobilePhone(params.get("userPhone").toString());
            customerElectronicCard.setCustomerName(params.get("customerName").toString());
            //查询客户余额和卡的类型
            Map<String, String> map = this.selectCardBalance(customerElectronicCard, params);
            payOrderResultInfo.setBalance(map.get("balance"));
            payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
            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 dzkDiscountAmt = discountAmt;  //优惠金额
        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);  //应收金额
        amt =amt.signum() == -1 ? new BigDecimal("0.01"): amt;
        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.setDzkDiscountAmt(discountAmt.toString());
        payOrderResultInfo.setDiscountPrice(discountPrice.toString());
        payOrderResultInfo.setOilLiters(oilLiters.toString());
        payOrderResultInfo.setReceivableAmt(receivableAmt.toString());
        payOrderResultInfo.setOilPrice(oilPrice.toString());
        payOrderResultInfo.setDzkAmt(amt.toString());
        payOrderResultInfo.setOilsCardFlag("0");
        if(params.get("cardRuleFlagGroup").toString().equals("1")){
            //表示开启共享
            if(params.get("cardEnabledFlagGroup").toString().equals("1")){  //表示开启电子卡功能
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }else {
            //不共享，则查看油站电子卡是否开启
            if(params.get("cardEnabledFlag").toString().equals("1")){
                payOrderResultInfo.setCardEnabledFlag("1");
            }else {
                payOrderResultInfo.setCardEnabledFlag("0");
            }
        }
        //电子卡功能是否开启
        logger.info("油站是否开启电子会员卡功能: " +payOrderResultInfo.getCardEnabledFlag());
        if(payOrderResultInfo.getCardEnabledFlag().equals("1")){
            payOrderResultInfo.setDzkAmt(receivableAmt.toString());
            payOrderResultInfo.setDzkDiscountAmt("0");
            CustomerCardSetting customerCardSetting = new CustomerCardSetting();
            customerCardSetting.setStationId(Integer.valueOf(params.get("stationId").toString()));
            if(params.get("cardRuleFlagGroup").toString().equals("1")){
                customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").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());
                    payOrderResultInfo.setDzkDiscountAmt(discountAmt.toString());
                }
            }
            CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
            customerElectronicCard.setStationId(Integer.valueOf(params.get("stationId").toString()));
            customerElectronicCard.setCardOilsType(params.get("cardOilsType").toString());
            customerElectronicCard.setUnionId(params.get("unionId").toString());
            customerElectronicCard.setMobilePhone(params.get("userPhone").toString());
            customerElectronicCard.setCustomerName(params.get("customerName").toString());
            //查询客户余额和卡的类型
            Map<String, String> map = this.selectCardBalance(customerElectronicCard, params);
            payOrderResultInfo.setBalance(map.get("balance"));
            payOrderResultInfo.setOilsCardFlag(map.get("oilsCardFlag"));
            payOrderResultInfo.setCardOilsType(map.get("cardOilsType"));
        }
        return  payOrderResultInfo;
    }

    //查询用户电子会员卡余额
    public Map<String, String>  selectCardBalance(CustomerElectronicCard card, Map params) {
        CustomerElectronicCard customerElectronicCard = new CustomerElectronicCard();
        customerElectronicCard.setCardOilsType(card.getCardOilsType());
        customerElectronicCard.setStationId(card.getStationId());
        customerElectronicCard.setUnionId(card.getUnionId());
        BigDecimal balance = new BigDecimal(0);
        String cardOilsType1 ="";
        Map<String, String> result = new HashMap<>();
        CustomerCardSetting customerCardSetting = new CustomerCardSetting();
        customerCardSetting.setStationId(card.getStationId());
        if(params.get("cardRuleFlagGroup").equals("1")){    //
            customerCardSetting.setStationId(Integer.valueOf(params.get("groupId").toString()));
            customerElectronicCard.setStationId(Integer.valueOf(params.get("groupId").toString()));
        }
        List<CustomerCardSetting> cardRechargeSettingList = electronicMembershipCardService.getCardRechargeSettingList(customerCardSetting);
        if(cardRechargeSettingList !=null && cardRechargeSettingList.size()>0){
            String cardOilsTypeExist = cardRechargeSettingList.get(0).getCardOilsType();
            String[] split = cardOilsTypeExist.split(",");
            List<String> strings = Arrays.asList(split);
            if(strings.contains(card.getCardOilsType())){
                CustomerElectronicCard electronicCardInfo = electronicMembershipCardService.getElectronicCardInfoByUnionId(customerElectronicCard);
                if(electronicCardInfo !=null){
                    //已存在卡
                    balance = electronicCardInfo.getAmt();
                    cardOilsType1 = electronicCardInfo.getCardOilsType();
                    result.put("balance",balance.toString());
                    result.put("oilsCardFlag", "1");
                    result.put("cardOilsType",cardOilsType1);
                }else {
                    //如果油站已开启该卡，用户没有卡
                    String currentTime = String.valueOf(System.currentTimeMillis());
                    String customerNo = card.getStationId() + currentTime;
                    customerElectronicCard.setCustomerNo(customerNo);
                    customerElectronicCard.setAmt(new BigDecimal(0));
                    customerElectronicCard.setCreateTime(new Date());
                    customerElectronicCard.setCustomerName(card.getCustomerName());
                    customerElectronicCard.setMobilePhone(card.getMobilePhone());
                    electronicMembershipCardService.insetElectronicCard(customerElectronicCard);
                    CustomerElectronicCard electronicCardInfoNew  = electronicMembershipCardService.getElectronicCardInfoByUnionId(customerElectronicCard);
                    balance = electronicCardInfoNew.getAmt();
                    result.put("balance",balance.toString());
                    result.put("oilsCardFlag", "1");
                    result.put("cardOilsType",electronicCardInfoNew.getCardOilsType());
                }
            }else {
                result.put("oilsCardFlag", "0");
            }
        }else {
            result.put("oilsCardFlag", "0");
        }
        return result;
    }

    /**
     * 根据订单号获取订单信息
     * produces="application/json;charset=UTF-8",consumes = "application/json",
     * @RequestBody String orderno
     * @param
     * @return
     */
    @RequestMapping(value = "/selectOrderInfoByOrdNo", method = RequestMethod.GET)
    @ResponseBody
    public String getPayOrderList(@RequestParam String orderNo){
        Gson gson =new Gson();
        ResultData resultData =null;
        if(StringUtils.isNotBlank(orderNo)){
            PayOrder payOrder = payOrderService.selectOrderInfoByOrdNo(orderNo);
            resultData = ResultData.success(payOrder);
        }else {
            resultData=ResultData.error(CodeMsg.SEARCH_FAIL);
        }
        return gson.toJson(resultData);
    }

    /*
     * 根据用户openId和用户类型userType查询用户订单
     * @param openId
     * @param userType
     * @return
     */
    @RequestMapping(value = "/getOrderListByOpenIdAndUserType", method = RequestMethod.GET)
    @ResponseBody
    public String getOrderListByOpenIdAndUserType(@RequestParam("openId") String openId, @RequestParam("userType") String userType){
        Gson gson =new Gson();
        ResultData resultData =null;
            if(StringUtils.isNotBlank(openId) && StringUtils.isNotBlank(userType)){
                AppUserInfo appUserInfo = new AppUserInfo();
                switch (userType){
                    case "1":
                        appUserInfo.setBlogOpenid(openId);
                        break;
                    case "2":
                        appUserInfo.setALiId(openId);
                        break;
                }
                List<PayOrder> payOrderList = payOrderService.getOrderListByOpenIdAndUserType(appUserInfo);
                resultData=ResultData.success(payOrderList);
            }else {
                resultData=ResultData.error(CodeMsg.SEARCH_FAIL);
            }

        return gson.toJson(resultData);
    }
}

