package org.jeecg.modules.xcx.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.DateUtils2;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.hoteladdress.entity.HotelAddress;
import org.jeecg.modules.hoteladdress.service.IHotelAddressService;
import org.jeecg.modules.hotelbalancelog.entity.HotelBalanceLog;
import org.jeecg.modules.hotelbalancelog.service.IHotelBalanceLogService;
import org.jeecg.modules.hotelcategory.entity.HotelCategory;
import org.jeecg.modules.hotelcategory.service.IHotelCategoryService;
import org.jeecg.modules.hotelconf.entity.HotelConf;
import org.jeecg.modules.hotelconf.service.IHotelConfService;
import org.jeecg.modules.hotelcouponlog.entity.HotelCouponLog;
import org.jeecg.modules.hotelcouponlog.service.IHotelCouponLogService;
import org.jeecg.modules.hotelgoods.entity.HotelGoods;
import org.jeecg.modules.hotelgoods.service.IHotelGoodsService;
import org.jeecg.modules.hotelgoodssku.entity.HotelGoodsSku;
import org.jeecg.modules.hotelgoodssku.service.IHotelGoodsSkuService;
import org.jeecg.modules.hotelleaselog.entity.HotelLeaseLog;
import org.jeecg.modules.hotelleaselog.service.IHotelLeaseLogService;
import org.jeecg.modules.hotelmemberaccount.entity.HotelMemberAccount;
import org.jeecg.modules.hotelmemberaccount.service.IHotelMemberAccountService;
import org.jeecg.modules.hotelorder.entity.HotelOrder;
import org.jeecg.modules.hotelorder.service.IHotelOrderService;
import org.jeecg.modules.hotelorderdetail.entity.HotelOrderDetail;
import org.jeecg.modules.hotelorderdetail.service.IHotelOrderDetailService;
import org.jeecg.modules.hotelorderflow.entity.HotelOrderFlow;
import org.jeecg.modules.hotelorderflow.service.IHotelOrderFlowService;
import org.jeecg.modules.hotelorderlog.entity.HotelOrderLog;
import org.jeecg.modules.hotelorderlog.service.IHotelOrderLogService;
import org.jeecg.modules.hotelshop.entity.HotelShop;
import org.jeecg.modules.hotelshop.service.IHotelShopService;
import org.jeecg.modules.pay.MpWxPayService;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.xcx.goods.req.EditLeaseNumReq;
import org.jeecg.modules.xcx.order.req.*;
import org.jeecg.modules.xcx.order.service.IOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class OrderServiceImpl implements IOrderService {

    @Resource
    private IHotelOrderService hotelOrderService;
    @Resource
    private ShiroRealm shiroRealm;
    @Resource
    private IHotelGoodsService hotelGoodsService;
    @Resource
    private IHotelGoodsSkuService hotelGoodsSkuService;
    @Resource
    private MpWxPayService mpWxPayService;
    @Resource
    private IHotelAddressService hotelAddressService;
    @Resource
    private IHotelLeaseLogService hotelLeaseLogService;
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private IHanHaiMemberService hanHaiMemberService;
    @Resource
    private IHotelConfService hotelConfService;
    @Value("${weixin.orderNotifyUrl}")
    private String orderNotifyUrl;
    @Value("${weixin.replaceOrderNotifyUrl}")
    private String replaceOrderNotifyUrl;
    @Resource
    private IHotelOrderLogService hotelOrderLogService;
    @Resource
    private IHotelShopService hotelShopService;
    @Resource
    private IHotelMemberAccountService hotelMemberAccountService;
    @Resource
    private IHotelBalanceLogService hotelBalanceLogService;
    @Resource
    private IHotelCategoryService hotelCategoryService;
    @Resource
    private IHotelOrderFlowService hotelOrderFlowService;
    @Resource
    private IHotelCouponLogService hotelCouponLogService;
    @Resource
    private IHotelOrderDetailService hotelOrderDetailService;
    @Resource
    private ISysBaseAPI sysBaseAPI;
    @Resource
    private ISysUserRoleService sysUserRoleService;
    @Resource
    private ISysUserService sysUserService;




    @Override
    public Result<?> orderPage(OrderPageReq orderPageReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPageReq.getToken());
        Page<HotelOrder> page = new Page<>(orderPageReq.getPageNo(), orderPageReq.getPageSize());
        LambdaQueryChainWrapper<HotelOrder> queryChainWrapper = hotelOrderService.lambdaQuery();
        queryChainWrapper.eq(HotelOrder::getDelFlag , 0);
        if(StringUtils.isBlank(orderPageReq.getUid())){
            queryChainWrapper.and(ew->ew.eq(HotelOrder::getUserId,hanHaiMember.getId()).or().eq(HotelOrder::getShopId,hanHaiMember.getId()));


        }else{
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hanHaiMember.getId())
                    .one();
            HanHaiMember haiMember = hanHaiMemberService.lambdaQuery()
                    .eq(HanHaiMember::getId, orderPageReq.getUid())
                    .eq(HanHaiMember::getShopId, hotelShop.getId())
                    .one();
            if(haiMember == null){
                throw new JeecgBootException("数据错误，请刷新重试");
            }
            queryChainWrapper.eq(HotelOrder::getUserId,orderPageReq.getUid());
        }


        if(orderPageReq.getType() != null){
            queryChainWrapper.eq(HotelOrder::getType,orderPageReq.getType());
        }
        Page<HotelOrder> hotelOrderPage = queryChainWrapper.orderByDesc(HotelOrder::getCreateTime).page(page);


        return Result.OK(hotelOrderPage);
    }

    @Override
    public Result<?> orderPage2(OrderPageReq orderPageReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPageReq.getToken());
        Page<HotelOrderLog> page = new Page<>(orderPageReq.getPageNo(), orderPageReq.getPageSize());
        IPage<HotelOrderLog> orderLogPage = null;
        if(StringUtils.isNotBlank(orderPageReq.getUid())){
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hanHaiMember.getId())
                    .one();
            HanHaiMember haiMember = hanHaiMemberService.lambdaQuery()
                    .eq(HanHaiMember::getId, orderPageReq.getUid())
                    .eq(HanHaiMember::getShopId, hotelShop.getId())
                    .one();
            if(haiMember == null){
                throw new JeecgBootException("数据错误，请刷新重试");
            }
            orderLogPage = hotelOrderLogService.getOrderLogPage(page, hanHaiMember.getId(), orderPageReq.getType(),orderPageReq.getUid());
        }else{
            orderLogPage = hotelOrderLogService.getOrderLogPage(page, hanHaiMember.getId(), orderPageReq.getType(),null);
        }


        return Result.OK(orderLogPage);
    }

    @Override
    public Result<?> orderPage3(OrderPageReq orderPageReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPageReq.getToken());
        Page<HotelOrder> page = new Page<>(orderPageReq.getPageNo(), orderPageReq.getPageSize());
        IPage<HotelOrder> orderPage = null;
        if(StringUtils.isNotBlank(orderPageReq.getUid())){
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hanHaiMember.getId())
                    .one();
            HanHaiMember haiMember = hanHaiMemberService.lambdaQuery()
                    .eq(HanHaiMember::getId, orderPageReq.getUid())
                    .eq(HanHaiMember::getShopId, hotelShop.getId())
                    .one();
            if(haiMember == null){
                throw new JeecgBootException("数据错误，请刷新重试");
            }
            orderPage = hotelOrderService.getOrderLogPage(page, hanHaiMember.getId(), orderPageReq.getType(),orderPageReq.getUid());
        }else{
            orderPage = hotelOrderService.getOrderLogPage(page, hanHaiMember.getId(), orderPageReq.getType(),null);
        }


        return Result.OK(orderPage);
    }

    @Override
    public Result<?> shopWashOrderPage(OrderPageReq orderPageReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPageReq.getToken());
        Page<HotelOrder> page = new Page<>(orderPageReq.getPageNo(), orderPageReq.getPageSize());
        IPage<HotelOrder> shopWashOrderPage = hotelOrderService.getShopWashOrderPage(page, hanHaiMember.getId());
        BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
        if(shopWashOrderPage != null && shopWashOrderPage.getRecords().size() != 0){
            for (HotelOrder hotelOrder:shopWashOrderPage.getRecords()){
                BigDecimal multiply = hotelOrder.getOrderPay().multiply(platformServiceRate);
                hotelOrder.setOrderPay(hotelOrder.getOrderPay().subtract(multiply));
            }
        }
        return Result.OK(shopWashOrderPage);
    }


    @Override
    public Result<?> orderDetail(String id, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getUserId, hanHaiMember.getId())
                .one();
//        HotelOrder byId = hotelOrderService.getById(id);
        HotelOrder hotelOrder = null;
//        if(hotelShop == null){
            hotelOrder = hotelOrderService.getOrderOne(id,hanHaiMember.getId());
//        }else if(byId.getType() == 0 ){
//            hotelOrder = hotelOrderService.getOrderOne2(id,hotelShop.getUserId());
//        }
        List<HotelOrderFlow> hotelOrderFlows = hotelOrderFlowService.lambdaQuery()
                .eq(HotelOrderFlow::getDelFlag, 0)
                .eq(HotelOrderFlow::getPid, hotelOrder.getType())
                .orderByAsc(HotelOrderFlow::getSort)
                .list();
        hotelOrder.setHotelOrderFlows(hotelOrderFlows);

//        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
//                .eq(HotelOrder::getDelFlag, 0)
//                .and(qw -> qw.eq(HotelOrder::getShopId, hanHaiMember.getId()).or().eq(HotelOrder::getUserId, hanHaiMember.getId()))
//                .eq(HotelOrder::getId, id)
//                .one();
        return Result.OK(hotelOrder);
    }

    @Override
    public Result<?> orderDetail2(String id, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.getOrderLogOne(hanHaiMember.getId(), id);
        return Result.OK(hotelOrderLog);
    }

    @Override
    public Result<?> orderDetail3(String id, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        HotelOrder hotelOrder = hotelOrderService.getOrderOne3(id,hanHaiMember.getId());
        BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
        BigDecimal multiply = hotelOrder.getOrderPay().multiply(platformServiceRate);
        hotelOrder.setShopCoin(hotelOrder.getOrderPay().subtract(multiply).setScale(2,BigDecimal.ROUND_HALF_UP));
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();
        hotelOrder.setOrderDetails(hotelOrderDetails);
        List<HotelOrderFlow> hotelOrderFlows = hotelOrderFlowService.lambdaQuery()
                .eq(HotelOrderFlow::getDelFlag, 0)
                .eq(HotelOrderFlow::getPid, hotelOrder.getType())
                .orderByAsc(HotelOrderFlow::getSort)
                .list();
        hotelOrder.setHotelOrderFlows(hotelOrderFlows);

        return Result.OK(hotelOrder);
    }

    @Override
    public Result<?> shopWashOrderDetail(String id, String token) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        HotelOrder hotelOrder = hotelOrderService.getOrderOne3(id,hanHaiMember.getId());
        BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
        BigDecimal multiply = hotelOrder.getOrderPay().multiply(platformServiceRate);
        hotelOrder.setOrderPay(hotelOrder.getOrderPay().subtract(multiply));
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();
        hotelOrder.setOrderDetails(hotelOrderDetails);
        List<HotelOrderFlow> hotelOrderFlows = hotelOrderFlowService.lambdaQuery()
                .eq(HotelOrderFlow::getDelFlag, 0)
                .eq(HotelOrderFlow::getPid, hotelOrder.getType())
                .orderByAsc(HotelOrderFlow::getSort)
                .list();
        hotelOrder.setHotelOrderFlows(hotelOrderFlows);

        return Result.OK(hotelOrder);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> createOrder(String req,  String token) {
        Integer n = (Integer) redisUtil.get("create:order:"+token);
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("create:order:"+token,1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        if(StringUtils.isBlank(req)){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        List<CreateOrderReq> createOrderReqs = JSON.parseArray(req, CreateOrderReq.class);
        if(createOrderReqs == null || createOrderReqs.size() == 0){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        List<HotelOrder> hotelOrders = new ArrayList<>();
        List<HotelOrder> hotelOrders2 = new ArrayList<>();
        BigDecimal totalPrice = BigDecimal.ZERO;
        BigDecimal restPrice = BigDecimal.ZERO;
        HotelOrderLog hotelOrderLog = new HotelOrderLog();
        hotelOrderLog.setId(IdWorker.getIdStr());

        for (CreateOrderReq createOrderReq:createOrderReqs){


            Long count = hotelAddressService.lambdaQuery()
                    .eq(HotelAddress::getDelFlag, 0)
                    .eq(HotelAddress::getUserId, hanHaiMember.getId())
                    .count();
            if (count == 0){
                throw new JeecgBootException("请先添加地址");
            }
            HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                    .eq(HotelAddress::getDelFlag, 0)
                    .eq(HotelAddress::getUserId, hanHaiMember.getId())
                    .eq(HotelAddress::getId, createOrderReq.getAddressId())
                    .one();
            if(hotelAddress == null){
                throw new JeecgBootException("请选择地址");
            }
            HotelConf hotelConf = hotelConfService.lambdaQuery()
                    .eq(HotelConf::getDelFlag, 0)
                    .eq(HotelConf::getName, "depositPrice")
                    .one();
            BigDecimal depositPrice = new BigDecimal(hotelConf.getValue());



            HotelOrder hotelOrder = new HotelOrder();
            HotelOrder hotelOrder2 = null;

            //租赁逻辑
            if(createOrderReq.getType() == 0){
                hotelOrderLog.setType(0);
                hotelOrder2 = new HotelOrder();
                if(StringUtils.isBlank(createOrderReq.getId())){
                    throw new JeecgBootException("商品信息错误");
                }
                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, createOrderReq.getId())
                        .one();
                if(hotelGoods == null){
                    throw new JeecgBootException("商品信息错误");
                }

                if(StringUtils.isBlank(createOrderReq.getSkuId())){
                    throw new JeecgBootException("请选择规格");
                }

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, createOrderReq.getSkuId())
                        .one();
                if(hotelGoodsSku == null){
                    throw new JeecgBootException("规格信息错误");
                }

                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelGoods.getCategoryId())
                        .one();

                BigDecimal price = depositPrice.multiply(new BigDecimal(createOrderReq.getNum()));
                totalPrice = totalPrice.add(price);

                hotelOrder.setTitle(hotelGoods.getName());
                hotelOrder.setPic(hotelGoods.getPic());
                hotelOrder.setUserName(hotelAddress.getName());
                hotelOrder.setUserPhone(hotelAddress.getPhone());
                hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
                hotelOrder.setUserId(hanHaiMember.getId());
//                hotelOrder.setShopId(hotelShop.getUserId());
                hotelOrder.setDeposit(price);
                hotelOrder.setType(0);
                hotelOrder.setStatus(0);
                hotelOrder.setGoodsId(hotelGoods.getId());
                hotelOrder.setGoodsName(hotelGoods.getName());
                hotelOrder.setSkuId(hotelGoodsSku.getId());
                hotelOrder.setSku(hotelGoodsSku.getTitle());
                hotelOrder.setNum(createOrderReq.getNum());
                hotelOrder.setOrderPay(price);
                hotelOrder.setOrderLogId(hotelOrderLog.getId());
                hotelOrder.setWashShopFlag(0);
                hotelOrder.setCategoryId(hotelCategory.getId());
                hotelOrder.setOriginalPrice(price);

                /*水洗店*/
//                hotelOrder2.setTitle(hotelGoods.getName());
//                hotelOrder2.setPic(hotelGoods.getPic());
//                hotelOrder2.setUserName(hotelShop.getUserName());
//                hotelOrder2.setUserPhone(hotelShop.getPhone());
//                hotelOrder2.setUserAddress(hotelShop.getAddress());
//                hotelOrder2.setUserId(hotelShop.getUserId());
//                hotelOrder2.setDeposit(price);
//                hotelOrder2.setType(0);
//                hotelOrder2.setStatus(0);
//                hotelOrder2.setGoodsId(hotelGoods.getId());
//                hotelOrder2.setGoodsName(hotelGoods.getName());
//                hotelOrder2.setSkuId(hotelGoodsSku.getId());
//                hotelOrder2.setSku(hotelGoodsSku.getTitle());
//                hotelOrder2.setNum(createOrderReq.getNum());
//                hotelOrder2.setOrderPay(price);
//                hotelOrder2.setOrderLogId(hotelOrderLog.getId());
//                hotelOrder2.setWashShopFlag(1);
//                hotelOrder2.setCategoryId(hotelCategory.getId());


            }else if(createOrderReq.getType() == 1){/*水洗逻辑*/
                hotelOrderLog.setType(1);
                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, createOrderReq.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }
                if(hotelLeaseLog.getLeaseFlag() == 1 && hotelLeaseLog.getStartTime() == null){
                    throw new JeecgBootException("还未确认收货，无法水洗");
                }

                HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
                        .eq(HotelOrder::getDelFlag, 0)
                        .eq(HotelOrder::getType, 1)
                        .in(HotelOrder::getStatus, 4, 5, 6, 16)
                        .eq(HotelOrder::getLeaseId, hotelLeaseLog.getId())
                        .one();
                if(hotelOrder1 != null){
                    throw new JeecgBootException("该租赁正在水洗中");
                }
//                if(!StringUtils.equals(createOrderReq.getShopId(), hotelLeaseLog.getShopId())){
//                    throw new JeecgBootException("所选择的店铺不是绑定店铺");
//                }

//                if(StringUtils.isBlank(createOrderReq.getId())){
//                    throw new JeecgBootException("商品信息错误");
//                }


                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelLeaseLog.getCategoryId())
                        .one();

                /*相差天数*/
                Long untilDay = new Long(0);
                BigDecimal sumDepositPrice = BigDecimal.ZERO;

                if(hotelLeaseLog.getLeaseFlag() == 1){
                    HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                            .eq(HotelGoodsSku::getDelFlag, 0)
                            .eq(HotelGoodsSku::getId, hotelLeaseLog.getSkuId())
                            .one();
                    if(hotelGoodsSku == null){
                        throw new JeecgBootException("规格信息错误");
                    }
                    untilDay = DateUtils2.getUntilDay(hotelLeaseLog.getStartTime(), DateUtils2.getDate(DateUtils2.getNowDate()));
//                untilDay = untilDay == null
                    /*租金费用*/
                    sumDepositPrice = hotelGoodsSku.getPrice().multiply(new BigDecimal(untilDay));
                }

                /*水洗费用*/
                BigDecimal washPrice = hotelCategory.getPrice().multiply(new BigDecimal(hotelLeaseLog.getNum()));
                /*总费用*/
                BigDecimal countPrice = sumDepositPrice.add(washPrice);
                totalPrice = totalPrice.add(countPrice);

                hotelOrder.setTitle(hotelLeaseLog.getGoodsName());
                hotelOrder.setPic(hotelLeaseLog.getGoodsPic());
                hotelOrder.setUserName(hotelAddress.getName());
                hotelOrder.setUserPhone(hotelAddress.getPhone());
                hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
                hotelOrder.setUserId(hanHaiMember.getId());
                hotelOrder.setShopId(hotelShop.getUserId());
                hotelOrder.setRentPay(sumDepositPrice);
                hotelOrder.setWashPay(washPrice);
                hotelOrder.setOrderPay(countPrice);
                hotelOrder.setType(1);
                hotelOrder.setStatus(3);
                hotelOrder.setOriginalPrice(countPrice);
                if(StringUtils.isNotBlank(hotelLeaseLog.getGoodsId())){
                    hotelOrder.setGoodsId(hotelLeaseLog.getGoodsId());
                }

                hotelOrder.setGoodsName(hotelLeaseLog.getGoodsName());
                if(StringUtils.isNotBlank(hotelLeaseLog.getSkuId())){
                    hotelOrder.setSkuId(hotelLeaseLog.getSkuId());
                }

                hotelOrder.setSku(hotelLeaseLog.getSku());
                hotelOrder.setNum(hotelLeaseLog.getNum());
                hotelOrder.setOrderLogId(hotelOrderLog.getId());
                hotelOrder.setLeaseId(hotelLeaseLog.getId());

            }
            hotelOrders.add(hotelOrder);
            if(hotelOrder2 != null){
                hotelOrders2.add(hotelOrder2);
            }
        }
        hotelOrderLog.setOrderPay(totalPrice);
        hotelOrderLog.setUserId(hanHaiMember.getId());
        hotelOrderLogService.save(hotelOrderLog);

        hotelOrderService.saveBatch(hotelOrders);
        hotelOrderService.saveBatch(hotelOrders2);

//        BigDecimal multiply = price.multiply(new BigDecimal(100));
//        mpWxPayService.createOrder(hotelGoods.getName(), "127.0.0.1", hotelGoods.getId(), multiply.intValue(), hotelOrder.getId(), "{}", hanHaiMember.getAppOpenid());

//        this.testPay(hotelOrder.getId());
        return Result.OK(hotelOrderLog);
    }

    @Override
    public Result<?> createOrder2(String req, String token) {

        Integer n = (Integer) redisUtil.get("create:order:"+token);
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("create:order:"+token,1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        if(StringUtils.isBlank(req)){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        List<CreateOrderReq> createOrderReqs = JSON.parseArray(req, CreateOrderReq.class);
        if(createOrderReqs == null || createOrderReqs.size() == 0){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        Long count = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .count();
        if (count == 0){
            throw new JeecgBootException("请先添加地址");
        }
        HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .eq(HotelAddress::getId, createOrderReqs.get(0).getAddressId())
                .one();
        if(hotelAddress == null){
            throw new JeecgBootException("请选择地址");
        }

        //押金
        String depositPrice1 = hotelConfService.getConf("depositPrice");
        BigDecimal depositPrice = new BigDecimal(depositPrice1);

        //押金优惠券开关
        Integer couponFlag = Integer.parseInt(hotelConfService.getConf("couponFlag"));
        //押金券额
        BigDecimal couponPrice = new BigDecimal(hotelConfService.getConf("couponPrice"));
        //押金优惠券条件
        BigDecimal couponCondition = new BigDecimal(hotelConfService.getConf("couponCondition"));

        //租金优惠券开关
        Integer leaseCouponFlag = Integer.parseInt(hotelConfService.getConf("leaseCouponFlag"));
        //租金券额
        BigDecimal leaseCouponPrice = new BigDecimal(hotelConfService.getConf("leaseCouponPrice"));
        //租金优惠券条件
        BigDecimal leaseCouponCondition = new BigDecimal(hotelConfService.getConf("leaseCouponCondition"));


        List<HotelOrderDetail> hotelOrderDetails = new ArrayList<>();
        BigDecimal totalPrice = BigDecimal.ZERO;
        BigDecimal totalRentPrice = BigDecimal.ZERO;
        BigDecimal totalwashPrice = BigDecimal.ZERO;
        HotelOrderLog hotelOrderLog = new HotelOrderLog();
        hotelOrderLog.setId(IdWorker.getIdStr());

        HotelOrder hotelOrder = new HotelOrder();
        hotelOrder.setId(IdWorker.getIdStr());
        hotelOrder.setUserName(hotelAddress.getName());
        hotelOrder.setUserPhone(hotelAddress.getPhone());
        hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
        hotelOrder.setUserId(hanHaiMember.getId());
        hotelOrder.setType(0);
        hotelOrder.setStatus(0);
        hotelOrder.setWashShopFlag(0);
        hotelOrder.setOrderLogId(hotelOrderLog.getId());
        for (CreateOrderReq createOrderReq:createOrderReqs){
            HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
            hotelOrderDetail.setOrderId(hotelOrder.getId());

            //租赁逻辑
            if(createOrderReq.getType() == 0){
                hotelOrder.setTitle("押金租赁");
                hotelOrderLog.setType(0);
                if(StringUtils.isBlank(createOrderReq.getId())){
                    throw new JeecgBootException("商品信息错误");
                }
                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, createOrderReq.getId())
                        .one();
                if(hotelGoods == null){
                    throw new JeecgBootException("商品信息错误");
                }

                if(StringUtils.isBlank(createOrderReq.getSkuId())){
                    throw new JeecgBootException("请选择规格");
                }

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, createOrderReq.getSkuId())
                        .one();
                if(hotelGoodsSku == null){
                    throw new JeecgBootException("规格信息错误");
                }

                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelGoods.getCategoryId())
                        .one();

                BigDecimal price = depositPrice.multiply(new BigDecimal(createOrderReq.getNum()));
                totalPrice = totalPrice.add(price);
                hotelOrder.setDeposit(totalPrice);


                hotelOrderDetail.setPic(hotelGoods.getPic());
                hotelOrderDetail.setDeposit(price);
                hotelOrderDetail.setGoodsId(hotelGoods.getId());
                hotelOrderDetail.setGoodsName(hotelGoods.getName());
                hotelOrderDetail.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail.setNum(createOrderReq.getNum());
                hotelOrderDetail.setOrderPay(price);
                hotelOrderDetail.setCategoryId(hotelCategory.getId());
                hotelOrderDetail.setOriginalPrice(price);
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);
            }else if(createOrderReq.getType() == 1){//水洗逻辑
                hotelOrderLog.setType(1);
                hotelOrder.setType(1);
                hotelOrder.setStatus(3);

                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, createOrderReq.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }
                if(hotelLeaseLog.getLeaseFlag() == 1 && hotelLeaseLog.getStartTime() == null){
                    throw new JeecgBootException("还未确认收货，无法水洗");
                }

                List<HotelOrderDetail> hotelOrderDetailList = hotelOrderDetailService.lambdaQuery()
                        .eq(HotelOrderDetail::getDelFlag, 0)
                        .eq(HotelOrderDetail::getLeaseId, hotelLeaseLog.getId())
                        .list();

                if(hotelOrderDetailList != null && hotelOrderDetailList.size() > 0){
                    HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
                            .eq(HotelOrder::getDelFlag, 0)
                            .eq(HotelOrder::getType, 1)
                            .in(HotelOrder::getStatus, 4, 5, 6, 16)
                            .eq(HotelOrder::getId, hotelOrderDetailList.stream().map(HotelOrderDetail::getOrderId).collect(Collectors.toList()))
                            .one();
                    if(hotelOrder1 != null){
                        throw new JeecgBootException("该租赁正在水洗中");
                    }
                }



                hotelOrder.setOrderLogId(hotelOrderLog.getId());


                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelLeaseLog.getCategoryId())
                        .one();

                /*相差天数*/
                Long untilDay = new Long(0);
                BigDecimal sumDepositPrice = BigDecimal.ZERO;

                if(hotelLeaseLog.getLeaseFlag() == 1){
                    HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                            .eq(HotelGoodsSku::getDelFlag, 0)
                            .eq(HotelGoodsSku::getId, hotelLeaseLog.getSkuId())
                            .one();
                    if(hotelGoodsSku == null){
                        throw new JeecgBootException("规格信息错误");
                    }
                    untilDay = DateUtils2.getUntilDay(hotelLeaseLog.getStartTime(), DateUtils2.getDate(DateUtils2.getNowDate()));
//                untilDay = untilDay == null
                    /*租金费用*/
                    sumDepositPrice = hotelGoodsSku.getPrice().multiply(new BigDecimal(untilDay));
                }
                totalRentPrice = totalRentPrice.add(sumDepositPrice);


                /*水洗费用*/
                BigDecimal washPrice = hotelCategory.getPrice().multiply(new BigDecimal(hotelLeaseLog.getNum()));
                totalwashPrice = totalwashPrice.add(washPrice);
                /*总费用*/
                BigDecimal countPrice = sumDepositPrice.add(washPrice);
                totalPrice = totalPrice.add(countPrice);

                hotelOrder.setTitle("水洗订单");
                hotelOrderDetail.setPic(hotelLeaseLog.getGoodsPic());
                hotelOrder.setShopId(hotelShop.getUserId());
                hotelOrderDetail.setRentPay(sumDepositPrice);
                hotelOrderDetail.setWashPay(washPrice);
                hotelOrderDetail.setOrderPay(countPrice);

                hotelOrderDetail.setOriginalPrice(countPrice);
                if(StringUtils.isNotBlank(hotelLeaseLog.getGoodsId())){
                    hotelOrderDetail.setGoodsId(hotelLeaseLog.getGoodsId());
                }

                hotelOrderDetail.setGoodsName(hotelLeaseLog.getGoodsName());
                if(StringUtils.isNotBlank(hotelLeaseLog.getSkuId())){
                    hotelOrderDetail.setSkuId(hotelLeaseLog.getSkuId());
                }

                hotelOrderDetail.setSku(hotelLeaseLog.getSku());
                hotelOrderDetail.setNum(hotelLeaseLog.getNum());
                hotelOrderDetail.setLeaseId(hotelLeaseLog.getId());
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);
            }
        }

        BigDecimal originalPrice = totalPrice;
        hotelOrder.setOriginalPrice(originalPrice);
        hotelOrder.setDiscountPrice(couponPrice);
        hotelOrder.setRentPay(totalRentPrice);
        hotelOrder.setWashPay(totalwashPrice);
        if(createOrderReqs.get(0).getType() == 0 && couponFlag == 1){

            if(totalPrice.compareTo(couponCondition) >= 0){
                totalPrice = totalPrice.subtract(couponPrice);
            }
        }else if(createOrderReqs.get(0).getType() == 1 && leaseCouponFlag == 1){
            if(totalRentPrice.compareTo(leaseCouponCondition) >= 0){
                totalRentPrice = totalRentPrice.subtract(leaseCouponPrice);
                totalPrice = totalRentPrice.add(totalwashPrice);
                hotelOrder.setRentPay(totalRentPrice);
            }

        }
        hotelOrder.setOrderPay(totalPrice);

        hotelOrderLog.setOrderPay(totalPrice);
        hotelOrderLog.setUserId(hanHaiMember.getId());
        hotelOrderLogService.save(hotelOrderLog);
        hotelOrderDetailService.saveBatch(hotelOrderDetails);
        hotelOrderService.save(hotelOrder);

        return Result.OK(hotelOrderLog);
    }


    @Override
    public Result<?> createOrder3(String req, String token) {

        Integer n = (Integer) redisUtil.get("create:order:"+token);
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("create:order:"+token,1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        if(StringUtils.isBlank(req)){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        List<CreateOrderReq> createOrderReqs = JSON.parseArray(req, CreateOrderReq.class);
        if(createOrderReqs == null || createOrderReqs.size() == 0){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        Long count = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .count();
        if (count == 0){
            throw new JeecgBootException("请先添加地址");
        }
        HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .eq(HotelAddress::getId, createOrderReqs.get(0).getAddressId())
                .one();
        if(hotelAddress == null){
            throw new JeecgBootException("请选择地址");
        }

        //押金
        String depositPrice1 = hotelConfService.getConf("depositPrice");
        BigDecimal depositPrice = new BigDecimal(depositPrice1);

        //押金优惠券开关
        Integer couponFlag = Integer.parseInt(hotelConfService.getConf("couponFlag"));
        //押金券额
        BigDecimal couponPrice = new BigDecimal(hotelConfService.getConf("couponPrice"));
        //押金优惠券条件
        BigDecimal couponCondition = new BigDecimal(hotelConfService.getConf("couponCondition"));

        //租金优惠券开关
        Integer leaseCouponFlag = Integer.parseInt(hotelConfService.getConf("leaseCouponFlag"));
        //租金券额
        BigDecimal leaseCouponPrice = new BigDecimal(hotelConfService.getConf("leaseCouponPrice"));
        //租金优惠券条件
        BigDecimal leaseCouponCondition = new BigDecimal(hotelConfService.getConf("leaseCouponCondition"));


        List<HotelOrderDetail> hotelOrderDetails = new ArrayList<>();
        //总支付金额
        BigDecimal totalPrice = BigDecimal.ZERO;
        //总租金费用
        BigDecimal totalRentPrice = BigDecimal.ZERO;
        //总水洗费用
        BigDecimal totalwashPrice = BigDecimal.ZERO;
        HotelOrderLog hotelOrderLog = new HotelOrderLog();
        hotelOrderLog.setId(IdWorker.getIdStr());

        HotelOrder hotelOrder = new HotelOrder();
        hotelOrder.setId(IdWorker.getIdStr());
        hotelOrder.setUserName(hotelAddress.getName());
        hotelOrder.setUserPhone(hotelAddress.getPhone());
        hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
        hotelOrder.setUserId(hanHaiMember.getId());
        hotelOrder.setType(0);
        hotelOrder.setStatus(0);
        hotelOrder.setWashShopFlag(0);
        hotelOrder.setOrderLogId(hotelOrderLog.getId());
        for (CreateOrderReq createOrderReq:createOrderReqs){
            HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
            hotelOrderDetail.setOrderId(hotelOrder.getId());

            //租赁逻辑
            if(createOrderReq.getType() == 0){
                hotelOrder.setTitle("押金租赁");
                hotelOrderLog.setType(0);
                if(StringUtils.isBlank(createOrderReq.getId())){
                    throw new JeecgBootException("商品信息错误");
                }
                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, createOrderReq.getId())
                        .one();
                if(hotelGoods == null){
                    throw new JeecgBootException("商品信息错误");
                }

                if(StringUtils.isBlank(createOrderReq.getSkuId())){
                    throw new JeecgBootException("请选择规格");
                }

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, createOrderReq.getSkuId())
                        .one();
                if(hotelGoodsSku == null){
                    throw new JeecgBootException("规格信息错误");
                }

                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelGoods.getCategoryId())
                        .one();

                BigDecimal price = depositPrice.multiply(new BigDecimal(createOrderReq.getNum()));
                totalPrice = totalPrice.add(price);
                hotelOrder.setDeposit(totalPrice);


                hotelOrderDetail.setPic(hotelGoods.getPic());
                hotelOrderDetail.setDeposit(price);
                hotelOrderDetail.setGoodsId(hotelGoods.getId());
                hotelOrderDetail.setGoodsName(hotelGoods.getName());
                hotelOrderDetail.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail.setNum(createOrderReq.getNum());
                hotelOrderDetail.setOrderPay(price);
                hotelOrderDetail.setCategoryId(hotelCategory.getId());
                hotelOrderDetail.setOriginalPrice(price);
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);
            }else if(createOrderReq.getType() == 1){//水洗逻辑
                hotelOrderLog.setType(1);
                hotelOrder.setType(1);
                hotelOrder.setStatus(3);

                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, createOrderReq.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }
                if(hotelLeaseLog.getLeaseFlag() == 1 && hotelLeaseLog.getStartTime() == null){
                    throw new JeecgBootException("还未确认收货，无法水洗");
                }
                int num = hotelLeaseLog.getNum() - hotelLeaseLog.getWashNum();
                if(num <= 0 || num<createOrderReq.getNum()){
                    throw new JeecgBootException("当前选择的数量已超过可水洗的最大值");
                }

                List<HotelOrderDetail> hotelOrderDetailList = hotelOrderDetailService.lambdaQuery()
                        .eq(HotelOrderDetail::getDelFlag, 0)
                        .eq(HotelOrderDetail::getLeaseId, hotelLeaseLog.getId())
                        .list();

                if(hotelOrderDetailList != null && hotelOrderDetailList.size() > 0){
                    HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
                            .eq(HotelOrder::getDelFlag, 0)
                            .eq(HotelOrder::getType, 1)
                            .in(HotelOrder::getStatus, 4, 5, 6, 16)
                            .eq(HotelOrder::getId, hotelOrderDetailList.stream().map(HotelOrderDetail::getOrderId).collect(Collectors.toList()))
                            .one();
                    if(hotelOrder1 != null){
                        throw new JeecgBootException("该租赁正在水洗中");
                    }
                }



                hotelOrder.setOrderLogId(hotelOrderLog.getId());


                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelLeaseLog.getCategoryId())
                        .one();

                /*相差天数*/
                Long untilDay = new Long(0);
//                BigDecimal sumDepositPrice = BigDecimal.ZERO;

                List<HotelLeaseLog> hotelLeaseLogList = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getLeaseFlag, 1)
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .list();

                for (HotelLeaseLog hotelLeaseLog2:hotelLeaseLogList){
//                    if(hotelLeaseLog.getLeaseFlag() == 1){
                        HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                                .eq(HotelGoodsSku::getDelFlag, 0)
                                .eq(HotelGoodsSku::getId, hotelLeaseLog2.getSkuId())
                                .one();
                        if(hotelGoodsSku == null){
                            throw new JeecgBootException("规格信息错误");
                        }
                        untilDay = DateUtils2.getUntilDay(hotelLeaseLog2.getStartTime(), DateUtils2.getDate(DateUtils2.getNowDate()));
//                untilDay = untilDay == null
                        /*租金费用*/
                    BigDecimal sumDepositPrice = hotelGoodsSku.getPrice().multiply(new BigDecimal(untilDay).multiply(new BigDecimal(hotelLeaseLog2.getNum())));
                        totalRentPrice = totalRentPrice.add(sumDepositPrice);
//                    }
                }





                /*水洗费用*/
                BigDecimal washPrice = hotelCategory.getPrice().multiply(new BigDecimal(createOrderReq.getNum()));
                totalwashPrice = totalwashPrice.add(washPrice);
                /*总费用*/
                BigDecimal countPrice = totalRentPrice.add(washPrice);
                totalPrice = totalPrice.add(countPrice);

                hotelOrder.setTitle("水洗订单");
                hotelOrderDetail.setPic(hotelLeaseLog.getGoodsPic());
                hotelOrder.setShopId(hotelShop.getUserId());
                hotelOrderDetail.setRentPay(totalRentPrice);
                hotelOrderDetail.setWashPay(washPrice);
                hotelOrderDetail.setOrderPay(countPrice);

                hotelOrderDetail.setOriginalPrice(countPrice);
                if(StringUtils.isNotBlank(hotelLeaseLog.getGoodsId())){
                    hotelOrderDetail.setGoodsId(hotelLeaseLog.getGoodsId());
                }

                hotelOrderDetail.setGoodsName(hotelLeaseLog.getGoodsName());
                if(StringUtils.isNotBlank(hotelLeaseLog.getSkuId())){
                    hotelOrderDetail.setSkuId(hotelLeaseLog.getSkuId());
                }

                hotelOrderDetail.setSku(hotelLeaseLog.getSku());
                hotelOrderDetail.setNum(createOrderReq.getNum());
                hotelOrderDetail.setLeaseId(hotelLeaseLog.getId());
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);

            }
        }

        BigDecimal originalPrice = totalPrice;
        hotelOrder.setOriginalPrice(originalPrice);
        hotelOrder.setDiscountPrice(couponPrice);
        hotelOrder.setRentPay(totalRentPrice);
        hotelOrder.setWashPay(totalwashPrice);
        if(createOrderReqs.get(0).getType() == 0 && couponFlag == 1){

            if(totalPrice.compareTo(couponCondition) >= 0){
                totalPrice = totalPrice.subtract(couponPrice);
            }
        }else if(createOrderReqs.get(0).getType() == 1 && leaseCouponFlag == 1){
            if(totalRentPrice.compareTo(leaseCouponCondition) >= 0){
                totalRentPrice = totalRentPrice.subtract(leaseCouponPrice);
                totalPrice = totalRentPrice.add(totalwashPrice);
                hotelOrder.setRentPay(totalRentPrice);
            }

        }
        hotelOrder.setOrderPay(totalPrice);

        hotelOrderLog.setOrderPay(totalPrice);
        hotelOrderLog.setUserId(hanHaiMember.getId());
        hotelOrderLogService.save(hotelOrderLog);
        hotelOrderDetailService.saveBatch(hotelOrderDetails);
        hotelOrderService.save(hotelOrder);

        return Result.OK(hotelOrderLog);
    }

    @Override
    public Result<?> createOrder4(String req, String token) {

        Integer n = (Integer) redisUtil.get("create:order:"+token);
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("create:order:"+token,1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(token);
        if(StringUtils.isBlank(req)){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        List<CreateOrderReq> createOrderReqs = JSON.parseArray(req, CreateOrderReq.class);
        if(createOrderReqs == null || createOrderReqs.size() == 0){
            throw new JeecgBootException("请求错误，请刷新重试");
        }
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        Long count = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .count();
        if (count == 0){
            throw new JeecgBootException("请先添加地址");
        }
        HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getUserId, hanHaiMember.getId())
                .eq(HotelAddress::getId, createOrderReqs.get(0).getAddressId())
                .one();
        if(hotelAddress == null){
            throw new JeecgBootException("请选择地址");
        }

        //租金
        String depositPrice1 = hotelConfService.getConf("depositPrice");
        BigDecimal depositPrice = new BigDecimal(depositPrice1);

        //押金优惠券开关
        Integer couponFlag = Integer.parseInt(hotelConfService.getConf("couponFlag"));
        //押金券额
        BigDecimal couponPrice = new BigDecimal(hotelConfService.getConf("couponPrice"));
        //押金优惠券条件
        BigDecimal couponCondition = new BigDecimal(hotelConfService.getConf("couponCondition"));

        //租金优惠券开关
        Integer leaseCouponFlag = Integer.parseInt(hotelConfService.getConf("leaseCouponFlag"));
        //租金券额
        BigDecimal leaseCouponPrice = new BigDecimal(hotelConfService.getConf("leaseCouponPrice"));
        //租金优惠券条件
        BigDecimal leaseCouponCondition = new BigDecimal(hotelConfService.getConf("leaseCouponCondition"));


        List<HotelOrderDetail> hotelOrderDetails = new ArrayList<>();
        //总支付金额
        BigDecimal totalPrice = BigDecimal.ZERO;
        //总租金费用
        BigDecimal totalRentPrice = BigDecimal.ZERO;
        //总水洗费用
        BigDecimal totalwashPrice = BigDecimal.ZERO;
        HotelOrderLog hotelOrderLog = new HotelOrderLog();
        hotelOrderLog.setId(IdWorker.getIdStr());

        HotelOrder hotelOrder = new HotelOrder();
        hotelOrder.setId(IdWorker.getIdStr());
        hotelOrder.setUserName(hotelAddress.getName());
        hotelOrder.setUserPhone(hotelAddress.getPhone());
        hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
        hotelOrder.setUserId(hanHaiMember.getId());
        hotelOrder.setType(0);
        hotelOrder.setStatus(0);
        hotelOrder.setWashShopFlag(0);
        hotelOrder.setOrderLogId(hotelOrderLog.getId());
        for (CreateOrderReq createOrderReq:createOrderReqs){
            HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
            hotelOrderDetail.setOrderId(hotelOrder.getId());

            //租赁逻辑
            if(createOrderReq.getType() == 0){
                hotelOrder.setTitle("押金租赁");
                hotelOrderLog.setType(0);
                if(StringUtils.isBlank(createOrderReq.getId())){
                    throw new JeecgBootException("商品信息错误");
                }
                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, createOrderReq.getId())
                        .one();
                if(hotelGoods == null){
                    throw new JeecgBootException("商品信息错误");
                }

                if(StringUtils.isBlank(createOrderReq.getSkuId())){
                    throw new JeecgBootException("请选择规格");
                }

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, createOrderReq.getSkuId())
                        .one();
                if(hotelGoodsSku == null){
                    throw new JeecgBootException("规格信息错误");
                }

                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelGoods.getCategoryId())
                        .one();

                //计算押金
                BigDecimal price = hotelGoodsSku.getPrice().multiply(new BigDecimal(createOrderReq.getNum()));
                totalPrice = totalPrice.add(price);
                hotelOrder.setDeposit(totalPrice);


                hotelOrderDetail.setPic(hotelGoods.getPic());
                hotelOrderDetail.setDeposit(price);
                hotelOrderDetail.setGoodsId(hotelGoods.getId());
                hotelOrderDetail.setGoodsName(hotelGoods.getName());
                hotelOrderDetail.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail.setSku(hotelGoodsSku.getColour()+","+hotelGoodsSku.getTitle());
                hotelOrderDetail.setNum(createOrderReq.getNum());
                hotelOrderDetail.setOrderPay(price);
                hotelOrderDetail.setCategoryId(hotelCategory.getId());
                hotelOrderDetail.setOriginalPrice(price);
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);
            }else if(createOrderReq.getType() == 1){//水洗逻辑
                hotelOrderLog.setType(1);
                hotelOrder.setType(1);
                hotelOrder.setStatus(3);

                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, createOrderReq.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }
                if(hotelLeaseLog.getLeaseFlag() == 1 && hotelLeaseLog.getStartTime() == null){
                    throw new JeecgBootException("还未确认收货，无法水洗");
                }
                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelLeaseLog.getCategoryId())
                        .one();
                int num = hotelLeaseLog.getNum() - createOrderReq.getNum();
                HotelLeaseLog newLeaseLog = null;
                if(num > 0){
                    //新物品
                    newLeaseLog = new HotelLeaseLog();
                    BeanUtils.copyProperties(hotelLeaseLog, newLeaseLog);
                    newLeaseLog.setId(IdWorker.getIdStr());
                    newLeaseLog.setNum(createOrderReq.getNum());
                    BigDecimal multiply1 = hotelCategory.getPrice().multiply(new BigDecimal(createOrderReq.getNum()));
                    newLeaseLog.setPrice(multiply1);
                    newLeaseLog.setPid(hotelLeaseLog.getId());
                    newLeaseLog.setCreateTime(new Date());

                    //旧物品修改
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setNum(num);
                    BigDecimal multiply = hotelCategory.getPrice().multiply(new BigDecimal(num));
                    hotelLeaseLog1.setPrice(multiply);
                    hotelLeaseLogService.updateById(hotelLeaseLog1);
                }


                List<HotelOrderDetail> hotelOrderDetailList = hotelOrderDetailService.lambdaQuery()
                        .eq(HotelOrderDetail::getDelFlag, 0)
                        .eq(HotelOrderDetail::getLeaseId, hotelLeaseLog.getId())
                        .list();

                if(hotelOrderDetailList != null && hotelOrderDetailList.size() > 0){
                    HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
                            .eq(HotelOrder::getDelFlag, 0)
                            .eq(HotelOrder::getType, 1)
                            .in(HotelOrder::getStatus, 4, 5, 6, 16)
                            .eq(HotelOrder::getId, hotelOrderDetailList.stream().map(HotelOrderDetail::getOrderId).collect(Collectors.toList()))
                            .one();
                    if(hotelOrder1 != null){
                        throw new JeecgBootException("该租赁正在水洗中");
                    }
                }



                hotelOrder.setOrderLogId(hotelOrderLog.getId());




                /*相差天数*/
                Long untilDay = new Long(0);
//                BigDecimal sumDepositPrice = BigDecimal.ZERO;

                List<HotelLeaseLog> hotelLeaseLogList = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getLeaseFlag, 1)
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .list();

                for (HotelLeaseLog hotelLeaseLog2:hotelLeaseLogList){
//                    if(hotelLeaseLog.getLeaseFlag() == 1){
                    HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
                            .eq(HotelOrder::getId, hotelLeaseLog2.getOrderId())
                            .eq(HotelOrder::getStatus, 15)
                            .one();
                    if(hotelOrder1 == null){
                        continue;
                    }
                    HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                            .eq(HotelGoodsSku::getDelFlag, 0)
                            .eq(HotelGoodsSku::getId, hotelLeaseLog2.getSkuId())
                            .one();
                    if(hotelGoodsSku == null){
                        throw new JeecgBootException("规格信息错误");
                    }
                    untilDay = DateUtils2.getUntilDay(hotelLeaseLog2.getStartTime(), DateUtils2.getDate(DateUtils2.getNowDate()));
//                untilDay = untilDay == null
                    /*租金费用*/
                    BigDecimal sumDepositPrice = depositPrice.multiply(new BigDecimal(untilDay).multiply(new BigDecimal(hotelLeaseLog2.getNum())));
                    totalRentPrice = totalRentPrice.add(sumDepositPrice);
//                    }
                }





                /*水洗费用*/
                BigDecimal washPrice = hotelCategory.getPrice().multiply(new BigDecimal(createOrderReq.getNum()));
                totalwashPrice = totalwashPrice.add(washPrice);
                /*总费用*/
                BigDecimal countPrice = totalRentPrice.add(washPrice);
                totalPrice = totalPrice.add(countPrice);

                hotelOrder.setTitle("水洗订单");
                hotelOrderDetail.setPic(hotelLeaseLog.getGoodsPic());
                hotelOrder.setShopId(hotelShop.getUserId());
                hotelOrderDetail.setRentPay(totalRentPrice);
                hotelOrderDetail.setWashPay(washPrice);
                hotelOrderDetail.setOrderPay(countPrice);

                hotelOrderDetail.setOriginalPrice(countPrice);
                if(StringUtils.isNotBlank(hotelLeaseLog.getGoodsId())){
                    hotelOrderDetail.setGoodsId(hotelLeaseLog.getGoodsId());
                }

                hotelOrderDetail.setGoodsName(hotelLeaseLog.getGoodsName());
                if(StringUtils.isNotBlank(hotelLeaseLog.getSkuId())){
                    hotelOrderDetail.setSkuId(hotelLeaseLog.getSkuId());
                }

                hotelOrderDetail.setSku(hotelLeaseLog.getSku());
                hotelOrderDetail.setNum(createOrderReq.getNum());
                hotelOrderDetail.setLeaseId(newLeaseLog == null ?hotelLeaseLog.getId():newLeaseLog.getId());
                hotelOrderDetail.setOrderId(hotelOrder.getId());
                hotelOrderDetails.add(hotelOrderDetail);

                //新增新物品
                if(newLeaseLog != null){
                    hotelLeaseLogService.save(newLeaseLog);
                }
            }
        }

        BigDecimal originalPrice = totalPrice;
        hotelOrder.setOriginalPrice(originalPrice);

        hotelOrder.setRentPay(totalRentPrice);
        hotelOrder.setWashPay(totalwashPrice);
        if(createOrderReqs.get(0).getType() == 0 && couponFlag == 1){

            if(totalPrice.compareTo(couponCondition) >= 0){
                totalPrice = totalPrice.subtract(couponPrice);
                hotelOrder.setDiscountPrice(couponPrice);
            }
        }else if(createOrderReqs.get(0).getType() == 1 && leaseCouponFlag == 1){
            if(totalRentPrice.compareTo(leaseCouponCondition) >= 0){
                totalRentPrice = totalRentPrice.subtract(leaseCouponPrice);
                totalPrice = totalRentPrice.add(totalwashPrice);
                hotelOrder.setRentPay(totalRentPrice);
                hotelOrder.setDiscountPrice(leaseCouponPrice);
            }

        }
        hotelOrder.setOrderPay(totalPrice);

        hotelOrderLog.setOrderPay(totalPrice);
        hotelOrderLog.setUserId(hanHaiMember.getId());
        hotelOrderLogService.save(hotelOrderLog);
        hotelOrderDetailService.saveBatch(hotelOrderDetails);
        hotelOrderService.save(hotelOrder);


        return Result.OK(hotelOrderLog);
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> orderPay(OrderPayReq orderPayReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPayReq.getToken());

        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, orderPayReq.getId())
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        String orderNo = hotelOrderLog.getId();
        HotelCouponLog hotelCouponLog = hotelCouponLogService.lambdaQuery()
                .eq(HotelCouponLog::getDelFlag, 0)
                .eq(HotelCouponLog::getStatus,0)
                .eq(HotelCouponLog::getUserId, hanHaiMember.getId())
                .eq(HotelCouponLog::getId, orderPayReq.getCouponId())
                .one();

//        if(hotelOrderLog.getType() == 1){
//            hotelOrderService.lambdaQuery()
//                    .eq(HotelOrder::getDelFlag, 0)
//                    .eq(HotelOrder::getType, 1)
//                    .eq(HotelOrder::get,)
//            HotelOrder hotelOrder1 = hotelOrderService.lambdaQuery()
//                    .eq(HotelOrder::getDelFlag, 0)
//                    .eq(HotelOrder::getType, 1)
//                    .in(HotelOrder::getStatus, 4, 5, 6, 16)
//                    .eq(HotelOrder::getLeaseId, hotelLeaseLog.getId())
//                    .one();
//            if(hotelOrder1 != null){
//                throw new JeecgBootException("该租赁正在水洗中");
//            }
//        }

        //0可使用优惠券 1不可以
        Integer use = 1;
        if(hotelCouponLog!= null){
            if(hotelCouponLog.getType() == 0){
                Long nowMill = DateUtils2.getMilliSecond(DateUtils2.getNowDate());
                if(hotelCouponLog.getEndTime() != null){
                    if(nowMill < DateUtils2.getMilliSecond(hotelCouponLog.getEndTime().toString())){
                        use = 0;
                    }
                }else{
                    String couponTime = hotelConfService.getConf("couponTime");
                    String[] split = StringUtils.split(couponTime, "=");
                    if(nowMill > DateUtils2.getMilliSecond(split[0]) || nowMill < DateUtils2.getMilliSecond(split[1])){
                        use = 0;
                    }
                }
            }else if(hotelCouponLog.getType() == 1){
                use = 0;
            }

        }



        HttpServletRequest req = SpringContextUtils.getHttpServletRequest();
        BigDecimal multiply = hotelOrderLog.getOrderPay();
        HotelOrderLog hotelOrderLog1 = null;
        HotelOrder hotelOrder1 = null;
        //租金
        BigDecimal rentPay = BigDecimal.ZERO;
        BigDecimal washPay = BigDecimal.ZERO;
        if(StringUtils.isNotBlank(orderPayReq.getOrderId()) && hotelOrderLog.getType() == 0){
            HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                    .eq(HotelOrder::getDelFlag, 0)
                    .eq(HotelOrder::getId, orderPayReq.getOrderId())
                    .eq(HotelOrder::getUserId, hanHaiMember.getId())
                    .one();


            hotelOrderLog1 = new HotelOrderLog();
            hotelOrderLog1.setId(IdWorker.getIdStr());
            hotelOrderLog1.setType(hotelOrderLog.getType());
            hotelOrderLog1.setOrderPay(hotelOrder.getOrderPay());
            hotelOrderLog1.setUserId(hotelOrderLog.getUserId());
            multiply = hotelOrderLog1.getOrderPay();
            orderNo = hotelOrderLog1.getId();

            hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setOrderLogId(hotelOrderLog1.getId());
        }

        if(use == 0){
            if(hotelOrderLog1 == null){
                if(hotelOrderLog.getOrderPay().compareTo(hotelCouponLog.getConditionPrice()) >= 0){
                    if(hotelOrderLog.getType() == 0 && hotelCouponLog.getUseType() == 0){
                        multiply = hotelOrderLog.getOrderPay().subtract(hotelCouponLog.getPrice());

                        HotelCouponLog hotelCouponLog1 = new HotelCouponLog();
                        hotelCouponLog1.setId(hotelCouponLog.getId());
                        hotelCouponLog1.setOrderLogId(hotelOrderLog.getId());
                        hotelCouponLogService.updateById(hotelCouponLog1);

                        HotelOrderLog hotelOrderLog2 = new HotelOrderLog();
                        hotelOrderLog2.setId(hotelOrderLog.getId());
                        hotelOrderLog2.setDiscountOrderPay(multiply);
                        hotelOrderLogService.updateById(hotelOrderLog2);
                    }else if(hotelOrderLog.getType() == 1 && hotelCouponLog.getUseType() == 1){//租金
                        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                                .eq(HotelOrder::getDelFlag, 0)
                                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                                .one();
                        rentPay = (hotelOrder.getRentPay() == null?BigDecimal.ZERO:hotelOrder.getRentPay()).subtract(hotelCouponLog.getPrice());
                        multiply = (hotelOrder.getWashPay() == null?BigDecimal.ZERO:hotelOrder.getWashPay()).add(rentPay);
                        HotelCouponLog hotelCouponLog1 = new HotelCouponLog();
                        hotelCouponLog1.setId(hotelCouponLog.getId());
                        hotelCouponLog1.setOrderLogId(hotelOrderLog.getId());
                        hotelCouponLogService.updateById(hotelCouponLog1);

                        HotelOrderLog hotelOrderLog2 = new HotelOrderLog();
                        hotelOrderLog2.setId(hotelOrderLog.getId());
                        hotelOrderLog2.setDiscountOrderPay(multiply);
                        hotelOrderLogService.updateById(hotelOrderLog2);

                        HotelOrder hotelOrder2 = new HotelOrder();
                        hotelOrder2.setId(hotelOrder.getId());
                        hotelOrder2.setRentPay(rentPay);
                        hotelOrderService.updateById(hotelOrder2);

                    }else if(hotelOrderLog.getType() == 1 && hotelCouponLog.getUseType() == 2){//水洗
                        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                                .eq(HotelOrder::getDelFlag, 0)
                                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                                .one();
                        washPay = hotelOrder.getWashPay().subtract(hotelCouponLog.getPrice());
                        multiply = (hotelOrder.getRentPay() == null?BigDecimal.ZERO:hotelOrder.getRentPay()).add(washPay);
                        HotelCouponLog hotelCouponLog1 = new HotelCouponLog();
                        hotelCouponLog1.setId(hotelCouponLog.getId());
                        hotelCouponLog1.setOrderLogId(hotelOrderLog.getId());
                        hotelCouponLogService.updateById(hotelCouponLog1);

                        HotelOrderLog hotelOrderLog2 = new HotelOrderLog();
                        hotelOrderLog2.setId(hotelOrderLog.getId());
                        hotelOrderLog2.setDiscountOrderPay(multiply);
                        hotelOrderLogService.updateById(hotelOrderLog2);

                        HotelOrder hotelOrder2 = new HotelOrder();
                        hotelOrder2.setId(hotelOrder.getId());
                        hotelOrder2.setWashPay(washPay);
                        hotelOrderService.updateById(hotelOrder2);
                    }

                }
            }else{
                if(hotelOrderLog1.getOrderPay().compareTo(hotelCouponLog.getConditionPrice()) >= 0){
                    multiply = hotelOrderLog1.getOrderPay().subtract(hotelCouponLog.getPrice());

                    HotelCouponLog hotelCouponLog1 = new HotelCouponLog();
                    hotelCouponLog1.setId(hotelCouponLog.getId());
                    hotelCouponLog1.setOrderLogId(hotelOrderLog.getId());
                    hotelCouponLogService.updateById(hotelCouponLog1);

                    hotelOrderLog1.setDiscountOrderPay(multiply);
                }
            }


        }

        if(hotelOrderLog1 != null){
            hotelOrderLogService.save(hotelOrderLog1);
            hotelOrderService.updateById(hotelOrder1);
        }

        multiply = multiply.multiply(new BigDecimal(100));
//        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
//                .eq(HotelOrder::getDelFlag, 0)
//                .eq(HotelOrder::getId, orderPayReq.getId())
//                .one();
//
//        HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
//                .eq(HotelGoods::getDelFlag, 0)
//                .eq(HotelGoods::getId, hotelOrder.getGoodsId())
//                .one();


        Object order = mpWxPayService.createOrder("酒店桌布", oConvertUtils.getIpAddrByRequest(req), hotelOrderLog.getId(), multiply.intValue(), orderNo, hanHaiMember.getAppletOpenid(),orderNotifyUrl,"{}");

        return Result.OK(order);
    }

    @Override
    public Result<?> orderPay2(OrderPayReq orderPayReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(orderPayReq.getToken());

        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, orderPayReq.getId())
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        if(hotelOrderLog.getPayInfo() != null){

            Long time = DateUtils2.getMilliSecond(DateUtils2.getYYYYMMDDHHMMSS(hotelOrderLog.getCreateTime()))+ 3600000L;
            if(time < DateUtils2.getMilliSecond(DateUtils2.getNowDate())){
                HotelOrder order = hotelOrderService.lambdaQuery()
                        .eq(HotelOrder::getDelFlag, 0)
                        .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                        .one();
//                HotelOrder hotelOrder = new HotelOrder();
//                hotelOrder.setId(order.getId());
//                hotelOrder.setDelFlag(1);
                hotelOrderService.removeById(order.getId());
                hotelOrderLogService.removeById(hotelOrderLog.getId());


                return Result.error("该订单已超过一小时，无法继续支付，请重新创建订单");
            }

            Object jsonObject = JSON.parseObject(hotelOrderLog.getPayInfo());
            return Result.OK(jsonObject);
        }
        String orderNo = hotelOrderLog.getId();

        HttpServletRequest req = SpringContextUtils.getHttpServletRequest();
        BigDecimal multiply = hotelOrderLog.getOrderPay();

        multiply = multiply.multiply(new BigDecimal(100));
        Object order = mpWxPayService.createOrder("酒店桌布", oConvertUtils.getIpAddrByRequest(req), hotelOrderLog.getId(), multiply.intValue(), orderNo, hanHaiMember.getAppletOpenid(),orderNotifyUrl,"{}");

        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(orderNo);
        hotelOrderLog1.setPayInfo(JSON.toJSONString(order));
        hotelOrderLogService.updateById(hotelOrderLog1);

        return Result.OK(order);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object orderNotify(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, outTradeNo)
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        List<HotelOrder> hotelOrderList = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                .list();

        /*订单未找到*/
        if(hotelOrderList == null || hotelOrderList.size() == 0){
            System.err.println("订单未找到");
            return "FAIL";
        }
        HotelCouponLog hotelCouponLog = hotelCouponLogService.lambdaQuery()
                .eq(HotelCouponLog::getDelFlag, 0)
                .eq(HotelCouponLog::getStatus, 0)
                .eq(HotelCouponLog::getOrderLogId, hotelOrderLog.getId())
                .one();

        BigDecimal divide = BigDecimal.ONE;
        if(hotelCouponLog != null){
            HotelCouponLog hotelCouponLog1 = new HotelCouponLog();
            hotelCouponLog1.setId(hotelCouponLog.getId());
            hotelCouponLog1.setStatus(1);
            hotelCouponLogService.updateById(hotelCouponLog1);
            divide = hotelOrderLog.getDiscountOrderPay().divide(hotelOrderLog.getOrderPay(), 2, BigDecimal.ROUND_HALF_UP);

        }


        List<HotelOrder> hotelOrders = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
        List<HotelOrder> orders = new ArrayList<>();
        Integer type = 0;
        Integer n = 0;
        for (HotelOrder hotelOrder:hotelOrderList) {
            n = n+1;
            /*租赁业务*/
            if(hotelOrder.getType() == 0){
                /*已经处理过订单*/
                if (hotelOrder.getStatus() !=0){
                    return "SUCCESS";
                }
                HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();
                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
//                if(hotelOrder.getWashShopFlag() == 1){//水洗店







//                }else{//用户

                //用户
                hotelLeaseLog.setUserId(hotelOrder.getUserId());
                hotelLeaseLog.setShopId(hotelOrder.getShopId());
                hotelLeaseLog.setOrderId(hotelOrder.getId());
                hotelLeaseLog.setGoodsId(hotelOrder.getGoodsId());
                hotelLeaseLog.setSkuId(hotelOrder.getSkuId());
                hotelLeaseLog.setGoodsName(hotelOrder.getGoodsName());
                hotelLeaseLog.setGoodsPic(hotelOrder.getPic());
                hotelLeaseLog.setSku(hotelOrder.getSku());
                hotelLeaseLog.setStatus(0);
                hotelLeaseLog.setNum(hotelOrder.getNum());
                hotelLeaseLog.setPrice(hotelOrder.getDeposit());
                hotelLeaseLog.setCategoryId(hotelOrder.getCategoryId());


                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, hotelOrder.getGoodsId())
                        .one();

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, hotelOrder.getSkuId())
                        .one();

                HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
                        .eq(HanHaiMember::getId, hotelOrder.getUserId())
                        .one();

                HotelShop hotelShop = hotelShopService.lambdaQuery()
                        .eq(HotelShop::getDelFlag, 0)
                        .eq(HotelShop::getId, hanHaiMember.getShopId())
                        .one();

                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelGoods.getCategoryId())
                        .one();
                /*水洗店*/
                HotelOrder hotelOrder2 = new HotelOrder();
                hotelOrder2.setId(IdWorker.getIdStr());
                hotelOrder2.setTitle(hotelGoods.getName());
                hotelOrder2.setPic(hotelGoods.getPic());
                hotelOrder2.setUserName(hotelShop.getUserName());
                hotelOrder2.setUserPhone(hotelShop.getPhone());
                hotelOrder2.setUserAddress(hotelShop.getAddress());
                hotelOrder2.setUserId(hotelShop.getUserId());
                hotelOrder2.setDeposit(hotelOrder.getDeposit());
                hotelOrder2.setType(0);
                hotelOrder2.setStatus(1);
                hotelOrder2.setGoodsId(hotelGoods.getId());
                hotelOrder2.setGoodsName(hotelGoods.getName());
                hotelOrder2.setSkuId(hotelGoodsSku.getId());
                hotelOrder2.setSku(hotelGoodsSku.getTitle());
                hotelOrder2.setNum(hotelOrder.getNum());
                hotelOrder2.setOrderPay(hotelOrder.getOrderPay());
                hotelOrder2.setOrderLogId(hotelOrderLog.getId());
                hotelOrder2.setWashShopFlag(1);
                hotelOrder2.setCategoryId(hotelCategory.getId());
                orders.add(hotelOrder2);


                //水洗店
                hotelLeaseLog1.setUserId(hotelShop.getUserId());
                hotelLeaseLog1.setOrderId(hotelOrder2.getId());
                hotelLeaseLog1.setGoodsId(hotelOrder2.getGoodsId());
                hotelLeaseLog1.setSkuId(hotelOrder2.getSkuId());
                hotelLeaseLog1.setGoodsName(hotelOrder2.getGoodsName());
                hotelLeaseLog1.setGoodsPic(hotelOrder2.getPic());
                hotelLeaseLog1.setSku(hotelOrder2.getSku());
                hotelLeaseLog1.setStatus(0);
                hotelLeaseLog1.setNum(hotelOrder2.getNum());
                hotelLeaseLog1.setPrice(hotelOrder2.getDeposit());
                hotelLeaseLog1.setFormUserId(hotelOrderLog.getUserId());
                hotelLeaseLog1.setCategoryId(hotelOrder2.getCategoryId());
//                }

                hotelLeaseLogs.add(hotelLeaseLog1);
                hotelLeaseLogs.add(hotelLeaseLog);

                HotelOrder hotelOrder1 = new HotelOrder();
                hotelOrder1.setId(hotelOrder.getId());
                hotelOrder1.setStatus(1);
                BigDecimal multiply = hotelOrder.getOriginalPrice().multiply(divide);
                if(n == hotelOrderList.size()){
                    BigDecimal add = multiply;
                    for (HotelOrder hotelOrder3:hotelOrders){
                        add = add.add(hotelOrder3.getOrderPay());
                        if(add.compareTo(hotelOrderLog.getOrderPay()) == -1){
                            multiply = multiply.add(hotelOrderLog.getOrderPay().subtract(add));
                        }else if(add.compareTo(hotelOrderLog.getOrderPay()) == 1){
                            multiply = multiply.subtract(hotelOrderLog.getOrderPay().subtract(add));
                        }
                    }
                }
                hotelOrder1.setDiscountPrice(hotelOrder.getOriginalPrice().subtract(multiply));
                hotelOrder1.setOrderPay(multiply);
                hotelOrders.add(hotelOrder1);

            }else if(hotelOrder.getType() == 1){/*水洗逻辑*/


                HotelOrder hotelOrder1 = new HotelOrder();
                hotelOrder1.setId(hotelOrder.getId());
                hotelOrder1.setStatus(4);
                hotelOrder1.setOriginalPrice(hotelOrder.getOrderPay());

                if(hotelCouponLog != null){
                    BigDecimal subtract = hotelOrder.getOrderPay().subtract(hotelOrderLog.getDiscountOrderPay());
                    hotelOrder1.setOrderPay(hotelOrderLog.getDiscountOrderPay());
                    hotelOrder1.setDiscountPrice(subtract);
                    if(hotelCouponLog.getUseType() == 1){//租金
                        hotelOrder1.setRentPay(subtract);

                    }else if(hotelCouponLog.getUseType() == 2){ //水洗
                        hotelOrder1.setWashPay(subtract);
                    }
                }
                hotelOrders.add(hotelOrder1);

                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, hotelOrder.getLeaseId())
                        .one();
                if(hotelLeaseLog == null){
                    return "FAIL";
                }
                if(hotelLeaseLog.getLeaseFlag() == 1){
                    type = 1;
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setStartTime(new Date());
                    hotelLeaseLogs.add(hotelLeaseLog1);
                }


            }

        }
        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(hotelOrderLog.getId());
        hotelOrderLog1.setIsPay(1);
        hotelOrderLogService.updateById(hotelOrderLog1);

        if(type == 0){
            hotelLeaseLogService.saveBatch(hotelLeaseLogs);
            hotelOrderService.saveBatch(orders);
        }else{
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);

        }

        hotelOrderService.updateBatchById(hotelOrders);


        //不再通知该结果
        return "SUCCESS";
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object orderNotify2(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, outTradeNo)
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
         HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                .one();

        /*订单未找到*/
        if(hotelOrder == null ){
            System.err.println("订单未找到");
            return "FAIL";
        }

        /*已经处理过订单*/
        if (hotelOrder.getStatus() !=0 && hotelOrder.getStatus() != 3){
            return "SUCCESS";
        }

        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();

        HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
                .eq(HanHaiMember::getId, hotelOrder.getUserId())
                .one();

        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        HotelOrder shopOrder = new HotelOrder();
        shopOrder.setId(IdWorker.getIdStr());
        shopOrder.setTitle(hotelOrder.getTitle());
        List<HotelOrderDetail> hotelOrderDetails1 = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs2 = new ArrayList<>();
        List<HotelOrder> orders = new ArrayList<>();
        Integer type = 0;
        for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails) {
            /*租赁业务*/
            if(hotelOrder.getType() == 0){

                HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();


                //用户
                hotelLeaseLog.setUserId(hotelOrder.getUserId());
                hotelLeaseLog.setShopId(hotelOrder.getShopId());
                hotelLeaseLog.setOrderId(hotelOrder.getId());
                hotelLeaseLog.setOrderDetailId(hotelOrderDetail.getId());
                hotelLeaseLog.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog.setStatus(0);
                hotelLeaseLog.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog.setCategoryId(hotelOrderDetail.getCategoryId());


                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, hotelOrderDetail.getGoodsId())
                        .one();

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, hotelOrderDetail.getSkuId())
                        .one();





                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelOrderDetail.getCategoryId())
                        .one();
                /*水洗店*/
                HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();

                shopOrder.setUserName(hotelShop.getUserName());
                shopOrder.setUserPhone(hotelShop.getPhone());
                shopOrder.setUserAddress(hotelShop.getAddress());
                shopOrder.setUserId(hotelShop.getUserId());
                shopOrder.setDeposit(hotelOrder.getDeposit());
                shopOrder.setType(0);
                shopOrder.setStatus(1);
                shopOrder.setOrderLogId(hotelOrderLog.getId());
                shopOrder.setWashShopFlag(1);
                hotelOrderDetail1.setId(IdWorker.getIdStr());
                hotelOrderDetail1.setPic(hotelGoods.getPic());
                hotelOrderDetail1.setGoodsId(hotelGoods.getId());
                hotelOrderDetail1.setGoodsName(hotelGoods.getName());
                hotelOrderDetail1.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail1.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail1.setNum(hotelOrderDetail.getNum());
                hotelOrderDetail1.setOrderPay(hotelOrderDetail.getOrderPay());
                hotelOrderDetail1.setCategoryId(hotelCategory.getId());
                hotelOrderDetail1.setOrderId(shopOrder.getId());
                hotelOrderDetails1.add(hotelOrderDetail1);


                //水洗店
                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setUserId(hotelShop.getUserId());
                hotelLeaseLog1.setOrderId(shopOrder.getId());
                hotelLeaseLog1.setOrderDetailId(hotelOrderDetail1.getId());
                hotelLeaseLog1.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog1.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog1.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog1.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog1.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog1.setStatus(0);
                hotelLeaseLog1.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog1.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog1.setFormUserId(hotelOrderLog.getUserId());
                hotelLeaseLog1.setCategoryId(hotelOrderDetail.getCategoryId());

                hotelLeaseLogs.add(hotelLeaseLog1);
                hotelLeaseLogs.add(hotelLeaseLog);



            }else if(hotelOrder.getType() == 1){/*水洗逻辑*/


                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, hotelOrderDetail.getLeaseId())
                        .one();
                if(hotelLeaseLog == null){
                    return "FAIL";
                }
                if(hotelLeaseLog.getLeaseFlag() == 1){
                    type = 1;
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setStartTime(new Date());
                    hotelLeaseLogs.add(hotelLeaseLog1);
                }


            }
        }
        //修改订单状态
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        if(hotelOrder.getType() == 0){
            hotelOrder1.setStatus(1);
        }else if(hotelOrder.getType() == 1){
            hotelOrder1.setStatus(4);
        }
        hotelOrderService.updateById(hotelOrder1);

        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(hotelOrderLog.getId());
        hotelOrderLog1.setIsPay(1);
        hotelOrderLogService.updateById(hotelOrderLog1);

        if(type == 0){
            hotelLeaseLogService.saveBatch(hotelLeaseLogs);
            hotelOrderService.save(shopOrder);
            hotelOrderDetailService.saveBatch(hotelOrderDetails1);
        }else{
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);

        }

        if(hotelOrder.getType() == 0){
            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hanHaiMember.getId())
                    .one();
            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setDeposit(hotelMemberAccount.getDeposit().add(hotelOrder.getDeposit()));
            hotelMemberAccountService.updateById(hotelMemberAccount1);

            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setBalance(hotelOrder.getDeposit());
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getDeposit());
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLog.setPayType(0);
            hotelBalanceLog.setUserId(hanHaiMember.getId());
            hotelBalanceLog.setTitle("租赁押金");
            hotelBalanceLogService.save(hotelBalanceLog);
        }



        //不再通知该结果
        return "SUCCESS";
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object orderNotify3(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, outTradeNo)
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                .one();

        /*订单未找到*/
        if(hotelOrder == null ){
            System.err.println("订单未找到");
            return "FAIL";
        }

        /*已经处理过订单*/
        if (hotelOrder.getStatus() !=0 && hotelOrder.getStatus() != 3){
            return "SUCCESS";
        }

        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();

        HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
                .eq(HanHaiMember::getId, hotelOrder.getUserId())
                .one();

        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        HotelOrder shopOrder = new HotelOrder();
        shopOrder.setId(IdWorker.getIdStr());
        shopOrder.setTitle(hotelOrder.getTitle());
        List<HotelOrderDetail> hotelOrderDetails1 = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs2 = new ArrayList<>();
        List<HotelOrder> orders = new ArrayList<>();
        Integer type = 0;
        for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails) {
            /*租赁业务*/
            if(hotelOrder.getType() == 0){

                HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();


                //用户
                hotelLeaseLog.setUserId(hotelOrder.getUserId());
                hotelLeaseLog.setShopId(hotelOrder.getShopId());
                hotelLeaseLog.setOrderId(hotelOrder.getId());
                hotelLeaseLog.setOrderDetailId(hotelOrderDetail.getId());
                hotelLeaseLog.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog.setStatus(0);
                hotelLeaseLog.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog.setCategoryId(hotelOrderDetail.getCategoryId());


                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, hotelOrderDetail.getGoodsId())
                        .one();

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, hotelOrderDetail.getSkuId())
                        .one();





                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelOrderDetail.getCategoryId())
                        .one();
                /*水洗店*/
                HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();

                shopOrder.setUserName(hotelShop.getUserName());
                shopOrder.setUserPhone(hotelShop.getPhone());
                shopOrder.setUserAddress(hotelShop.getAddress());
                shopOrder.setUserId(hotelShop.getUserId());
                shopOrder.setDeposit(hotelOrder.getDeposit());
                shopOrder.setType(0);
                shopOrder.setStatus(1);
                shopOrder.setOrderLogId(hotelOrderLog.getId());
                shopOrder.setWashShopFlag(1);
                hotelOrderDetail1.setId(IdWorker.getIdStr());
                hotelOrderDetail1.setPic(hotelGoods.getPic());
                hotelOrderDetail1.setGoodsId(hotelGoods.getId());
                hotelOrderDetail1.setGoodsName(hotelGoods.getName());
                hotelOrderDetail1.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail1.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail1.setNum(hotelOrderDetail.getNum());
                hotelOrderDetail1.setOrderPay(hotelOrderDetail.getOrderPay());
                hotelOrderDetail1.setCategoryId(hotelCategory.getId());
                hotelOrderDetail1.setOrderId(shopOrder.getId());
                hotelOrderDetails1.add(hotelOrderDetail1);


                //水洗店
                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setUserId(hotelShop.getUserId());
                hotelLeaseLog1.setOrderId(shopOrder.getId());
                hotelLeaseLog1.setOrderDetailId(hotelOrderDetail1.getId());
                hotelLeaseLog1.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog1.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog1.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog1.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog1.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog1.setStatus(0);
                hotelLeaseLog1.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog1.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog1.setFormUserId(hotelOrderLog.getUserId());
                hotelLeaseLog1.setCategoryId(hotelOrderDetail.getCategoryId());

                hotelLeaseLogs.add(hotelLeaseLog1);
                hotelLeaseLogs.add(hotelLeaseLog);



            }else if(hotelOrder.getType() == 1){/*水洗逻辑*/


                List<HotelLeaseLog> hotelLeaseLogList = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getLeaseFlag, 1)
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .list();

                for (HotelLeaseLog hotelLeaseLog:hotelLeaseLogList){
                    type = 1;
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setStartTime(new Date());
                    if(StringUtils.equals(hotelLeaseLog.getId(),hotelOrderDetail.getLeaseId())){
                        hotelLeaseLog1.setWashNum(hotelOrderDetails.get(0).getNum());
                    }
                    hotelLeaseLogs.add(hotelLeaseLog1);
                }


            }
        }
        //修改订单状态
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        if(hotelOrder.getType() == 0){
            hotelOrder1.setStatus(1);
        }else if(hotelOrder.getType() == 1){
            hotelOrder1.setStatus(4);
        }
        hotelOrderService.updateById(hotelOrder1);

        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(hotelOrderLog.getId());
        hotelOrderLog1.setIsPay(1);
        hotelOrderLogService.updateById(hotelOrderLog1);

        if(type == 0){
            hotelLeaseLogService.saveBatch(hotelLeaseLogs);
            hotelOrderService.save(shopOrder);
            hotelOrderDetailService.saveBatch(hotelOrderDetails1);
        }else{
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);

        }

        if(hotelOrder.getType() == 0){
            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hanHaiMember.getId())
                    .one();
            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setDeposit(hotelMemberAccount.getDeposit().add(hotelOrder.getDeposit()));
            hotelMemberAccountService.updateById(hotelMemberAccount1);

            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setBalance(hotelOrder.getDeposit());
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getDeposit());
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLog.setPayType(0);
            hotelBalanceLog.setUserId(hanHaiMember.getId());
            hotelBalanceLog.setTitle("租赁押金");
            hotelBalanceLogService.save(hotelBalanceLog);
        }



        //不再通知该结果
        return "SUCCESS";
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object orderNotify4(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, outTradeNo)
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                .one();

        /*订单未找到*/
        if(hotelOrder == null ){
            System.err.println("订单未找到");
            return "FAIL";
        }

        /*已经处理过订单*/
        if (hotelOrder.getStatus() !=0 && hotelOrder.getStatus() != 3){
            return "SUCCESS";
        }

        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();

        HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
                .eq(HanHaiMember::getId, hotelOrder.getUserId())
                .one();

        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        HotelOrder shopOrder = new HotelOrder();
        shopOrder.setId(IdWorker.getIdStr());
        shopOrder.setTitle(hotelOrder.getTitle());
        List<HotelOrderDetail> hotelOrderDetails1 = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs2 = new ArrayList<>();
        List<HotelOrder> orders = new ArrayList<>();
        Integer type = 0;
        for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails) {
            /*租赁业务*/
            if(hotelOrder.getType() == 0){

                HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();


                //用户
                hotelLeaseLog.setUserId(hotelOrder.getUserId());
                hotelLeaseLog.setShopId(hotelOrder.getShopId());
                hotelLeaseLog.setOrderId(hotelOrder.getId());
                hotelLeaseLog.setOrderDetailId(hotelOrderDetail.getId());
                hotelLeaseLog.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog.setStatus(0);
                hotelLeaseLog.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog.setCategoryId(hotelOrderDetail.getCategoryId());


                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, hotelOrderDetail.getGoodsId())
                        .one();

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, hotelOrderDetail.getSkuId())
                        .one();





                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelOrderDetail.getCategoryId())
                        .one();
                /*水洗店*/
                HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();

                shopOrder.setUserName(hotelShop.getUserName());
                shopOrder.setUserPhone(hotelShop.getPhone());
                shopOrder.setUserAddress(hotelShop.getAddress());
                shopOrder.setUserId(hotelShop.getUserId());
                shopOrder.setDeposit(hotelOrder.getDeposit());
                shopOrder.setType(0);
                shopOrder.setStatus(1);
                shopOrder.setOrderLogId(hotelOrderLog.getId());
                shopOrder.setWashShopFlag(1);
                hotelOrderDetail1.setId(IdWorker.getIdStr());
                hotelOrderDetail1.setPic(hotelGoods.getPic());
                hotelOrderDetail1.setGoodsId(hotelGoods.getId());
                hotelOrderDetail1.setGoodsName(hotelGoods.getName());
                hotelOrderDetail1.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail1.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail1.setNum(hotelOrderDetail.getNum());
                hotelOrderDetail1.setOrderPay(hotelOrderDetail.getOrderPay());
                hotelOrderDetail1.setCategoryId(hotelCategory.getId());
                hotelOrderDetail1.setOrderId(shopOrder.getId());
                hotelOrderDetails1.add(hotelOrderDetail1);


                //水洗店
                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setUserId(hotelShop.getUserId());
                hotelLeaseLog1.setOrderId(shopOrder.getId());
                hotelLeaseLog1.setOrderDetailId(hotelOrderDetail1.getId());
                hotelLeaseLog1.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog1.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog1.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog1.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog1.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog1.setStatus(0);
                hotelLeaseLog1.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog1.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog1.setFormUserId(hotelOrderLog.getUserId());
                hotelLeaseLog1.setCategoryId(hotelOrderDetail.getCategoryId());

                hotelLeaseLogs.add(hotelLeaseLog1);
                hotelLeaseLogs.add(hotelLeaseLog);



            }else if(hotelOrder.getType() == 1){/*水洗逻辑*/


                List<HotelLeaseLog> hotelLeaseLogList = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getLeaseFlag, 1)
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .list();

                for (HotelLeaseLog hotelLeaseLog:hotelLeaseLogList){
                    type = 1;
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setStartTime(new Date());
                    hotelLeaseLogs.add(hotelLeaseLog1);
                }


            }
        }
        //修改订单状态
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        if(hotelOrder.getType() == 0){
            hotelOrder1.setStatus(1);
        }else if(hotelOrder.getType() == 1){
            hotelOrder1.setStatus(4);
        }
        hotelOrderService.updateById(hotelOrder1);

        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(hotelOrderLog.getId());
        hotelOrderLog1.setIsPay(1);
        hotelOrderLogService.updateById(hotelOrderLog1);

        if(type == 0){
            hotelLeaseLogService.saveBatch(hotelLeaseLogs);
            hotelOrderService.save(shopOrder);
            hotelOrderDetailService.saveBatch(hotelOrderDetails1);
        }else{
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);

        }

        if(hotelOrder.getType() == 0){
            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hanHaiMember.getId())
                    .one();
            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setDeposit(hotelMemberAccount.getDeposit().add(hotelOrder.getDeposit()));
            hotelMemberAccountService.updateById(hotelMemberAccount1);

            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setBalance(hotelOrder.getDeposit());
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getDeposit());
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLog.setPayType(0);
            hotelBalanceLog.setUserId(hanHaiMember.getId());
            hotelBalanceLog.setTitle("租赁押金");
            hotelBalanceLogService.save(hotelBalanceLog);
        }

        if(hotelOrder.getType() == 0){
            List<SysUserRole> sysUserRoles = sysUserRoleService.lambdaQuery()
                    .eq(SysUserRole::getRoleId, hotelConfService.getConf("messageId"))
                    .list();
            List<String> collect = sysUserRoles.stream().map(SysUserRole::getUserId).collect(Collectors.toList());

            MessageDTO messageDTO = new MessageDTO();
            messageDTO.setTitle("租赁订单");
            messageDTO.setToUser(collect.toString());
            messageDTO.setFromUser("");
            messageDTO.setContent("您有新的租赁订单");
            sysBaseAPI.sendSysAnnouncement(messageDTO);
        }


        //不再通知该结果
        return "SUCCESS";
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Object orderNotify5(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
                .eq(HotelOrderLog::getDelFlag, 0)
                .eq(HotelOrderLog::getId, outTradeNo)
                .eq(HotelOrderLog::getIsPay, 0)
                .one();
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getOrderLogId, hotelOrderLog.getId())
                .one();

        /*订单未找到*/
        if(hotelOrder == null ){
            System.err.println("订单未找到");
            return "FAIL";
        }

        /*已经处理过订单*/
        if (hotelOrder.getStatus() !=0 && hotelOrder.getStatus() != 3){
            return "SUCCESS";
        }

        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();

        HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
                .eq(HanHaiMember::getId, hotelOrder.getUserId())
                .one();

        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        HotelOrder shopOrder = new HotelOrder();
        shopOrder.setId(IdWorker.getIdStr());
        shopOrder.setTitle(hotelOrder.getTitle());
        List<HotelOrderDetail> hotelOrderDetails1 = new ArrayList<>();
        List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();

        List<HotelOrder> orders = new ArrayList<>();
        Integer type = 0;
        for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails) {
            /*租赁业务*/
            if(hotelOrder.getType() == 0){

                HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();


                //用户
                hotelLeaseLog.setUserId(hotelOrder.getUserId());
                hotelLeaseLog.setShopId(hotelOrder.getShopId());
                hotelLeaseLog.setOrderId(hotelOrder.getId());
                hotelLeaseLog.setOrderDetailId(hotelOrderDetail.getId());
                hotelLeaseLog.setGoodsId(hotelOrderDetail.getGoodsId());
                hotelLeaseLog.setSkuId(hotelOrderDetail.getSkuId());
                hotelLeaseLog.setGoodsName(hotelOrderDetail.getGoodsName());
                hotelLeaseLog.setGoodsPic(hotelOrderDetail.getPic());
                hotelLeaseLog.setSku(hotelOrderDetail.getSku());
                hotelLeaseLog.setStatus(0);
                hotelLeaseLog.setNum(hotelOrderDetail.getNum());
                hotelLeaseLog.setPrice(hotelOrderDetail.getDeposit());
                hotelLeaseLog.setCategoryId(hotelOrderDetail.getCategoryId());


                HotelGoods hotelGoods = hotelGoodsService.lambdaQuery()
                        .eq(HotelGoods::getDelFlag, 0)
                        .eq(HotelGoods::getId, hotelOrderDetail.getGoodsId())
                        .one();

                HotelGoodsSku hotelGoodsSku = hotelGoodsSkuService.lambdaQuery()
                        .eq(HotelGoodsSku::getDelFlag, 0)
                        .eq(HotelGoodsSku::getId, hotelOrderDetail.getSkuId())
                        .one();





                HotelCategory hotelCategory = hotelCategoryService.lambdaQuery()
                        .eq(HotelCategory::getDelFlag, 0)
                        .eq(HotelCategory::getId, hotelOrderDetail.getCategoryId())
                        .one();
                /*水洗店*/
                HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();

                shopOrder.setUserName(hotelShop.getUserName());
                shopOrder.setUserPhone(hotelShop.getPhone());
                shopOrder.setUserAddress(hotelShop.getAddress());
                shopOrder.setUserId(hotelShop.getUserId());
                shopOrder.setDeposit(hotelOrder.getDeposit());
                shopOrder.setType(0);
                shopOrder.setStatus(1);
                shopOrder.setOrderLogId(hotelOrderLog.getId());
                shopOrder.setWashShopFlag(1);
                hotelOrderDetail1.setId(IdWorker.getIdStr());
                hotelOrderDetail1.setPic(hotelGoods.getPic());
                hotelOrderDetail1.setGoodsId(hotelGoods.getId());
                hotelOrderDetail1.setGoodsName(hotelGoods.getName());
                hotelOrderDetail1.setSkuId(hotelGoodsSku.getId());
                hotelOrderDetail1.setSku(hotelGoodsSku.getTitle());
                hotelOrderDetail1.setNum(hotelOrderDetail.getNum());
                hotelOrderDetail1.setOrderPay(hotelOrderDetail.getOrderPay());
                hotelOrderDetail1.setCategoryId(hotelCategory.getId());
                hotelOrderDetail1.setOrderId(shopOrder.getId());
                hotelOrderDetails1.add(hotelOrderDetail1);



                hotelLeaseLogs.add(hotelLeaseLog);



            }else if(hotelOrder.getType() == 1){/*水洗逻辑*/


                List<HotelLeaseLog> hotelLeaseLogList = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getLeaseFlag, 1)
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .list();

                for (HotelLeaseLog hotelLeaseLog:hotelLeaseLogList){
                    type = 1;
                    HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                    hotelLeaseLog1.setId(hotelLeaseLog.getId());
                    hotelLeaseLog1.setStartTime(new Date());
                    hotelLeaseLogs.add(hotelLeaseLog1);
                }


            }
        }
        //修改订单状态
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        if(hotelOrder.getType() == 0){
            hotelOrder1.setStatus(1);
        }else if(hotelOrder.getType() == 1){
            hotelOrder1.setStatus(4);
        }
        hotelOrderService.updateById(hotelOrder1);

        HotelOrderLog hotelOrderLog1 = new HotelOrderLog();
        hotelOrderLog1.setId(hotelOrderLog.getId());
        hotelOrderLog1.setIsPay(1);
        hotelOrderLogService.updateById(hotelOrderLog1);

        if(type == 0){
            hotelLeaseLogService.saveBatch(hotelLeaseLogs);
            hotelOrderService.save(shopOrder);
            hotelOrderDetailService.saveBatch(hotelOrderDetails1);
        }else{
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);

        }

        if(hotelOrder.getType() == 0){
            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hanHaiMember.getId())
                    .one();
            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setDeposit(hotelMemberAccount.getDeposit().add(hotelOrder.getDeposit()));
            hotelMemberAccountService.updateById(hotelMemberAccount1);

            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setBalance(hotelOrder.getDeposit());
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getDeposit());
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLog.setPayType(0);
            hotelBalanceLog.setUserId(hanHaiMember.getId());
            hotelBalanceLog.setTitle("租赁押金");
            hotelBalanceLogService.save(hotelBalanceLog);
        }

        if(hotelOrder.getType() == 0){
            List<SysUserRole> sysUserRoles = sysUserRoleService.lambdaQuery()
                    .eq(SysUserRole::getRoleId, hotelConfService.getConf("messageId"))
                    .list();
            List<String> collect = sysUserRoles.stream().map(SysUserRole::getUserId).collect(Collectors.toList());

            MessageDTO messageDTO = new MessageDTO();
            messageDTO.setTitle("租赁订单");
            messageDTO.setToUser(collect.toString());
            messageDTO.setFromUser("");
            messageDTO.setContent("您有新的租赁订单");
            sysBaseAPI.sendSysAnnouncement(messageDTO);
        }


        //不再通知该结果
        return "SUCCESS";
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> applyRefundOrder(ApplyRefundOrderReq applyRefundOrderReq) {
        Integer n = (Integer) redisUtil.get("apply:refund:order:"+applyRefundOrderReq.getToken());
        if(n != null){
            return Result.error("请勿重复点击");
        }
        redisUtil.set("apply:refund:order:"+applyRefundOrderReq.getToken(),1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(applyRefundOrderReq.getToken());
        if(StringUtils.isBlank(applyRefundOrderReq.getReason())){
            throw new JeecgBootException("请填写申请原因");
        }
        if(applyRefundOrderReq.getRefundNum() == null || applyRefundOrderReq.getRefundNum() <= 0){
            String name = applyRefundOrderReq.getType() == 0?"退货数量":"换货数量";
            throw new JeecgBootException("请填写"+name);
        }

        if(StringUtils.isBlank(applyRefundOrderReq.getAddressId())){
            throw new JeecgBootException("请选择收货地址");
        }
        HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getDelFlag, 0)
                .eq(HotelAddress::getId, applyRefundOrderReq.getAddressId())
                .one();
        if(hotelAddress == null){
            throw new JeecgBootException("地址数据错误");
        }


        HotelOrder hotelOrder1 = new HotelOrder();

        if(applyRefundOrderReq.getType() == 0){
            if(applyRefundOrderReq.getReasonPrice() == null || applyRefundOrderReq.getReasonPrice().compareTo(BigDecimal.ZERO) <= 0){
                throw new JeecgBootException("请输入申请金额");
            }
            hotelOrder1.setOrderPay(hotelOrder1.getReasonPrice());
        }

        HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                .eq(HotelLeaseLog::getDelFlag, 0)
                .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                .eq(HotelLeaseLog::getId, applyRefundOrderReq.getId())
                .one();
        if(hotelLeaseLog == null){
            throw new JeecgBootException("数据错误，请刷新重试");
        }
//        int num = hotelLeaseLog.getNum() - hotelLeaseLog.getWashNum();
//        if(num <= 0 || num<applyRefundOrderReq.getRefundNum()){
//            throw new JeecgBootException("当前选择的数量已超过可选择的最大值");
//        }
        List<HotelOrder> hotelOrders = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getType,applyRefundOrderReq.getType() == 0?2:1)
                .eq(HotelOrder::getLeaseId, hotelLeaseLog.getId())
                .ne(HotelOrder::getStatus, 15)
                .list();
        if(hotelOrders.size() != 0){
            throw new JeecgBootException("该租赁不可操作");
        }
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, hotelLeaseLog.getOrderId())
                .one();
        if(hotelOrder.getStatus() != 15){
            throw new JeecgBootException("该订单还未收货");
        }

        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();
        HotelLeaseLog hotelLeaseLog2 = new HotelLeaseLog();
        int num = hotelLeaseLog.getNum() - applyRefundOrderReq.getRefundNum();
        if(num > 0){

            hotelLeaseLog2.setUserId(hotelLeaseLog.getUserId());
            hotelLeaseLog2.setShopId(hotelLeaseLog.getShopId());
            hotelLeaseLog2.setOrderId(hotelLeaseLog.getOrderId());
            hotelLeaseLog2.setGoodsId(hotelLeaseLog.getGoodsId());
            hotelLeaseLog2.setSkuId(hotelLeaseLog.getSkuId());
            hotelLeaseLog2.setGoodsName(hotelLeaseLog.getGoodsName());
            hotelLeaseLog2.setGoodsPic(hotelLeaseLog.getGoodsPic());
            hotelLeaseLog2.setSku(hotelLeaseLog.getSku());
            hotelLeaseLog2.setStatus(applyRefundOrderReq.getType() == 0?2:1);
            hotelLeaseLog2.setNum(applyRefundOrderReq.getRefundNum());
            hotelLeaseLog2.setPrice(hotelLeaseLog.getPrice());
            hotelLeaseLog2.setCategoryId(hotelLeaseLog.getCategoryId());
            hotelLeaseLog2.setPid(hotelLeaseLog.getId());
            hotelLeaseLogService.save(hotelLeaseLog2);
        }


        HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
        hotelOrder1.setReason(applyRefundOrderReq.getReason());
        hotelOrder1.setRefundNum(applyRefundOrderReq.getRefundNum());
        hotelOrder1.setType(applyRefundOrderReq.getType() == 0?3:2);
        hotelOrder1.setReasonInfo(applyRefundOrderReq.getReasonInfo() == null?null:applyRefundOrderReq.getReasonInfo());
        hotelOrder1.setReasonPic(applyRefundOrderReq.getReasonPic() == null?null:applyRefundOrderReq.getReasonPic());
        hotelOrder1.setReasonPhone(applyRefundOrderReq.getPhone() == null?null:applyRefundOrderReq.getPhone());
        hotelOrder1.setUserId(hanHaiMember.getId());
        hotelOrderDetail.setGoodsId(hotelLeaseLog.getGoodsId());
        hotelOrderDetail.setGoodsName(hotelLeaseLog.getGoodsName());
        hotelOrderDetail.setSkuId(hotelLeaseLog.getSkuId());
        hotelOrderDetail.setSku(hotelLeaseLog.getSku());
        hotelOrderDetail.setPic(hotelLeaseLog.getGoodsPic());
        hotelOrder1.setStatus(applyRefundOrderReq.getType() == 0 ?11:7);
        hotelOrderDetail.setLeaseId(hotelLeaseLog.getNum() > applyRefundOrderReq.getRefundNum()?hotelLeaseLog2.getId():hotelLeaseLog.getId());
        hotelOrder1.setLeaseId(hotelLeaseLog.getNum() > applyRefundOrderReq.getRefundNum()?hotelLeaseLog2.getId():hotelLeaseLog.getId());
        hotelOrder1.setUserName(hotelAddress.getName());
        hotelOrder1.setUserPhone(hotelAddress.getPhone());
        hotelOrder1.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
        hotelOrder1.setShopId(hotelShop.getUserId());
        hotelOrderService.save(hotelOrder1);

        hotelOrderDetail.setOrderId(hotelOrder1.getId());
        hotelOrderDetailService.save(hotelOrderDetail);

        if(num > 0){
            HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
            hotelLeaseLog1.setId(hotelLeaseLog.getId());
            if(hotelLeaseLog.getNum().equals(applyRefundOrderReq.getRefundNum()
            )){
                hotelLeaseLog1.setStatus(applyRefundOrderReq.getType() == 0?2:1);
            }
//            int i = hotelLeaseLog.getNum() - applyRefundOrderReq.getRefundNum();
            hotelLeaseLog1.setNum(num);
            hotelLeaseLogService.updateById(hotelLeaseLog1);
        }

        List<SysUserRole> sysUserRoles = sysUserRoleService.lambdaQuery()
                .eq(SysUserRole::getRoleId, hotelConfService.getConf("messageId"))
                .list();
        List<String> collect = sysUserRoles.stream().map(SysUserRole::getUserId).collect(Collectors.toList());

        MessageDTO messageDTO = new MessageDTO();
        messageDTO.setTitle(applyRefundOrderReq.getType() == 0?"退货订单":"换货订单");
        messageDTO.setToUser(collect.toString());
        messageDTO.setFromUser("");
        messageDTO.setContent("您有新的"+(applyRefundOrderReq.getType() == 0?"退货订单":"换货订单"));
        sysBaseAPI.sendSysAnnouncement(messageDTO);


        return Result.OK();
    }





    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> confirmOrder(ConfirmOrderReq confirmOrderReq) {

        Integer n = (Integer) redisUtil.get("confirm:order:"+confirmOrderReq.getToken());
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("confirm:order:"+confirmOrderReq.getToken(),1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(confirmOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, confirmOrderReq.getId())
//                .eq(HotelOrder::getUserId, hanHaiMember.getId())
                .one();
        if(hotelOrder == null){
            throw new JeecgBootException("数据错误，请刷新重试");
        }
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();
        if(hotelOrder.getType() == 0){
            if(!StringUtils.equals(hotelOrder.getUserId(),hanHaiMember.getId())){
                throw new JeecgBootException("数据订单错误");
            }
            List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
            for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails){
                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getOrderDetailId, hotelOrderDetail.getId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }

                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setId(hotelLeaseLog.getId());
                hotelLeaseLog1.setStartTime(new Date());
                hotelLeaseLogs.add(hotelLeaseLog1);

            }
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);
            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);

        }else if(hotelOrder.getType() == 1){
            if(!StringUtils.equals(hotelOrder.getShopId(),hanHaiMember.getId())){
                throw new JeecgBootException("数据订单错误");
            }
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hotelOrder.getShopId())
                    .one();

            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hotelShop.getUserId())
                    .one();


            BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
            BigDecimal platformServicePrice = hotelOrder.getOrderPay().multiply(platformServiceRate);
            BigDecimal shopPrice = hotelOrder.getOrderPay().multiply(hotelShop.getRate());
            BigDecimal price = hotelMemberAccount.getShopBalance().add(shopPrice);


            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setShopBalance(price);
            hotelMemberAccountService.updateById(hotelMemberAccount1);


            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setUserId(hotelShop.getUserId());
            hotelBalanceLog.setBalance(shopPrice);
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getShopBalance());
            hotelBalanceLog.setType(2);
            hotelBalanceLog.setTitle("佣金到账");
            hotelBalanceLog.setPayType(1);
            hotelBalanceLog.setPlatformServicePrice(platformServicePrice);
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLogService.save(hotelBalanceLog);

            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);



        }


        return Result.OK();
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> confirmOrder2(ConfirmOrderReq confirmOrderReq) {

        Integer n = (Integer) redisUtil.get("confirm:order:"+confirmOrderReq.getToken());
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("confirm:order:"+confirmOrderReq.getToken(),1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(confirmOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, confirmOrderReq.getId())
//                .eq(HotelOrder::getUserId, hanHaiMember.getId())
                .one();
        if(hotelOrder == null){
            throw new JeecgBootException("数据错误，请刷新重试");
        }
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();
        if(hotelOrder.getType() == 0){
            if(!StringUtils.equals(hotelOrder.getUserId(),hanHaiMember.getId())){
                throw new JeecgBootException("数据订单错误");
            }
            List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
            for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails){
                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getOrderDetailId, hotelOrderDetail.getId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }

                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setId(hotelLeaseLog.getId());
                hotelLeaseLog1.setStartTime(new Date());
                hotelLeaseLogs.add(hotelLeaseLog1);

            }
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);
            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);

        }else if(hotelOrder.getType() == 1){
            if(!StringUtils.equals(hotelOrder.getShopId(),hanHaiMember.getId())){
                throw new JeecgBootException("数据订单错误");
            }
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hotelOrder.getShopId())
                    .one();

            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hotelShop.getUserId())
                    .one();


            BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
            BigDecimal platformServicePrice = hotelOrder.getOrderPay().multiply(platformServiceRate);
            BigDecimal shopPrice = hotelOrder.getOrderPay().multiply(hotelShop.getRate());
            BigDecimal price = hotelMemberAccount.getShopBalance().add(shopPrice);


            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setShopBalance(price);
            hotelMemberAccountService.updateById(hotelMemberAccount1);


            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setUserId(hotelShop.getUserId());
            hotelBalanceLog.setBalance(shopPrice);
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getShopBalance());
            hotelBalanceLog.setType(2);
            hotelBalanceLog.setTitle("佣金到账");
            hotelBalanceLog.setPayType(1);
            hotelBalanceLog.setPlatformServicePrice(platformServicePrice);
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLogService.save(hotelBalanceLog);

            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);

            HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                    .eq(HotelLeaseLog::getDelFlag, 0)
                    .eq(HotelLeaseLog::getOrderDetailId, hotelOrderDetails.get(0).getId())
                    .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                    .one();
            if(hotelLeaseLog == null){
                throw new JeecgBootException("数据错误，请刷新重试");
            }

            HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
            hotelLeaseLog1.setId(hotelLeaseLog.getId());
            int num = hotelLeaseLog.getWashNum() - hotelOrderDetails.get(0).getNum();
            hotelLeaseLog1.setWashNum(num);
            hotelLeaseLogService.updateById(hotelLeaseLog1);

        }


        return Result.OK();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result<?> confirmOrder3(ConfirmOrderReq confirmOrderReq) {

        Integer n = (Integer) redisUtil.get("confirm:order:"+confirmOrderReq.getToken());
        if(n != null){
            throw new JeecgBootException("请勿重复点击");
        }
        redisUtil.set("confirm:order:"+confirmOrderReq.getToken(),1,3);
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(confirmOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, confirmOrderReq.getId())
//                .eq(HotelOrder::getUserId, hanHaiMember.getId())
                .one();
        if(hotelOrder == null){
            throw new JeecgBootException("数据错误，请刷新重试");
        }
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                .list();
        if(hotelOrder.getType() == 0){
            if(!StringUtils.equals(hotelOrder.getUserId(),hanHaiMember.getId())){
                throw new JeecgBootException("数据订单错误");
            }
            List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
            for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails){
                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, hotelOrderDetail.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }

                HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
                hotelLeaseLog1.setId(hotelLeaseLog.getId());
                hotelLeaseLog1.setStartTime(new Date());
                hotelLeaseLogs.add(hotelLeaseLog1);

            }
            hotelLeaseLogService.updateBatchById(hotelLeaseLogs);
            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);

        }else if(hotelOrder.getType() == 1){
//            if(!StringUtils.equals(hotelOrder.getShopId(),hanHaiMember.getId())){
//                throw new JeecgBootException("数据订单错误");
//            }
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getUserId, hotelOrder.getShopId())
                    .one();

            HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
                    .eq(HotelMemberAccount::getDelFlag, 0)
                    .eq(HotelMemberAccount::getUserId, hotelShop.getUserId())
                    .one();


            BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
            BigDecimal platformServicePrice = hotelOrder.getOrderPay().multiply(platformServiceRate);
            BigDecimal shopPrice = hotelOrder.getOrderPay().multiply(hotelShop.getRate());
            BigDecimal price = hotelMemberAccount.getShopBalance().add(shopPrice);


            HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
            hotelMemberAccount1.setId(hotelMemberAccount.getId());
            hotelMemberAccount1.setShopBalance(price);
            hotelMemberAccountService.updateById(hotelMemberAccount1);


            HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
            hotelBalanceLog.setUserId(hotelShop.getUserId());
            hotelBalanceLog.setBalance(shopPrice);
            hotelBalanceLog.setUserBalance(hotelMemberAccount.getShopBalance());
            hotelBalanceLog.setType(2);
            hotelBalanceLog.setTitle("佣金到账");
            hotelBalanceLog.setPayType(1);
            hotelBalanceLog.setPlatformServicePrice(platformServicePrice);
            hotelBalanceLog.setOrderId(hotelOrder.getId());
            hotelBalanceLogService.save(hotelBalanceLog);

            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(15);
            hotelOrderService.updateById(hotelOrder1);

            for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails){
                //子
                HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                        .eq(HotelLeaseLog::getDelFlag, 0)
                        .eq(HotelLeaseLog::getId, hotelOrderDetail.getLeaseId())
                        .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                        .one();
                if(hotelLeaseLog == null){
                    throw new JeecgBootException("数据错误，请刷新重试");
                }

                if(StringUtils.isNotBlank(hotelLeaseLog.getPid())){
                    //父
                    HotelLeaseLog hotelLeaseLog1 = hotelLeaseLogService.lambdaQuery()
                            .eq(HotelLeaseLog::getDelFlag, 0)
                            .eq(HotelLeaseLog::getId, hotelLeaseLog.getPid())
                            .one();
                    int num = hotelLeaseLog.getNum() + hotelLeaseLog1.getNum();
                    BigDecimal price2 = hotelLeaseLog1.getPrice().add(hotelLeaseLog.getPrice());
                    HotelLeaseLog hotelLeaseLog2 = new HotelLeaseLog();
                    hotelLeaseLog2.setId(hotelLeaseLog1.getId());

                    hotelLeaseLog2.setPrice(price2);
                    hotelLeaseLog2.setNum(num);
                    hotelLeaseLogService.updateById(hotelLeaseLog2);


                    hotelLeaseLogService.removeById(hotelLeaseLog.getId());
                }
            }






        }


        return Result.OK();
    }

    @Override
    public Result<?> uploadTablecloth(UploadTableclothReq uploadTableclothReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(uploadTableclothReq.getToken());
        if(StringUtils.isBlank(uploadTableclothReq.getCategoryId())){
            throw new JeecgBootException("请选择分类");
        }
        if(uploadTableclothReq.getNum() == null || uploadTableclothReq.getNum() <= 0){
            throw new JeecgBootException("请填写数量");
        }
        if(StringUtils.isBlank(uploadTableclothReq.getLength())){
            throw new JeecgBootException("请填写长度");
        }
        if(StringUtils.isBlank(uploadTableclothReq.getWide())){
            throw new JeecgBootException("请填写宽");
        }

        HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();
        hotelLeaseLog.setCategoryId(uploadTableclothReq.getCategoryId());
        hotelLeaseLog.setGoodsName(uploadTableclothReq.getName());
        hotelLeaseLog.setNum(uploadTableclothReq.getNum());
        hotelLeaseLog.setGoodsPic(uploadTableclothReq.getPic());
        hotelLeaseLog.setUserId(hanHaiMember.getId());
        hotelLeaseLog.setShopId(hotelLeaseLog.getShopId());
        hotelLeaseLog.setLeaseFlag(0);
        hotelLeaseLog.setStatus(0);
        hotelLeaseLog.setSku(uploadTableclothReq.getLength()+"*"+uploadTableclothReq.getWide());
        hotelLeaseLogService.save(hotelLeaseLog);

        /*
        HotelShop hotelShop = hotelShopService.lambdaQuery()
                .eq(HotelShop::getDelFlag, 0)
                .eq(HotelShop::getId, hanHaiMember.getShopId())
                .one();

        HotelAddress hotelAddress = hotelAddressService.lambdaQuery()
                .eq(HotelAddress::getId, uploadTableclothReq.getAddressId())
                .one();

        HotelOrderLog hotelOrderLog = new HotelOrderLog();
        hotelOrderLog.setOrderPay(BigDecimal.ZERO);
        hotelOrderLog.setType(0);
        hotelOrderLog.setUserId(hanHaiMember.getId());
        hotelOrderLog.setShopId(hotelShop.getUserId());
        hotelOrderLogService.save(hotelOrderLog);


        HotelOrder hotelOrder = new HotelOrder();
        hotelOrder.setTitle("租赁押金");
        hotelOrder.setUserName(hotelAddress.getName());
        hotelOrder.setUserPhone(hotelAddress.getPhone());
        hotelOrder.setUserAddress(hotelAddress.getAddress()+hotelAddress.getAddressDetail());
        hotelOrder.setUserId(hanHaiMember.getId());
        hotelOrder.setType(0);
        hotelOrder.setStatus(15);
        hotelOrder.setWashShopFlag(0);
        hotelOrder.setOrderPay(BigDecimal.ZERO);
        hotelOrder.setDeposit(BigDecimal.ZERO);
        hotelOrder.setRentPay(BigDecimal.ZERO);
        hotelOrder.setWashPay(BigDecimal.ZERO);
        hotelOrder.setOrderLogId(hotelOrderLog.getId());
        hotelOrder.setLeaseFlag(0);
        hotelOrderService.save(hotelOrder);

        HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();
        hotelOrderDetail.setGoodsName(uploadTableclothReq.getName());
        hotelOrderDetail.setPic(uploadTableclothReq.getPic());
        hotelOrderDetail.setSku(hotelLeaseLog.getSku());
        hotelOrderDetail.setNum(uploadTableclothReq.getNum());
        hotelOrderDetail.setOrderPay(BigDecimal.ZERO);
        hotelOrderDetail.setCategoryId(uploadTableclothReq.getCategoryId());
        hotelOrderDetail.setOrderId(hotelOrder.getId());
        hotelOrderDetail.setCategoryId(uploadTableclothReq.getCategoryId());
        hotelOrderDetail.setDeposit(BigDecimal.ZERO);
        hotelOrderDetailService.save(hotelOrderDetail);

        HotelOrder shopOrder = new HotelOrder();
        shopOrder.setUserName(hotelShop.getUserName());
        shopOrder.setUserPhone(hotelShop.getPhone());
        shopOrder.setUserAddress(hotelShop.getAddress());
        shopOrder.setUserId(hotelShop.getUserId());
        shopOrder.setDeposit(hotelOrder.getDeposit());
        shopOrder.setOrderPay(hotelOrder.getOrderPay());
        shopOrder.setWashPay(hotelOrder.getWashPay());
        shopOrder.setRentPay(hotelOrder.getRentPay());
        shopOrder.setType(0);
        shopOrder.setStatus(1);
        shopOrder.setOrderLogId(hotelOrderLog.getId());
        shopOrder.setWashShopFlag(1);
        shopOrder.setLeaseFlag(0);
        hotelOrderService.save(shopOrder);

        HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();
        hotelOrderDetail1.setGoodsName(uploadTableclothReq.getName());
        hotelOrderDetail1.setPic(uploadTableclothReq.getPic());
        hotelOrderDetail1.setSku(hotelLeaseLog.getSku());
        hotelOrderDetail1.setNum(uploadTableclothReq.getNum());
        hotelOrderDetail1.setOrderPay(BigDecimal.ZERO);
        hotelOrderDetail1.setCategoryId(uploadTableclothReq.getCategoryId());
        hotelOrderDetail1.setOrderId(shopOrder.getId());
        hotelOrderDetail1.setCategoryId(uploadTableclothReq.getCategoryId());
        hotelOrderDetail1.setDeposit(BigDecimal.ZERO);
        hotelOrderDetailService.save(hotelOrderDetail1);

         */



        return Result.OK();
    }

    @Override
    public Result<?> confirmAcceptOrder(ConfirmAcceptOrderReq confirmAcceptOrderReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(confirmAcceptOrderReq.getToken());

        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getShopId,hanHaiMember.getId())
                .eq(HotelOrder::getId, confirmAcceptOrderReq.getId())
                .one();

        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getId, hotelOrder.getId())
                .list();



        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());

        if(confirmAcceptOrderReq.getFlag() == 0){
            switch (hotelOrder.getType()){
                case 1:
                    if(confirmAcceptOrderReq.getLogisticsFlag() == 0){
                        hotelOrder1.setStatus(20);
                    }else{
                        hotelOrder1.setStatus(21);
                    }

                    break;
                case 2:
                    hotelOrder1.setStatus(17);
                    break;
                case 3:
                    hotelOrder1.setStatus(18);
                    break;
            }
        }else if(confirmAcceptOrderReq.getFlag() == 1){
            switch (hotelOrder.getStatus()){
                case 5:
                    hotelOrder1.setStatus(6);
                    break;
                case 6:
                    if(confirmAcceptOrderReq.getLogisticsFlag() == 0){
                        hotelOrder1.setStatus(22);
                    }else{
                        hotelOrder1.setStatus(23);
                    }

                    break;
            }

        }else if(confirmAcceptOrderReq.getFlag() == 2){/*破损换布流程*/
            HotelShop hotelShop = hotelShopService.lambdaQuery()
                    .eq(HotelShop::getDelFlag, 0)
                    .eq(HotelShop::getStatus, 1)
                    .eq(HotelShop::getUserId, hanHaiMember.getId())
                    .one();

            if(hotelShop == null){
                throw new JeecgBootException("数据错误");
            }

            HotelOrderDetail hotelOrderDetail = hotelOrderDetailService.lambdaQuery()
                    .eq(HotelOrderDetail::getDelFlag, 0)
                    .eq(HotelOrderDetail::getId, confirmAcceptOrderReq.getOrderDetailId())
                    .one();
            if(hotelOrderDetail.getStatus() == 1){
                throw new JeecgBootException("该商品正在换货中");
            }
            HotelOrder hotelOrder3 = hotelOrderService.lambdaQuery()
                    .eq(HotelOrder::getDelFlag, 0)
                    .eq(HotelOrder::getId, hotelOrderDetail.getOrderId())
                    .one();
            HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                    .eq(HotelLeaseLog::getDelFlag, 0)
                    .eq(HotelLeaseLog::getId, hotelOrderDetail.getLeaseId())
                    .one();

            HotelOrder hotelOrder2 = new HotelOrder();
            hotelOrder2.setUserId(hotelOrder3.getUserId());
            hotelOrder2.setShopId(hotelShop.getUserId());

            hotelOrder2.setTitle("破损换货");
            hotelOrder2.setStatus(7);
            hotelOrder2.setType(2);
            hotelOrder2.setReason("破损换布");
            hotelOrder2.setRefundNum(confirmAcceptOrderReq.getNum());
            hotelOrder2.setReasonInfo(confirmAcceptOrderReq.getInfo());
            hotelOrder2.setReasonPic(confirmAcceptOrderReq.getPic());
            hotelOrder2.setReasonPhone(hotelShop.getPhone());
            hotelOrder2.setLeaseId(hotelLeaseLog.getId());
            hotelOrder2.setUserName(hotelShop.getUserName());
            hotelOrder2.setUserPhone(hotelShop.getPhone());
            hotelOrder2.setUserAddress(hotelShop.getAddress());
            hotelOrder2.setReplaceType(1);
            hotelOrderService.save(hotelOrder2);

            HotelOrderDetail hotelOrderDetail2 = new HotelOrderDetail();
            hotelOrderDetail2.setGoodsId(hotelLeaseLog.getGoodsId());
            hotelOrderDetail2.setGoodsName(hotelLeaseLog.getGoodsName());
            hotelOrderDetail2.setSkuId(hotelLeaseLog.getSkuId());
            hotelOrderDetail2.setSku(hotelLeaseLog.getSku());
            hotelOrderDetail2.setPic(hotelLeaseLog.getGoodsPic());
            hotelOrderDetail2.setLeaseId(hotelLeaseLog.getId());
            hotelOrderDetail2.setOrderDetailId(hotelOrderDetail.getId());


            hotelOrderDetail2.setOrderId(hotelOrder2.getId());
            hotelOrderDetailService.save(hotelOrderDetail2);

            HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();
            hotelOrderDetail1.setId(hotelOrderDetail.getId());
            hotelOrderDetail1.setStatus(1);
            hotelOrderDetailService.updateById(hotelOrderDetail1);

            List<SysUserRole> sysUserRoles = sysUserRoleService.lambdaQuery()
                    .eq(SysUserRole::getRoleId, hotelConfService.getConf("messageId"))
                    .list();
            List<String> collect = sysUserRoles.stream().map(SysUserRole::getUserId).collect(Collectors.toList());

            MessageDTO messageDTO = new MessageDTO();
            messageDTO.setTitle("换货订单");
            messageDTO.setToUser(collect.toString());
            messageDTO.setFromUser("");
            messageDTO.setContent("您有新的换货订单");
            sysBaseAPI.sendSysAnnouncement(messageDTO);
        }


        hotelOrderService.updateById(hotelOrder1);

        return Result.OK();
    }

    @Override
    public Result<?> shopReceiptOrder(ShopReceiptOrderReq shopReceiptOrderReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(shopReceiptOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, shopReceiptOrderReq.getId())
                .eq(HotelOrder::getType, 1)
                .eq(HotelOrder::getStatus, 21)
                .one();

        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        hotelOrder1.setStatus(5);
        hotelOrderService.updateById(hotelOrder1);

        return Result.OK();
    }

    @Override
    public Result<?> receiptWashOrder(ShopReceiptOrderReq shopReceiptOrderReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(shopReceiptOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, shopReceiptOrderReq.getId())
                .eq(HotelOrder::getType, 1)
                .eq(HotelOrder::getStatus, 23)
                .one();

//        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
//                .eq(HotelOrderDetail::getDelFlag, 0)
//                .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
//                .list();

//        HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
//                .eq(HotelLeaseLog::getDelFlag, 0)
//                .eq(HotelLeaseLog::getId, hotelOrderDetails.get(0).getLeaseId())
//                .one();
//        HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
//        hotelLeaseLog1.setId(hotelLeaseLog.getId());
//        hotelLeaseLog1.setWashNum(hotelLeaseLog.getWashNum() - hotelOrderDetails.get(0).getNum());
//        hotelLeaseLogService.updateById(hotelLeaseLog1);

        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        hotelOrder1.setStatus(15);
        hotelOrderService.updateById(hotelOrder1);

        return Result.OK();
    }

    @Override
    public Result<?> cancelOrder(CancelOrderReq cancelOrderReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(cancelOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .in(HotelOrder::getStatus, 0, 3)
                .eq(HotelOrder::getUserId,hanHaiMember.getId())
                .eq(HotelOrder::getId, cancelOrderReq.getId())
                .one();
        if(hotelOrder == null){
            throw new JeecgBootException("未找到该订单");
        }
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        hotelOrderService.removeById(hotelOrder1);

        return Result.OK();
    }

    @Override
    public Result<?> cancelOrder2(CancelOrderReq cancelOrderReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(cancelOrderReq.getToken());
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .in(HotelOrder::getStatus, 0, 3)
                .eq(HotelOrder::getUserId,hanHaiMember.getId())
                .eq(HotelOrder::getId, cancelOrderReq.getId())
                .one();
        if(hotelOrder == null){
            throw new JeecgBootException("未找到该订单");
        }

        if(hotelOrder.getType() == 1){
            HotelOrderDetail hotelOrderDetail = hotelOrderDetailService.lambdaQuery()
                    .eq(HotelOrderDetail::getDelFlag, 0)
                    .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
                    .one();
            //子物品
            HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                    .eq(HotelLeaseLog::getDelFlag,0)
                    .eq(HotelLeaseLog::getId, hotelOrderDetail.getLeaseId())
                    .one();

            //父物品
            HotelLeaseLog hotelLeaseLog1 = hotelLeaseLogService.lambdaQuery()
                    .eq(HotelLeaseLog::getDelFlag, 0)
                    .eq(HotelLeaseLog::getId, hotelLeaseLog.getPid())
                    .one();

            //如果父物品不为空，则还原物品数据
            if(null != hotelLeaseLog1){
                int num = hotelLeaseLog1.getNum() + hotelLeaseLog.getNum();
                BigDecimal price = hotelLeaseLog1.getPrice().add(hotelLeaseLog.getPrice());
                HotelLeaseLog hotelLeaseLog2 = new HotelLeaseLog();
                hotelLeaseLog2.setId(hotelLeaseLog1.getId());
                hotelLeaseLog2.setNum(num);
                hotelLeaseLog2.setPrice(price);
                hotelLeaseLogService.updateById(hotelLeaseLog2);

                hotelLeaseLogService.removeById(hotelLeaseLog.getId());
            }

        }


        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());
        hotelOrderService.removeById(hotelOrder1);

        return Result.OK();
    }

    @Override
    public Result<?> replaceOrderPay(ReplaceOrderPayReq replaceOrderPayReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(replaceOrderPayReq.getToken());

        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getType, 2)
                .eq(HotelOrder::getStatus, 10)
                .eq(HotelOrder::getUserId,hanHaiMember.getId())
                .eq(HotelOrder::getId, replaceOrderPayReq.getId())
                .one();

        if(hotelOrder == null){
            throw new JeecgBootException("数据错误，请稍后重试");
        }

        HttpServletRequest req = SpringContextUtils.getHttpServletRequest();
        BigDecimal multiply = hotelOrder.getReasonPrice().multiply(new BigDecimal(100));
        Object order = mpWxPayService.createOrder("酒店桌布换货", oConvertUtils.getIpAddrByRequest(req), hotelOrder.getId(), multiply.intValue(), hotelOrder.getId(), hanHaiMember.getAppletOpenid(),replaceOrderNotifyUrl,"{}");

        return Result.OK(order);
    }

    @Override
    public Object replaceOrderNotify(String requestBody) {
        WxPayOrderNotifyResult notify = mpWxPayService.notify(requestBody);
        //对比outTradeNo进行业务处理
        if (notify == null){
            //会继续通知
            return "FAIL";
        }
        String outTradeNo = notify.getOutTradeNo();
        System.err.println(outTradeNo);
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, outTradeNo)
                .one();

        if(hotelOrder.getStatus() == 15){
            return "SUCCESS";
        }

        HotelOrder hotelOrder2 = new HotelOrder();
        hotelOrder2.setId(hotelOrder.getId());
        hotelOrder2.setStatus(15);
        hotelOrderService.updateById(hotelOrder2);

        if(hotelOrder.getReplaceType() == 0){
            HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                    .eq(HotelLeaseLog::getDelFlag, 0)
                    .eq(HotelLeaseLog::getId, hotelOrder.getId())
                    .one();

            HotelLeaseLog hotelLeaseLog2 = new HotelLeaseLog();
            hotelLeaseLog2.setId(hotelLeaseLog.getId());
            hotelLeaseLog2.setStatus(0);
            hotelLeaseLogService.updateById(hotelLeaseLog2);
        }



        //不再通知该结果
        return "SUCCESS";
    }

    @Override
    public Result<?> sendLogistics(SendLogisticsReq sendLogisticsReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(sendLogisticsReq.getToken());

        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, sendLogisticsReq.getId())
                .one();

        if(StringUtils.isBlank(sendLogisticsReq.getLogisticsName())){
            throw new JeecgBootException("请填写物流名称");
        }
        if(StringUtils.isBlank(sendLogisticsReq.getLogisticsCode())){
            throw new JeecgBootException("请填写物流单号");
        }
        HotelOrder hotelOrder1 = new HotelOrder();
        hotelOrder1.setId(hotelOrder.getId());

        switch (hotelOrder.getType()){
            case 1:
                if(hotelOrder.getStatus() == 20){
                    hotelOrder1.setLogisticsName(sendLogisticsReq.getLogisticsName());
                    hotelOrder1.setLogisticsCode(sendLogisticsReq.getLogisticsCode());
                    hotelOrder1.setStatus(21);
                }else if(hotelOrder.getStatus() == 22){
                    hotelOrder1.setLogisticsNameTwo(sendLogisticsReq.getLogisticsName());
                    hotelOrder1.setLogisticsCodeTwo(sendLogisticsReq.getLogisticsCode());
                    hotelOrder1.setStatus(23);
                }

                break;
            case 2:
                hotelOrder1.setLogisticsName(sendLogisticsReq.getLogisticsName());
                hotelOrder1.setLogisticsCode(sendLogisticsReq.getLogisticsCode());
                hotelOrder1.setStatus(9);
                break;
        }

        hotelOrderService.updateById(hotelOrder1);


        return Result.OK();
    }

    @Override
    public Result<?> getOrderDetails(String id) {
        List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
                .eq(HotelOrderDetail::getDelFlag, 0)
                .eq(HotelOrderDetail::getOrderId, id)
                .list();
        return Result.OK(hotelOrderDetails);
    }

    @Override
    public Result<?> editLeaseNum(EditLeaseNumReq editLeaseNumReq) {
        HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiAccount(editLeaseNumReq.getToken());
        HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
                .eq(HotelLeaseLog::getDelFlag, 0)
                .eq(HotelLeaseLog::getId, editLeaseNumReq.getId())
                .eq(HotelLeaseLog::getUserId, hanHaiMember.getId())
                .eq(HotelLeaseLog::getLeaseFlag,0)
                .one();

        if(hotelLeaseLog == null){
            throw new JeecgBootException("只能修改上传物品");
        }

        HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
        hotelLeaseLog1.setId(hotelLeaseLog.getId());
        hotelLeaseLog1.setNum(editLeaseNumReq.getNum());
        hotelLeaseLogService.updateById(hotelLeaseLog1);


        return Result.OK();
    }

    public Object testPay(String id){
        HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
                .eq(HotelOrder::getDelFlag, 0)
                .eq(HotelOrder::getId, id)
                .one();
        /*订单未找到*/
        if(hotelOrder == null){
            System.err.println("订单未找到");
            return "FAIL";
        }
        /*租赁业务*/
        if(hotelOrder.getType() == 0){
            /*已经处理过订单*/
            if (hotelOrder.getStatus() !=0){
                return "SUCCESS";
            }
            HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();
            hotelLeaseLog.setUserId(hotelOrder.getUserId());
            hotelLeaseLog.setShopId(hotelOrder.getShopId());
            hotelLeaseLog.setOrderId(hotelOrder.getId());
            hotelLeaseLog.setGoodsId(hotelOrder.getGoodsId());
            hotelLeaseLog.setSkuId(hotelOrder.getSkuId());
            hotelLeaseLog.setGoodsName(hotelOrder.getGoodsName());
            hotelLeaseLog.setSku(hotelOrder.getSku());
            hotelLeaseLog.setStatus(0);
            hotelLeaseLog.setNum(hotelOrder.getNum());
            hotelLeaseLog.setPrice(hotelOrder.getDeposit());
            hotelLeaseLogService.save(hotelLeaseLog);

            HotelOrder hotelOrder1 = new HotelOrder();
            hotelOrder1.setId(hotelOrder.getId());
            hotelOrder1.setStatus(1);
            hotelOrderService.updateById(hotelOrder1);


            return "SUCCESS";

        }

        //不再通知该结果
        return "SUCCESS";
    }


}
