Ejemplo n.º 1
0
  @RequestMapping("/savePaintingPartsInfo")
  @ResponseBody
  public Object savePaintingPartsInfo(String data, HttpServletRequest request) throws Exception {
    log.info("------------start savePaintingPartsInfo -----------------");
    log.info("----------------------data:" + data + "-------------------------");
    HeadObject headObject = null;
    try {
      headObject = CommonHeadUtil.geneHeadObject("paintingService.saveCarParts");
      JSONObject jsonData = JSONObject.fromObject(data);
      MemberListDo memberListDo =
          APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
      JSONObject jsonObject = new JSONObject();

      //			JSONObject carPartsJson = new JSONObject();
      //			carPartsJson.put("car_part_id", jsonData.getString("car_part_id"));
      //			carPartsJson.put("pic", jsonData.getString("pic"));
      //			carPartsJson.put("remark", jsonData.getString("remark"));

      jsonObject.put("catParts", jsonData.get("catParts"));
      jsonObject.put("memberId", memberListDo.getMemberId());
      jsonObject.put("accountId", memberListDo.getAccountId());
      HeadObject retObject =
          (HeadObject) otherService.doServiceByServer(new RequestObject(headObject, jsonObject));
      return new ResultObject(retObject);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return processExpction(e.getMessage());
    }
  }
Ejemplo n.º 2
0
  /**
   * @Title: replyComment @Description: 卖家回复评论
   *
   * @author <a href="*****@*****.**">蔡志杰</a>
   * @date 2015-8-25 下午4:35:02
   * @version 1.0.0
   * @param @param data
   * @param @param request
   * @param @return
   * @return Object 返回类型
   * @throws
   */
  @RequestMapping("/replyComment")
  public Object replyComment(String data, HttpServletRequest request) {
    log.info("---------CommentsManagerController.replyComment-----------");
    log.info("----------------------data:" + data + "-------------------------");
    HeadObject headObject = null;
    ResultObject resultObject = null;

    OrderCommentVO orderCommentVO = JSON.parseObject(data, OrderCommentVO.class);
    ValidationResult bindingResult = ValidationUtils.validateEntity(orderCommentVO);
    if (bindingResult.isHasErrors()) {
      return elementErrors(headObject, bindingResult);
    }

    try {
      MemberListDo memberListDo =
          APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
      if (null != memberListDo) {
        orderCommentVO.setCommentsType(CommentConstant.CommentsType.EXPLAIN.getKey());
        orderCommentVO.setMemberId(Long.parseLong(memberListDo.getMemberId()));
        OrderComment record = new OrderComment();
        BeanUtils.copyProperties(record, orderCommentVO);
        headObject = CommonHeadUtil.geneHeadObject("orderCommentService.saveOrderComment");
        resultObject =
            (ResultObject) orderService.doServiceByServer(new RequestObject(headObject, record));
      } else {
        return CommonUtil.notLoign(headObject);
      }
    } catch (Exception e) {
      e.printStackTrace();
      log.error("数据处理异常{}", e);
      return processExpction(headObject);
    }
    return resultObject;
  }
Ejemplo n.º 3
0
  /**
   * @Title: commentsListData @Description: 评论列表
   *
   * @author <a href="*****@*****.**">蔡志杰</a>
   * @date 2015-8-25 下午4:34:48
   * @version 1.0.0
   * @param @param data
   * @param @param request
   * @param @return
   * @return Object 返回类型
   * @throws
   */
  @RequestMapping("/commentsListData")
  public Object commentsListData(String data, HttpServletRequest request) {
    log.info("---------CommentsManagerController.commentsListData-----------");
    log.info("----------------------data:" + data + "-------------------------");
    HeadObject headObject = null;
    ResultObject resultObject = null;
    try {
      MemberListDo memberListDo =
          APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
      if (null != memberListDo) {
        JSONObject obj = JSON.parseObject(data);
        String pageIndex = obj.getString("page");
        String pageSize = obj.getString("rows");

        MemberCommentQryDTO qryDTO = new MemberCommentQryDTO();
        qryDTO.setPage(
            StringUtil.isEmpty(pageIndex)
                ? GlobalStatic.DEFAULT_PAGE_INDEX
                : Integer.parseInt(pageIndex));
        qryDTO.setRows(
            StringUtil.isEmpty(pageSize)
                ? GlobalStatic.DEFAULT_PAGE_SIZE
                : Integer.parseInt(pageSize));
        qryDTO.setStoreId(memberListDo.getStoreId().intValue());
        qryDTO.setCompanyId(memberListDo.getCompanyId());
        qryDTO.setObjectType("order");
        headObject = CommonHeadUtil.geneHeadObject("orderCommentService.findMemberComment");
        resultObject =
            (ResultObject) orderService.doServiceByServer(new RequestObject(headObject, qryDTO));
      }

    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return processExpction(e.getMessage());
    }
    return resultObject;
  }
Ejemplo n.º 4
0
  @RequestMapping("/deleteCart")
  @ResponseBody
  public Object deleteCart(String data, HttpServletRequest request) throws Exception {
    log.info("start[CartController.deleteCart]");

    // 获取请求参数
    JSONObject jsonData = JSONObject.fromObject(data);
    MemberListDo memberListDo =
        APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
    Integer accountId = memberListDo.getAccountId();

    ///////// 测试代码 start //////
    //		Integer  accountId=152;
    //		jsonData = new JSONObject();
    //		jsonData.put("proIdListString", "[445,399,438]");
    ///////// 测试代码 end //////

    // 获取数据
    String proIdString = jsonData.getString("proIdListString");

    // 检查参数
    if (StringUtils.isEmpty(proIdString)) {
      return processExpction("货品ID不能为空");
    }

    PamAccount pamAccount = findAccountId(accountId);
    if (pamAccount != null && !"100".equals(pamAccount.getAccountType())) {
      return new ResultObject(
          new HeadObject(ErrorCode.SUCCESS), JSONObject.fromObject("{result:false,isBuyer:false}"));
    }
    if (pamAccount != null) {
      accountId = pamAccount.getAccountId();
    }
    List<Integer> proIdList = null;
    String resultMsg = null;
    if (proIdString != null && !"".equals(proIdString)) {
      proIdList =
          (List<Integer>) JSONArray.toCollection(JSONArray.fromObject(proIdString), Integer.class);
    } else {
      resultMsg = "没有选中任何商品";
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE),
          JSONObject.fromObject("{result:false,msg:'" + resultMsg + "'}"));
    }
    // 判断登陆状态
    Member member = null;
    ResultObject resultObject = null;
    member = this.selectMember(accountId);
    if (member != null) // 用户已登录
    {
      boolean deleteResult = this.deleteCartFromDb(proIdList, member.getMemberId());
      resultObject =
          new ResultObject(
              new HeadObject(ErrorCode.SUCCESS),
              JSONObject.fromObject("{result:" + deleteResult + "}"));
    } else { // 用户未登录
      resultObject =
          new ResultObject(new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{msg:未登录}"));
    }
    log.info("end[CartController.deleteCart]");
    return resultObject;
  }
Ejemplo n.º 5
0
  @RequestMapping("/addCart")
  @ResponseBody
  public Object addCart(String data, HttpServletRequest request) {
    log.info("start[CartController.addCart]");
    try {
      // 获取请求参数
      JSONObject jsonData = JSONObject.fromObject(data);
      MemberListDo memberListDo =
          APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
      Integer accountId = memberListDo.getAccountId();

      // 测试数据
      //			Integer accountId = 152;
      //			jsonData = new JSONObject();
      //			jsonData.put("quantity", "10");
      //			jsonData.put("productId", "438");

      // 获取数据
      String goodsIdString = (String) CommonUtil.getJsonValue(jsonData, "goodsId");
      String quantityString = (String) CommonUtil.getJsonValue(jsonData, "quantity");
      String specValueId = (String) CommonUtil.getJsonValue(jsonData, "specValueId");
      String productIdString = (String) CommonUtil.getJsonValue(jsonData, "productId");

      // 检查参数
      if (StringUtils.isEmpty(quantityString)) {
        return processExpction("数量不能为空");
      }
      if (StringUtils.isEmpty(productIdString)) {
        return processExpction("货品id不能为空");
      }
      PamAccount pamAccount = findAccountId(accountId);
      if (pamAccount != null && !"100".equals(pamAccount.getAccountType())) {
        return new ResultObject(
            new HeadObject(ErrorCode.SUCCESS),
            JSONObject.fromObject("{result:false,isBuyer:false}"));
      }
      if (pamAccount != null) {
        accountId = pamAccount.getAccountId();
      }
      // 判断数据是否合法
      String addCartDataResult =
          this.addCartdata(
              goodsIdString, quantityString, specValueId, productIdString, accountId, null);
      ResultObject resultObject = null;
      if ("".equals(addCartDataResult)) // 数据合法
      {
        // 判断登陆状态
        Member member = this.selectMember(accountId);
        String addCartResult = null;
        if (member != null) // 用户已登录
        {
          newCart.setMemberId(member.getMemberId());
          addCartResult = this.addCartToDb(newCart, accountId);
        } else { // 用户未登录

        }
        resultObject =
            new ResultObject(
                new HeadObject(ErrorCode.SUCCESS),
                addCartResult != null
                    ? JSONObject.fromObject("{result:false,msg:'" + addCartResult + "'}")
                    : JSONObject.fromObject("{result:true}"));
      } else { // 加入购物车的数据不合法
        resultObject =
            new ResultObject(
                new HeadObject(ErrorCode.SUCCESS),
                JSONObject.fromObject("{result:false,msg:'" + addCartDataResult + "'}"));
      }
      log.info("end[CartController.addCart]");
      return resultObject;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return processExpction(e.getMessage());
    }
  }
Ejemplo n.º 6
0
  /**
   * @Title: orderAdd @Description: (提交订单)
   *
   * @author <a href="*****@*****.**">赖彩妙</a>
   * @date 2015-4-18
   * @version 1.0.0
   * @param request
   * @param response
   * @param @return
   * @param @throws Exception
   * @return Object 返回类型
   * @throws
   */
  @ResponseBody
  @RequestMapping("/submitOrder")
  public Object submitOrder(String data, HttpServletRequest request) throws Exception {
    log.info("start[CartController.submitOrder]");
    // 获取请求参数
    JSONObject jsonData = JSONObject.fromObject(data);
    MemberListDo memberListDo =
        APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));

    //  		//测试
    //  		memberListDo = new MemberListDo();
    //  		memberListDo.setAccountType("100");
    //  		memberListDo.setMemberId("62");
    //  		memberListDo.setAccountId(152);
    //  		memberListDo.setLoginName("YOYO");

    // 订单号
    ResultObject resultObject = null;
    HeadObject headObject = null;
    JSONObject jsonObject = new JSONObject();
    // 查询当前登陆的member对象
    if (memberListDo == null || !memberListDo.getAccountType().equals("100")) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,isBuyer:false}"));
    }
    // 用户已登录
    String storeIdString = jsonData.getJSONArray("storeIds").toString();
    String payment = (String) CommonUtil.getJsonValue(jsonData, "payment");

    String proIdsString = jsonData.getJSONArray("proIdListString").toString();
    String remark = jsonData.getString("remark");
    String quantityListString = jsonData.getJSONArray("quantityListString").toString();
    Integer point =
        StringUtil.isNotEmpty((String) CommonUtil.getJsonValue(jsonData, "point"))
            ? Integer.parseInt((String) CommonUtil.getJsonValue(jsonData, "point"))
            : 0;
    String appointmentStr = (String) CommonUtil.getJsonValue(jsonData, "appointmens");
    String goodsIdsStr = (String) CommonUtil.getJsonValue(jsonData, "goodsIds");

    List<Integer> storeIdList = null;
    payment =
        (payment != null && ("到店支付".equals(payment) || "在线支付".equals(payment))) ? payment : "在线支付";
    if (StringUtil.isEmpty(storeIdString)) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,msg:'请选择门店'}"));
    }
    storeIdList =
        (List<Integer>) JSONArray.toCollection(JSONArray.fromObject(storeIdString), Integer.class);
    if (null == storeIdList || storeIdList.size() <= 0) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,msg:'请选择门店'}"));
    }
    List<Integer> proIdList = null;
    if (StringUtil.isEmpty(proIdsString)) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,msg:'该货品不存在'}"));
    }
    proIdList =
        (List<Integer>) JSONArray.toCollection(JSONArray.fromObject(proIdsString), Integer.class);
    if (null == proIdList || proIdList.size() <= 0) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,msg:'该货品不存在'}"));
    }
    Member member = this.selectMember(memberListDo.getAccountId());
    if (point > member.getPointUseable().intValue()) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE),
          JSONObject.fromObject("{result:false,msg:'可用积分小于兑换积分'}"));
    }
    List<Integer> quantityList =
        (List<Integer>)
            JSONArray.toCollection(JSONArray.fromObject(quantityListString), Integer.class);
    // 根据proIdList查询购物车对象
    headObject = CommonHeadUtil.geneHeadObject("cartService.findMemberCartListByProIdList");
    Map<String, Object> cartParam = new HashMap<String, Object>();
    cartParam.put("proIdList", proIdList);
    cartParam.put("memberId", Integer.valueOf(memberListDo.getMemberId()));
    resultObject =
        (ResultObject) orderService.doServiceByServer(new RequestObject(headObject, cartParam));
    List<CartListDTO> cartList =
        (List<CartListDTO>)
            JSONArray.toCollection(
                JSONArray.fromObject(resultObject.getContent()), CartListDTO.class);
    if (null != cartList && cartList.size() > 0) {
      for (CartListDTO cartListDTO : cartList) {
        if ("1".equals(cartListDTO.getLimitGoodsdown())
            || "1".equals(cartListDTO.getLimitStore())
            || "1".equals(cartListDTO.getLimitStoredown())
            || "1".equals(cartListDTO.getShopStatus())
            || "1".equals(cartListDTO.getStatus())
            || "1".equals(cartListDTO.getDisabled())) {
          return new ResultObject(
              new HeadObject(ErrorCode.FAILURE),
              JSONObject.fromObject("{result:false,isLogin:true,msg:\"很抱歉,该订单中存在失效货品\"}"));
        }
      }
    }
    if (cartList != null && cartList.size() >= 1) {
      // 查询店铺
      storeIdList.clear();
      for (int i = 0; i < cartList.size(); i++) {
        storeIdList.add(cartList.get(i).getStoreId());
      }
      headObject = CommonHeadUtil.geneHeadObject("storeService.selectByStoreIdList3");
      resultObject =
          (ResultObject)
              memberService.doServiceByServer(new RequestObject(headObject, storeIdList));
      List<Store> storeList = null;
      if (resultObject.getContent() != null) {
        storeList =
            com.alibaba.fastjson.JSONArray.parseArray(
                resultObject.getContent().toString(), Store.class);
      }
      if (storeList != null) {
        for (int i = 0; i < storeList.size(); i++) {
          if ("1".equals(storeList.get(i).getLimitGoodsdown())
              || "1".equals(storeList.get(i).getLimitStore())
              || "1".equals(storeList.get(i).getLimitStoredown())
              || "1".equals(storeList.get(i).getShopstatus())
              || "1".equals(storeList.get(i).getStatus())
              || "1".equals(storeList.get(i).getDisabled())) {
            return new ResultObject(
                new HeadObject(ErrorCode.FAILURE),
                JSONObject.fromObject("{result:false,isLogin:true,msg:'很抱歉,该订单中存在失效货品'}"));
          }
        }
      }

      for (int i = 0; i < cartList.size(); i++) {
        if ("0".equals(cartList.get(i).getgMarketable())
            || "1".equals(cartList.get(i).getgDisabled())
            || "0".equals(cartList.get(i).getpMarketable())
            || "1".equals(cartList.get(i).getpDisabled())) {
          return new ResultObject(
              new HeadObject(ErrorCode.FAILURE),
              JSONObject.fromObject("{result:false,isLogin:true,msg:'很抱歉,该订单中存在失效货品'}"));
        }
        for (int j = 0; j < proIdList.size(); j++) {
          if (proIdList.get(j).equals(cartList.get(i).getProductId())) {
            if (quantityList.get(j) > cartList.get(i).getStore()) {
              return new ResultObject(
                  new HeadObject(ErrorCode.FAILURE),
                  JSONObject.fromObject("{result:false,isLogin:true,msg:'很抱歉,该订单中存在货品库存不足'}"));
            } else {
              cartList.get(i).setQuantity(quantityList.get(j));
            }
          }
        }

        String specDesc = cartList.get(i).getSpecDesc();
        if (specDesc != null && !"".equals(specDesc)) {
          String[] specItems = specDesc.split(",");
          if (specItems != null && specItems.length >= 1) {
            for (int j = specItems.length - 1; j >= 0; j--) {
              if (specItems[j].split(":")[0].split("\\|")[1].equals("分店")) {
                cartList
                    .get(i)
                    .setStoreId(Integer.parseInt(specItems[j].split(":")[1].split("\\|")[0]));
                cartList.get(i).setStoreName(specItems[j].split(":")[1].split("\\|")[1]);
                break;
              }
            }
          }
        }
        cartList.get(i).setMemberId(Integer.valueOf(memberListDo.getMemberId()));
      }
    }

    // 判断请求来源是否来自移动端
    String checkFrom =
        jsonData.getString("fphoneostype") != null
                && jsonData.getString("fphoneostype").equals("5000")
            ? "appAndroid"
            : "appIOS";
    // 存入数据库
    if (null == cartList || cartList.size() <= 0) {
      // 删除购物车数据
      headObject = CommonHeadUtil.geneHeadObject("cartService.deleteCartByProIdAndMemberId");
      jsonObject.clear();
      jsonObject.put("memberId", memberListDo.getMemberId());
      jsonObject.put("proIdList", proIdList);
      orderService.doServiceByServer(new RequestObject(headObject, jsonObject));
      resultObject =
          new ResultObject(
              new HeadObject(ErrorCode.SUCCESS), JSONObject.fromObject("{result:true}"));
      resultObject =
          new ResultObject(
              new HeadObject(ErrorCode.FAILURE),
              JSONObject.fromObject("{result:false,msg:'订单提交失败,该订单中的货品不存在'}"));
    }

    for (CartListDTO cartListDTO : cartList) {
      headObject = CommonHeadUtil.geneHeadObject("goodsTimePriceService.findGoodsTimePrice");
      Map<String, Object> param = new HashMap<String, Object>();
      if (StringUtil.isNotEmpty(cartListDTO.getAppointment())) {
        int index =
            cartListDTO.getAppointment().indexOf("|") == -1
                ? cartListDTO.getAppointment().length()
                : cartListDTO.getAppointment().indexOf("|");
        param.put("priceDate", cartListDTO.getAppointment().substring(0, index));
      } else {
        param.put("priceDate", new Date());
      }
      param.put("goodsId", cartListDTO.getGoodsId());
      resultObject =
          (ResultObject) itemService.doServiceByServer(new RequestObject(headObject, param));
      if (null != resultObject.getContent()) {
        GoodsTimePrice goodsTimePrice = (GoodsTimePrice) resultObject.getContent();
        cartListDTO.setGoodsPrice(goodsTimePrice.getPrice().doubleValue());
      }
    }
    jsonObject.clear();
    jsonObject.put("member", member);
    jsonObject.put("cartList", cartList);
    jsonObject.put("payment", payment);
    jsonObject.put("checkFrom", checkFrom);
    jsonObject.put("ip", request.getRemoteAddr());
    jsonObject.put("remark", remark);
    jsonObject.put("memberName", memberListDo.getLoginName());
    jsonObject.put("point", point);
    synchronized (this) {
      headObject = CommonHeadUtil.geneHeadObject("cartService.saveOrder");
      resultObject =
          (ResultObject) orderService.doServiceByServer(new RequestObject(headObject, jsonObject));
      if (resultObject.getHead().getRetCode().equals(ErrorCode.FAILURE)) {
        return new ResultObject(
            new HeadObject(ErrorCode.SUCCESS),
            JSONObject.fromObject(
                "{result:false,msg:'订单提交失败," + resultObject.getHead().getRetMsg() + "'}"));
      } else {
        for (CartListDTO c : cartList) {
          headObject = CommonHeadUtil.geneHeadObject("productService.decreStore");
          jsonObject.clear();
          jsonObject.put("productId", c.getProductId());
          jsonObject.put("quantity", c.getQuantity());
          itemService.doServiceByServer(new RequestObject(headObject, jsonObject));
        }

        headObject = CommonHeadUtil.geneHeadObject("cartService.deleteCartByProIdAndMemberId");
        jsonObject.clear();
        jsonObject.put("memberId", memberListDo.getMemberId());
        jsonObject.put("proIdList", proIdList);
        orderService.doServiceByServer(new RequestObject(headObject, jsonObject));

        try {
          String[] appointments = appointmentStr.split(",");
          String[] goodsIds = goodsIdsStr.split(",");
          for (int j = 0; j < goodsIds.length; j++) {
            String key =
                goodsIds[j]
                    + "_"
                    + appointments[j].replace("-", "").replace(":", "").replace("|", "_");
            String count = redisService.get(key.toString());
            if (StringUtil.isEmpty(count)) {
              count = "1";
            } else {
              count = String.valueOf(Integer.valueOf(count) + 1);
            }
            redisService.set(key.toString(), count, 60 * 60 * 24);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      return new ResultObject(new HeadObject(ErrorCode.SUCCESS), null);
    }
  }
Ejemplo n.º 7
0
  /**
   * @Description: (获取确认订单页面的货品和分店数据)
   *
   * @param request
   * @param response
   * @return
   * @throws Exception
   */
  @RequestMapping("/findOrderInfo")
  @ResponseBody
  public Object findOrderInfo(String data, HttpServletRequest request) throws Exception {
    log.info("start[CartController.findOrderInfo]");

    // 获取请求参数
    JSONObject jsonData = JSONObject.fromObject(data);
    MemberListDo memberListDo =
        APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
    Integer accountId = memberListDo.getAccountId();

    ///////// 测试代码 start //////
    //		Integer  accountId=152;
    //		jsonData = new JSONObject();
    //		jsonData.put("proIdListString", "[399,445,438]");
    //		jsonData.put("quantityListString", "[3,2,4]");
    ///////// 测试代码 end //////
    String proIdListString = (String) CommonUtil.getJsonValue(jsonData, "proIdListString");
    String quantityListString = (String) CommonUtil.getJsonValue(jsonData, "quantityListString");

    // 检查参数
    if (StringUtils.isEmpty(proIdListString)) {
      return processExpction("货品id不能为空!");
    }
    if (StringUtils.isEmpty(quantityListString)) {
      return processExpction("数量不能为空!");
    }

    PamAccount pamAccount = findAccountId(accountId);
    if (pamAccount != null && !"100".equals(pamAccount.getAccountType())) {
      return new ResultObject(
          new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{result:false,isBuyer:false}"));
    }
    if (pamAccount != null) {
      accountId = pamAccount.getAccountId();
    }
    ResultObject resultObject = null;
    HeadObject headObject;
    JSONObject jsonObject = new JSONObject();

    if (accountId != null && accountId != 0) {
      List<Integer> proIdList =
          (List<Integer>)
              JSONArray.toCollection(JSONArray.fromObject(proIdListString), Integer.class);
      if (proIdList != null && proIdList.size() >= 1) {
        // 查询member对象
        Member member = this.selectMember(accountId);
        // 根据proIdList查询购物车对象
        List<CartListDTO> cartList = null;
        List<Integer> quantityList =
            (List<Integer>)
                JSONArray.toCollection(JSONArray.fromObject(quantityListString), Integer.class);
        if (quantityList.size() == proIdList.size()) {
          headObject = CommonHeadUtil.geneHeadObject("cartService.findCartListByProIdList");
          resultObject =
              (ResultObject)
                  orderService.doServiceByServer(
                      new RequestObject(headObject, JSONArray.fromObject(proIdList)));
          cartList =
              (List<CartListDTO>)
                  JSONArray.toCollection(
                      JSONArray.fromObject(resultObject.getContent()), CartListDTO.class);
          if (cartList != null && cartList.size() > 0) {
            for (int j = cartList.size() - 1; j >= 0; j--) {
              if ("1".equals(cartList.get(j).getLimitGoodsdown())
                  || "1".equals(cartList.get(j).getLimitStore())
                  || "1".equals(cartList.get(j).getLimitStoredown())
                  || "1".equals(cartList.get(j).getShopStatus())
                  || "1".equals(cartList.get(j).getStatus())
                  || "1".equals(cartList.get(j).getDisabled())) {
                return new ResultObject(
                    new HeadObject(ErrorCode.FAILURE),
                    JSONObject.fromObject("{ msg:\"很抱歉,该订单中存在失效货品\"}"));
              }
              for (int i = 0; i < proIdList.size(); i++) {
                if (proIdList.get(i).equals(cartList.get(j).getProductId())) {
                  if (quantityList.get(i) > cartList.get(j).getStore()) {
                    return new ResultObject(
                        new HeadObject(ErrorCode.FAILURE),
                        JSONObject.fromObject("{ msg:\"很抱歉,该订单中存在货品库存不足\"}"));
                  } else {
                    cartList.get(j).setQuantity(quantityList.get(i));
                  }
                }
              }
            }
          }
        }
        if (!(cartList != null && cartList.size() >= 1)) {
          headObject = CommonHeadUtil.geneHeadObject("cartService.findCartListByProIdAndMem");
          jsonObject.put("memberId", member.getMemberId());
          jsonObject.put("proIdList", proIdList);
          resultObject =
              (ResultObject)
                  orderService.doServiceByServer(new RequestObject(headObject, jsonObject));
          cartList =
              (List<CartListDTO>)
                  JSONArray.toCollection(
                      JSONArray.fromObject(resultObject.getContent()), CartListDTO.class);
        }
        List<Store> storeList = null;
        if (cartList != null && cartList.size() >= 1) {
          // 查询店铺
          List<Integer> storeIdList = new ArrayList<Integer>();
          for (int i = 0; i < cartList.size(); i++) {
            storeIdList.add(cartList.get(i).getStoreId());
          }
          headObject = CommonHeadUtil.geneHeadObject("storeService.selectByStoreIdList3");
          resultObject =
              (ResultObject)
                  memberService.doServiceByServer(new RequestObject(headObject, storeIdList));

          if (resultObject.getContent() != null) {
            storeList =
                com.alibaba.fastjson.JSONArray.parseArray(
                    resultObject.getContent().toString(), Store.class);
          }
          if (storeList != null) {
            for (int i = 0; i < storeList.size(); i++) {
              if ("1".equals(storeList.get(i).getLimitGoodsdown())
                  || "1".equals(storeList.get(i).getLimitStore())
                  || "1".equals(storeList.get(i).getLimitStoredown())
                  || "1".equals(storeList.get(i).getShopstatus())
                  || "1".equals(storeList.get(i).getStatus())
                  || "1".equals(storeList.get(i).getDisabled())) {
                return new ResultObject(
                    new HeadObject(ErrorCode.FAILURE),
                    JSONObject.fromObject("{isLogin:true,msg:\"很抱歉,该订单中存在失效货品\"}"));
              }
            }
          }

          // 查询货品图片
          this.findProImage(cartList);
          for (int j = cartList.size() - 1; j >= 0; j--) {
            if (cartList.get(j).getQuantity() <= 0
                || "0".equals(cartList.get(j).getgMarketable())
                || "1".equals(cartList.get(j).getgDisabled())
                || "0".equals(cartList.get(j).getpMarketable())
                || "1".equals(cartList.get(j).getpDisabled())) {
              return new ResultObject(
                  new HeadObject(ErrorCode.FAILURE),
                  JSONObject.fromObject("{isLogin:true,msg:\"很抱歉,该订单中存在失效货品\"}"));
            }
          }
        }

        Double sumPrice = this.totalPrice(cartList);

        com.alibaba.fastjson.JSONObject returnJson = new com.alibaba.fastjson.JSONObject();
        DecimalFormat df2 = new DecimalFormat("#.00"); // 四舍五入保留两位小数
        returnJson.put("sumPrice", df2.format(Double.parseDouble(sumPrice.toString())));
        // 按商店号分组
        List<List<CartListDTO>> list = new ArrayList();
        Map<Integer, List<CartListDTO>> map = new HashMap<Integer, List<CartListDTO>>();

        // 图片地址转成httpURL
        String imgUrl = Configuration.getInstance().getConfigValue("images.url");
        if (cartList != null && !cartList.isEmpty()) {
          for (CartListDTO cto : cartList) {
            cto.setGoodsImage(imgUrl + cto.getGoodsImage());

            Integer storeId = cto.getStoreId();
            List<CartListDTO> cList = map.get(storeId);
            if (cList == null) {
              cList = new ArrayList<CartListDTO>();
              map.put(storeId, cList);
            }
            cList.add(cto);
          }
          for (List<CartListDTO> cList : map.values()) {
            list.add(cList);
          }
        }
        returnJson.put("content", list);
        returnJson.put("storeList", storeList);
        returnJson.put("isLogin", true);
        resultObject = new ResultObject(new HeadObject(ErrorCode.SUCCESS), returnJson);
      } else {
        resultObject =
            new ResultObject(
                new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{empty:true}"));
      }
    } else {
      resultObject =
          new ResultObject(new HeadObject(ErrorCode.FAILURE), JSONObject.fromObject("{}"));
    }

    log.info("end[CartController.findOrderInfo]");
    return resultObject;
  }
Ejemplo n.º 8
0
  /**
   * 获取购物车列表
   *
   * @param data
   * @param request
   * @return
   */
  @RequestMapping("/cartList")
  @ResponseBody
  public Object cartList(String data, HttpServletRequest request) {
    log.info("###########cartList-->start");
    log.info("----------------------data:" + data + "-------------------------");
    try {
      // 获取请求参数
      JSONObject jsonData = JSONObject.fromObject(data);
      MemberListDo memberListDo =
          APICommonUtil.getMemberListDo((String) request.getAttribute("sessionid"));
      Integer accountId = memberListDo.getAccountId();
      //				Integer accountId = 152;
      HeadObject headObject = CommonHeadUtil.geneHeadObject("accountService.selectByAccountId");
      ResultObject resultObject =
          (ResultObject) memberService.doServiceByServer(new RequestObject(headObject, accountId));
      PamAccount pamAccount = null;
      if (resultObject != null && resultObject.getContent() != null) {
        pamAccount = (PamAccount) resultObject.getContent();
      }

      if (pamAccount != null && !"100".equals(pamAccount.getAccountType())) {
        return new ResultObject(
            new HeadObject(ErrorCode.FAILURE),
            JSONObject.fromObject("{result:false,isBuyer:false}"));
      }
      if (pamAccount != null) {
        accountId = pamAccount.getAccountId();
      }
      Member member = null;
      if (accountId != null && accountId != 0) {
        member = this.selectMember(accountId);
      }
      List<CartListDTO> cartList = null;
      if (member != null && member.getMemberId() != 0) {
        // 用户已登录
        // 查询数据库中的购物车商品
        headObject = CommonHeadUtil.geneHeadObject("cartService.findCartListByAccountId");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("accountId", accountId);
        resultObject =
            (ResultObject)
                orderService.doServiceByServer(new RequestObject(headObject, jsonObject));
        cartList = (List<CartListDTO>) resultObject.getContent();
      }

      // 查询货品图片
      cartList = this.findProImage(cartList);

      // 查询分店
      cartList = this.findStoresByCartList(cartList);

      // 按商店号分组
      List<List<CartListDTO>> list = new ArrayList();
      Map<Integer, List<CartListDTO>> map = new HashMap<Integer, List<CartListDTO>>();

      // 图片地址转成httpURL
      String imgUrl = Configuration.getInstance().getConfigValue("images.url");
      if (cartList != null && !cartList.isEmpty()) {
        for (CartListDTO cto : cartList) {
          cto.setGoodsImage(imgUrl + cto.getGoodsImage());

          Integer storeId = cto.getStoreId();
          List<CartListDTO> cList = map.get(storeId);
          if (cList == null) {
            cList = new ArrayList<CartListDTO>();
            map.put(storeId, cList);
          }
          cList.add(cto);
        }
        for (List<CartListDTO> cList : map.values()) {
          list.add(cList);
        }
      }

      JSONObject jsonObject = new JSONObject();
      jsonObject.put("cartList", list);
      resultObject = new ResultObject(new HeadObject(ErrorCode.SUCCESS), jsonObject);
      log.info("###########cartList-->end");
      return resultObject;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return processExpction(e.getMessage());
    }
  }