无关风月
2025-02-28 c92df6e57423bfbd71c4b228337d99b7653755bd
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TBillServiceImpl.java
@@ -12,15 +12,13 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.TencentMailUtil;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.dto.OfflinePayCheckDto;
import com.ruoyi.system.dto.SmsByBillDto;
import com.ruoyi.system.dto.TBillDto;
import com.ruoyi.system.dto.TbillSaveDto;
import com.ruoyi.system.dto.*;
import com.ruoyi.system.mapper.TBillMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TBillQuery;
import com.ruoyi.system.query.TInvoiceToBillQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TBillVO;
import com.taxi591.bankapi.dto.ChargeBillRequest;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
@@ -243,32 +241,50 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean checkOfflinePay(OfflinePayCheckDto dto) {
        List<TBill> tBills = listByIds(dto.getBillIds());
        TBillConfirm confirm = tBillConfirmService.getById(dto.getConfirmId());
        lockAndUpdateByAmountBatch(tBills,dto.getAmount(),(bill)->{
        TBankFlow bankflow = tBankFlowService.getById(dto.getTBankFlow().getId());
        TBillDto bill = getDetailByBillId(dto.getBillId());
        if (bankflow.getRemainingMoney().compareTo(BigDecimal.ZERO)<=0){
            throw new ServiceException("该流水已无可抵扣剩余金额");
        }
        if (bankflow.getRemainingMoney().compareTo(dto.getAmount())<0){
            throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额");
        }
        //如果实付金额大于欠费金额
        if (dto.getAmount().compareTo(bill.getOutstandingMoney())>=0){
            throw new ServiceException("实付金额不能高于该账单欠费金额");
        }
        TBill billSave = new TBill();
        billSave.setId(bill.getId());
        billSave.setPayFeesMoney(dto.getAmount());
        billSave.setBankSerialNumber(dto.getTBankFlow().getBankSerialNumber());
        billSave.setPayFeesTime(dto.getTBankFlow().getPayTime());
        billSave.setVoucher(dto.getVoucher());
        billSave.setPayFeesType(2);
        TBill back = lockAndUpdateInfo(billSave, 2);
        //更新银行流水的已抵扣金额和剩余可抵扣金额
        TBankFlow saveBankFlow = new TBankFlow();
        saveBankFlow.setId(bankflow.getId());
        saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
        saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
        tBankFlowService.updateById(saveBankFlow);
        //存流水
            TFlowManagement save = new TFlowManagement();
            save.setPayType(3);
            save.setPayer(dto.getPayer());
            save.setPayTime(dto.getPayTime()==null?DateUtils.dateToLocalDateTime(confirm.getPayTime()):dto.getPayTime());
            save.setBankSerialNumber(dto.getBankSerilNum());
        save.setPayTime(dto.getTBankFlow().getPayTime());
        save.setBankSerialNumber(dto.getTBankFlow().getBankSerialNumber());
            save.setFlowType(2);
            save.setPaymentBillId(bill.getId());
            save.setDeductionMoney(bill.getDeductionMoney());
        save.setPaymentBillId(back.getId());
        save.setDeductionMoney(back.getDeductionMoney());
            save.setFlowMoney(dto.getAmount());
            save.setRemainingMoney(bill.getOutstandingMoney());
            save.setPreOutstand(bill.getPreOutstand());
        save.setRemainingMoney(back.getOutstandingMoney());
        save.setPreOutstand(back.getPreOutstand());
            tFlowManagementService.save(save);
        });
        TBankFlow bankFlow = new TBankFlow();
        bankFlow.setPayType(3);
        bankFlow.setPayer(dto.getPayer());
        bankFlow.setPayTime(dto.getPayTime()==null?DateUtils.dateToLocalDateTime(confirm.getPayTime()):dto.getPayTime());
        bankFlow.setBankSerialNumber(dto.getBankSerilNum());
        bankFlow.setFlowMoney(dto.getAmount());
        bankFlow.setFlowStatus(1);
        tBankFlowService.save(bankFlow);
        return false;
        return true;
    }
    @Override
@@ -344,16 +360,18 @@
     * @return
     */
    @Override
    public PageInfo<TBill> getBillByInvoiceId(String invoiceId){
        invoiceId = "1889552849671061505";
        PageInfo<TBill> pageInfo = new PageInfo<>();
        ArrayList<TBill> bills = new ArrayList<>();
    public PageInfo<TBillDto> getBillByInvoiceId(String invoiceId){
        PageInfo<TBillDto> pageInfo = new PageInfo<>();
        ArrayList<TBillDto> bills = new ArrayList<>();
        TInvoiceToBillQuery query = new TInvoiceToBillQuery();
        query.setInvoiceId(invoiceId);
        List<TInvoiceToBill> tInvoiceToBills = tInvoiceToBillService.makeQuery(query);
        for (TInvoiceToBill tInvoiceToBill : tInvoiceToBills) {
            TBill byId = getById(tInvoiceToBill.getBillId());
            bills.add(byId);
            TBill bill = getById(tInvoiceToBill.getBillId());
            if (bill != null && bill.getId() != null){
                TBillDto detailByBillId = getDetailByBillId(bill.getId());
                bills.add(detailByBillId);
            }
        }
        pageInfo.setRecords(bills);
        return pageInfo;
@@ -377,7 +395,7 @@
            TBill save = new TBill();
            save.setId(bill.getId());
            try {
                smsUtil.sendSms(bill.getPhone(), "", new String[]{""});
                smsUtil.sendSms(bill.getPhone(), "2365726", new String[]{bill.getPartyTwoName()});
                save.setSmsStatus(1);
            }catch (ServiceException e){
                failNum++;
@@ -395,9 +413,9 @@
        int failNum = 0;
        for (String billId : dto.getBillIds()) {
            TBillDto bill = getDetailByBillId(billId);
            if (bill.getSmsLastTime()!=null
                    && (System.currentTimeMillis()-bill.getSmsLastTime().getTime()<mailUtil.getPro().getBillMailDelayPeriod()*60*1000L)){
                throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getSmsLastTime()));
            if (bill.getMailLastTime()!=null
                    && (System.currentTimeMillis()-bill.getMailLastTime().getTime()<mailUtil.getPro().getBillMailDelayPeriod()*60*1000L)){
                throw new ServiceException("有账单最近一次发送的时间是:"+DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,bill.getMailLastTime()));
            }
            if (StringUtils.isEmpty(bill.getEmail())){
                failNum++;
@@ -423,5 +441,62 @@
        return getBaseMapper().selectDetailByBillId(billId);
    }
    /**
     * 收款、类型可能是现金、银行
     * @param dto
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean cashPay(CachPayDto dto) {
        TBill back = null;
        TBankFlow bankflow = null;
        if (dto.getPayType()==1){
            bankflow = tBankFlowService.getById(dto.getTBankFlow().getId());
            TBillDto bill = getDetailByBillId(dto.getBillId());
            if (bankflow.getRemainingMoney().compareTo(BigDecimal.ZERO)<=0){
                throw new ServiceException("该流水已无可抵扣剩余金额");
            }
            if (bankflow.getRemainingMoney().compareTo(dto.getAmount())<0){
                throw new ServiceException("实付金额不能高于于流水可抵扣剩余金额");
            }
            //如果实付金额大于欠费金额
            if (dto.getAmount().compareTo(bill.getOutstandingMoney())>=0){
                throw new ServiceException("实付金额不能高于该账单欠费金额");
            }
        }
        TBillDto bill = getDetailByBillId(dto.getBillId());
        TBill billSave = new TBill();
        billSave.setId(bill.getId());
        billSave.setPayFeesMoney(dto.getAmount());
        billSave.setBankSerialNumber(dto.getTBankFlow().getBankSerialNumber());
        billSave.setPayFeesTime(dto.getTBankFlow().getPayTime());
        billSave.setVoucher(dto.getVoucher());
        billSave.setPayFeesType(2);
        back = lockAndUpdateInfo(billSave, 2);
        if (dto.getPayType()==1){
            //更新银行流水的已抵扣金额和剩余可抵扣金额
            TBankFlow saveBankFlow = new TBankFlow();
            saveBankFlow.setId(bankflow.getId());
            saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount()));
            saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount()));
            tBankFlowService.updateById(saveBankFlow);
        }
        //存流水
        TFlowManagement save = new TFlowManagement();
        save.setPayType(3);
        save.setPayer(dto.getPayer());
        save.setPayTime(dto.getTBankFlow().getPayTime());
        save.setBankSerialNumber(dto.getTBankFlow().getBankSerialNumber());
        save.setFlowType(dto.getPayType()==1?2:1);
        save.setPaymentBillId(back.getId());
        save.setDeductionMoney(back.getDeductionMoney());
        save.setFlowMoney(dto.getAmount());
        save.setRemainingMoney(back.getOutstandingMoney());
        save.setPreOutstand(back.getPreOutstand());
        tFlowManagementService.save(save);
        return true;
    }
}