giftcertificateservices.java

来自「Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电」· Java 代码 · 共 1,365 行 · 第 1/5 页

JAVA
1,365
字号
                return ServiceUtil.returnError(err + ServiceUtil.getErrorMessage(serviceResults));            }            return result;        } catch (GenericServiceException e) {            Debug.logError(e, e.getMessage(), module);            return ServiceUtil.returnError(err + e.getMessage());        }    }    private static Map giftCertificateRestore(DispatchContext dctx, GenericValue userLogin, GenericValue paymentPref, Double amount, String currency, String resultPrefix) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        // get the orderId for tracking        String orderId = paymentPref.getString("orderId");        OrderReadHelper orh = new OrderReadHelper(delegator, orderId);        String productStoreId = orh.getProductStoreId();        // party ID for tracking        GenericValue placingParty = orh.getPlacingParty();        String partyId = null;        if (placingParty != null) {            partyId = placingParty.getString("partyId");        }        // get the GiftCard VO        GenericValue giftCard = null;        try {            giftCard = paymentPref.getRelatedOne("GiftCard");        } catch (GenericEntityException e) {            Debug.logError(e, "Unable to get GiftCard from OrderPaymentPreference", module);            return ServiceUtil.returnError("Unable to locate GiftCard Information");        }        if (giftCard == null) {            return ServiceUtil.returnError("Attempt to release GiftCard payment faild; not a valid GiftCard record");        }        // make sure we have a currency        if (currency == null) {            currency = UtilProperties.getPropertyValue("general.properties", "currency.uom.id.default", "USD");        }        Map refundCtx = new HashMap();        refundCtx.put("productStoreId", productStoreId);        refundCtx.put("currency", currency);        refundCtx.put("partyId", partyId);        //reloadCtx.put("orderId", orderId);        refundCtx.put("cardNumber", giftCard.get("cardNumber"));        refundCtx.put("pinNumber", giftCard.get("pinNumber"));        refundCtx.put("amount", amount);        refundCtx.put("userLogin", userLogin);        Map restoreGcResult = null;        try {            restoreGcResult = dispatcher.runSync("addFundsToGiftCertificate", refundCtx);        } catch (GenericServiceException e) {            Debug.logError(e, module);            return ServiceUtil.returnError("Unable to call refund service!");        }        if (ServiceUtil.isError(restoreGcResult)) {            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(restoreGcResult));        }        Map result = ServiceUtil.returnSuccess();        if (restoreGcResult != null) {            Boolean processResult = (Boolean) restoreGcResult.get("processResult");            result.put(resultPrefix + "Amount", amount);            result.put(resultPrefix + "Result", processResult);            result.put(resultPrefix + "Code", "R");            result.put(resultPrefix + "Flag", restoreGcResult.get("responseCode"));            result.put(resultPrefix + "RefNum", restoreGcResult.get("referenceNum"));        }        return result;    }    public static Map giftCertificatePurchase(DispatchContext dctx, Map context) {        // this service should always be called via FULFILLMENT_EXTASYNC        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 purchase; no productStoreId on OrderHeader : " + orderId);        }        // party ID for tracking        GenericValue placingParty = orh.getPlacingParty();        String partyId = null;        if (placingParty != null) {            partyId = placingParty.getString("partyId");        }        // amount/quantity of the gift card(s)        Double amount = orderItem.getDouble("unitPrice");        Double quantity = orderItem.getDouble("quantity");        // the product entity needed for information        GenericValue product = null;        try {            product = orderItem.getRelatedOne("Product");        } catch (GenericEntityException e) {            Debug.logError(e, "Unable to get Product from OrderItem", module);        }        if (product == null) {            return ServiceUtil.returnError("No product associated with OrderItem, cannot fulfill gift card");        }        // Gift certificate settings are per store in this entity        GenericValue giftCertSettings = null;        try {            giftCertSettings = delegator.findByPrimaryKeyCache("ProductStoreFinActSetting", UtilMisc.toMap("productStoreId", productStoreId, "finAccountTypeId", FinAccountHelper.giftCertFinAccountTypeId));            } catch (GenericEntityException e) {            Debug.logError(e, "Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId, module);            ServiceUtil.returnError("Unable to get Product Store FinAccount settings for " + FinAccountHelper.giftCertFinAccountTypeId + ": " + e.getMessage());        }               // survey information        String surveyId = giftCertSettings.getString("purchaseSurveyId");        // 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");        }        if (surveyResponse == null) {            return ServiceUtil.returnError("Survey response came back null from the database for order item: " + orderItem);        }        // 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");        }        // 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);                }            }        }        // get the send to email address - key defined in product store settings entity        String sendToKey = giftCertSettings.getString("purchSurveySendTo");        String sendToEmail = (String) answerMap.get(sendToKey);        // get the copyMe flag and set the order email address        String orderEmails = orh.getOrderEmailString();        String copyMeField = giftCertSettings.getString("purchSurveyCopyMe");        String copyMeResp = copyMeField != null ? (String) answerMap.get(copyMeField) : null;        boolean copyMe = (UtilValidate.isNotEmpty(copyMeField)                && UtilValidate.isNotEmpty(copyMeResp) && "true".equalsIgnoreCase(copyMeResp)) ? true : false;        int qtyLoop = quantity.intValue();        for (int i = 0; i < qtyLoop; i++) {            // create a gift certificate            Map createGcCtx = new HashMap();            //createGcCtx.put("paymentConfig", paymentConfig);            createGcCtx.put("productStoreId", productStoreId);            createGcCtx.put("currency", currency);            createGcCtx.put("partyId", partyId);            //createGcCtx.put("orderId", orderId);            createGcCtx.put("initialAmount", amount);            createGcCtx.put("userLogin", userLogin);            Map createGcResult = null;            try {                createGcResult = dispatcher.runSync("createGiftCertificate", createGcCtx);            } catch (GenericServiceException e) {                Debug.logError(e, module);                return ServiceUtil.returnError("Unable to create gift certificate: " + e.getMessage());            }            if (ServiceUtil.isError(createGcResult)) {                return ServiceUtil.returnError("Create Gift Certificate Failed: " + ServiceUtil.getErrorMessage(createGcResult));            }            // create the fulfillment record            Map gcFulFill = new HashMap();            gcFulFill.put("typeEnumId", "GC_ACTIVATE");            gcFulFill.put("partyId", partyId);            gcFulFill.put("orderId", orderId);            gcFulFill.put("orderItemSeqId", orderItem.get("orderItemSeqId"));            gcFulFill.put("surveyResponseId", surveyResponse.get("surveyResponseId"));            gcFulFill.put("cardNumber", createGcResult.get("cardNumber"));            gcFulFill.put("pinNumber", createGcResult.get("pinNumber"));            gcFulFill.put("amount", createGcResult.get("initialAmount"));            gcFulFill.put("responseCode", createGcResult.get("responseCode"));            gcFulFill.put("referenceNum", createGcResult.get("referenceNum"));            gcFulFill.put("userLogin", userLogin);            try {                dispatcher.runAsync("createGcFulFillmentRecord", gcFulFill, true);            } catch (GenericServiceException e) {                Debug.logError(e, module);                return ServiceUtil.returnError("Unable to store fulfillment info: " + e.getMessage());            }            // add some information to the answerMap for the email            answerMap.put("cardNumber", createGcResult.get("cardNumber"));            answerMap.put("pinNumber", createGcResult.get("pinNumber"));            answerMap.put("amount", createGcResult.get("initialAmount"));            // get the email setting for this email type            GenericValue productStoreEmail = null;            String emailType = "PRDS_GC_PURCHASE";            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);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?