Beispiel #1
0
        /// <summary>
        /// 添加保养套餐
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public bool InsertVipBaoYangPackage(VipBaoYangPackageViewModel package)
        {
            var result    = false;
            var productId = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var pkid = DALVipBaoYangPackage.InsertVipBaoYangPackage(conn, new VipBaoYangPackageDbModel(package));
                    if (pkid > 0)
                    {
                        productId = $"BY-TUHU-BXGSDCBY|{pkid.ToString()}";
                        result    = DALVipBaoYangPackage.UpdateVipBaoYangPackagePID(conn, pkid, productId) > 0;
                    }
                    if (result)
                    {
                        package.PKID = pkid;
                        package.PID  = productId;
                        VipBaoYangPackageService.CreateProduct(pkid.ToString(), package.PackageName, package.CreateUser);
                    }
                });

                if (result)
                {
                    InsertLog(productId, null, JsonConvert.SerializeObject(package), "Insert", package.CreateUser);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }
Beispiel #2
0
        public bool BatchAddBeautyCode(List <CreateBeautyCodeTaskModel> list, int mappindId, string type, string userName, string sha1)
        {
            var success = false;

            try
            {
                var batchCode = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                list.ForEach(x =>
                {
                    x.CreateUser = userName;
                    x.Type       = "serviceCode";
                    x.MappingId  = mappindId;
                    x.BatchCode  = batchCode;
                    x.Status     = "Created";
                });
                TuhuGrouponDbScopeManager.CreateTransaction(conn =>
                {
                    success = handler.BatchAddBeautyCode(conn, list);
                    if (success)
                    {
                        handler.UpdateBeautyCodeStatus(conn, batchCode, "Preparing");
                        SetUploadedFileSah1Cache(sha1);
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error("BatchAddBeautyCode", ex);
            }
            return(success);
        }
        public Tuple <bool, bool> AddBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels)
        {
            var result      = false;
            var cacheResult = true;

            try
            {
                dbScopeManagerConfig.CreateTransaction(conn =>
                {
                    var fastDeliveryId = DalBatteryFastDelivery.AddBatteryFastDelivery(conn, model);
                    if (fastDeliveryId > 0)
                    {
                        if (productModels != null && productModels.Any())
                        {
                            foreach (var productModel in productModels)
                            {
                                productModel.FastDeliveryId = fastDeliveryId;
                                var insertResult            = DalBatteryFastDelivery.AddBatteryFastDeliveryProducts(conn, productModel);
                            }
                            cacheResult = RefreshFastDeliveryServiceCache(model.RegionId, productModels.Select(s => s.ProductPid).ToList());
                        }
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error("AddBatteryFastDelivery", ex);
            }
            return(Tuple.Create(result, cacheResult));
        }
Beispiel #4
0
        /// <summary>
        /// 批量删除选车攻略配置
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool MultDeleteVehicleArticle(List <VehicleArticleModel> models)
        {
            var result = true;

            try
            {
                var delList = new List <VehicleArticleModel>();
                var logs    = new List <VehicleArticleOprLogModel>();
                foreach (var model in models)
                {
                    var oldValue = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                           DalVehicleArticle.GetVehicleArticle(conn, model));
                    if (oldValue != null)
                    {
                        delList.Add(oldValue);
                        var log = new VehicleArticleOprLogModel
                        {
                            LogType       = "VehicleArticle",
                            IdentityId    = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}",
                            OperationType = "Delete",
                            OldValue      = JsonConvert.SerializeObject(oldValue),
                            NewValue      = null,
                            Remarks       = $"删除选车攻略:{ model.VehicleId }_{ model.PaiLiang }_{ model.Nian }的配置",
                            Operator      = _user
                        };
                        logs.Add(log);
                    }
                }
                if (delList.Any())
                {
                    dbScopeManagerConfiguration.CreateTransaction(conn =>
                    {
                        foreach (var model in delList)
                        {
                            var delResult = DalVehicleArticle.DeleteVehicleArticle(conn, model.PKID);
                            if (!delResult)
                            {
                                throw new Exception($"DeleteVehicleArticle失败," +
                                                    $"待删除数据:{JsonConvert.SerializeObject(model)}");
                            }
                        }
                        result = true;
                    });
                }
                if (result && logs.Any())
                {
                    logs.ForEach(s => LoggerManager.InsertLog("VehicleArticleOprLog", s));
                }
            }
            catch (Exception ex)
            {
                result = false;
                Logger.Error("MultDeleteVehicleArticle", ex);
            }
            return(result);
        }
Beispiel #5
0
        public Tuple <bool, string> InsertRebateConfig(RebateConfigModel data, string user)
        {
            var result = 0;
            var msg    = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var existedData = DALRebateConfig.SelectRebateApplyConfigByParam(conn, data);

                    if (String.Equals(data.Source, "Rebate25"))
                    {
                        existedData = existedData.Where(_ => String.Equals(_.Source, "Rebate25")).ToList();
                        if (existedData?.Where(x => String.Equals(x.OrderId, data.OrderId)).Count() > 0 ||
                            existedData?.Where(x => String.Equals(x.UserPhone, data.UserPhone)).Count() > 0)
                        {
                            data.Remarks += "  重复返现";
                        }
                        data.RebateMoney = 25M;
                        data.Status      = Status.Complete;
                        data.RebateTime  = DateTime.Now;
                        data.PKID        = DALRebateConfig.InsertRebateConfig(conn, data);
                        if (data.PKID > 0 && data.ImgList != null && data.ImgList.Any())
                        {
                            foreach (var item in data.ImgList)
                            {
                                DALRebateConfig.InsertRebateImgConfig(conn, data.PKID, item.ImgUrl, ImgSource.UserImg, string.Empty);
                            }
                        }
                        result = data.PKID;
                    }
                    else
                    {
                        existedData = existedData.Where(_ => String.Equals(_.Source, "爱卡") || String.Equals(_.Source, "汽车之家")).ToList();
                        if (existedData?.Where(x => String.Equals(x.OrderId, data.OrderId)).Count() > 0 ||
                            existedData?.Where(x => String.Equals(x.UserPhone, data.UserPhone)).Count() > 0)
                        {
                            msg = "每个客户只能参与一次(包含手机号、订单号、微信号)均视为同一客户";
                        }
                        else
                        {
                            data.RebateMoney = 58M;
                            data.Status      = Status.Applying;
                            result           = DALRebateConfig.InsertRebateConfig(conn, data);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            InsertLog(result.ToString(), "InsertRebateConfig", result > 0 ? "添加成功" : "添加失败", $"PKID:{result.ToString()},Status:Applying", string.Empty, string.Empty, user);
            return(Tuple.Create(result > 0, msg));
        }
Beispiel #6
0
        /// <summary>
        /// 上传覆盖区域
        /// </summary>
        /// <param name="models"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <bool> UploadBatterCoverArea(List <VendorProductCoverAreaModel> models, string user)
        {
            var result = false;

            try
            {
                var insertList = new List <VendorProductCoverAreaModel>();
                var updateList = new List <VendorProductCoverAreaModel>();
                var logs       = new List <OprVendorProductModel>();
                foreach (var model in models)
                {
                    var oldValue = _dbScopeManagerConfigRead.Execute(conn =>
                                                                     _dal.GetVendorProductConverAreaByBrand(conn, model));
                    if (oldValue != null)
                    {
                        updateList.Add(model);
                        model.PKID = oldValue.PKID;
                        logs.Add(new OprVendorProductModel()
                        {
                            LogType        = "VendorProductCoverArea",
                            IdentityId     = $"{model.ProductType}_{model.CoverType}_{model.CoverRegionId}_{model.Brand ?? model.Pid}",
                            OldValue       = JsonConvert.SerializeObject(oldValue),
                            NewValue       = JsonConvert.SerializeObject(model),
                            CreateDateTime = DateTime.Now,
                            Remarks        = "Update",
                            OperateUser    = user
                        });
                    }
                    else
                    {
                        insertList.Add(model);
                    }
                }
                _dbScopeManagerConfig.CreateTransaction(conn =>
                {
                    if (insertList.Any() || updateList.Any())
                    {
                        result = UplnsertBatterCoverArea(insertList, updateList, logs, user);
                    }
                });
                if (result)
                {
                    await RemoveCache(models);
                }
            }
            catch (Exception ex)
            {
                _logger.Error("UploadBatterCoverArea", ex);
            }
            return(result);
        }
        public bool UpdateInstallTypeConfig(InstallTypeConfig config, string user)
        {
            bool result = false;

            if (config != null)
            {
                try
                {
                    string packageType = config.PackageType;
                    string imageUrl    = config.ImageUrl;

                    var prevData = GetInstallTypeConfigs();

                    dbScopeManager.CreateTransaction(conn =>
                    {
                        dalInstallType.UpdateImage(conn, packageType, imageUrl);
                        foreach (var installType in config.InstallTypes)
                        {
                            installType.TextFormat = JsonConvert.SerializeObject(installType.TextFormats);
                            dalInstallType.Update(conn, packageType, installType.Type, installType.IsDefault, installType.TextFormat);
                        }

                        result = true;
                    });

                    if (result)
                    {
                        var resultData = GetInstallTypeConfigs();
                        var log        = new
                        {
                            ObjectId    = packageType,
                            ObjectType  = "UpdateBaoYangInstallType",
                            BeforeValue = JsonConvert.SerializeObject(prevData.FirstOrDefault(o => string.Equals(o.PackageType, packageType))),
                            AfterValue  = JsonConvert.SerializeObject(resultData.FirstOrDefault(o => string.Equals(o.PackageType, packageType))),
                            Remark      = "",
                            Creator     = user
                        };
                        LoggerManager.InsertLog("CommonConfigLog", log);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }
            }

            return(result);
        }
        /// <summary>
        /// 插入透明工场配置记录
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool ImportLiveWorkShopConfig(List <LiveWorkShopConfigModel> models)
        {
            var result = false;

            try
            {
                var existsConfig = dbScopeManagerConfigRead.Execute(conn => DalLiveWorkShopConfig.GetExistLiveWorkShopConfig(conn));
                var delConfig    = existsConfig.Where(s => !models.Any(m => string.Equals(m.TypeName, s.TypeName) && m.SortNumber == s.SortNumber)).Select(v => v.PKID).ToList();
                dbScopeManagerConfig.CreateTransaction(conn =>
                {
                    foreach (var model in models)
                    {
                        DalLiveWorkShopConfig.ImportLiveWorkShopConfig(conn, model);
                    }
                    foreach (var pkid in delConfig)
                    {
                        DalLiveWorkShopConfig.DeleteLiveWorkShopConfig(conn, pkid);
                    }
                });
                result = true;
            }
            catch (Exception ex)
            {
                Logger.Error("ImportLiveWorkShopConfig", ex);
            }
            return(result);
        }
        public bool DeletedCompanyClientConfig(int pkid, string user)
        {
            var result = false;
            CompanyClientConfig data = null;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    data = DALCompanyClient.SelectCompanyClientConfigByPkid(conn, pkid);
                    if (data != null)
                    {
                        DALCompanyClient.DeletedCompanyClientConfig(conn, pkid);
                        DALCompanyClient.DeletedCouponCodeByPkid(conn, pkid);
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Log(Level.Error, ex, "DeletedCompanyClientConfig");
            }

            InsertLog("DeletedCompanyClientConfig", pkid.ToString(), JsonConvert.SerializeObject(data), result ? "删除成功" : "删除失败", user);

            return(result);
        }
        /// <summary>
        /// 编辑三方码信息
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public Tuple <bool, string> UpsertCodeSourceConfig(ServiceCodeSourceConfig config)
        {
            var result = false;
            var msg    = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    if (config.PKID > 0)
                    {
                        result = DALThirdParty.UpdateServiceCodeSourceConfig(conn, config);
                    }
                    else
                    {
                        var allSourceConfigs = DALThirdParty.GetServiceCodeSourceConfigBySource(conn, config.Source);
                        if (allSourceConfigs != null && allSourceConfigs.Any())
                        {
                            msg = "服务码来源重复";
                        }
                        else
                        {
                            result = DALThirdParty.InsertServiceCodeSourceConfig(conn, config);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                msg = "服务异常";
                Logger.Error(ex);
            }
            return(Tuple.Create(result, msg));
        }
Beispiel #11
0
        /// <summary>
        /// 根据ID 删除单个模型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BaoYangResultEntity <bool> > DeleteChannelConfigsByConfigId(int id, string name)
        {
            var result = new BaoYangResultEntity <bool>()
            {
                Status = false
            };

            try
            {
                var oldModel = GetCouponActivityConfig(id).Data;
                await RemoveCouponActivityConfigCache(id);

                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    if (DalCouponActivityConfigV2.DeleteCouponActivityConfig(conn, id))
                    {
                        var configIds = new List <int> {
                            id
                        };
                        result.Data   = DalCouponActivityConfigV2.DeleteChannelConfigsByConfigId(conn, configIds);
                        result.Status = true;
                        result.Data   = true;
                    }
                    else
                    {
                        result.Data = false;
                    }
                });
                if (result.Status && oldModel != null)
                {
                    SaveCouponActivityConfigLog(oldModel, null, name);
                }
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }
            return(result);
        }
        public static bool UpdateInsuranceIndex(List <int> insuranceIds)
        {
            bool success = false;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var index = 0;
                    foreach (var insuranceId in insuranceIds)
                    {
                        DalCarInsuranceConfig.UpdateInsuranceIndex(conn, insuranceId, ++index);
                    }
                    success = true;
                });
            }
            catch (Exception ex)
            {
                Logger.Error("UpdateInsuranceIndex", ex);
            }
            return(success);
        }
        public bool UpdateStatusForComplete(int pkid, string user)
        {
            var result = false;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var data = DALRebateConfig.SelectRebateConfigByPKID(conn, pkid);
                    if (data.Status == Status.Approved || ((String.Equals(data.Source, "爱卡") || String.Equals(data.Source, "汽车之家")) && data.Status == Status.Applying))
                    {
                        result = DALRebateConfig.UpdateStatusForComplete(conn, pkid) > 0;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            InsertLog(pkid.ToString(), "UpdateStatusForComplete", result ? "成功" : "失败", $"PKID:{pkid.ToString()},Status:Complete", string.Empty, string.Empty, user);
            return(result);
        }
        /// <summary>
        /// 删除活动其对应的活动页
        /// </summary>
        /// <param name="activityId"></param>
        /// <returns></returns>
        public bool DeleteActivity(Guid activityId)
        {
            var result = false;

            try
            {
                ConfigurationDb.CreateTransaction(conn =>
                {
                    if (!DalCityActivityPageConfig.DeleteActivityByActivityId(conn, activityId))
                    {
                        result = false;
                    }
                    DalCityActivityPageConfig.DeleteActivityUrlByActivityId(conn, activityId);
                    result = true;
                });
            }
            catch (Exception ex)
            {
                result = false;
                Logger.Error("deleteActivity", ex);
            }
            return(result);
        }
        public int UpdateGroupConfig(DianpingGroupConfig groupConfig, string user)
        {
            int result = 0;

            if (groupConfig != null)
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    int rows    = 0;
                    var current = dalGroupConfig.SelectDianpingGroupConfig(conn, groupConfig.DianpingGroupId);
                    if (current != null)
                    {
                        rows   = dalGroupConfig.Update(conn, groupConfig);
                        result = rows == 1 ? 1 : 0;
                        if (result == 1)
                        {
                            var log = new
                            {
                                ObjectId    = groupConfig.DianpingGroupId,
                                ObjectType  = "UpdateGroupConfig",
                                BeforeValue = JsonConvert.SerializeObject(current),
                                AfterValue  = JsonConvert.SerializeObject(groupConfig),
                                Remark      = "",
                                Creator     = user
                            };
                            LoggerManager.InsertLog("CommonConfigLog", log);
                        }
                    }
                    else
                    {
                        result = -1;
                    }
                });
            }

            return(result);
        }
        private bool BatchUpdateBatteryCoverArea(List <BaoYangBatteryCoverArea> list)
        {
            var success = false;

            dbScopeManagerBaoYang.CreateTransaction(conn =>
            {
                foreach (var item in list)
                {
                    if (item.PKID > 0)
                    {
                        _battery.UpdateBaoYangBatteryCoverArea(conn, item);
                    }
                    else
                    {
                        item.PKID = _battery.AddBaoYangBatteryCoverArea(conn, item);
                    }
                }
                success = true;
            });
            return(success);
        }
        /// <summary>
        /// 新增对应关系
        /// </summary>
        /// <param name="data"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Tuple <bool, string> UpsertPingAnRegionPackageMap(PingAnRegionPackageMap data, string user)
        {
            var result = false;
            var msg    = "";

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var allConfig = DALRegionPackageMap.GetAllPingAnRegionPackageMapList(conn);
                    var isExist   = false;
                    if (!string.IsNullOrEmpty(data.BYPackagePID))
                    {
                        isExist = allConfig?.Where(_ => String.Equals(_.BYPackagePID, data.BYPackagePID))?.Count() > 0;
                    }
                    else if (data.PackageId != null && data.PackageId != Guid.Empty)
                    {
                        isExist = allConfig?.Where(_ => String.Equals(_.PackageId, data.PackageId))?.Count() > 0;
                    }
                    data.RegionId = data.CityId > 0 ? data.CityId : (data.ProvinceId > 0 ? data.ProvinceId : 0);
                    if (!isExist)
                    {
                        result = DALRegionPackageMap.InsertPingAnRegionPackageMap(conn, data);
                    }
                    else
                    {
                        msg = "该美容包或保养套餐已存在关联关系";
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            return(Tuple.Create(result, msg));
        }
Beispiel #18
0
        /// <summary>
        /// 批量新增或更新保养活动车型配置
        /// </summary>
        /// <param name="vehicleIds"></param>
        /// <param name="activityId"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Tuple <bool, bool> MultiAddOrEditBaoYangActivityVehicle(List <string> vehicleIds, string activityId, string user)
        {
            bool result      = false;
            var  cacheResult = false;

            try
            {
                if (vehicleIds != null && vehicleIds.Any() && !string.IsNullOrWhiteSpace(activityId))
                {
                    var insertModels = new List <BaoYangActivityVehicleAndRegionModel>();
                    var updateValues = new List <BaoYangActivityVehicleAndRegionModel>();
                    var logData      = new List <BaoYangOprLog>();
                    foreach (var vehicleId in vehicleIds)
                    {
                        var oldValue = GetBaoYangActivityVehicleByVehicleId(vehicleId);
                        if (oldValue == null)
                        {
                            var insertModel = new BaoYangActivityVehicleAndRegionModel
                            {
                                VehicleId          = vehicleId,
                                ActivityId         = activityId,
                                RegionId           = 0,
                                Type               = "Vehicle",
                                CreateDateTime     = DateTime.Now,
                                LastUpdateDateTime = DateTime.Now
                            };
                            insertModels.Add(insertModel);
                        }
                        else
                        {
                            updateValues.Add(oldValue);
                        }
                    }
                    dbScopeManagerGungnir.CreateTransaction(conn =>
                    {
                        foreach (var insertModel in insertModels)
                        {
                            var pkid = DalBaoYangActivitySetting.AddBaoYangActivityVehicle(conn, insertModel);
                            if (pkid < 1)
                            {
                                throw new Exception($"AddBaoYangActivityVehicle失败,{JsonConvert.SerializeObject(insertModel)}");
                            }
                            insertModel.PKID = pkid;
                            var log          = new BaoYangOprLog
                            {
                                LogType     = "BaoYangActivityVehicle",
                                IdentityID  = insertModel.VehicleId,
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(insertModel),
                                Remarks     = "Add",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        foreach (var oldValue in updateValues)
                        {
                            var updateModel = new BaoYangActivityVehicleAndRegionModel
                            {
                                VehicleId          = oldValue.VehicleId,
                                ActivityId         = activityId,
                                RegionId           = oldValue.RegionId,
                                Type               = oldValue.Type,
                                CreateDateTime     = oldValue.CreateDateTime,
                                LastUpdateDateTime = DateTime.Now
                            };
                            var updateResult = DalBaoYangActivitySetting.UpdateBaoYangActivityVehicle(conn, updateModel);
                            if (!updateResult)
                            {
                                throw new Exception($"UpdateBaoYangActivityVehicle失败,{JsonConvert.SerializeObject(updateModel)}");
                            }
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangActivityVehicle",
                                IdentityID  = updateModel.VehicleId,
                                OldValue    = JsonConvert.SerializeObject(oldValue),
                                NewValue    = JsonConvert.SerializeObject(updateModel),
                                Remarks     = "Update",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        result = true;
                    });
                    foreach (var log in logData)
                    {
                        LoggerManager.InsertLog("BYOprLog", log);
                    }
                    cacheResult = CleanBaoYangActivityVehicleCache(vehicleIds);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("MultiAddOrEditBaoYangActivityVehicle", ex);
            }
            return(Tuple.Create(result, cacheResult));
        }
Beispiel #19
0
        /// <summary>
        /// 批量新增或更新机油粘度特殊地区配置
        /// </summary>
        /// <param name="regionIds"></param>
        /// <param name="oilViscosity"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool MultAddOrEditOilViscosityRegionConfig(List <int> regionIds, string oilViscosity, string user)
        {
            var result = false;

            try
            {
                if (regionIds != null && regionIds.Any() && !string.IsNullOrWhiteSpace(oilViscosity))
                {
                    var insertModels = new List <OilViscosityRegionModel>();
                    var backupModels = new List <OilViscosityRegionModel>();
                    var updateModels = new List <OilViscosityRegionModel>();
                    var logData      = new List <BaoYangOprLog>();
                    foreach (var regionId in regionIds)
                    {
                        var oldValue = GetOilViscosityRegionConfigByRegionId(regionId);
                        if (oldValue == null)
                        {
                            var insertModel = new OilViscosityRegionModel
                            {
                                RegionId           = regionId,
                                OilViscosity       = oilViscosity,
                                CreateDateTime     = DateTime.Now,
                                LastUpdateDateTime = DateTime.Now
                            };
                            insertModels.Add(insertModel);
                        }
                        else
                        {
                            if (oldValue.IsDeleted)
                            {
                                backupModels.Add(oldValue);
                            }
                            else
                            {
                                updateModels.Add(oldValue);
                            }
                        }
                    }
                    dbScopeManagerGungnir.CreateTransaction(conn =>
                    {
                        foreach (var insertModel in insertModels)
                        {
                            var pkid = DalBaoYangOilViscosityPriorityConfig.AddOilViscosityRegionConfig(conn, insertModel);
                            if (pkid < 1)
                            {
                                throw new Exception($"AddOilViscosityRegionConfig失败,{JsonConvert.SerializeObject(insertModel)}");
                            }
                            insertModel.PKID = pkid;
                            var log          = new BaoYangOprLog
                            {
                                LogType     = "OilViscosityRegionConfig",
                                IdentityID  = insertModel.RegionId.ToString(),
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(insertModel),
                                Remarks     = $"添加机油粘度配置:{oilViscosity}",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        foreach (var oldValue in updateModels)
                        {
                            var updateModel = new OilViscosityRegionModel
                            {
                                PKID               = oldValue.PKID,
                                RegionId           = oldValue.RegionId,
                                OilViscosity       = oilViscosity,
                                CreateDateTime     = oldValue.CreateDateTime,
                                LastUpdateDateTime = DateTime.Now,
                                IsDeleted          = false
                            };
                            var updateResult = DalBaoYangOilViscosityPriorityConfig.UpdateOilViscosityRegionConfig(conn, updateModel);
                            if (!updateResult)
                            {
                                throw new Exception($"UpdateOilViscosityRegionConfig失败,{JsonConvert.SerializeObject(updateModel)}");
                            }

                            var log = new BaoYangOprLog
                            {
                                LogType     = "OilViscosityRegionConfig",
                                IdentityID  = updateModel.RegionId.ToString(),
                                OldValue    = JsonConvert.SerializeObject(oldValue),
                                NewValue    = JsonConvert.SerializeObject(updateModel),
                                Remarks     = $"更新机油粘度配置:{oilViscosity}",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        foreach (var backupModel in backupModels)
                        {
                            var updateModel = new OilViscosityRegionModel
                            {
                                PKID               = backupModel.PKID,
                                RegionId           = backupModel.RegionId,
                                OilViscosity       = oilViscosity,
                                CreateDateTime     = backupModel.CreateDateTime,
                                LastUpdateDateTime = DateTime.Now,
                                IsDeleted          = false
                            };
                            var updateResult = DalBaoYangOilViscosityPriorityConfig.UpdateOilViscosityRegionConfig(conn, updateModel);
                            if (!updateResult)
                            {
                                throw new Exception($"UpdateOilViscosityRegionConfig失败,{JsonConvert.SerializeObject(updateModel)}");
                            }

                            var log = new BaoYangOprLog
                            {
                                LogType     = "OilViscosityRegionConfig",
                                IdentityID  = updateModel.RegionId.ToString(),
                                OldValue    = JsonConvert.SerializeObject(backupModel),
                                NewValue    = JsonConvert.SerializeObject(updateModel),
                                Remarks     = $"添加机油粘度配置:{oilViscosity}",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        result = true;
                    });
                    foreach (var log in logData)
                    {
                        LoggerManager.InsertLog("BYOprLog", log);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("MultiAddOrEditOilViscosityRegionConfig", ex);
            }
            return(result);
        }
        /// <summary>
        /// 批量添加或更新蓄电池券后价展示配置
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool MultUpSertBatteryCouponPriceDisplay(List <BatteryCouponPriceDisplayModel> models)
        {
            var result = false;

            try
            {
                var logs       = new List <BatteryOprLogModel>();
                var addList    = new List <BatteryCouponPriceDisplayModel>();
                var updateList = new List <BatteryCouponPriceDisplayModel>();
                foreach (var model in models)
                {
                    var oldValue = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                           _dal.GetBatteryCouponPriceDisplay(conn, model.Pid));
                    if (oldValue != null)
                    {
                        model.CreateDateTime     = oldValue.CreateDateTime;
                        model.LastUpdateDateTime = DateTime.Now;
                        updateList.Add(model);
                        logs.Add(new BatteryOprLogModel
                        {
                            LogType       = "BatteryCouponPriceDisplay",
                            IdentityId    = model.Pid,
                            OperationType = "Update",
                            OldValue      = JsonConvert.SerializeObject(oldValue),
                            NewValue      = JsonConvert.SerializeObject(model),
                            Remarks       = $"更新蓄电池:{model.Pid}的券后价展示配置",
                            Operator      = _user,
                        });
                    }
                    else
                    {
                        addList.Add(model);
                    }
                }
                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    foreach (var model in updateList)
                    {
                        var updateResult = _dal.UpdateBatteryCouponPriceDisplay(conn, model);
                        if (!updateResult)
                        {
                            throw new Exception($"UpdateBatteryCouponPriceDisplay失败, " +
                                                $"待更新数据{JsonConvert.SerializeObject(model) }");
                        }
                    }
                    foreach (var model in addList)
                    {
                        var pkid      = _dal.AddBatteryCouponPriceDisplay(conn, model);
                        var addResult = pkid > 0;
                        if (!addResult)
                        {
                            throw new Exception($"AddBatteryCouponPriceDisplay失败, " +
                                                $"待添加数据{JsonConvert.SerializeObject(model) }");
                        }
                        model.PKID               = pkid;
                        model.CreateDateTime     = DateTime.Now;
                        model.LastUpdateDateTime = DateTime.Now;
                        logs.Add(new BatteryOprLogModel
                        {
                            LogType       = "BatteryCouponPriceDisplay",
                            IdentityId    = model.Pid,
                            OperationType = "Add",
                            OldValue      = null,
                            NewValue      = JsonConvert.SerializeObject(model),
                            Remarks       = $"添加蓄电池:{model.Pid}的券后价展示配置",
                            Operator      = _user,
                        });
                    }
                    result = true;
                });
                if (result && logs.Any())
                {
                    logs.ForEach(s => LoggerManager.InsertLog("BatteryOprLog", s));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UpSertBatteryCouponPriceDisplay", ex);
            }
            return(result);
        }
Beispiel #21
0
        public bool UpsertPaceageActivityConfig(PackageActivityConfig data, string user)
        {
            var    result = false;
            string msg    = "";

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var flag = false;
                    if (data.ActivityId != Guid.Empty)
                    {
                        msg  = "更新活动配置";
                        flag = DALPackageActivity.UpdatePackageActivityConfig(conn, data, user);
                    }
                    else
                    {
                        msg             = "添加活动配置";
                        data.ActivityId = Guid.NewGuid();
                        flag            = DALPackageActivity.InsertPackageActivityConfig(conn, data, user);
                    }

                    if (flag)
                    {
                        DALPackageActivity.DeletePackageActivitySceneConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityShopConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityProductConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityVehicleConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityPriceConfig(conn, data.ActivityId);
                        if (data.RoundConfig != null && data.RoundConfig.Any())
                        {
                            foreach (var item in data.RoundConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivitySceneConfig(conn, item);
                            }
                        }
                        if (data.ProductConfig != null && data.ProductConfig.Any())
                        {
                            foreach (var item in data.ProductConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivityProductConfig(conn, item);
                            }
                        }
                        if (data.ShopConfig != null && data.ShopConfig.Any())
                        {
                            foreach (var item in data.ShopConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivityShopConfig(conn, item);
                            }
                        }
                        if (data.VehicleConfig != null && data.VehicleConfig.Any())
                        {
                            var vehicleIds = data.VehicleConfig.Select(x => x.VehicleID).Distinct();
                            foreach (var vehicleId in vehicleIds)
                            {
                                DALPackageActivity.InsertPackageActivityVehicleConfig(conn, data.ActivityId, vehicleId);
                            }
                        }
                        if (data.PriceConfig != null && data.PriceConfig.Any())
                        {
                            var priceConfigs = data.PriceConfig;
                            foreach (var priceConfig in priceConfigs)
                            {
                                DALPackageActivity.InsertPackageActivityPriceConfig(conn, data.ActivityId, priceConfig);
                            }
                        }
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            if (result)
            {
                data.ProductConfig = new List <PackageActivityProductConfig>();
                data.RoundConfig   = new List <PackageActivityRoundConfig>();
                data.VehicleConfig = new List <PackageActivityVehicleConfig>();
                RecordActivityTypeLog(data.ActivityId, data.StartTime, data.EndTime);
                InsertLog("UpsertPaceageActivityConfig", data.ActivityId.ToString(), JsonConvert.SerializeObject(data), msg, user, LogType);
                Thread.Sleep(2000);
                RefreshPackageBaoYangCache(data.ActivityId);
            }

            return(result);
        }
        /// <summary>
        /// 批量添加或更新券后价展示配置
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool MultUpSertVendorProductCouponPriceConfig(List <VendorProductCouponPriceConfigModel> models, string user)
        {
            var result = false;

            try
            {
                var logs       = new List <OprVendorProductModel>();
                var addList    = new List <VendorProductCouponPriceConfigModel>();
                var updateList = new List <VendorProductCouponPriceConfigModel>();
                foreach (var model in models)
                {
                    var oldValue = dbScopeManagerConfigurationRead.Execute(conn =>
                                                                           _dal.GetVendorProductCouponPriceConfig(conn, model.ProductType, model.Pid));
                    if (oldValue != null)
                    {
                        model.CreateDateTime     = oldValue.CreateDateTime;
                        model.LastUpdateDateTime = DateTime.Now;
                        updateList.Add(model);
                        logs.Add(new OprVendorProductModel()
                        {
                            LogType     = "VendorProductCouponPriceConfig",
                            IdentityId  = $"{model.ProductType}_{model.Pid}",
                            OldValue    = JsonConvert.SerializeObject(oldValue),
                            NewValue    = JsonConvert.SerializeObject(model),
                            Remarks     = $"更新{model.ProductType}:{model.Pid}的券后价展示配置",
                            OperateUser = user,
                        });
                    }
                    else
                    {
                        addList.Add(model);
                    }
                }
                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    foreach (var model in updateList)
                    {
                        var updateResult = _dal.UpdateVendorProductCouponPriceConfig(conn, model);
                        if (!updateResult)
                        {
                            throw new Exception($"UpdateVendorProductCouponPriceConfig失败, " +
                                                $"待更新数据{JsonConvert.SerializeObject(model) }");
                        }
                    }
                    foreach (var model in addList)
                    {
                        var pkid      = _dal.AddVendorProductCouponPriceConfig(conn, model);
                        var addResult = pkid > 0;
                        if (!addResult)
                        {
                            throw new Exception($"AddVendorProductCouponPriceConfig失败, " +
                                                $"待添加数据{JsonConvert.SerializeObject(model) }");
                        }
                        model.PKID               = pkid;
                        model.CreateDateTime     = DateTime.Now;
                        model.LastUpdateDateTime = DateTime.Now;
                        logs.Add(new OprVendorProductModel
                        {
                            LogType     = "VendorProductCouponPriceConfig",
                            IdentityId  = $"{model.ProductType}_{model.Pid}",
                            OldValue    = null,
                            NewValue    = JsonConvert.SerializeObject(model),
                            Remarks     = $"添加{model.ProductType}:{model.Pid}的券后价展示配置",
                            OperateUser = user,
                        });
                    }
                    result = true;
                });
                if (result && logs.Any())
                {
                    logs.ForEach(s => LoggerManager.InsertLog("OprVendorProduct", s));
                }
            }
            catch (Exception ex)
            {
                Logger.Error("UpSertVendorProductCouponPriceConfig", ex);
            }
            return(result);
        }
Beispiel #23
0
        /// <summary>
        /// 添加或编辑保养项目加价配置
        /// </summary>
        /// <param name="models"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool AddOrEditBaoYangInstallFeeConfig(List <BaoYangInstallFeeConfigModel> models, string user)
        {
            var result = false;

            try
            {
                var delList     = new List <BaoYangInstallFeeConfigModel>();
                var logs        = new List <BaoYangOprLog>();
                var serviceId   = models.Select(s => s.ServiceId).FirstOrDefault();
                var configs     = dbScopeManagerGungnirRead.Execute(conn => DalBaoYangInstallFeeConfig.SelectBaoYangInstallFeeConfig(conn, serviceId));
                var existConfig = configs.Where(s => s.PKID > 0).ToList();
                foreach (var oldValue in existConfig)
                {
                    var sameValue = models.Where(model =>
                                                 (string.Equals(model.ServiceId, oldValue.ServiceId) && model.CarMinPrice.Equals(oldValue.CarMinPrice) &&
                                                  model.CarMaxPrice.Equals(oldValue.CarMaxPrice) && model.AddInstallFee.Equals(oldValue.AddInstallFee))).FirstOrDefault();
                    if (sameValue == null)
                    {
                        delList.Add(oldValue);//删除旧数据
                    }
                    else
                    {
                        models.Remove(sameValue);//数据没变的不做任何操作
                    }
                }
                dbScopeManagerGungnir.CreateTransaction(conn =>
                {
                    #region  除旧数据
                    foreach (var oldValue in delList)
                    {
                        var log = new BaoYangOprLog
                        {
                            LogType     = "BaoYangInstallFeeConfig",
                            IdentityID  = oldValue.PKID.ToString(),
                            OldValue    = JsonConvert.SerializeObject(oldValue),
                            NewValue    = null,
                            Remarks     = $"删除保养项目:{oldValue.ServiceName}的加价配置",
                            OperateUser = user,
                        };
                        logs.Add(log);
                        DalBaoYangInstallFeeConfig.DeleteBaoYangInstallFeeConfigByPKID(conn, oldValue.PKID);
                    }
                    #endregion

                    #region 插入新数据
                    foreach (var model in models)
                    {
                        var deletedModel = dbScopeManagerGungnirRead.Execute(co => DalBaoYangInstallFeeConfig.GetDeletedBaoYangInstallFeeConfig(co, model));
                        if (deletedModel != null)
                        {
                            var backUpResult = DalBaoYangInstallFeeConfig.BackUpBaoYangInstallFeeConfigByPKID(conn, deletedModel.PKID);
                            if (!backUpResult)
                            {
                                throw new Exception($"BackUpBaoYangInstallFeeConfigByPKID失败,待插入数据{JsonConvert.SerializeObject(deletedModel)}");
                            }
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangInstallFeeConfig",
                                IdentityID  = deletedModel.PKID.ToString(),
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(deletedModel),
                                Remarks     = $"添加保养项目:{model.ServiceName}的加价配置",
                                OperateUser = user,
                            };
                            logs.Add(log);
                        }
                        else
                        {
                            var pkid = DalBaoYangInstallFeeConfig.AddBaoYangInstallFeeConfig(conn, model);
                            if (pkid < 1)
                            {
                                throw new Exception($"AddBaoYangInstallFeeConfig失败,待插入数据{JsonConvert.SerializeObject(model)}");
                            }
                            model.PKID               = pkid;
                            model.CreateDateTime     = DateTime.Now;
                            model.LastUpdateDateTime = DateTime.Now;
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangInstallFeeConfig",
                                IdentityID  = model.PKID.ToString(),
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(model),
                                Remarks     = $"添加保养项目:{model.ServiceName}的加价配置",
                                OperateUser = user,
                            };
                            logs.Add(log);
                        }
                    }
                    #endregion
                    result = true;
                });
                foreach (var log in logs)
                {
                    LoggerManager.InsertLog("BYOprLog", log);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("AddOrEditBaoYangInstallFeeConfig", ex);
            }
            return(result);
        }
        /// <summary>
        /// 添加或更新车型配置信息
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="table"></param>
        /// <param name="fileName"></param>
        /// <param name="cpremark"></param>
        /// <returns></returns>
        public bool InsertOrUpdateVehicleInfoByPID(string pid, DataTable table, string fileName, string cpremark)
        {
            var result              = true;
            var vehicleIdList       = new List <string>();
            var insertTidList       = new List <string>();
            var updateTidList       = new List <string>();
            var deleteVehicleIdList = new List <string>();
            var deleteTidList       = new List <string>();
            var batchCount          = 1000;

            try
            {
                dbManager.CreateTransaction(conn =>
                {
                    var pidInfo = DalProductVehicleInfo.GetAllProductVehicleTypeConfigInfoByPid(conn, pid, fileName, cpremark);
                    VerifyAndConvertData(pidInfo, table, fileName, cpremark, out vehicleIdList, out insertTidList, out updateTidList, out deleteVehicleIdList, out deleteTidList);
                    if (deleteVehicleIdList.Any())//删除的二级车型信息
                    {
                        while (deleteVehicleIdList.Any())
                        {
                            if (deleteVehicleIdList.Count() < batchCount)
                            {
                                batchCount = deleteVehicleIdList.Count();
                            }
                            DalProductVehicleInfo.BatchDeleteSecondVehicleTypeConfig(conn, deleteVehicleIdList.GetRange(0, batchCount), pid);
                            deleteVehicleIdList.RemoveRange(0, batchCount);
                        }
                    }
                    if (deleteTidList.Any())//删除的五级车型信息
                    {
                        while (deleteTidList.Any())
                        {
                            if (deleteTidList.Count() < batchCount)
                            {
                                batchCount = deleteTidList.Count();
                            }
                            DalProductVehicleInfo.BatchDeleteFiveVehicleTypeConfig(conn, deleteTidList.GetRange(0, batchCount), pid);
                            deleteTidList.RemoveRange(0, batchCount);
                        }
                    }
                    if (vehicleIdList.Any())//增加的二级车型信息
                    {
                        while (vehicleIdList.Any())
                        {
                            if (vehicleIdList.Count() < batchCount)
                            {
                                batchCount = vehicleIdList.Count();
                            }
                            DalProductVehicleInfo.BatchInsertSecondVehicleTypeConfig(conn, vehicleIdList.GetRange(0, batchCount), pid);
                            vehicleIdList.RemoveRange(0, batchCount);
                        }
                    }
                    if (insertTidList.Any())//增加的五级车型信息
                    {
                        while (insertTidList.Any())
                        {
                            if (insertTidList.Count() < batchCount)
                            {
                                batchCount = insertTidList.Count();
                            }
                            DalProductVehicleInfo.BatchInsertFiveVehicleTypeConfig(conn, insertTidList.GetRange(0, batchCount), pid);
                            insertTidList.RemoveRange(0, batchCount);
                        }
                    }
                    if (updateTidList.Any())//需要更新的五级车型信息
                    {
                        while (updateTidList.Any())
                        {
                            if (updateTidList.Count() < batchCount)
                            {
                                batchCount = updateTidList.Count();
                            }
                            DalProductVehicleInfo.BatchUpdateFiveVehicleTypeConfig(conn, updateTidList.GetRange(0, batchCount), pid);
                            updateTidList.RemoveRange(0, batchCount);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                result = false;
                logger.Error(ex);
            }

            return(result);
        }
        /// <summary>
        /// 插入或更新银行美容活动配置
        /// </summary>
        /// <param name="config">插入活动配置</param>
        /// <param name="adConfig">广告位配置</param>
        /// <param name="operateUser">操作人</param>
        /// <returns></returns>
        public bool UpsertBankMRActivityConfig(BankMRActivityConfig config, IEnumerable <BankMRActivityAdConfig> adConfig, string operateUser)
        {
            var result = false;

            try
            {
                TuhuGrouponDbScopeManager.CreateTransaction(conn =>
                {
                    if (config.ActivityId != null && config.ActivityId != Guid.Empty)
                    {
                        var currentActivity = GetBankMRActivityConfigByActivityId(config.ActivityId);
                        if (!string.Equals(currentActivity.RoundCycleType, config.RoundCycleType) ||
                            currentActivity.StartTime != config.StartTime || currentActivity.EndTime != config.EndTime)//如果活动场次周期类型变了,则需要重新生成活动场次
                        {
                            BankMRActivityDal.SetBankMRActivityRoundDisable(conn, config.ActivityId);
                            var roundResult = handler.GenerateBankMRActivityRound(conn, config);
                            if (!roundResult)
                            {
                                throw new Exception("生成银行美容活动场次失败");
                            }
                        }
                        var updateResult = BankMRActivityDal.UpdateBankMRActivityConfig(conn, config);

                        if (!updateResult)
                        {
                            throw new Exception("更新银行美容活动配置失败");
                        }
                        var log = new BeautyOprLog
                        {
                            LogType     = "UpdateBankMRActivityConfig",
                            IdentityID  = config.ActivityId.ToString(),
                            OldValue    = JsonConvert.SerializeObject(currentActivity),
                            NewValue    = JsonConvert.SerializeObject(config),
                            Remarks     = $"修改银行美容活动配置,活动ID:{config.ActivityId}",
                            OperateUser = operateUser,
                        };
                        LoggerManager.InsertLog("BeautyOprLog", log);
                    }
                    else
                    {
                        config.ActivityId = Guid.NewGuid();
                        adConfig?.ForEach(s => s.ActivityId = config.ActivityId);
                        var insertResult = BankMRActivityDal.InsertBankMRActivityConfig(conn, config);
                        if (insertResult)
                        {
                            var roundResult = handler.GenerateBankMRActivityRound(conn, config);
                            if (!roundResult)
                            {
                                throw new Exception("生成银行美容活动场次失败");
                            }
                        }
                        else
                        {
                            throw new Exception("插入银行美容活动配置失败");
                        }
                        var log = new BeautyOprLog
                        {
                            LogType     = "InsertBankMRActivityConfig",
                            IdentityID  = config.ActivityId.ToString(),
                            OldValue    = null,
                            NewValue    = JsonConvert.SerializeObject(config),
                            Remarks     = $"插入银行美容活动配置,活动ID:{config.ActivityId}",
                            OperateUser = operateUser,
                        };
                        LoggerManager.InsertLog("BeautyOprLog", log);
                    }

                    if (adConfig != null && adConfig.Any())
                    {
                        foreach (var ad in adConfig)
                        {
                            if (ad != null && ad.ActivityId != Guid.Empty)
                            {
                                BankMRActivityDal.UpsertBankMRActivityAdConfig(conn, ad);
                            }
                        }
                        var oldAdConfig =
                            BankMRActivityDal.SelectBankMRActivityAdConfigByActivityId(conn, config.ActivityId);
                        var adLog = new BeautyOprLog()
                        {
                            LogType    = "UpsertBankMRActivityAdConfig",
                            IdentityID = config.ActivityId.ToString(),
                            OldValue   = oldAdConfig != null && oldAdConfig.Any()
                                ? JsonConvert.SerializeObject(oldAdConfig)
                                : string.Empty,
                            NewValue    = JsonConvert.SerializeObject(adConfig),
                            Remarks     = $"修改银行广告位配置,活动ID:{config.ActivityId}",
                            OperateUser = operateUser,
                        };
                        LoggerManager.InsertLog("BeautyOprLog", adLog);
                    }

                    result = true;
                });
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
            }

            return(result);
        }
        /// <summary>
        /// 编辑团购信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public Tuple <bool, string> UpsertGroupBuyingConfig(GroupBuyingProductGroupConfigEntity data)
        {
            var result = false;
            var msg    = "操作失败";
            GroupBuyingProductGroupConfigEntity oldData = null;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    if (string.IsNullOrWhiteSpace(data.ProductGroupId))
                    {
                        data.ProductGroupId = $"PT{DateTime.Now.GetHashCode()}".Substring(0, 10);
                        if (DalGroupBuyingProductGroupConfig.IsExistProductGroupId(conn, data.ProductGroupId) > 0)
                        {
                            data.ProductGroupId = $"PT{DateTime.Now.GetHashCode()}".Substring(0, 10);
                        }
                        DalGroupBuyingProductGroupConfig.InsertGroupBuyingGroupConfig(conn, data);
                        foreach (var item in data.GroupProductDetails)
                        {
                            item.ProductGroupId = data.ProductGroupId;
                            item.Creator        = data.Creator;
                            DalGroupBuyingProductGroupConfig.InsertGroupBuyingProductConfig(conn, item);
                        }
                    }
                    else
                    {
                        oldData = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ConfigByGroupId(conn, data.ProductGroupId);
                        if (oldData != null)
                        {
                            oldData.GroupProductDetails = DalGroupBuyingProductGroupConfig.GetGroupBuyingV2ProductConfigByGroupId(conn, new List <string> {
                                data.ProductGroupId
                            });
                        }

                        DalGroupBuyingProductGroupConfig.UpdateGroupBuyingGroupConfig(conn, data);
                        DalGroupBuyingProductGroupConfig.DeleteGroupBuyingProductConfig(conn, data.ProductGroupId);
                        foreach (var item in data.GroupProductDetails)
                        {
                            item.ProductGroupId = data.ProductGroupId;
                            item.Creator        = data.Creator;
                            DalGroupBuyingProductGroupConfig.InsertGroupBuyingProductConfig(conn, item);
                        }
                    }
                    result = true;
                });
            }
            catch (Exception ex)
            {
                msg = "系统异常";
                logger.Error(ex);
            }
            if (result)
            {
                ThreadPool.QueueUserWorkItem(o =>
                {
                    foreach (var item in data.GroupProductDetails)
                    {
                        TuhuNotification.SendNotification("#.PinTuanProductStatusSyncQueue.#",
                                                          new Dictionary <string, object>
                        {
                            ["PId"]            = item.PID,
                            ["ProductGroupId"] = data.ProductGroupId
                        }, 3000);
                    }
                    InsertLog(data.ProductGroupId, "GroupBuyingProductConfig", "UpsertGroupBuyingConfig", result ? "操作成功" : msg, JsonConvert.SerializeObject(oldData), JsonConvert.SerializeObject(data), data.Creator);
                    ActivityService.RefrestPTCache(data.ProductGroupId);
                });
            }
            return(Tuple.Create(result, msg));
        }
Beispiel #27
0
        public bool UpsertTiresFloorActivity(TiresFloorActivityConfig model, string user)
        {
            var    result = false;
            string msg    = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    if (model != null && model.TiresActivityId != Guid.Empty && model.FlashSaleId != Guid.Empty)
                    {
                        if (model.FloorActivityId == Guid.Empty)
                        {
                            msg = "添加楼层活动";
                            model.FloorActivityId = Guid.NewGuid();
                            DALTiresActivity.InsertTiresFloorActivity(conn, model);
                        }
                        else
                        {
                            msg = "修改楼层活动";
                            DALTiresActivity.UpdateTiresFloorActivity(conn, model);
                        }

                        foreach (var item in model.ImgList)
                        {
                            item.ActivityId = model.FloorActivityId;
                            var imgInfo     = DALTiresActivity.SelectActivityImgByIdAndType(conn, item.ActivityId, item.Type);
                            if (imgInfo != null)
                            {
                                DALTiresActivity.UpdateActivityImgByIdAnType(conn, item.ActivityId, item.ImgUrl, item.Type, item.Position);
                            }
                            else
                            {
                                DALTiresActivity.InsertActivityImg(conn, item.ActivityId, item.ImgUrl, item.Type, item.Position);
                            }
                        }
                        foreach (var item in model.ProductList)
                        {
                            item.ActivityId = model.FloorActivityId;
                            var proInfo     = DALTiresActivity.SelectRegionProductsByPID(conn, item.ActivityId, item.ProductId);
                            if (proInfo != null)
                            {
                                DALTiresActivity.UpdateTiresProductInfo(conn, item.ActivityId, item.ProductId, item.AdvertiseTitle, item.SpecialCondition, item.IsCancelProgressBar, item.Position);
                            }
                            else
                            {
                                DALTiresActivity.InsertTiresProductInfo(conn, item.ActivityId, item.ProductId, item.AdvertiseTitle, item.SpecialCondition, item.IsCancelProgressBar, item.Position);
                            }
                        }
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error($"UpsertTiresFloorActivity Error:{ex.Message}; Stack:{ex.StackTrace}", ex);
            }

            if (result)
            {
                model.ProductList = new List <DataAccess.Entity.TiresActivity.TiresActivityProductConfig>();
                model.ImgList     = new List <DataAccess.Entity.TiresActivity.ActivityImageConfig>();
                InsertLog("UpsertTiresFloorActivity", model.TiresActivityId, JsonConvert.SerializeObject(model), msg, user, LogType);
            }

            return(result);
        }
Beispiel #28
0
        public bool SaveRegionarketingConfig(RegionMarketingModel data, string user)
        {
            var    result    = false;
            var    flag      = false;
            string msg       = string.Empty;
            var    isAdd     = false;
            var    startTime = data.StartTime.GetValueOrDefault();
            var    endTime   = data.EndTime.GetValueOrDefault();

            try
            {
                if (data != null)
                {
                    data.StartTime = data.EndTime = null;
                    dbScopeManager.CreateTransaction(conn =>
                    {
                        var info = DALRegionMarketing.SelectRegionMarketingConfig(conn, data.ActivityId, string.Empty, null, null, 1, 10);
                        if (info == null || info.Count == 0)
                        {
                            isAdd = true;
                            msg   = "添加活动配置";
                            flag  = DALRegionMarketing.InsertRegionMarketingConfig(conn, data) > 0;
                        }
                        else
                        {
                            msg  = "修改活动配置";
                            flag = DALRegionMarketing.UpdateRegionMarketingConfig(conn, data) > 0;
                        }
                        if (flag)
                        {
                            foreach (var item in data.ImgList)
                            {
                                var imgInfo = DALRegionMarketing.SelectActivityImgByIdAndType(conn, item.ActivityId, item.Type);
                                if (imgInfo != null)
                                {
                                    result = DALRegionMarketing.UpdateActivityImgByIdAnType(conn, item.ActivityId, item.ImgUrl, item.Type, item.Position) > 0;
                                }
                                else
                                {
                                    result = DALRegionMarketing.InsertActivityImg(conn, item.ActivityId, item.ImgUrl, item.Type, item.Position) > 0;
                                }
                            }
                            foreach (var item in data.ProductList)
                            {
                                var proInfo = DALRegionMarketing.SelectRegionProductsByPID(conn, item.ActivityId, item.ProductId);
                                if (proInfo != null)
                                {
                                    result = DALRegionMarketing.UpdateRegionProductInfo(conn, item.ActivityId, item.ProductId, item.AdvertiseTitle, item.SpecialCondition) > 0;
                                }
                                else
                                {
                                    result = DALRegionMarketing.InsertRegionProductInfo(conn, item.ActivityId, item.ProductId, item.AdvertiseTitle, item.SpecialCondition) > 0;
                                }
                            }
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                result = false;
                logger.Log(Level.Error, ex, "SaveRegionarketingConfig");
            }

            if (result)
            {
                data.ProductList = new List <RegionMarketingProductConfig>();
                data.ImgList     = new List <DataAccess.Entity.RegionMarketing.ActivityImageConfig>();
                InsertLog("RegionMarketingLog", data.ActivityId, JsonConvert.SerializeObject(data), msg, user, LogType);
                if (isAdd)
                {
                    CallCRMService.NewAddActivity(data.ActivityName, startTime, endTime, "", data.ActivityRules, data.ActivityId.ToString(), CRMSourceType.TiresActivityOne, user);
                }
                else
                {
                    CallCRMService.NewUpdateActivity(data.ActivityName, startTime, endTime, "", data.ActivityRules, data.ActivityId.ToString(), CRMSourceType.TiresActivityOne, user);
                }
            }

            return(result);
        }
        /// <summary>
        /// 更新喷漆车型档次分类
        /// </summary>
        /// <param name="vehicleLevel"></param>
        /// <param name="vehicleIds"></param>
        /// <param name="initalWord"></param>
        /// <param name="operateUser"></param>
        /// <returns></returns>
        public bool UpdatePaintVehicleLevel(string vehicleLevel, string vehicleIds, string initalWord, string operateUser)
        {
            var result = false;

            try
            {
                var oldValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord);
                dbScopeManagerCF.CreateTransaction(conn =>
                {
                    if (oldValue.Any())
                    {
                        var isDeleteSuccess = DalSprayPaintVehicle.DeletePaintVehicleDataByInitalWord(conn, vehicleLevel, initalWord);
                        if (isDeleteSuccess)
                        {
                            var toDelete = new List <VehicleLevelLog>();
                            if (!string.IsNullOrWhiteSpace(vehicleIds))
                            {
                                foreach (var item in oldValue)
                                {
                                    if (!vehicleIds.Split(',').Contains(item.VehicleId))
                                    {
                                        toDelete.Add(item);
                                    }
                                }
                            }
                            else
                            {
                                toDelete = oldValue;
                            }
                            if (toDelete.Any())
                            {
                                foreach (var value in toDelete)
                                {
                                    var log = new PaintVehicleOprLog
                                    {
                                        LogType      = "PaintVehicleLevelConfig",
                                        VehicleLevel = value.VehicleLevel,
                                        VehicleId    = value.VehicleId,
                                        OldValue     = JsonConvert.SerializeObject(value),
                                        NewValue     = null,
                                        Remarks      = "Delete",
                                        OperateUser  = operateUser,
                                    };
                                    InsertLog("PaintVehicle", log);
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(vehicleIds))
                    {
                        result = DalSprayPaintVehicle.AddPaintVehicleLevel(conn, vehicleLevel, vehicleIds);
                        if (result)
                        {
                            Thread.Sleep(1000);
                            var newValue = SeletePaintVehicleByInitalWord(vehicleLevel, initalWord);
                            var toAdd    = new List <VehicleLevelLog>();
                            foreach (var newData in newValue)
                            {
                                if (!oldValue.Any(p => p.VehicleId.Equals(newData.VehicleId)))
                                {
                                    toAdd.Add(newData);
                                }
                            }
                            if (toAdd.Any())
                            {
                                foreach (var value in toAdd)
                                {
                                    var log = new PaintVehicleOprLog
                                    {
                                        LogType      = "PaintVehicleLevelConfig",
                                        VehicleLevel = value.VehicleLevel,
                                        VehicleId    = value.VehicleId,
                                        OldValue     = null,
                                        NewValue     = JsonConvert.SerializeObject(value),
                                        Remarks      = "Add",
                                        OperateUser  = operateUser,
                                    };
                                    InsertLog("PaintVehicle", log);
                                }
                            }
                        }
                    }
                    else
                    {
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                Logger.Log(Level.Error, ex, "UpdatePaintVehicleLevel");
            }
            return(result);
        }
Beispiel #30
0
        public bool UpsertNewConponConfig(NewCouponActivity model, string user)
        {
            var result = false;
            var msg    = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var flag = false;
                    if (model != null)
                    {
                        if (model.ActivityId != Guid.Empty)
                        {
                            msg  = "更新配置";
                            flag = DALNewCoupon.UpdateNewCouponConfig(conn, model, user) > 0;
                        }
                        else
                        {
                            msg = "添加配置";
                            model.ActivityId = Guid.NewGuid();
                            flag             = DALNewCoupon.InsertNewCouponConfig(conn, model, user) > 0;
                        }

                        if (model.RecommendActivityForInit != null && model.RecommendActivityForInit.Any())
                        {
                            model.AllRecommendActivity.AddRange(model.RecommendActivityForInit);
                        }
                        if (model.RecommendActivityForSuccess != null && model.RecommendActivityForSuccess.Any())
                        {
                            model.AllRecommendActivity.AddRange(model.RecommendActivityForSuccess);
                        }

                        if (flag)
                        {
                            DALNewCoupon.DeleteRecommendActivityByActivityId(conn, model.ActivityId);
                            DALNewCoupon.DeleteCouponRulesConfig(conn, model.ActivityId);
                            if (model.AllRecommendActivity != null && model.AllRecommendActivity.Any())
                            {
                                foreach (var item in model.AllRecommendActivity)
                                {
                                    item.ActivityId = model.ActivityId;
                                    DALNewCoupon.InsertRecommendActivityConfig(conn, item);
                                }
                            }
                            if (model.CouponRulesConfig != null && model.CouponRulesConfig.Any())
                            {
                                foreach (var item in model.CouponRulesConfig)
                                {
                                    item.ActivityId = model.ActivityId;
                                    DALNewCoupon.InsertCouponRulesConfig(conn, item);
                                }
                            }
                        }
                        result = true;
                    }
                });
                if (result)
                {
                    model.AllRecommendActivity = new List <RecommendActivityConfig>();
                    InsertLog("UpsertNewConponConfig", model.ActivityId.ToString(), JsonConvert.SerializeObject(model), msg, user, LogType);
                    Thread.Sleep(2000);
                    RefreshRandomCouponCache(model.ActivityId);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }