public PageResult endWechatOrder(String orderNo, String ip, PageResult result, String openid) { String hql = "from BabysitterOrder t where t.orderId = ?"; BabysitterOrder order = dao.getSingleResultByHQL(BabysitterOrder.class, hql, orderNo); if (order == null) { result.setResult(ResultInfo.BABYSITTER_ORDER_NULL); return result; } if (order.getState() != Constants.EARNEST_MONEY) { result.setResult(ResultInfo.INVALID_ORDER); return result; } BigDecimal orderPrice = new BigDecimal(order.getOrderPrice()); orderPrice = orderPrice.add(new BigDecimal(0 - order.getOrderFrontPrice())); orderPrice = orderPrice.multiply(new BigDecimal(100)); Map<String, String> params = RequestXMLCreater.getInstance() .getPayRequestMap( order.getGuid(), "月嫂尾款", order.getOrderId() + BabysitterOrderService.END, orderPrice.toString(), ip, openid); String xml = RequestXMLCreater.getInstance() .buildXmlString(params, Constants.WECHAT_OPENID_PAY_APPSECRET); System.out.println("======================>" + xml); sendPaymentToWeChatServer(result, order, xml); return result; }
@Transactional public PageResult addMakeBabysitterOrder( String date, String address, String name, String mobile, String checkCode, String openid, String countyGuid, String babysitterGuid, PageResult result) { Babysitter babysitter = dao.getResultByGUID(Babysitter.class, babysitterGuid); if (babysitter == null) { result.setResult(ResultInfo.BABYSITTER_NULL); return result; } ServiceOrder order = addEmployerServiceOrder( date, babysitter.getLevel().getGuid(), countyGuid, address, name, mobile, checkCode, openid); if (order == null) { result.setResult(ResultInfo.COUNTY_LEVEL_NULL); return result; } result = markBabysitter(babysitterGuid, order.getGuid(), result); return result; }
public PageResult payFrontMoney(String orderNo, String ip, PageResult result, String openid) { String hql = "from BabysitterOrder t where t.orderId = ?"; BabysitterOrder order = dao.getSingleResultByHQL(BabysitterOrder.class, hql, orderNo); if (order == null) { result.setResult(ResultInfo.BABYSITTER_ORDER_NULL); return result; } if (order.getState() != Constants.NEW_ORDER) { result.setResult(ResultInfo.INVALID_ORDER); return result; } Map<String, String> params = RequestXMLCreater.getInstance() .getPayRequestMap( order.getGuid(), "月嫂定金", order.getOrderId() + BabysitterOrderService.FRONT, String.valueOf(order.getOrderFrontPrice() * 100), ip, openid); String xml = RequestXMLCreater.getInstance() .buildXmlString(params, Constants.WECHAT_OPENID_PAY_APPSECRET); System.out.println("======================>" + xml); sendPaymentToWeChatServer(result, order, xml); return result; }
public PageResult orderHistoryRecord(String orderGuid, PageResult result) { BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid); if (order == null) { result.setResult(ResultInfo.BABYSITTER_ORDER_NULL); return result; } result.setResult(ResultInfo.SUCCESS); result.put("result", order.getInfos()); return result; }
/** 雇主添加订单,需要根据订单的开始结束时间、订单所属地区查找符合要求的月嫂添加到需要通知的月嫂的数据表中 */ @Transactional public PageResult wechatAddServiceOrder( String date, String countyLevelGuid, String countyGuid, String address, String name, String mobile, String checkCode, String openid, PageResult result, String isNotAdvice) { try { // boolean flag = codeService.updateCheckCode(mobile, checkCode, // CheckCodeService.PUBLISH_ORDER); // if (!flag) { // throw new CheckErrorException(); // } // 添加雇主订单 ServiceOrder order = addEmployerServiceOrder( date, countyLevelGuid, countyGuid, address, name, mobile, checkCode, openid); if (order == null) { result.setResult(ResultInfo.COUNTY_LEVEL_NULL); return result; } Map<String, Date> expectedDate = ExpectedDateCreate.getExpectedDate(date); if (StringUtils.isEmpty(isNotAdvice)) { addBabysitterAdvice(countyGuid, order, expectedDate); } result.setResult(ResultInfo.SUCCESS); result.put("result", order.view()); // 短信通知客户经理 String telephone = Constants.MSG_TEMPLATE_ADVICE_PHONE; String telephones[] = telephone.split(","); for (String phone : telephones) { CheckCodeUtil.sendMessage( phone, Constants.MSG_TEMPLATE_ADVICE, ExpectedDateCreate.formatDateTime(new Date()), String.valueOf(order.getId())); } return result; } catch (CheckErrorException e) { result.setResult(ResultInfo.CHECK_CODE_ERROR); return result; } catch (Exception e) { e.printStackTrace(); } result.setResult(ResultInfo.BAD_REQUEST); return result; }
@Transactional public PageResult serviceEnd(String orderGuid, PageResult result) { BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid); if (order == null) { result.setResult(ResultInfo.BABYSITTER_ORDER_NULL); return result; } order.setState(Constants.OUT_ORDER); // 设置订单日志 BabysitterOrderRecordInfo info = BabysitterOrderRecordInfo.getInstance(); info.setBabysitterOrder(order); info.setState(order.getState()); dao.add(info); result.setResult(ResultInfo.SUCCESS); return result; }
public PageResult getBabysitterOrderInfo(String serviceOrderGuid, PageResult result) { ServiceOrder serviceOrder = dao.getResultByGUID(ServiceOrder.class, serviceOrderGuid); if (serviceOrder == null) { result.setResult(ResultInfo.SERVICE_ORDER_NULL); return result; } if (StringUtils.isEmpty(serviceOrder.getOrderGuid())) { result.setResult(ResultInfo.NO_BABYSITTER_SERVICE_ORDER); return result; } String orderGuid = serviceOrder.getOrderGuid(); BabysitterOrder order = dao.getResultByGUID(BabysitterOrder.class, orderGuid); result.setResult(ResultInfo.SUCCESS); result.put("result", order.view()); return result; }
@Transactional public PageResult markBabysitter(String babysitterGuid, String orderGuid, PageResult result) { Babysitter babysitter = dao.getResultByGUID(Babysitter.class, babysitterGuid); ServiceOrder serviceOrder = dao.getResultByGUID(ServiceOrder.class, orderGuid); BabysitterOrder order = updateBabysitterOrder(orderGuid, babysitter, serviceOrder); result.setResult(ResultInfo.SUCCESS); result.put("result", order.view()); return result; }
public PageResult orderList(String mobile, String openid, PageResult result) { Employer employer = null; List<ServiceOrderView> view = new ArrayList<ServiceOrderView>(); if (StringUtils.isEmpty(openid)) { String mobileHql = "from Employer t where t.ovld = true and t.mobilePhone = ?"; employer = dao.getSingleResultByHQL(Employer.class, mobileHql, mobile); } else { String openidHql = "from Employer t where t.ovld = true and t.openid = ?"; List<Employer> listEmployers = dao.getListResultByHQL(Employer.class, openidHql, openid); if (listEmployers == null || listEmployers.size() == 0) { result.setResult(ResultInfo.SUCCESS); result.put("result", view); return result; } if (listEmployers.size() > 1) { result.setResult(ResultInfo.MULTI_EMPLYER); List<EmployerView> listViews = new ArrayList<EmployerView>(); for (Employer e : listEmployers) { listViews.add(e.view()); } result.put("result", listViews); return result; } else { employer = listEmployers.get(0); } } if (employer == null) { result.setResult(ResultInfo.SUCCESS); result.put("result", view); return result; } String hql = "from ServiceOrder t where t.ovld = true and t.employer.id=?"; List<ServiceOrder> orders = dao.getListResultByHQL(ServiceOrder.class, hql, employer.getId()); if (orders == null) orders = new ArrayList<ServiceOrder>(); for (ServiceOrder order : orders) { view.add(order.view()); } result.setResult(ResultInfo.SUCCESS); result.put("result", view); return result; }
@Transactional public PageResult markBabysitterId( String babysitterId, String serviceOrderId, PageResult result) { long babysitterIdl = Long.valueOf(babysitterId); long serviceOrderIdl = Long.valueOf(serviceOrderId); Babysitter babysitter = dao.getResultById(Babysitter.class, babysitterIdl); ServiceOrder serviceOrder = dao.getResultById(ServiceOrder.class, serviceOrderIdl); updateBabysitterOrder(serviceOrder.getGuid(), babysitter, serviceOrder); result.setResult(ResultInfo.SUCCESS); result.put("result", babysitter.view()); return result; }
@SuppressWarnings("resource") private void sendPaymentToWeChatServer(PageResult result, BabysitterOrder order, String xml) { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(Constants.WECHAT_OPENID_PAY_URL); StringEntity myEntity = new StringEntity(xml, "UTF-8"); httppost.addHeader("Content-Type", "text/xml"); httppost.setEntity(myEntity); try { HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); InputStreamReader reader = new InputStreamReader(resEntity.getContent(), "UTF-8"); StringBuffer resultStr = new StringBuffer(); char[] buff = new char[1024]; int length = 0; while ((length = reader.read(buff)) != -1) { resultStr.append(new String(buff, 0, length)); } System.out.println(resultStr.toString()); httpclient.getConnectionManager().shutdown(); Map<String, String> responseResult = RequestXMLCreater.getInstance().getXmlMapResult(resultStr.toString()); Map<String, String> resultMap; if (Constants.PAY_SUCCESS.equals(responseResult.get("return_code")) && Constants.PAY_MESSAGE_OK.equals(responseResult.get("return_msg")) && Constants.PAY_SUCCESS.equals(responseResult.get("result_code"))) { resultMap = RequestXMLCreater.getInstance() .getPayResponseMap(responseResult.get("prepay_id"), order.getGuid()); result.setResult(ResultInfo.SUCCESS); result.put("result", resultMap); } else { result.put("code", responseResult.get("err_code")); result.put("msg", responseResult.get("err_code_des")); } } catch (Exception e) { e.printStackTrace(); } }