/// <summary>
        /// 根据用户输入的商品信息构造一个ConfigItem
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public ComputerConfigItem BuildConfigItem(ComputerConfigItem item)
        {
            var foundProduct = ExternalDomainBroker.GetProductInfo(item.ProductSysNo.Value);

            if (foundProduct == null)
            {
                throw new BizException("商品不存在。");
            }
            var partsCategoryList = _configDA.GetComputerPartsCategory(item.ComputerPartSysNo);

            if (!foundProduct.ProductBasicInfo.ProductCategoryInfo.SysNo.HasValue ||
                !partsCategoryList.Exists(c => c == foundProduct.ProductBasicInfo.ProductCategoryInfo.SysNo.Value))
            {
                throw new BizException(string.Format("商品{0}不在该组件的可选分类中,不能添加。", foundProduct.ProductID));
            }
            if (foundProduct.ProductStatus != BizEntity.IM.ProductStatus.Active)
            {
                throw new BizException(string.Format("商品{0}不是上架状态,不能添加!。", foundProduct.ProductID));
            }
            //填充商品详细
            item.ProductID    = foundProduct.ProductID;
            item.ProductName  = foundProduct.ProductName;
            item.UnitCost     = foundProduct.ProductPriceInfo.UnitCost;
            item.CurrentPrice = foundProduct.ProductPriceInfo.CurrentPrice;

            //填充库存信息
            var foundInventory = ExternalDomainBroker.GetProductTotalInventoryInfo(item.ProductSysNo.Value);

            if (foundInventory != null)
            {
                if (foundInventory.OnlineQty <= 0)
                {
                    throw new BizException(string.Format("商品{0}库存为零,不能添加!。", foundProduct.ProductID));
                }
                item.OnlineQty = foundInventory.OnlineQty;
            }
            item.ProductQty = 1;
            item.Discount   = 0;

            return(item);
        }
Exemple #2
0
        /// <summary>
        /// 更新产品Keywords0
        /// </summary>
        /// <param name="item"></param>
        public virtual void UpdateProductPageKeywords(ProductPageKeywords item)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                keywordDA.UpdateProductPageKeywords(item);

                /*2012-12-31 update bug95058  jack.g.tang
                 * 修改目的:ProductSysNo可能为null
                 * 解决办法:为null时 根据productId取得ProducuSysNo
                 */
                int?productSysNo = item.ProductSysNo;
                if (item.ProductSysNo == null || item.ProductSysNo == 0)
                {
                    productSysNo = ExternalDomainBroker.GetProductInfo(item.ProductId).SysNo;
                }
                ExternalDomainBroker.UpdateProductExKeyKeywords(
                    (int)productSysNo, item.Keywords.ToString()
                    , item.Keywords0.ToString(), ServiceContext.Current.UserSysNo, item.CompanyCode);
                scope.Complete();
            }
        }
        /// <summary>
        /// 获取指定商品,赠品池活动的非“买满即赠”的赠品成本总和 -OK
        /// Old Method:GetCurrentGiftAmount
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <returns></returns>
        public virtual decimal GetSaleGiftAmountForFull(int productSysNo, int saleGiftSysNo, int ItemGiftCount)
        {
            decimal result = 0.00m;
            //获取指定商品,指定赠品活动的非“买满即赠”的赠品及赠品数量
            DataTable dt            = _da.GetSaleGiftGiftProductsExcludeFull(productSysNo, saleGiftSysNo);
            var       productPrices = new List <decimal>();

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow     dr = dt.Rows[i];
                    int         giftProductSysNo = int.Parse(dr["ProductSysNo"].ToString());
                    ProductInfo product          = ExternalDomainBroker.GetProductInfo(giftProductSysNo);
                    productPrices.Add(product.ProductPriceInfo.CurrentPrice.Value);
                }
            }
            var price = productPrices.OrderByDescending(p => p).Take(ItemGiftCount).Sum();

            return(price);
        }
Exemple #4
0
        /// <summary>
        /// 验证商品是否存在相冲突时间段的限时抢购中
        /// </summary>
        private void CheckGroupBuyAndCountDownConflict(GroupBuyingInfo groupBuy)
        {
            List <int> productSysNos = new List <int>();

            productSysNos.Add(groupBuy.ProductSysNo.Value);

            if (groupBuy.IsByGroup.Value)
            {
                List <ProductInfo> products = ExternalDomainBroker.GetProductsInSameGroupWithProductSysNo(groupBuy.ProductSysNo.Value);

                foreach (ProductInfo p in products)
                {
                    productSysNos.Add(p.SysNo);
                }
            }

            if (ObjectFactory <CountdownProcessor> .Instance.CheckGroupBuyAndCountDownConflict(productSysNos, groupBuy.BeginDate.Value, groupBuy.EndDate.Value))
            {
                // throw new BizException("该商品或者同组商品已经存在一个时间冲突的限时抢购!");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.GroupBuying", "GroupBuying_ExsistTimeConflictCountdown"));
            }
        }
        public ProductPriceCompareEntity Load(int sysNo)
        {
            var productPriceCompare = _ProductPriceCompareDA.Load(sysNo);

            var productInfo = ExternalDomainBroker.GetProductInfo(productPriceCompare.ProductSysNo);

            if (productInfo != null)
            {
                productPriceCompare.ProductID   = productInfo.ProductID;
                productPriceCompare.ProductName = productInfo.ProductBasicInfo.ProductBriefName;
            }
            var customerInfo = ExternalDomainBroker.GetCustomerInfo(productPriceCompare.CustomerSysNo);

            if (customerInfo != null)
            {
                productPriceCompare.CustomerID    = customerInfo.BasicInfo.CustomerID;
                productPriceCompare.CustomerName  = customerInfo.BasicInfo.CustomerName;
                productPriceCompare.CustomerEmail = customerInfo.BasicInfo.Email;
            }

            return(productPriceCompare);
        }
 /// <summary>
 /// 创建配置单
 /// </summary>
 /// <param name="msg"></param>
 public void CreateComputerConfigMaster(ComputerConfigMaster msg)
 {
     ValidateCommon(msg);
     using (TransactionScope scope = new TransactionScope())
     {
         _configDA.CreateComputerConfigMaster(msg);
         foreach (var configItem in msg.ConfigItemList)
         {
             configItem.ComputerConfigSysNo = msg.SysNo.Value;
             _configDA.CreateComputerConfigInfo(configItem);
         }
         //操作Combo
         InteractWithCombo(msg);
         ExternalDomainBroker.CreateOperationLog(
             String.Format("{0}{1}SysNo:{2}",
                           DateTime.Now.ToString(), "新建配置单"
                           , msg.SysNo)
             , BizEntity.Common.BizLogType.ComputerConfig_Add
             , msg.SysNo.Value, msg.CompanyCode);
         scope.Complete();
     }
 }
        //加载
        public ComputerConfigMaster LoadComputerConfig(int sysNo)
        {
            var configItems = _configDA.GetComputerConfigItems(sysNo);
            var categories  = _configDA.GetAllComputerPartsCategory();
            //调用IM接口取得商品详细
            var productSysNoList = configItems.Where(item => item.ProductSysNo.HasValue).Select(item => item.ProductSysNo.Value).ToList();
            var productInfoList  = ExternalDomainBroker.GetProductInfoListByProductSysNoList(productSysNoList);
            //调用Inventory接口取得库存信息
            var inventoryInfoList = ExternalDomainBroker.GetProductInventoryInfoByProductSysNoList(productSysNoList);

            foreach (var item in configItems)
            {
                //填充商品详细
                var foundProduct = productInfoList.FirstOrDefault(product => product.SysNo == item.ProductSysNo);
                if (foundProduct != null)
                {
                    item.ProductID    = foundProduct.ProductID;
                    item.ProductName  = foundProduct.ProductName;
                    item.UnitCost     = foundProduct.ProductPriceInfo.UnitCost;
                    item.CurrentPrice = foundProduct.ProductPriceInfo.CurrentPrice;
                }
                //填充库存信息
                var foundInventory = inventoryInfoList.FirstOrDefault(inventory => inventory.ProductSysNo.Value == item.ProductSysNo);
                if (foundInventory != null)
                {
                    item.OnlineQty = foundInventory.OnlineQty;
                }
                item.PartsCategories = categories.FindAll(c => c.ComputerPartSysNo == item.ComputerPartSysNo);
            }
            //按优先级升序
            configItems.OrderBy(item => item.Priority);


            var master = _configDA.LoadMaster(sysNo);

            master.ConfigItemList = configItems;

            return(master);
        }
Exemple #8
0
        /// <summary>
        /// 验证商品是否存在相冲突时间段的团购中
        /// </summary>
        private void CheckGroupBuyConflict(int?GroupBuySysNo, GroupBuyingInfo groupBuy)
        {
            List <int> productSysNos = new List <int>();

            productSysNos.Add(groupBuy.ProductSysNo.Value);

            if (groupBuy.IsByGroup.Value)
            {
                List <ProductInfo> products = ExternalDomainBroker.GetProductsInSameGroupWithProductSysNo(groupBuy.ProductSysNo.Value);

                foreach (ProductInfo p in products)
                {
                    productSysNos.Add(p.SysNo);
                }
            }

            if (m_GroupBuyingDA.CheckConflict(GroupBuySysNo, productSysNos, groupBuy.BeginDate.Value, groupBuy.EndDate.Value))
            {
                //throw new BizException("该商品或者同组商品已经存在一个时间冲突的团购!");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.GroupBuying", "GroupBuying_ExsistTimeConflictGroupBuying"));
            }
        }
        /// <summary>
        /// 回复邮件操作,并发送邮件
        /// </summary>
        /// <param name="item"></param>
        public virtual void UpdateProductConsultMailLog(ProductReview item)
        {
            if (productReviewMailLogDA.CheckProductCommentMailLog(item.ProductReviewMailLog))
            {
                productReviewMailLogDA.UpdateProductCommentMailLog(item.ProductReviewMailLog);
            }
            else
            {
                productReviewMailLogDA.CreateProductCommentMailLog(item.ProductReviewMailLog);
            }

            #region 发送邮件
            KeyValueVariables replaceVariables = new KeyValueVariables();

            ECCentral.BizEntity.IM.ProductInfo product = ExternalDomainBroker.GetProductInfo(item.ProductSysNo.Value);
            replaceVariables.AddKeyValue(@"ProductID", product.ProductID);
            replaceVariables.AddKeyValue(@"ProductName", product.ProductName);

            replaceVariables.AddKeyValue(@"Content", item.ProductReviewMailLog.Content);
            replaceVariables.AddKeyValue(@"EmailText", item.ProductReviewMailLog.TopicMailContent.Content);
            replaceVariables.AddKeyValue(@"All", DateTime.Now.ToString());
            replaceVariables.AddKeyValue(@"InDate-Y", DateTime.Now.Year.ToString());
            replaceVariables.AddKeyValue(@"InDate-M", DateTime.Now.Month.ToString());
            replaceVariables.AddKeyValue(@"InDate-D", DateTime.Now.Day.ToString());
            replaceVariables.AddKeyValue(@"Year", DateTime.Now.Year.ToString());

            ECCentral.BizEntity.Customer.CustomerInfo customer = ExternalDomainBroker.GetCustomerInfo(item.CustomerSysNo.Value);
            replaceVariables.AddKeyValue(@"CustomerName", customer.BasicInfo.CustomerID);
            if (string.IsNullOrEmpty(customer.BasicInfo.Email))
            {
                throw new BizException("邮件地址为空!");
            }
            else
            {
                ECCentral.Service.Utility.EmailHelper.SendEmailByTemplate(customer.BasicInfo.Email, "MKT_ProductConsultMailContent", replaceVariables, false);
            }
            #endregion
        }
Exemple #10
0
        /// <summary>
        /// 中止
        /// </summary>
        /// <param name="sysNo"></param>
        public virtual void Stop(List <int> sysNoList)
        {
            string userfullname = ObjectFactory <ICommonBizInteract> .Instance.GetUserFullName(ServiceContext.Current.UserSysNo.ToString(), true);

            foreach (int sysNo in sysNoList)
            {
                GroupBuyingInfo infoTemp = Load(sysNo);
                if (infoTemp.Status.Value != GroupBuyingStatus.Active)
                {
                    //throw new BizException(string.Format("团购[{0}]中止失败,只有运行状态的团购才能作废!", sysNo));
                    throw new BizException(string.Format(ResouceManager.GetMessageString("MKT.Promotion.GroupBuying", "roupBuying_JustRunStop"), sysNo));
                }
                TransactionScopeFactory.TransactionAction(() =>
                {
                    m_GroupBuyingDA.UpdateGroupBuyingEndDate(sysNo, userfullname);

                    //促销引擎-更新活动状态 -中止即为完成
                    //ObjectFactory<GroupBuyingPromotionEngine>.Instance.UpdateGroupBuyingActivityStatus(sysNo, GroupBuyingStatus.Finished);

                    ExternalDomainBroker.CreateOperationLog(BizLogType.GroupBuyingStop.ToEnumDesc(), BizLogType.GroupBuyingStop, sysNo, infoTemp.CompanyCode);
                });
            }
        }
Exemple #11
0
        /// <summary>
        /// 加载
        /// </summary>
        /// <param name="sysNo"></param>
        /// <returns></returns>
        public GroupBuyingInfo Load(int?sysNo)
        {
            var result = m_GroupBuyingDA.Load(sysNo.Value);

            if (result == null)
            {
                //throw new BizException("团购信息不存在!");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.GroupBuying", "GroupBuying_NotExsitGroupBuyInfo"));
            }
            if (result.ProductSysNo > 0)
            {
                var product = ExternalDomainBroker.GetProductInfo(result.ProductSysNo.Value);
                result.BasicPrice = product.ProductPriceInfo.BasicPrice;
                List <object> oPriceList = m_GroupBuyingDA.GetProductOriginalPrice(product.SysNo, result.IsByGroup ?? false ? "Y" : "N", result.CompanyCode);
                //result.OriginalPrice = (oPriceList == null || oPriceList[0] == null
                //            ? 0m : decimal.Round(decimal.Parse(oPriceList[0].ToString()), 2));
            }
            if (result.CategoryType == GroupBuyingCategoryType.Virtual)
            {
                result.VendorStoreSysNoList = m_GroupBuyingDA.GetGroupBuyingVendorStores(result.SysNo.Value);
            }
            return(result);
        }
Exemple #12
0
        /// <summary>
        /// 创建广告信息
        /// </summary>
        /// <param name="bannerLocation">广告信息</param>
        public virtual void Create(BannerLocation bannerLocation)
        {
            if (!bannerLocation.BeginDate.HasValue)
            {
                bannerLocation.BeginDate = DateTime.Now;
            }

            Validate(bannerLocation);
            using (TransactionScope ts = new TransactionScope())
            {
                //新建广告
                CreateBanner(bannerLocation);
                //处理三级分类扩展生效
                ProcessECCategory3Extend(bannerLocation);
                //TODO:写入创建日志
                ExternalDomainBroker.CreateOperationLog(
                    String.Format("{0}{1}SysNo:{2}",
                                  DateTime.Now.ToString(), ResouceManager.GetMessageString("MKT.Banner", "Banner_Add")
                                  , bannerLocation.SysNo)
                    , BizEntity.Common.BizLogType.Banner_Add
                    , bannerLocation.SysNo.Value, bannerLocation.CompanyCode);
                ts.Complete();
            }
        }
        private void ValidateCommon(ComputerConfigMaster entity)
        {
            entity.SysNo = entity.SysNo ?? 0;
            if (entity.ComputerConfigTypeSysNo <= 0)
            {
                throw new BizException("请选择配置单类型!");
            }
            if (string.IsNullOrEmpty(entity.ComputerConfigName))
            {
                throw new BizException("配置单名称不能为空!");
            }
            if (string.IsNullOrEmpty(entity.Note))
            {
                throw new BizException("配置单说明不能为空!");
            }
            if (entity.Priority < 0)
            {
                throw new BizException("配置单优先级必须>=0!");
            }
            if (entity.ConfigItemList == null || entity.ConfigItemList.Count == 0)
            {
                throw new BizException("配置单商品信息列表不能为空!");
            }

            int duplicateCount = _configDA.CountComputerConfigName(entity.SysNo.Value, entity.ComputerConfigName, entity.CompanyCode, entity.WebChannel.ChannelID);

            if (duplicateCount > 0)
            {
                throw new BizException("配置单名称已存在,请验证。");
            }

            decimal totalDiscountPrice = 0M;

            foreach (ComputerConfigItem configItem in entity.ConfigItemList)
            {
                var product = ExternalDomainBroker.GetProductInfo(configItem.ProductSysNo.Value);
                if (product == null)
                {
                    throw new BizException(string.Format("商品{0}不存在。", configItem.ProductSysNo));
                }

                if (configItem.ProductQty <= 0)
                {
                    throw new BizException("商品购买数量未填写或输入有误!");
                }

                if (configItem.Discount > 0)
                {
                    throw new BizException("商品折扣未填写或输入有误!");
                }

                if (configItem.OnlineQty <= 0 || configItem.ProductQty > configItem.OnlineQty)
                {
                    throw new BizException(configItem.ComputerPartName + "商品库存不足!");
                }

                totalDiscountPrice += ObjectFactory <IIMBizInteract> .Instance.GetProductMarginAmount(
                    configItem.CurrentPrice.Value + configItem.Discount, 0, configItem.UnitCost) * configItem.ProductQty;
            }

            if (totalDiscountPrice < 0)
            {
                if (entity.Status != ComputerConfigStatus.Pending)
                {
                    throw new BizException("配置单折扣价毛利率低于基准毛利率,请提交审核!");
                }
            }
            else if (entity.Status == ComputerConfigStatus.Pending)
            {
                throw new BizException("不需要审核,请直接保存!");
            }

            ValidateMustParts(entity);

            //如果通过所有Check, 且提交状态为初始‘O’,则直接运行‘A’
            if (entity.Status == ComputerConfigStatus.Origin)
            {
                entity.Status = ComputerConfigStatus.Running;
            }
        }
        private BatchCreateGiftRuleInfo CreateGiftRules(BatchCreateGiftRuleInfo info)
        {
            string       msg         = string.Empty;
            int          special     = 0;//是否特殊规则1是0否
            SaleGiftInfo g           = _SaleGiftDA.Load(info.PromotionSysNo);
            int          vendorsysno = g.VendorSysNo.Value;

            if (g.VendorType == 0)
            {
                vendorsysno = 1;
            }
            CheckGiftRules(info);

            foreach (ProductItemInfo entity in info.ProductList)
            {
                //只有状态为2(不展示)的赠品才允许插入
                if (entity.ProductStatus == ProductStatus.InActive_UnShow)
                {
                    int count = _BatchCreateSaleGiftDA.CheckGiftRulesForVendor(entity.ProductSysNo, g.Type == SaleGiftType.Vendor?true:false, info.CompanyCode);

                    if (count > 0)
                    {
                        //msg += string.Format("赠品{0}[#:{1}]存在有效记录 ", entity.ProductName, entity.ProductID);
                        msg += string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_AlreadyExsistActiceRecord"), entity.ProductName, entity.ProductID);
                        continue;
                    }

                    //判断是否为附件
                    bool isAttachment = ExternalDomainBroker.CheckIsAttachment(entity.ProductSysNo.Value);
                    if (isAttachment)
                    {
                        //msg += string.Format("商品{0}[#:{1}]已经设置成附件,不能设置为赠品 ", entity.ProductName,entity.ProductID);
                        msg += string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_AccessoryCannotBeGift"), entity.ProductName, entity.ProductID);
                        continue;
                    }


                    //如果是赠品池,把赠送数量置为NULL
                    if (info.GiftComboType == SaleGiftGiftItemType.GiftPool)
                    {
                        entity.HandselQty = null;
                    }
                    _BatchCreateSaleGiftDA.CreateGiftRules(entity, info);
                }
                else
                {
                    //msg += string.Format("赠品{0}[#:{1}]必须为不展示状态 ", entity.ProductName, entity.ProductID);
                    msg += string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_AccessoryCannotBeGift"), entity.ProductName, entity.ProductID);
                }
                //检查不能添加其他商家的商品
                if (entity.ProductSysNo.HasValue)
                {
                    int productvendorsysno = _da.GetVendorSysNoByProductSysNo(entity.ProductSysNo.Value);
                    if (productvendorsysno != vendorsysno)
                    {
                        //msg += string.Format("赠品信息中{0}不能添加其他商家的商品【{1}】 ", g.VendorName, entity.ProductID);
                        msg += string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_AccessoryCannotBeGift"), entity.ProductName, entity.ProductID);
                    }
                }
            }
            if (msg != string.Empty)
            {
                throw new BizException(msg);
            }
            else
            {
                _BatchCreateSaleGiftDA.UpdateItemGiftCouontGiftRules(info.PromotionSysNo, (info.GiftComboType == SaleGiftGiftItemType.AssignGift ? null : info.SumCount), info.GiftComboType.Value, info.CompanyCode, info.InUser, special);
            }
            return(info);
        }
        /// <summary>
        /// Check 厂商赠品的赠品不能作为其它赠品活动的赠品
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private List <String> CheckVendorGiftRules(SaleGiftBatchInfo info)
        {
            List <SaleGiftInfo> giftInfoListTmp = new List <SaleGiftInfo>();
            List <String>       msgTmp          = new List <String>();

            foreach (var item in info.Gifts)
            {
                giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.Run));
                giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.Ready));
                giftInfoListTmp.AddRange(_da.GetGiftItemListByProductSysNo(item.ProductSysNo.Value, SaleGiftStatus.WaitingAudit));

                if (info.SaleGiftType == SaleGiftType.Vendor)
                {
                    if (giftInfoListTmp != null && giftInfoListTmp.Where(p => p.SysNo != info.SysNo && p.Type != SaleGiftType.Vendor).ToList().Count > 0)
                    {
                        //msgTmp.Add(string.Format("厂商赠品 ({0}) 在其他赠品活动中存在有效的重复的记录!", ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID));
                        msgTmp.Add(string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_ExsisitActivityInOther"), ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID));
                        continue;
                    }
                }
                else
                {
                    if (giftInfoListTmp != null && giftInfoListTmp.Where(p => p.SysNo != info.SysNo && p.Type == SaleGiftType.Vendor).ToList().Count > 0)
                    {
                        //msgTmp.Add(string.Format("赠品 ({0}) 在厂商赠品活动中存在有效的重复的记录!", ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID));
                        msgTmp.Add(string.Format(ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_ExsisitActivityInMerchant"), ExternalDomainBroker.GetSimpleProductInfo(item.ProductSysNo.Value).ProductID));
                        continue;
                    }
                }
            }
            return(msgTmp);
        }
        public virtual decimal GetCategoryMinGrossMarginRate(ProductInfo product)
        {
            CategorySetting setting = ExternalDomainBroker.GetCategorySetting(product.ProductBasicInfo.ProductCategoryInfo.SysNo.Value);

            return(setting.PrimaryMargin);
        }
        /// <summary>
        /// 获取指定商品类别下最小毛利
        /// </summary>
        /// <param name="itemSysNo"></param>
        /// <param name="minMargin"></param>
        public virtual decimal GetCategoryMinGrossMarginRate(int productSysNo)
        {
            ProductInfo product = ExternalDomainBroker.GetProductInfo(productSysNo);

            return(GetCategoryMinGrossMarginRate(product));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="product"></param>
        /// <param name="isPrimary">是否为初级毛利,否的话就是高级毛利</param>
        /// <returns></returns>
        public virtual decimal GetStockGrossMarginRate(ProductInfo product, bool isPrimary)
        {
            int             inStockDays = ExternalDomainBroker.GetInStockDaysByProductSysNo(product.SysNo);
            CategorySetting cateSetting = ExternalDomainBroker.GetCategorySetting(product.ProductBasicInfo.ProductCategoryInfo.SysNo.Value);
            MinMarginKPI    kpi         = new MinMarginKPI();

            if (cateSetting.CategoryMinMarginInfo != null && cateSetting.CategoryMinMarginInfo.Margin != null && cateSetting.CategoryMinMarginInfo.Margin.Count() > 0)
            {
                if (inStockDays >= 0 && inStockDays <= 30)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.Thirty];
                }

                if (inStockDays >= 31 && inStockDays <= 60)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.Sixty];
                }

                if (inStockDays >= 61 && inStockDays <= 90)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.Ninety];
                }

                if (inStockDays >= 91 && inStockDays <= 120)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.OneHundredAndTwenty];
                }

                if (inStockDays >= 120 && inStockDays <= 180)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.OneHundredAndEighty];
                }

                if (inStockDays > 180)
                {
                    kpi = cateSetting.CategoryMinMarginInfo.Margin[MinMarginDays.Other];
                }
            }
            else
            {
                if (inStockDays >= 0 && inStockDays <= 30)
                {
                    kpi.MinMargin = 0.05m;
                    kpi.MaxMargin = 0.05m;
                }

                if (inStockDays >= 31 && inStockDays <= 180)
                {
                    kpi.MinMargin = 0.01m;
                    kpi.MaxMargin = 0.01m;
                }

                if (inStockDays > 180)
                {
                    kpi.MinMargin = -0.03m;
                    kpi.MaxMargin = -0.03m;
                }
            }
            if (isPrimary)
            {
                return(kpi.MinMargin);//初级毛利率下限
            }
            else
            {
                return(kpi.MaxMargin);//高级毛利率下限
            }
        }
        /// <summary>
        /// 获取指定商品的库龄高级毛利率下限
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <returns></returns>
        public virtual decimal GetStockSeniorGrossMarginRate(int productSysNo)
        {
            ProductInfo product = ExternalDomainBroker.GetProductInfo(productSysNo);

            return(GetStockGrossMarginRate(product, false));
        }
        /// <summary>
        /// 指定活动,指定商品的“PM-产品优惠券”的折扣金额
        /// Old Method:GetCurrentCouponAmount
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <param name="couponSysNo"></param>
        /// <returns></returns>
        public virtual decimal GetCouponAmountForPM(int productSysNo, int couponSysNo)
        {
            ProductInfo product = ExternalDomainBroker.GetProductInfo(productSysNo);

            return(GetCouponAmountForPM(product, couponSysNo));
        }
        public virtual SaleAdvertisementItem CreateItem(SaleAdvertisementItem entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (string.IsNullOrEmpty(entity.Introduction))
            {
                entity.Introduction = null;
            }
            //UI上可以不选择Group,如果GroupSysNo写入DB为null的话则查不出来
            if (entity.GroupSysNo == null)
            {
                entity.GroupName  = null;
                entity.GroupSysNo = 0;
            }


            ProductInfo product = null;

            if (entity.ProductSysNo == null)
            {
                product = ExternalDomainBroker.GetProductInfo(entity.ProductID);
            }
            else
            {
                product = ExternalDomainBroker.GetProductInfo(entity.ProductSysNo.Value);
            }
            if (product == null)
            {
                //throw new BizException("商品无效!");
                throw new BizException(ResouceManager.GetMessageString("MKT.SaleAdvertisement", "SaleAdvertisement_InvalidProduct"));
            }
            else
            {
                entity.MarketPrice   = product.ProductPriceInfo.BasicPrice;
                entity.ProductSysNo  = product.SysNo;
                entity.ProductID     = product.ProductID;
                entity.ProductName   = product.ProductName;
                entity.ProductStatus = product.ProductStatus;
            }
            if (da.CheckSaleAdvItemDuplicate(entity))
            {
                //throw new BizException("你要创建或修改的记录已经存在了!");
                throw new BizException(ResouceManager.GetMessageString("MKT.SaleAdvertisement", "SaleAdvertisement_RecordAreadyExsist"));
            }
#warning To do 获取京东价
            var inventoryInfo = ExternalDomainBroker.GetProductInventoryInfo(entity.ProductSysNo.Value);
            entity.OnlineQty = inventoryInfo.Sum(p => p.OnlineQty);

            entity.Status = ADStatus.Active;
            TransactionOptions options = new TransactionOptions();
            options.IsolationLevel = IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope())
            {
                da.CreateItem(entity);

                da.CreateSaleAdvItemLog(entity, "A");

                scope.Complete();
            }

            return(entity);
        }
        /// <summary>
        /// 从IMDomain获取商品及赠品的商品信息,主要是状态信息。
        /// </summary>
        private void InitProductInfosFromIM(SaleGiftBatchInfo saleGiftBatchInfo)
        {
            List <int> productSysNos = new List <int>();

            if (saleGiftBatchInfo.ProductItems1 != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems1)
                {
                    productSysNos.Add(item.ProductSysNo.Value);
                }
            }

            if (saleGiftBatchInfo.ProductItems2 != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems2)
                {
                    productSysNos.Add(item.ProductSysNo.Value);
                }
            }

            if (saleGiftBatchInfo.Gifts != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.Gifts)
                {
                    productSysNos.Add(item.ProductSysNo.Value);
                }
            }

            List <ProductInfo> products = ExternalDomainBroker.GetProductInfoListByProductSysNoList(productSysNos);

            //将商品的相关信息,状态、价格信息等赋值给Item.
            RetryFunc <ProductItemInfo, int> copyItemInfo = (ProductItemInfo item) => {
                ProductInfo swapItem = products.Find(p => p.SysNo == item.ProductSysNo);
                if (swapItem != null)
                {
                    item.ProductStatus = swapItem.ProductStatus;
                    item.ProductID     = swapItem.ProductID;
                    item.ProductName   = swapItem.ProductName;
                    item.CurrentPrice  = swapItem.ProductPriceInfo.CurrentPrice.Value;
                    item.C3SysNo       = swapItem.ProductBasicInfo.ProductCategoryInfo.SysNo;
                    item.BrandSysNo    = swapItem.ProductBasicInfo.ProductBrandInfo.SysNo;
                }

                return(0);
            };



            if (saleGiftBatchInfo.ProductItems1 != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems1)
                {
                    copyItemInfo(item);
                }
            }

            if (saleGiftBatchInfo.ProductItems2 != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.ProductItems2)
                {
                    copyItemInfo(item);
                }
            }

            if (saleGiftBatchInfo.Gifts != null)
            {
                foreach (ProductItemInfo item in saleGiftBatchInfo.Gifts)
                {
                    copyItemInfo(item);
                }
            }
        }
        public void CheckComputerConfigInfo()
        {
            var computerConfigList = ObjectFactory <IComputerConfigQueryDA> .Instance.GetComputerConfigMasterList();

            var masterSysNoTmp = new List <int>();

            //分 Customer 和 NewEgg 配置单进行处理
            foreach (var computerConfig in computerConfigList)
            {
                foreach (var configItem in computerConfig.ConfigItemList)
                {
                    //邮件内容
                    string recordTmp = string.Empty;
                    var    hostEntry = Dns.GetHostEntry(Dns.GetHostName());
                    //判断是否是NewEgg配置单
                    if (computerConfig.CustomerSysNo < 0 && computerConfig.CreateUserSysNo == 0)
                    {
                        //是否库存不足或商品状态无效
                        if ((configItem.OnlineQty <= 0 || configItem.OnlineQty < configItem.ProductQty || configItem.ProductStatus != ProductStatus.Active) && !masterSysNoTmp.Contains(computerConfig.SysNo.Value))
                        {
                            using (var ts = new TransactionScope())
                            {
                                computerConfig.Status = ComputerConfigStatus.Void;
                                ObjectFactory <IComputerConfigDA> .Instance.SetComputerConfigMasterStatus(computerConfig);

                                ObjectFactory <IComputerConfigDA> .Instance.UpdateSaleRuleStatus(computerConfig);

                                masterSysNoTmp.Add(computerConfig.SysNo.Value);
                                recordTmp = (string.Format("\r\n由于商品\"{1}\"的库存或者状态有变化,配置单\"{0}\"状态已被修改为无效。" + "库存:{2} 商品状态:{3}"
                                                           , computerConfig.ComputerConfigName, configItem.ProductID, configItem.OnlineQty, GetProductStatusStr((int)configItem.ProductStatus)));
                                //写入日志
                                ExternalDomainBroker.CreateOperationLog(recordTmp, BizLogType.ComputerConfig_Void, computerConfig.SysNo.Value, computerConfig.CompanyCode);
                                //发送邮件
                                SendMail("配置单编辑", computerConfig.SysNo.Value, recordTmp, computerConfig.CompanyCode, computerConfig.CreateUserSysNo);
                                ts.Complete();
                            }
                        }
                    }
                    else
                    {
                        if (configItem.ProductStatus != 0 && configItem.ProductStatus != ProductStatus.Active && !masterSysNoTmp.Contains(computerConfig.SysNo.Value))
                        {
                            using (var ts = new TransactionScope())
                            {
                                computerConfig.Status = ComputerConfigStatus.Void;
                                ObjectFactory <IComputerConfigDA> .Instance.SetComputerConfigMasterStatus(computerConfig);

                                ObjectFactory <IComputerConfigDA> .Instance.UpdateSaleRuleStatus(computerConfig);

                                masterSysNoTmp.Add(computerConfig.SysNo.Value);
                                recordTmp = (string.Format("\r\n由于商品\"{1}\"的库存或者状态有变化,配置单\"{0}\"状态已被修改为无效。" + "状态:{3}"
                                                           , computerConfig.ComputerConfigName, configItem.ProductID, configItem.OnlineQty, GetProductStatusStr((int)configItem.ProductStatus)));
                                //写入日志
                                ExternalDomainBroker.CreateOperationLog(recordTmp, BizLogType.ComputerConfig_Void, computerConfig.SysNo.Value, computerConfig.CompanyCode);
                                //发送邮件
                                SendMail("配置单编辑", computerConfig.SysNo.Value, recordTmp, computerConfig.CompanyCode, computerConfig.CreateUserSysNo);
                                ts.Complete();
                            }
                        }
                    }
                }
            }
        }
        private void CheckData(BuyLimitRule data)
        {
            int sysNo = data.SysNo ?? 0;

            if (data.LimitType == LimitType.Combo)
            {
                //1.验证套餐是否存在
                var combo = ObjectFactory <ComboProcessor> .Instance.Load(data.ItemSysNo);

                if (combo == null)
                {
                    throw new BizException(string.Format(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_NotExistThisGroupBuy"), data.ItemSysNo));
                }
                //2.验证套餐是否已存在规则设置
                //CheckExistsRule(LimitType.Combo, "该套餐已存在相关限购规则,请不要重复设置。"
                //    , sysNo, data.ItemSysNo);
                CheckExistsRule(LimitType.Combo, ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_ExisitThisLimitRuleForGroupBuy")
                                , sysNo, data.ItemSysNo);
            }
            else
            {
                //1.验证商品是否存在
                var product = ExternalDomainBroker.GetProductInfo(data.ItemSysNo);
                if (product == null)
                {
                    //throw new BizException("商品不存在。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_NotExistProduct"));
                }
                //2.验证商品或其所属商品组是否已存在规则设置
                var        productInGroup = ExternalDomainBroker.GetProductsInSameGroupWithProductSysNo(data.ItemSysNo);
                List <int> productSysNos  = new List <int>(0);
                if (productInGroup != null && productInGroup.Count > 0)
                {
                    productSysNos = productInGroup.Select(item => item.SysNo).ToList();
                }
                else
                {
                    productSysNos.Add(data.ItemSysNo);
                }
                //CheckExistsRule(LimitType.SingleProduct, "该单品或其所属商品组已存在相关限购规则,请不要重复设置。"
                //    , sysNo, productSysNos.ToArray());
                CheckExistsRule(LimitType.SingleProduct, ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_ExisitThisLimitRuleForProduct")
                                , sysNo, productSysNos.ToArray());
            }
            if (data.EndDate <= data.BeginDate)
            {
                //throw new BizException("结束时间必须大于开始时间。");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_EndDateNeedMoreThanStartDate"));
            }
            if (data.EndDate.HasValue && data.EndDate.Value <= DateTime.Now)
            {
                //throw new BizException("结束时间必须大于当前时间。");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_EndDateNeedMoreThanCurrentDate"));
            }
            if (data.MinQty < 0)
            {
                //throw new BizException("限购下限必须大于等于零。");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_LowerLimitNeedMoreThan0"));
            }
            if (data.MaxQty < 0)
            {
                //throw new BizException("限购上限必须大于等于零。");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_UpperLimitNeedMoreThan0"));
            }
            if (data.MaxQty < data.MinQty)
            {
                //throw new BizException("限购上限必须大于等于限购下限");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_UpperLimitNeedMoreThanLowerLimit"));
            }

            if (data.OrderTimes < 0)
            {
                //throw new BizException("当日限购次数必须大于等于零。");
                throw new BizException(ResouceManager.GetMessageString("MKT.Promotion.BuyLimit", "BuyLimit_LimitCountNeedMoreThan0InCurrentDay"));
            }
        }
Exemple #25
0
        private void Validate(ProductRecommendInfo entity)
        {
            //大于等于100的PageType是首页Domain馆,对应的PageID应置为0
            if (entity.Location.PageType >= 100)
            {
                entity.Location.PageID = 0;
            }
            //如果PageID为空,则置为0
            if (!entity.Location.PageID.HasValue)
            {
                entity.Location.PageID = 0;
            }
            if (entity.BeginDate == DateTime.MinValue)
            {
                entity.BeginDate = null;
            }
            if (entity.EndDate == DateTime.MinValue)
            {
                entity.EndDate = null;
            }
            //验证商品状态必须为show
            ProductInfo product = ExternalDomainBroker.GetProductInfo(entity.ProductID);

            if (product == null)
            {
                //throw new BizException("商品不存在。");
                throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductNotExists"));
            }
            if (product.ProductStatus != ProductStatus.Active)
            {
                //throw new BizException("商品状态必须为上架状态。");
                throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductStatusNotValid"));
            }
            ////验证商品必须有库存OnlineQty>0
            //var inventory = ExternalDomainBroker.GetProductTotalInventoryInfo(entity.ProductSysNo);
            //if (inventory.OnlineQty <= 0)
            //{
            //    throw new BizException("商品库存不足。");
            //}


            //如果是首页新品推荐,验证商品FirstOnlineTime不能大于1天
            bool isNewRecommend = PageTypeUtil.IsProductRecommendHomePageNewPosition(entity.Location.PageType, entity.Location.PageID, entity.Location.PositionID);

            if (isNewRecommend)
            {
                if (!product.FirstOnSaleDate.HasValue || product.FirstOnSaleDate.Value < DateTime.Parse(DateTime.Now.AddDays(-1).ToLongDateString() + " 00:00:01"))
                {
                    //throw new BizException("请选择上架时间小于1天的商品进行维护。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductOnlineTimeInvalid"));
                }
            }

            //8.PageType=4,当类型是专卖店时判断description是否有重复的
            var presentationType = PageTypeUtil.ResolvePresentationType(ModuleType.ProductRecommend, entity.Location.PageType.ToString());

            //如果是专卖店,判断description是否有重复的
            if (presentationType == PageTypePresentationType.Brand)
            {
                if (product.ProductBasicInfo.ProductBrandInfo.SysNo != entity.Location.PageID)
                {
                    //throw new BizException("该产品不属于所选专卖店。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductBrandInvalid"));
                }
                if (_recommendDA.ExitsSameDescription(entity.Location) > 0)
                {
                    // throw new BizException("已存在相同的模块名称。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ExistsSameModuleName"));
                }
            }
            //如果是品牌专属或类别专属
            else if (presentationType == PageTypePresentationType.BrandExclusive)
            {
                if (product.ProductBasicInfo.ProductBrandInfo.SysNo != entity.Location.PageID)
                {
                    //throw new BizException("该产品不属于所选专卖店。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductBrandInvalid"));
                }
            }
            else if (presentationType == PageTypePresentationType.Merchant)
            {
                if (product.Merchant.MerchantID != entity.Location.PageID)
                {
                    //throw new BizException("该产品不属于所选商家。");
                    throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductMerchantInvalid"));
                }
            }
            else if (presentationType == PageTypePresentationType.Category3)
            {
                //-1表示默认类别,即不指定任何分类
                if (entity.Location.PageID.Value != -1)
                {
                    var ecC3 = ObjectFactory <ECCategoryProcessor> .Instance.Load(entity.Location.PageID.Value);

                    if (ecC3 == null || !ecC3.C3SysNo.HasValue)
                    {
                        //throw new BizException("请选择产品三级分类!");
                        throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_Category3NotNull"));
                    }
                    if (product.ProductBasicInfo.ProductCategoryInfo.SysNo != ecC3.C3SysNo)
                    {
                        //throw new BizException("该产品不属于所选分类。");
                        throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ProductCategoryInvalid"));
                    }
                }
            }

            if (CheckExists(entity))
            {
                //throw new BizException("已经存在同一位置同一时期的商品,请更换后重试。");
                throw new BizException(ResouceManager.GetMessageString("MKT.ProductRecommend", "ProductRecommend_ExistsSameProductRecommend"));
            }
        }
        /// <summary>
        /// 检查客户条件是否满足
        /// </summary>
        /// <param name="customerSysNo"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        protected virtual List <string> CheckCustomerCondition(SOInfo soInfo, PSCustomerCondition condition)
        {
            List <string> errorList = new List <string>();

            if (condition == null)
            {
                return(errorList);
            }
            CustomerInfo customerInfo = ExternalDomainBroker.GetCustomerInfo(soInfo.BaseInfo.CustomerSysNo.Value);

            if (customerInfo == null)
            {
                //throw new BizException("订单信息异常:找不到该客户的详细信息!");
                throw new BizException(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_NeedCustomerInfo"));
            }
            if (condition.NeedEmailVerification.HasValue && condition.NeedEmailVerification.Value)
            {
                if (customerInfo.BasicInfo.IsEmailConfirmed == null || !customerInfo.BasicInfo.IsEmailConfirmed.Value)
                {
                    //errorList.Add("该客户的Email未验证,不符合要求!");
                    errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_ErrorEmail"));
                    return(errorList);
                }
            }
            if (condition.NeedMobileVerification.HasValue && condition.NeedMobileVerification.Value)
            {
                if (customerInfo.BasicInfo.CellPhoneConfirmed == null || !customerInfo.BasicInfo.CellPhoneConfirmed.Value)
                {
                    //errorList.Add("该客户的手机未验证,不符合要求!");
                    errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_ErrorPhone"));
                    return(errorList);
                }
            }
            if (condition.InvalidForAmbassador.HasValue && condition.InvalidForAmbassador.Value)
            {
                if (customerInfo.AgentInfo != null)
                {
                    //errorList.Add("该活动泰隆优选大使不可参加!");
                    errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_CanntBeJoin"));
                    return(errorList);
                }
            }
            if (condition.RelAreas != null && condition.RelAreas.AreaList != null && condition.RelAreas.AreaList.Count > 0)
            {
                int      districtSysNo = customerInfo.BasicInfo.DwellAreaSysNo.Value;
                AreaInfo area          = ObjectFactory <ICommonBizInteract> .Instance.GetAreaInfo(districtSysNo);

                if (condition.RelAreas.AreaList.Find(f => f.SysNo == area.ProvinceSysNo) == null)
                {
                    //errorList.Add("该客户的所属地不在本活动的限定地区范围内!");
                    errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_ErrorArea"));
                    return(errorList);
                }
            }

            if (condition.RelCustomerRanks != null && condition.RelCustomerRanks.CustomerRankList != null && condition.RelCustomerRanks.CustomerRankList.Count > 0)
            {
                if (condition.RelCustomerRanks.CustomerRankList[0].SysNo.Value != -1)
                {
                    if (condition.RelCustomerRanks.CustomerRankList.Find(f => f.SysNo == (int)customerInfo.Rank.Value) == null)
                    {
                        //errorList.Add("该用户不在本活动的限定用户组范围内!");
                        errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_ErrorUser"));
                        return(errorList);
                    }
                }
            }

            if (condition.RelCustomers != null && condition.RelCustomers.CustomerIDList != null && condition.RelCustomers.CustomerIDList.Count > 0)
            {
                if (condition.RelCustomers.CustomerIDList.Find(f => f.CustomerSysNo == customerInfo.SysNo) == null)
                {
                    //errorList.Add("该用户不属于本活动的绑定用户!");
                    errorList.Add(ResouceManager.GetMessageString("MKT.Calculate", "Calculate_UserOutOfArry"));
                    return(errorList);
                }
            }

            return(errorList);
        }