Пример #1
0
  /**
   * 保存节假日信息和对应的交易时间 事物处理
   *
   * @param message
   * @param date
   * @return
   */
  @Before(Tx.class)
  public void saveHolidayTime() {
    TradeTime tradeTime =
        new TradeTime()
            .set("id", "20160101")
            .set("startTime", "00:01:02")
            .set("endTime", "16:00:00");

    Db.save("tradeTime", tradeTime.toRecord());
    log.info("save:" + tradeTime.toJson());
    HolidayList holidayList = new HolidayList();
    Db.save("", holidayList.toRecord());
    log.info("save:" + holidayList.toJson());
    return;
  }
Пример #2
0
  public Record init(String username) {

    Record user = Db.findFirst("SELECT * FROM b_users WHERE username = ? AND status = 0");
    if (user == null) {
      // user初始化
      user = new Record();
      user.set("username", username).set("mobile", username).set("status", 0);
      Db.save("b_user", user);
    }
    return user;
  }
  /*申请客服介入*/
  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");
      }
    }
  }
Пример #4
0
 public static JSONObject login(String username, String validateNum, String deviceId) {
   JSONObject items = new JSONObject();
   boolean rs = false;
   if (!username.equals("") && !validateNum.equals("") && !deviceId.equals("")) {
     // status 0=初始化 1=正常
     Record user =
         Db.findFirst(
             "SELECT bu.*,fur.content AS roleValue,fus.content AS sexValue FROM b_user AS bu LEFT JOIN f_user_role AS fur ON bu.role = fur.id LEFT JOIN f_user_sex AS fus ON bu.sex = fus.id WHERE bu.username = ? AND bu.validateNum = ? AND bu.status < 2",
             username,
             validateNum);
     Long nowTime = System.currentTimeMillis();
     // validate时会初始化b_user 这里null 一定有误
     if (user != null) {
       if ((nowTime - user.getTimestamp("validateTime").getTime()) < 300000) {
         Db.update(
             "UPDATE b_user SET validateNum = ? , status = 1 WHERE username = ?",
             "----",
             user.getStr("username"));
         items.put("user", user.toJson());
         String agentToken = Token.add(username, deviceId);
         items.put("agentToken", agentToken);
         Record auth =
             Db.findFirst(
                 "SELECT * FROM b_auth WHERE username = ? AND role = ?",
                 username,
                 user.getInt("role"));
         if (auth != null) {
           items.put("auth", auth.toJson());
         } else {
           auth = new Record();
           auth.set("username", username).set("role", user.getInt("role")).set("status", 0);
           boolean authRs = Db.save("b_auth", auth);
           if (authRs) {
             items.put("auth", auth.toJson());
           }
         }
         rs = true;
       }
     }
   }
   items.put("rs", rs);
   return items;
 }
Пример #5
0
  /**
   * 客户端向服务器验证
   *
   * <p>* checkState A 验证成功有效(返回收据) B 账单有效,但己经验证过 C 服务器数据库中没有此账单(无效账单) D 不处理
   *
   * @return
   * @throws IOException
   */
  public void search() throws IOException {

    Fetcher f = this.fetch();
    logger.debug("search,params={}", f.getParameterMap());
    //		String signature = f.s("signature");
    //		String purchase_info = f.s("purchase-info");
    //		String environment = f.s("environment");
    //		String pod = f.s("pod");
    //		String signing_status = f.s("signing-status");
    //		Map<String,Object> receive=new HashMap<String,Object>();
    //		receive.put("signature", signature);
    //		receive.put("purchase-info", purchase_info);
    //		receive.put("environment", environment);
    //		receive.put("pod", pod);
    //		receive.put("signing-status", signing_status);
    //        //String receipt=JsonUtil.toJson(receive);
    //		String receipt = String.format(Locale.CHINA,"{\"signature\"=\"" + signature +
    // "\";\"purchase-info\"=\"" + purchase_info +  "\";\"environment\"=\"" + environment +
    // "\";\"pod\"=\"" + pod + "\";\"signing-status\"=\"" + signing_status + "\"}");
    //		System.out.println("receipt "+receipt);
    String receipt = f.s("content");
    System.out.println("receipt " + receipt);
    String environment = f.s("environment");
    // 拿到收据的MD5
    // String md5_receipt=MD5.md5Digest(receipt);

    String md5_receipt = Md5Util.digest(receipt);
    // 默认是无效账单
    String result = STATE_C + "#" + md5_receipt;
    // 查询数据库,看是否是己经验证过的账号
    boolean isExists = false;
    String sql = "select receipt_id,receipt from ocr_ios_purchase where receipt=?";
    if (Db.find(sql, md5_receipt) != null) {
      isExists = true;
    }
    String verifyResult = null;
    if (!isExists) {
      verifyResult = IOS_Verify.buyAppVerify(receipt, environment);
      System.out.println("verifyResult:" + verifyResult);
      if (verifyResult == null) {
        // 苹果服务器没有返回验证结果
        result = STATE_D + "#" + md5_receipt;
      } else {
        // 跟苹果验证有返回结果------------------
        Map<String, Object> data = JsonUtil.fromJsonToMap(verifyResult);
        Set keys = data.keySet();
        if (keys != null) {
          Iterator iterator = keys.iterator();
          while (iterator.hasNext()) {
            Object key = iterator.next();
            Object value = data.get(key);
            System.out.println(key.toString() + "   " + value.toString());
          }
        }
        Object states = data.get("status");
        String sta = states.toString();
        if (sta.equals("0") || sta.equals("0.0")) // 验证成功
        {
          Map<String, Object> r_receipt = (Map<String, Object>) data.get("receipt");

          // 产品ID
          String product_id = (String) r_receipt.get("product_id");
          // 数量
          String quantity = (String) r_receipt.get("quantity");
          // 跟苹果的服务器验证成功
          result = STATE_A + "#" + md5_receipt + "_" + product_id + "_" + quantity;
          // 交易日期
          String purchase_date = (String) data.get("purchase_date");
          // 保存到数据库
          Record user = new Record().set("receipt", md5_receipt); // .set("age", 25);
          Db.save("ocr_ios_purchase", user);
          // user.get("id");
        } else {
          // 账单无效
          result = STATE_C + "#" + md5_receipt;
        }
        // 跟苹果验证有返回结果------------------
      }
      // 传上来的收据有购买信息==end=============
    } else {
      // 账单有效,但己验证过
      result = STATE_B + "#" + md5_receipt;
    }
    // 返回结果
    try {
      System.out.println("验证结果     " + result);
      System.out.println();
      // response.getWriter().write(result);
      Map<String, Object> data = new LinkedHashMap<String, Object>();
      data.put("content", result);
      this.renderData(data);
    } catch (Throwable e) {
      logger.error("ios purchase", e);
      this.renderData(e);
    }
  }
  /** 申请退单 */
  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");
      }
    }
  }