| | |
| | | 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; |
| | |
| | | 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); |
| | |
| | | } |
| | | 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(); |
| | | } |
| | | } |