Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }