KKSU
2023-11-21 5b818c73e70ef4618681fd103ca593020431eeef
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallProductServiceImpl.java
@@ -8,17 +8,18 @@
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.common.utils.MallUtils;
import cc.mrbird.febs.mall.dto.ApiCreateNFTDto;
import cc.mrbird.febs.mall.dto.ApiOutFcmDto;
import cc.mrbird.febs.mall.dto.ApiOutNFTDto;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.IApiMallProductService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.vo.ApiMallProductNftVo;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -26,6 +27,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@@ -41,6 +43,7 @@
    private final AgentProducer agentProducer;
    private final MallProductSellMapper mallProductSellMapper;
    private final MallProductSellRecordMapper mallProductSellRecordMapper;
    private final MallProductBuyRecordMapper mallProductBuyRecordMapper;
    @Override
    public List<ApiMallProductNftVo> productNFTList() {
@@ -81,8 +84,11 @@
         || priceToken.compareTo(mallMemberAmount.getTokenAva()) > 0){
            throw new FebsException("余额不足");
        }
        String orderNo = MallUtils.getOrderNum("YY");
        mallProductBuy = new MallProductBuy();
        mallProductBuy.setMemberId(memberId);
        mallProductBuy.setOrderNo(orderNo);
        mallProductBuy.setProductNftId(mallProductNft.getId());
        mallProductBuy.setState(ProductEnum.PRODUCT_BUY_ON_GOING.getValue());
        mallProductBuy.setMateState(ProductEnum.PRODUCT_MATE_STATE_ON_GOING.getValue());
@@ -93,8 +99,6 @@
        mallMemberAmount.setTokenAva(mallMemberAmount.getTokenAva().subtract(priceToken));
        mallMemberAmount.setTokenFrozen(mallMemberAmount.getTokenFrozen().add(priceToken));
        mallMemberAmountMapper.updateTokenAvaAndTokenFrozenById(mallMemberAmount);
        String orderNo = MallUtils.getOrderNum("YY");
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                priceToken.negate(),
@@ -227,8 +231,10 @@
        BigDecimal fcmPrice = ObjectUtil.isEmpty(fcmPriceDic) ? new BigDecimal(2) : new BigDecimal(fcmPriceDic.getValue());
        BigDecimal fcmFeeCnt = nftFee.divide(fcmPrice, 2, BigDecimal.ROUND_DOWN);
        String orderNo = MallUtils.getOrderNum("NFT");
        MallProductSell mallProductSell = new MallProductSell();
        mallProductSell.setMemberId(memberId);
        mallProductSell.setOrderNo(orderNo);
        mallProductSell.setNftTotal(nftCnt);
        mallProductSell.setNftCnt(nftCntAva);
        mallProductSell.setNftCntAva(nftCntAva);
@@ -242,7 +248,6 @@
        mallMemberAmount.setFrozenNft(mallMemberAmount.getFrozenNft().add(nftCntAva));
        mallMemberAmountMapper.updateFrozenNftById(mallMemberAmount);
        String orderNo = MallUtils.getOrderNum("NFT");
        iMallMoneyFlowService.addMoneyFlow(
                memberId,
                nftCnt.negate(),
@@ -263,4 +268,64 @@
        agentProducer.sendFcmNFTExchangeMsg(fcmFeeCnt.toString());
        return new FebsResponse().success();
    }
    @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);
                }
            }
        }
        //卖单
        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);
                }
            }
        }
        return new FebsResponse().success().data(objects);
    }
    @Override
    public FebsResponse orderSell(ApiOrderSellInfoDto apiOrderSellInfoDto) {
        Long productSellId = apiOrderSellInfoDto.getId();
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiOrderSellInfoVo apiOrderSellInfoVo = mallProductSellMapper.selectSellInfoById(productSellId);
        if(ObjectUtil.isEmpty(apiOrderSellInfoVo)){
            throw new FebsException("记录不存在");
        }
        List<ApiOrderSellRecordInfoVo> apiOrderSellRecordInfoVos = mallProductSellRecordMapper.selectBySellId(productSellId);
        if(CollUtil.isNotEmpty(apiOrderSellRecordInfoVos)){
            apiOrderSellInfoVo.setApiOrderSellRecordInfoVos(apiOrderSellRecordInfoVos);
        }
        return new FebsResponse().success().data(apiOrderSellInfoVo);
    }
    @Override
    public FebsResponse orderBuy(ApiOrderBuyInfoDto apiOrderBuyInfoDto) {
        Long productBuyId = apiOrderBuyInfoDto.getId();
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiOrderBuyInfoVo apiOrderBuyInfoVo = mallProductBuyMapper.selectBuyById(productBuyId);
        if(ObjectUtil.isEmpty(apiOrderBuyInfoVo)){
            throw new FebsException("记录不存在");
        }
        List<ApiOrderBuyRecordInfoVo> apiOrderBuyRecordInfoVos = mallProductBuyRecordMapper.selectByBuyId(productBuyId);
        if(CollUtil.isNotEmpty(apiOrderBuyRecordInfoVos)){
            apiOrderBuyInfoVo.setApiOrderBuyRecordInfoVos(apiOrderBuyRecordInfoVos);
        }
        return new FebsResponse().success().data(apiOrderBuyInfoVo);
    }
}