Esempio n. 1
0
  /**
   * @param orderId
   * @param percent
   */
  public void payAllMoneyBackButService(int orderId, float percent) {
    if (percent > 100) {
      System.err.println("the return money percent > 100 in payMoneyBack");
      return;
    }
    Order order = orderService.getOrderById(orderId);
    if (order.getOrderStatus() == OrderStatus.CLOSE) {
      return;
    }

    FinanceUnit originToSeller =
        getFinanceUnitByRelatedIdAndDetailsTypeForSeller(orderId, FinanceType.Normal);
    FinanceUnit originToPlatform =
        getFinanceUnitByRelatedIdAndDetailsTypeForAdmin(orderId, FinanceType.Normal);

    FinanceUnit sellerToPlatform = new FinanceUnit(originToSeller, percent);
    sellerToPlatform.setReceiver(originToSeller.getSender());
    sellerToPlatform.setSender(originToSeller.getReceiver());
    sellerToPlatform.setFinanceDetailsType(FinanceType.Return);

    FinanceUnit platformToCustomer = new FinanceUnit(originToPlatform, percent);
    platformToCustomer.setReceiver(originToPlatform.getSender());
    platformToCustomer.setSender(originToPlatform.getReceiver());
    platformToCustomer.setFinanceDetailsType(FinanceType.Return);

    insertDirectly(platformToCustomer);
    insertDirectly(sellerToPlatform);
  }
Esempio n. 2
0
  /** 插入两条记录,一条是 买家付给平台,一条是平台付给卖家 */
  private boolean insertPaidOrder(Order order) {
    FinanceUnit unit = new FinanceUnit(order); // 买家付给平台
    unit.setReceiver(UserType.ADMIN);
    unit.setSender(contructID(order.getCustomerId(), UserType.CUSTOMER));
    unit.setMoney(order.getPriceRMB());
    unit.setFinanceDetailsType(FinanceType.Normal);
    insert(unit);

    FinanceUnit unit2 = new FinanceUnit(order); // 平台付给卖家
    unit2.setReceiver(contructID(order.getSellerId(), UserType.SELLER));
    unit2.setSender(UserType.ADMIN);
    unit2.setMoney(order.getOriginTotal());
    unit2.setFinanceDetailsType(FinanceType.Normal);
    insert(unit2);
    return true;
  }
Esempio n. 3
0
 /**
  * 插入该订单的佣金记录
  *
  * @param order
  */
 public void insertServiceMoney(Order order) {
   List<OrderItem> orderItems = order.getOrderItems();
   float moneySum = 0;
   for (OrderItem item : orderItems) {
     int productLineId = item.getProductLineId();
     ProductLine productLine = productLineService.getProductLineById(productLineId);
     float serviceRate = productLine.getCommission();
     float money = serviceRate * item.getPrice() * item.getNum();
     moneySum += money;
   }
   FinanceUnit unit = new FinanceUnit(order);
   unit.setMoney(moneySum);
   unit.setReceiver(UserType.ADMIN);
   unit.setSender(contructID(order.getSellerId(), UserType.SELLER));
   unit.setFinanceType(FinanceType.Service);
   unit.setFinanceDetailsType(FinanceType.ServiceNormal);
   insert(unit);
 }
Esempio n. 4
0
  /** 插入某订单的退货仓库费 */
  public void insertStoreMoney(int orderId) {
    Order order = orderService.getOrderById(orderId);
    FinanceUnit unit = new FinanceUnit(order);
    unit.setFinanceType(FinanceType.Store);
    float money = 0f;

    List<OrderItem> orderItems = order.getOrderItems();
    for (OrderItem orderItem : orderItems) {
      int productId = orderItem.getProductId();
      Product product = productService.getSimpleProductById(productId);
      String size = product.getSizeWithPackage();
      float moneyTmp = computeStoreFee(size);
      money += (moneyTmp * orderItem.getNum());
    }
    int coinage = order.getCoinage();
    money = Coinage.convertToAimCoinage(coinage, money, Coinage.Dollar);
    unit.setMoney(money);
    unit.setSender(UserType.SELLER + "-" + order.getSellerId());
    unit.setReceiver(UserType.ADMIN);
    insert(unit);
  }
Esempio n. 5
0
 /**
  * 插入订单相关项
  *
  * @param order
  */
 @Transactional(rollbackFor = Exception.class)
 public void insertOrderFinance(Order order, int newStatus) {
   int originStatus = order.getOrderStatus();
   switch (newStatus) {
     case OrderStatus.PAID: // 买家付款
       if (originStatus == OrderStatus.NOPAY) { // 如果之前状态是未付款,才可以付款
         insertPaidOrder(order);
         insertServiceMoney(order);
       }
       break;
   }
 }
Esempio n. 6
0
  public void payMoneyBackCauseReturnNoExcuse(int orderId, float percent) { // 无理由退货
    if (percent > 100) {
      System.err.println("the return money percent > 100 in payMoneyBack");
      return;
    }
    Order order = orderService.getOrderById(orderId);
    if (order.getOrderStatus() == OrderStatus.CLOSE) {
      return;
    }

    FinanceUnit originToSeller =
        getFinanceUnitByRelatedIdAndDetailsTypeForSeller(orderId, FinanceType.Normal);
    FinanceUnit originToPlatform =
        getFinanceUnitByRelatedIdAndDetailsTypeForAdmin(orderId, FinanceType.Normal);
    FinanceUnit serviceMoney =
        getFinanceUnitByRelatedIdAndDetailsTypeForAdmin(orderId, FinanceType.ServiceNormal);

    FinanceUnit sellerToPlatform = new FinanceUnit(originToSeller); // 不退运费
    float tmp_money = order.getOriginPrice() * percent / 100.0f;
    sellerToPlatform.setMoney(tmp_money);
    sellerToPlatform.setReceiver(originToSeller.getSender());
    sellerToPlatform.setSender(originToSeller.getReceiver());
    sellerToPlatform.setFinanceDetailsType(FinanceType.Return);

    FinanceUnit platformToCustomer = new FinanceUnit(originToPlatform); // 不退运费
    float money = order.getOriginPriceRMB() * percent / 100.0f;
    platformToCustomer.setMoney(money);
    platformToCustomer.setReceiver(originToPlatform.getSender());
    platformToCustomer.setSender(originToPlatform.getReceiver());
    platformToCustomer.setFinanceDetailsType(FinanceType.Return);

    FinanceUnit serviceMoneyBack = new FinanceUnit(serviceMoney, 100); // 服务费全退
    serviceMoneyBack.setReceiver(serviceMoney.getSender());
    serviceMoneyBack.setSender(serviceMoney.getReceiver());
    serviceMoneyBack.setFinanceDetailsType(FinanceType.ServiceBack);

    insertDirectly(platformToCustomer);
    insertDirectly(sellerToPlatform);
    insertDirectly(serviceMoneyBack);
  }
Esempio n. 7
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);
  }