Esempio n. 1
0
 public async Task <List <Merchant> > GetMerchantsAsync(string merchantName, SettlementMethod settlementMethod, bool status)
 {
     throw new System.NotImplementedException();
 }
        public ActionResult AddOrUpdateRedeemMrCodeConfig(RedeemMrCodeConfig config)
        {
            Func <string> validatedFun = () =>
            {
                if (config == null)
                {
                    return("参数不能为空");
                }

                if (string.IsNullOrEmpty(config.Name))
                {
                    return("名称不能为空");
                }
                SettlementMethod SettlementMethod;
                if (string.IsNullOrEmpty(config.SettlementMethod) ||
                    !Enum.TryParse(config.SettlementMethod, out SettlementMethod) ||
                    SettlementMethod == SettlementMethod.None)
                {
                    return("结算方式不是有效的值");
                }

                if (config.SettlementPrice <= 0.0M || config.ShopCommission < 0 || config.ShopCommission >= 1)
                {
                    return("结算价不能小于0并且佣金比必须再0~1之间");
                }

                if (config.CodeTypeConfigId <= 0 || config.Num <= 0)
                {
                    return("必须选择一个服务并且服务数量不能小于1");
                }
                var startTime    = config.StartTime.GetValueOrDefault().Date;
                var endTime      = config.EndTime.GetValueOrDefault().Date.AddDays(1).AddSeconds(-1);
                var effectiveDay = config.EffectiveDay.GetValueOrDefault();
                if (((startTime == DateTime.MinValue || endTime == DateTime.MinValue) && effectiveDay <= 0) ||
                    (startTime > DateTime.MinValue && endTime > startTime && effectiveDay > 0) ||
                    (startTime > DateTime.MinValue && endTime < startTime))
                {
                    return("时间范围和兑换后天数必须填一个,并且只能填一个;时间范围必须有效,天数必须大于0");
                }
                config.Name             = config.Name.Trim();
                config.SettlementMethod = SettlementMethod.ToString();
                if (effectiveDay > 0)
                {
                    config.EffectiveDay = effectiveDay;
                    config.StartTime    = null;
                    config.EndTime      = null;
                }
                else
                {
                    config.EffectiveDay = null;
                    config.StartTime    = startTime;
                    config.EndTime      = endTime;
                }
                if (manager.IsExistsRedeemMrCodeConfig(config))
                {
                    return("该配置名称已经存在");
                }
                var temp_config = manager.GetRedemptionCodeConfig(config.RedemptionConfigId);
                if (temp_config != null && temp_config.GroupId != null && !config.IsRequired)
                {
                    return("配置了群组的模板,模板详情内容都应该必选");
                }
                var redemption = manager.GetRedemptionCodeConfig(config.RedemptionConfigId);
                if (redemption != null && redemption.SumQuantity > 0)
                {
                    if (config.PKID <= 0)
                    {
                        return("兑换码已生成,不允许新加项目");
                    }
                    var oldValue = manager.GetRedeemMrCodeConfig(config.PKID);
                    if (oldValue == null)
                    {
                        return("参数有误");
                    }
                    if (oldValue.CodeTypeConfigId != config.CodeTypeConfigId || !string.Equals(oldValue.SettlementMethod, config.SettlementMethod) ||
                        oldValue.SettlementPrice != config.SettlementPrice || oldValue.ShopCommission != config.ShopCommission ||
                        oldValue.Num != config.Num || oldValue.EffectiveDay != config.EffectiveDay || (oldValue.StartTime != null && config.StartTime != oldValue.StartTime) ||
                        (oldValue.EndTime != null && config.EndTime != oldValue.EndTime) ||
                        !string.Equals(oldValue.SettlementMethod, config.SettlementMethod) || oldValue.Num != config.Num ||
                        oldValue.IsActive != config.IsActive)
                    {
                        return("兑换码已生成,关键信息不允许修改");
                    }
                }
                return(string.Empty);
            };
            var validatedResult = validatedFun();

            if (!string.IsNullOrEmpty(validatedResult))
            {
                return(Json(new { status = false, msg = validatedResult }));
            }
            bool result = config.PKID <= 0 ? manager.AddRedeemMrCodeConfig(config, User.Identity.Name)
                : manager.UpdateRedeemMrCodeConfig(config, User.Identity.Name);

            return(Json(new { status = result }));
        }