giftcertificateservices.java
来自「Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电」· Java 代码 · 共 1,365 行 · 第 1/5 页
JAVA
1,365 行
// set the bcc address(s) String bcc = productStoreEmail.getString("bccAddress"); if (copyMe) { if (UtilValidate.isNotEmpty(bcc)) { bcc = bcc + "," + orderEmails; } else { bcc = orderEmails; } } Map emailCtx = new HashMap(); String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation"); if (UtilValidate.isEmpty(bodyScreenLocation)) { bodyScreenLocation = ProductStoreWorker.getDefaultProductStoreEmailScreenLocation(emailType); } emailCtx.put("bodyScreenUri", bodyScreenLocation); emailCtx.put("bodyParameters", answerMap); emailCtx.put("sendTo", sendToEmail); emailCtx.put("contentType", productStoreEmail.get("contentType")); emailCtx.put("sendFrom", productStoreEmail.get("fromAddress")); emailCtx.put("sendCc", productStoreEmail.get("ccAddress")); emailCtx.put("sendBcc", bcc); emailCtx.put("subject", productStoreEmail.getString("subject")); emailCtx.put("userLogin", userLogin); // send off the email async so we will retry on failed attempts // SC 20060405: Changed to runSync because runAsync kept getting an error: // Problem serializing service attributes (Cannot serialize object of class java.util.PropertyResourceBundle) try { dispatcher.runSync("sendMailFromScreen", emailCtx); } catch (GenericServiceException e) { Debug.logError(e, "Problem sending mail", module); // this is fatal; we will rollback and try again later return ServiceUtil.returnError("Error sending Gift Card notice email: " + e.toString()); } } } return ServiceUtil.returnSuccess(); } public static Map giftCertificateReload(DispatchContext dctx, Map context) { // this service should always be called via FULFILLMENT_EXTSYNC LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); GenericValue orderItem = (GenericValue) context.get("orderItem"); Locale locale = (Locale) context.get("locale"); // order ID for tracking String orderId = orderItem.getString("orderId"); // the order header for store info GenericValue orderHeader = null; try { orderHeader = orderItem.getRelatedOne("OrderHeader"); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get OrderHeader from OrderItem",module); return ServiceUtil.returnError("Unable to get OrderHeader from OrderItem"); } // get the order read helper OrderReadHelper orh = new OrderReadHelper(orderHeader); // get the currency String currency = orh.getCurrency(); // make sure we have a currency if (currency == null) { currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD"); } // get the product store String productStoreId = null; if (orderHeader != null) { productStoreId = orh.getProductStoreId(); } if (productStoreId == null) { return ServiceUtil.returnError("Unable to process gift card reload; no productStoreId on OrderHeader : " + orderId); } // payment config GenericValue paymentSetting = ProductStoreWorker.getProductStorePaymentSetting(delegator, productStoreId, "GIFT_CARD", null, true); String paymentConfig = null; if (paymentSetting != null) { paymentConfig = paymentSetting.getString("paymentPropertiesPath"); } if (paymentConfig == null) { return ServiceUtil.returnError("Unable to get payment configuration file"); } // party ID for tracking GenericValue placingParty = orh.getPlacingParty(); String partyId = null; if (placingParty != null) { partyId = placingParty.getString("partyId"); } // amount of the gift card reload Double amount = orderItem.getDouble("unitPrice"); // survey information String surveyId = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.surveyId"); // get the survey response GenericValue surveyResponse = null; try { Map fields = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "surveyId", surveyId); List order = UtilMisc.toList("-responseDate"); List responses = delegator.findByAnd("SurveyResponse", fields, order); // there should be only one surveyResponse = EntityUtil.getFirst(responses); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to get survey response information; cannot fulfill gift card reload"); } // get the response answers List responseAnswers = null; try { responseAnswers = surveyResponse.getRelated("SurveyResponseAnswer"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to get survey response answers from survey response; cannot fulfill gift card reload"); } // make a map of answer info Map answerMap = new HashMap(); if (responseAnswers != null) { Iterator rai = responseAnswers.iterator(); while (rai.hasNext()) { GenericValue answer = (GenericValue) rai.next(); GenericValue question = null; try { question = answer.getRelatedOne("SurveyQuestion"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to get survey question from answer"); } if (question != null) { String desc = question.getString("description"); String ans = answer.getString("textResponse"); // only support text response types for now answerMap.put(desc, ans); } } } String cardNumberKey = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.survey.cardNumber"); String pinNumberKey = UtilProperties.getPropertyValue(paymentConfig, "payment.giftcert.reload.survey.pinNumber"); String cardNumber = (String) answerMap.get(cardNumberKey); String pinNumber = (String) answerMap.get(pinNumberKey); // reload the gift card Map reloadCtx = new HashMap(); reloadCtx.put("productStoreId", productStoreId); reloadCtx.put("currency", currency); reloadCtx.put("partyId", partyId); //reloadCtx.put("orderId", orderId); reloadCtx.put("cardNumber", cardNumber); reloadCtx.put("pinNumber", pinNumber); reloadCtx.put("amount", amount); reloadCtx.put("userLogin", userLogin); String errorMessage = null; Map reloadGcResult = null; try { reloadGcResult = dispatcher.runSync("addFundsToGiftCertificate", reloadCtx); } catch (GenericServiceException e) { Debug.logError(e, module); errorMessage = "Unable to call reload service!"; } if (ServiceUtil.isError(reloadGcResult)) { errorMessage = ServiceUtil.getErrorMessage(reloadGcResult); } // create the fulfillment record Map gcFulFill = new HashMap(); gcFulFill.put("typeEnumId", "GC_RELOAD"); gcFulFill.put("userLogin", userLogin); gcFulFill.put("partyId", partyId); gcFulFill.put("orderId", orderId); gcFulFill.put("orderItemSeqId", orderItem.get("orderItemSeqId")); gcFulFill.put("surveyResponseId", surveyResponse.get("surveyResponseId")); gcFulFill.put("cardNumber", cardNumber); gcFulFill.put("pinNumber", pinNumber); gcFulFill.put("amount", amount); if (reloadGcResult != null) { gcFulFill.put("responseCode", reloadGcResult.get("responseCode")); gcFulFill.put("referenceNum", reloadGcResult.get("referenceNum")); } try { dispatcher.runAsync("createGcFulFillmentRecord", gcFulFill, true); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to store fulfillment info"); } if (errorMessage != null) { // there was a problem Debug.logError("Reload Failed Need to Refund : " + reloadGcResult, module); // process the return try { Map refundCtx = UtilMisc.toMap("orderItem", orderItem, "partyId", partyId, "userLogin", userLogin); dispatcher.runAsync("refundGcPurchase", refundCtx, null, true, 300, true); } catch (GenericServiceException e) { Debug.logError(e, "ERROR! Unable to call create refund service; this failed reload will NOT be refunded", module); } return ServiceUtil.returnError(errorMessage); } // add some information to the answerMap for the email answerMap.put("processResult", reloadGcResult.get("processResult")); answerMap.put("responseCode", reloadGcResult.get("responseCode")); answerMap.put("previousAmount", reloadGcResult.get("previousBalance")); answerMap.put("amount", reloadGcResult.get("amount")); // get the email setting for this email type GenericValue productStoreEmail = null; String emailType = "PRDS_GC_RELOAD"; try { productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", productStoreId, "emailType", emailType)); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get product store email setting for gift card purchase", module); } if (productStoreEmail == null) { Debug.logError("No gift card purchase email setting found for this store; cannot send gift card information", module); } else { ResourceBundleMapWrapper uiLabelMap = (ResourceBundleMapWrapper) UtilProperties.getResourceBundleMap("EcommerceUiLabels", locale); uiLabelMap.addBottomResourceBundle("OrderUiLabels"); uiLabelMap.addBottomResourceBundle("CommonUiLabels"); answerMap.put("uiLabelMap", uiLabelMap); answerMap.put("locale", locale); Map emailCtx = new HashMap(); String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation"); if (UtilValidate.isEmpty(bodyScreenLocation)) { bodyScreenLocation = ProductStoreWorker.getDefaultProductStoreEmailScreenLocation(emailType); } emailCtx.put("bodyScreenUri", bodyScreenLocation); emailCtx.put("bodyParameters", answerMap); emailCtx.put("sendTo", orh.getOrderEmailString()); emailCtx.put("contentType", productStoreEmail.get("contentType")); emailCtx.put("sendFrom", productStoreEmail.get("fromAddress")); emailCtx.put("sendCc", productStoreEmail.get("ccAddress")); emailCtx.put("sendBcc", productStoreEmail.get("bccAddress")); emailCtx.put("subject", productStoreEmail.getString("subject")); emailCtx.put("userLogin", userLogin); // send off the email async so we will retry on failed attempts try { dispatcher.runAsync("sendMailFromScreen", emailCtx); } catch (GenericServiceException e) { Debug.logError(e, "Problem sending mail", module); // this is fatal; we will rollback and try again later return ServiceUtil.returnError("Error sending Gift Card notice email: " + e.toString()); } } return ServiceUtil.returnSuccess(); } // Tracking Service public static Map createFulfillmentRecord(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); // create the fulfillment record GenericValue gcFulFill = delegator.makeValue("GiftCardFulfillment", null); gcFulFill.set("fulfillmentId", delegator.getNextSeqId("GiftCardFulfillment")); gcFulFill.set("typeEnumId", context.get("typeEnumId")); gcFulFill.set("merchantId", context.get("merchantId"));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?