| | |
| | | import com.mzl.flower.constant.LockConstants; |
| | | import com.mzl.flower.dto.request.wallet.QueryWalletAmountDTO; |
| | | import com.mzl.flower.dto.response.supplier.SupplierDTO; |
| | | import com.mzl.flower.entity.supplier.Supplier; |
| | | import com.mzl.flower.entity.wallet.WalletDO; |
| | | import com.mzl.flower.enums.TrueOrFalseEnum; |
| | | import com.mzl.flower.mapper.wallet.WalletMapper; |
| | |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | |
| | | @Override |
| | | public WalletDO getOrCreateBySupplierId(Long supplierId) { |
| | | |
| | | |
| | | WalletDO walletDO=getBySupplierId(supplierId); |
| | | if(null==walletDO){ |
| | | RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_SUPPLIER_ID_KEY, supplierId)); |
| | |
| | | try { |
| | | walletDO=getBySupplierId(supplierId); |
| | | if(null!=walletDO) return walletDO; |
| | | |
| | | final Supplier supplier = supplierService.getSupplierById(supplierId); |
| | | |
| | | // 创建一个钱包 |
| | | walletDO =new WalletDO(); |
| | | walletDO.setUserId(SecurityUtils.getUserId()); |
| | | walletDO.setUserId(supplier.getUserId()); |
| | | walletDO.setSupplierId(supplierId); |
| | | walletDO.setTotalAmount(BigDecimal.ZERO); |
| | | walletDO.setWithdrawableAmount(BigDecimal.ZERO); |
| | |
| | | walletDO.setSettlingAmount(BigDecimal.ZERO); |
| | | walletDO.setTotalDeduction(BigDecimal.ZERO); |
| | | walletDO.setTotalTransactionAmount(BigDecimal.ZERO); |
| | | walletDO.setSettlingAmount(BigDecimal.ZERO); |
| | | walletDO.setSettledAmount(BigDecimal.ZERO); |
| | | walletDO.create(SecurityUtils.getUserId()); |
| | | baseMapper.insert(walletDO); |
| | | // 将再次查询的结果返回 |
| | |
| | | |
| | | @Override |
| | | public BigDecimal getWaittingSettlementAmount(WalletDO walletDO) { |
| | | |
| | | if(null!=walletDO && !StringUtils.isEmpty(walletDO.getSupplierId()) && StringUtils.isEmpty(walletDO.getUserId())){ |
| | | final Supplier supplier = supplierService.getSupplierById(walletDO.getSupplierId()); |
| | | walletDO.setUserId(supplier.getUserId()); |
| | | } |
| | | return baseMapper.getWaittingSettlementAmount(walletDO); |
| | | } |
| | | |
| | |
| | | queryWalletAmountDTO.setStartTime(getWalletOnLineTime()); |
| | | queryWalletAmountDTO.setUserId(walletDO.getUserId()); |
| | | |
| | | // 质检扣款 |
| | | BigDecimal checkDeduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO); |
| | | checkDeduceAmount = checkDeduceAmount != null ? checkDeduceAmount : BigDecimal.ZERO; |
| | | // 质检扣款(缺货和补货) |
| | | BigDecimal checkReplaceLockAmount = walletReduceService.getCheckLackReplaceAmount(queryWalletAmountDTO); |
| | | checkReplaceLockAmount = checkReplaceLockAmount != null ? checkReplaceLockAmount : BigDecimal.ZERO; |
| | | |
| | | // 质检扣款(降级) |
| | | BigDecimal checkReduceAmount = walletReduceService.getCheckReduceAmount(queryWalletAmountDTO); |
| | | checkReduceAmount = checkReduceAmount != null ? checkReduceAmount : BigDecimal.ZERO; |
| | | |
| | | // 售后扣款 |
| | | BigDecimal saleDeduceAmount = walletReduceService.getSaleReduceAmount(queryWalletAmountDTO); |
| | | saleDeduceAmount = saleDeduceAmount != null ? saleDeduceAmount : BigDecimal.ZERO; |
| | | |
| | | // 集货站运费 |
| | | BigDecimal stationFeeAmount = walletReduceService.getStationFeeAmount(queryWalletAmountDTO); |
| | | stationFeeAmount = stationFeeAmount != null ? stationFeeAmount : BigDecimal.ZERO; |
| | | |
| | | // 总扣款 |
| | | BigDecimal deduceAmount = checkDeduceAmount.add(saleDeduceAmount); |
| | | BigDecimal deduceAmount = checkReplaceLockAmount.add(checkReduceAmount).add(saleDeduceAmount).add(stationFeeAmount); |
| | | |
| | | return deduceAmount; |
| | | } |