Example #1
0
        /// <summary>
        /// 保存大翻牌配置操作日志
        /// </summary>
        /// <param name="oldInfo"></param>
        /// <param name="newInfo"></param>
        /// <param name="oldWheel"></param>
        /// <param name="newWheel"></param>
        private void SubmitFormLog(BigBrandRewardListEntity oldInfo, BigBrandRewardListEntity newInfo,
                                   IEnumerable <BigBrandWheelEntity> oldWheel, IEnumerable <BigBrandWheelEntity> newWheel)
        {
            try
            {
                var isAdd            = oldInfo?.PKID > 0 ? false : true;
                var operationLogType = isAdd ? "BigBrandReward_Insert" : "BigBrandReward_Update";

                var operationLogModel = new SalePromotionActivityLogModel()
                {
                    ReferId          = "BigBrandReward_" + newInfo.PKID,
                    ReferType        = "BigBrandReward",
                    OperationLogType = operationLogType,
                    CreateDateTime   = DateTime.Now.ToString(),
                    CreateUserName   = this.User.Identity.Name,
                    LogDetailList    = new List <SalePromotionActivityLogDetail>()
                };
                if (newInfo.Title != oldInfo?.Title)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "名称",
                        NewValue = newInfo.Title,
                        OldValue = isAdd ? "" : oldInfo?.Title
                    });
                }
                if (newInfo.BigBrandType != oldInfo?.BigBrandType)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "抽奖类型",
                        NewValue = newInfo.BigBrandType == 1 ? "普通抽奖" : (newInfo.BigBrandType == 2 ? "积分抽奖" : "定人群抽奖"),
                        OldValue = isAdd ? "" : oldInfo?.BigBrandType == 1 ? "普通抽奖" : (oldInfo?.BigBrandType == 2 ? "积分抽奖" : "定人群抽奖")
                    });
                }
                if (newInfo.PreTimes != oldInfo?.PreTimes)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "抽奖次数",
                        NewValue = newInfo.PreTimes.ToString(),
                        OldValue = isAdd ? "" : oldInfo?.PreTimes.ToString()
                    });
                }
                if (newInfo.CompletedTimes != oldInfo?.CompletedTimes)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "抽奖次数(分享后)",
                        NewValue = newInfo.CompletedTimes.ToString(),
                        OldValue = isAdd ? "" : oldInfo?.CompletedTimes.ToString()
                    });
                }
                if (newInfo.Period != oldInfo?.Period || newInfo.PeriodType != oldInfo?.PeriodType)
                {
                    var newType = newInfo.PeriodType == 1 ? "小时" : (newInfo.PeriodType == 2 ? "天" : "月");
                    var oldType = isAdd ? "" : oldInfo?.PeriodType == 1 ? "小时" : (oldInfo?.PeriodType == 2 ? "天" : "月");
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "抽奖周期",
                        NewValue = newInfo.Period + newType,
                        OldValue = isAdd ? "" : oldInfo?.Period + oldType
                    });
                }
                if (newInfo.StartDateTime != oldInfo?.StartDateTime)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "开始时间",
                        NewValue = newInfo.StartDateTime.ToString(),
                        OldValue = isAdd ? "" : oldInfo?.StartDateTime.ToString()
                    });
                }
                if (newInfo.NeedIntegral != oldInfo?.NeedIntegral)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "单次抽奖消耗积分",
                        NewValue = newInfo.NeedIntegral.ToString(),
                        OldValue = isAdd ? "" : oldInfo?.NeedIntegral.ToString()
                    });
                }
                if (newInfo.AfterLoginType != oldInfo?.AfterLoginType)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "抽奖验证类型",
                        NewValue = newInfo.AfterLoginType == 1 ? "微信授权" : "",
                        OldValue = isAdd ? "" : oldInfo?.AfterLoginType == 1 ? "微信授权" : ""
                    });
                }
                if (newInfo.AfterLoginValue != oldInfo?.AfterLoginValue)
                {
                    operationLogModel.LogDetailList.Add(new SalePromotionActivityLogDetail()
                    {
                        Property = "必须关注公众号",
                        NewValue = GetWXName(newInfo.AfterLoginValue),
                        OldValue = GetWXName(oldInfo?.AfterLoginValue)
                    });
                }
                if (newWheel?.Count() > 0 || oldWheel?.Count() > 0)
                {
                    var logModel = new SalePromotionActivityLogDetail()
                    {
                        Property = "对应奖池",
                        NewValue = GetWheelListLogStr(newWheel),
                        OldValue = isAdd ? "" : GetWheelListLogStr(oldWheel)
                    };
                    if (!(!string.IsNullOrWhiteSpace(logModel.OldValue) && logModel.OldValue == logModel.NewValue))
                    {
                        operationLogModel.LogDetailList.Add(logModel);
                    }
                }
                SetOperationLog(operationLogModel, "SubmitFormLog");
            }
            catch (Exception ex)
            {
                Logger.Log(Level.Warning, ex, $"SubmitFormLog异常,ex:{ex}");
            }
        }
Example #2
0
        /// <summary>
        /// 提交大翻盘的配置
        /// </summary>
        /// <param name="modeljson"></param>
        /// <param name="wheeljson"></param>
        /// <returns></returns>
        public async Task <ActionResult> SubmitForm(string modeljson, string wheeljson)
        {
            modeljson = modeljson.Replace("\"&nbsp;\"", "null");
            wheeljson = wheeljson.Replace("\"&nbsp;\"", "null");
            try
            {
                BigBrandRewardListEntity entity = JsonConvert.DeserializeObject <BigBrandRewardListEntity>(modeljson);

                IEnumerable <BigBrandWheelEntity> wheel = null;
                if (!string.IsNullOrWhiteSpace(wheeljson))
                {
                    wheel = JsonConvert.DeserializeObject <IEnumerable <BigBrandWheelEntity> >(wheeljson);
                }

                RepositoryManager manager = new RepositoryManager();

                //获取修改前旧数据
                var oldEntity = new BigBrandRewardListEntity();
                var oldWheel  = new List <BigBrandWheelEntity>();
                if (entity.PKID > 0)
                {
                    try
                    {
                        oldEntity = manager.GetEntity <BigBrandRewardListEntity>(p => p.PKID == entity.PKID && p.Is_Deleted == false);

                        Expression <Func <BigBrandWheelEntity, bool> > wheelExp = _ => _.FKBigBrand == entity.PKID && _.Is_Deleted == false;
                        oldWheel = manager.GetEntityList <BigBrandWheelEntity>(wheelExp)?.ToList();
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(Level.Error, $"ex:{ex}");
                    }
                }

                using (var db = manager.BeginTrans())
                {
                    string errorMsg     = string.Empty;
                    var    newWheelList = new List <BigBrandWheelEntity>();

                    //判断FKBigBrand,TimeNumber,FKPoolPKID(奖池ID) 是否唯一
                    if (wheel != null)
                    {
                        foreach (var item in wheel)
                        {
                            item.CreateDateTime     = DateTime.Now;
                            item.CreateUserName     = User.Identity.Name;
                            item.LastUpdateDateTime = DateTime.Now;
                            item.UpdateUserName     = User.Identity.Name;
                            item.FKBigBrand         = entity.PKID;

                            var array = item.FKPoolPKIDText.TrimEnd(',').Split(',');
                            if (array != null && array.Length > 0)
                            {
                                foreach (var s in array)
                                {
                                    int poolPKID = 0;
                                    if (int.TryParse(s, out poolPKID))
                                    {
                                        if (poolPKID != 0)
                                        {
                                            item.FKPoolPKID = poolPKID;
                                            var wheelPkidList  = manager.GetEntityList <BigBrandWheelEntity>(_ => _.FKBigBrand == item.FKBigBrand && _.TimeNumber == item.TimeNumber && _.FKPoolPKID == item.FKPoolPKID && _.Is_Deleted == false).ToList().Select(p => p.PKID).ToList();
                                            var existWheelList = manager.GetEntityList <BigBrandWheelEntity>(_ => _.FKBigBrand == item.FKBigBrand && _.TimeNumber == item.TimeNumber && _.FKPoolPKID == item.FKPoolPKID && _.Is_Deleted == false && !wheelPkidList.Contains(_.PKID));
                                            if (existWheelList != null && existWheelList.ToList().Count > 0)
                                            {
                                                if (!errorMsg.Contains("第" + item.TimeNumber + "轮"))
                                                {
                                                    errorMsg = errorMsg + "第" + item.TimeNumber + "轮奖池ID,";
                                                }
                                            }
                                            else
                                            {
                                                string json      = JsonConvert.SerializeObject(item);
                                                var    tempModel = JsonConvert.DeserializeObject <BigBrandWheelEntity>(json);
                                                newWheelList.Add(tempModel);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (errorMsg.Length > 0)
                    {
                        errorMsg = errorMsg.TrimEnd(',') + "的值重复了!";
                        return(Content(JsonConvert.SerializeObject(new
                        {
                            state = "false",
                            message = errorMsg,
                            data = ""
                        })));
                    }

                    if (entity.PKID == 0)
                    {
                        entity.HashKeyValue       = Tuhu.Provisioning.Common.SecurityHelper.Sha1Encrypt(Guid.NewGuid().ToString(), System.Text.Encoding.UTF8).Substring(0, 8);
                        entity.CreateDateTime     = DateTime.Now;
                        entity.LastUpdateDateTime = DateTime.Now;
                        entity.UpdateUserName     = User.Identity.Name;
                        entity.CreateUserName     = User.Identity.Name;
                        manager.Add <BigBrandRewardListEntity>(entity);
                        // LoggerManager.InsertOplog(new ConfigHistory() { AfterValue = JsonConvert.SerializeObject(entity), Author = User.Identity.Name, Operation = "新增大翻牌活动", ObjectType = "BigBrand" });
                    }
                    else
                    {
                        entity.LastUpdateDateTime = DateTime.Now;
                        entity.UpdateUserName     = User.Identity.Name;
                        manager.Update <BigBrandRewardListEntity>(entity);
                        // LoggerManager.InsertOplog(new ConfigHistory() { AfterValue = JsonConvert.SerializeObject(entity), Author = User.Identity.Name, Operation = "更新大翻牌活动", ObjectType = "BigBrand" });
                    }

                    Expression <Func <BigBrandWheelEntity, bool> > exp = _ => _.FKBigBrand == entity.PKID && _.Is_Deleted == false;
                    var bigBrandWheelList = manager.GetEntityList <BigBrandWheelEntity>(exp);
                    foreach (var item in bigBrandWheelList)
                    {
                        item.Is_Deleted         = true;
                        item.LastUpdateDateTime = DateTime.Now;
                        item.UpdateUserName     = User.Identity.Name;
                        manager.Update <BigBrandWheelEntity>(item);
                    }
                    if (wheel != null)
                    {
                        foreach (var item in newWheelList)
                        {
                            db.Insert <BigBrandWheelEntity>(item);
                        }
                    }
                    db.Commit();
                    // LoggerManager.InsertOplog(new ConfigHistory() { AfterValue = JsonConvert.SerializeObject(wheel), Author = User.Identity.Name, Operation = "大翻牌明细", ObjectType = "BigBrand" });
                }

                entity = manager.GetEntity <BigBrandRewardListEntity>(p => p.PKID == entity.PKID && p.Is_Deleted == false);

                //操作日志
                SubmitFormLog(oldEntity, entity, oldWheel, wheel);

                //读写分离 做延时
                await Task.Delay(3000);

                #region 更新大翻盘缓存
                using (var client = new Tuhu.Service.Activity.BigBrandClient())
                {
                    var result = client.UpdateBigBrand(entity.HashKeyValue);
                    result.ThrowIfException(true);
                }
                #endregion

                #region 更新 活动页的 缓存
                //筛选 出大翻盘相关的 活动页 配置
                List <ActivePageContentEntity> activeEntityList = manager.GetEntityList <ActivePageContentEntity>(p => p.HashKey == entity.HashKeyValue && p.Type == 20).ToList();
                foreach (var activeEntity in activeEntityList)
                {
                    var activePageList = manager.GetEntity <ActivePageListEntity>(activeEntity.FKActiveID);
                    using (var client = new Tuhu.Service.Activity.ActivityClient())
                    {
                        var result1 = await client.RefreshActivePageListModelCacheAsync(new Service.Activity.Models.Requests.ActivtyPageRequest()
                        {
                            Channel = "wap",
                            HashKey = activePageList.HashKey,
                        });

                        result1.ThrowIfException(true);
                        var result2 = await client.RefreshActivePageListModelCacheAsync(new Service.Activity.Models.Requests.ActivtyPageRequest()
                        {
                            ActivityId = activePageList.PKGuid.Value,
                            Channel    = "website",
                            HashKey    = activePageList.HashKey,
                        });

                        result2.ThrowIfException(true);
                    }

                    var list = manager.GetEntityList <ActivePageContentEntity>(_ => _.FKActiveID == activeEntity.FKActiveID);
                    var lucy = list?.Where(_ => _.Type == 13)?.FirstOrDefault();
                    if (lucy != null)
                    {
                        using (var client = new Tuhu.Service.Activity.ActivityClient())
                        {
                            var result = await client.RefreshLuckWheelCacheAsync(lucy.ActivityID.ToString());

                            result.ThrowIfException(true);
                        }
                    }
                }

                #endregion

                return(Content(JsonConvert.SerializeObject(new
                {
                    state = "success",
                    message = "操作成功",
                    data = ""
                })));
            }
            catch (Exception em)
            {
                throw em;
            }
        }
        public ActionResult SubmitForm(string modeljson, string wheeljson)
        {
            modeljson = modeljson.Replace("\"&nbsp;\"", "null");
            wheeljson = wheeljson.Replace("\"&nbsp;\"", "null");
            try
            {
                BigBrandRewardListEntity entity = JsonConvert.DeserializeObject <BigBrandRewardListEntity>(modeljson);

                IEnumerable <BigBrandWheelEntity> wheel = null;
                if (!string.IsNullOrWhiteSpace(wheeljson))
                {
                    wheel = JsonConvert.DeserializeObject <IEnumerable <BigBrandWheelEntity> >(wheeljson);
                }

                RepositoryManager manager = new RepositoryManager();
                using (var db = manager.BeginTrans())
                {
                    if (entity.PKID == 0)
                    {
                        entity.HashKeyValue       = Tuhu.Provisioning.Common.SecurityHelper.Sha1Encrypt(Guid.NewGuid().ToString(), System.Text.Encoding.UTF8).Substring(0, 8);
                        entity.CreateDateTime     = DateTime.Now;
                        entity.LastUpdateDateTime = DateTime.Now;
                        entity.UpdateUserName     = User.Identity.Name;
                        entity.CreateUserName     = User.Identity.Name;
                        manager.Add <BigBrandRewardListEntity>(entity);
                        LoggerManager.InsertOplog(new ConfigHistory()
                        {
                            AfterValue = JsonConvert.SerializeObject(entity), Author = User.Identity.Name, Operation = "新增大翻牌活动", ObjectType = "BigBrand"
                        });
                    }
                    else
                    {
                        entity.LastUpdateDateTime = DateTime.Now;
                        entity.UpdateUserName     = User.Identity.Name;
                        manager.Update <BigBrandRewardListEntity>(entity);
                        LoggerManager.InsertOplog(new ConfigHistory()
                        {
                            AfterValue = JsonConvert.SerializeObject(entity), Author = User.Identity.Name, Operation = "更新大翻牌活动", ObjectType = "BigBrand"
                        });
                    }

                    Expression <Func <BigBrandWheelEntity, bool> > exp = _ => _.FKBigBrand == entity.PKID;
                    db.Delete <BigBrandWheelEntity>(exp);

                    if (wheel != null)
                    {
                        foreach (var item in wheel)
                        {
                            item.CreateDateTime     = DateTime.Now;
                            item.CreateUserName     = User.Identity.Name;
                            item.LastUpdateDateTime = DateTime.Now;
                            item.UpdateUserName     = User.Identity.Name;
                            item.FKBigBrand         = entity.PKID;

                            var array = item.FKPoolPKIDText.TrimEnd(',').Split(',');
                            if (array != null && array.Length > 0)
                            {
                                foreach (var s in array)
                                {
                                    int poolPKID = 0;
                                    if (int.TryParse(s, out poolPKID))
                                    {
                                        if (poolPKID != 0)
                                        {
                                            item.FKPoolPKID = poolPKID;
                                            string json      = JsonConvert.SerializeObject(item);
                                            var    tempModel = JsonConvert.DeserializeObject <BigBrandWheelEntity>(json);
                                            db.Insert <BigBrandWheelEntity>(tempModel);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    db.Commit();
                    LoggerManager.InsertOplog(new ConfigHistory()
                    {
                        AfterValue = JsonConvert.SerializeObject(wheel), Author = User.Identity.Name, Operation = "大翻牌明细", ObjectType = "BigBrand"
                    });
                }

                return(Content(JsonConvert.SerializeObject(new
                {
                    state = "success",
                    message = "操作成功",
                    data = ""
                })));
            }
            catch (Exception em)
            {
                throw em;
            }
        }