Example #1
0
        /// <summary>
        /// 刷新大翻盘的缓存
        /// </summary>
        /// <param name="pkid"></param>
        /// <returns></returns>
        public ActionResult Reload(int?pkid)
        {
            RepositoryManager manager = new RepositoryManager();
            Expression <Func <BigBrandRewardListEntity, bool> > exp = _ => _.PKID == pkid.Value && _.Is_Deleted == false;
            var entity = manager.GetEntity <BigBrandRewardListEntity>(exp);

            using (var client = new Tuhu.Service.Activity.BigBrandClient())
            {
                var result = client.UpdateBigBrand(entity.HashKeyValue);
                result.ThrowIfException(true);
                if (result.Result)
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        Code = 1,
                        Msg = "刷新成功"
                    })));
                }
                else
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        Code = 0,
                        Msg = "刷新失败"
                    })));
                }
            }
        }
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;
            }
        }