Ejemplo n.º 1
0
        public JsonResult SaveBeautyYearCardConfig(BeautyYearCardModel request)
        {
            if (request == null)
            {
                return(Json(Tuple.Create(false, $"请求参数不能为空:{JsonConvert.SerializeObject(request)}")));
            }
            var result = BeautyYearCardConfigManger.Instanse.SaveBeautyYearCardConfig(request, User.Identity.Name);

            if (result)
            {
                return(Json(Tuple.Create(result, "")));
            }
            return(Json(Tuple.Create(result, "服务端执行异常!")));
        }
Ejemplo n.º 2
0
        public BeautyYearCardModel GetBeautyYearCardConfigDetail(int cardId)
        {
            BeautyYearCardModel result = null;

            try
            {
                result = DalBeautyYearCardConfig.GetBeautyYearCardConfig(cardId);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            //CreateBeautyYearCardConfig
            return(result);
        }
Ejemplo n.º 3
0
        public bool SaveBeautyYearCardConfig(BeautyYearCardModel model, string user)
        {
            try
            {
                if (model.PKID > 0)//编辑
                {
                    model.BeautyYearCardRegions.ForEach(f =>
                    {
                        f.CityId = (f.IsAllCity ? null : f.CityId);
                    });
                    var oldObject = GetBeautyYearCardConfigDetail(model.PKID);
                    var log       = new BeautyOprLog
                    {
                        LogType     = "UpdateBeautyYearCardConfig",
                        IdentityID  = $"{model.PKID}",
                        OldValue    = JsonConvert.SerializeObject(oldObject),
                        NewValue    = JsonConvert.SerializeObject(model),
                        Remarks     = $"更新美容年卡配置",
                        OperateUser = user,
                    };
                    model.BeautyYearCardRegions.ForEach(f =>
                    {
                        f.CityId = (f.IsAllCity ? null : f.CityId);
                    });
                    var result = DalBeautyYearCardConfig.UpdateBeautyYearCardConfig(model);

                    LoggerManager.InsertLog("BeautyOprLog", log);
                    return(result);
                }
                else//新增
                {
                    model.CardPrice = Math.Round(model.CardPrice);
                    using (var client = new ProductClient())
                    {
                        var product = DalBeautyYearCardConfig.GetParentProuductInfo(BeautyYearCardProductId);
                        if (product == null)
                        {
                            return(false);
                        }
                        var pid = client.CreateProductV2(new Service.Product.Models.WholeProductInfo
                        {
                            ProductID             = BeautyYearCardProductId,
                            Image_filename        = model.CardImageUrl,
                            Description           = model.CardName,
                            DefinitionName        = product.Item3,
                            PrimaryParentCategory = product.Item2,
                            CatalogName           = product.Item1,
                            DisplayName           = model.CardName,
                            Name               = model.CardName,
                            cy_list_price      = model.CardPrice,
                            cy_marketing_price = model.CardPrice,
                        },
                                                         user,
                                                         Service.Product.Enum.ChannelType.MenDian);
                        pid.ThrowIfException(true);
                        if (!string.IsNullOrEmpty(pid.Result))
                        {
                            model.PID = pid.Result;
                            model.BeautyYearCardRegions.ForEach(f =>
                            {
                                f.CityId = (f.IsAllCity ? null : f.CityId);
                            });
                            var result = DalBeautyYearCardConfig.CreateBeautyYearCardConfig(model);

                            var log = new BeautyOprLog
                            {
                                LogType     = "CreateBeautyYearCardConfig",
                                IdentityID  = $"{result}",
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(model),
                                Remarks     = $"创建美容年卡配置",
                                OperateUser = user,
                            };
                            LoggerManager.InsertLog("BeautyOprLog", log);
                            return(result > 0);
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"SaveBeautyYearCardConfig:{ex.Message}", ex);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static bool UpdateBeautyYearCardConfig(BeautyYearCardModel model)
        {
            #region sql
            const string sql       = @"Update  [Tuhu_groupon].[dbo].[ShopBeautyYearCardConfig] WITH(ROWLOCK)
 SET 
[CardName]=IsNULL(@CardName,CardName)
,[CardPrice]=IsNULL(@CardPrice,CardPrice)
,[PID]=IsNULL(@PID,PID)
,[CardImageUrl]=IsNULL(@CardImageUrl,CardImageUrl)
,[AdaptVehicle]=IsNULL(@AdaptVehicle,AdaptVehicle)
,[Remark]=IsNULL(@Remark,Remark)
,[Rule]=IsNULL(@Rule,[Rule])
,[SalesBeginTime]=IsNULL(@SalesBeginTime,SalesBeginTime)
,[SalesEndTime]=IsNULL(@SalesEndTime,SalesEndTime)
,[CardValidDays]=IsNULL(@CardValidDays,CardValidDays)
,[CardType]=IsNULL(@CardType,CardType) 
 WHERE PKID=@PKID";
            const string sqlPro    = @"UPDATE  [Tuhu_groupon].[dbo].[ShopBeautyYearCardProductsConfig] WITH(ROWLOCK)
 SET 
  [ProductId]=IsNULL(@ProductId,ProductId)
 ,[ProductName]=IsNULL(@ProductName,ProductName)
 ,[ProductNumber]=IsNULL(@ProductNumber,ProductNumber)
 ,[ProductPrice]=IsNULL(@ProductPrice,ProductPrice)
 ,[ProductDescription]=IsNULL(@ProductDescription,ProductDescription)
 ,[Commission]=IsNULL(@Commission,Commission)
 ,[UseCycle]=IsNULL(@UseCycle,UseCycle)
 ,[CycleType]=IsNULL(@CycleType,CycleType)
 ,[UpdateTime]=GETDATE()
 WHERE PKID=@PKID AND CardId=@CardId";
            const string regionDel = @"Delete from [Tuhu_groupon].[dbo].[ShopBeautyYearCardRegionConfig] where CardId=@CardId";

            const string sqlRegion = @"Insert Into [Tuhu_groupon].[dbo].[ShopBeautyYearCardRegionConfig]
([CardId]
 ,[ProvinceId]
 ,[CityId]
 ,[IsAllCity]
 ,[CreateTime]
 ,[UpdateTime])
 values(
 @CardId,
 @ProvinceId,
 @CityId,
 @IsAllCity,
GetDate(),
GetDate()
 )
";
            #endregion
            using (var db = new SqlDbHelper(strConn))
            {
                db.BeginTransaction();
                try
                {
                    #region CardConfig
                    var cardId = Convert.ToInt32(db.ExecuteNonQuery(sql,
                                                                    CommandType.Text,
                                                                    new SqlParameter[] {
                        new SqlParameter("@PKID", model.PKID),
                        new SqlParameter("@CardName", model.CardName),
                        new SqlParameter("@CardPrice", model.CardPrice),
                        new SqlParameter("@PID", model.PID),
                        new SqlParameter("@CardImageUrl", model.CardImageUrl),
                        new SqlParameter("@AdaptVehicle", model.AdaptVehicle),
                        new SqlParameter("@Remark", model.Remark),
                        new SqlParameter("@Rule", model.Rule),
                        new SqlParameter("@SalesBeginTime", model.SalesBeginTime),
                        new SqlParameter("@SalesEndTime", model.SalesEndTime),
                        new SqlParameter("@CardType", model.CardType),
                        new SqlParameter("@CardValidDays", model.CardValidDays)
                    }));
                    #endregion
                    if (cardId > 0 && model.BeautyYearCardProducts.Any())
                    {
                        #region proConfig
                        var proUpdate = true;
                        foreach (var f in model.BeautyYearCardProducts)
                        {
                            var proResult = Convert.ToInt32(db.ExecuteNonQuery(sqlPro,
                                                                               CommandType.Text,
                                                                               new SqlParameter[] {
                                new SqlParameter("@PKID", f.PKID),
                                new SqlParameter("@CardId", model.PKID),
                                new SqlParameter("@ProductId", f.ProductId),
                                new SqlParameter("@ProductName", f.ProductName),
                                new SqlParameter("@ProductDescription", f.ProductDescription),
                                new SqlParameter("@ProductNumber", f.ProductNumber),
                                new SqlParameter("@ProductPrice", f.ProductPrice),
                                new SqlParameter("@Commission", f.Commission),
                                new SqlParameter("@UseCycle", f.UseCycle),
                                new SqlParameter("@CycleType", f.CycleType)
                            }));
                            if (proResult <= 0)
                            {
                                db.Rollback();
                                proUpdate = false;
                                break;
                            }
                        }
                        #endregion
                        if (proUpdate && model.BeautyYearCardRegions.Any())
                        {
                            #region regConfig
                            var regInsert = true;
                            var delResult = Convert.ToInt32(db.ExecuteNonQuery(regionDel,
                                                                               CommandType.Text,
                                                                               new SqlParameter[] {
                                new SqlParameter("@CardId", model.PKID)
                            })
                                                            );
                            if (delResult > 0)
                            {
                                foreach (var e in model.BeautyYearCardRegions)
                                {
                                    var regResult = Convert.ToInt32(db.ExecuteNonQuery(sqlRegion,
                                                                                       CommandType.Text,
                                                                                       new SqlParameter[] { new SqlParameter("@CardId", model.PKID),
                                                                                                            new SqlParameter("@ProvinceId", e.ProvinceId),
                                                                                                            new SqlParameter("@CityId", (e.IsAllCity? null: e.CityId)),
                                                                                                            new SqlParameter("@IsAllCity", e.IsAllCity) }));
                                    if (regResult <= 0)
                                    {
                                        db.Rollback();
                                        regInsert = false;
                                        break;
                                    }
                                }
                                if (regInsert)
                                {
                                    db.Commit();
                                    return(true);
                                }
                            }
                            #endregion
                        }
                    }
                    db.Rollback();
                    return(false);
                }
                catch (Exception ex)
                {
                    db.Rollback();
                    throw ex;
                }
            }
        }
Ejemplo n.º 5
0
        public static int CreateBeautyYearCardConfig(BeautyYearCardModel model)
        {
            #region sql
            const string sql       = @"Insert Into [Tuhu_groupon].[dbo].[ShopBeautyYearCardConfig]
([CardName]
,[CardPrice]
,[PID]
,[CardImageUrl]
,[AdaptVehicle]
,[Remark]
,[Rule]
,[SalesBeginTime]
,[SalesEndTime]
,[CardValidDays]
,IsDeleted
,CreateTime
,UpdateTime
,CardType)
values(
@CardName,
@CardPrice,
@PID,
@CardImageUrl,
@AdaptVehicle,
@Remark,
@Rule,
@SalesBeginTime,
@SalesEndTime,
@CardValidDays,
0,
GetDate(),
GetDate(),
@CardType
);Select @@identity;";
            const string sqlPro    = @"Insert into [Tuhu_groupon].[dbo].[ShopBeautyYearCardProductsConfig]
([CardId]
 ,[ProductId]
 ,[ProductName]
 ,[ProductNumber]
 ,[ProductPrice]
 ,[ProductDescription]
 ,[Commission]
 ,[UseCycle]
 ,[CycleType]
 ,[IsDeleted]
 ,[CreateTime]
 ,[UpdateTime])
  values(
  @CardId,
@ProductId,
@ProductName,
@ProductNumber,
@ProductPrice,
@ProductDescription,
@Commission,
@UseCycle,
@CycleType,
0,
GetDate(),
GetDate()
  ) ";
            const string sqlRegion = @"Insert Into [Tuhu_groupon].[dbo].[ShopBeautyYearCardRegionConfig]
([CardId]
 ,[ProvinceId]
 ,[CityId]
 ,[IsAllCity]
 ,[CreateTime]
 ,[UpdateTime])
 values(
 @CardId,
 @ProvinceId,
 @CityId,
 @IsAllCity,
GetDate(),
GetDate()
 )";
            #endregion
            using (var db = new SqlDbHelper(strConn))
            {
                db.BeginTransaction();
                try
                {
                    #region CardConfig
                    var cardId = Convert.ToInt32(db.ExecuteScalar(sql,
                                                                  CommandType.Text,
                                                                  new SqlParameter[] { new SqlParameter("@CardName", model.CardName),
                                                                                       new SqlParameter("@CardPrice", model.CardPrice),
                                                                                       new SqlParameter("@PID", model.PID),
                                                                                       new SqlParameter("@CardImageUrl", model.CardImageUrl),
                                                                                       new SqlParameter("@AdaptVehicle", model.AdaptVehicle),
                                                                                       new SqlParameter("@Remark", model.Remark),
                                                                                       new SqlParameter("@Rule", model.Rule),
                                                                                       new SqlParameter("@SalesBeginTime", model.SalesBeginTime),
                                                                                       new SqlParameter("@SalesEndTime", model.SalesEndTime),
                                                                                       new SqlParameter("@CardType", model.CardType),
                                                                                       new SqlParameter("@CardValidDays", model.CardValidDays) }
                                                                  ));
                    #endregion
                    if (cardId > 0 && model.BeautyYearCardProducts.Any())
                    {
                        #region proConfig
                        var proInsert = true;
                        foreach (var f in model.BeautyYearCardProducts)
                        {
                            var proResult = Convert.ToInt32(db.ExecuteNonQuery(sqlPro,
                                                                               CommandType.Text,
                                                                               new SqlParameter[] { new SqlParameter("@CardId", cardId),
                                                                                                    new SqlParameter("@ProductId", f.ProductId),
                                                                                                    new SqlParameter("@ProductName", f.ProductName),
                                                                                                    new SqlParameter("@ProductDescription", f.ProductDescription),
                                                                                                    new SqlParameter("@ProductNumber", f.ProductNumber),
                                                                                                    new SqlParameter("@ProductPrice", f.ProductPrice),
                                                                                                    new SqlParameter("@Commission", f.Commission),
                                                                                                    new SqlParameter("@UseCycle", f.UseCycle),
                                                                                                    new SqlParameter("@CycleType", f.CycleType) }));
                            if (proResult <= 0)
                            {
                                db.Rollback();
                                proInsert = false;
                            }
                        }
                        #endregion
                        if (proInsert && model.BeautyYearCardRegions.Any())
                        {
                            #region regConfig

                            var regInsert = true;
                            foreach (var e in model.BeautyYearCardRegions)
                            {
                                var regResult = Convert.ToInt32(db.ExecuteNonQuery(sqlRegion,
                                                                                   CommandType.Text,
                                                                                   new SqlParameter[] { new SqlParameter("@CardId", cardId),
                                                                                                        new SqlParameter("@ProvinceId", e.ProvinceId),
                                                                                                        new SqlParameter("@CityId", (e.IsAllCity? null:e.CityId)),
                                                                                                        new SqlParameter("@IsAllCity", e.IsAllCity) }));
                                if (regResult <= 0)
                                {
                                    db.Rollback();
                                    regInsert = false;
                                }
                            }
                            if (regInsert)
                            {
                                db.Commit();
                                return(cardId);
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        db.Rollback();
                    }
                    return(0);
                }
                catch (Exception ex)
                {
                    db.Rollback();
                    throw ex;
                }
            }
        }