Example #1
0
 /**
  * 自动检测款项双方,同时设置币种
  *
  * @param unit
  * @return
  */
 public boolean insert(FinanceUnit unit) {
   String receiver = unit.getReceiver();
   String sender = unit.getSender();
   int userId = 0;
   if (receiver.contains(UserType.SELLER)) { // 收款人是卖家
     String[] tmpArray = receiver.split("-");
     userId = Integer.parseInt(tmpArray[1]);
     if (userId != 0) { // 给卖家设置币种
       ShopSetting ss = shopSettingMapper.getShopSettingBySellerId(userId);
       if (ss == null) {
         throw new ShopException();
       }
       int coinage = ss.getDefaultCoinage();
       unit.setCoinage(coinage);
     }
   } else if (receiver.contains(UserType.TRANSLATOR)) { // 翻译人员默认是人民币
     unit.setCoinage(Coinage.RMB);
   } else if (receiver.contains(UserType.ADMIN)) { // 收款人是管理员
     if (sender.contains(UserType.CUSTOMER)) {
       unit.setCoinage(Coinage.RMB);
     } else if (sender.contains(UserType.SELLER)) {
       //				String[] tmpArray = sender.split("-");
       //				userId = Integer.parseInt(tmpArray[1]);
       //				ShopSetting ss = shopSettingMapper.getShopSettingBySellerId(userId);
       //				if(ss == null){
       //					throw new ShopException();
       //				}
       //				int coinage = ss.getDefaultCoinage();
       //				unit.setCoinage(coinage);
       unit.setCoinage(Coinage.Dollar);
     }
   } else if (receiver.contains(UserType.CUSTOMER)) { // 收款人是买家
     unit.setCoinage(Coinage.RMB);
   }
   financeUnitMapper.insert(unit);
   return true;
 }
Example #2
0
  @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);
  }