Exemplo n.º 1
0
        public object UpdateRedeemPromotionConfig(RedeemPromotionConfig config, string userName)
        {
            var result = false;

            try
            {
                var oldConfig = GetRedeemPromotionConfig(config.PKID);
                if (config != null)
                {
                    result = DbTuhuGrouponScopeManager.Execute(conn => DALUnivRedemptionCode.UpdateRedeemPromotionConfig(conn, config));
                }
                if (result)
                {
                    InsertBeautyOprLog(new
                    {
                        LogType     = RedeemPromotionConfigType,
                        IdentityID  = config.PKID,
                        OldValue    = JsonConvert.SerializeObject(oldConfig),
                        NewValue    = JsonConvert.SerializeObject(config),
                        OperateUser = userName,
                        Remarks     = "更新",
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error(nameof(UpdateRedeemPromotionConfig), ex);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static bool UpdateRedeemPromotionConfig(SqlConnection conn, RedeemPromotionConfig config)
        {
            const string sql   = @"UPDATE  Tuhu_groupon..RedeemPromotionConfig
SET     Name = @Name ,
        GetRuleGuid = @GetRuleGuid ,
        BusinessType = @BusinessType ,
        PackageId = @PackageId ,
        Num = @Num ,
        SettlementMethod = @SettlementMethod ,
        SettlementPrice = @SettlementPrice ,
        IsRequired = @IsRequired ,
        IsActive = @IsActive ,
        Description = @Description ,
        UpdateTime = GETDATE()
WHERE   PKID = @PKID;";
            var          count = conn.Execute(sql, new
            {
                config.PKID,
                config.GetRuleGuid,
                config.BusinessType,
                config.PackageId,
                config.Num,
                config.Name,
                config.SettlementMethod,
                config.SettlementPrice,
                config.IsRequired,
                config.IsActive,
                config.Description
            }, commandType: CommandType.Text);

            return(count > 0);
        }
Exemplo n.º 3
0
        public object AddRedeemPromotionConfig(RedeemPromotionConfig config, string userName)
        {
            var result = false;

            try
            {
                config.PKID = DbTuhuGrouponScopeManager.Execute(conn => DALUnivRedemptionCode.AddRedeemPromotionConfig(conn, config));
                result      = config.PKID > 0;
                if (result)
                {
                    InsertBeautyOprLog(new
                    {
                        LogType     = RedeemPromotionConfigType,
                        IdentityID  = config.PKID,
                        NewValue    = JsonConvert.SerializeObject(config),
                        OldValue    = string.Empty,
                        OperateUser = userName,
                        Remarks     = "添加",
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Error(nameof(AddRedeemPromotionConfig), ex);
            }
            return(result);
        }
Exemplo n.º 4
0
        public static bool DeleteRedeemPromotionConfig(SqlConnection conn, RedeemPromotionConfig config)
        {
            const string sql   = @"DELETE  FROM Tuhu_groupon..RedeemPromotionConfig WHERE   PKID = @PKID;";
            var          count = conn.Execute(sql, new { config.PKID, config.Name }, commandType: CommandType.Text);

            return(count > 0);
        }
Exemplo n.º 5
0
        public static bool IsExistsRedeemPromotionConfig(SqlConnection conn, RedeemPromotionConfig config)
        {
            const string sql   = @"SELECT  COUNT(1)
FROM    Tuhu_groupon..RedeemPromotionConfig AS c WITH ( NOLOCK )
WHERE   c.PKID <> @PKID
        AND c.Name = @Name;";
            var          count = conn.ExecuteScalar(sql, new { config.PKID, config.Name }, commandType: CommandType.Text);

            return(Convert.ToInt32(count) > 0);
        }
Exemplo n.º 6
0
        public bool IsExistsRedeemPromotionConfig(RedeemPromotionConfig config)
        {
            bool result = true;

            try
            {
                result = DbTuhuGrouponScopeReadManager.Execute(conn => DALUnivRedemptionCode.IsExistsRedeemPromotionConfig(conn, config));
            }
            catch (Exception ex)
            {
                Logger.Error(nameof(IsExistsRedeemPromotionConfig), ex);
            }
            return(result);
        }
Exemplo n.º 7
0
        public static int AddRedeemPromotionConfig(SqlConnection conn, RedeemPromotionConfig config)
        {
            const string sql  = @"INSERT  INTO Tuhu_groupon..RedeemPromotionConfig
        ( RedemptionConfigId ,
          Name ,
          GetRuleGuid ,
          BusinessType ,
          PackageId ,
          Num ,
          SettlementMethod ,
          SettlementPrice ,
          IsRequired ,
          IsActive ,
          Description ,
          CreateTime ,
          UpdateTime
        )
VALUES  ( @RedemptionConfigId ,
          @Name ,
          @GetRuleGuid ,
          @BusinessType ,
          @PackageId ,
          @Num ,
          @SettlementMethod ,
          @SettlementPrice ,
          @IsRequired ,
          @IsActive ,
          @Description ,
          GETDATE() ,
          GETDATE()
        );";
            var          pkid = conn.Execute(sql, new
            {
                config.PKID,
                config.GetRuleGuid,
                config.BusinessType,
                config.PackageId,
                config.Num,
                config.Name,
                config.SettlementMethod,
                config.SettlementPrice,
                config.IsRequired,
                config.IsActive,
                config.Description,
                config.RedemptionConfigId,
            }, commandType: CommandType.Text);

            return(pkid);
        }
Exemplo n.º 8
0
        public RedeemPromotionConfig GetRedeemPromotionConfig(int id)
        {
            RedeemPromotionConfig result = null;

            try
            {
                result = DbTuhuGrouponScopeReadManager.Execute(conn => DALUnivRedemptionCode.SelectRedeemPromotionConfig(conn, id));
                if (result != null)
                {
                    var coupon = GetCouponRules(new[] { result.GetRuleGuid })?.FirstOrDefault();
                    if (coupon != null)
                    {
                        result.CouponDescription = $"{coupon.PKID}-{coupon.PromotionName}-{coupon.Description}";
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(nameof(GetRedeemPromotionConfig), ex);
            }
            return(result);
        }
        public ActionResult AddOrUpdateRedeemPromotionConfig(RedeemPromotionConfig config)
        {
            Func <string> validatedFun = () =>
            {
                if (config == null)
                {
                    return("参数不能为空");
                }
                if (string.IsNullOrWhiteSpace(config.Name))
                {
                    return("名称不能为空");
                }
                BusinessType type;
                if (string.IsNullOrWhiteSpace(config.BusinessType) || !Enum.TryParse(config.BusinessType, out type) || type == BusinessType.None)
                {
                    return("业务类型不是有效的值");
                }
                if ((type == BusinessType.AnnualInspectionPackage ||
                     type == BusinessType.BaoYangPackage ||
                     type == BusinessType.PaintPackage) && config.PackageId <= 0)
                {
                    return("业务为套餐流程的时候必须选择一个套餐");
                }
                if (config.SettlementPrice <= 0)
                {
                    return("大客户结算价是必填的并且必须大于0");
                }
                if (config.Num <= 0)
                {
                    return("数量是必填的并且必须大于0");
                }
                if (manager.IsExistsRedeemPromotionConfig(config))
                {
                    return("该配置已经存在");
                }
                var redemption = manager.GetRedemptionCodeConfig(config.RedemptionConfigId);
                if (redemption != null && redemption.SumQuantity > 0)
                {
                    if (config.PKID <= 0)
                    {
                        return("兑换码已生成,不允许新加项目");
                    }
                    var oldValue = manager.GetRedeemPromotionConfig(config.PKID);
                    if (oldValue == null)
                    {
                        return("参数有误");
                    }
                    if (!string.Equals(oldValue.BusinessType, config.BusinessType) || !string.Equals(oldValue.GetRuleGuid, config.GetRuleGuid) ||
                        oldValue.SettlementPrice != config.SettlementPrice || oldValue.PackageId != config.PackageId ||
                        !string.Equals(oldValue.SettlementMethod, config.SettlementMethod) || oldValue.Num != config.Num ||
                        oldValue.IsActive != config.IsActive)
                    {
                        return("兑换码已生成,关键信息不允许修改");
                    }
                }
                config.Name         = config.Name.Trim();
                config.BusinessType = type.ToString();
                return(string.Empty);
            };
            var validatedResult = validatedFun();

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

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