コード例 #1
0
        public static FreeShippingChargeRuleInfo CreateMasterInfo(FreeShippingChargeRuleInfo entity)
        {
            DataCommand command = DataCommandManager.GetDataCommand("InsertFreeShippingChargeRule");

            command.SetParameterValue("@StartDate", entity.StartDate);
            command.SetParameterValue("@EndDate", entity.EndDate);
            command.SetParameterValue("@Status", entity.Status);
            command.SetParameterValue("@AmountSettingType", entity.AmountSettingType);
            command.SetParameterValue("@AmountSettingValue", entity.AmountSettingValue);
            command.SetParameterValue("@IsGlobal", entity.IsGlobal);
            command.SetParameterValue("@Description", entity.Description);
            command.SetParameterValue("@InUser", entity.InUserSysNo);
            command.SetParameterValue("@SellerSysNo", entity.SellerSysNo);

            string payTypeSettingValue = string.Empty;

            if (entity.PayTypeSettingValue != null)
            {
                payTypeSettingValue = ECommerce.DataAccess.Utility.StringUtility.Join(entity.PayTypeSettingValue, ",");
            }
            command.SetParameterValue("@PayTypeSettingValue", payTypeSettingValue);

            string shipAreaSettingValue = string.Empty;

            if (entity.ShipAreaSettingValue != null)
            {
                shipAreaSettingValue = ECommerce.DataAccess.Utility.StringUtility.Join(entity.ShipAreaSettingValue, ",");
            }
            command.SetParameterValue("@ShipAreaSettingValue", shipAreaSettingValue);

            entity.SysNo = Convert.ToInt32(command.ExecuteScalar());

            return(entity);
        }
コード例 #2
0
 public static void SettingValueMapper(DbDataReader reader, FreeShippingChargeRuleInfo entity)
 {
     if (!(reader["PayTypeSettingValueStr"] is DBNull) && reader["PayTypeSettingValueStr"] != null)
     {
         entity.PayTypeSettingValue = new List <SimpleObject>();
         foreach (string key in Convert.ToString(reader["PayTypeSettingValueStr"]).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         {
             entity.PayTypeSettingValue.Add(new SimpleObject()
             {
                 ID = key
             });
         }
     }
     if (!(reader["ShipAreaSettingValueStr"] is DBNull) && reader["ShipAreaSettingValueStr"] != null)
     {
         entity.ShipAreaSettingValue = new List <SimpleObject>();
         foreach (string key in Convert.ToString(reader["ShipAreaSettingValueStr"]).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
         {
             entity.ShipAreaSettingValue.Add(new SimpleObject()
             {
                 ID = key
             });
         }
     }
 }
コード例 #3
0
        public void Save(FreeShippingChargeRuleVM model, EventHandler <RestClientEventArgs <FreeShippingChargeRuleVM> > callback)
        {
            string relativeUrl = "/CommonService/FreeShippingChargeRule";

            FreeShippingChargeRuleInfo info = model.ConvertVM <FreeShippingChargeRuleVM, FreeShippingChargeRuleInfo>();

            if (!info.SysNo.HasValue)
            {
                restClient.Create <FreeShippingChargeRuleInfo>(relativeUrl + "/Create", info, (_, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    model = args.Result.Convert <FreeShippingChargeRuleInfo, FreeShippingChargeRuleVM>();
                    callback(this, new RestClientEventArgs <FreeShippingChargeRuleVM>(model, this.Page));
                });
            }
            else
            {
                restClient.Update(relativeUrl + "/Update", info, (_, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    callback(this, new RestClientEventArgs <FreeShippingChargeRuleVM>(model, this.Page));
                });
            }
        }
コード例 #4
0
        public static void UpdateMasterInfo(FreeShippingChargeRuleInfo entity)
        {
            DataCommand command = DataCommandManager.GetDataCommand("UpdateFreeShippingChargeRule");

            command.SetParameterValue("@SysNo", entity.SysNo);
            command.SetParameterValue("@StartDate", entity.StartDate);
            command.SetParameterValue("@EndDate", entity.EndDate);
            command.SetParameterValue("@AmountSettingType", entity.AmountSettingType);
            command.SetParameterValue("@AmountSettingValue", entity.AmountSettingValue);
            command.SetParameterValue("@IsGlobal", entity.IsGlobal);
            command.SetParameterValue("@Description", entity.Description);
            command.SetParameterValue("@EditUser", entity.EditUserSysNo);
            string payTypeSettingValue = string.Empty;

            if (entity.PayTypeSettingValue != null)
            {
                payTypeSettingValue = ECommerce.DataAccess.Utility.StringUtility.Join(entity.PayTypeSettingValue, ",");
            }
            command.SetParameterValue("@PayTypeSettingValue", payTypeSettingValue);

            string shipAreaSettingValue = string.Empty;

            if (entity.ShipAreaSettingValue != null)
            {
                shipAreaSettingValue = ECommerce.DataAccess.Utility.StringUtility.Join(entity.ShipAreaSettingValue, ",");
            }
            command.SetParameterValue("@ShipAreaSettingValue", shipAreaSettingValue);

            command.ExecuteNonQuery();
        }
コード例 #5
0
        public static void LoadRuleProductSettingValue(FreeShippingChargeRuleInfo entity)
        {
            DataCommand command = DataCommandManager.GetDataCommand("GetFreeShippingChargeRuleProductSettingValue");

            command.SetParameterValue("@RuleSysNo", entity.SysNo.Value);

            entity.ProductSettingValue = command.ExecuteEntityList <SimpleObject>();
        }
コード例 #6
0
        /// <summary>
        /// 新建或更新一条免运费规则前的预检查
        /// </summary>
        /// <param name="entity"></param>
        protected virtual void CreateOrUpdatePreCheck(FreeShippingChargeRuleInfo entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (!entity.StartDate.HasValue)
            {
                ThrowBizException("Res_StartDateIsRequired");
            }
            if (!entity.EndDate.HasValue)
            {
                ThrowBizException("Res_EndDateIsRequired");
            }
            if (!entity.AmountSettingType.HasValue)
            {
                ThrowBizException("Res_AmountSettingTypeIsRequired");
            }
            if (!entity.AmountSettingValue.HasValue)
            {
                ThrowBizException("Res_AmountSettingValueIsRequired");
            }
            if (!String.IsNullOrEmpty(entity.Description) && entity.Description.Length > 350)
            {
                ThrowBizException("Res_DescriptionMoreThan350Characters");
            }

            int tempValue;

            if (entity.PayTypeSettingValue != null)
            {
                if (entity.PayTypeSettingValue.Any(x => !int.TryParse(x.ID, out tempValue) || tempValue < 0))
                {
                    ThrowBizException("Res_PayTypeSettingValueIsIncorrect");
                }
            }
            if (entity.ShipAreaSettingValue != null)
            {
                if (entity.ShipAreaSettingValue.Any(x => !int.TryParse(x.ID, out tempValue) || tempValue < 0))
                {
                    ThrowBizException("Res_ShipAreaSettingValueIsIncorrect");
                }
            }

            if (!entity.IsGlobal)
            {
                if (entity.ProductSettingValue == null || entity.ProductSettingValue.Count <= 0)
                {
                    ThrowBizException("Res_UnGlobalModeProductSettingIsRequired");
                }
            }

            if (entity.Status == FreeShippingAmountSettingStatus.Active)
            {
                //检查冲突的免运费规则
                this.CheckConflictRule(entity);
            }
        }
コード例 #7
0
        public static void UpdateStatus(FreeShippingChargeRuleInfo entity, int UserSysNo)
        {
            DataCommand command = DataCommandManager.GetDataCommand("UpdateFreeShippingChargeRuleStatus");

            command.SetParameterValue("@SysNo", entity.SysNo);
            command.SetParameterValue("@Status", entity.Status);
            command.SetParameterValue("@EditUser", UserSysNo);
            command.ExecuteNonQuery();
        }
コード例 #8
0
        /// <summary>
        /// 创建一条免运费规则
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public virtual FreeShippingChargeRuleInfo Create(FreeShippingChargeRuleInfo entity)
        {
            //新建的规则设置状态为“无效”,防止不符合规则的规则立即生效
            entity.Status = FreeShippingAmountSettingStatus.DeActive;

            this.CreateOrUpdatePreCheck(entity);

            return(ObjectFactory <IFreeShippingChargeRuleDA> .Instance.Create(entity));
        }
コード例 #9
0
        /// <summary>
        /// 创建一条免运费规则
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static FreeShippingChargeRuleInfo Create(FreeShippingChargeRuleInfo entity)
        {
            //新建的规则设置状态为“无效”,防止不符合规则的规则立即生效
            entity.Status   = FreeShippingAmountSettingStatus.DeActive;
            entity.IsGlobal = false;

            CreateOrUpdatePreCheck(entity);

            return(FreeShippingChargeRuleDA.Create(entity));
        }
コード例 #10
0
 public static void UpdateInfo(FreeShippingChargeRuleInfo entity)
 {
     using (TransactionScope ts = new TransactionScope())
     {
         UpdateMasterInfo(entity);
         if (!entity.IsGlobal)
         {
             UpdateProductSettingValue(entity);
         }
         ts.Complete();
     }
 }
コード例 #11
0
        public static void UpdateProductSettingValue(FreeShippingChargeRuleInfo entity)
        {
            DeleteRuleAllProductSettingValue(entity.SysNo.Value);

            if (entity.ProductSettingValue != null && entity.ProductSettingValue.Count > 0)
            {
                foreach (var item in entity.ProductSettingValue)
                {
                    CreateRuleProductSettingItemValue(entity.SysNo.Value, item);
                }
            }
        }
コード例 #12
0
        public ActionResult FreeShippingMaintain()
        {
            var sysNo = Request.QueryString["sysNo"];
            int id;
            FreeShippingChargeRuleInfo data = null;

            if (sysNo != null && int.TryParse(sysNo, out id))
            {
                var loginUser = UserAuthHelper.GetCurrentUser();
                data = FreeShippingChargeRuleService.Load(id, loginUser.SellerSysNo);
            }
            ViewBag.Data = new JavaScriptSerializer().Serialize(data);
            return(View());
        }
コード例 #13
0
        public static FreeShippingChargeRuleInfo Create(FreeShippingChargeRuleInfo entity)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                entity = CreateMasterInfo(entity);
                if (!entity.IsGlobal)
                {
                    UpdateProductSettingValue(entity);
                }
                ts.Complete();
            }
            LoadRuleProductSettingValue(entity);

            return(entity);
        }
コード例 #14
0
        public FreeShippingChargeRuleInfo Load(int sysno)
        {
            DataCommand command = DataCommandManager.GetDataCommand("GetFreeShippingChargeRuleBySysNo");

            command.SetParameterValue("@SysNo", sysno);

            FreeShippingChargeRuleInfo info = command.ExecuteEntity <FreeShippingChargeRuleInfo>(SettingValueMapper);

            this.SetMultipleSettingValue(new List <FreeShippingChargeRuleInfo>()
            {
                info
            });

            return(info);
        }
コード例 #15
0
        /// <summary>
        /// 删除一条无效的免运费规则
        /// </summary>
        /// <param name="sysno"></param>
        public virtual void Delete(int sysno)
        {
            FreeShippingChargeRuleInfo info = this.Load(sysno);

            if (info == null)
            {
                ThrowBizException("Res_FreeShippingChargeRuleIsNotExist", sysno);
            }

            if (info.Status != FreeShippingAmountSettingStatus.DeActive)
            {
                ThrowBizException("Res_OnlyInvalidStatusCanBeDelete");
            }

            ObjectFactory <IFreeShippingChargeRuleDA> .Instance.Delete(info.SysNo.Value);
        }
コード例 #16
0
        /// <summary>
        /// 删除一条无效的免运费规则
        /// </summary>
        /// <param name="sysno"></param>
        public static void Delete(int sysno, int SellerSysNo)
        {
            FreeShippingChargeRuleInfo info = Load(sysno, SellerSysNo);

            if (info == null)
            {
                throw new BusinessException(LanguageHelper.GetText("编号为{0}的免运费规则不存在!"), sysno);
            }

            if (info.Status != FreeShippingAmountSettingStatus.DeActive)
            {
                throw new BusinessException("只有“无效”状态的免运费规则才能删除!");
            }

            FreeShippingChargeRuleDA.Delete(info.SysNo.Value);
        }
コード例 #17
0
        /// <summary>
        /// 设置一条免运费规则为无效状态
        /// </summary>
        /// <param name="sysno"></param>
        public virtual void Invalid(int sysno)
        {
            FreeShippingChargeRuleInfo info = this.Load(sysno);

            if (info == null)
            {
                ThrowBizException("Res_FreeShippingChargeRuleIsNotExist", sysno);
            }

            if (info.Status != FreeShippingAmountSettingStatus.Active)
            {
                ThrowBizException("Res_OnlyValidStatusCanSetToBeInvalidStatus");
            }

            info.Status = FreeShippingAmountSettingStatus.DeActive;
            ObjectFactory <IFreeShippingChargeRuleDA> .Instance.UpdateStatus(info);
        }
コード例 #18
0
        /// <summary>
        /// 设置一条免运费规则为无效状态
        /// </summary>
        /// <param name="sysno"></param>
        public static void Invalid(int sysno, int SellerSysNo, int UserSysNo)
        {
            FreeShippingChargeRuleInfo info = Load(sysno, SellerSysNo);

            if (info == null)
            {
                throw new BusinessException(LanguageHelper.GetText("编号为{0}的免运费规则不存在!"), sysno);
            }

            if (info.Status != FreeShippingAmountSettingStatus.Active)
            {
                throw new BusinessException("只有“有效”状态的免运费规则才能设置为无效!");
            }

            info.Status = FreeShippingAmountSettingStatus.DeActive;
            FreeShippingChargeRuleDA.UpdateStatus(info, UserSysNo);
        }
コード例 #19
0
        /// <summary>
        /// 更新一条免运费规则
        /// </summary>
        /// <param name="entity"></param>
        public static void Update(FreeShippingChargeRuleInfo entity)
        {
            FreeShippingChargeRuleInfo info = Load(entity.SysNo.Value, entity.SellerSysNo.Value);

            if (info == null)
            {
                throw new BusinessException(LanguageHelper.GetText("编号为{0}的免运费规则不存在!"), entity.SysNo);
            }

            if (info.Status == FreeShippingAmountSettingStatus.Active)
            {
                throw new BusinessException("只有“无效”状态的免运费规则才能编辑!");
            }
            entity.IsGlobal = false;
            CreateOrUpdatePreCheck(entity);

            FreeShippingChargeRuleDA.UpdateInfo(entity);
        }
コード例 #20
0
        /// <summary>
        /// 更新一条免运费规则
        /// </summary>
        /// <param name="entity"></param>
        public virtual void Update(FreeShippingChargeRuleInfo entity)
        {
            FreeShippingChargeRuleInfo info = this.Load(entity.SysNo.Value);

            if (info == null)
            {
                ThrowBizException("Res_FreeShippingChargeRuleIsNotExist", entity.SysNo);
            }

            if (info.Status == FreeShippingAmountSettingStatus.Active)
            {
                ThrowBizException("Res_OnlyInvalidStatusCanBeEdit");
            }

            this.CreateOrUpdatePreCheck(entity);

            ObjectFactory <IFreeShippingChargeRuleDA> .Instance.UpdateInfo(entity);
        }
コード例 #21
0
        public ActionResult FreeShippingChargeRuleSave()
        {
            FreeShippingChargeRuleInfo info = SerializationUtility.JsonDeserialize2 <FreeShippingChargeRuleInfo>(Request.Form["data"]);
            var loginUser = UserAuthHelper.GetCurrentUser();

            info.SellerSysNo   = loginUser.SellerSysNo;
            info.InUserSysNo   = loginUser.UserSysNo;
            info.InUserName    = loginUser.UserDisplayName;
            info.EditUserSysNo = loginUser.UserSysNo;
            info.EditUserName  = loginUser.UserDisplayName;
            if (info.SysNo > 0)
            {
                FreeShippingChargeRuleService.Update(info);
                return(JsonSuccess(info.SysNo.Value, LanguageHelper.GetText("更新成功。")));
            }
            else
            {
                FreeShippingChargeRuleService.Create(info);
                return(JsonSuccess(info.SysNo.Value, LanguageHelper.GetText("创建成功。")));
            }
        }
コード例 #22
0
        /// <summary>
        /// 检查冲突的规则
        /// </summary>
        /// <param name="entity"></param>
        private void CheckConflictRule(FreeShippingChargeRuleInfo entity)
        {
            List <FreeShippingChargeRuleInfo> allValidRules =
                ObjectFactory <IFreeShippingChargeRuleDA> .Instance.GetAllByStatus(FreeShippingAmountSettingStatus.Active);

            allValidRules.RemoveAll(x => x.SysNo == entity.SysNo);

            if (allValidRules != null && allValidRules.Count > 0)
            {
                List <FreeShippingChargeRuleInfo> checkList = new List <FreeShippingChargeRuleInfo>();
                List <SimpleObject> conflictList            = new List <SimpleObject>();

                // 1. 找出有相同时间段的规则
                foreach (var ruleItem in allValidRules)
                {
                    if (entity.StartDate >= ruleItem.StartDate && entity.EndDate <= ruleItem.EndDate)
                    {
                        checkList.Add(ruleItem);
                    }
                    else if (entity.StartDate <= ruleItem.StartDate && entity.EndDate >= ruleItem.StartDate)
                    {
                        checkList.Add(ruleItem);
                    }
                    else if (entity.StartDate <= ruleItem.EndDate && entity.EndDate >= ruleItem.EndDate)
                    {
                        checkList.Add(ruleItem);
                    }
                }

                if (HasElements(entity.PayTypeSettingValue) || HasElements(entity.ShipAreaSettingValue))
                {
                    SimpleObjectEqualityComparer comparer = new SimpleObjectEqualityComparer();

                    for (var index = checkList.Count - 1; index >= 0; index--)
                    {
                        var          rule           = checkList[index];
                        bool         conflict       = false;
                        SimpleObject conflictObject = null;

                        //2.  检查这些规则是否和当前规则有相同的支付方式
                        if (HasElements(entity.PayTypeSettingValue) && HasElements(rule.PayTypeSettingValue))
                        {
                            var intersect = entity.PayTypeSettingValue.Intersect(rule.PayTypeSettingValue, comparer);
                            if (intersect != null && intersect.Count() > 0)
                            {
                                conflict = true;
                                //冲突的支付方式:{0} !
                                conflictObject = new SimpleObject()
                                {
                                    ID         = rule.SysNo.ToString(),
                                    BakString1 = GetMessageString("Res_ConflictPayType", String.Join(",", intersect.Select(x => x.Name)))
                                };
                            }
                        }
                        else
                        {
                            //没有配置支付方式表示不限定配送方式,相当于entity和rule具有相同的支付方式设置,支付方式冲突
                            conflict       = true;
                            conflictObject = new SimpleObject()
                            {
                                ID         = rule.SysNo.ToString(),
                                BakString1 = GetMessageString("Res_ConflictAllPayType")
                            };
                        }

                        //2.  检查这些规则是否和当前规则有相同的配送区域
                        if (HasElements(entity.ShipAreaSettingValue) && HasElements(rule.ShipAreaSettingValue))
                        {
                            var intersect = entity.ShipAreaSettingValue.Intersect(rule.ShipAreaSettingValue, comparer);
                            if (intersect != null && intersect.Count() > 0)
                            {
                                if (conflict)
                                {
                                    //冲突的配送区域:{0} !
                                    conflictObject.BakString1 = string.Format("{0} {1}", conflictObject.BakString1
                                                                              , GetMessageString("Res_ConflictShipArea", String.Join(",", intersect.Select(x => x.Name))));
                                }
                            }
                            else
                            {
                                conflict       = false;
                                conflictObject = null;
                            }
                        }
                        else
                        {
                            if (conflict)
                            {
                                //冲突的配送区域
                                conflictObject.BakString1 = string.Format("{0} {1}", conflictObject.BakString1
                                                                          , GetMessageString("Res_ConflictAllShipArea"));
                            }
                        }

                        if (conflict)
                        {
                            conflictList.Add(conflictObject);
                            break;
                        }
                    }
                }
                else
                {
                    if (checkList.Count > 0)
                    {
                        var checkItem = checkList.First();
                        //冲突的时间范围:{1:yyyy-MM-dd} - {2:yyyy-MM-dd} !
                        conflictList.Add(new SimpleObject()
                        {
                            ID         = checkItem.SysNo.ToString(),
                            BakString1 = GetMessageString("Res_ConflictTimeRange", checkItem.StartDate, checkItem.EndDate)
                        });
                    }
                }

                if (conflictList.Count > 0)
                {
                    var conflictRuleItem = conflictList.First();
                    ThrowBizException("Res_ConflictCheckResult", conflictRuleItem.ID, conflictRuleItem.BakString1);
                }
            }
        }
コード例 #23
0
 public void UpdateRule(FreeShippingChargeRuleInfo entity)
 {
     ObjectFactory <FreeShippingChargeRuleAppService> .Instance.Update(entity);
 }
コード例 #24
0
 public FreeShippingChargeRuleInfo CreateRule(FreeShippingChargeRuleInfo entity)
 {
     return(ObjectFactory <FreeShippingChargeRuleAppService> .Instance.Create(entity));
 }
コード例 #25
0
 /// <summary>
 /// 更新一条免运费规则
 /// </summary>
 /// <param name="entity">免运费规则DTO</param>
 public virtual void Update(FreeShippingChargeRuleInfo entity)
 {
     ObjectFactory <FreeShippingChargeRuleProcessor> .Instance.Update(entity);
 }
コード例 #26
0
 /// <summary>
 /// 创建一条免运费规则
 /// </summary>
 /// <param name="entity">免运费规则DTO</param>
 /// <returns>免运费规则</returns>
 public virtual FreeShippingChargeRuleInfo Create(FreeShippingChargeRuleInfo entity)
 {
     return(ObjectFactory <FreeShippingChargeRuleProcessor> .Instance.Create(entity));
 }
コード例 #27
0
        /// <summary>
        /// 新建或更新一条免运费规则前的预检查
        /// </summary>
        /// <param name="entity"></param>
        protected static void CreateOrUpdatePreCheck(FreeShippingChargeRuleInfo entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (!entity.StartDate.HasValue)
            {
                throw new BusinessException("开始日期不能为空!");
            }
            if (!entity.EndDate.HasValue)
            {
                throw new BusinessException("结束日期不能为空!");
            }
            if (entity.StartDate.Value > entity.EndDate.Value)
            {
                throw new BusinessException("开始日期不能大于结束日期!");
            }
            if (!entity.AmountSettingType.HasValue)
            {
                throw new BusinessException("免运费条件金额类型不能为空!");
            }
            if (!entity.AmountSettingValue.HasValue)
            {
                throw new BusinessException("免运费条件的门槛金额不能为空!");
            }
            if (!String.IsNullOrEmpty(entity.Description) && entity.Description.Length > 350)
            {
                throw new BusinessException("免运费规则描述不能超过350个字符!");
            }

            int tempValue;

            if (entity.PayTypeSettingValue != null)
            {
                if (entity.PayTypeSettingValue.Any(x => !int.TryParse(x.ID, out tempValue) || tempValue < 0))
                {
                    throw new BusinessException("支付类型不正确!");
                }
            }
            if (entity.ShipAreaSettingValue != null)
            {
                if (entity.ShipAreaSettingValue.Any(x => !int.TryParse(x.ID, out tempValue) || tempValue < 0))
                {
                    throw new BusinessException("配送区域不正确!");
                }
            }

            if (entity.ProductSettingValue != null)
            {
                if (entity.ProductSettingValue == null || entity.ProductSettingValue.Count <= 0)
                {
                    throw new BusinessException("请添加至少一个免运费商品!");
                }
            }

            if (!entity.IsGlobal)
            {
                if (entity.ProductSettingValue == null || entity.ProductSettingValue.Count <= 0)
                {
                    throw new BusinessException("非全网模式必须设置免运费商品!");
                }
            }

            if (entity.Status == FreeShippingAmountSettingStatus.Active)
            {
                //检查冲突的免运费规则
                CheckConflictRule(entity);
            }
        }
コード例 #28
0
        /// <summary>
        /// 检查冲突的规则
        /// </summary>
        /// <param name="entity"></param>
        private static void CheckConflictRule(FreeShippingChargeRuleInfo entity)
        {
            List <FreeShippingChargeRuleInfo> allValidRules =
                FreeShippingChargeRuleDA.GetAllByStatus(FreeShippingAmountSettingStatus.Active, entity.SellerSysNo.Value);

            allValidRules.RemoveAll(x => x.SysNo == entity.SysNo);
            if (allValidRules != null && allValidRules.Count > 0)
            {
                List <FreeShippingChargeRuleInfo> checkList = new List <FreeShippingChargeRuleInfo>();
                List <SimpleObject> conflictList            = new List <SimpleObject>();
                // 1. 找出有相同时间段的规则
                foreach (var ruleItem in allValidRules)
                {
                    if (entity.StartDate >= ruleItem.StartDate && entity.EndDate <= ruleItem.EndDate)
                    {
                        checkList.Add(ruleItem);
                    }
                    else if (entity.StartDate <= ruleItem.StartDate && entity.EndDate >= ruleItem.StartDate)
                    {
                        checkList.Add(ruleItem);
                    }
                    else if (entity.StartDate <= ruleItem.EndDate && entity.EndDate >= ruleItem.EndDate)
                    {
                        checkList.Add(ruleItem);
                    }
                }
                #region  旧逻辑 现在不用

                /*if (HasElements(entity.PayTypeSettingValue) || HasElements(entity.ShipAreaSettingValue))
                 * {
                 *  SimpleObjectEqualityComparer comparer = new SimpleObjectEqualityComparer();
                 *
                 *  for (var index = checkList.Count - 1; index >= 0; index--)
                 *  {
                 *      var rule = checkList[index];
                 *      bool conflict = false;
                 *      SimpleObject conflictObject = null;
                 *
                 *      //2.  检查这些规则是否和当前规则有相同的支付方式
                 *      if (HasElements(entity.PayTypeSettingValue) && HasElements(rule.PayTypeSettingValue))
                 *      {
                 *          var intersect = entity.PayTypeSettingValue.Intersect(rule.PayTypeSettingValue, comparer);
                 *          if (intersect != null && intersect.Count() > 0)
                 *          {
                 *              conflict = true;
                 *              //冲突的支付方式:{0} !
                 *              conflictObject = new SimpleObject()
                 *              {
                 *                  ID = rule.SysNo.ToString(),
                 *                  BakString1 = string.Format("冲突的支付方式:{0} !", String.Join(",", intersect.Select(x => x.Name)))
                 *              };
                 *          }
                 *      }
                 *      else
                 *      {
                 *          //没有配置支付方式表示不限定配送方式,相当于entity和rule具有相同的支付方式设置,支付方式冲突
                 *          conflict = true;
                 *          conflictObject = new SimpleObject()
                 *          {
                 *              ID = rule.SysNo.ToString(),
                 *              BakString1 = "支付方式冲突 !"
                 *          };
                 *      }
                 *
                 *      //2.  检查这些规则是否和当前规则有相同的配送区域
                 *      if (HasElements(entity.ShipAreaSettingValue) && HasElements(rule.ShipAreaSettingValue))
                 *      {
                 *          var intersect = entity.ShipAreaSettingValue.Intersect(rule.ShipAreaSettingValue, comparer);
                 *          if (intersect != null && intersect.Count() > 0)
                 *          {
                 *              if (conflict)
                 *              {
                 *                  //冲突的配送区域:{0} !
                 *                  conflictObject.BakString1 = string.Format("{0} {1}", conflictObject.BakString1
                 *                      , string.Format("冲突的配送区域:{0} !", String.Join(",", intersect.Select(x => x.Name))));
                 *              }
                 *          }
                 *          else
                 *          {
                 *              conflict = false;
                 *              conflictObject = null;
                 *          }
                 *      }
                 *      else
                 *      {
                 *          if (conflict)
                 *          {
                 *              //冲突的配送区域
                 *              conflictObject.BakString1 = string.Format("{0} {1}", conflictObject.BakString1
                 *                  , "配送区域冲突!");
                 *          }
                 *      }
                 *
                 *      if (conflict)
                 *      {
                 *          conflictList.Add(conflictObject);
                 *          break;
                 *      }
                 *  }
                 * }
                 * else
                 * {
                 *  if (checkList.Count > 0)
                 *  {
                 *      var checkItem = checkList.First();
                 *      //冲突的时间范围:{1:yyyy-MM-dd} - {2:yyyy-MM-dd} !
                 *      conflictList.Add(new SimpleObject()
                 *      {
                 *          ID = checkItem.SysNo.ToString(),
                 *          BakString1 = string.Format("冲突的时间范围:{0:yyyy-MM-dd} - {1:yyyy-MM-dd} !", checkItem.StartDate, checkItem.EndDate)
                 *      });
                 *  }
                 * }*/
                #endregion
                if (checkList.Count > 0)
                {
                    SimpleObjectEqualityComparer comparer = new SimpleObjectEqualityComparer();
                    foreach (var checkitem in checkList)
                    {
                        bool         conflict       = false;
                        SimpleObject conflictObject = null;
                        var          Intersect      = checkitem.ProductSettingValue.Intersect(entity.ProductSettingValue, comparer);
                        if (Intersect != null && Intersect.Count() > 0)
                        {
                            conflict       = true;
                            conflictObject = new SimpleObject()
                            {
                                ID         = checkitem.SysNo.ToString(),
                                BakString1 = string.Format("冲突的商品:{0} !", String.Join(",", Intersect.Select(x => x.Name)))
                            };
                        }
                        if (conflict)
                        {
                            conflictList.Add(conflictObject);
                            break;
                        }
                    }
                }
                if (conflictList.Count > 0)
                {
                    var conflictRuleItem = conflictList.First();
                    throw new BusinessException("存在冲突的免运费规则:编号为{0},{1} ", conflictRuleItem.ID, conflictRuleItem.BakString1);
                }
            }
        }