コード例 #1
0
        protected override UnitVipOverviewReportRD ProcessRequest(DTO.Base.APIRequest <UnitVipOverviewReportRP> pRequest)
        {
            var rd = new UnitVipOverviewReportRD();
            var rp = pRequest.Parameters;
            var agg_UnitDaily_VipCardTypeBLL   = new Agg_UnitDaily_VipCardTypeBLL(CurrentUserInfo);
            var agg_UnitMonthly_VipCardTypeBLL = new Agg_UnitMonthly_VipCardTypeBLL(CurrentUserInfo);
            var agg_UnitMonthlyBLL             = new Agg_UnitMonthlyBLL(CurrentUserInfo);
            var lstDayVipCardType   = default(Agg_UnitDaily_VipCardTypeEntity[]);
            var lstMonthVipCardType = default(Agg_UnitMonthly_VipCardTypeEntity[]);
            var lstMonth            = default(Agg_UnitMonthlyEntity[]);

            #region 查询数据
            var tasks = new List <Task>();
            //门店日结基础数据-会员等级
            tasks.Add(Task.Factory.StartNew(() =>
            {
                lstDayVipCardType = agg_UnitDaily_VipCardTypeBLL.GetEntitiesForVip(rp.CustomerID, rp.UnitID, Convert.ToDateTime(rp.Date));
            }));

            //门店月结数据-会员等级
            tasks.Add(Task.Factory.StartNew(() =>
            {
                lstMonthVipCardType = agg_UnitMonthly_VipCardTypeBLL.GetEntitiesForVip(rp.CustomerID, rp.UnitID, Convert.ToDateTime(rp.Date));
            }));

            //门店月结数据
            tasks.Add(Task.Factory.StartNew(() =>
            {
                lstMonth = agg_UnitMonthlyBLL.Get1YearEntities(rp.CustomerID, rp.UnitID, Convert.ToDateTime(rp.Date));
            }));

            //查询数据
            Task.WaitAll(tasks.ToArray());
            #endregion

            #region 全部会员数量(按会员卡等级)
            //有会员等级的数量
            var lstVipCount = lstDayVipCardType.Select(p => new UnitVipCountByVipCardLevel()
            {
                VipCardLevelName = p.VipCardTypeName, //会员卡等级名称
                VipCount         = p.VipCount         //会员数量
            }).ToList();

            //合计行并返回值
            rd.UnitVipCountList = UnitVipCountByVipCardLevel.TotalAllLevel(lstVipCount);
            #endregion

            #region 全部活跃会员数量(按会员卡等级)
            //有会员等级的数量
            var lstActiveVipCount = lstDayVipCardType.Select(p => new UnitVipCountByVipCardLevel()
            {
                VipCardLevelName = p.VipCardTypeName, //会员卡等级名称
                VipCount         = p.ActiveVipCount   //活跃会员数量
            }).ToList();

            //返回值
            rd.UnitActiveVipCountList = UnitVipCountByVipCardLevel.TotalAllLevel(lstActiveVipCount);
            #endregion

            #region 高价值会员数量(按会员卡等级)
            //有会员等级的数量
            var lstHighValueVipCount = lstDayVipCardType.Select(p => new UnitVipCountByVipCardLevel()
            {
                VipCardLevelName = p.VipCardTypeName,  //会员卡等级名称
                VipCount         = p.HighValueVipCount //高价值会员数量
            }).ToList();

            //返回值
            rd.UnitHighValueVipCountList = UnitVipCountByVipCardLevel.TotalAllLevel(lstHighValueVipCount);
            #endregion

            #region 门店本月新增会员数量(按会员卡等级)
            //有会员等级的数量
            var lstNewVipCount = lstMonthVipCardType.Select(p => new UnitVipCountByVipCardLevel()
            {
                VipCardLevelName = p.VipCardTypeName, //会员卡等级名称
                VipCount         = p.NewVipCount      //会员数量
            }).ToList();

            //合计行并返回值
            rd.UnitCurrentMonthNewVipCountList = UnitVipCountByVipCardLevel.TotalAllLevel(lstNewVipCount);
            #endregion

            #region 门店12月新增会员数量
            //门店12月新增会员数量
            var lstMonthNewVipCount = lstMonth.Select(p => new UnitMonthNewVipCount()
            {
                Month       = Convert.ToDateTime(p.DateCode).ToString("yyyy-MM"), //月份
                NewVipCount = p.NewVipCount                                       //新增会员数量
            }).ToList();

            //填充空缺数据
            DateTime startMonth = new DateTime(Convert.ToDateTime(rp.Date).Year, Convert.ToDateTime(rp.Date).Month, 1).AddMonths(-11);
            lstMonthNewVipCount = UnitMonthNewVipCount.AddEmptyItem(lstMonthNewVipCount, startMonth, 12);

            //返回值
            rd.Unit12MonthNewVipCountList = lstMonthNewVipCount;
            #endregion

            #region 门店与上月新增会员增减数量
            //本月新增会员增减数量
            UnitMonthNewVipCount CurrentMonthAddVipCount = lstMonthNewVipCount.Where(p => p.Month == Convert.ToDateTime(rp.Date).ToString("yyyy-MM")).FirstOrDefault();
            Int32 nCurrentMonthAddVipCount = (CurrentMonthAddVipCount == null) ? 0 : (Int32)CurrentMonthAddVipCount.NewVipCount;
            //上月新增会员增减数量
            UnitMonthNewVipCount LastMonthAddVipCount = lstMonthNewVipCount.Where(p => p.Month == Convert.ToDateTime(rp.Date).AddMonths(-1).ToString("yyyy-MM")).FirstOrDefault();
            Int32 nLastMonthAddVipCount = (LastMonthAddVipCount == null) ? 0 : (Int32)LastMonthAddVipCount.NewVipCount;
            //门店与上月新增会员增减数量
            rd.UnitCurrentMonthNewVipCountMoM = nCurrentMonthAddVipCount - nLastMonthAddVipCount;
            #endregion

            return(rd);
        }
コード例 #2
0
        protected override UnitMonthReportRD ProcessRequest(APIRequest <UnitMonthReportRP> pRequest)
        {
            //
            var rd = new UnitMonthReportRD();
            var rp = pRequest.Parameters;

            //
            var aggUnitMonthlyBLL            = new Agg_UnitMonthlyBLL(CurrentUserInfo);
            var rUnitProductMonthSalesTopBLL = new R_UnitProductMonthSalesTopBLL(CurrentUserInfo);
            var aggUnitMonthlyEmplBLL        = new Agg_UnitMonthly_EmplBLL(CurrentUserInfo);
            var aggUnitNowEmplBLL            = new Agg_UnitNow_EmplBLL(CurrentUserInfo);
            var t_UserBLL = new T_UserBLL(CurrentUserInfo);

            //
            var aggUnitMonthlyEntity              = default(Agg_UnitMonthlyEntity);              // 本月
            var lastMonthAggUnitMonthlyEntity     = default(Agg_UnitMonthlyEntity);              //  上月
            var lastYearAggUnitMonthlyEntity      = default(Agg_UnitMonthlyEntity);              //  去年同月
            var rUnitProductMonthSalesTopEntities = default(R_UnitProductMonthSalesTopEntity[]); //  销量榜
            var aggUnitMonthlyEmplEntities        = default(Agg_UnitMonthly_EmplEntity[]);       // 业绩榜
            //var setoffAggUnitMonthlyEmplEntities = default(Agg_UnitMonthly_EmplEntity[]);  // 集客榜
            var aggUnitNowEmplEntities = default(Agg_UnitNow_EmplEntity[]);                      //  员工总数据
            var t_UserEntities         = default(T_UserEntity[]);                                //门店员工

            //
            var tasks = new List <Task>();
            var date  = Convert.ToDateTime(rp.Date);

            tasks.Add(Task.Factory.StartNew(() =>
            {
                aggUnitMonthlyEntity = aggUnitMonthlyBLL.QueryByEntity(new Agg_UnitMonthlyEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(date.Year + "-" + date.Month + "-01")
                }, null).FirstOrDefault();
            }));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                var dateNew = date.AddMonths(-1);
                lastMonthAggUnitMonthlyEntity = aggUnitMonthlyBLL.QueryByEntity(new Agg_UnitMonthlyEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(dateNew.Year + "-" + dateNew.Month + "-01")
                }, null).FirstOrDefault();
            }));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                var dateNew = date.AddYears(-1);
                lastYearAggUnitMonthlyEntity = aggUnitMonthlyBLL.QueryByEntity(new Agg_UnitMonthlyEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(dateNew.Year + "-" + dateNew.Month + "-01")
                }, null).FirstOrDefault();
            }));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                rUnitProductMonthSalesTopEntities = rUnitProductMonthSalesTopBLL.PagedQueryByEntity(new R_UnitProductMonthSalesTopEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(date.Year + "-" + date.Month + "-01")
                }, new OrderBy[]
                {
                    new OrderBy
                    {
                        FieldName = "SalesQty",
                        Direction = OrderByDirections.Desc
                    }
                }, 10, 1).Entities;
            }));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                aggUnitMonthlyEmplEntities = aggUnitMonthlyEmplBLL.QueryByEntity(new Agg_UnitMonthly_EmplEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(date.Year + "-" + date.Month + "-01")
                }, null);
            }));
            //tasks.Add(Task.Factory.StartNew(() =>
            //{
            //    setoffAggUnitMonthlyEmplEntities = aggUnitMonthlyEmplBLL.PagedQueryByEntity(new Agg_UnitMonthly_EmplEntity
            //    {
            //        CustomerId = rp.CustomerID,
            //        UnitId = rp.UnitID,
            //        DateCode = Convert.ToDateTime(date.Year + "-" + date.Month + "-01")
            //    }, new OrderBy[]
            //    {
            //        new OrderBy
            //        {
            //            FieldName="setoffCount",
            //            Direction= OrderByDirections.Desc
            //        },
            //        new OrderBy
            //        {
            //            FieldName="EmplName",
            //            Direction=OrderByDirections.Asc
            //        }

            //    }, 10, 1).Entities;
            //}));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                aggUnitNowEmplEntities = aggUnitNowEmplBLL.QueryByEntity(new Agg_UnitNow_EmplEntity
                {
                    CustomerId = rp.CustomerID,
                    UnitId     = rp.UnitID,
                    DateCode   = Convert.ToDateTime(rp.Date)
                }, null);
            }));
            tasks.Add(Task.Factory.StartNew(() =>
            {
                t_UserEntities = t_UserBLL.GetEntitiesByCustomerIdUnitId(rp.CustomerID, rp.UnitID);
            }));
            Task.WaitAll(tasks.ToArray());

            // 本月
            if (aggUnitMonthlyEntity != null)
            {
                rd.UnitCurrentMonthSalesAmount     = aggUnitMonthlyEntity.SalesAmount;
                rd.UnitCurrentMonthNewVipCount     = aggUnitMonthlyEntity.NewVipCount;
                rd.UnitCurrentMonthOldVipBackCount = aggUnitMonthlyEntity.OldVipBackCount;
                rd.UnitCurrentMonthUseCouponCount  = aggUnitMonthlyEntity.UseCouponCount;
            }

            // 上月
            if (lastMonthAggUnitMonthlyEntity != null)
            {
                rd.UnitLastMonthSalesAmount     = lastMonthAggUnitMonthlyEntity.SalesAmount;
                rd.UnitLastMonthNewVipCount     = lastMonthAggUnitMonthlyEntity.NewVipCount;
                rd.UnitLastMonthOldVipBackCount = lastMonthAggUnitMonthlyEntity.OldVipBackCount;
                rd.UnitLastMonthUseCouponCount  = lastMonthAggUnitMonthlyEntity.UseCouponCount;
            }

            // 环比
            rd.UnitCurrentMonthSalesAmountMoM     = ReportCommonBLL.Instance.CalcuDoD(lastMonthAggUnitMonthlyEntity == null ? null : lastMonthAggUnitMonthlyEntity.SalesAmount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.SalesAmount);
            rd.UnitCurrentMonthNewVipCountMoM     = ReportCommonBLL.Instance.CalcuDoD(lastMonthAggUnitMonthlyEntity == null ? null : lastMonthAggUnitMonthlyEntity.NewVipCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.NewVipCount);
            rd.UnitCurrentMonthOldVipBackCountMoM = ReportCommonBLL.Instance.CalcuDoD(lastMonthAggUnitMonthlyEntity == null ? null : lastMonthAggUnitMonthlyEntity.OldVipBackCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.OldVipBackCount);
            rd.UnitCurrentMonthUseCouponCountMoM  = ReportCommonBLL.Instance.CalcuDoD(lastMonthAggUnitMonthlyEntity == null ? null : lastMonthAggUnitMonthlyEntity.UseCouponCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.UseCouponCount);

            // 同比
            rd.UnitCurrentMonthSalesAmountYoY     = ReportCommonBLL.Instance.CalcuDoD(lastYearAggUnitMonthlyEntity == null ? null : lastYearAggUnitMonthlyEntity.SalesAmount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.SalesAmount);
            rd.UnitCurrentMonthNewVipCountYoY     = ReportCommonBLL.Instance.CalcuDoD(lastYearAggUnitMonthlyEntity == null ? null : lastYearAggUnitMonthlyEntity.NewVipCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.NewVipCount);
            rd.UnitCurrentMonthOldVipBackCountYoY = ReportCommonBLL.Instance.CalcuDoD(lastYearAggUnitMonthlyEntity == null ? null : lastYearAggUnitMonthlyEntity.OldVipBackCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.OldVipBackCount);
            rd.UnitCurrentMonthUseCouponCountYoY  = ReportCommonBLL.Instance.CalcuDoD(lastYearAggUnitMonthlyEntity == null ? null : lastYearAggUnitMonthlyEntity.UseCouponCount, aggUnitMonthlyEntity == null ? null : aggUnitMonthlyEntity.UseCouponCount);

            // 销量榜
            rd.UnitCurrentMonthProductSalesTopList = new List <UnitProductSalesTop>();
            if (rUnitProductMonthSalesTopEntities != null && rUnitProductMonthSalesTopEntities.Length > 0)
            {
                var list = rUnitProductMonthSalesTopEntities.ToList();
                foreach (var item in list)
                {
                    rd.UnitCurrentMonthProductSalesTopList.Add(new UnitProductSalesTop
                    {
                        TopIndex    = item.TopIndex,
                        ProductName = item.item_name,
                        ProductSKU  = item.SkuName,
                        SalesAmount = item.SalesQty
                    });
                }
            }

            // 业绩榜
            rd.UnitCurrentMonthSalesAmountEmplTopList = new List <UnitSalesAmountEmplTop>();
            if (aggUnitMonthlyEmplEntities != null && aggUnitMonthlyEmplEntities.Length > 0)
            {
                var list = aggUnitMonthlyEmplEntities.OrderByDescending(p => p.SalesAmount).ThenBy(p => p.EmplName).ToList();
                var i    = 1;
                foreach (var item in list)
                {
                    var user = t_UserEntities.Where(p => p.user_id == item.EmplID).FirstOrDefault();
                    if (user == null)
                    {
                        continue;
                    }

                    rd.UnitCurrentMonthSalesAmountEmplTopList.Add(new UnitSalesAmountEmplTop
                    {
                        TopIndex    = i,
                        EmplName    = item.EmplName,
                        SalesAmount = item.SalesAmount
                    });
                    i++;
                    if (i > 10)
                    {
                        break;
                    }
                }
            }

            // 集客榜
            rd.UnitCurrentMonthSetoffEmplTopList = new List <UnitMonthSetoffEmplTop>();
            if (aggUnitMonthlyEmplEntities != null && aggUnitMonthlyEmplEntities.Length > 0)
            {
                var list = aggUnitMonthlyEmplEntities.OrderByDescending(p => p.SetoffCount).ThenBy(p => p.EmplName).ToList();
                var i    = 1;
                foreach (var item in list)
                {
                    var user = t_UserEntities.Where(p => p.user_id == item.EmplID).FirstOrDefault();
                    if (user == null)
                    {
                        continue;
                    }

                    var empSum = aggUnitNowEmplEntities.FirstOrDefault(it => it.EmplID == item.EmplID);
                    rd.UnitCurrentMonthSetoffEmplTopList.Add(new UnitMonthSetoffEmplTop
                    {
                        TopIndex         = i,
                        EmplName         = item.EmplName,
                        MonthSetoffCount = item.SetoffCount,
                        AllSetoffCount   = empSum != null ? empSum.SetoffCount : 0
                    });
                    i++;
                    if (i > 10)
                    {
                        break;
                    }
                }
            }

            //
            return(rd);
        }