示例#1
0
        public void CreateGiftRules(ProductItemInfo productItem, BatchCreateGiftRuleInfo ruleInfo)
        {
            DataCommand dataCommand = DataCommandManager.GetDataCommand("SaleGift_CreateGiftRules");

            dataCommand.SetParameterValue("@PromotionSysNo", ruleInfo.PromotionSysNo);
            dataCommand.SetParameterValue("@ProductSysNo", productItem.ProductSysNo);
            dataCommand.SetParameterValue("@Count", productItem.HandselQty);
            dataCommand.SetParameterValue("@Priority", productItem.Priority);
            dataCommand.ExecuteNonQuery();
        }
        /// <summary>
        /// 检查赠品信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private void CheckGiftRules(BatchCreateGiftRuleInfo info)
        {
            if (info == null || info.ProductList == null || info.ProductList.Count == 0)
            {
                return;
            }
            var products =
                (from s in info.ProductList where (new decimal?[] { 0, 999999 }).Contains(s.CurrentPrice) select s).Select
                    (p => p.ProductID).ToArray();

            if (products.Length > 0)
            {
                //string errorMsg = "当前价格为0或999999的商品不能作为赠品 商品编号为" + products.Join(",");
                string errorMsg = ResouceManager.GetMessageString("MKT.Promotion.SaleGift", "SaleGift_GoodsNotAsGift") + products.Join(",");
                throw new BizException(errorMsg);
            }
        }
        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);
        }