示例#1
0
  /**
   * 某类用户的支出情况
   *
   * @param userId
   * @param userType
   * @param begin
   * @param end
   * @param page
   * @return
   */
  public List<FinanceUnit> getFinanceBySenderAndMonthByPage(
      int userId, String userType, Date begin, Date end, Page page) {
    String sender = contructID(userId, userType);

    if (begin != null && end != null) {
      return financeUnitMapper.getFinanceBySenderAndMonthByPage(sender, begin, end, page);
    } else {
      return financeUnitMapper.getFinanceBySenderByPage(sender, page);
    }
  }
示例#2
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;
 }
示例#3
0
 /**
  * 对于翻译人员的财务
  *
  * @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);
 }
示例#4
0
 public void delete(int id) {
   FinanceUnit unit = getFinanceUnitById(id);
   if (unit != null && unit.getStatus() == FinanceUnit.NOPAY) {
     financeUnitMapper.delete(id);
   }
 }
示例#5
0
 private void insertDirectly(FinanceUnit unit) {
   financeUnitMapper.insert(unit);
 }
示例#6
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);
  }
示例#7
0
 public List<FinanceUnit> getFinanceUnitsByTransitionId(int translationTaskId) {
   return financeUnitMapper.getFinanceUnitsByRelatedIdAndRelatedType(
       translationTaskId, FinanceUnit.TranslationRelated);
 }
示例#8
0
 /**
  * 根据订单id查找其所有账目项
  *
  * @param orderId
  * @return
  */
 public List<FinanceUnit> getFinanceUnitsByOrderId(int orderId) {
   return financeUnitMapper.getFinanceUnitsByRelatedIdAndRelatedType(
       orderId, FinanceUnit.OrderRelated);
 }
示例#9
0
 /**
  * 每次更新,订单时间就会变化
  *
  * @param unit
  * @return
  */
 public boolean update(FinanceUnit unit) {
   unit.setCreateAt(new Date());
   financeUnitMapper.update(unit);
   return true;
 }
示例#10
0
 /**
  * 根据unit的id查找
  *
  * @param id
  * @return
  */
 public FinanceUnit getFinanceUnitById(int id) {
   return financeUnitMapper.getFinanceUnitById(id);
 }
示例#11
0
 private FinanceUnit getFinanceUnitByRelatedIdAndDetailsType(
     int relatedId, int financeType, String userType) {
   return financeUnitMapper.getFinanceUnitsByRelatedIdAndDetailsType(
       relatedId, financeType, userType);
 }
示例#12
0
 /**
  * 批量更新财务单元状态
  *
  * @param ids
  * @param status
  */
 public void batchUpdate(Set<Integer> idset, int status) {
   if (idset != null && idset.size() > 0) financeUnitMapper.batchUpdate(idset, status);
 }