@RequestMapping(method = RequestMethod.POST, value = "/charge")
  @ResponseBody
  public Charge charge(HttpServletRequest request) {
    // 获取请求body中的参数
    JSONObject params = Tools.getParams(request);
    // 文章的标识
    String articleId = params.getString("articleId");
    // 付款读者的标识
    String wechat = params.getString("wgateid");
    // 付款的渠道
    String channel = params.getString("channel");
    // 当前页面的URL
    String url = params.getString("url");
    // 付款的金额
    int amount = params.getInt("amount");
    // 获取请求的IP地址
    String ip = Tools.getIP(request);

    Deal deal = new Deal(wechat, articleId);
    deal.setDealPayment(amount);
    deal.setClientIp(ip);
    if (dealService.queryDealRecord(deal).getResponseCode() == ResponseCode.RESPONSE_NULL) {
      ResultData createMessage = dealService.createDealRecord(deal);
      if (createMessage.getResponseCode() == ResponseCode.RESPONSE_OK) {
        logger.debug("Insert a deal record successfully.");
      } else {
        logger.debug("Fail to insert a deal record.");
        return null;
      }
    }

    // 设置订单的ID
    String orderNo = deal.getDealId();

    // 根据文章的标识查询文章的信息
    Article article = new Article();
    article.setArticleId(articleId);
    article = (Article) articleService.queryArticle(article).getData();

    Reader reader = new Reader();
    if (!StringUtils.isEmpty(wechat)) {
      reader.setReaderWechat(wechat);
      ResultData readerExistMessage = readerService.queryReader(reader);
      if (readerExistMessage.getResponseCode() == ResponseCode.RESPONSE_NULL) {
        readerService.createReader(reader);
      } else if (readerExistMessage.getResponseCode() == ResponseCode.RESPONSE_ERROR) {
        return null;
      }
    }

    ChargeForm form = new ChargeForm(orderNo, article, reader, channel, amount, ip, url);
    ResultData result = dealService.charge(form);

    Charge charge = (Charge) result.getData();
    logger.debug(charge.toString());
    return charge;
  }
 @RequestMapping(value = "Publish", method = RequestMethod.POST)
 public ModelAndView publish(Article article) {
   ModelAndView mv = new ModelAndView("redirect:/ContestSystem/Administrator/AdminArticle");
   System.out.println(article.getContent());
   this.articleService.create(article);
   return mv;
 }
Example #3
0
  /**
   * Adds an article (notebook, supply, software) to the cart.
   *
   * @param article the requested article
   * @param number the amount of requested articles
   * @param cart contains a fresh initialized cart
   * @param success notification about adding an article to the cart
   * @return redirect to the category the requested article is part of
   */
  @RequestMapping(value = "/cart", method = RequestMethod.POST)
  public String addarticle(
      @RequestParam("pid") Article article,
      @RequestParam("number") int number,
      @ModelAttribute Cart cart,
      RedirectAttributes success) {

    Optional<InventoryItem> item = inventory.findByProductIdentifier(article.getIdentifier());

    Quantity quantity = item.map(InventoryItem::getQuantity).orElse(NONE);
    BigDecimal amount1 =
        quantity.getAmount(); // Herrje, wer das schöner schreiben will, kann das gerne machen
    int i = amount1.intValue(); // Endlich funktioniert die Validierung, besser als beim
    int amount = number; // Videoshop :P Kevin
    if (number <= 0) {
      amount = 1;
    }
    if (number >= i) {
      amount = i;
    }

    cart.addOrUpdateItem(article, Quantity.of(amount));

    success.addFlashAttribute(
        "success", "Der Artikel wurde erfolgreich Ihrem Warenkorb hinzugefügt.");

    switch (article.getType()) {
      case NOTEBOOK:
        return "redirect:laptop";

      case SOFTWARE:
        return "redirect:software";
      case ZUBE:
      default:
        return "redirect:zubehoer";
    }
  }
  @RequestMapping(method = RequestMethod.GET, value = "/{articleId}")
  public ModelAndView distribute(@PathVariable String articleId, HttpServletRequest request) {
    ModelAndView view = new ModelAndView();
    String wxopenid = request.getParameter("wxopenid");
    String wechat = request.getParameter("wgateid");
    String verify = request.getParameter("verify");
    String articleURL = "";
    if (!StringUtils.isEmpty(wechat)) {
      Reader reader = new Reader();
      reader.setReaderWechat(wechat);
      ResultData readerExistMessage = readerService.queryReader(reader);
      if (readerExistMessage.getResponseCode() == ResponseCode.RESPONSE_NULL) {
        readerService.createReader(reader);
      } else if (readerExistMessage.getResponseCode() == ResponseCode.RESPONSE_ERROR) {

      }
    }
    // 根据文章的ID查询图文信息
    ArticleViewVO vo = new ArticleViewVO();
    Article article = new Article();
    article.setArticleId(articleId);
    ResultData articleMessage = articleService.queryArticle(article);
    vo.setArticle((Article) articleMessage.getData());
    // 根据文章的ID和用户的微信标识查询当前用户是否已经打赏过此文章
    if (!StringUtils.isEmpty(wechat)) {
      Deal deal = new Deal(wechat, articleId);
      ResultData dealMessage = dealService.queryDealRecord(deal);
      if (dealMessage.getResponseCode() == ResponseCode.RESPONSE_OK) {
        vo.setPaymentStatus(ArticlePaymentStatus.ARTICLE_PAYED);
      } else {
        vo.setPaymentStatus(ArticlePaymentStatus.ARTICLE_NOT_PAYED);
      }
    } else {
      vo.setPaymentStatus(ArticlePaymentStatus.ARTICLE_NOT_PAYED);
    }
    view.setViewName("/distribute/view");
    view.addObject("vo", vo);
    if (!StringUtils.isEmpty(wechat)) {
      String url =
          "http://www.njuat.com/distribute/"
              + articleId
              + "?wxopenid="
              + wxopenid
              + "&wgateid="
              + wechat
              + "&verify="
              + verify;
      Configuration configuration = WechatConfig.config(url);
      try {
        String shareURL =
            "http://www.weixingate.com/gate.php?back="
                + URLEncoder.encode("http://www.njuat.com/distribute/" + articleId, "utf-8")
                + "&force=1";
        configuration.setShareLink(shareURL);
      } catch (Exception e) {

      }
      view.addObject("configuration", configuration);
      view.addObject("wgateid", wechat);
    }
    return view;
  }