Пример #1
0
 public static bool ReflashQiangGouCache(Guid aid, bool needLog)
 {
     try
     {
         using (var client = new FlashSaleClient())
         {
             var result = client.UpdateFlashSaleDataToCouchBaseByActivityID(aid);
             if (needLog)
             {
                 var oprLog = new FlashSaleProductOprLog();
                 oprLog.OperateUser    = ThreadIdentity.Operator.Name;
                 oprLog.CreateDateTime = DateTime.Now;
                 oprLog.BeforeValue    = JsonConvert.SerializeObject(new { actvityid = aid });
                 oprLog.AfterValue     = JsonConvert.SerializeObject(new { actvityid = aid });
                 oprLog.LogType        = "FlashSaleLog";
                 oprLog.LogId          = aid.ToString();
                 oprLog.Operation      = "刷新缓存";
                 LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
             }
             result.ThrowIfException(true);
             return(result.Result);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        /// <summary>
        /// 更新可选配置关联商品
        /// </summary>
        public static bool UpdateOrderOptionReferProducts(List <OrderOptionReferProductModel> refers, int orderOptionId, string user)
        {
            var result = true;
            var model  = DalCreateOrder.SelectOrderOptionReferProducts(orderOptionId);

            if (model.Any())
            {
                var del = DalCreateOrder.DelOrderOptionReferProducts(orderOptionId);
                result = del >= 0;
            }
            if (refers != null && refers.Any())
            {
                foreach (var refer in refers)
                {
                    refer.OrderOptionId = orderOptionId;
                    var res = DalCreateOrder.InsertOrderOptionReferProducts(refer);
                    result = result && res > 0;
                }
            }
            var oprLog = new FlashSaleProductOprLog
            {
                OperateUser    = user,
                CreateDateTime = DateTime.Now,
                BeforeValue    = JsonConvert.SerializeObject(model),
                AfterValue     = JsonConvert.SerializeObject(refers),
                LogType        = "OOption",
                LogId          = orderOptionId.ToString(),
                Operation      = "编辑关联产品"
            };

            LoggerManager.InsertLog("OrderOpertionOprLog", oprLog);
            //LoggerManager.InsertOplog(new ConfigHistory() { BeforeValue = JsonConvert.SerializeObject(refers), AfterValue = JsonConvert.SerializeObject(model), Author = user, Operation = "编辑关联产品", ObjectType = "OrderOption" });
            return(result);
        }
Пример #3
0
 public ActionResult ExamActivity(Guid aid)
 {
     try
     {
         var cacheGetFlag = GetOperateFlagCache();
         if (cacheGetFlag)
         {
             return(Json(new { Status = 0, Message = "现在有人正在操作请稍等下。。。。" }));
         }
         var cacheSetStartFlag = SetOperateFlagStartCache();
         if (!cacheSetStartFlag)
         {
             return(Json(new { Status = 0, Message = "服务器异常,请再点击审核" }));
         }
         var origin = QiangGouManager.FetchQiangGouAndProducts(aid) ?? new QiangGouModel();
         var result = QiangGouManager.ExamActivity(aid);
         if (result > 0)
         {
             var after       = QiangGouManager.FetchQiangGouAndProducts(aid);
             var chandata    = LogChangeDataManager.GetLogChangeData(origin, after);
             var beforeValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item1);
             var afterValue  = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item2);
             var oprLog      = new FlashSaleProductOprLog();
             oprLog.OperateUser    = ThreadIdentity.Operator.Name;
             oprLog.CreateDateTime = DateTime.Now;
             oprLog.BeforeValue    = JsonConvert.SerializeObject(beforeValue);
             oprLog.AfterValue     = JsonConvert.SerializeObject(afterValue);
             oprLog.LogType        = "FlashSaleLog";
             oprLog.LogId          = after.ActivityID.ToString();
             oprLog.Operation      = "审核活动";
             LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
             LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey);
             LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey);
             UpdateToCache(aid, false, origin.ActiveType);
         }
         //throw new Exception();
         return(Json(new
         {
             code = result
         }));
     }
     catch (Exception e)
     {
         return(Json(new
         {
             code = -3,
             msg = e.Message + e.InnerException + e.StackTrace
         }));
     }
     finally
     {
         SetOperateFlagEndCache();
     }
 }
Пример #4
0
        /// <summary>
        /// 天天秒杀保存按钮 与 审核按钮操所时调用
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="needLog"></param>
        /// <returns></returns>
        public static bool SpikeReflashCache(Guid aid, bool needLog)
        {
            try
            {
                var result = true;

                //天天秒杀场次刷新
                using (var client = new Service.Activity.CacheClient())
                {
                    var cacheresult = client.RefreshRedisCachePrefixForCommon(new RefreshCachePrefixRequest()
                    {
                        Prefix     = "SecondKillPrefix",
                        ClientName = "FlashSale",
                        Expiration = TimeSpan.FromDays(1)
                    });
                    cacheresult.ThrowIfException(true);
                    result = cacheresult.Result;
                }

                using (var client = new FlashSaleClient())
                {
                    var result1 = client.SpikeListRefresh(aid);
                    //初始化缓存数据
                    var result2 = client.RefreshFlashSaleHashCount(new List <string> {
                        aid.ToString()
                    }, false);

                    if (needLog)
                    {
                        var oprLog = new FlashSaleProductOprLog();
                        oprLog.OperateUser    = ThreadIdentity.Operator.Name;
                        oprLog.CreateDateTime = DateTime.Now;
                        oprLog.BeforeValue    = JsonConvert.SerializeObject(new { actvityid = aid });
                        oprLog.AfterValue     = JsonConvert.SerializeObject(new { actvityid = aid });
                        oprLog.LogType        = "FlashSaleLog";
                        oprLog.LogId          = aid.ToString();
                        oprLog.Operation      = "刷新缓存";
                        LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                    }
                    result1.ThrowIfException(true);
                    result2.ThrowIfException(true);

                    return(result1.Result && result2.Result && result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        public static bool OpertionLogs(OpertionType type, string beforevalue, string afterValue, string activityId)
        {
            var oprLog = new FlashSaleProductOprLog
            {
                OperateUser    = ThreadIdentity.Operator.Name,
                CreateDateTime = DateTime.Now,
                BeforeValue    = beforevalue,
                AfterValue     = afterValue,
                LogType        = "Seckill",
                LogId          = activityId,
                Operation      = ""
            };

            switch (type)
            {
            case OpertionType.Add:
                oprLog.Operation = "Add";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            case OpertionType.EditAdd:
                oprLog.Operation = "EditAdd";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            case OpertionType.EditDelete:
                oprLog.Operation = "EditDelete";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            case OpertionType.EditEdit:
                oprLog.Operation = "EditEdit";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            case OpertionType.ApprovePass:
                oprLog.Operation = "ApprovePass";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            case OpertionType.ApproveBack:
                oprLog.Operation = "ApproveBack";
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                return(true);

            default:
                return(true);
            }
        }
Пример #6
0
 public ActionResult SelectQGCache(Guid aid, bool needLog)
 {
     using (var client = new FlashSaleClient())
     {
         var result = client.GetFlashSaleList(new Guid[] { aid });
         result.ThrowIfException(true);
         if (needLog)
         {
             var oprLog = new FlashSaleProductOprLog();
             oprLog.OperateUser    = ThreadIdentity.Operator.Name;
             oprLog.CreateDateTime = DateTime.Now;
             oprLog.BeforeValue    = JsonConvert.SerializeObject(Json(new { actvityid = aid }));
             oprLog.AfterValue     = JsonConvert.SerializeObject(Json(new { actvityid = aid }));
             oprLog.LogType        = "FlashSaleLog";
             oprLog.LogId          = aid.ToString();
             oprLog.Operation      = "刷新缓存";
             LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
         }
         return(Json(result.Result, JsonRequestBehavior.AllowGet));
     }
 }
Пример #7
0
 public ActionResult DelActivity(Guid aid)
 {
     if (aid != Guid.Empty)
     {
         var result = DALQiangGou.DelFlashSale(aid);
         if (result > 0)
         {
             UpdateToCache(aid);
             var oprLog = new FlashSaleProductOprLog();
             oprLog.OperateUser    = ThreadIdentity.Operator.Name;
             oprLog.BeforeValue    = aid.ToString();
             oprLog.CreateDateTime = DateTime.Now;
             oprLog.AfterValue     = aid.ToString();
             oprLog.LogType        = "FlashSaleLog";
             oprLog.LogId          = aid.ToString();
             oprLog.Operation      = "删除活动";
             LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
             return(Json(new { Status = 1 }));
         }
     }
     return(Json(new { Status = 0 }));
 }
        /// <summary>
        /// 记录日志查询
        /// </summary>
        /// <param name="beforvalue"></param>
        /// <param name="newvalue"></param>
        private void SaveLog(CityAgingModel beforvalue, CityAgingModel newvalue)
        {
            var model = new CityAgingModel()
            {
                CityId     = newvalue.CityId,
                CityName   = newvalue.CityName,
                CreateUser = newvalue.CreateUser,
                UpdateUser = newvalue.UpdateUser
            };

            if (newvalue.PKid != -1)
            {
                model.PKid = newvalue.PKid;
            }
            if (newvalue.IsShow != -1)
            {
                model.IsShow = newvalue.IsShow;
            }
            if (newvalue.Title != "-1")
            {
                model.Title = newvalue.Title;
            }
            if (newvalue.Content != "-1")
            {
                model.Content = newvalue.Content;
            }
            var oprLog = new FlashSaleProductOprLog
            {
                OperateUser    = ThreadIdentity.Operator.Name,
                CreateDateTime = DateTime.Now,
                BeforeValue    = JsonConvert.SerializeObject(beforvalue),
                AfterValue     = JsonConvert.SerializeObject(model),
                LogType        = "CityAging",
                LogId          = $"0|{newvalue.CityId}",
                Operation      = "修改城市时效开关"
            };

            var result = Tuhu.Provisioning.Business.Logger.LoggerManager.InsertLog("CityAgingOprLog", oprLog);
        }
        public static bool SaveLimitAreaSaleCity(int productConfigId, int cityId, string cityName, int isAllowSale, int?warehouseId, string warehouseName, int?supplierId, string supplierName, string user = null)
        {
            bool result = false;

            try
            {
                var beforvalue = DalLimitAreaSale.GetLimitAreaSaleCityConfigLimit(productConfigId, cityId);
                var dbresult   = DalLimitAreaSale.SaveLimitAreaSaleCity(productConfigId, cityId, cityName, isAllowSale,
                                                                        warehouseId, warehouseName, supplierId, supplierName);
                result = dbresult > 0;

                var oprLog = new FlashSaleProductOprLog
                {
                    OperateUser    = ThreadIdentity.Operator.Name,
                    CreateDateTime = DateTime.Now,
                    BeforeValue    = JsonConvert.SerializeObject(beforvalue),
                    AfterValue     = JsonConvert.SerializeObject(new SimpleLimitAreaSaleCityModel()
                    {
                        CityId        = cityId,
                        CityName      = cityName,
                        IsAllowSale   = isAllowSale,
                        WarehouseId   = warehouseId,
                        WarehouseName = warehouseName,
                        SupplierId    = supplierId,
                        SupplierName  = supplierName
                    }),
                    LogType   = "LimitAreaCity",
                    LogId     = productConfigId + "|" + cityId,
                    Operation = "修改地区限售"
                };
                LoggerManager.InsertLog("LimitAreaOprLog", oprLog);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            return(result);
        }
Пример #10
0
        /// <summary>
        /// 天天秒杀保存按钮使用
        /// </summary>
        /// <param name="qiang"></param>
        /// <param name="diffs"></param>
        /// <param name="dbHelper"></param>
        /// <returns></returns>
        public static int SpikeSynchroDiffActivity(QiangGouModel qiang, List <QiangGouDiffModel> diffs, Tuhu.Component.Common.SqlDbHelper dbHelper)
        {
            var selectedDiffs = diffs.GroupBy(r => new { r.ActivityID, r.ActiveType }).Select(d => new QiangGouModel
            {
                ActivityID = d.Key.ActivityID,
                ActiveType = d.Key.ActiveType,
                Products   = d.Select(product => new QiangGouProductModel
                {
                    PID                = product.PID,
                    ProductName        = product.ProductName,
                    Price              = product.Price,
                    FalseOriginalPrice = product.FalseOriginalPrice,
                    InstallAndPay      = product.InstallAndPay,
                    IsUsePCode         = product.IsUsePCode,
                })
            });
            List <QiangGouProductModel> list = new List <QiangGouProductModel>();

            //List<QiangGouProductModel> selectedlist = new List<QiangGouProductModel>();
            foreach (var a in selectedDiffs)
            {
                var selecteddiffs = DALQiangGou.SelectSelectedDiffActivityProducts(a.ActivityID, a.ActiveType, a.Products, dbHelper);
                list.AddRange(selecteddiffs);
            }
            var aids = list.Select(_ => _.ActivityID);

            foreach (var aid in aids)
            {
                var  model         = DALQiangGou.SelectQiangGouForSynchro(aid, dbHelper);
                var  origin        = DALQiangGou.SelectQiangGouForSynchro(aid, dbHelper);
                var  needAsyncPids = list.Where(_ => _.ActivityID == aid).Select(_ => _.PID).ToList();
                var  tempProducts  = model.Products.Where(_ => !needAsyncPids.Contains(_.PID)).ToList();
                bool flag          = true;
                foreach (var pid in needAsyncPids)
                {
                    var product   = qiang.Products.FirstOrDefault(_ => _.PID == pid);
                    var y_product = model.Products.FirstOrDefault(_ => _.PID == pid);
                    y_product.ProductName        = product.ProductName;
                    y_product.Price              = product.Price;
                    y_product.FalseOriginalPrice = product.FalseOriginalPrice;
                    y_product.InstallAndPay      = product.InstallAndPay;
                    y_product.IsUsePCode         = product.IsUsePCode;

                    tempProducts.Add(y_product);
                    if (!string.IsNullOrWhiteSpace(qiang.NeedExamPids) && qiang.NeedExamPids.Split(';').Contains(pid) && flag)
                    {
                        flag = false;
                    }
                }

                model.NeedExam = !flag;
                model.Products = tempProducts;
                var result = DALQiangGou.CreateOrUpdateQianggou(dbHelper, model);
                if (result.Item1 < 0)
                {
                    dbHelper.Rollback();
                    return(-38);//同步失败
                }
                else
                {
                    var chandata    = LogChangeDataManager.GetLogChangeData(origin, model);
                    var beforeValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item1);
                    var afterValue  = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item2);
                    var oprLog      = new FlashSaleProductOprLog
                    {
                        OperateUser    = ThreadIdentity.Operator.Name,
                        CreateDateTime = DateTime.Now,
                        BeforeValue    = JsonConvert.SerializeObject(beforeValue),
                        AfterValue     = JsonConvert.SerializeObject(afterValue),
                        LogType        = "FlashSaleLog",
                        LogId          = result.Item2.ToString(),
                        Operation      = model.NeedExam ? "同步活动到待审核" : "同步活动"
                    };
                    LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                    LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey);
                    LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey);
                }
            }
            foreach (var aid in aids)
            {
                var cache = SpikeReflashCache(aid, false);
                if (cache == false)
                {
                    return(-3);
                }
            }

            return(1);
        }
Пример #11
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="needLog"></param>
        /// <param name="activityType"></param>
        /// <returns></returns>
        public static bool ReflashActivityCache(Guid aid, bool needLog, int activityType)
        {
            try
            {
                var result = true;
                if (activityType == 1 || activityType == 3)
                {
                    using (var client = new Service.Activity.CacheClient())
                    {
                        var cacheresult = client.RefreshRedisCachePrefixForCommon(new RefreshCachePrefixRequest()
                        {
                            Prefix     = "SecondKillPrefix",
                            ClientName = "FlashSale",
                            Expiration = TimeSpan.FromDays(1)
                        });
                        cacheresult.ThrowIfException(true);
                        result = cacheresult.Result;
                    }
                }
                using (var client = new FlashSaleClient())
                {
                    var result1 = client.UpdateFlashSaleDataToCouchBaseByActivityID(aid);
                    //初始化缓存数据
                    var result2 = client.RefreshFlashSaleHashCount(new List <string> {
                        aid.ToString()
                    }, false);
                    //刷新活动页固化下来的数据
                    var activityExists = DALQiangGou.FetchActivityPageContentByActivityId(aid.ToString());

                    if (activityExists != null && activityExists.Any())
                    {
                        foreach (var activityExist in activityExists)
                        {
                            using (var actclient = new ActivityClient())
                            {
                                var activityId = actclient.GetOrSetActivityPageSortedPids(new SortedPidsRequest
                                {
                                    Brand          = activityExist.Brand,
                                    ProductType    = (ProductType)activityExist.ProductType,
                                    NeedUpdatePkid = activityExist.Pkid,
                                    DicActivityId  = new KeyValuePair <string, ActivityIdType>(aid.ToString(), ActivityIdType.FlashSaleActivity)
                                });
                                var refresh = actclient.RefreshActivePageListModelCache(new ActivtyPageRequest
                                {
                                    Channel = "wap",
                                    HashKey = activityExist.HashKey,
                                });
                            }
                        }
                    }
                    if (needLog)
                    {
                        var oprLog = new FlashSaleProductOprLog();
                        oprLog.OperateUser    = ThreadIdentity.Operator.Name;
                        oprLog.CreateDateTime = DateTime.Now;
                        oprLog.BeforeValue    = JsonConvert.SerializeObject(new { actvityid = aid });
                        oprLog.AfterValue     = JsonConvert.SerializeObject(new { actvityid = aid });
                        oprLog.LogType        = "FlashSaleLog";
                        oprLog.LogId          = aid.ToString();
                        oprLog.Operation      = "刷新缓存";
                        LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                    }
                    result1.ThrowIfException(true);
                    result2.ThrowIfException(true);

                    return(result1.Result && result2.Result && result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #12
0
        public static int SyncDiffActivity(QiangGouModel qiang, List <QiangGouDiffModel> diffs, SqlDbHelper dbHelper)
        {
            var diffList = new List <QiangGouProductModel>();

            if (diffs.Count > 0)
            {
                foreach (var item in diffs)
                {
                    diffList.Add(new QiangGouProductModel
                    {
                        PID                = item.PID,
                        ActivityID         = (Guid)item.ActivityID,
                        ProductName        = item.ProductName,
                        Price              = item.Price,
                        FalseOriginalPrice = item.FalseOriginalPrice,
                        InstallAndPay      = item.InstallAndPay,
                        IsUsePCode         = item.IsUsePCode
                    });
                }
            }

            var aids = diffList.Select(_ => _.ActivityID).Distinct().ToArray();

            foreach (var aid in aids)
            {
                var  model         = DALQiangGou.SelectQiangGouForSynchro(aid, dbHelper);
                var  origin        = model;
                var  needAsyncPids = diffList.Where(_ => _.ActivityID == aid).Select(_ => _.PID).ToList();
                var  tempProducts  = model.Products.Where(_ => !needAsyncPids.Contains(_.PID)).ToList();
                bool flag          = true;
                foreach (var pid in needAsyncPids)
                {
                    var product = qiang.Products.FirstOrDefault(_ => _.PID == pid);

                    var y_product = model.Products.FirstOrDefault(_ => _.PID == pid);
                    y_product.ProductName        = product.ProductName;
                    y_product.Price              = product.Price;
                    y_product.FalseOriginalPrice = product.FalseOriginalPrice;
                    y_product.InstallAndPay      = product.InstallAndPay;
                    y_product.IsUsePCode         = product.IsUsePCode;

                    tempProducts.Add(y_product);
                    if (!string.IsNullOrWhiteSpace(qiang.NeedExamPids) && qiang.NeedExamPids.Split(';').Contains(pid) && flag)
                    {
                        flag = false;
                    }
                }

                model.NeedExam = !flag;
                model.Products = tempProducts;

                var result = DALQiangGou.CreateOrUpdateQiangGou(dbHelper, model);

                if (result.Item1 < 0)
                {
                    dbHelper.Rollback();
                    return(-38);//同步失败
                }

                var chandata    = LogChangeDataManager.GetLogChangeData(origin, model);
                var beforeValue = GenerateSimpleQiangGouModel(chandata.Item1);
                var afterValue  = GenerateSimpleQiangGouModel(chandata.Item2);
                var oprLog      = new FlashSaleProductOprLog
                {
                    OperateUser    = ThreadIdentity.Operator.Name,
                    CreateDateTime = DateTime.Now,
                    BeforeValue    = JsonConvert.SerializeObject(beforeValue),
                    AfterValue     = JsonConvert.SerializeObject(afterValue),
                    LogType        = "FlashSaleLog",
                    LogId          = result.Item2.ToString(),
                    Operation      = model.NeedExam ? "同步活动到待审核" : "同步活动"
                };
                LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey);
                LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey);
            }

            foreach (var aid in aids)
            {
                var cache = ReflashActivityCache(aid, false, 0);
                if (cache == false)
                {
                    return(-3);
                }
            }

            return(1);
        }
        public static bool SaveLimitAreaSalePid(string pid, int isLimit, string user)
        {
            var bResult = true;

            try
            {
                var beforvalue = DalLimitAreaSale.GetLimitAreaSaleProductConfigLimit(pid);
                var result1    = DalLimitAreaSale.SaveLimitAreaSalePid(pid, isLimit);
                if (result1 <= 0)
                {
                    return(false);
                }
                var oprLog = new FlashSaleProductOprLog
                {
                    OperateUser    = ThreadIdentity.Operator.Name,
                    CreateDateTime = DateTime.Now,
                    BeforeValue    = beforvalue == null?JsonConvert.SerializeObject(null) :
                                         JsonConvert.SerializeObject(new SimpleLimitAreaSaleModel()
                    {
                        Pid     = pid,
                        IsLimit = beforvalue.Value,
                    }),
                                         AfterValue = JsonConvert.SerializeObject(new SimpleLimitAreaSaleModel()
                    {
                        Pid     = pid,
                        IsLimit = isLimit,
                    }),
                                         LogType   = "LimitAreaPid",
                                         LogId     = pid,
                                         Operation = beforvalue == null? "新增产品限售": "修改产品限售"
                };
                LoggerManager.InsertLog("LimitAreaOprLog", oprLog);

                var tableData = SelectLimitAreaSaleCityInfo();
                if (!tableData.Any())
                {
                    var municipalit = new[] { "上海市", "北京市", "天津市", "重庆市" };
                    var dbresult    = LimitAreaSaleManager.SelectRegions();
                    var result      = new List <LimitAreaSaleCityModel>();
                    foreach (var province in dbresult)
                    {
                        if (municipalit.Contains(province.RegionName))
                        {
                            var regionModel = new LimitAreaSaleCityModel()
                            {
                                ProvinceId   = province.PKID,
                                ProvinceName = province.RegionName,
                                CityId       = province.PKID,
                                CityName     = province.RegionName
                            };
                            result.Add(regionModel);
                        }
                        else
                        {
                            foreach (var city in province.ChildrenRegion)
                            {
                                var regionModel = new LimitAreaSaleCityModel()
                                {
                                    ProvinceId   = province.PKID,
                                    ProvinceName = province.RegionName,
                                    CityId       = city.PKID,
                                    CityName     = city.RegionName
                                };
                                result.Add(regionModel);
                            }
                        }
                    }
                    var tempdata = (from a in result
                                    join b in tableData on a.CityId equals b.CityId into temp
                                    from b in temp.DefaultIfEmpty()
                                    select new LimitAreaSaleCityModel
                    {
                        ProductConfigId = 0,
                        ProvinceId = a.ProvinceId,
                        ProvinceName = a.ProvinceName,
                        CityId = a.CityId,
                        CityName = a.CityName,
                        IsAllowSale = b?.IsAllowSale ?? 0,
                        WarehouseId = b?.WarehouseId,
                        WarehouseName = b?.WarehouseName,
                        SupplierId = b?.SupplierId,
                        SupplierName = b?.SupplierName,
                        Pid = pid,
                    }).ToList();
                    tempdata.ForEach(r =>
                    {
                        bResult = bResult &&
                                  SaveLimitAreaSaleCity(r.ProductConfigId, r.CityId, r.CityName, r.IsAllowSale,
                                                        r.WarehouseId, r.WarehouseName, r.SupplierId, r.SupplierName);
                    });
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            return(bResult);
        }
Пример #14
0
        public ActionResult Save(QiangGouModel model, string Products, string QiangGouDiff)
        {
            try
            {
                if (model == null)
                {
                    return(Json(new { Status = 0, Message = "保存失败【活动内容为空】" }));
                }
                var cacheGetFlag = GetOperateFlagCache();
                if (cacheGetFlag)
                {
                    return(Json(new { Status = 0, Message = "现在有人正在操作请稍等下。。。。" }));
                }
                var cacheSetStartFlag = SetOperateFlagStartCache();
                if (!cacheSetStartFlag)
                {
                    return(Json(new { Status = 0, Message = "服务器异常,请再点击保存" }));
                }
                var isUpdate = model.ActivityID != null;
                var origin   = new QiangGouModel();
                if (isUpdate)
                {
                    origin = QiangGouManager.FetchQiangGouAndProducts(model.ActivityID.Value);
                }
                model.Products = JsonConvert.DeserializeObject <List <QiangGouProductModel> >(Products);
                List <QiangGouDiffModel> qiangGouDiff = new List <QiangGouDiffModel>();
                if (QiangGouDiff != null)
                {
                    qiangGouDiff = JsonConvert.DeserializeObject <List <QiangGouDiffModel> >(QiangGouDiff);
                }
                if (!model.Products.Any())
                {
                    return(Json(new { Status = 0, Message = "保存失败【活动无产品】" }));
                }

                var result = QiangGouManager.Save(model, qiangGouDiff);
                if (result.Item1 == -1)
                {
                    return(Json(new { Status = 0, Message = "保存失败【闪购活动时间不允许重叠】" }));
                }
                if (result.Item1 == -3)
                {
                    return(Json(new { Status = 0, Message = "刷新缓存失败【请手动刷新】" }));
                }
                else if (result.Item1 > 0)
                {
                    QiangGouModel after;
                    if (model.ActivityID != null && !model.NeedExam)
                    {
                        after = QiangGouManager.FetchQiangGouAndProducts(model.ActivityID.Value);
                    }
                    else
                    {
                        after = QiangGouManager.FetchQiangGouAndProductsTemp(model.ActivityID.Value);
                    }
                    var request = new ActivityTypeRequest()
                    {
                        ActivityId    = model.ActivityID.Value,
                        StartDateTime = model.StartDateTime,
                        EndDateTime   = model.EndDateTime,
                        Status        = 1,
                        Type          = 1
                    };
                    var activityTypeResult = QiangGouManager.RecordActivityType(request);
                    if (!activityTypeResult)
                    {
                        return(Json(new { Status = 0, Message = "保存失败重试" }));
                    }
                    if (isUpdate)
                    {
                        var chandata    = LogChangeDataManager.GetLogChangeData(origin, after);
                        var beforeValue = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item1);
                        var afterValue  = QiangGouManager.GenerateSimpleQiangGouModel(chandata.Item2);
                        var oprLog      = new FlashSaleProductOprLog
                        {
                            OperateUser    = ThreadIdentity.Operator.Name,
                            CreateDateTime = DateTime.Now,
                            BeforeValue    = JsonConvert.SerializeObject(beforeValue),
                            AfterValue     = JsonConvert.SerializeObject(afterValue),
                            LogType        = "FlashSaleLog",
                            LogId          = result.Item2.ToString(),
                            Operation      = model.NeedExam ? "修改活动到待审核" : "修改活动"
                        };
                        LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                        LoggerManager.InsertFlashSaleLog(chandata.Item1, beforeValue.HashKey);
                        LoggerManager.InsertFlashSaleLog(chandata.Item2, afterValue.HashKey);
                    }
                    else
                    {
                        var afterValue = QiangGouManager.GenerateSimpleQiangGouModel(after);
                        var oprLog     = new FlashSaleProductOprLog
                        {
                            OperateUser    = ThreadIdentity.Operator.Name,
                            CreateDateTime = DateTime.Now,
                            BeforeValue    = JsonConvert.SerializeObject(Json(new { actvityid = result.Item2.ToString() })),
                            AfterValue     = JsonConvert.SerializeObject(afterValue),
                            LogType        = "FlashSaleLog",
                            LogId          = result.Item2.ToString(),
                            Operation      = model.NeedExam ? "新建活动到待审核" : "新建活动"
                        };
                        LoggerManager.InsertLog("FlashSaleOprLog", oprLog);
                        LoggerManager.InsertFlashSaleLog(after, afterValue.HashKey);
                    }
                    if (model.ActivityID != null && !model.NeedExam)
                    {
                        var cache = UpdateToCache(model.ActivityID.Value, false, model.ActiveType);
                        if (cache == false)
                        {
                            return(Json(new { Status = 0, Message = "刷新缓存失败【请手动刷新】" }));
                        }
                    }
                    return(Json(new { Status = 1, Message = "保存成功" }));
                }

                return(Json(new { Status = 0, Message = "保存失败【未知错误】" }));
            }
            catch (Exception e)
            {
                return(Json(new { Status = 0, Message = e.Message + e.InnerException + e.StackTrace }));
            }
            finally
            {
                SetOperateFlagEndCache();
            }
        }