From aa2f32ff62700f7602ac19fdce93a156fc2dd447 Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Fri, 24 Nov 2023 11:00:17 +0800 Subject: [PATCH] 匹配 --- src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java | 161 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 145 insertions(+), 16 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java index bc49198..15fb84f 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java @@ -16,6 +16,8 @@ import cc.mrbird.febs.mall.vo.*; import cc.mrbird.febs.rabbit.producter.AgentProducer; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.crypto.SecureUtil; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -91,7 +93,7 @@ mallProductBuy.setOrderNo(orderNo); mallProductBuy.setProductNftId(mallProductNft.getId()); mallProductBuy.setState(ProductEnum.PRODUCT_BUY_ON_GOING.getValue()); - mallProductBuy.setMateState(ProductEnum.PRODUCT_MATE_STATE_ON_GOING.getValue()); + mallProductBuy.setMateState(ProductEnum.PRODUCT_BUY_MATE_STATE_FAIL.getValue()); mallProductBuy.setNftTotal(mallProductNft.getPriceNft()); mallProductBuy.setNftAva(BigDecimal.ZERO); mallProductBuyMapper.insert(mallProductBuy); @@ -269,29 +271,53 @@ return new FebsResponse().success(); } + public static void main(String[] args) { + DateTime dateTime = DateUtil.parseTime("15:00:00"); + DateTime dateTime2 = DateUtil.parseTime("19:00:00"); + DateTime dateTime1 = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date())); + System.out.println(dateTime); + System.out.println(dateTime1); + System.out.println(dateTime1.compareTo(dateTime)); + System.out.println(dateTime1.compareTo(dateTime2)); + System.out.println(dateTime1.compareTo(dateTime) >= 0 && dateTime1.compareTo(dateTime2) <= 0); + } + @Override public FebsResponse orderList(ApiOrderListDto apiOrderListDto) { Long memberId = LoginUserUtil.getLoginUser().getId(); List<ApiOrderListVo> objects = new ArrayList<>(); Integer orderType = apiOrderListDto.getOrderType(); apiOrderListDto.setMemberId(memberId); - //买单 - if(2 == orderType){ - IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize()); - IPage<ApiOrderListVo> apiOrderListVoIPageBuy = mallProductBuyMapper.selectListInPage(page, apiOrderListDto); - if(CollUtil.isNotEmpty(apiOrderListVoIPageBuy.getRecords())){ - for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageBuy.getRecords()){ - objects.add(apiOrderListVo); + DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date())); + DataDictionaryCustom startTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.YU_YUE_START_TIME.getType(), + DataDictionaryEnum.YU_YUE_START_TIME.getCode() + ); + DateTime startTime = DateUtil.parseTime(startTimeDic.getValue()); + DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.YU_YUE_END_TIME.getType(), + DataDictionaryEnum.YU_YUE_END_TIME.getCode() + ); + DateTime endTime = DateUtil.parseTime(endTimeDic.getValue()); + if(nowTime.compareTo(startTime) >= 0 && nowTime.compareTo(endTime) <= 0){ + //买单 + if(2 == orderType){ + IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize()); + IPage<ApiOrderListVo> apiOrderListVoIPageBuy = mallProductBuyMapper.selectListInPage(page, apiOrderListDto); + if(CollUtil.isNotEmpty(apiOrderListVoIPageBuy.getRecords())){ + for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageBuy.getRecords()){ + objects.add(apiOrderListVo); + } } } - } - //卖单 - if(1 == orderType){ - IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize()); - IPage<ApiOrderListVo> apiOrderListVoIPageSell = mallProductSellMapper.selectListInPage(page, apiOrderListDto); - if(CollUtil.isNotEmpty(apiOrderListVoIPageSell.getRecords())){ - for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageSell.getRecords()){ - objects.add(apiOrderListVo); + //卖单 + if(1 == orderType){ + IPage<ApiOrderListVo> page = new Page<>(apiOrderListDto.getPageNum(), apiOrderListDto.getPageSize()); + IPage<ApiOrderListVo> apiOrderListVoIPageSell = mallProductSellMapper.selectListInPage(page, apiOrderListDto); + if(CollUtil.isNotEmpty(apiOrderListVoIPageSell.getRecords())){ + for(ApiOrderListVo apiOrderListVo : apiOrderListVoIPageSell.getRecords()){ + objects.add(apiOrderListVo); + } } } } @@ -328,4 +354,107 @@ } return new FebsResponse().success().data(apiOrderBuyInfoVo); } + + @Override + public FebsResponse orderBuyInsure(ApiOrderBuyInsureDto apiOrderBuyInsureDto) { + Long memberId = LoginUserUtil.getLoginUser().getId(); + MallMember mallMember = memberMapper.selectById(memberId); + Long buyRecordId = apiOrderBuyInsureDto.getBuyRecordId(); + String nftImg = apiOrderBuyInsureDto.getNftImg(); + Integer type = apiOrderBuyInsureDto.getType(); + String tradePassword = SecureUtil.md5(apiOrderBuyInsureDto.getTradePassword()); + /** + * 验证订单是否存在 + * 更新买单状态 + * 更新卖单状态 + * 生成流水信息 + */ + if(!tradePassword.equals(mallMember.getTradePassword())){ + throw new FebsException("请输入正确的交易密码"); + } + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(buyRecordId); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + throw new FebsException("记录不存在"); + } + Integer state = mallProductBuyRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != state){ + throw new FebsException("记录不是待支付状态"); + } + + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(mallProductBuyRecord.getSellRecordId()); + if(ObjectUtil.isEmpty(mallProductSellRecord)){ + throw new FebsException("记录不存在"); + } + Integer stateSell = mallProductSellRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != stateSell){ + throw new FebsException("记录不是待支付状态"); + } + + DateTime payTime = DateUtil.date(); + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue()); + mallProductBuyRecord.setPayTime(payTime); + mallProductBuyRecord.setNftImg(nftImg); + mallProductBuyRecord.setType(type); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue()); + mallProductSellRecord.setPayTime(payTime); + mallProductSellRecord.setNftImg(nftImg); + mallProductSellRecord.setType(type); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + + String orderNo = MallUtils.getOrderNum("ZF"); + iMallMoneyFlowService.addMoneyFlow( + memberId, + mallProductBuyRecord.getPickNftCnt(), + MoneyFlowTypeNewEnum.PAY.getValue(), + orderNo, + mallMember.getId(), + FlowTypeNewEnum.NFT.getValue(), + MoneyFlowTypeNewEnum.PAY.getDescrition()); + return new FebsResponse().success(); + } + + @Override + public FebsResponse orderSellInsure(ApiOrderSellInsureDto apiOrderSellInsureDto) { + Long memberId = LoginUserUtil.getLoginUser().getId(); + MallMember mallMember = memberMapper.selectById(memberId); + String tradePassword = SecureUtil.md5(apiOrderSellInsureDto.getTradePassword()); + Long sellRecordId = apiOrderSellInsureDto.getSellRecordId(); + /** + * 验证订单是否存在 + * 更新买单状态 + * 更新卖单状态 + * 生成流水信息 + */ + if(!tradePassword.equals(mallMember.getTradePassword())){ + throw new FebsException("请输入正确的交易密码"); + } + MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); + if(ObjectUtil.isEmpty(mallProductSellRecord)){ + throw new FebsException("记录不存在"); + } + Integer stateSell = mallProductSellRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != stateSell){ + throw new FebsException("记录不是已支付状态"); + } + + MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(mallProductSellRecord.getBuyRecordId()); + if(ObjectUtil.isEmpty(mallProductBuyRecord)){ + throw new FebsException("记录不存在"); + } + Integer state = mallProductBuyRecord.getState(); + if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != state){ + throw new FebsException("记录不是已支付状态"); + } + + mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue()); + mallProductBuyRecordMapper.updateById(mallProductBuyRecord); + + mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_CONFIRM.getValue()); + mallProductSellRecordMapper.updateById(mallProductSellRecord); + + agentProducer.sendFcmOrderSellInsureMsg(sellRecordId); + return new FebsResponse().success(); + } } -- Gitblit v1.9.1