| | |
| | | package com.xcong.excoin.modules.otc.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.xcong.excoin.common.entity.QueryRequest; |
| | | import com.xcong.excoin.modules.member.entity.MemberAccountMoneyChangeEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberEntity; |
| | | import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity; |
| | | import com.xcong.excoin.modules.member.mapper.MemberMapper; |
| | | import com.xcong.excoin.modules.otc.entity.OtcMarketBussinessEntity; |
| | | import com.xcong.excoin.modules.otc.entity.OtcOrderAppealEntity; |
| | | import com.xcong.excoin.modules.otc.mapper.OtcMarketBussinessMapper; |
| | | import com.xcong.excoin.modules.otc.mapper.OtcOrderAppealMapper; |
| | | import com.xcong.excoin.modules.member.mapper.MemberWalletCoinMapper; |
| | | import com.xcong.excoin.modules.otc.entity.*; |
| | | import com.xcong.excoin.modules.otc.mapper.*; |
| | | import com.xcong.excoin.modules.otc.service.OtcService; |
| | | import com.xcong.excoin.modules.otc.vo.OtcAppealInfoVo; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @RequiredArgsConstructor |
| | |
| | | private OtcMarketBussinessMapper otcMarketBussinessMapper; |
| | | @Resource |
| | | private OtcOrderAppealMapper otcOrderAppealMapper; |
| | | @Resource |
| | | private OtcEntrustOrderMapper otcEntrustOrderMapper; |
| | | @Resource |
| | | private OtcOrderMapper otcOrderMapper; |
| | | @Resource |
| | | private OtcSettingMapper otcSettingMapper; |
| | | @Resource |
| | | private MemberWalletCoinMapper memberWalletCoinMapper; |
| | | @Resource |
| | | private MemberMapper memberMapper; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public FebsResponse dealIng(Long id) { |
| | | OtcOrderAppealEntity otcOrderAppealEntity = otcOrderAppealMapper.selectById(id); |
| | | Integer status = otcOrderAppealEntity.getStatus(); |
| | |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<OtcEntrustOrderEntity> otcEntrustList(OtcEntrustOrderEntity otcEntrustOrderEntity, QueryRequest request) { |
| | | Page<OtcEntrustOrderEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | IPage<OtcEntrustOrderEntity> otcEntrustOrderEntitys = otcEntrustOrderMapper.otcEntrustList(page, otcEntrustOrderEntity); |
| | | return otcEntrustOrderEntitys; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<OtcOrderEntity> otcOrderList(OtcOrderEntity otcOrderEntity, QueryRequest request) { |
| | | Page<OtcOrderEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | IPage<OtcOrderEntity> otcOrderEntitys = otcOrderMapper.otcOrderList(page, otcOrderEntity); |
| | | return otcOrderEntitys; |
| | | } |
| | | |
| | | @Override |
| | | public OtcAppealInfoVo otcAppealInfo(long id) { |
| | | OtcAppealInfoVo otcAppealInfoVo = new OtcAppealInfoVo(); |
| | | |
| | | OtcOrderAppealEntity otcOrderAppealEntity = otcOrderAppealMapper.selectById(id); |
| | | otcAppealInfoVo.setId(id); |
| | | if(ObjectUtil.isNotEmpty(otcOrderAppealEntity)){ |
| | | String reason = otcOrderAppealEntity.getReason(); |
| | | otcAppealInfoVo.setReason(reason); |
| | | String content = otcOrderAppealEntity.getContent(); |
| | | List arr = Arrays.asList(content.split(",")); |
| | | otcAppealInfoVo.setContent(arr); |
| | | } |
| | | //获取对应的订单详情 |
| | | long orderId = otcOrderAppealEntity.getOrderId(); |
| | | OtcOrderEntity otcOrderEntity = otcOrderMapper.selectById(orderId); |
| | | if(ObjectUtil.isNotEmpty(otcOrderEntity)){ |
| | | String orderNo = otcOrderEntity.getOrderNo(); |
| | | otcAppealInfoVo.setOrderNo(orderNo); |
| | | BigDecimal unitPrice = otcOrderEntity.getUnitPrice(); |
| | | otcAppealInfoVo.setUnitPrice(unitPrice); |
| | | BigDecimal coinAmount = otcOrderEntity.getCoinAmount(); |
| | | otcAppealInfoVo.setCoinAmount(coinAmount); |
| | | BigDecimal totalAmount = otcOrderEntity.getTotalAmount(); |
| | | otcAppealInfoVo.setTotalAmount(totalAmount); |
| | | Integer status = otcOrderEntity.getStatus(); |
| | | otcAppealInfoVo.setStatus(status); |
| | | Date payTime = otcOrderEntity.getPayTime(); |
| | | otcAppealInfoVo.setPayTime(payTime); |
| | | Date finishTime = otcOrderEntity.getFinishTime(); |
| | | otcAppealInfoVo.setFinishTime(finishTime); |
| | | } |
| | | //获取对应的商户信息 |
| | | long payMdId = otcOrderEntity.getPayMbId(); |
| | | OtcMarketBussinessEntity otcMarketBussinessEntity = otcMarketBussinessMapper.selectById(payMdId); |
| | | if(ObjectUtil.isNotEmpty(otcMarketBussinessEntity)){ |
| | | String nikename = otcMarketBussinessEntity.getNikename(); |
| | | otcAppealInfoVo.setNikename(nikename); |
| | | } |
| | | return otcAppealInfoVo; |
| | | } |
| | | |
| | | @Override |
| | | public OtcOrderEntity otcOrderInfo(long id) { |
| | | OtcOrderEntity otcOrderEntity = otcOrderMapper.selectById(id); |
| | | return otcOrderEntity; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public FebsResponse updateOrderInfo(OtcOrderEntity otcOrderEntity) { |
| | | Long id = otcOrderEntity.getId(); |
| | | OtcOrderEntity otcOrder = otcOrderMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(otcOrder)){ |
| | | return new FebsResponse().fail().message("连接超时,请刷新页面重试"); |
| | | } |
| | | Integer status = otcOrder.getStatus(); |
| | | if(OtcOrderEntity.STATUS_ONE != status){ |
| | | return new FebsResponse().fail().message("当前订单不是待付款状态"); |
| | | } |
| | | String payName = otcOrderEntity.getPayName(); |
| | | if(StrUtil.isEmpty(payName)){ |
| | | return new FebsResponse().fail().message("请输入付款人"); |
| | | } |
| | | BigDecimal coinAmount = otcOrderEntity.getCoinAmount(); |
| | | /** |
| | | * 获取订单信息--订单编号 |
| | | * 获取买单和买单 |
| | | * 更新payName字段 |
| | | * 更新订单状态 |
| | | */ |
| | | QueryWrapper<OtcOrderEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("order_no",otcOrder.getOrderNo()); |
| | | List<OtcOrderEntity> list = otcOrderMapper.selectList(queryWrapper); |
| | | if(CollUtil.isNotEmpty(list)){ |
| | | for(OtcOrderEntity order : list){ |
| | | order.setStatus(OtcOrderEntity.STATUS_TWO); |
| | | order.setPayName(payName); |
| | | order.setPayTime(DateUtil.date()); |
| | | otcOrderMapper.updateById(order); |
| | | } |
| | | } |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public OtcMarketBussinessEntity otcHuiKuan(long id) { |
| | | return otcMarketBussinessMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public FebsResponse otcHuiKuan(OtcMarketBussinessEntity otcMarketBussinessEntity) { |
| | | Long id = otcMarketBussinessEntity.getId(); |
| | | OtcMarketBussinessEntity otcMarketBussiness = otcMarketBussinessMapper.selectById(id); |
| | | if(ObjectUtil.isNotEmpty(otcMarketBussiness)){ |
| | | return new FebsResponse().fail().message("连接超时,请刷新页面重试"); |
| | | } |
| | | BigDecimal coinAmount = otcMarketBussinessEntity.getCoinAmount(); |
| | | if(coinAmount.compareTo(BigDecimal.ZERO) <= 0){ |
| | | return new FebsResponse().fail().message("请输入正确的回款金额"); |
| | | } |
| | | BigDecimal waitBackMoney = otcMarketBussiness.getWaitBackMoney(); |
| | | if(coinAmount.compareTo(waitBackMoney) > 0){ |
| | | return new FebsResponse().fail().message("请输入正确的回款金额"); |
| | | } |
| | | /** |
| | | * 增加已回款金额 |
| | | * 减少待回款金额 |
| | | * 增加汇款记录 |
| | | */ |
| | | BigDecimal hasBackMoney = otcMarketBussiness.getHasBackMoney(); |
| | | BigDecimal add = hasBackMoney.add(coinAmount); |
| | | otcMarketBussiness.setHasBackMoney(add); |
| | | |
| | | BigDecimal subtract = waitBackMoney.subtract(coinAmount); |
| | | otcMarketBussiness.setWaitBackMoney(subtract); |
| | | otcMarketBussinessMapper.updateById(otcMarketBussiness); |
| | | |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<OtcSettingEntity> otcSettingList(OtcSettingEntity otcSettingEntity, QueryRequest request) { |
| | | Page<OtcSettingEntity> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | IPage<OtcSettingEntity> otcSettingEntitys = otcSettingMapper.otcSettingList(page, otcSettingEntity); |
| | | return otcSettingEntitys; |
| | | } |
| | | |
| | | @Override |
| | | public OtcSettingEntity otcSettingUpdate(long id) { |
| | | return otcSettingMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse updateOtcSetting(OtcSettingEntity otcSettingEntity) { |
| | | Integer orderNum = otcSettingEntity.getOrderNum(); |
| | | if(ObjectUtil.isEmpty(orderNum) || orderNum < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的总单数"); |
| | | } |
| | | BigDecimal completionRate = otcSettingEntity.getCompletionRate(); |
| | | if(ObjectUtil.isEmpty(completionRate) || completionRate.compareTo(BigDecimal.ZERO) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的完成率"); |
| | | } |
| | | BigDecimal totalAmount = otcSettingEntity.getTotalAmount(); |
| | | if(ObjectUtil.isEmpty(totalAmount) || totalAmount.compareTo(BigDecimal.ZERO) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的总金额"); |
| | | } |
| | | |
| | | Integer cancellNum = otcSettingEntity.getCancellNum(); |
| | | if(ObjectUtil.isEmpty(cancellNum) || cancellNum < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的取消次数"); |
| | | } |
| | | otcSettingMapper.updateById(otcSettingEntity); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int reduceCoin(Long id) { |
| | | OtcOrderEntity order = otcOrderMapper.selectById(id); |
| | | |
| | | MemberWalletCoinEntity saleWallet = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(order.getMemberId(), "USDT"); |
| | | MemberWalletCoinEntity buyWallet = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(order.getOppositeMemberId(), "USDT"); |
| | | |
| | | memberWalletCoinMapper.updateBlockBalance(order.getCoinAmount(), buyWallet.getId()); |
| | | memberWalletCoinMapper.reduceFrozenBalance(order.getCoinAmount(), saleWallet.getId()); |
| | | |
| | | otcOrderMapper.updateOrderStatusByOrderNo(OtcOrderEntity.STATUS_THREE, order.getOrderNo()); |
| | | return 1; |
| | | } |
| | | |
| | | @Override |
| | | public OtcEntrustOrderEntity otcEntrustListUpdate(long id) { |
| | | return otcEntrustOrderMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse otcEntrustConfirm(OtcEntrustOrderEntity otcEntrustOrderEntity) { |
| | | Long id = otcEntrustOrderEntity.getId(); |
| | | OtcEntrustOrderEntity otcEntrustOrder = otcEntrustOrderMapper.selectById(id); |
| | | BigDecimal unitPrice = otcEntrustOrderEntity.getUnitPrice(); |
| | | if(ObjectUtil.isEmpty(unitPrice) || unitPrice.compareTo(BigDecimal.ZERO) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的单价"); |
| | | } |
| | | otcEntrustOrder.setUnitPrice(unitPrice); |
| | | BigDecimal coinAmount = otcEntrustOrderEntity.getCoinAmount(); |
| | | if(ObjectUtil.isEmpty(coinAmount) || coinAmount.compareTo(BigDecimal.ZERO) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的数量"); |
| | | } |
| | | otcEntrustOrder.setCoinAmount(coinAmount); |
| | | BigDecimal totalAmount = coinAmount.multiply(unitPrice); |
| | | otcEntrustOrder.setTotalAmount(totalAmount); |
| | | |
| | | BigDecimal remainCoinAmount = otcEntrustOrderEntity.getRemainCoinAmount(); |
| | | if(ObjectUtil.isEmpty(remainCoinAmount) || remainCoinAmount.compareTo(BigDecimal.ZERO) < 0 |
| | | || totalAmount.compareTo(remainCoinAmount) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的剩余数量"); |
| | | } |
| | | otcEntrustOrder.setRemainCoinAmount(remainCoinAmount); |
| | | BigDecimal limitMinAmount = otcEntrustOrderEntity.getLimitMinAmount(); |
| | | if(ObjectUtil.isEmpty(limitMinAmount) || limitMinAmount.compareTo(BigDecimal.ZERO) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的最小限额"); |
| | | } |
| | | otcEntrustOrder.setLimitMinAmount(limitMinAmount); |
| | | BigDecimal limitMaxAmount = otcEntrustOrderEntity.getLimitMaxAmount(); |
| | | if(ObjectUtil.isEmpty(limitMaxAmount) || limitMaxAmount.compareTo(BigDecimal.ZERO) < 0 |
| | | || limitMaxAmount.compareTo(limitMinAmount) < 0 || totalAmount.compareTo(limitMaxAmount) < 0){ |
| | | return new FebsResponse().fail().message("请设置正确的最大限额"); |
| | | } |
| | | otcEntrustOrder.setLimitMaxAmount(limitMaxAmount); |
| | | otcEntrustOrder.setStatus(otcEntrustOrderEntity.getStatus()); |
| | | otcEntrustOrderMapper.updateById(otcEntrustOrder); |
| | | |
| | | return new FebsResponse().success(); |
| | | } |
| | | } |