// 业务员申请退单列表
  public void listserordercb() {
    String ddzt = StringUtil.toStr(this.getPara("ddzt"));
    String zfzt = StringUtil.toStr(this.getPara("zfzt"));
    String sjqrzt = StringUtil.toStr(this.getPara("sjqrzt"));
    String sfjd = StringUtil.toStr(this.getPara("sfjd"));

    SysUser abuser = this.getSessionAttr("abuser");
    StringBuffer sb = new StringBuffer();
    sb.append("select * from (");
    sb.append("select ao.*, aoc.id cbid, aoc.cb_status from (");
    sb.append("select * from ab_order where qdrid='" + abuser.getStr("id") + "' and ddzt<>'0' ");
    sb.append("AND TIMESTAMPDIFF(HOUR,xdsj,CURRENT_TIMESTAMP) > 1 ");
    sb.append("AND TIMESTAMPDIFF(HOUR,xdsj,CURRENT_TIMESTAMP) < 24 ");
    if (ddzt.length() > 0) {
      sb.append(" and ddzt='" + ddzt + "'");
    }
    if (zfzt.length() > 0) {
      sb.append(" and zfzt='" + zfzt + "'");
    }
    if (sjqrzt.length() > 0) {
      sb.append(" and sjqrzt='" + sjqrzt + "'");
    }
    if (sfjd.length() > 0) {
      sb.append(" and sfjd='" + sfjd + "'");
    }
    sb.append(") ao left join ab_order_chargeback aoc on aoc.order_id = ao.id");
    sb.append(") a where cbid is null");
    sb.append(" order by xdsj desc");
    PageUtil listpage = DbPage.paginate(this.getParaToInt("curPage", 1), 14, sb.toString());
    this.keepPara();
    this.setAttr("listpage", listpage);
    this.render("/ab/mer/listmerordercb.html");
  }
 @Before(AccessAbInterceptor.class)
 public void listorder() {
   SysUser abuser = this.getSessionAttr("abuser");
   String sql =
       "select * from ab_order where xdrid='" + abuser.getStr("id") + "' order by xdsj desc";
   PageUtil listpage = DbPage.paginate(this.getParaToInt("curPage", 1), 14, sql);
   this.setAttr("listpage", listpage);
   this.render("/ab/user/listorder.html");
 }
  /*申请客服介入*/
  public void applycbJudge() {
    SysUser abuser = this.getSessionAttr("abuser");

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str_date = df.format(new Date());

    if (abuser == null || abuser.get("id") == null) {
      redirect("/ab/login");
    } else {
      String cbid = this.getPara("cbid");
      String inputRandomCode = this.getPara("captchaCode");
      String content = this.getPara("content");
      Object objMd5RandomCode = this.getSessionAttr(CaptchaRender.DEFAULT_CAPTCHA_MD5_CODE_KEY);
      // 验证验证码
      if (!CaptchaRender.validate(objMd5RandomCode.toString(), inputRandomCode)) {
        this.renderJson("1");
      }
      // 验证content
      else if (StringUtil.isNull(content) || content.length() > 100) {
        this.renderJson("2");
      } // 更新退单记录
      else {
        AbOrderChargeback cb = AbOrderChargeback.dao.findById(cbid);
        cb.set(AbOrderChargeback.JUDGE_ID, abuser.get(SysUser.ID));
        cb.set(AbOrderChargeback.JUDGE_DESC, content);
        cb.set(AbOrderChargeback.JUDGE_TIME, DateUtil.getCurrentDate());
        cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE5);
        cb.set(AbOrderChargeback.STATUS, CommonStaticData.CB_STATUS2);
        cb.update();

        String userid = abuser.getStr("id");
        String roleid = abuser.getStr("role_id");
        Record record = new Record();
        record.set("id", StringUtil.getUuid32());
        record.set("user_id", userid);
        record.set("role_id", roleid);
        record.set("mes_title", "退单消息");
        record.set("mes_type", "0");
        record.set("isread", "0");
        record.set("text", "您已申请了客服介入!");
        record.set("send_date", str_date);
        Db.save("message", record);

        this.renderJson("0");
      }
    }
  }
 /*用户退单列表*/
 public void listcbforuser() {
   SysUser abuser = this.getSessionAttr("abuser");
   if (abuser == null || abuser.get("id") == null) {
     redirect("/ab/login");
   } else {
     String sn = this.getPara("sn");
     String name = this.getPara("mname");
     String status = this.getPara("status");
     PageUtil listpage =
         DbPage.paginate(
             this.getParaToInt("curPage", 1),
             14,
             CommonSQL.findChargeBackForUser(abuser.getStr(SysUser.ID), sn, name, status));
     this.setAttr("listpage", listpage);
     this.render("/ab/user/listorderchargeback.html");
   }
 }
  /*退单处理显示*/
  public void showcb() {
    SysUser abuser = this.getSessionAttr("abuser");
    if (abuser == null || abuser.get("id") == null) {
      redirect("/ab/login");
    } else {
      String cbid = this.getPara("id");
      List<Record> list = Db.find(CommonSQL.getChargebackById(cbid));
      CommonProcess.createChargebackImageFile(list);

      // 查询补充说明
      List<Record> items = Db.find(CommonSQL.getChargebackItemByCbid(cbid));
      CommonProcess.createImageFile(items);
      this.setAttr("items", items);
      this.setAttr("role", abuser.getStr(SysUser.ROLE_ID));
      this.setAttr("cb", list.get(0));
      this.render("/ab/user/listcbdetail.html");
    }
  }
 public void saveCzResult() {
   Map<String, Object> resultMap = new HashMap<String, Object>();
   String uid = this.getPara("uid");
   String loginid = this.getPara("loginid");
   String mc = this.getPara("mc");
   String czje = this.getPara("czje");
   String czResult = this.getPara("czResult");
   try {
     if (StringUtil.isNull(uid) || StringUtil.isNull(loginid) || StringUtil.isNull(czje)) {
       formatInvalidParamResponse(resultMap);
     } else {
       if ("1".equals(czResult)) {
         SysUser abuser = SysUser.dao.findById(uid);
         if (null != abuser) {
           BigDecimal ud = abuser.getBigDecimal(SysUser.ZHYE);
           double f = Double.parseDouble(czje);
           ud = ud.add(BigDecimal.valueOf(f));
           abuser.set(SysUser.ZHYE, ud);
           abuser.update();
         }
       }
       LogUserDeposit lud = new LogUserDeposit();
       String ludid = StringUtil.getUuid32();
       lud.set("id", ludid);
       lud.set("userid", uid);
       lud.set("loginid", loginid);
       lud.set("mc", mc);
       lud.set("czje", czje);
       // '充值结果[1: -成功、0:  -失败     2: 支付结果确认中]',
       lud.set("status", czResult);
       lud.set("remark", mc + "手机充值" + czje + "元");
       lud.save();
       resultMap.put("result", RESULT_SUCCESS);
       resultMap.put("msg", "操作成功");
     }
   } catch (Exception e) {
     resultMap.put("result", RESULT_FAIL);
     resultMap.put("msg", "系统错误,请稍后重试!");
     e.printStackTrace();
     RestLogUtils.writeToLocal(RestLogUtils.getStackTrace(e), true);
   }
   this.renderJson(resultMap);
 }
 /*用户,商户增加补充证据*/
 public void addcomplement() {
   Map<String, Object> resultMap = new HashMap<String, Object>();
   String userid = this.getPara("uid");
   String orderId = this.getPara("orderid");
   if (StringUtil.isNull(userid) || StringUtil.isNull(orderId)) {
     formatInvalidParamResponse(resultMap);
   } else {
     String cbid = this.getPara("cbid");
     String content = this.getPara("content");
     String img_url = this.getPara("apyimg");
     // 验证验证码
     // 验证content
     SysUser abuser = SysUser.dao.findById(userid);
     AbOrderChargebackItem aoci = new AbOrderChargebackItem();
     aoci.set(AbOrderChargebackItem.ID, StringUtil.getUuid32());
     aoci.set(AbOrderChargebackItem.CBID, cbid);
     aoci.set(AbOrderChargebackItem.UID, userid);
     if (CommonStaticData.USER_TYPE_MEMBER.equals(abuser.get(SysUser.ROLE_ID))) {
       aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_MEMBER);
     } else if (CommonStaticData.USER_TYPE_MERCHANT.equals(abuser.get(SysUser.ROLE_ID))) {
       aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_MERCHANT);
     } else if (CommonStaticData.USER_TYPE_SERVICE.equals(abuser.get(SysUser.ROLE_ID))) {
       aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_SERVICE);
     }
     aoci.set(AbOrderChargebackItem.CONTENT, content);
     aoci.set(AbOrderChargebackItem.DATETIME, DateUtil.getCurrentDate());
     if (img_url != null) {
       FileInputStream file = null;
       try {
         file = new FileInputStream(PathKit.getWebRootPath() + "\\upload\\" + img_url);
       } catch (FileNotFoundException e) {
         e.printStackTrace();
       }
       aoci.set(AbOrderChargebackItem.IMG_URL, img_url);
       aoci.set(AbOrderChargebackItem.IMAGE, file);
     }
     aoci.save();
     resultMap.put("result", RESULT_SUCCESS);
     resultMap.put("msg", "维权成功,请耐心等待调解结果");
   }
   renderJson(resultMap);
 }
  @Before(AccessAbInterceptor.class)
  public void saverz() {
    boolean flag = false;
    SysUser user = this.getModel(SysUser.class, "tb");
    SysUser loginUser = this.getSessionAttr("abuser");
    String name = this.getPara("abFmcar_driver");
    user.set("mc", name);
    user.set("tjsj", DateUtil.getCurrentDate());
    user.set("sfrzzt", "1");
    user.set(SysUser.ID, loginUser.get(SysUser.ID));
    user.update();

    // 保存车辆信息
    AbFmcar car = AbFmcar.dao.findByMobile(getPara("abFmcar_mobile"));
    boolean update = false;
    if (car == null) {
      car = new AbFmcar();
      car.set("id", StringUtil.getRandString32());
      update = false;
    } else update = true;
    car.set("driver", name);
    car.set("car_no", getPara("abFmcar_car_no"));
    car.set("mobile", getPara("abFmcar_mobile"));

    car.set("length", getPara("abFmcar_length"));
    car.set("type", getPara("abFmcar_type"));
    car.set("vv", getPara("abFmcar_vv"));
    if (update) {
      car.update();
    } else car.save();

    // 保存常跑城市
    AbFmcarCity.dao.delByCarId(car.getStr("id"));
    String citynames = getPara("runcity");
    String[] citys = citynames.split(",");
    AbFmcarCity cc = new AbFmcarCity();
    for (String n : citys) {
      cc.set("city_name", n);
      cc.set("car_id", car.get("id"));
      cc.set("id", StringUtil.getRandString32());
      cc.save();
    }
    flag = true;
    renderJson(flag);
  }
  @Before(AccessAbInterceptor.class)
  public void list_order_cxtj() {
    SysUser abuser = this.getSessionAttr("abuser");
    String kssj = StringUtil.toStr(this.getPara("kssj"));
    String jzsj = StringUtil.toStr(this.getPara("jzsj"));
    String ddzt = StringUtil.toStr(this.getPara("ddzt"));
    String queryType = StringUtil.toStr(this.getPara("queryType"));
    //		String lastDate = StringUtil.toStr(this.getPara("lastDate"));
    if (queryType.equals("")) {
      queryType = "dayQuery";
      setAttr("queryType", queryType);
    }

    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -1); // 得到前一天
    Date date = calendar.getTime();
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String str_lastDate = df.format(date);

    String sql =
        "select ao.*,tc.style style,tc.min_price min_price,tc.max_price max_price,tc.pay_type from ab_order ao left join ab_tc_express_order tc on tc.sn=ao.sn where qdrid='"
            + abuser.getStr("id")
            + "' ";
    if ("day".equals(queryType)) {
      // 日报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 00:00:00'";
      sql += " and qdsj<='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 59:59:59'";
    } else if ("week".equals(queryType)) {
      // 周报表
      sql +=
          " and qdsj>='" + DateUtil.format(DateUtil.getMondayOfWeek(), "yyyy-MM-dd") + " 00:00:00'";
      sql +=
          " and qdsj<='" + DateUtil.format(DateUtil.getSundayOfWeek(), "yyyy-MM-dd") + " 59:59:59'";
    } else if ("month".equals(queryType)) {
      // 月报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM") + "-01 00:00:00'";
      sql +=
          " and qdsj<='"
              + DateUtil.format(DateUtil.getLastDayOfMonth(), "yyyy-MM-dd")
              + " 59:59:59'";
    } else if ("dayQuery".equals(queryType)) {
      if (kssj.length() > 0) {
        sql += " and qdsj>='" + kssj + " 00:00:00'";
      }
      if (jzsj.length() > 0) {
        sql += " and qdsj<='" + jzsj + " 59:59:59'";
      }
    } else if ("monthWeekQuery".equals(queryType)) {
      String query_year_begin = getPara("query_year_begin");
      String query_month_begin = getPara("query_month_begin");
      String query_year_end = getPara("query_year_end");
      String query_month_end = getPara("query_month_end");
      sql += " and qdsj>='" + query_year_begin + "-" + query_month_begin + "-01 00:00:00'";
      sql += " and qdsj<='" + query_year_end + "-" + query_month_end + "-31 59:59:59'";
    }
    if (!ddzt.equals("-1") && !ddzt.equals("")) {
      sql += " and ddzt='" + ddzt + "' ";
    }
    sql += "  order by xdsj desc";
    PageUtil listpage = DbPage.paginate(this.getParaToInt("curPage", 1), 14, sql);

    sql =
        "SELECT qdrid,qdrname,COUNT(id) cnt,SUM(ddzje) je,SUBSTR(qdsj,1,10) rq FROM ab_order WHERE qdrid='"
            + abuser.getStr("id")
            + "' ";

    List<Record> listtj = null;
    if ("day".equals(queryType)) {
      // 日报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 00:00:00'";
      sql += " and qdsj<='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 59:59:59'";
    } else if ("week".equals(queryType)) {
      // 周报表
      sql +=
          " and qdsj>='" + DateUtil.format(DateUtil.getMondayOfWeek(), "yyyy-MM-dd") + " 00:00:00'";
      sql +=
          " and qdsj<='" + DateUtil.format(DateUtil.getSundayOfWeek(), "yyyy-MM-dd") + " 59:59:59'";
    } else if ("month".equals(queryType)) {
      // 月报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM") + "-01 00:00:00'";
      sql +=
          " and qdsj<='"
              + DateUtil.format(DateUtil.getLastDayOfMonth(), "yyyy-MM-dd")
              + " 59:59:59'";
    } else if ("dayQuery".equals(queryType)) {
      if (kssj.length() > 0) {
        sql += " and qdsj>='" + kssj + " 00:00:00'";
      }
      if (jzsj.length() > 0) {
        sql += " and qdsj<='" + jzsj + " 59:59:59'";
      }
    } else if ("monthWeekQuery".equals(queryType)) {
      String query_year_begin = getPara("query_year_begin");
      String query_month_begin = getPara("query_month_begin");
      String query_year_end = getPara("query_year_end");
      String query_month_end = getPara("query_month_end");
      sql += " and qdsj>='" + query_year_begin + "-" + query_month_begin + "-01 00:00:00'";
      sql += " and qdsj<='" + query_year_end + "-" + query_month_end + "-31 59:59:59'";
    }
    if (!ddzt.equals("-1") && !ddzt.equals("")) {
      sql += " and ddzt='" + ddzt + "' ";
    }
    sql += "  GROUP BY SUBSTR(qdsj,1,10)";
    listtj = Db.find(sql);

    Record r = null;
    sql =
        "SELECT COUNT(id) totleorder,IFNULL(SUM(ddzje),0) totalmoney FROM ab_order WHERE qdrid='"
            + abuser.getStr("id")
            + "'";
    if ("day".equals(queryType)) {
      // 日报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 00:00:00'";
      sql += " and qdsj<='" + DateUtil.getCurrentDate("yyyy-MM-dd") + " 59:59:59'";
    } else if ("week".equals(queryType)) {
      // 周报表
      sql +=
          " and qdsj>='" + DateUtil.format(DateUtil.getMondayOfWeek(), "yyyy-MM-dd") + " 00:00:00'";
      sql +=
          " and qdsj<='" + DateUtil.format(DateUtil.getSundayOfWeek(), "yyyy-MM-dd") + " 59:59:59'";
    } else if ("month".equals(queryType)) {
      // 月报表
      sql += " and qdsj>='" + DateUtil.getCurrentDate("yyyy-MM") + "-01 00:00:00'";
      sql +=
          " and qdsj<='"
              + DateUtil.format(DateUtil.getLastDayOfMonth(), "yyyy-MM-dd")
              + " 59:59:59'";
    } else if ("dayQuery".equals(queryType)) {
      if (kssj.length() > 0) {
        sql += " and qdsj>='" + kssj + " 00:00:00'";
      }
      if (jzsj.length() > 0) {
        sql += " and qdsj<='" + jzsj + " 59:59:59'";
      }
    } else if ("monthWeekQuery".equals(queryType)) {
      String query_year_begin = getPara("query_year_begin");
      String query_month_begin = getPara("query_month_begin");
      String query_year_end = getPara("query_year_end");
      String query_month_end = getPara("query_month_end");
      sql += " and qdsj>='" + query_year_begin + "-" + query_month_begin + "-01 00:00:00'";
      sql += " and qdsj<='" + query_year_end + "-" + query_month_end + "-31 59:59:59'";
    }
    if (!ddzt.equals("-1")) {
      sql += " and ddzt='" + ddzt + "' ";
    }
    r = Db.findFirst(sql);
    this.keepPara();
    this.setAttr("r", r);
    this.setAttr("listtj", listtj);
    this.setAttr("listpage", listpage);
    this.render("/ab/ywy/list_order_cxtj.html");
  }
 /** 提现数据处理 */
 public void txAction() {
   String uid = this.getPara("uid");
   String WIDtotal_fee = StringUtil.toStr(this.getPara("WIDtotal_fee")); // 提现金额
   String WIDout_trade_no = StringUtil.toStr(this.getPara("WIDout_trade_no")); // 交易流水号
   String zffs = StringUtil.toStr(this.getPara("zzfs")); // 提现方式
   String zfbzh = StringUtil.toStr(this.getPara("zfbzh")); // 支付宝账号
   String yhkid = StringUtil.toStr(this.getPara("yhkid")); // 提现银行卡id
   String yhknum = StringUtil.toStr(this.getPara("yhknum")); // 提现银行卡卡号
   String zfpwd = StringUtil.toStr(this.getPara("zfpwd")); // 支付密码
   SysUser user = SysUser.dao.findById(uid);
   Map<String, Object> result = new HashMap<String, Object>();
   try {
     if (Db.findFirst(
                 "select count(*) ctn from sys_user_zfpwd where userid='"
                     + user.getStr("loginid")
                     + "' and zfpwd='"
                     + zfpwd
                     + "'")
             .getLong("ctn")
         == 0) {
       result.put("msg", "支付密码错误!");
       result.put("result", RESULT_FAIL);
     } else if (user.getBigDecimal("zhye").subtract(new BigDecimal(WIDtotal_fee)).doubleValue()
         < 0) { // 账户余额不足以提现
       result.put("result", RESULT_FAIL);
       result.put("msg", "账户余额不足!");
     } else {
       user.set(
           "zhye",
           user.getBigDecimal("zhye")
               .subtract(new BigDecimal(WIDtotal_fee))); // 现将金额扣除,后期提现失败,提现金额退换
       user.update();
       this.setSessionAttr("abuser", user);
       if ("0".equals(zffs)) { // 支付宝提现
         SysCzTx cztx = new SysCzTx();
         cztx.set("id", StringUtil.getUuid32());
         cztx.set("tradeno", WIDout_trade_no);
         cztx.set("type", 1); // 0-充值 1-提现 2-付款
         cztx.set("result", 0); // 0-等待 1-成功 2-失败
         cztx.set("totalfee", WIDtotal_fee);
         cztx.set("userid", user.getStr("id"));
         cztx.set("mc", user.getStr("mc"));
         cztx.set("time", DateUtil.getCurrentDate());
         cztx.set("zfbaddress", zfbzh);
         cztx.set("txtype", 0); // 提现种类 0-支付宝  1-银行卡
         cztx.save();
       } else { // 银行卡提现
         SysCzTx cztx = new SysCzTx();
         cztx.set("id", StringUtil.getUuid32());
         cztx.set("tradeno", WIDout_trade_no);
         cztx.set("type", 1); // 0-充值 1-提现 2-付款
         cztx.set("result", 0); // 0-等待 1-成功 2-失败
         cztx.set("totalfee", WIDtotal_fee);
         cztx.set("userid", user.getStr("id"));
         cztx.set("mc", user.getStr("mc"));
         cztx.set("txtype", 1); // 提现种类 0-支付宝  1-银行卡
         cztx.set("txyhkid", yhkid);
         cztx.set("txyhknum", yhknum);
         cztx.set("time", DateUtil.getCurrentDate());
         cztx.save();
       }
       result.put("msg", "提现申请已经提交,约7个工作日内到账,请您耐心等待!");
       result.put("result", RESULT_SUCCESS);
     }
   } catch (Exception e) {
     result.put("result", RESULT_FAIL);
     result.put("msg", "系统错误,请稍后重试!");
     e.printStackTrace();
     RestLogUtils.writeToLocal(RestLogUtils.getStackTrace(e), true);
   }
   this.renderJson(result);
 }
  /**
   * 用户申请退单 参数 userid 用户ID orderid 订单ID content 描述 apyimg 图片路径
   *
   * <p>返回值 true or false
   */
  public void addchargeback() {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    String userid = this.getPara("uid");
    String orderId = this.getPara("orderid");
    String content = this.getPara("content");
    String img_url = this.getPara("apyimg");
    if (StringUtil.isNull(userid) || StringUtil.isNull(orderId) || StringUtil.isNull(content)) {
      formatInvalidParamResponse(resultMap);
    } else {
      // 插入退单记录
      SysUser abuser = SysUser.dao.findById(userid);
      AbOrder order = AbOrder.dao.findFirst("SELECT * FROM ab_order WHERE sn='" + orderId + "' ");
      if (order == null) {
        order = AbOrder.dao.findFirst("SELECT * FROM ab_order WHERE id='" + orderId + "' ");
      }
      if (null == abuser || null == order) {
        resultMap.put("result", RESULT_FAIL);
        resultMap.put("msg", "数据异常,请稍后重试!");

      } else {
        AbOrderChargeback cb = null;
        cb =
            AbOrderChargeback.dao.findFirst(
                "select * from ab_order_chargeback where order_id = '" + orderId + "'");
        boolean flag = false;
        if (cb == null) {
          cb = new AbOrderChargeback();
          cb.set(AbOrderChargeback.ID, StringUtil.getUuid32());
          flag = true;
        }

        cb.set(AbOrderChargeback.ID, StringUtil.getUuid32());
        cb.set(AbOrderChargeback.MER_ID, order.getStr(AbOrder.MID));
        cb.set(AbOrderChargeback.XDR_ID, order.getStr(AbOrder.XDRID));
        cb.set(AbOrderChargeback.QDR_ID, order.getStr(AbOrder.QDRID));
        cb.set(AbOrderChargeback.ORDER_ID, orderId);
        cb.set(AbOrderChargeback.APPLY_ID, abuser.get(SysUser.ID));
        cb.set(AbOrderChargeback.APPLY_DESC, content);
        cb.set(AbOrderChargeback.APPLY_TIME, DateUtil.getCurrentDate());
        cb.set(AbOrderChargeback.STATUS, CommonStaticData.CB_STATUS1);
        // 申请人类型 1 用户 2商户 3业务员
        if (CommonStaticData.USER_TYPE_MEMBER.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE1);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_MEMBER);
        } else if (CommonStaticData.USER_TYPE_MERCHANT.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE2);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_MERCHANT);
        } else if (CommonStaticData.USER_TYPE_SERVICE.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE8);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_SERVICE);
        }
        if (!StringUtil.isNull(img_url)) {
          FileInputStream file = null;
          try {
            file = new FileInputStream(PathKit.getWebRootPath() + "\\upload\\" + img_url);
          } catch (FileNotFoundException e) {
            e.printStackTrace();
          }
          cb.set(AbOrderChargeback.APPLY_IMG_URL, img_url);
          cb.set(AbOrderChargeback.APPLY_IMG, file);
        }
        if (flag) {
          cb.update();
        } else {
          cb.save();
        }
        resultMap.put("result", RESULT_SUCCESS);
        resultMap.put("msg", "维权成功,请耐心等待调解结果");
      }
    }
    renderJson(resultMap);
  }
  /** 申请退单 */
  public void addchargeback() {
    SysUser abuser = this.getSessionAttr("abuser");
    if (abuser == null || abuser.get("id") == null) {
      redirect("/ab/login");
    } else {
      String inputRandomCode = this.getPara("backCaptchaCode");
      String orderId = this.getPara("orderid");
      String content = this.getPara("applyBackContent");
      String img_url = this.getPara("apyimg");
      Object objMd5RandomCode = this.getSessionAttr(CaptchaRender.DEFAULT_CAPTCHA_MD5_CODE_KEY);
      // 验证验证码
      if (!CaptchaRender.validate(objMd5RandomCode.toString(), inputRandomCode)) {
        this.renderJson("1");
      }
      // 验证content
      else if (StringUtil.isNull(content) || content.length() > 100) {
        this.renderJson("2");
      }
      // 判断是否已经申请退单
      else if (AbOrderChargeback.dao.findFirst(
              "select * from ab_order_chargeback where order_id = '" + orderId + "'")
          != null) {
        this.renderJson("3");
      }
      // 插入退单记录
      else {
        abuser = SysUser.dao.findById(abuser.get("id"));
        AbOrder order = AbOrder.dao.findById(orderId);
        AbOrderChargeback cb = new AbOrderChargeback();
        cb.set(AbOrderChargeback.ID, StringUtil.getUuid32());
        cb.set(AbOrderChargeback.MER_ID, order.getStr(AbOrder.MID));
        cb.set(AbOrderChargeback.XDR_ID, order.getStr(AbOrder.XDRID));
        cb.set(AbOrderChargeback.QDR_ID, order.getStr(AbOrder.QDRID));
        cb.set(AbOrderChargeback.ORDER_ID, orderId);
        cb.set(AbOrderChargeback.APPLY_ID, abuser.get(SysUser.ID));
        cb.set(AbOrderChargeback.APPLY_DESC, content);
        cb.set(AbOrderChargeback.APPLY_TIME, DateUtil.getCurrentDate());
        cb.set(AbOrderChargeback.STATUS, CommonStaticData.CB_STATUS1);
        //				申请人类型 1 用户 2商户 3业务员
        if (CommonStaticData.USER_TYPE_MEMBER.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE1);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_MEMBER);
        } else if (CommonStaticData.USER_TYPE_MERCHANT.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE2);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_MERCHANT);
        } else if (CommonStaticData.USER_TYPE_SERVICE.equals(abuser.get(SysUser.ROLE_ID))) {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE8);
          cb.set(AbOrderChargeback.APPLY_TYPE, CommonStaticData.CB_APPLYTYPE_SERVICE);
        }
        if (!StringUtil.isNull(img_url)) {
          FileInputStream file = null;
          try {
            file = new FileInputStream(PathKit.getWebRootPath() + "\\upload\\" + img_url);
          } catch (FileNotFoundException e) {
            e.printStackTrace();
          }
          cb.set(AbOrderChargeback.APPLY_IMG_URL, img_url);
          cb.set(AbOrderChargeback.APPLY_IMG, file);
        }
        cb.save();

        String sn = order.getStr("sn");
        String userid = abuser.getStr("id");
        String roleid = abuser.getStr("role_id");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str_date = df.format(new Date());
        Record record = new Record();
        record.set("id", StringUtil.getUuid32());
        record.set("user_id", userid);
        record.set("role_id", roleid);
        record.set("mes_title", "退单消息");
        record.set("mes_type", "0");
        record.set("isread", "0");
        record.set("text", "申请退单成功!订单号:" + sn);
        record.set("send_date", str_date);
        Db.save("message", record);

        this.renderJson("0");
      }
    }
  }
  /*商户回复 1同意退单,2申诉*/
  public void addcbReponse() {
    SysUser abuser = this.getSessionAttr("abuser");
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str_date = df.format(new Date());
    if (abuser == null || abuser.get("id") == null) {
      redirect("/ab/login");
    } else {
      String cbid = this.getPara("cbid");
      String agree = this.getPara("agree");
      String inputRandomCode = this.getPara("captchaCode");
      String content = this.getPara("content");
      Object objMd5RandomCode = this.getSessionAttr(CaptchaRender.DEFAULT_CAPTCHA_MD5_CODE_KEY);
      // 验证验证码
      if (!CaptchaRender.validate(objMd5RandomCode.toString(), inputRandomCode)) {
        this.renderJson("1");
      }
      // 验证content
      else if (StringUtil.isNull(content) || content.length() > 100) {
        this.renderJson("2");
      } // 更新退单记录
      else {
        AbOrderChargeback cb = AbOrderChargeback.dao.findById(cbid);
        cb.set(AbOrderChargeback.REP_DESC, content);
        cb.set(AbOrderChargeback.REP_TIME, DateUtil.getCurrentDate());
        SysUser mer = SysUser.dao.findById(abuser.getStr(SysUser.ID));
        SysUser user = SysUser.dao.findById(cb.getStr(AbOrderChargeback.XDR_ID));
        // 同意
        if (agree.equals("1")) {
          // 更新退单状态
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE6);
          cb.set(AbOrderChargeback.STATUS, CommonStaticData.CB_STATUS3);
          // 金额
          AbOrder order = AbOrder.dao.findById(cb.getStr(AbOrderChargeback.ORDER_ID));
          BigDecimal money = order.getBigDecimal(AbOrder.DDZJE);
          // 更新订单状态
          order.set(AbOrder.DDZT, "5");
          order.update();
          // 商户余额金额减少

          BigDecimal merye = mer.getBigDecimal(SysUser.ZHYE);
          mer.set(SysUser.ZHYE, merye.subtract(money));
          mer.update();
          // 用户余额增加

          BigDecimal userye = mer.getBigDecimal(SysUser.ZHYE);
          user.set(SysUser.ZHYE, userye.add(money));
          // 判断是否已经支付,如果已经支付,则扣除积分
          if ("1".equals(order.getStr(AbOrder.ZFZT))) {
            int jf = user.getInt(SysUser.JIFEN);
            int mjf = money.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
            user.set(SysUser.JIFEN, jf - mjf);
          }
          user.update();

          String sn = order.getStr("sn");
          String userid = user.getStr("id");
          String roleid = user.getStr("role_id");
          Record record = new Record();
          record.set("id", StringUtil.getUuid32());
          record.set("user_id", userid);
          record.set("role_id", roleid);
          record.set("mes_title", "退单消息");
          record.set("mes_type", "0");
          record.set("isread", "0");
          record.set("text", "商户同意退单!订单号:" + sn);
          record.set("send_date", str_date);
          Db.save("message", record);

        } else {
          cb.set(AbOrderChargeback.CB_STATUS, CommonStaticData.CB_TYPE3);

          String userid = user.getStr("id");
          String roleid = user.getStr("role_id");
          Record record = new Record();
          record.set("id", StringUtil.getUuid32());
          record.set("user_id", userid);
          record.set("role_id", roleid);
          record.set("mes_title", "退单消息");
          record.set("mes_type", "0");
          record.set("isread", "0");
          record.set("text", "商户已提起申诉!");
          record.set("send_date", str_date);
          Db.save("message", record);
        }
        cb.update();
        this.renderJson("0");
      }
    }
  }
  /*用户,商户增加补充证据*/
  public void addcomplement() {
    SysUser abuser = this.getSessionAttr("abuser");
    if (abuser == null || abuser.get("id") == null) {
      redirect("/ab/login");
    } else {
      String cbid = this.getPara("cbid");
      String inputRandomCode = this.getPara("comCaptchaCode");
      String content = this.getPara("comContent");
      String img_url = this.getPara("apyimg");
      Object objMd5RandomCode = this.getSessionAttr(CaptchaRender.DEFAULT_CAPTCHA_MD5_CODE_KEY);
      // 验证验证码
      if (!CaptchaRender.validate(objMd5RandomCode.toString(), inputRandomCode)) {
        this.renderJson("1");
      }
      // 验证content
      else if (StringUtil.isNull(content) || content.length() > 100) {
        this.renderJson("2");
      } // 插入退单补充记录
      else {
        abuser = SysUser.dao.findById(abuser.get("id"));
        AbOrderChargebackItem aoci = new AbOrderChargebackItem();
        aoci.set(AbOrderChargebackItem.ID, StringUtil.getUuid32());
        aoci.set(AbOrderChargebackItem.CBID, cbid);
        aoci.set(AbOrderChargebackItem.UID, abuser.getStr(SysUser.ID));
        if (CommonStaticData.USER_TYPE_MEMBER.equals(abuser.get(SysUser.ROLE_ID))) {
          aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_MEMBER);
        } else if (CommonStaticData.USER_TYPE_MERCHANT.equals(abuser.get(SysUser.ROLE_ID))) {
          aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_MERCHANT);
        } else if (CommonStaticData.USER_TYPE_SERVICE.equals(abuser.get(SysUser.ROLE_ID))) {
          aoci.set(AbOrderChargebackItem.TYPE, CommonStaticData.CB_APPLYTYPE_SERVICE);
        }
        aoci.set(AbOrderChargebackItem.CONTENT, content);
        aoci.set(AbOrderChargebackItem.DATETIME, DateUtil.getCurrentDate());
        if (img_url != null) {
          FileInputStream file = null;
          try {
            file = new FileInputStream(PathKit.getWebRootPath() + "\\upload\\" + img_url);
          } catch (FileNotFoundException e) {
            e.printStackTrace();
          }
          aoci.set(AbOrderChargebackItem.IMG_URL, img_url);
          aoci.set(AbOrderChargebackItem.IMAGE, file);
        }
        aoci.save();

        String userid = abuser.getStr("id");
        String roleid = abuser.getStr("role_id");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str_date = df.format(new Date());
        Record record = new Record();
        record.set("id", StringUtil.getUuid32());
        record.set("user_id", userid);
        record.set("role_id", roleid);
        record.set("mes_title", "退单消息");
        record.set("mes_type", "0");
        record.set("isread", "0");
        record.set("text", "证据已补充!");
        record.set("send_date", str_date);
        Db.save("message", record);

        this.renderJson("0");
      }
    }
  }