Пример #1
0
  /*
   * (non-Javadoc)
   * @see com.opensymphony.xwork2.ActionSupport#execute()
   */
  @Override
  @Action(
      results = {
        @Result(name = "success", location = "/WEB-INF/content/success.jsp"),
        @Result(name = "fail", location = "/WEB-INF/content/register.jsp")
      })
  public String execute() {
    HttpServletRequest request = ServletActionContext.getRequest();
    String ccode = (String) request.getSession().getAttribute(SystemVariables.VALIDATE_CODE);
    log.debug(">>>from session ccode:" + ccode);
    if (vcode == null || !ccode.equals(vcode)) {
      return "fail";
    }

    boolean exist = enterpriseService.exist(email);
    if (exist) {
      return "fail";
    }

    Enterprise ent = new Enterprise();
    ent.setUserType(userType);
    ent.setSex(sex == 0);
    ent.setAccount(email);
    ent.setEmail(email);
    ent.setNickname(nickname);
    ent.setAddress(address);
    ent.setLinkman(linkman);
    ent.setName(name);
    ent.setMobilePhone(mobilePhone);
    if (userType == Enterprise.USER_TYPE_PERSON) {
      ent.setName(nickname);
    }

    // 拼音
    String pinyin = ent.getNamePinyinByName();
    String firstPinyin = ent.getNameFirstPinyinByName();
    ent.setNamePinyin(pinyin);
    ent.setNameFirstPinyin(firstPinyin);

    ent.setPassword(EncryptUtil.md5(password));

    enterpriseService.insert(ent);

    entInfo = new EntInfo();
    entInfo.setEnterprise(ent);
    entInfo.setIndexImgUrl("/member/images/banner1.jpg");
    entInfoService.insert(entInfo);

    enterpriseId = ent.getId();

    log.debug(">>>用户注册:" + ent);

    request.getSession().setAttribute(SystemVariables.ENTERPRISE_USER, ent);
    request.getSession().setAttribute(SystemVariables.ENTERPRISE_USER_ID, ent.getId());

    return SUCCESS;
  }
Пример #2
0
  public String checkEmail() {
    try {
      HttpServletResponse rsp = ServletActionContext.getResponse();
      HttpServletRequest req = ServletActionContext.getRequest();
      String email = req.getParameter("email");
      log.debug("注册邮箱帐号验证:" + email);
      Enterprise ent = enterpriseService.getEntByEmail(email);
      if (ent == null) {
        rsp.setContentType("text/html;charset=utf-8");
        PrintWriter out = rsp.getWriter();
        out.write("success");
        out.flush();
      } else {

      }
      return null;
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
Пример #3
0
  public void clickedKeywordExecute(HttpServletRequest request) {

    String __flag = (String) request.getSession().getAttribute("__flag");
    String __key = (String) request.getSession().getAttribute("__key");
    String __ip = request.getRemoteAddr();

    Long enterpriseId = supply.getCreator().getId();

    if (__key != null && __flag != null && __flag.equals("1")) {

      ClickedKeyword ck = new ClickedKeyword();
      ck.setClickedTime(new Date());
      ck.setEnterpriseId(enterpriseId);
      ck.setIp(__ip);
      ck.setKeyword(__key);

      ClickedKeyword clickedKeyword = clickedKeywordService.add(ck); // 添加点击记录

      // 扣费处理
      if (clickedKeyword != null) {
        EnterpriseKeyword enterpriseKeyword = clickedKeyword.getEnterpriseKeyword();
        Keyword keyword = enterpriseKeyword.getKeyword();

        // 判断是否过期,过期将不再进行扣费
        Date deadTime = keyword.getDeadTime();
        boolean expired = (deadTime.getTime() < System.currentTimeMillis());
        float amount = clickedKeyword.getEnterpriseKeyword().getPrice();

        String supplyName = supply.getName();
        String desc = "产品关键词点击扣费[" + supplyName + "|" + keyword.getKeyword() + "|" + amount + "]";
        try {
          if (!expired) { // 关键词为过期
            log.info(
                "==>关键字点击扣费处理[enterprise.id: "
                    + enterpriseId
                    + ", IP: "
                    + __ip
                    + ", keyword: "
                    + __key
                    + "]");
            log.info(desc);
            enterpriseService.pay(enterpriseId, amount, desc);
          } else {
            log.info(
                "%%% 该关键字已经过期[enterprise.id: "
                    + enterpriseId
                    + ", IP: "
                    + __ip
                    + ", keyword: "
                    + __key
                    + "]");
            log.debug("%%% 删除过期关键字的点击记录 begin %%%");
            clickedKeywordService.delete(clickedKeyword);
            log.debug("%%% 删除过期关键字的点击记录 end %%%");
          }
        } catch (Exception e) { // 没有足够的费用,将关键字排序作废
          log.error("==>点击扣费出错:" + e.getMessage());
          supplyService.invalidKeyword(supply.getId());
        }
      }
    }

    // 去掉session
    request.getSession().removeAttribute("__flag");
    request.getSession().removeAttribute("__key");
  }