Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            int             yearMonth     = Convert.ToInt32(context.Request["yearmonth"]);
            string          websiteOwner  = bll.WebsiteOwner;
            TeamPerformance myPerformance = bll.GetMyPerformance(CurrentUserInfo.UserID, websiteOwner, yearMonth);

            List <UserLevelConfig> userLvlist = bll.QueryUserLevelList(websiteOwner, "DistributionOnLine", levelNumber: CurrentUserInfo.MemberLevel.ToString(), colName: "AutoId,LevelNumber,LevelString", showAll: true);

            string templatePath = context.Server.MapPath("/JsonConfig/ExcelTemplate/业绩确认表模板.xlsx");

            Dictionary <String, Object> dictSource = new Dictionary <string, object>();

            if (userLvlist.Count > 0)
            {
                dictSource.Add("lvname", userLvlist[0].LevelString);
            }
            dictSource.Add("name", CurrentUserInfo.TrueName);
            dictSource.Add("performance", Convert.ToDouble(myPerformance.Performance).ToString());
            dictSource.Add("rate", Convert.ToDouble(myPerformance.Rate) + "%");
            dictSource.Add("totalreward", Convert.ToDouble(myPerformance.TotalReward).ToString());
            dictSource.Add("childreward", Convert.ToDouble(myPerformance.ChildReward).ToString());

            dictSource.Add("fund", Convert.ToDouble((myPerformance.Reward * 20 / 100)).ToString());
            decimal trueamount = (myPerformance.Reward * 80 / 100);

            dictSource.Add("amount", Convert.ToDouble(trueamount).ToString());

            string ym           = myPerformance.YearMonth.ToString();
            string dicYearmonth = ym.Substring(0, 4) + "年" + ym.Substring(4) + "月";
            string dicMinAmount = trueamount.ToString("N");

            dictSource.Add("lower", string.Format("{0}应结算总金额  人民币小写:{1}", dicYearmonth, dicMinAmount));
            string cnAmount = CommonPlatform.Helper.MoneyHelper.GetCnString(trueamount.ToString());

            dictSource.Add("upper", string.Format("                       人民币大写:{0}", cnAmount));
            List <TeamPerformanceDetails> performanceList = bll.GetPerformanceDetailList(int.MaxValue, 1, "", "", websiteOwner, myPerformance.YearMonth, "", myPerformance.DetailIds);
            DataTable dt = null;

            if (performanceList.Count > 0)
            {
                List <Admin.Performance.ConfrimFormExport.lvGroup> lvList = performanceList.Where(p => p.AddType == "注册").GroupBy(g => new{
                    up   = g.Performance,
                    cate = g.AddNote.Replace("注册", "").Replace("实单审核", "")
                }).Select(l => new Admin.Performance.ConfrimFormExport.lvGroup
                {
                    cate   = l.Key.cate,
                    count  = l.Count(),
                    up     = l.Key.up,
                    amount = l.Sum(li => li.Performance)
                }).OrderBy(a => a.amount).ToList();
                List <Admin.Performance.ConfrimFormExport.lvGroup> upList = performanceList.Where(p => p.AddType == "升级").GroupBy(g => new
                {
                    cate = "升级金额"
                }).Select(l => new Admin.Performance.ConfrimFormExport.lvGroup
                {
                    cate   = l.Key.cate,
                    count  = l.Count(),
                    amount = l.Sum(li => li.Performance)
                }).OrderBy(a => a.amount).ToList();

                List <Admin.Performance.ConfrimFormExport.lvGroup> ceList = performanceList.Where(p => p.AddType == "撤单").GroupBy(g => new
                {
                    cate = "撤单扣除"
                }).Select(l => new Admin.Performance.ConfrimFormExport.lvGroup
                {
                    cate   = l.Key.cate,
                    count  = l.Count(),
                    amount = l.Sum(li => li.Performance)
                }).OrderBy(a => a.amount).ToList();

                List <Admin.Performance.ConfrimFormExport.lvGroup> upuList = performanceList.Where(p => p.AddType == "变更").GroupBy(g => new
                {
                    cate = "变更上级"
                }).Select(l => new Admin.Performance.ConfrimFormExport.lvGroup
                {
                    cate   = l.Key.cate,
                    count  = l.Count(),
                    amount = l.Sum(li => li.Performance)
                }).OrderBy(a => a.amount).ToList();

                lvList.AddRange(upList);
                lvList.AddRange(ceList);
                lvList.AddRange(upuList);

                if (lvList.Count > 0)
                {
                    dt = new DataTable();
                    dt.Columns.Add("num", typeof(string));
                    dt.Columns.Add("cate", typeof(string));
                    dt.Columns.Add("count", typeof(int));
                    dt.Columns.Add("up", typeof(string));
                    dt.Columns.Add("amount", typeof(string));
                    int num = 0;
                    foreach (var item in lvList)
                    {
                        num++;
                        DataRow dr = dt.NewRow();
                        dr["num"]    = num.ToString().PadLeft(3, '0');
                        dr["cate"]   = item.cate;
                        dr["count"]  = item.count;
                        dr["up"]     = item.up == 0 ? "" : Convert.ToDouble(item.up).ToString();
                        dr["amount"] = Convert.ToDouble(item.amount).ToString();
                        dt.Rows.Add(dr);
                    }
                    dictSource.Add("sumcount", lvList.Sum(p => p.count));
                    decimal sumamount = lvList.Sum(p => p.amount);
                    dictSource.Add("sumamount", Convert.ToDouble(sumamount).ToString());
                }
            }
            if (dt != null)
            {
                dt.TableName = "detail";
                dt.AcceptChanges();
            }
            MemoryStream ms      = CommonPlatform.Helper.Aspose.ExcelHelper.OutModelFileToStream(templatePath, dictSource, dt);
            ExportCache  exCache = new ExportCache()
            {
                FileName = string.Format("{1}业绩确认表_{0}.xls", CurrentUserInfo.TrueName, dicYearmonth),
                Stream   = ms
            };
            string cache = Guid.NewGuid().ToString("N").ToUpper();

            RedisHelper.RedisHelper.StringSetSerialize(cache, exCache, TimeSpan.FromMinutes(5));

            apiResp.status = true;
            apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.IsSuccess;
            apiResp.msg    = "生成完成";
            apiResp.result = new
            {
                cache = cache
            };
            bllUser.ContextResponse(context, apiResp);
        }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            int    rows         = Convert.ToInt32(context.Request["rows"]);
            int    page         = Convert.ToInt32(context.Request["page"]);
            string id           = context.Request["id"];
            string sum          = context.Request["sum"];
            string websiteOwner = bll.WebsiteOwner;

            TeamPerformance performance = bll.GetColByKey <TeamPerformance>("AutoId", id, "AutoId,YearMonth,DetailIds");
            string          ids         = string.IsNullOrWhiteSpace(performance.DetailIds) ? "-1" : performance.DetailIds;
            int             yearMonth   = performance.YearMonth;
            int             total       = bll.GetPerformanceDetailCount("", "", websiteOwner, yearMonth, "", ids);
            List <TeamPerformanceDetails> performanceList = new List <TeamPerformanceDetails>();

            if (total > 0)
            {
                performanceList = bll.GetPerformanceDetailList(rows, page, "", "", websiteOwner, yearMonth, "", ids);
            }

            decimal sumPerformance = 0;

            if (sum == "1")
            {
                sumPerformance = bll.GetPerformanceDetailSum("", "", websiteOwner, yearMonth, "", ids);
            }
            List <dynamic> resultList = new List <dynamic>();

            if (performanceList.Count > 0)
            {
                string          parentIds = ZentCloud.Common.MyStringHelper.ListToStr(performanceList.Select(p => p.DistributionOwner).ToList(), "'", ",");
                List <UserInfo> uuList    = bll.GetColMultListByKey <UserInfo>(int.MaxValue, 1, "UserID", parentIds, "AutoID,UserID,TrueName,Phone",
                                                                               websiteOwner: websiteOwner);
                foreach (TeamPerformanceDetails item in performanceList)
                {
                    UserInfo pu = uuList.FirstOrDefault(p => p.UserID == item.DistributionOwner);
                    resultList.Add(new
                    {
                        id          = item.AutoId,
                        name        = item.UserName,
                        phone       = item.UserPhone,
                        pid         = pu.AutoID,
                        pname       = pu.TrueName,
                        pphone      = pu.Phone,
                        performance = item.Performance,
                        addtype     = item.AddType,
                        addnote     = item.AddNote,
                        addtime     = item.AddTime.ToString("yyyy/MM/dd HH:mm:ss")
                    });
                }
            }

            apiResp.result = new
            {
                totalcount = total,
                list       = resultList,
                sum        = sumPerformance
            };
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.msg    = "获取业绩列表";
            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            int    rows         = int.MaxValue;
            int    page         = 1;
            string id           = context.Request["id"];
            string websiteOwner = bll.WebsiteOwner;

            TeamPerformance performance = bll.GetColByKey <TeamPerformance>("AutoId", id, "AutoId,YearMonth,DetailIds");
            string          ids         = string.IsNullOrWhiteSpace(performance.DetailIds) ? "-1" : performance.DetailIds;
            int             yearMonth   = performance.YearMonth;
            int             total       = bll.GetPerformanceDetailCount("", "", websiteOwner, yearMonth, "", ids);
            List <TeamPerformanceDetails> performanceList = new List <TeamPerformanceDetails>();

            if (total > 0)
            {
                performanceList = bll.GetPerformanceDetailList(rows, page, "", "", websiteOwner, yearMonth, "", ids);
            }

            DataTable dt = new DataTable();

            dt.Columns.Add("会员手机", typeof(string));
            dt.Columns.Add("会员姓名", typeof(string));
            dt.Columns.Add("推荐人手机", typeof(string));
            dt.Columns.Add("推荐人姓名", typeof(string));
            dt.Columns.Add("月份", typeof(int));
            dt.Columns.Add("事件", typeof(string));
            dt.Columns.Add("金额", typeof(decimal));
            dt.Columns.Add("时间", typeof(string));
            dt.Columns.Add("说明", typeof(string));
            if (performanceList.Count > 0)
            {
                string          parentIds = ZentCloud.Common.MyStringHelper.ListToStr(performanceList.Select(p => p.DistributionOwner).ToList(), "'", ",");
                List <UserInfo> uuList    = bll.GetColMultListByKey <UserInfo>(int.MaxValue, 1, "UserID", parentIds, "AutoID,UserID,TrueName,Phone",
                                                                               websiteOwner: websiteOwner);
                foreach (TeamPerformanceDetails item in performanceList)
                {
                    UserInfo pu = uuList.FirstOrDefault(p => p.UserID == item.DistributionOwner);

                    DataRow dr = dt.NewRow();
                    dr["会员手机"]  = item.UserPhone;
                    dr["会员姓名"]  = item.UserName;
                    dr["推荐人手机"] = pu == null ? "" : pu.Phone;
                    dr["推荐人姓名"] = pu == null ? "" : pu.TrueName;
                    dr["月份"]    = item.YearMonth;
                    dr["事件"]    = item.AddType;
                    dr["金额"]    = item.Performance;
                    dr["时间"]    = item.AddTime.ToString("yyyy-MM-dd HH:mm:ss");
                    dr["说明"]    = item.AddNote;
                    dt.Rows.Add(dr);
                }
                dt.AcceptChanges();
            }
            MemoryStream ms      = Web.DataLoadTool.NPOIHelper.Export(dt, "会员业绩明细");
            ExportCache  exCache = new ExportCache()
            {
                FileName = string.Format("会员业绩明细{0}.xls", DateTime.Now.ToString("yyyyMMddHHmm")),
                Stream   = ms
            };
            string cache = Guid.NewGuid().ToString("N").ToUpper();

            ZentCloud.Common.DataCache.SetCache(cache, exCache, slidingExpiration: TimeSpan.FromMinutes(5));

            apiResp.status = true;
            apiResp.code   = (int)BLLJIMP.Enums.APIErrCode.IsSuccess;
            apiResp.msg    = "生成完成";
            apiResp.result = new
            {
                cache = cache
            };
            bllUser.ContextResponse(context, apiResp);
        }