/**
   * 生成订单,跳转到支付宝支付页面<br>
   *
   * @author 冯鑫<br>
   *     2014-9-12
   * @throws IOException
   * @update 侯杨
   * @see OrderManagerAction#toPayOrder
   * @since vmaque1.5
   */
  public String toPayOrder() throws IOException {
    String price = request.getParameter("price");
    String paytype = request.getParameter("paytype"); // 支付方式
    // 商品总价赋值
    conSumerUserData.setPayType(Integer.parseInt(paytype));
    commodityConfigData.setConfigPrice(Double.parseDouble(price));
    conSumerOrderData =
        orderManagerFacade.createOrder(
            commodityConfigData, conSumerUserData, pageDomainName, goodsNum);
    GoodsInfoData goodsInfoData = new GoodsInfoData();
    goodsInfoData.setId(commodityConfigData.getGoodsInfoData().getId());
    goodsInfoData = goodsInfoFacade.getGoodsInfoData(goodsInfoData);
    String alipayForm;

    conSumerOrderData.setPrice(Double.parseDouble(price));
    if (price.equals("0")) {
      request.setAttribute("ordercode", conSumerOrderData.getOrderCode());
      if (conSumerUserData.getRedPackageId() != null
          && !"".equals(conSumerUserData.getRedPackageId())) {
        request.setAttribute("redpackageId", conSumerUserData.getRedPackageId());
        request.setAttribute("cId", conSumerUserData.getcId());
        request.setAttribute("sId", conSumerUserData.getsId());
      }
      return "payForSuccess_order";
    }
    // 如果为1 则是pc支付
    if ("1".equals(pcFlag)) {
      alipayForm = this.getAlipayForm(conSumerOrderData, goodsInfoData); // 支付的表单getAlipayForm_Phone
    } else {
      alipayForm = this.getAlipayForm_Phone(conSumerOrderData, goodsInfoData);
    }
    request.setAttribute("alipayForm", alipayForm);
    return "toPayJsp";
  }
  /**
   * 生成订单,跳转到微信支付<br>
   *
   * @author 侯杨<br>
   *     2015-01-13
   * @throws IOException
   * @update
   * @see OrderManagerAction#toweixinPayOrder
   * @since vmaque2.0
   */
  public void toweixinPayOrder() throws IOException {
    String price = request.getParameter("price");
    String paytype = request.getParameter("paytype"); // 支付方式
    // 商品总价赋值
    conSumerUserData.setPayType(Integer.parseInt(paytype));
    commodityConfigData.setConfigPrice(Double.parseDouble(price));
    conSumerOrderData =
        orderManagerFacade.createOrder(
            commodityConfigData, conSumerUserData, pageDomainName, goodsNum);
    GoodsInfoData goodsInfoData = new GoodsInfoData();
    goodsInfoData.setId(commodityConfigData.getGoodsInfoData().getId());
    goodsInfoData = goodsInfoFacade.getGoodsInfoData(goodsInfoData);

    conSumerOrderData.setPrice(Double.parseDouble(price));
    conSumerOrderData.setGoodsName(goodsInfoData.getGoodsName());
    if (conSumerOrderData != null) {
      conSumerOrderData.setConSumerUserData(conSumerUserData);
      JSONObject object = JSONObject.fromObject(conSumerOrderData);
      response.getWriter().print(object);
    } else {
      response.getWriter().print("1");
    }
  }
  /**
   * 根据查询条件分页查询出符合条件的商品订单信息
   *
   * @author 左香勇 2014-9-9
   * @update
   * @param conSumerOrderData 查询条件实体信息 pageRoll 分页查询对象
   * @return List<ConsumerOrderGoodsinfoData> 符合查询条件商品订单信息集合
   * @since vmaque 1.5
   */
  public List<ConsumerOrderGoodsinfoData> getConSumerOrderGoodsInfoDataList(
      PageRoll pageRoll, ConSumerOrderData conSumerOrderData) {
    // 定义查询语句
    StringBuffer querySql = new StringBuffer("SELECT ");
    querySql.append("MCG.ID AS ID,MCG.GOODSNUM AS GOODSNUM,");
    querySql.append(
        "MCO.ID AS CONSUMERORDERID,MCO.PRICE AS PRICE,MCO.STATE AS STATE,MCO.CREATETIME AS CREATETIME,MCO.LOGISTICSCOMPANY AS LOGISTICSCOMPANY,MCO.LOGISTICSNUMBER AS LOGISTICSNUMBER,MCO.DELIVERTIME AS DELIVERTIME,");
    querySql.append("MCC.CONFIGNAME AS CONFIGNAME,");
    querySql.append("MGI.GOODSNAME AS GOODSNAME,");
    querySql.append(
        "MCU.USERNAME AS USERNAME,MCU.USERADDRESS AS USERADDRESS,MCU.USERMOBILE AS USERMOBILE ");
    querySql.append("FROM MINI_CONSUMERORDER_GOODSINFO MCG ");
    querySql.append("JOIN MINI_CONSUMERORDER MCO ON MCG.CONSUMERORDERID = MCO.ID ");
    querySql.append("JOIN MINI_COMMODITYCONFIG MCC ON MCG.COMMODITYCONFIGID = MCC.ID ");
    querySql.append("JOIN MINI_GOODSINFO MGI ON MCG.GOODSINFID = MGI.ID ");
    querySql.append("JOIN MINI_CONSUMERUSER MCU ON MCO.CONSUMERUSERID = MCU.ID ");
    querySql.append("JOIN MINI_PAGE_GOODSINFO MPG ON MPG.PAGEID = MCO.PAGEID ");
    querySql.append(
        "WHERE MCG.ISDELETE = 1 AND MCO.ISDELETE = 1 AND MCC.ISDELETE = 1 AND MGI.ISDELETE = 1 AND MCU.ISDELETE = 1 AND MCO.STATE <> 4 ");

    // 定义查询条件
    StringBuffer where = new StringBuffer("");

    List<Object> objects = new ArrayList<Object>();

    // 添加查询条件
    if (conSumerOrderData != null) {

      if (conSumerOrderData.getState() != null) {
        where.append(" AND MCO.STATE=?");
        objects.add(conSumerOrderData.getState());
      }

      if (conSumerOrderData.getPageId() != null && !conSumerOrderData.getPageId().equals("")) {
        where.append("AND MCO.PAGEID=? ");
        objects.add(conSumerOrderData.getPageId());
      }
      querySql.append(where.toString());
    }

    if (conSumerOrderData.getState() != null) {
      querySql.append("ORDER BY MCO.CREATETIME,MCO.PAYTYPE DESC");
    } else {
      querySql.append("ORDER BY MCO.CREATETIME DESC");
    }

    // 分页查询
    pageRoll.setCountSQL("SELECT COUNT(1) FROM (" + querySql.toString() + ")");
    pageRoll.setSearchSQL(querySql.toString());

    JdbcDao jdbcDao = (JdbcDao) SpringContextHelper.getBean("jdbc"); // 获取jdbc
    List<ETIPResultSet> rsList = jdbcDao.search(pageRoll, objects);

    List<ConsumerOrderGoodsinfoData> consumerOrderGoodsinfoDatas =
        new ArrayList<ConsumerOrderGoodsinfoData>();

    for (int i = 0; i < rsList.size(); i++) {
      ConsumerOrderGoodsinfoData consumerOrderGoodsinfoData = new ConsumerOrderGoodsinfoData();
      ConSumerOrderData sumerOrderData = new ConSumerOrderData();
      GoodsInfoData goodsInfoData = new GoodsInfoData();
      CommodityConfigData commodityConfigData = new CommodityConfigData();
      ConSumerUserData conSumerUserData = new ConSumerUserData();

      conSumerUserData.setUserName(rsList.get(i).getString("USERNAME"));
      conSumerUserData.setUserAddress(rsList.get(i).getString("USERADDRESS"));
      conSumerUserData.setUserMobile(rsList.get(i).getString("USERMOBILE"));

      sumerOrderData.setConSumerUserData(conSumerUserData);
      sumerOrderData.setId(rsList.get(i).getString("CONSUMERORDERID"));
      sumerOrderData.setCreateTime(rsList.get(i).getDate("CREATETIME"));
      sumerOrderData.setPrice(rsList.get(i).getDouble("PRICE"));
      sumerOrderData.setState(rsList.get(i).getInt("STATE"));
      sumerOrderData.setLogisticsCompany(rsList.get(i).getString("LOGISTICSCOMPANY"));
      sumerOrderData.setLogisticsNumber(rsList.get(i).getString("LOGISTICSNUMBER"));
      sumerOrderData.setDeliverTime(rsList.get(i).getDate("DELIVERTIME"));

      commodityConfigData.setConfigName(rsList.get(i).getString("CONFIGNAME"));

      goodsInfoData.setGoodsName(rsList.get(i).getString("GOODSNAME"));

      consumerOrderGoodsinfoData.setCommodityConfigData(commodityConfigData);
      consumerOrderGoodsinfoData.setGoodsInfoData(goodsInfoData);
      consumerOrderGoodsinfoData.setConSumerOrderData(sumerOrderData);
      consumerOrderGoodsinfoData.setGoodsNum(rsList.get(i).getInt("GOODSNUM"));
      consumerOrderGoodsinfoData.setId(rsList.get(i).getString("ID"));

      consumerOrderGoodsinfoDatas.add(consumerOrderGoodsinfoData);
    }

    return consumerOrderGoodsinfoDatas;
  }
  /**
   * 根据订单商品信息中间表Id查询的商品订单信息(后台)
   *
   * @author 左香勇 2014-9-15
   * @update
   * @param consumerOrderGoodsinfoDataId 订单商品信息中间表id
   * @return ConsumerOrderGoodsinfoData 订单商品信息中间实体
   * @since vmaque 1.5
   */
  public ConsumerOrderGoodsinfoData getConSumerOrderGoodsInfoDataById(
      String consumerOrderGoodsinfoDataId) {
    // 定义查询语句
    StringBuffer querySql = new StringBuffer("SELECT ");
    querySql.append("MCG.ID AS ID,MCG.GOODSNUM AS GOODSNUM,");
    querySql.append("MCO.ID AS CONSUMERORDERID,MCO.PRICE AS PRICE,MCO.STATE AS STATE,");
    querySql.append("MCO.CREATETIME AS CREATETIME,MCO.LOGISTICSCOMPANY AS LOGISTICSCOMPANY,");
    querySql.append("MCO.LOGISTICSNUMBER AS LOGISTICSNUMBER,MCO.DELIVERTIME AS DELIVERTIME,");
    querySql.append("MCC.CONFIGNAME AS CONFIGNAME,");
    querySql.append("MGI.GOODSNAME AS GOODSNAME,");
    querySql.append(
        "MCU.USERNAME AS USERNAME,MCU.USERADDRESS AS USERADDRESS,MCU.USERMOBILE AS USERMOBILE,");
    querySql.append("MPE.DOMAIN AS DOMAIN,MPG.NAME AS PAGENAME,");
    querySql.append("CSU.RECEIVABLEACCOUNT AS RECEIVABLEACCOUNT,CSU.ACCOUNTTYPE AS ACCOUNTTYPE,");
    querySql.append("CSU.LOGINMAIL AS LOGINMAIL,CSU.LOGINMOBLE AS LOGINMOBLE ");
    querySql.append("FROM MINI_CONSUMERORDER_GOODSINFO MCG ");
    querySql.append("JOIN MINI_CONSUMERORDER MCO ON MCG.CONSUMERORDERID = MCO.ID ");
    querySql.append("JOIN MINI_COMMODITYCONFIG MCC ON MCG.COMMODITYCONFIGID = MCC.ID ");
    querySql.append("JOIN MINI_GOODSINFO MGI ON MCG.GOODSINFID = MGI.ID ");
    querySql.append("JOIN MINI_CONSUMERUSER MCU ON MCO.CONSUMERUSERID = MCU.ID ");
    querySql.append("JOIN MINI_PAGE MPG ON MCO.PAGEID=MPG.ID ");
    querySql.append("JOIN CTN_SYSUSER CSU ON MPG.USER_ID=CSU.ID ");
    querySql.append("RIGHT JOIN MINI_PAGE_INFO_EXTRA MPE ON MPG.ID=MPE.PAGE_ID ");
    querySql.append("WHERE MCG.ISDELETE = 1 AND MCO.ISDELETE = 1 ");
    querySql.append("AND MCC.ISDELETE = 1 AND MGI.ISDELETE = 1 AND MCU.ISDELETE = 1 ");
    querySql.append("AND MCG.ID = ?");

    JdbcDao jdbcDao = (JdbcDao) SpringContextHelper.getBean("jdbc"); // 获取jdbc
    List<ETIPResultSet> rsList =
        jdbcDao.queryForList(querySql.toString(), new Object[] {consumerOrderGoodsinfoDataId});

    if (rsList.size() > 0) {
      ConsumerOrderGoodsinfoData consumerOrderGoodsinfoData = new ConsumerOrderGoodsinfoData();
      ConSumerOrderData sumerOrderData = new ConSumerOrderData();
      GoodsInfoData goodsInfoData = new GoodsInfoData();
      CommodityConfigData commodityConfigData = new CommodityConfigData();
      ConSumerUserData conSumerUserData = new ConSumerUserData();
      PageData pageData = new PageData();
      PageInfoExtraData pageInfoExtraData = new PageInfoExtraData();
      UserData userData = new UserData();

      // 给登录用户表添加数据
      userData.setAccountType(rsList.get(0).getInt("ACCOUNTTYPE"));
      userData.setReceivableAccount(rsList.get(0).getString("RECEIVABLEACCOUNT"));
      userData.setLoginMail(rsList.get(0).getString("LOGINMAIL"));
      userData.setLoginMoble(rsList.get(0).getString("LOGINMOBLE"));

      // 给Page信息表添加数据
      pageInfoExtraData.setDomain(rsList.get(0).getString("DOMAIN"));

      // 给page表添加数据
      pageData.setName(rsList.get(0).getString("PAGENAME"));
      pageData.setUserData(userData);
      pageData.setPageInfoExtra(pageInfoExtraData);

      // 给订单用户信息表添加数据
      conSumerUserData.setUserName(rsList.get(0).getString("USERNAME"));
      conSumerUserData.setUserAddress(rsList.get(0).getString("USERADDRESS"));
      conSumerUserData.setUserMobile(rsList.get(0).getString("USERMOBILE"));

      // 给订单表添加数据
      sumerOrderData.setConSumerUserData(conSumerUserData);
      sumerOrderData.setPageData(pageData);
      sumerOrderData.setId(rsList.get(0).getString("CONSUMERORDERID"));
      sumerOrderData.setCreateTime(rsList.get(0).getDate("CREATETIME"));
      sumerOrderData.setPrice(rsList.get(0).getDouble("PRICE"));
      sumerOrderData.setState(rsList.get(0).getInt("STATE"));
      sumerOrderData.setLogisticsCompany(rsList.get(0).getString("LOGISTICSCOMPANY"));
      sumerOrderData.setLogisticsNumber(rsList.get(0).getString("LOGISTICSNUMBER"));
      sumerOrderData.setDeliverTime(rsList.get(0).getDate("DELIVERTIME"));

      // 给规格表添加数据
      commodityConfigData.setConfigName(rsList.get(0).getString("CONFIGNAME"));

      // 给商品表添加数据
      goodsInfoData.setGoodsName(rsList.get(0).getString("GOODSNAME"));

      // 给订单商品中间表添加数据
      consumerOrderGoodsinfoData.setCommodityConfigData(commodityConfigData);
      consumerOrderGoodsinfoData.setGoodsInfoData(goodsInfoData);
      consumerOrderGoodsinfoData.setConSumerOrderData(sumerOrderData);
      consumerOrderGoodsinfoData.setGoodsNum(rsList.get(0).getInt("GOODSNUM"));
      consumerOrderGoodsinfoData.setId(rsList.get(0).getString("ID"));

      return consumerOrderGoodsinfoData;
    }

    return null;
  }