package cc.mrbird.febs.mall.service.impl; import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.common.entity.QueryRequest; import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; import cc.mrbird.febs.common.enumerates.FlowTypeNewEnum; import cc.mrbird.febs.common.enumerates.MoneyFlowTypeNewEnum; import cc.mrbird.febs.common.enumerates.ProductEnum; 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.conversion.MallProductNftConversion; import cc.mrbird.febs.mall.dto.AdminBuyRecordPayDto; import cc.mrbird.febs.mall.dto.AdminMallProductNftDto; import cc.mrbird.febs.mall.dto.AdminPickSellRecordDtoDto; import cc.mrbird.febs.mall.dto.MallNewsInfoDto; import cc.mrbird.febs.mall.entity.*; import cc.mrbird.febs.mall.mapper.*; import cc.mrbird.febs.mall.service.IMallMoneyFlowService; import cc.mrbird.febs.mall.service.IMallNewsInfoService; import cc.mrbird.febs.mall.vo.*; import cc.mrbird.febs.rabbit.producter.AgentProducer; import cn.hutool.core.bean.BeanUtil; 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.core.util.StrUtil; 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; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.List; /** * @author wzy * @date 2022-05-13 **/ @Slf4j @Service @RequiredArgsConstructor public class MallNewsInfoServiceImpl extends ServiceImpl implements IMallNewsInfoService { private final MallNewsCategoryMapper mallNewsCategoryMapper; private final MallProductNftMapper mallProductNftMapper; private final MallProductBuyMapper mallProductBuyMapper; private final MallProductSellMapper mallProductSellMapper; private final MallProductSellRecordMapper mallProductSellRecordMapper; private final MallProductBuyRecordMapper mallProductBuyRecordMapper; private final IMallMoneyFlowService mallMoneyFlowService; private final AgentProducer agentProducer; private final MallMemberSpeakMapper mallMemberSpeakMapper; private final DataDictionaryCustomMapper dataDictionaryCustomMapper; @Override public IPage getNewInfoList(MallNewsInfo mallNewsInfo, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallNewsInfoVos = this.baseMapper.getNewInfoListInPage(page, mallNewsInfo); return adminMallNewsInfoVos; } @Override public FebsResponse addNewsInfo(MallNewsInfoDto mallNewsInfoDto) { // Integer type = mallNewsInfoDto.getType(); // if(type == 2){ // Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); // if(goodsId == 0L){ // return new FebsResponse().fail().message("请选择跳转的产品"); // } // } // MallNewsInfo mallNewsInfo = new MallNewsInfo(); // mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); // mallNewsInfo.setContent(mallNewsInfoDto.getContent()); // mallNewsInfo.setType(mallNewsInfoDto.getType()); // if(mallNewsInfoDto.getType() == 2){ // mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); // } String content = mallNewsInfoDto.getContent(); if(StrUtil.isNotBlank(content)){ //正文图片样式居中 mallNewsInfoDto.setContent(content+""); } MallNewsInfo mallNewsInfo = new MallNewsInfo(); BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); this.baseMapper.insert(mallNewsInfo); return new FebsResponse().success(); } @Override public FebsResponse delNewsInfo(Long id) { MallNewsInfo mallNewsInfo = this.baseMapper.selectById(id); if(ObjectUtil.isEmpty(mallNewsInfo)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } this.baseMapper.deleteById(id); return new FebsResponse().success(); } @Override public FebsResponse updateNewsInfo(MallNewsInfoDto mallNewsInfoDto) { MallNewsInfo mallNewsInfoBefore = this.baseMapper.selectById(mallNewsInfoDto.getId()); if(ObjectUtil.isEmpty(mallNewsInfoBefore)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } // Integer type = mallNewsInfoDto.getType(); // if(type == 2){ // Long goodsId = mallNewsInfoDto.getGoodsId()==null?0L:mallNewsInfoDto.getGoodsId(); // if(goodsId == 0L){ // return new FebsResponse().fail().message("请选择跳转的产品"); // } // } // MallNewsInfo mallNewsInfo = new MallNewsInfo(); // mallNewsInfo.setTitle(mallNewsInfoDto.getTitle()); // mallNewsInfo.setContent(mallNewsInfoDto.getContent()); // mallNewsInfo.setType(mallNewsInfoDto.getType()); // if(mallNewsInfoDto.getType() == 2){ // mallNewsInfo.setTargetId(mallNewsInfoDto.getGoodsId()); // } // this.baseMapper.insert(mallNewsInfo); // this.baseMapper.deleteById(mallNewsInfoDto.getId()); String content = mallNewsInfoDto.getContent(); if(StrUtil.isNotBlank(content)){ //正文图片样式居中 mallNewsInfoDto.setContent(content+""); } MallNewsInfo mallNewsInfo = new MallNewsInfo(); BeanUtil.copyProperties(mallNewsInfoDto, mallNewsInfo); this.baseMapper.updateById(mallNewsInfo); return new FebsResponse().success(); } @Override public MallNewsInfo getNewsInfoById(long id) { return this.baseMapper.selectById(id); } @Override public IPage findNewsCategoryInPage(MallNewsCategory mallNewsCategory, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); return mallNewsCategoryMapper.selectInPage(mallNewsCategory, page); } @Override public void addOrModifyNewsCategory(MallNewsCategory mallNewsCategory) { if (mallNewsCategory.getId() != null) { mallNewsCategoryMapper.updateById(mallNewsCategory); return; } mallNewsCategoryMapper.insert(mallNewsCategory); } @Override public MallNewsCategory findNewsCategoryById(Long id) { return mallNewsCategoryMapper.selectById(id); } @Override public List findAllCategory() { return mallNewsCategoryMapper.selectList(null); } @Override public FebsResponse delNewsCategoryInfo(Long id) { MallNewsCategory mallNewsCategory = mallNewsCategoryMapper.selectById(id); if(ObjectUtil.isEmpty(mallNewsCategory)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } mallNewsCategoryMapper.deleteById(id); return new FebsResponse().success(); } @Override public IPage getProductNFTList(MallProductNft mallProductNft, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallNewsInfoVoIPage = mallProductNftMapper.getProductNFTList(page, mallProductNft); return adminMallNewsInfoVoIPage; } @Override public FebsResponse addProductNFT(AdminMallProductNftDto adminMallProductNftDto) { MallProductNft mallProductNft = MallProductNftConversion.INSTANCE.dtoToEntity(adminMallProductNftDto); mallProductNftMapper.insert(mallProductNft); return new FebsResponse().success(); } @Override public FebsResponse delNFT(Long id) { MallProductNft mallProductNft = mallProductNftMapper.selectById(id); if(ObjectUtil.isEmpty(mallProductNft)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } mallProductNftMapper.deleteById(id); return new FebsResponse().success(); } @Override public FebsResponse nftInfoUpdate(MallProductNft mallProductNft) { mallProductNftMapper.updateById(mallProductNft); return new FebsResponse().success(); } @Override public IPage getBuyList(MallProductBuy mallProductBuy, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallProductBuyVoIPage = mallProductNftMapper.getBuyList(page, mallProductBuy); DateTime nowTime = DateUtil.parseTime(DateUtil.formatTime(DateUtil.date())); DataDictionaryCustom endTimeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( DataDictionaryEnum.YU_YUE_END_TIME.getType(), DataDictionaryEnum.YU_YUE_END_TIME.getCode() ); DateTime endTime = DateUtil.parseTime(endTimeDic.getValue()); /** * 当前时间比结束时间大 */ List records = adminMallProductBuyVoIPage.getRecords(); if(CollUtil.isNotEmpty(records)){ for(AdminMallProductBuyVo adminMallProductBuyVo :records){ if(nowTime.compareTo(endTime) >= 0){ adminMallProductBuyVo.setButtonState(0); }else{ adminMallProductBuyVo.setButtonState(1); } } } return adminMallProductBuyVoIPage; } @Override public IPage getBuyRecordList(MallProductBuy mallProductBuy, QueryRequest request) { if(ObjectUtil.isNotEmpty(mallProductBuy.getAccountLogin())){ String accountLogin = mallProductBuy.getAccountLogin(); } Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage mallProductBuyRecordIPage = mallProductNftMapper.getBuyRecordList(page, mallProductBuy); return mallProductBuyRecordIPage; } @Override public IPage getSellList(MallProductSell mallProductSell, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallProductSellVoIPage = mallProductNftMapper.getSellList(page, mallProductSell); return adminMallProductSellVoIPage; } @Override public List findSellList() { List list = mallProductNftMapper.selectProductSellByState(ProductEnum.PRODUCT_SELL_ON_GOING.getValue()); return list; } @Override public FebsResponse pickSellRecord(AdminPickSellRecordDtoDto pickSellRecordDto) { /** * 买单条件是否满足 * 卖单条件是否满足 * 生成卖单子记录 * 生成买单子记录 * 更新卖单状态 * 更新买单状态 */ Long productBuyId = pickSellRecordDto.getId(); Long productSellId = pickSellRecordDto.getProductSellId(); BigDecimal pickNftCnt = new BigDecimal(pickSellRecordDto.getPickNftCnt()); //买单 MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(productBuyId); int state = mallProductBuy.getState(); if(ProductEnum.PRODUCT_BUY_ON_GOING.getValue() != state){ return new FebsResponse().fail().message("预约状态不是进行中"); } BigDecimal nftAva = mallProductBuy.getNftAva(); if(BigDecimal.ZERO.compareTo(pickNftCnt) >= 0){ return new FebsResponse().fail().message("本次金额不能小于等于零"); } if(nftAva.compareTo(pickNftCnt) < 0){ return new FebsResponse().fail().message("可分配不足"); } //卖单 MallProductSell mallProductSell = mallProductSellMapper.selectById(productSellId); BigDecimal nftCntAva = mallProductSell.getNftCntAva(); if(ProductEnum.PRODUCT_SELL_ON_GOING.getValue() != mallProductSell.getState()){ return new FebsResponse().fail().message("预约状态不是进行中"); } if(nftCntAva.compareTo(pickNftCnt) < 0){ return new FebsResponse().fail().message("匹配提现剩余不足"); } DateTime orderTime = DateUtil.date(); //生成卖单子记录 MallProductSellRecord mallProductSellRecord = new MallProductSellRecord(); mallProductSellRecord.setSellId(mallProductSell.getId()); mallProductSellRecord.setMemberId(mallProductBuy.getMemberId()); mallProductSellRecord.setOrderTime(orderTime); mallProductSellRecord.setNftCnt(pickNftCnt); mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue()); mallProductSellRecordMapper.insert(mallProductSellRecord); //生成买单子记录 MallProductBuyRecord mallProductBuyRecord = new MallProductBuyRecord(); mallProductBuyRecord.setBuyId(mallProductBuy.getId()); mallProductBuyRecord.setMemberId(mallProductSell.getMemberId()); mallProductBuyRecord.setSellRecordId(mallProductSellRecord.getId()); mallProductBuyRecord.setPickNftCnt(pickNftCnt); mallProductBuyRecord.setBuyOrderNo(mallProductBuy.getOrderNo()); mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue()); mallProductBuyRecord.setOrderTime(orderTime); mallProductBuyRecordMapper.insert(mallProductBuyRecord); //更新卖单 mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().subtract(pickNftCnt)); mallProductSellMapper.updateById(mallProductSell); mallProductSellRecord.setBuyRecordId(mallProductBuyRecord.getId()); mallProductSellRecordMapper.updateById(mallProductSellRecord); //更新买单 mallProductBuy.setNftAva(mallProductBuy.getNftAva().subtract(pickNftCnt)); mallProductBuyMapper.updateById(mallProductBuy); return new FebsResponse().success(); } @Override public FebsResponse buyRecordPay(AdminBuyRecordPayDto buyRecordPayDto) { Long buyRecordId = buyRecordPayDto.getId(); String nftImg = buyRecordPayDto.getNftImg(); Integer type = buyRecordPayDto.getType(); /** * 验证订单是否存在 * 更新买单状态 * 更新卖单状态 * 生成流水信息 */ 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"); mallMoneyFlowService.addMoneyFlow( mallProductSellRecord.getMemberId(), mallProductBuyRecord.getPickNftCnt(), MoneyFlowTypeNewEnum.PAY.getValue(), orderNo, mallProductSellRecord.getMemberId(), FlowTypeNewEnum.NFT.getValue(), MoneyFlowTypeNewEnum.PAY.getDescrition()); return new FebsResponse().success(); } @Override public FebsResponse buyRecordConfirm(Long id) { /** * 验证订单是否存在 * 更新买单状态 * 更新卖单状态 * 生成流水信息 */ MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(id); if(ObjectUtil.isEmpty(mallProductBuyRecord)){ throw new FebsException("记录不存在"); } // Integer state = mallProductBuyRecord.getState(); // if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != state){ // throw new FebsException("记录不是已支付状态"); // } Long sellRecordId = mallProductBuyRecord.getSellRecordId(); MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(mallProductBuyRecord.getSellRecordId()); if(ObjectUtil.isEmpty(mallProductSellRecord)){ throw new FebsException("记录不存在"); } // Integer stateSell = mallProductSellRecord.getState(); // if(ProductEnum.PRODUCT_MATE_STATE_PAY.getValue() != stateSell){ // 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(); } @Override public FebsResponse buyRecordCancel(Long id) { MallProductBuyRecord mallProductBuyRecord = mallProductBuyRecordMapper.selectById(id); if(ObjectUtil.isEmpty(mallProductBuyRecord)){ throw new FebsException("记录不存在"); } // Integer state = mallProductBuyRecord.getState(); // if(ProductEnum.PRODUCT_MATE_STATE_WAIT_PAY.getValue() != state){ // throw new FebsException("记录不是待支付状态"); // } Long sellRecordId = mallProductBuyRecord.getSellRecordId(); //更新买单子表的数据 mallProductBuyRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); mallProductBuyRecordMapper.updateById(mallProductBuyRecord); //更新买单主表 MallProductBuy mallProductBuy = mallProductBuyMapper.selectById(mallProductBuyRecord.getBuyId()); mallProductBuy.setNftAva(mallProductBuy.getNftAva().add(mallProductBuyRecord.getPickNftCnt())); mallProductBuyMapper.updateById(mallProductBuy); //更新卖单子表的数据 MallProductSellRecord mallProductSellRecord = mallProductSellRecordMapper.selectById(sellRecordId); mallProductSellRecord.setState(ProductEnum.PRODUCT_MATE_STATE_FAIL.getValue()); mallProductSellRecordMapper.updateById(mallProductSellRecord); //更新卖单主表 Long sellId = mallProductSellRecord.getSellId(); MallProductSell mallProductSell = mallProductSellMapper.selectById(sellId); mallProductSell.setNftCntAva(mallProductSell.getNftCntAva().add(mallProductSellRecord.getNftCnt())); mallProductSellMapper.updateById(mallProductSell); return new FebsResponse().success(); } @Override public IPage getSpeakList(MallMemberSpeak mallMemberSpeak, QueryRequest request) { Page page = new Page<>(request.getPageNum(), request.getPageSize()); IPage adminMallNewsInfoVoIPage = mallProductSellMapper.getSpeakListInPage(page, mallMemberSpeak); return adminMallNewsInfoVoIPage; } }