Ejemplo n.º 1
0
 /** Sets the user login time to the current time */
 public void setLoginTimeAndUpdate() {
   secondToLastLoginTime = lastLoginTime;
   lastLoginTime = DateUtil.now();
   doUpdateAndRetry();
   Logger.debug(
       getClass().getCanonicalName() + " " + pk + " login time updated to " + lastLoginTime);
 }
Ejemplo n.º 2
0
 /** Sets the user last access time to the current time */
 public void setLastAccessTimeAndUpdate() {
   lastAccessTime = DateUtil.now();
   doUpdateAndRetry();
   Logger.debug(
       getClass().getCanonicalName()
           + " "
           + pk
           + " last access time updated to "
           + lastAccessTime);
 }
Ejemplo n.º 3
0
  /** Creates a user with the given information Username will be some default value */
  private UserModel(
      String fbId, String username, String email, boolean isTestUser, UserModel creator) {
    Date now = DateUtil.now();

    this.pk = UUID.randomUUID();
    this.fbId = fbId;
    this.fbIsAuthed = (this.fbId != null);
    this.username = username;
    this.email = email;
    this.registerTime = now;
    this.isTestUser = isTestUser;
    this.creator = creator;
    this.lastAccessTime = now;
    this.lastLoginTime = now;
    this.secondToLastLoginTime = null;
  }
Ejemplo n.º 4
0
  public static void create() throws Exception {
    ObjectType type = ObjectType.get(getControllerClass());
    notFoundIfNull(type);
    Constructor<?> constructor = type.entityClass.getDeclaredConstructor();
    constructor.setAccessible(true);
    SMSLog object = new SMSLog();
    object.content = params.get("content");
    String mobiles = "";
    String wMobile = params.get("wMobile").trim();
    String[] phoneNos;
    if (StringUtil.isEmpty(wMobile)) {
      phoneNos = params.getAll("selMobile");
      for (String tmp : phoneNos) {
        mobiles += tmp + ",";
      }
    } else {
      phoneNos = wMobile.split(",");
      mobiles = wMobile.trim();
    }

    object.phoneNos = mobiles;
    validation.valid(object);

    boolean flag = SendSMS.sendMsg(phoneNos, object.content);

    object.updatetime = DateUtil.reverseDate(new Date(), 0);
    if (validation.hasErrors()) {
      renderArgs.put("error", play.i18n.Messages.get("crud.hasErrors"));
      try {
        render(request.controller.replace(".", "/") + "/blank.html", type, object);
      } catch (TemplateNotFoundException e) {
        render("CRUD/blank.html", type, object);
      }
    }
    object._save();
    flash.success(play.i18n.Messages.get("crud.created", type.modelName));
    if (params.get("_save") != null) {
      redirect(request.controller + ".list");
    }
    if (params.get("_saveAndAddAnother") != null) {
      redirect(request.controller + ".blank");
    }
    redirect(request.controller + ".show", object._key());
  }
Ejemplo n.º 5
0
  @Override
  protected String infoNotify(Map<String, String> requestParams) {
    String respCode = requestParams.get("respCode");
    if (StringUtil.isNotBlank(respCode) && respCode.equals("00")) {
      String outTradeNo = new String(requestParams.get("orderId").replaceFirst("^0*", ""));
      // 获取交易金额 txnAmt
      String totalFee = String.valueOf(Double.valueOf(requestParams.get("txnAmt")) / 100);
      // 获取付款时间
      String payedMill = requestParams.get("txnTime");
      // 获取流水号
      String tradeNo = requestParams.get("queryId");

      String tradeStatus = "SUCCESS";
      Date payedAt = DateUtil.timeMillToDate(payedMill);
      Integer id = resultOfPayment(outTradeNo, tradeNo, tradeStatus, totalFee, payedAt);

      logger.info(id + "验证签名结果[成功].");
    } else {
      logger.error("银联支付返回,失败" + "\n以下是回掉信息" + requestParams.toString());
    }
    return notifySuccess();
  }
Ejemplo n.º 6
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;
  }