/** * 对于翻译人员的财务 * * @param begin * @param end * @param userId */ @Transactional(rollbackFor = Exception.class) public void computeForTranslator(Date begin, Date end, int userId) { String user = contructID(userId, UserType.TRANSLATOR); FinanceRecord record = new FinanceRecord(); // 收入 List<FinanceUnit> unitsReceiveThisRun = financeUnitMapper.getFinanceByReceiverAndMonthByPage(user, begin, end, null); float receive = 0f; for (FinanceUnit unit : unitsReceiveThisRun) { int financeType = unit.getFinanceType(); float money = unit.getMoney(); switch (financeType) { case FinanceType.Translation: // 翻译的钱 receive += money; record.addId(unit.getId()); break; } } record.setTotalGetFromAdmin(receive); record.setReceiver(contructID(userId, UserType.TRANSLATOR)); record.setBeginDate(begin); record.setEndDate(end); financeRecordService.insert(record); }
@Transactional(rollbackFor = Exception.class) public void computeForSeller(Date begin, Date end, int userId) { String user = contructID(userId, UserType.SELLER); FinanceRecord record = new FinanceRecord(); // 收入 List<FinanceUnit> unitsReceiveThisRun = financeUnitMapper.getFinanceByReceiverAndMonthByPage(user, begin, end, null); float receive = 0f; // 从平台收的钱 /** 计算平台需要支付给卖家的钱 1. 正常买卖 */ for (FinanceUnit unit : unitsReceiveThisRun) { if (unit.getStatus() != FinanceUnit.NOPAY) { continue; } int financeType = unit.getFinanceType(); int financeDetailsType = unit.getFinanceDetailsType(); float money = unit.getMoney(); switch (financeType) { case FinanceType.Order: // 订单的钱 if (financeDetailsType == FinanceType.Normal) { // 正常订单 Order order = orderService.getOrderById(unit.getRelatedId()); int orderStatus = order.getOrderStatus(); if (orderStatus == OrderStatus.AUTOCLOSE || // 自动结束 orderStatus == OrderStatus.CLOSE || // 管理员关闭 orderStatus == OrderStatus.CANCELBYSELLER) { receive += money; record.addId(unit.getId()); } } break; case FinanceType.Service: if (financeDetailsType == FinanceType.ServiceBack) { receive += money; record.addId(unit.getId()); } break; case FinanceType.Other: receive += money; record.addId(unit.getId()); break; } } // 支出 List<FinanceUnit> unitsSendThisRun = financeUnitMapper.getFinanceBySenderAndMonthByPage(user, begin, end, null); float translationFee = 0f; // 付给平台的翻译钱 float returnFee = 0f; // 返款给平台的钱 float storeFee = 0f; // 使用仓库的钱 float serviceFee = 0f; // 付给平台的服务钱 float otherFee = 0f; /** 计算需要付给平台的钱 1. 翻译 2. 退款 */ for (FinanceUnit unit : unitsSendThisRun) { if (unit.getStatus() != FinanceUnit.NOPAY) { continue; } int financeType = unit.getFinanceType(); int financeDetailsType = unit.getFinanceDetailsType(); float money = unit.getMoney(); switch (financeType) { case FinanceType.Translation: // 翻译的钱 translationFee += money; record.addId(unit.getId()); break; case FinanceType.Order: // 给平台的返款,如退款 if (financeDetailsType == FinanceType.Return) { returnFee += money; record.addId(unit.getId()); } break; case FinanceType.Other: otherFee += money; record.addId(unit.getId()); break; case FinanceType.Store: { Order order = orderService.getOrderById(unit.getRelatedId()); int orderStatus = order.getOrderStatus(); if (orderStatus == OrderStatus.AUTOCLOSE || // 自动结束 orderStatus == OrderStatus.CLOSE // 管理员关闭 ) { storeFee += money; record.addId(unit.getId()); } } break; case FinanceType.Service: { Order order = orderService.getOrderById(unit.getRelatedId()); int orderStatus = order.getOrderStatus(); if (orderStatus == OrderStatus.AUTOCLOSE || // 自动结束 orderStatus == OrderStatus.CLOSE || // 管理员关闭 orderStatus == OrderStatus.CANCELBYSELLER) { serviceFee += money; record.addId(unit.getId()); } } break; } } float totalGetFromAdmin = receive; float payAdmin = translationFee + returnFee + storeFee + serviceFee + otherFee; float total = totalGetFromAdmin - payAdmin; ShopSetting shopSetting = shopSettingMapper.getShopSettingBySellerId(userId); int coinage = 0; if (shopSetting != null) { coinage = shopSetting.getDefaultCoinage(); } record.setOrderMoney(totalGetFromAdmin); record.setOtherMoney(otherFee); record.setReceiver(contructID(userId, UserType.SELLER)); record.setServiceMoney(serviceFee); record.setStoreMoney(storeFee); record.setTotalGetFromAdmin(totalGetFromAdmin); record.setTotalPayAdmin(payAdmin); record.setTotal(total); record.setBeginDate(begin); record.setEndDate(end); record.setCoinage(coinage); financeRecordService.insert(record); }