⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productpromoworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }    /** calculate low use limit for this promo for the current "order", check per order, customer, promo */    public static Long getProductPromoUseLimit(GenericValue productPromo, String partyId, GenericDelegator delegator) throws GenericEntityException {        String productPromoId = productPromo.getString("productPromoId");        Long candidateUseLimit = null;        Long useLimitPerOrder = productPromo.getLong("useLimitPerOrder");        if (useLimitPerOrder != null) {            if (candidateUseLimit == null || candidateUseLimit.longValue() > useLimitPerOrder.longValue()) {                candidateUseLimit = useLimitPerOrder;            }        }                // Debug.logInfo("Promo [" + productPromoId + "] use limit after per order check: " + candidateUseLimit, module);        Long useLimitPerCustomer = productPromo.getLong("useLimitPerCustomer");        // check this whether or not there is a party right now        if (useLimitPerCustomer != null) {            // if partyId is not empty check previous usage            long productPromoCustomerUseSize = 0;            if (UtilValidate.isNotEmpty(partyId)) {                // check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order                EntityCondition checkCondition = new EntityConditionList(UtilMisc.toList(                        new EntityExpr("productPromoId", EntityOperator.EQUALS, productPromoId),                        new EntityExpr("partyId", EntityOperator.EQUALS, partyId),                        new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),                        new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);                productPromoCustomerUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null);            }            long perCustomerThisOrder = useLimitPerCustomer.longValue() - productPromoCustomerUseSize;            if (candidateUseLimit == null || candidateUseLimit.longValue() > perCustomerThisOrder) {                candidateUseLimit = new Long(perCustomerThisOrder);            }        }        // Debug.logInfo("Promo [" + productPromoId + "] use limit after per customer check: " + candidateUseLimit, module);        Long useLimitPerPromotion = productPromo.getLong("useLimitPerPromotion");        if (useLimitPerPromotion != null) {            // check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order            EntityCondition checkCondition = new EntityConditionList(UtilMisc.toList(                    new EntityExpr("productPromoId", EntityOperator.EQUALS, productPromoId),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);            long productPromoUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null);            long perPromotionThisOrder = useLimitPerPromotion.longValue() - productPromoUseSize;            if (candidateUseLimit == null || candidateUseLimit.longValue() > perPromotionThisOrder) {                candidateUseLimit = new Long(perPromotionThisOrder);            }        }        // Debug.logInfo("Promo [" + productPromoId + "] use limit after per promotion check: " + candidateUseLimit, module);        return candidateUseLimit;    }    public static Long getProductPromoCodeUseLimit(GenericValue productPromoCode, String partyId, GenericDelegator delegator) throws GenericEntityException {        String productPromoCodeId = productPromoCode.getString("productPromoCodeId");        Long codeUseLimit = null;        // check promo code use limits, per customer, code        Long codeUseLimitPerCustomer = productPromoCode.getLong("useLimitPerCustomer");        if (codeUseLimitPerCustomer != null && UtilValidate.isNotEmpty(partyId)) {            // check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order            EntityCondition checkCondition = new EntityConditionList(UtilMisc.toList(                    new EntityExpr("productPromoCodeId", EntityOperator.EQUALS, productPromoCodeId),                    new EntityExpr("partyId", EntityOperator.EQUALS, partyId),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);            long productPromoCustomerUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null);            long perCustomerThisOrder = codeUseLimitPerCustomer.longValue() - productPromoCustomerUseSize;            if (codeUseLimit == null || codeUseLimit.longValue() > perCustomerThisOrder) {                codeUseLimit = new Long(perCustomerThisOrder);            }        }        Long codeUseLimitPerCode = productPromoCode.getLong("useLimitPerCode");        if (codeUseLimitPerCode != null) {            // check to see how many times this has been used for other orders for this customer, the remainder is the limit for this order            EntityCondition checkCondition = new EntityConditionList(UtilMisc.toList(                    new EntityExpr("productPromoCodeId", EntityOperator.EQUALS, productPromoCodeId),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_REJECTED"),                    new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ORDER_CANCELLED")), EntityOperator.AND);            long productPromoCodeUseSize = delegator.findCountByCondition("ProductPromoUseCheck", checkCondition, null);            long perCodeThisOrder = codeUseLimitPerCode.longValue() - productPromoCodeUseSize;            if (codeUseLimit == null || codeUseLimit.longValue() > perCodeThisOrder) {                codeUseLimit = new Long(perCodeThisOrder);            }        }        return codeUseLimit;    }        public static String checkCanUsePromoCode(String productPromoCodeId, String partyId, GenericDelegator delegator) {        try {            GenericValue productPromoCode = delegator.findByPrimaryKey("ProductPromoCode", UtilMisc.toMap("productPromoCodeId", productPromoCodeId));            if (productPromoCode == null) {                return "The promotion code [" + productPromoCodeId + "] is not valid.";            }                        if ("Y".equals(productPromoCode.getString("requireEmailOrParty"))) {                boolean hasEmailOrParty = false;                                // check partyId                if (UtilValidate.isNotEmpty(partyId)) {                    if (delegator.findByPrimaryKey("ProductPromoCodeParty", UtilMisc.toMap("productPromoCodeId", productPromoCodeId, "partyId", partyId)) != null) {                        // found party associated with the code, looks good...                        return null;                    }                                        // check email address in ProductPromoCodeEmail                    Timestamp nowTimestamp = UtilDateTime.nowTimestamp();                    List validEmailCondList = new ArrayList();                    validEmailCondList.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));                    validEmailCondList.add(new EntityExpr("productPromoCodeId", EntityOperator.EQUALS, productPromoCodeId));                    validEmailCondList.add(new EntityExpr("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp));                    validEmailCondList.add(new EntityExpr(new EntityExpr("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp),                             EntityOperator.OR, new EntityExpr("thruDate", EntityOperator.EQUALS, null)));                    EntityCondition validEmailCondition = new EntityConditionList(validEmailCondList, EntityOperator.AND);                    long validEmailCount = delegator.findCountByCondition("ProductPromoCodeEmailParty", validEmailCondition, null);                    if (validEmailCount > 0) {                        // there was an email in the list, looks good...                         return null;                    }                }                                if (!hasEmailOrParty) {                    return "This promotion code [" + productPromoCodeId + "] requires you to be associated with it by account or email address and you are not associated with it.";                }            }                        // check per customer and per promotion code use limits            Long useLimit = getProductPromoCodeUseLimit(productPromoCode, partyId, delegator);            if (useLimit != null && useLimit.longValue() <= 0) {                return "This promotion code [" + productPromoCodeId + "] has reached it's maximum use limit for you and can no longer be used.";            }                        return null;        } catch (GenericEntityException e) {            Debug.logError(e, "Error looking up ProductPromoCode", module);            return "Error looking up code [" + productPromoCodeId + "]:" + e.toString();        }    }    public static String makeAutoDescription(GenericValue productPromo, GenericDelegator delegator, Locale locale) throws GenericEntityException {        if (productPromo == null) {            return "";        }        StringBuffer promoDescBuf = new StringBuffer();        List productPromoRules = productPromo.getRelatedCache("ProductPromoRule", null, null);        Iterator promoRulesIter = productPromoRules.iterator();        while (promoRulesIter != null && promoRulesIter.hasNext()) {            GenericValue productPromoRule = (GenericValue) promoRulesIter.next();            List productPromoConds = delegator.findByAndCache("ProductPromoCond", UtilMisc.toMap("productPromoId", productPromo.get("productPromoId")), UtilMisc.toList("productPromoCondSeqId"));            productPromoConds = EntityUtil.filterByAnd(productPromoConds, UtilMisc.toMap("productPromoRuleId", productPromoRule.get("productPromoRuleId")));            // using the other method to consolodate cache entries because the same cache is used elsewhere: List productPromoConds = productPromoRule.getRelatedCache("ProductPromoCond", null, UtilMisc.toList("productPromoCondSeqId"));            Iterator productPromoCondIter = UtilMisc.toIterator(productPromoConds);            while (productPromoCondIter != null && productPromoCondIter.hasNext()) {                GenericValue productPromoCond = (GenericValue) productPromoCondIter.next();                String equalityOperator = UtilProperties.getMessage("promotext", "operator.equality." + productPromoCond.getString("operatorEnumId"), locale);                String quantityOperator = UtilProperties.getMessage("promotext", "operator.quantity." + productPromoCond.getString("operatorEnumId"), locale);                String condValue = "invalid";                if (UtilValidate.isNotEmpty(productPromoCond.getString("condValue"))) {                    condValue = productPromoCond.getString("condValue");                }                                Map messageContext = UtilMisc.toMap("condValue", condValue, "equalityOperator", equalityOperator, "quantityOperator", quantityOperator);                String msgProp = UtilProperties.getMessage("promotext", "condition." + productPromoCond.getString("inputParamEnumId"), messageContext, locale);                promoDescBuf.append(msgProp);                promoDescBuf.append(" ");                                if (promoRulesIter.hasNext()) {                    promoDescBuf.append(" and ");                }            }            List productPromoActions = productPromoRule.getRelatedCache("ProductPromoAction", null, UtilMisc.toList("productPromoActionSeqId"));            Iterator productPromoActionIter = UtilMisc.toIterator(productPromoActions);            while (productPromoActionIter != null && productPromoActionIter.hasNext()) {                GenericValue productPromoAction = (GenericValue) productPromoActionIter.next();                String productId = productPromoAction.getString("productId");                                Map messageContext = UtilMisc.toMap("quantity", productPromoAction.get("quantity"), "amount", productPromoAction.get("amount"), "productId", productId, "partyId", productPromoAction.get("partyId"));                if (UtilValidate.isEmpty((String) messageContext.get("productId"))) messageContext.put("productId", "any");                if (UtilValidate.isEmpty((String) messageContext.get("partyId"))) messageContext.put("partyId", "any");                GenericValue product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId));                if (product != null) {                    messageContext.put("productName", ProductContentWrapper.getProductContentAsText(product, "PRODUCT_NAME", locale));                }                                String msgProp = UtilProperties.getMessage("promotext", "action." + productPromoAction.getString("productPromoActionEnumId"), messageContext, locale);                promoDescBuf.append(msgProp);                promoDescBuf.append(" ");                                if (promoRulesIter.hasNext()) {                    promoDescBuf.append(" and ");                }            }                        if (promoRulesIter.hasNext()) {                promoDescBuf.append(" or ");            }        }

⌨️ 快捷键说明

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