| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.config.SmsProperties; |
| | | import com.ruoyi.common.constant.AmountConstant; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.*; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.OrderNos; |
| | | import com.ruoyi.common.utils.SmsUtil; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.TencentMailUtil; |
| | | import com.ruoyi.common.utils.uuid.UUID; |
| | | import com.ruoyi.system.dto.*; |
| | | import com.ruoyi.system.dto.BillStatisticsDto; |
| | | import com.ruoyi.system.dto.CachPayDto; |
| | | 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.mapper.TBillMapper; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.model.TBankFlow; |
| | | import com.ruoyi.system.model.TBill; |
| | | import com.ruoyi.system.model.TBillDetail; |
| | | import com.ruoyi.system.model.TFlowManagement; |
| | | import com.ruoyi.system.model.TInvoiceToBill; |
| | | import com.ruoyi.system.model.TOrderBill; |
| | | import com.ruoyi.system.model.TPayOrder; |
| | | import com.ruoyi.system.query.TBillQuery; |
| | | import com.ruoyi.system.query.TInvoiceToBillQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.service.TBankFlowService; |
| | | import com.ruoyi.system.service.TBillConfirmService; |
| | | import com.ruoyi.system.service.TBillDetailService; |
| | | import com.ruoyi.system.service.TBillService; |
| | | import com.ruoyi.system.service.TFlowManagementService; |
| | | import com.ruoyi.system.service.TInvoiceToBillService; |
| | | import com.ruoyi.system.service.TOrderBillService; |
| | | import com.ruoyi.system.service.TPayOrderService; |
| | | import com.ruoyi.system.vo.ScreenRentRankVO; |
| | | import com.taxi591.bankapi.dto.ChargeBillRequest; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jetbrains.annotations.NotNull; |
| | |
| | | import javax.validation.constraints.NotEmpty; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean checkOfflinePay(OfflinePayCheckDto dto) { |
| | | TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId()); |
| | | 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("实付金额不能高于该账单欠费金额"); |
| | | } |
| | | if (dto.getPayType()==1){ //银行 |
| | | if (StringUtils.isEmpty(dto.getFlowId())){ |
| | | throw new ServiceException("银行流水ID不能为空"); |
| | | } |
| | | TBankFlow bankflow = tBankFlowService.getById(dto.getFlowId()); |
| | | 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(bankflow.getBankSerialNumber()); |
| | | billSave.setPayFeesTime(bankflow.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())); |
| | | BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount()); |
| | | saveBankFlow.setRemainingMoney(subtract); |
| | | if (BigDecimal.ZERO.compareTo(subtract) == 0){ |
| | | saveBankFlow.setFlowStatus(1); |
| | | } |
| | | tBankFlowService.updateById(saveBankFlow); |
| | | //更新银行流水的已抵扣金额和剩余可抵扣金额 |
| | | |
| | | //存流水 |
| | | TFlowManagement save = new TFlowManagement(); |
| | | save.setPayType(3); |
| | | save.setPayer(dto.getPayer()); |
| | | save.setPayTime(bankflow.getPayTime()); |
| | | save.setSysSerialNumber(OrderNos.getDid(30)); |
| | | save.setBankSerialNumber(bankflow.getBankSerialNumber()); |
| | | save.setFlowType(2); |
| | | 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; |
| | | } |
| | | //现金支付 |
| | | TBill billSave = new TBill(); |
| | | billSave.setId(bill.getId()); |
| | | billSave.setPayFeesMoney(dto.getAmount()); |
| | | billSave.setBankSerialNumber(bankflow.getBankSerialNumber()); |
| | | billSave.setPayFeesTime(bankflow.getPayTime()); |
| | | billSave.setPayFeesTime(dto.getPayTime()!=null?dto.getPayTime():DateUtils.dateToLocalDateTime(new Date())); |
| | | 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(bankflow.getPayTime()); |
| | | save.setPayTime(billSave.getPayFeesTime()); |
| | | save.setSysSerialNumber(OrderNos.getDid(30)); |
| | | save.setBankSerialNumber(bankflow.getBankSerialNumber()); |
| | | save.setFlowType(2); |
| | | save.setFlowType(1); |
| | | save.setPaymentBillId(back.getId()); |
| | | save.setDeductionMoney(back.getDeductionMoney()); |
| | | save.setFlowMoney(dto.getAmount()); |
| | |
| | | TBankFlow saveBankFlow = new TBankFlow(); |
| | | saveBankFlow.setId(bankflow.getId()); |
| | | saveBankFlow.setDeductionMoney(bankflow.getDeductionMoney().add(dto.getAmount())); |
| | | saveBankFlow.setRemainingMoney(bankflow.getRemainingMoney().subtract(dto.getAmount())); |
| | | BigDecimal subtract = bankflow.getRemainingMoney().subtract(dto.getAmount()); |
| | | saveBankFlow.setRemainingMoney(subtract); |
| | | if (BigDecimal.ZERO.compareTo(subtract) == 0){ |
| | | saveBankFlow.setFlowStatus(1); |
| | | } |
| | | tBankFlowService.updateById(saveBankFlow); |
| | | } |
| | | //存流水 |
| | |
| | | save.setPayType(3); |
| | | save.setPayer(dto.getPayer()); |
| | | save.setPayTime(bankflow!=null?bankflow.getPayTime():DateUtils.dateToLocalDateTime(new Date())); |
| | | save.setSysSerialNumber(OrderNos.getDid()); |
| | | save.setBankSerialNumber(bankflow!=null?bankflow.getBankSerialNumber():null); |
| | | save.setFlowType(dto.getPayType()==1?2:1); |
| | | save.setPaymentBillId(back.getId()); |
| | |
| | | return dto; |
| | | } |
| | | |
| | | @Override |
| | | public Integer batchBillCount(String userId, List<String> billIds) { |
| | | return this.baseMapper.batchBillCount(userId,billIds); |
| | | } |
| | | |
| | | /** |
| | | * 街道租金排行 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<ScreenRentRankVO> getStreetRentRank() { |
| | | return baseMapper.getStreetRentRank(); |
| | | } |
| | | } |