Exemplo n.º 1
0
        public void GetUserSummaryTest()
        {
            var accessToken = AccessTokenContainer.GetAccessToken(_appId);

            var result = AnalysisApi.GetUserSummary(accessToken, beginData, endData);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.list[0].ref_date != null);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            //如果没有配置租户信息,则必须前去配置
            if (!HasConfigWeiChat && IsSystemIenant)
            {
                return(RedirectToAction("WeiChatAppConfig", "Account_Tenant",
                                        new { area = "SystemAdmin", tenantId = TenantId }));
            }

            #region 获取最新关注的用户

            var lastUsers = GetLastUsers(8);
            ViewBag.LastUsers = lastUsers;

            #endregion

            var cache = WeiChat.Infrastructure.Cache.CacheManager.Current;

            #region 累积关注数

            {
                var value = cache.GetByTenant <int>("UserSummaryCount");
                if (value == default(int))
                {
                    value = SafeReturnHelper.SafeReturn(() =>
                    {
                        //TODO:切换SDK
                        var userCumulateData = AnalysisApi.GetUserCumulate(WeChatConfigManager.Current.GetAccessToken(),
                                                                           DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd"),
                                                                           DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"));

                        if ((userCumulateData.list != null) && (userCumulateData.list.Count > 0))
                        {
                            return(Convert.ToInt32(userCumulateData.list.First().cumulate_user));
                        }
                        return(default(int));
                    });
                }
                cache.AddOrUpdateByTenant("UserSummaryCount", value, TimeSpan.FromHours(12));
                ViewBag.UserSummaryCount = value;
            }

            #endregion

            #region 取消关注数、新关注数、净增用户数

            {
                //取消关注数
                var cancelUserCount = cache.GetByTenant <int>("CancelUserCount");
                //新关注数
                var newUserCount = cache.GetByTenant <int>("NewUserCount");
                //净增用户数
                var growUserCount = cache.GetByTenant <int>("GrowUserCount");
                if (newUserCount == default(int))
                {
                    var value =
                        SafeReturnHelper.SafeReturn(
                            () =>
                    {
                        //TODO:切换SDK
                        return(AnalysisApi.GetUserSummary(WeChatConfigManager.Current.GetAccessToken(),
                                                          DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd"),
                                                          DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd")));
                    });
                    if (value != null)
                    {
                        cancelUserCount = value.list.Select(p => Convert.ToInt32(p.cancel_user)).Sum();
                        newUserCount    = value.list.Select(p => Convert.ToInt32(p.new_user)).Sum();
                        growUserCount   = Convert.ToInt32(newUserCount) - Convert.ToInt32(cancelUserCount);
                        cache.AddOrUpdateByTenant("CancelUserCount", cancelUserCount, TimeSpan.FromHours(12));
                        cache.AddOrUpdateByTenant("NewUserCount", newUserCount, TimeSpan.FromHours(12));
                        cache.AddOrUpdateByTenant("GrowUserCount", growUserCount, TimeSpan.FromHours(12));
                    }
                }
                //取消关注数
                ViewBag.CancelUserCount = cancelUserCount;
                //新关注数
                ViewBag.NewUserCount = newUserCount;
                //净增用户数
                ViewBag.GrowUserCount = growUserCount;
            }

            #endregion

            ViewBag.ChartEnable = false;
            //如果粉丝量大于20万,禁用部分图表
            if (cache.GetByTenant <int>("UserSummaryCount") < 200000)
            {
                if (db.WeiChat_Users.Count() < 200000)
                {
                    ViewBag.ChartEnable = true;
                }
            }
            return(View());
        }