package com.example.demo.serviceImpl.cash; import com.example.demo.domain.entity.CashRecord; import com.example.demo.domain.vo.cash.CashCollection; import com.example.demo.domain.vo.coin.Result; import com.example.demo.mapper.cash.CashCollectionMapper; import com.example.demo.mapper.coin.MarketMapper; import com.example.demo.service.cash.CashCollectionService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.UUID; /** * @program: gold-java * @ClassName cashCollectionServiceImpl * @description: * @author: Ethan * @create: 2025−09-26 11:23 * @Version 1.0 **/ @Service public class CashCollectionServiceImpl implements CashCollectionService { @Autowired private CashCollectionMapper cashCollectionMapper; @Autowired private MarketMapper marketMapper; //新增收款订单 @Override public Result add(CashCollection cashCollection) { if (cashCollection.getJwcode()==null){ return Result.error("精网号不能为空"); } if(cashCollection.getJwcode()<10000000||cashCollection.getJwcode()>99999999){ return Result.error("精网号必须为8位"); } if(cashCollection.getName()== null){ return Result.error("客户姓名不能为空"); } if(cashCollection.getActivity()== null){ return Result.error("活动不能为空"); } if(cashCollection.getGoodsName()== null){ return Result.error("商品名不能为空"); } if(cashCollection.getGoodNum()== null){ return Result.error("商品数量不能为空"); } if(cashCollection.getPaymentCurrency()== null){ return Result.error("支付币种不能为空"); } if(cashCollection.getPaymentAmount()== null){ return Result.error("支付金额不能为空"); } if (cashCollection.getPayType()== null){ return Result.error("支付方式不能为空"); } if (cashCollection.getReceivedMarket()== null){ return Result.error("到账地区不能为空"); } if(cashCollection.getPayTime()== null){ return Result.error("付款时间不能为空"); } if (cashCollection.getVoucher()== null){ return Result.error("转账凭证不能为空"); } if (cashCollection.getRemark()==null){ return Result.error("备注不能为空"); } //生成订单号后半部分 String orderNumber = UUID.randomUUID().toString().replaceAll("-", ""); CashRecord cashRecord = new CashRecord(); //构建订单信息 cashRecord.setOrderCode("XJ_" + orderNumber); //订单号 cashRecord.setJwcode(cashCollection.getJwcode()); //精网号 cashRecord.setName(cashCollection.getName()); //客户姓名 cashRecord.setActivity(cashCollection.getActivity()); // 活动 cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称 cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量 cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种 cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额 cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区 cashRecord.setPayType(cashCollection.getPayType()); //支付方式 cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间 cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证 cashRecord.setRemark(cashCollection.getRemark()); //备注 cashRecord.setStatus(0); //订单状态:付款线下财务待审核 cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID cashRecord.setOrderType(1); //订单类型:1-收款 //地区,根据jwcode插入 cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); //插入新收款订单 cashCollectionMapper.add(cashRecord); return Result.success("添加成功"); } //撤回未审核的订单 @Override public Result cancel(String orderCode) { CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode); if (cashRecord == null) { return Result.error("订单不存在"); } if (cashRecord.getStatus() != 0){ return Result.error("订单状态不符合条件"); } //修改订单状态 int rows = cashCollectionMapper.updateStatus(orderCode, 5); return rows > 0 ? Result.success("撤回成功") : Result.error("撤回失败"); } //编辑并重新提交收款订单 @Override public Result reSubmit(CashRecord cashRecord) { if (cashRecord.getJwcode()==null){ return Result.error("精网号不能为空"); } if(cashRecord.getJwcode()<10000000||cashRecord.getJwcode()>99999999){ return Result.error("精网号必须为8位"); } if(cashRecord.getName()== null){ return Result.error("客户姓名不能为空"); } if(cashRecord.getActivity()== null){ return Result.error("活动不能为空"); } if(cashRecord.getGoodsName()== null){ return Result.error("商品名不能为空"); } if(cashRecord.getGoodNum()== null){ return Result.error("商品数量不能为空"); } if(cashRecord.getPaymentCurrency()== null){ return Result.error("支付币种不能为空"); } if(cashRecord.getPaymentAmount()== null){ return Result.error("支付金额不能为空"); } if (cashRecord.getPayType()== null){ return Result.error("支付方式不能为空"); } if (cashRecord.getReceivedMarket()== null){ return Result.error("到账地区不能为空"); } if(cashRecord.getPayTime()== null){ return Result.error("付款时间不能为空"); } if (cashRecord.getVoucher()== null){ return Result.error("转账凭证不能为空"); } if (cashRecord.getRemark()==null){ return Result.error("备注不能为空"); } CashRecord status=cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode()); if (!status.getStatus().equals(5)){ return Result.error("只允许编辑已撤回订单"); } //地区,根据jwcode插入 cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode())); int rows = cashCollectionMapper.updateByOrderCode(cashRecord); return rows > 0 ? Result.success("重新提交成功") : Result.error("重新提交失败"); } //多条件查询收款订单列表 @Override public PageInfo selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) { //将操作人的地区列表改为id List markets = marketMapper.getMarketIds(cashCollection.getMarkets()); if (markets.contains("9") || markets.contains("9999")){ markets=null; } cashCollection.setMarkets(markets); PageHelper.startPage(pageNum, pageSize); List cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection); return new PageInfo<>(cashCollections); } //补全手续费等内容 @Override public Result complete(CashRecord cashRecord) { int rows = cashCollectionMapper.complete(cashRecord); return rows > 0 ? Result.success("编辑成功") : Result.error("编辑失败"); } }