Beispiel #1
0
  /**
   * 根据时间算出vip费用
   *
   * @param info
   * @return
   */
  public double vipMoney(ErrorInfo error) {
    error.clear();

    String sql =
        "select _value from t_system_options where _key = ? or _key =? or _key = ? order by id";
    List<String> keys = null;

    try {
      keys =
          t_system_options
              .find(sql, OptionKeys.VIP_MIN_TIME, OptionKeys.VIP_FEE, OptionKeys.VIP_TIME_TYPE)
              .fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("申请vip时,查询系统设置中的vip设置时" + e.getMessage());
      error.code = -1;
      error.msg = "申请vip失败";

      return error.code;
    }

    if (keys == null || keys.size() == 0) {
      error.code = -2;
      error.msg = "读取系统参数失败";

      return error.code;
    }

    if (keys.get(2).equals(Constants.YEAR + "")) {
      this.serviceTime *= 12;
    }

    int vipMinTime = Integer.parseInt(keys.get(1));

    if (this.serviceTime <= vipMinTime) {
      error.code = -3;
      error.msg = "至少开通" + vipMinTime + "月";

      return error.code;
    }

    double vipFee = Double.parseDouble(keys.get(0));
    double fee = Arith.mul(vipFee, serviceTime);

    error.code = 0;

    return fee;
  }
Beispiel #2
0
  /**
   * @param time 申请vip的时长,月为单位
   * @param user
   * @param info
   * @return
   */
  public int renewal(User user, ErrorInfo error) {
    error.clear();
    BackstageSet backstageSet = BackstageSet.getCurrentBackstageSet();

    int vipMinTimeType = backstageSet.vipMinTimeType;
    int vipMinTime = backstageSet.vipMinTimeLength;
    int vipTimeType = backstageSet.vipTimeType;
    double vipFee = backstageSet.vipFee;

    if (vipMinTimeType != 1) {
      vipMinTime *= 12;
    }

    if (this.serviceTime < vipMinTime) {
      error.code = -3;
      error.msg = "vip开通不能少于最少时长";

      return error.code;
    }

    int timeLen = this.serviceTime;

    double fee = 0;

    if (vipTimeType == 1) {
      fee = vipFee * timeLen;
    } else if (vipTimeType == 0) {
      fee = Arith.mul(vipFee, serviceTime / 12);
    }

    fee = fee * backstageSet.vipDiscount / 10;
    fee = Arith.round(fee, 2);

    DataSafety data = new DataSafety();

    data.id = user.id;

    if (!data.signCheck(error)) {
      JPA.setRollbackOnly();

      return error.code;
    }

    v_user_for_details forDetail = DealDetail.queryUserBalance(user.id, error);

    if (error.code < 0) {

      return error.code;
    }

    if (Constants.IPS_ENABLE) {
      switch (Constants.PAY_TYPE_VIP) {
          // 平台内部进行转账
        case PayType.INNER:
          error.code = -1;
          error.msg = "资金托管模式下,不能以平台内部进行转账的方式支付";

          return error.code;
          // 通过独立普通网关
        case PayType.INDEPENDENT:
          if (fee > user.balance2) {
            error.code = Constants.BALANCE_NOT_ENOUGH;
            error.msg = "对不起,您可用余额不足";
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("rechargeType", RechargeType.VIP);
            map.put("serviceTime", timeLen);
            map.put("fee", fee);
            Cache.set("rechargePay" + user.id, map, IPSConstants.CACHE_TIME);

            return error.code;
          }

          break;
          // 通过共享资金托管账户网关
        case PayType.SHARED:
          // 资金托管网关
        case PayType.IPS:
          if (this.isPay) {
            break;
          }

          if (fee > user.balance) {
            error.code = Constants.BALANCE_NOT_ENOUGH;
            error.msg = "对不起,您可用余额不足";

            return error.code;
          }

          if (fee > 0) {
            error.code = Constants.BALANCE_PAY_ENOUGH;
            error.msg = "请前去支付VIP费用";
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("rechargeType", RechargeType.VIP);
            map.put("serviceTime", timeLen);
            map.put("fee", fee);
            Cache.set("rechargePay" + user.id, map, IPSConstants.CACHE_TIME);

            return error.code;
          }

          break;
      }
    } else {
      if (fee > user.balance) {
        error.code = Constants.BALANCE_NOT_ENOUGH;
        error.msg = "对不起,您可用余额不足";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rechargeType", RechargeType.VIP);
        map.put("serviceTime", timeLen);
        map.put("fee", fee);
        Cache.set("rechargePay" + user.id, map, IPSConstants.CACHE_TIME);

        return error.code;
      }
    }

    t_user_vip_records vipRecord = new t_user_vip_records();
    t_user_vip_records record = null;

    int rows = 0;

    if (user.vipStatus) {
      try {
        record = t_user_vip_records.find("user_id = ? and status = 1", user.id).first();
        rows =
            JpaHelper.execute(
                    "update t_user_vip_records set status = 0 where user_id = ? and status = 1")
                .setParameter(1, user.id)
                .executeUpdate();
      } catch (Exception e) {
        e.printStackTrace();
        Logger.info("申请vip时,查询系统设置中的vip设置时" + e.getMessage());
        error.code = -1;
        error.msg = "申请vip失败";

        return error.code;
      }

      if (rows == 0) {
        JPA.setRollbackOnly();
        error.code = -1;
        error.msg = "数据未更新,vip申请失败";

        return error.code;
      }

      vipRecord.start_time = record.expiry_date;
      vipRecord.expiry_date = DateUtil.dateAddMonth(record.expiry_date, this.serviceTime);
    } else {
      vipRecord.start_time = new Date();
      vipRecord.expiry_date = DateUtil.dateAddMonth(new Date(), this.serviceTime);
    }

    vipRecord.user_id = user.id;
    vipRecord.time = new Date();
    vipRecord.service_fee = fee;
    vipRecord.status = true;

    try {
      JpaHelper.execute("update t_user_vip_records set status = 0 where user_id = ? and status = 1")
          .setParameter(1, user.id)
          .executeUpdate();
      vipRecord.save();
      rows =
          JpaHelper.execute("update t_users set vip_status = true where id = ?", user.id)
              .executeUpdate();
    } catch (Exception e) {
      JPA.setRollbackOnly();
      e.printStackTrace();
      Logger.info("申请vip时,查询系统设置中的vip设置时" + e.getMessage());
      error.code = -5;
      error.msg = "申请vip失败";

      return error.code;
    }

    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "数据未更新";

      return error.code;
    }

    // 更新用户资金
    if (Constants.PAY_TYPE_VIP == PayType.INDEPENDENT) {
      error.code = DealDetail.minusUserFund2(user.id, fee);
    } else {
      error.code = DealDetail.minusUserFund(user.id, fee);
    }

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    DealDetail dealDetail = null;
    forDetail = DealDetail.queryUserBalance(user.id, error);

    /* 添加交易记录 */
    if (Constants.PAY_TYPE_VIP == PayType.INDEPENDENT) {
      dealDetail =
          new DealDetail(
              user.id,
              DealType.CHARGE_VIP,
              fee,
              vipRecord.id,
              forDetail.user_amount2,
              forDetail.freeze,
              forDetail.receive_amount,
              "vip扣费");

      dealDetail.addDealDetail2(error);
    } else {
      dealDetail =
          new DealDetail(
              user.id,
              DealType.CHARGE_VIP,
              fee,
              vipRecord.id,
              forDetail.user_amount,
              forDetail.freeze,
              forDetail.receive_amount,
              "vip扣费");

      dealDetail.addDealDetail(error);
    }

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    data.id = user.id;
    data.updateSign(error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    DealDetail.addPlatformDetail(
        DealType.VIP_FEE, vipRecord.id, user.id, -1, DealType.ACCOUNT, fee, 1, "vip费用", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    DealDetail.userEvent(this.id, UserEvent.VIP, "申请vip", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    // vip申请站内信
    TemplateStation station = new TemplateStation();
    station.id = Templets.M_VIP_SUCCESS;

    if (station.status) {
      TemplateStation.addMessageTask(
          userId, station.title, station.content.replace("vipFee", fee + ""));
    }

    // 发送邮件
    TemplateEmail email = new TemplateEmail();
    email.id = Templets.E_VIP_SUCCESS;

    if (email.status) {
      TemplateEmail.addEmailTask(
          user.email, email.title, email.content.replace("vipFee", fee + ""));
    }

    // 发送短信
    TemplateSms sms = new TemplateSms();

    if (StringUtils.isNotBlank(user.mobile)) {
      sms.id = Templets.S_VIP_SUCCESS;

      if (sms.status) {
        TemplateSms.addSmsTask(
            user.mobile,
            sms.content
                .replace("vipFee", fee + "")
                .replace("userName", user.name)
                .replace("date", DateUtil.dateToString(new Date())));
      }
    }

    if (Constants.IPS_ENABLE) {
      user.balance2 = forDetail.user_amount2 - fee;
    } else {
      user.balance = forDetail.user_amount - fee;
    }

    user.vipStatus = true;

    User.setCurrUser(user);

    error.code = 0;
    error.msg = "申请vip成功!";

    return error.code;
  }
Beispiel #3
0
  /** 填充自己 */
  public void setId(long id) {
    t_products product = null;

    try {
      product = t_products.findById(id);
    } catch (Exception e) {
      Logger.error("产品->填充自己:" + e.getMessage());
      this._id = -1;

      return;
    }

    if (null == product) {
      this._id = -1;

      return;
    }

    this._id = product.id;
    this.mark = product.mark;

    if (this.createBid) {
      this.isUse = product.is_use;
      if (!this.isUse) return;
      this.isAgency = product.is_agency;
      this.name = product.name;
      this.loanImageFilename = product.loan_image_filename;
      this.bailScale = product.bail_scale;
      this.maxCopies = product.max_copies;
      this.minInvestAmount = product.min_invest_amount;
      this.minInterestRate = product.min_interest_rate;
      this.maxInterestRate = product.max_interest_rate;
      this.minAmount = product.min_amount;
      this.maxAmount = product.max_amount;
      this.loanType = product.loan_type;
      this.isDealPassword = product.is_deal_password;
      this.repaymentId = product.repayment_type_id;
      this.periodYear = product.period_year;
      this.periodMonth = product.period_month;
      this.periodDay = product.period_day;
      this.investPeriod = product.invest_period;
      this.loanImageType = product.loan_image_type;
      this.creditId = product.credit_id;
      this.showType = product.show_type;

      return;
    }

    if (this.bidDetail) {
      this.name = product.name;
      this.smallImageFilename = product.small_image_filename;

      return;
    }

    this.time = product.time;
    this.name = product.name;
    this.nameImageFilename = product.name_image_filename;
    this.fitCrowd = product.fit_crowd;
    this.characteristic = product.characteristic;
    this.minAmount = product.min_amount;
    this.maxAmount = product.max_amount;
    this.minInvestAmount = product.min_invest_amount;
    this.maxCopies = product.max_copies;
    this.creditId = product.credit_id;
    this.auditCycle = product.audit_cycle;
    this.applicantCondition = product.applicant_condition;
    this.loanType = product.loan_type;
    this.bailScale = product.bail_scale;
    this.isDealPassword = product.is_deal_password;
    this.loanImageType = product.loan_image_type;
    this.loanImageFilename = product.loan_image_filename;
    this.smallImageFilename = product.small_image_filename;
    this.isAgency = product.is_agency;
    this.isUse = product.is_use;
    this.order = product._order;
    this.showType = product.show_type;
    this.repaymentId = product.repayment_type_id;

    /* 年借款期限 */
    this.periodYear = product.period_year;

    /* 月借款期限 */
    this.periodMonth = product.period_month;

    /* 日借款期限 */
    this.periodDay = product.period_day;

    /* 投标期限 */
    this.investPeriod = product.invest_period;

    /* 年利率 */
    double minApr = product.min_interest_rate;
    double maxApr = product.max_interest_rate;
    this.minInterestRate = minApr;
    this.maxInterestRate = maxApr;
    this.monthMinApr = minApr > 0 ? Arith.div(minApr, 12, 2) : 0;
    this.monthMaxApr = maxApr > 0 ? Arith.div(maxApr, 12, 2) : 0;
  }