| | |
| | | import com.mzl.flower.entity.supplier.Station; |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.entity.system.UserWechat; |
| | | import com.mzl.flower.entity.wallet.WalletBillRecordDO; |
| | | import com.mzl.flower.entity.wallet.WalletBillRecordDetail; |
| | | import com.mzl.flower.entity.wallet.WalletDO; |
| | | import com.mzl.flower.mapper.flower.FlowerSupplierSaleNumMapper; |
| | | import com.mzl.flower.mapper.payment.*; |
| | | import com.mzl.flower.mapper.supplier.StationMapper; |
| | | import com.mzl.flower.mapper.system.UserWechatMapper; |
| | | import com.mzl.flower.mapper.wallet.WalletBillRecordDetailMapper; |
| | | import com.mzl.flower.mapper.wallet.WalletBillRecordMapper; |
| | | import com.mzl.flower.mapper.wallet.WalletMapper; |
| | | import com.mzl.flower.service.BaseService; |
| | | import com.mzl.flower.utils.UUIDGenerator; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | |
| | | @Autowired |
| | | private TransferDetailMapper transferDetailMapper; |
| | | |
| | | @Autowired |
| | | private WalletBillRecordMapper walletBillRecordMapper; |
| | | |
| | | @Autowired |
| | | private WalletMapper walletMapper; |
| | | |
| | | @Autowired |
| | | private WalletBillRecordDetailMapper walletBillRecordDetailMapper; |
| | | |
| | | public Page<OrderSettlementListDTO> selectSettlementList(Page page, OrderSettlementQueryDTO dto){ |
| | | dto.setStartDate(parseLocalDateTime(dto.getStartDateStr(), true)); |
| | | dto.setEndDate(parseLocalDateTime(dto.getEndDateStr(), false)); |
| | |
| | | if(settlement == null){ |
| | | throw new ValidationException("结算单不存在"); |
| | | } |
| | | String type = settlement.getType(); |
| | | |
| | | //2024-10-23 |
| | | //供应商新的结算逻辑不结算供应商的钱。 |
| | | if (Constants.SETTLEMENT_TYPE.supplier.name().equals(type)) { |
| | | throw new ValidationException("供应商不需要手动结算"); |
| | | } |
| | | String status = settlement.getStatus(); |
| | | if(Constants.SETTLEMENT_STATUS.PROCESSING.name().equals(status)){ |
| | | throw new ValidationException("结算中,不用重复结算"); |
| | |
| | | if(Constants.SETTLEMENT_STATUS.COMPLETED.name().equals(status)){ |
| | | throw new ValidationException("结算成功,不用重复结算"); |
| | | } |
| | | String type = settlement.getType(); |
| | | |
| | | String name = ""; |
| | | if(Constants.SETTLEMENT_TYPE.supplier.name().equals(type)){ |
| | |
| | | settlement.setUserId(s.getUserId()); |
| | | settlement.setStatus(Constants.SETTLEMENT_STATUS.PENDING.name()); |
| | | |
| | | //2024-10-23 |
| | | //新增WalletBillRecordDO |
| | | WalletBillRecordDO walletBillRecord = new WalletBillRecordDO(); |
| | | walletBillRecord.setId(UUIDGenerator.getUUID()); |
| | | |
| | | Integer flowerNum = 0;//商品数量 |
| | | BigDecimal totalAmount = new BigDecimal(0);//交易合计 |
| | | BigDecimal checkFee = new BigDecimal(0);//降级扣款 |
| | |
| | | detail.create(); |
| | | settlementDetailMapper.insert(detail); |
| | | |
| | | //2024-10-23 |
| | | //copy信息到t_wallet_bill_record_detail |
| | | WalletBillRecordDetail walletBillRecordDetail = new WalletBillRecordDetail(); |
| | | BeanUtils.copyProperties(detail, walletBillRecordDetail, "id"); |
| | | walletBillRecordDetail.setBillRecordId(walletBillRecord.getId()); |
| | | walletBillRecordDetailMapper.insert(walletBillRecordDetail); |
| | | |
| | | flowerNum += oi.getNum(); |
| | | totalAmount = totalAmount.add(detail.getTotalAmount()); |
| | | checkFee = checkFee.add(detail.getCheckFee()); |
| | |
| | | settlement.setSettlementAmount(settlementAmount); |
| | | settlement.create(); |
| | | |
| | | //2024-10-23 |
| | | //计算到钱包后订单状态变成已结算 |
| | | //旧逻辑转账的时候才会标记状态为结算中 |
| | | //新逻辑不是立即转账。不走结算后转账逻辑。此时没有转账时间、openID、转账ID、转账明细ID,直接标记结算状态完成,存金额到钱包中 |
| | | settlement.setStatus(Constants.SETTLEMENT_STATUS.COMPLETED.name()); |
| | | |
| | | settlementMapper.insert(settlement); |
| | | |
| | | //增加供应商结算金额保存到钱包 |
| | | walletBillRecord.setSupplierId(s.getId()); |
| | | walletBillRecord.setSettlementId(settlement.getId()); |
| | | walletBillRecord.setType(Constants.BILL_CHANGE_TYPE.settlement.name()); |
| | | walletBillRecord.setMethod(Constants.BILL_CHANGE_METHOD.add.name()); |
| | | WalletDO walletDOInfo = walletMapper.getTotalAmount(s.getUserId()); |
| | | if (ObjectUtils.isEmpty(walletDOInfo)) { |
| | | // 新增钱包 |
| | | WalletDO walletDO = new WalletDO(); |
| | | walletDO.setUserId(s.getUserId()); |
| | | walletDO.setSupplierId(s.getId()); |
| | | walletDO.setTotalAmount(BigDecimal.ZERO); |
| | | walletMapper.insert(walletDO); |
| | | walletBillRecord.setOriginalAmount(BigDecimal.ZERO); |
| | | walletBillRecord.setChangeAmount(settlementAmount); |
| | | walletBillRecord.setBalance(settlementAmount); |
| | | }else{ |
| | | walletBillRecord.setOriginalAmount(walletDOInfo.getTotalAmount()); |
| | | walletBillRecord.setChangeAmount(settlementAmount); |
| | | walletBillRecord.setBalance(walletDOInfo.getTotalAmount().add(settlementAmount)); |
| | | //更新钱包 |
| | | walletDOInfo.setTotalAmount(walletBillRecord.getBalance()); |
| | | walletMapper.updateById(walletDOInfo); |
| | | } |
| | | walletBillRecordMapper.insert(walletBillRecord); |
| | | |
| | | } |
| | | |
| | | /* ******************************************************************** */ |