Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
db857b44
Commit
db857b44
authored
Jun 10, 2021
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
1958764d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1349 additions
and
5 deletions
+1349
-5
RB_User_Statistics.cs
Mall.Model/Entity/User/RB_User_Statistics.cs
+20
-0
RB_User_Statistics_Extend.cs
Mall.Model/Extend/User/RB_User_Statistics_Extend.cs
+144
-0
StatisticsModule.cs
Mall.Module.MarketingCenter/StatisticsModule.cs
+1144
-5
LiveHouseController.cs
Mall.WebApi/Controllers/AppletWeChat/LiveHouseController.cs
+41
-0
No files found.
Mall.Model/Entity/User/RB_User_Statistics.cs
View file @
db857b44
...
@@ -143,5 +143,25 @@ namespace Mall.Model.Entity.User
...
@@ -143,5 +143,25 @@ namespace Mall.Model.Entity.User
/// </summary>
/// </summary>
public
DateTime
UpdateDate
{
get
;
set
;
}
public
DateTime
UpdateDate
{
get
;
set
;
}
/// <summary>
/// 普象累计
/// </summary>
public
int
PXLJNum
{
get
;
set
;
}
/// <summary>
/// VIP累计
/// </summary>
public
int
VipLJNum
{
get
;
set
;
}
/// <summary>
/// 银象累计
/// </summary>
public
int
YXLJNum
{
get
;
set
;
}
/// <summary>
/// 金象累计
/// </summary>
public
int
JXLJNum
{
get
;
set
;
}
}
}
}
}
Mall.Model/Extend/User/RB_User_Statistics_Extend.cs
View file @
db857b44
...
@@ -184,6 +184,150 @@ namespace Mall.Model.Extend.User
...
@@ -184,6 +184,150 @@ namespace Mall.Model.Extend.User
}
}
/// <summary>
/// 全部小数的
/// </summary>
public
class
User_Statistics_Query_V2
{
/// <summary>
/// 日期(yyyy-MM)
/// </summary>
public
string
Date
{
get
;
set
;
}
/// <summary>
/// 付款人数
/// </summary>
public
decimal
PeopleNum
{
get
;
set
;
}
/// <summary>
/// 订单数量
/// </summary>
public
decimal
OrderNum
{
get
;
set
;
}
/// <summary>
/// 付款金额
/// </summary>
public
decimal
PayMoney
{
get
;
set
;
}
/// <summary>
/// 购买数量
/// </summary>
public
decimal
BuyNum
{
get
;
set
;
}
/// <summary>
/// 累计付款人数
/// </summary>
public
decimal
TotalPayPeople
{
get
;
set
;
}
/// <summary>
/// 付款人数
/// </summary>
public
decimal
MAvgPeopleNum
{
get
;
set
;
}
/// <summary>
/// 订单数量
/// </summary>
public
decimal
MAvgOrderNum
{
get
;
set
;
}
/// <summary>
/// 付款金额
/// </summary>
public
decimal
MAvgPayMoney
{
get
;
set
;
}
/// <summary>
/// 购买数量
/// </summary>
public
decimal
MAvgBuyNum
{
get
;
set
;
}
/// <summary>
/// 平均每人购买单数
/// </summary>
public
decimal
PAvgOrderNum
{
get
;
set
;
}
/// <summary>
/// 平均每人购买件数
/// </summary>
public
decimal
PAvgBuyNum
{
get
;
set
;
}
/// <summary>
/// 平均每单单价
/// </summary>
public
decimal
PAvgUnitPrice
{
get
;
set
;
}
/// <summary>
/// 平均每人购买单价
/// </summary>
public
decimal
PAvgBuyPrice
{
get
;
set
;
}
/// <summary>
/// 平均会员数量
/// </summary>
public
decimal
PAvgMemberNum
{
get
;
set
;
}
/// <summary>
/// 平均付款累计人数
/// </summary>
public
decimal
PAvgPaymentNum
{
get
;
set
;
}
/// <summary>
/// 平均會員下訂單轉換率
/// </summary>
public
decimal
PAvgMOrderRate
{
get
;
set
;
}
/// <summary>
/// 平均复购人数
/// </summary>
public
decimal
PAvgReBuyNum
{
get
;
set
;
}
/// <summary>
/// 平均复购率
/// </summary>
public
decimal
PAvgReBuyRate
{
get
;
set
;
}
/// <summary>
/// 平均新人下单
/// </summary>
public
decimal
PAvgNewPeopleNum
{
get
;
set
;
}
/// <summary>
/// 平均利润率
/// </summary>
public
decimal
PAvgProfitRate
{
get
;
set
;
}
/// <summary>
/// 今日普象新增
/// </summary>
public
decimal
PXNum
{
get
;
set
;
}
/// <summary>
/// 今日VIP新增
/// </summary>
public
decimal
VipNum
{
get
;
set
;
}
/// <summary>
/// 今日银象新增
/// </summary>
public
decimal
YXNum
{
get
;
set
;
}
/// <summary>
/// 今日金象新增
/// </summary>
public
decimal
JXNum
{
get
;
set
;
}
/// <summary>
/// 总会员数量
/// </summary>
public
decimal
TotalMNum
{
get
;
set
;
}
/// <summary>
/// 利润
/// </summary>
public
decimal
Profit
{
get
;
set
;
}
}
/// <summary>
/// <summary>
/// 月度概率
/// 月度概率
/// </summary>
/// </summary>
...
...
Mall.Module.MarketingCenter/StatisticsModule.cs
View file @
db857b44
...
@@ -2154,6 +2154,7 @@ namespace Mall.Module.MarketingCenter
...
@@ -2154,6 +2154,7 @@ namespace Mall.Module.MarketingCenter
}
}
if
(
ReRateList
.
Any
())
if
(
ReRateList
.
Any
())
{
{
TotalMonthNum
++;
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
"平均"
};
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
"平均"
};
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
...
@@ -2523,6 +2524,7 @@ namespace Mall.Module.MarketingCenter
...
@@ -2523,6 +2524,7 @@ namespace Mall.Module.MarketingCenter
}
}
if
(
ReRateList
.
Any
())
if
(
ReRateList
.
Any
())
{
{
TotalMonthNum
++;
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
"平均"
};
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
"平均"
};
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
...
@@ -2693,23 +2695,1160 @@ namespace Mall.Module.MarketingCenter
...
@@ -2693,23 +2695,1160 @@ namespace Mall.Module.MarketingCenter
/// <returns></returns>
/// <returns></returns>
public
object
GetDSYearStartistics
(
int
startYear
,
int
endYear
,
int
tenantId
,
int
mallBaseId
)
public
object
GetDSYearStartistics
(
int
startYear
,
int
endYear
,
int
tenantId
,
int
mallBaseId
)
{
{
string
StartDate
=
startYear
+
"-01-01"
;
string
StartDate
=
Convert
.
ToDateTime
(
startYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM-dd"
);
//查询提前一个月数据 用于成长率对比
string
EndDate
=
Convert
.
ToDateTime
(
endYear
+
"-01-01"
).
AddYears
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
);
string
EndDate
=
Convert
.
ToDateTime
(
endYear
+
"-01-01"
).
AddYears
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
);
var
list
=
user_StatisticsRepository
.
GetList
(
new
RB_User_Statistics_Extend
()
{
TenantId
=
tenantId
,
MallBaseId
=
mallBaseId
,
StartTime
=
StartDate
,
EndTime
=
EndDate
});
var
list
=
user_StatisticsRepository
.
GetList
(
new
RB_User_Statistics_Extend
()
{
TenantId
=
tenantId
,
MallBaseId
=
mallBaseId
,
StartTime
=
StartDate
,
EndTime
=
EndDate
});
List
<
User_Statistics_Query
>
YearSList
=
new
List
<
User_Statistics_Query
>();
//月统计数据
List
<
User_Statistics_Query_V2
>
YearSList
=
new
List
<
User_Statistics_Query_V2
>();
//月统计数据
List
<
User_Statistics_Query
>
YearAvgSList
=
new
List
<
User_Statistics_Query
>();
//年平均统计数据
List
<
User_Statistics_Rate_Query
>
YearRateSList
=
new
List
<
User_Statistics_Rate_Query
>();
//年成长率统计数据
int
SYear
=
startYear
;
int
SYear
=
startYear
;
while
(
true
)
{
while
(
true
)
{
var
ylist
=
list
.
Where
(
x
=>
x
.
DateYear
==
SYear
).
ToList
();
var
ylist
=
list
.
Where
(
x
=>
x
.
DateYear
==
SYear
).
ToList
();
User_Statistics_Query
ymodel
=
new
User_Statistics_Query
()
{
Date
=
SYear
.
ToString
()
};
#
region
1
表统计
User_Statistics_Query_V2
ymodel
=
new
User_Statistics_Query_V2
()
{
Date
=
SYear
.
ToString
()
};
ymodel
.
PeopleNum
=
ylist
.
Sum
(
x
=>
x
.
PeopleNum
);
ymodel
.
PeopleNum
=
ylist
.
Sum
(
x
=>
x
.
PeopleNum
);
ymodel
.
OrderNum
=
ylist
.
Sum
(
x
=>
x
.
OrderNum
);
ymodel
.
PayMoney
=
ylist
.
Sum
(
x
=>
x
.
PayMoney
);
ymodel
.
BuyNum
=
ylist
.
Sum
(
x
=>
x
.
BuyNum
);
ymodel
.
TotalPayPeople
=
ylist
.
Any
()
?
ylist
.
Max
(
x
=>
x
.
MemberNum
)
:
0
;
ymodel
.
MAvgPeopleNum
=
ylist
.
Any
()
?
ylist
.
Max
(
x
=>
x
.
PaymentNum
)
:
0
;
ymodel
.
Profit
=
ylist
.
Sum
(
x
=>
x
.
Profit
);
ymodel
.
PXNum
=
ylist
.
Sum
(
x
=>
x
.
PXNum
);
ymodel
.
VipNum
=
ylist
.
Sum
(
x
=>
x
.
VipNum
);
ymodel
.
YXNum
=
ylist
.
Sum
(
x
=>
x
.
YXNum
);
ymodel
.
JXNum
=
ylist
.
Sum
(
x
=>
x
.
JXNum
);
ymodel
.
TotalMNum
=
ymodel
.
PXNum
+
ymodel
.
VipNum
+
ymodel
.
YXNum
+
ymodel
.
JXNum
;
YearSList
.
Add
(
ymodel
);
#
endregion
#
region
2
表平均统计
List
<
User_Statistics_Query
>
MonthSList
=
new
List
<
User_Statistics_Query
>();
//月统计数据
string
SMonth
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
);
//第一个月
string
endTime
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddYears
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM"
);
//最后一个月
int
TotalMonthNum
=
0
;
while
(
true
)
{
TotalMonthNum
++;
User_Statistics_Query
mmodel
=
new
User_Statistics_Query
()
{
Date
=
SMonth
};
//查询当月数据
var
mlist
=
list
.
Where
(
x
=>
x
.
DateMonth
==
SMonth
).
ToList
();
mmodel
.
PeopleNum
=
mlist
.
Sum
(
x
=>
x
.
PeopleNum
);
mmodel
.
OrderNum
=
mlist
.
Sum
(
x
=>
x
.
OrderNum
);
mmodel
.
PayMoney
=
mlist
.
Sum
(
x
=>
x
.
PayMoney
);
mmodel
.
BuyNum
=
mlist
.
Sum
(
x
=>
x
.
BuyNum
);
mmodel
.
TotalPayPeople
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
PaymentNum
)
:
0
;
mmodel
.
Profit
=
mlist
.
Sum
(
x
=>
x
.
Profit
);
int
TotalPXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
PXLJNum
)
:
0
;
int
TotalVIPNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
VipLJNum
)
:
0
;
int
TotalYXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
YXLJNum
)
:
0
;
int
TotalJXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
JXLJNum
)
:
0
;
mmodel
.
PXNum
=
TotalPXNum
;
mmodel
.
VipNum
=
TotalVIPNum
;
mmodel
.
YXNum
=
TotalYXNum
;
mmodel
.
JXNum
=
TotalJXNum
;
mmodel
.
TotalMNum
=
TotalPXNum
+
TotalVIPNum
+
TotalYXNum
+
TotalJXNum
;
#
region
求月平均
#
region
月平均参数
decimal
yPeopleNum
=
0
;
decimal
yOrderNum
=
0
;
decimal
yPayMoney
=
0
;
decimal
yBuyNum
=
0
;
decimal
yAvgOrderNum
=
0
;
decimal
yAvgBuyNum
=
0
;
decimal
yAvgUnitPrice
=
0
;
decimal
yAvgBuyPrice
=
0
;
decimal
yMemberNum
=
0
;
decimal
yPaymentNum
=
0
;
decimal
yMOrderRate
=
0
;
decimal
yReBuyNum
=
0
;
decimal
yReBuyRate
=
0
;
decimal
yNewPeopleNum
=
0
;
decimal
yPXNum
=
0
;
decimal
yVipNum
=
0
;
decimal
yYXNum
=
0
;
decimal
yJXNum
=
0
;
decimal
yProfit
=
0
;
decimal
yProfitRate
=
0
;
#
endregion
string
SDate
=
SMonth
+
"-01"
;
string
EDate
=
Convert
.
ToDateTime
(
SMonth
+
"-01"
).
AddMonths
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
);
int
MaxDay
=
Convert
.
ToDateTime
(
EDate
).
Day
;
//分三段求 每期的平均
if
(
true
)
{
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
OrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PayMoney
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
BuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
MemberNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PaymentNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
MOrderRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
VipNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
YXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
JXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
Profit
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ProfitRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
if
(
true
)
{
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
OrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PayMoney
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
BuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
MemberNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PaymentNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
MOrderRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
VipNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
YXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
JXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
Profit
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ProfitRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
if
(
true
)
{
int
NowDay
=
MaxDay
-
20
;
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PeopleNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
OrderNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PayMoney
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
BuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
MemberNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PaymentNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
MOrderRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
VipNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
YXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
JXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
Profit
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ProfitRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
if
(
startYear
==
endYear
)
{
#
region
月平均赋值
mmodel
.
MAvgPeopleNum
=
Math
.
Round
(
yPeopleNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgOrderNum
=
Math
.
Round
(
yOrderNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgPayMoney
=
Math
.
Round
(
yPayMoney
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgBuyNum
=
Math
.
Round
(
yBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgOrderNum
=
Math
.
Round
(
yAvgOrderNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgBuyNum
=
Math
.
Round
(
yAvgBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgUnitPrice
=
Math
.
Round
(
yAvgUnitPrice
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgBuyPrice
=
Math
.
Round
(
yAvgBuyPrice
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgMemberNum
=
Math
.
Round
(
yMemberNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgPaymentNum
=
Math
.
Round
(
yPaymentNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgMOrderRate
=
Math
.
Round
(
yMOrderRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgReBuyNum
=
Math
.
Round
(
yReBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgReBuyRate
=
Math
.
Round
(
yReBuyRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgNewPeopleNum
=
Math
.
Round
(
yNewPeopleNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgProfitRate
=
Math
.
Round
(
yProfitRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
endregion
MonthSList
.
Add
(
mmodel
);
if
(
SMonth
==
endTime
)
{
break
;
break
;
}
}
SYear
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddYears
(
1
).
Year
;
SMonth
=
Convert
.
ToDateTime
(
SMonth
+
"-01"
).
AddMonths
(
1
).
ToString
(
"yyyy-MM"
);
}
if
(
MonthSList
.
Any
())
{
string
ContrastMonth
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
);
var
MonthSList2
=
MonthSList
.
Where
(
x
=>
x
.
Date
!=
ContrastMonth
).
ToList
();
TotalMonthNum
--;
//计算平均/总计 平均需排除掉对比月数据
User_Statistics_Query
MTotalModel
=
new
User_Statistics_Query
()
{
Date
=
SYear
.
ToString
(),
MAvgPeopleNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgOrderNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgPayMoney
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgPayMoney
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgOrderNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgOrderNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgUnitPrice
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgUnitPrice
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgBuyPrice
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgBuyPrice
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgMemberNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgMemberNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgPaymentNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgPaymentNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgMOrderRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgMOrderRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgReBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgReBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgReBuyRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgReBuyRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgNewPeopleNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgNewPeopleNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgProfitRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgProfitRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
)
};
YearAvgSList
.
Add
(
MTotalModel
);
}
}
#
endregion
#
region
3
表成长率统计
List
<
User_Statistics_Rate_Query
>
ReRateList
=
new
List
<
User_Statistics_Rate_Query
>();
//概率数据
string
SRateMonth
=
SYear
+
"-01"
;
//这个要从查询第一个月开始
while
(
true
)
{
//求当月的所有比例 (当月-上月)/上月
var
NowMmodel
=
MonthSList
.
Where
(
x
=>
x
.
Date
==
SRateMonth
).
FirstOrDefault
();
var
PreMmodel
=
MonthSList
.
Where
(
x
=>
x
.
Date
==
Convert
.
ToDateTime
(
SRateMonth
+
"-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
)).
FirstOrDefault
();
return
""
;
User_Statistics_Rate_Query
smodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
SRateMonth
};
smodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreMmodel
.
MAvgPeopleNum
>
0
?
(
NowMmodel
.
MAvgPeopleNum
-
PreMmodel
.
MAvgPeopleNum
)
/
PreMmodel
.
MAvgPeopleNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgOrderNum
=
Math
.
Round
(
PreMmodel
.
MAvgOrderNum
>
0
?
(
NowMmodel
.
MAvgOrderNum
-
PreMmodel
.
MAvgOrderNum
)
/
PreMmodel
.
MAvgOrderNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgPayMoney
=
Math
.
Round
(
PreMmodel
.
MAvgPayMoney
>
0
?
(
NowMmodel
.
MAvgPayMoney
-
PreMmodel
.
MAvgPayMoney
)
/
PreMmodel
.
MAvgPayMoney
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgBuyNum
=
Math
.
Round
(
PreMmodel
.
MAvgBuyNum
>
0
?
(
NowMmodel
.
MAvgBuyNum
-
PreMmodel
.
MAvgBuyNum
)
/
PreMmodel
.
MAvgBuyNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgOrderNum
=
Math
.
Round
(
PreMmodel
.
PAvgOrderNum
>
0
?
(
NowMmodel
.
PAvgOrderNum
-
PreMmodel
.
PAvgOrderNum
)
/
PreMmodel
.
PAvgOrderNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgBuyNum
=
Math
.
Round
(
PreMmodel
.
PAvgBuyNum
>
0
?
(
NowMmodel
.
PAvgBuyNum
-
PreMmodel
.
PAvgBuyNum
)
/
PreMmodel
.
PAvgBuyNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreMmodel
.
PAvgUnitPrice
>
0
?
(
NowMmodel
.
PAvgUnitPrice
-
PreMmodel
.
PAvgUnitPrice
)
/
PreMmodel
.
PAvgUnitPrice
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreMmodel
.
PAvgBuyPrice
>
0
?
(
NowMmodel
.
PAvgBuyPrice
-
PreMmodel
.
PAvgBuyPrice
)
/
PreMmodel
.
PAvgBuyPrice
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreMmodel
.
PAvgMOrderRate
>
0
?
(
NowMmodel
.
PAvgMOrderRate
-
PreMmodel
.
PAvgMOrderRate
)
/
PreMmodel
.
PAvgMOrderRate
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgProfitRate
=
Math
.
Round
(
PreMmodel
.
PAvgProfitRate
>
0
?
(
NowMmodel
.
PAvgProfitRate
-
PreMmodel
.
PAvgProfitRate
)
/
PreMmodel
.
PAvgProfitRate
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgProfit
=
Math
.
Round
(
PreMmodel
.
Profit
>
0
?
(
NowMmodel
.
Profit
-
PreMmodel
.
Profit
)
/
PreMmodel
.
Profit
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgPXNum
=
Math
.
Round
(
PreMmodel
.
PXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
PXNum
-
PreMmodel
.
PXNum
)
/
PreMmodel
.
PXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgVipNum
=
Math
.
Round
(
PreMmodel
.
VipNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
VipNum
-
PreMmodel
.
VipNum
)
/
PreMmodel
.
VipNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgYXNum
=
Math
.
Round
(
PreMmodel
.
YXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
YXNum
-
PreMmodel
.
YXNum
)
/
PreMmodel
.
YXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgJXNum
=
Math
.
Round
(
PreMmodel
.
JXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
JXNum
-
PreMmodel
.
JXNum
)
/
PreMmodel
.
JXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgTotalMNum
=
Math
.
Round
(
PreMmodel
.
TotalMNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
TotalMNum
-
PreMmodel
.
TotalMNum
)
/
PreMmodel
.
TotalMNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
ReRateList
.
Add
(
smodel
);
if
(
SRateMonth
==
endTime
)
{
break
;
}
SRateMonth
=
Convert
.
ToDateTime
(
SRateMonth
+
"-01"
).
AddMonths
(
1
).
ToString
(
"yyyy-MM"
);
}
if
(
ReRateList
.
Any
())
{
TotalMonthNum
++;
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
SYear
.
ToString
()
};
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgPayMoney
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPayMoney
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgBuyNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgBuyNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgBuyNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgBuyNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgUnitPrice
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgUnitPrice
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgBuyPrice
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgBuyPrice
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgMOrderRate
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgMOrderRate
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgProfitRate
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgProfitRate
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgProfit
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgProfit
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgPXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgPXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgVipNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgVipNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgYXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgYXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgJXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgJXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgTotalMNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgTotalMNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
YearRateSList
.
Add
(
savgmodel
);
}
#
endregion
if
(
SYear
==
endYear
)
{
break
;
}
SYear
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddYears
(
1
).
Year
;
}
#
region
拿到所有年数据
成长率值
List
<
User_Statistics_Query_V2
>
YearSCList
=
new
List
<
User_Statistics_Query_V2
>();
//月统计数据 成长率
List
<
User_Statistics_Query
>
YearAvgSCList
=
new
List
<
User_Statistics_Query
>();
//年平均统计数据 成长率
List
<
User_Statistics_Rate_Query
>
YearRateSCList
=
new
List
<
User_Statistics_Rate_Query
>();
//年成长率统计数据 成长率
#
region
第一表
foreach
(
var
item
in
YearSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Query_V2
cmodel
=
new
User_Statistics_Query_V2
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
PeopleNum
=
Math
.
Round
(
PreModel
.
PeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
PeopleNum
-
PreModel
.
PeopleNum
)
/
PreModel
.
PeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
OrderNum
=
Math
.
Round
(
PreModel
.
OrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
OrderNum
-
PreModel
.
OrderNum
)
/
PreModel
.
OrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PayMoney
=
Math
.
Round
(
PreModel
.
PayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
PayMoney
-
PreModel
.
PayMoney
)
/
PreModel
.
PayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
BuyNum
=
Math
.
Round
(
PreModel
.
BuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
BuyNum
-
PreModel
.
BuyNum
)
/
PreModel
.
BuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
TotalPayPeople
=
Math
.
Round
(
PreModel
.
TotalPayPeople
>
0
?
Convert
.
ToDecimal
(
item
.
TotalPayPeople
-
PreModel
.
TotalPayPeople
)
/
PreModel
.
TotalPayPeople
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
Profit
=
Math
.
Round
(
PreModel
.
Profit
>
0
?
Convert
.
ToDecimal
(
item
.
Profit
-
PreModel
.
Profit
)
/
PreModel
.
Profit
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PXNum
=
Math
.
Round
(
PreModel
.
PXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PXNum
-
PreModel
.
PXNum
)
/
PreModel
.
PXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
VipNum
=
Math
.
Round
(
PreModel
.
VipNum
>
0
?
Convert
.
ToDecimal
(
item
.
VipNum
-
PreModel
.
VipNum
)
/
PreModel
.
VipNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
YXNum
=
Math
.
Round
(
PreModel
.
YXNum
>
0
?
Convert
.
ToDecimal
(
item
.
YXNum
-
PreModel
.
YXNum
)
/
PreModel
.
YXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
JXNum
=
Math
.
Round
(
PreModel
.
JXNum
>
0
?
Convert
.
ToDecimal
(
item
.
JXNum
-
PreModel
.
JXNum
)
/
PreModel
.
JXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
TotalMNum
=
cmodel
.
PXNum
+
cmodel
.
VipNum
+
cmodel
.
YXNum
+
cmodel
.
JXNum
;
YearSCList
.
Add
(
cmodel
);
}
}
YearSList
.
AddRange
(
YearSCList
);
YearSList
=
YearSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
//拍一下序
#
endregion
#
region
第二表
foreach
(
var
item
in
YearAvgSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearAvgSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Query
cmodel
=
new
User_Statistics_Query
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgOrderNum
=
Math
.
Round
(
PreModel
.
MAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgOrderNum
-
PreModel
.
MAvgOrderNum
)
/
PreModel
.
MAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPayMoney
=
Math
.
Round
(
PreModel
.
MAvgPayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPayMoney
-
PreModel
.
MAvgPayMoney
)
/
PreModel
.
MAvgPayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgBuyNum
=
Math
.
Round
(
PreModel
.
MAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgBuyNum
-
PreModel
.
MAvgBuyNum
)
/
PreModel
.
MAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgOrderNum
=
Math
.
Round
(
PreModel
.
PAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgOrderNum
-
PreModel
.
PAvgOrderNum
)
/
PreModel
.
PAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyNum
=
Math
.
Round
(
PreModel
.
PAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyNum
-
PreModel
.
PAvgBuyNum
)
/
PreModel
.
PAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreModel
.
PAvgBuyPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyPrice
-
PreModel
.
PAvgBuyPrice
)
/
PreModel
.
PAvgBuyPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreModel
.
PAvgUnitPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgUnitPrice
-
PreModel
.
PAvgUnitPrice
)
/
PreModel
.
PAvgUnitPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMemberNum
=
Math
.
Round
(
PreModel
.
PAvgMemberNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMemberNum
-
PreModel
.
PAvgMemberNum
)
/
PreModel
.
PAvgMemberNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgPaymentNum
=
Math
.
Round
(
PreModel
.
PAvgPaymentNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgPaymentNum
-
PreModel
.
PAvgPaymentNum
)
/
PreModel
.
PAvgPaymentNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreModel
.
PAvgMOrderRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMOrderRate
-
PreModel
.
PAvgMOrderRate
)
/
PreModel
.
PAvgMOrderRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgReBuyNum
=
Math
.
Round
(
PreModel
.
PAvgReBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgReBuyNum
-
PreModel
.
PAvgReBuyNum
)
/
PreModel
.
PAvgReBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgReBuyRate
=
Math
.
Round
(
PreModel
.
PAvgReBuyRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgReBuyRate
-
PreModel
.
PAvgReBuyRate
)
/
PreModel
.
PAvgReBuyRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgNewPeopleNum
=
Math
.
Round
(
PreModel
.
PAvgNewPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgNewPeopleNum
-
PreModel
.
PAvgNewPeopleNum
)
/
PreModel
.
PAvgNewPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfitRate
=
Math
.
Round
(
PreModel
.
PAvgProfitRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfitRate
-
PreModel
.
PAvgProfitRate
)
/
PreModel
.
PAvgProfitRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
YearAvgSCList
.
Add
(
cmodel
);
}
}
YearAvgSList
.
AddRange
(
YearAvgSCList
);
YearAvgSList
=
YearAvgSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
#
endregion
#
region
第三表
foreach
(
var
item
in
YearRateSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearRateSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Rate_Query
cmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgOrderNum
=
Math
.
Round
(
PreModel
.
MAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgOrderNum
-
PreModel
.
MAvgOrderNum
)
/
PreModel
.
MAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPayMoney
=
Math
.
Round
(
PreModel
.
MAvgPayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPayMoney
-
PreModel
.
MAvgPayMoney
)
/
PreModel
.
MAvgPayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgBuyNum
=
Math
.
Round
(
PreModel
.
MAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgBuyNum
-
PreModel
.
MAvgBuyNum
)
/
PreModel
.
MAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgOrderNum
=
Math
.
Round
(
PreModel
.
PAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgOrderNum
-
PreModel
.
PAvgOrderNum
)
/
PreModel
.
PAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyNum
=
Math
.
Round
(
PreModel
.
PAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyNum
-
PreModel
.
PAvgBuyNum
)
/
PreModel
.
PAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreModel
.
PAvgBuyPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyPrice
-
PreModel
.
PAvgBuyPrice
)
/
PreModel
.
PAvgBuyPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreModel
.
PAvgUnitPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgUnitPrice
-
PreModel
.
PAvgUnitPrice
)
/
PreModel
.
PAvgUnitPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreModel
.
PAvgMOrderRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMOrderRate
-
PreModel
.
PAvgMOrderRate
)
/
PreModel
.
PAvgMOrderRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfitRate
=
Math
.
Round
(
PreModel
.
PAvgProfitRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfitRate
-
PreModel
.
PAvgProfitRate
)
/
PreModel
.
PAvgProfitRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgPXNum
=
Math
.
Round
(
PreModel
.
PAvgPXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgPXNum
-
PreModel
.
PAvgPXNum
)
/
PreModel
.
PAvgPXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgVipNum
=
Math
.
Round
(
PreModel
.
PAvgVipNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgVipNum
-
PreModel
.
PAvgVipNum
)
/
PreModel
.
PAvgVipNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgYXNum
=
Math
.
Round
(
PreModel
.
PAvgYXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgYXNum
-
PreModel
.
PAvgYXNum
)
/
PreModel
.
PAvgYXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgJXNum
=
Math
.
Round
(
PreModel
.
PAvgJXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgJXNum
-
PreModel
.
PAvgJXNum
)
/
PreModel
.
PAvgJXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgTotalMNum
=
Math
.
Round
(
PreModel
.
PAvgTotalMNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgTotalMNum
-
PreModel
.
PAvgTotalMNum
)
/
PreModel
.
PAvgTotalMNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfit
=
Math
.
Round
(
PreModel
.
PAvgProfit
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfit
-
PreModel
.
PAvgProfit
)
/
PreModel
.
PAvgProfit
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
YearRateSCList
.
Add
(
cmodel
);
}
}
YearRateSList
.
AddRange
(
YearRateSCList
);
YearRateSList
=
YearRateSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
#
endregion
#
endregion
return
new
{
YearSList
=
YearSList
.
Select
(
x
=>
new
{
x
.
Date
,
x
.
PeopleNum
,
x
.
OrderNum
,
x
.
PayMoney
,
x
.
BuyNum
,
x
.
TotalPayPeople
,
x
.
MAvgPeopleNum
,
x
.
Profit
,
x
.
PXNum
,
x
.
VipNum
,
x
.
YXNum
,
x
.
JXNum
,
x
.
TotalMNum
}),
YearAvgSList
=
YearAvgSList
.
Select
(
x
=>
new
{
x
.
Date
,
x
.
MAvgPeopleNum
,
x
.
MAvgOrderNum
,
x
.
MAvgPayMoney
,
x
.
MAvgBuyNum
,
x
.
PAvgOrderNum
,
x
.
PAvgBuyNum
,
x
.
PAvgBuyPrice
,
x
.
PAvgUnitPrice
,
x
.
PAvgMemberNum
,
x
.
PAvgPaymentNum
,
x
.
PAvgMOrderRate
,
x
.
PAvgReBuyNum
,
x
.
PAvgReBuyRate
,
x
.
PAvgNewPeopleNum
,
x
.
PAvgProfitRate
}),
YearRateSList
};
}
/// <summary>
/// 年度统计excel导出
/// </summary>
/// <param name="startYear"></param>
/// <param name="endYear"></param>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <returns></returns>
public
List
<
ExcelDataSource
>
GetDSYearStartisticsToExcel
(
int
startYear
,
int
endYear
,
int
tenantId
,
int
mallBaseId
)
{
string
StartDate
=
Convert
.
ToDateTime
(
startYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM-dd"
);
//查询提前一个月数据 用于成长率对比
string
EndDate
=
Convert
.
ToDateTime
(
endYear
+
"-01-01"
).
AddYears
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
);
var
list
=
user_StatisticsRepository
.
GetList
(
new
RB_User_Statistics_Extend
()
{
TenantId
=
tenantId
,
MallBaseId
=
mallBaseId
,
StartTime
=
StartDate
,
EndTime
=
EndDate
});
List
<
User_Statistics_Query_V2
>
YearSList
=
new
List
<
User_Statistics_Query_V2
>();
//月统计数据
List
<
User_Statistics_Query
>
YearAvgSList
=
new
List
<
User_Statistics_Query
>();
//年平均统计数据
List
<
User_Statistics_Rate_Query
>
YearRateSList
=
new
List
<
User_Statistics_Rate_Query
>();
//年成长率统计数据
int
SYear
=
startYear
;
while
(
true
)
{
var
ylist
=
list
.
Where
(
x
=>
x
.
DateYear
==
SYear
).
ToList
();
#
region
1
表统计
User_Statistics_Query_V2
ymodel
=
new
User_Statistics_Query_V2
()
{
Date
=
SYear
.
ToString
()
};
ymodel
.
PeopleNum
=
ylist
.
Sum
(
x
=>
x
.
PeopleNum
);
ymodel
.
OrderNum
=
ylist
.
Sum
(
x
=>
x
.
OrderNum
);
ymodel
.
PayMoney
=
ylist
.
Sum
(
x
=>
x
.
PayMoney
);
ymodel
.
BuyNum
=
ylist
.
Sum
(
x
=>
x
.
BuyNum
);
ymodel
.
TotalPayPeople
=
ylist
.
Any
()
?
ylist
.
Max
(
x
=>
x
.
MemberNum
)
:
0
;
ymodel
.
MAvgPeopleNum
=
ylist
.
Any
()
?
ylist
.
Max
(
x
=>
x
.
PaymentNum
)
:
0
;
ymodel
.
Profit
=
ylist
.
Sum
(
x
=>
x
.
Profit
);
ymodel
.
PXNum
=
ylist
.
Sum
(
x
=>
x
.
PXNum
);
ymodel
.
VipNum
=
ylist
.
Sum
(
x
=>
x
.
VipNum
);
ymodel
.
YXNum
=
ylist
.
Sum
(
x
=>
x
.
YXNum
);
ymodel
.
JXNum
=
ylist
.
Sum
(
x
=>
x
.
JXNum
);
ymodel
.
TotalMNum
=
ymodel
.
PXNum
+
ymodel
.
VipNum
+
ymodel
.
YXNum
+
ymodel
.
JXNum
;
YearSList
.
Add
(
ymodel
);
#
endregion
#
region
2
表平均统计
List
<
User_Statistics_Query
>
MonthSList
=
new
List
<
User_Statistics_Query
>();
//月统计数据
string
SMonth
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
);
//第一个月
string
endTime
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddYears
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM"
);
//最后一个月
int
TotalMonthNum
=
0
;
while
(
true
)
{
TotalMonthNum
++;
User_Statistics_Query
mmodel
=
new
User_Statistics_Query
()
{
Date
=
SMonth
};
//查询当月数据
var
mlist
=
list
.
Where
(
x
=>
x
.
DateMonth
==
SMonth
).
ToList
();
mmodel
.
PeopleNum
=
mlist
.
Sum
(
x
=>
x
.
PeopleNum
);
mmodel
.
OrderNum
=
mlist
.
Sum
(
x
=>
x
.
OrderNum
);
mmodel
.
PayMoney
=
mlist
.
Sum
(
x
=>
x
.
PayMoney
);
mmodel
.
BuyNum
=
mlist
.
Sum
(
x
=>
x
.
BuyNum
);
mmodel
.
TotalPayPeople
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
PaymentNum
)
:
0
;
mmodel
.
Profit
=
mlist
.
Sum
(
x
=>
x
.
Profit
);
int
TotalPXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
PXLJNum
)
:
0
;
int
TotalVIPNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
VipLJNum
)
:
0
;
int
TotalYXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
YXLJNum
)
:
0
;
int
TotalJXNum
=
mlist
.
Any
()
?
mlist
.
Max
(
x
=>
x
.
JXLJNum
)
:
0
;
mmodel
.
PXNum
=
TotalPXNum
;
mmodel
.
VipNum
=
TotalVIPNum
;
mmodel
.
YXNum
=
TotalYXNum
;
mmodel
.
JXNum
=
TotalJXNum
;
mmodel
.
TotalMNum
=
TotalPXNum
+
TotalVIPNum
+
TotalYXNum
+
TotalJXNum
;
#
region
求月平均
#
region
月平均参数
decimal
yPeopleNum
=
0
;
decimal
yOrderNum
=
0
;
decimal
yPayMoney
=
0
;
decimal
yBuyNum
=
0
;
decimal
yAvgOrderNum
=
0
;
decimal
yAvgBuyNum
=
0
;
decimal
yAvgUnitPrice
=
0
;
decimal
yAvgBuyPrice
=
0
;
decimal
yMemberNum
=
0
;
decimal
yPaymentNum
=
0
;
decimal
yMOrderRate
=
0
;
decimal
yReBuyNum
=
0
;
decimal
yReBuyRate
=
0
;
decimal
yNewPeopleNum
=
0
;
decimal
yPXNum
=
0
;
decimal
yVipNum
=
0
;
decimal
yYXNum
=
0
;
decimal
yJXNum
=
0
;
decimal
yProfit
=
0
;
decimal
yProfitRate
=
0
;
#
endregion
string
SDate
=
SMonth
+
"-01"
;
string
EDate
=
Convert
.
ToDateTime
(
SMonth
+
"-01"
).
AddMonths
(
1
).
AddDays
(-
1
).
ToString
(
"yyyy-MM-dd"
);
int
MaxDay
=
Convert
.
ToDateTime
(
EDate
).
Day
;
//分三段求 每期的平均
if
(
true
)
{
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
OrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PayMoney
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
BuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
MemberNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PaymentNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
MOrderRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
PXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
VipNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
YXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
JXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
Profit
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
<=
10
).
Sum
(
x
=>
x
.
ProfitRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
if
(
true
)
{
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
OrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PayMoney
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
BuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
MemberNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PaymentNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
MOrderRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
PXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
VipNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
YXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
JXNum
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
Profit
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
10
&&
x
.
Date
.
Day
<=
20
).
Sum
(
x
=>
x
.
ProfitRate
))
/
10
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
if
(
true
)
{
int
NowDay
=
MaxDay
-
20
;
#
region
本月
decimal
PeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PeopleNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
OrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
OrderNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PayMoney
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PayMoney
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
BuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
BuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgOrderNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgOrderNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgBuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgUnitPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgUnitPrice
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
AvgBuyPrice
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
AvgBuyPrice
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MemberNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
MemberNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PaymentNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PaymentNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
MOrderRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
MOrderRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ReBuyNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ReBuyRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ReBuyRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
NewPeopleNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
NewPeopleNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
PXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
PXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
VipNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
VipNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
YXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
YXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
JXNum
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
JXNum
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
Profit
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
Profit
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
decimal
ProfitRate
=
Math
.
Round
(
Convert
.
ToDecimal
(
mlist
.
Where
(
x
=>
x
.
Date
.
Day
>
20
).
Sum
(
x
=>
x
.
ProfitRate
))
/
NowDay
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
region
月平均
yPeopleNum
+=
PeopleNum
;
yOrderNum
+=
OrderNum
;
yPayMoney
+=
PayMoney
;
yBuyNum
+=
BuyNum
;
yAvgOrderNum
+=
AvgOrderNum
;
yAvgBuyNum
+=
AvgBuyNum
;
yAvgUnitPrice
+=
AvgUnitPrice
;
yAvgBuyPrice
+=
AvgBuyPrice
;
yMemberNum
+=
MemberNum
;
yPaymentNum
+=
PaymentNum
;
yMOrderRate
+=
MOrderRate
;
yReBuyNum
+=
ReBuyNum
;
yReBuyRate
+=
ReBuyRate
;
yNewPeopleNum
+=
NewPeopleNum
;
yPXNum
+=
PXNum
;
yVipNum
+=
VipNum
;
yYXNum
+=
YXNum
;
yJXNum
+=
JXNum
;
yProfit
+=
Profit
;
yProfitRate
+=
ProfitRate
;
#
endregion
}
#
region
月平均赋值
mmodel
.
MAvgPeopleNum
=
Math
.
Round
(
yPeopleNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgOrderNum
=
Math
.
Round
(
yOrderNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgPayMoney
=
Math
.
Round
(
yPayMoney
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
MAvgBuyNum
=
Math
.
Round
(
yBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgOrderNum
=
Math
.
Round
(
yAvgOrderNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgBuyNum
=
Math
.
Round
(
yAvgBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgUnitPrice
=
Math
.
Round
(
yAvgUnitPrice
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgBuyPrice
=
Math
.
Round
(
yAvgBuyPrice
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgMemberNum
=
Math
.
Round
(
yMemberNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgPaymentNum
=
Math
.
Round
(
yPaymentNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgMOrderRate
=
Math
.
Round
(
yMOrderRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgReBuyNum
=
Math
.
Round
(
yReBuyNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgReBuyRate
=
Math
.
Round
(
yReBuyRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgNewPeopleNum
=
Math
.
Round
(
yNewPeopleNum
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
mmodel
.
PAvgProfitRate
=
Math
.
Round
(
yProfitRate
/
3
,
2
,
MidpointRounding
.
AwayFromZero
);
#
endregion
#
endregion
MonthSList
.
Add
(
mmodel
);
if
(
SMonth
==
endTime
)
{
break
;
}
SMonth
=
Convert
.
ToDateTime
(
SMonth
+
"-01"
).
AddMonths
(
1
).
ToString
(
"yyyy-MM"
);
}
if
(
MonthSList
.
Any
())
{
string
ContrastMonth
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
);
var
MonthSList2
=
MonthSList
.
Where
(
x
=>
x
.
Date
!=
ContrastMonth
).
ToList
();
TotalMonthNum
--;
//计算平均/总计 平均需排除掉对比月数据
User_Statistics_Query
MTotalModel
=
new
User_Statistics_Query
()
{
Date
=
SYear
.
ToString
(),
MAvgPeopleNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgOrderNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgPayMoney
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgPayMoney
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
MAvgBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
MAvgBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgOrderNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgOrderNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgUnitPrice
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgUnitPrice
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgBuyPrice
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgBuyPrice
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgMemberNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgMemberNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgPaymentNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgPaymentNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgMOrderRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgMOrderRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgReBuyNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgReBuyNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgReBuyRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgReBuyRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgNewPeopleNum
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgNewPeopleNum
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
),
PAvgProfitRate
=
Math
.
Round
(
MonthSList2
.
Sum
(
x
=>
x
.
PAvgProfitRate
)
/
TotalMonthNum
,
2
,
MidpointRounding
.
AwayFromZero
)
};
YearAvgSList
.
Add
(
MTotalModel
);
}
#
endregion
#
region
3
表成长率统计
List
<
User_Statistics_Rate_Query
>
ReRateList
=
new
List
<
User_Statistics_Rate_Query
>();
//概率数据
string
SRateMonth
=
SYear
+
"-01"
;
//这个要从查询第一个月开始
while
(
true
)
{
//求当月的所有比例 (当月-上月)/上月
var
NowMmodel
=
MonthSList
.
Where
(
x
=>
x
.
Date
==
SRateMonth
).
FirstOrDefault
();
var
PreMmodel
=
MonthSList
.
Where
(
x
=>
x
.
Date
==
Convert
.
ToDateTime
(
SRateMonth
+
"-01"
).
AddMonths
(-
1
).
ToString
(
"yyyy-MM"
)).
FirstOrDefault
();
User_Statistics_Rate_Query
smodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
SRateMonth
};
smodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreMmodel
.
MAvgPeopleNum
>
0
?
(
NowMmodel
.
MAvgPeopleNum
-
PreMmodel
.
MAvgPeopleNum
)
/
PreMmodel
.
MAvgPeopleNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgOrderNum
=
Math
.
Round
(
PreMmodel
.
MAvgOrderNum
>
0
?
(
NowMmodel
.
MAvgOrderNum
-
PreMmodel
.
MAvgOrderNum
)
/
PreMmodel
.
MAvgOrderNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgPayMoney
=
Math
.
Round
(
PreMmodel
.
MAvgPayMoney
>
0
?
(
NowMmodel
.
MAvgPayMoney
-
PreMmodel
.
MAvgPayMoney
)
/
PreMmodel
.
MAvgPayMoney
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
MAvgBuyNum
=
Math
.
Round
(
PreMmodel
.
MAvgBuyNum
>
0
?
(
NowMmodel
.
MAvgBuyNum
-
PreMmodel
.
MAvgBuyNum
)
/
PreMmodel
.
MAvgBuyNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgOrderNum
=
Math
.
Round
(
PreMmodel
.
PAvgOrderNum
>
0
?
(
NowMmodel
.
PAvgOrderNum
-
PreMmodel
.
PAvgOrderNum
)
/
PreMmodel
.
PAvgOrderNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgBuyNum
=
Math
.
Round
(
PreMmodel
.
PAvgBuyNum
>
0
?
(
NowMmodel
.
PAvgBuyNum
-
PreMmodel
.
PAvgBuyNum
)
/
PreMmodel
.
PAvgBuyNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreMmodel
.
PAvgUnitPrice
>
0
?
(
NowMmodel
.
PAvgUnitPrice
-
PreMmodel
.
PAvgUnitPrice
)
/
PreMmodel
.
PAvgUnitPrice
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreMmodel
.
PAvgBuyPrice
>
0
?
(
NowMmodel
.
PAvgBuyPrice
-
PreMmodel
.
PAvgBuyPrice
)
/
PreMmodel
.
PAvgBuyPrice
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreMmodel
.
PAvgMOrderRate
>
0
?
(
NowMmodel
.
PAvgMOrderRate
-
PreMmodel
.
PAvgMOrderRate
)
/
PreMmodel
.
PAvgMOrderRate
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgProfitRate
=
Math
.
Round
(
PreMmodel
.
PAvgProfitRate
>
0
?
(
NowMmodel
.
PAvgProfitRate
-
PreMmodel
.
PAvgProfitRate
)
/
PreMmodel
.
PAvgProfitRate
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgProfit
=
Math
.
Round
(
PreMmodel
.
Profit
>
0
?
(
NowMmodel
.
Profit
-
PreMmodel
.
Profit
)
/
PreMmodel
.
Profit
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgPXNum
=
Math
.
Round
(
PreMmodel
.
PXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
PXNum
-
PreMmodel
.
PXNum
)
/
PreMmodel
.
PXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgVipNum
=
Math
.
Round
(
PreMmodel
.
VipNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
VipNum
-
PreMmodel
.
VipNum
)
/
PreMmodel
.
VipNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgYXNum
=
Math
.
Round
(
PreMmodel
.
YXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
YXNum
-
PreMmodel
.
YXNum
)
/
PreMmodel
.
YXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgJXNum
=
Math
.
Round
(
PreMmodel
.
JXNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
JXNum
-
PreMmodel
.
JXNum
)
/
PreMmodel
.
JXNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
smodel
.
PAvgTotalMNum
=
Math
.
Round
(
PreMmodel
.
TotalMNum
>
0
?
Convert
.
ToDecimal
(
NowMmodel
.
TotalMNum
-
PreMmodel
.
TotalMNum
)
/
PreMmodel
.
TotalMNum
:
1
,
4
,
MidpointRounding
.
AwayFromZero
)
*
100
;
ReRateList
.
Add
(
smodel
);
if
(
SRateMonth
==
endTime
)
{
break
;
}
SRateMonth
=
Convert
.
ToDateTime
(
SRateMonth
+
"-01"
).
AddMonths
(
1
).
ToString
(
"yyyy-MM"
);
}
if
(
ReRateList
.
Any
())
{
TotalMonthNum
++;
User_Statistics_Rate_Query
savgmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
SYear
.
ToString
()
};
savgmodel
.
MAvgPeopleNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPeopleNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgPayMoney
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgPayMoney
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
MAvgBuyNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
MAvgBuyNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgOrderNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgOrderNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgBuyNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgBuyNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgUnitPrice
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgUnitPrice
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgBuyPrice
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgBuyPrice
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgMOrderRate
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgMOrderRate
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgProfitRate
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgProfitRate
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgProfit
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgProfit
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgPXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgPXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgVipNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgVipNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgYXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgYXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgJXNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgJXNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
savgmodel
.
PAvgTotalMNum
=
Math
.
Round
(
ReRateList
.
Sum
(
x
=>
x
.
PAvgTotalMNum
)
/
(
TotalMonthNum
-
1
),
2
,
MidpointRounding
.
AwayFromZero
);
YearRateSList
.
Add
(
savgmodel
);
}
#
endregion
if
(
SYear
==
endYear
)
{
break
;
}
SYear
=
Convert
.
ToDateTime
(
SYear
+
"-01-01"
).
AddYears
(
1
).
Year
;
}
#
region
拿到所有年数据
成长率值
List
<
User_Statistics_Query_V2
>
YearSCList
=
new
List
<
User_Statistics_Query_V2
>();
//月统计数据 成长率
List
<
User_Statistics_Query
>
YearAvgSCList
=
new
List
<
User_Statistics_Query
>();
//年平均统计数据 成长率
List
<
User_Statistics_Rate_Query
>
YearRateSCList
=
new
List
<
User_Statistics_Rate_Query
>();
//年成长率统计数据 成长率
#
region
第一表
foreach
(
var
item
in
YearSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Query_V2
cmodel
=
new
User_Statistics_Query_V2
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
PeopleNum
=
Math
.
Round
(
PreModel
.
PeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
PeopleNum
-
PreModel
.
PeopleNum
)
/
PreModel
.
PeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
OrderNum
=
Math
.
Round
(
PreModel
.
OrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
OrderNum
-
PreModel
.
OrderNum
)
/
PreModel
.
OrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PayMoney
=
Math
.
Round
(
PreModel
.
PayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
PayMoney
-
PreModel
.
PayMoney
)
/
PreModel
.
PayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
BuyNum
=
Math
.
Round
(
PreModel
.
BuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
BuyNum
-
PreModel
.
BuyNum
)
/
PreModel
.
BuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
TotalPayPeople
=
Math
.
Round
(
PreModel
.
TotalPayPeople
>
0
?
Convert
.
ToDecimal
(
item
.
TotalPayPeople
-
PreModel
.
TotalPayPeople
)
/
PreModel
.
TotalPayPeople
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
Profit
=
Math
.
Round
(
PreModel
.
Profit
>
0
?
Convert
.
ToDecimal
(
item
.
Profit
-
PreModel
.
Profit
)
/
PreModel
.
Profit
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PXNum
=
Math
.
Round
(
PreModel
.
PXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PXNum
-
PreModel
.
PXNum
)
/
PreModel
.
PXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
VipNum
=
Math
.
Round
(
PreModel
.
VipNum
>
0
?
Convert
.
ToDecimal
(
item
.
VipNum
-
PreModel
.
VipNum
)
/
PreModel
.
VipNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
YXNum
=
Math
.
Round
(
PreModel
.
YXNum
>
0
?
Convert
.
ToDecimal
(
item
.
YXNum
-
PreModel
.
YXNum
)
/
PreModel
.
YXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
JXNum
=
Math
.
Round
(
PreModel
.
JXNum
>
0
?
Convert
.
ToDecimal
(
item
.
JXNum
-
PreModel
.
JXNum
)
/
PreModel
.
JXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
TotalMNum
=
cmodel
.
PXNum
+
cmodel
.
VipNum
+
cmodel
.
YXNum
+
cmodel
.
JXNum
;
YearSCList
.
Add
(
cmodel
);
}
}
YearSList
.
AddRange
(
YearSCList
);
YearSList
=
YearSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
//拍一下序
#
endregion
#
region
第二表
foreach
(
var
item
in
YearAvgSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearAvgSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Query
cmodel
=
new
User_Statistics_Query
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgOrderNum
=
Math
.
Round
(
PreModel
.
MAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgOrderNum
-
PreModel
.
MAvgOrderNum
)
/
PreModel
.
MAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPayMoney
=
Math
.
Round
(
PreModel
.
MAvgPayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPayMoney
-
PreModel
.
MAvgPayMoney
)
/
PreModel
.
MAvgPayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgBuyNum
=
Math
.
Round
(
PreModel
.
MAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgBuyNum
-
PreModel
.
MAvgBuyNum
)
/
PreModel
.
MAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgOrderNum
=
Math
.
Round
(
PreModel
.
PAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgOrderNum
-
PreModel
.
PAvgOrderNum
)
/
PreModel
.
PAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyNum
=
Math
.
Round
(
PreModel
.
PAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyNum
-
PreModel
.
PAvgBuyNum
)
/
PreModel
.
PAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreModel
.
PAvgBuyPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyPrice
-
PreModel
.
PAvgBuyPrice
)
/
PreModel
.
PAvgBuyPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreModel
.
PAvgUnitPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgUnitPrice
-
PreModel
.
PAvgUnitPrice
)
/
PreModel
.
PAvgUnitPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMemberNum
=
Math
.
Round
(
PreModel
.
PAvgMemberNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMemberNum
-
PreModel
.
PAvgMemberNum
)
/
PreModel
.
PAvgMemberNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgPaymentNum
=
Math
.
Round
(
PreModel
.
PAvgPaymentNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgPaymentNum
-
PreModel
.
PAvgPaymentNum
)
/
PreModel
.
PAvgPaymentNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreModel
.
PAvgMOrderRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMOrderRate
-
PreModel
.
PAvgMOrderRate
)
/
PreModel
.
PAvgMOrderRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgReBuyNum
=
Math
.
Round
(
PreModel
.
PAvgReBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgReBuyNum
-
PreModel
.
PAvgReBuyNum
)
/
PreModel
.
PAvgReBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgReBuyRate
=
Math
.
Round
(
PreModel
.
PAvgReBuyRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgReBuyRate
-
PreModel
.
PAvgReBuyRate
)
/
PreModel
.
PAvgReBuyRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgNewPeopleNum
=
Math
.
Round
(
PreModel
.
PAvgNewPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgNewPeopleNum
-
PreModel
.
PAvgNewPeopleNum
)
/
PreModel
.
PAvgNewPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfitRate
=
Math
.
Round
(
PreModel
.
PAvgProfitRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfitRate
-
PreModel
.
PAvgProfitRate
)
/
PreModel
.
PAvgProfitRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
YearAvgSCList
.
Add
(
cmodel
);
}
}
YearAvgSList
.
AddRange
(
YearAvgSCList
);
YearAvgSList
=
YearAvgSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
#
endregion
#
region
第三表
foreach
(
var
item
in
YearRateSList
)
{
//第一年没有 从第二年开始
if
(
item
.
Date
!=
startYear
.
ToString
())
{
int
PreYear
=
Convert
.
ToInt32
(
item
.
Date
)
-
1
;
var
PreModel
=
YearRateSList
.
Where
(
x
=>
x
.
Date
==
PreYear
.
ToString
()).
FirstOrDefault
();
User_Statistics_Rate_Query
cmodel
=
new
User_Statistics_Rate_Query
()
{
Date
=
item
.
Date
+
"成長率"
};
// 成长率 = (当前年 - 上年) /上年
cmodel
.
MAvgPeopleNum
=
Math
.
Round
(
PreModel
.
MAvgPeopleNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPeopleNum
-
PreModel
.
MAvgPeopleNum
)
/
PreModel
.
MAvgPeopleNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgOrderNum
=
Math
.
Round
(
PreModel
.
MAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgOrderNum
-
PreModel
.
MAvgOrderNum
)
/
PreModel
.
MAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgPayMoney
=
Math
.
Round
(
PreModel
.
MAvgPayMoney
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgPayMoney
-
PreModel
.
MAvgPayMoney
)
/
PreModel
.
MAvgPayMoney
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
MAvgBuyNum
=
Math
.
Round
(
PreModel
.
MAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
MAvgBuyNum
-
PreModel
.
MAvgBuyNum
)
/
PreModel
.
MAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgOrderNum
=
Math
.
Round
(
PreModel
.
PAvgOrderNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgOrderNum
-
PreModel
.
PAvgOrderNum
)
/
PreModel
.
PAvgOrderNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyNum
=
Math
.
Round
(
PreModel
.
PAvgBuyNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyNum
-
PreModel
.
PAvgBuyNum
)
/
PreModel
.
PAvgBuyNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgBuyPrice
=
Math
.
Round
(
PreModel
.
PAvgBuyPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgBuyPrice
-
PreModel
.
PAvgBuyPrice
)
/
PreModel
.
PAvgBuyPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgUnitPrice
=
Math
.
Round
(
PreModel
.
PAvgUnitPrice
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgUnitPrice
-
PreModel
.
PAvgUnitPrice
)
/
PreModel
.
PAvgUnitPrice
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgMOrderRate
=
Math
.
Round
(
PreModel
.
PAvgMOrderRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgMOrderRate
-
PreModel
.
PAvgMOrderRate
)
/
PreModel
.
PAvgMOrderRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfitRate
=
Math
.
Round
(
PreModel
.
PAvgProfitRate
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfitRate
-
PreModel
.
PAvgProfitRate
)
/
PreModel
.
PAvgProfitRate
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgPXNum
=
Math
.
Round
(
PreModel
.
PAvgPXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgPXNum
-
PreModel
.
PAvgPXNum
)
/
PreModel
.
PAvgPXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgVipNum
=
Math
.
Round
(
PreModel
.
PAvgVipNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgVipNum
-
PreModel
.
PAvgVipNum
)
/
PreModel
.
PAvgVipNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgYXNum
=
Math
.
Round
(
PreModel
.
PAvgYXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgYXNum
-
PreModel
.
PAvgYXNum
)
/
PreModel
.
PAvgYXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgJXNum
=
Math
.
Round
(
PreModel
.
PAvgJXNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgJXNum
-
PreModel
.
PAvgJXNum
)
/
PreModel
.
PAvgJXNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgTotalMNum
=
Math
.
Round
(
PreModel
.
PAvgTotalMNum
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgTotalMNum
-
PreModel
.
PAvgTotalMNum
)
/
PreModel
.
PAvgTotalMNum
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
cmodel
.
PAvgProfit
=
Math
.
Round
(
PreModel
.
PAvgProfit
>
0
?
Convert
.
ToDecimal
(
item
.
PAvgProfit
-
PreModel
.
PAvgProfit
)
/
PreModel
.
PAvgProfit
:
1
,
2
,
MidpointRounding
.
AwayFromZero
);
YearRateSCList
.
Add
(
cmodel
);
}
}
YearRateSList
.
AddRange
(
YearRateSCList
);
YearRateSList
=
YearRateSList
.
OrderBy
(
x
=>
x
.
Date
).
ToList
();
#
endregion
#
endregion
#
region
组装
excel
数据
List
<
ExcelDataSource
>
DataList
=
new
List
<
ExcelDataSource
>();
#
region
第一表
#
region
组装标题
ExcelDataSource
header1
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>()
{
new
ExcelColumn
(
value
:
"年度"
){
CellWidth
=
25
,
HAlignmentEnum
=
HAlignmentEnum
.
CENTER
,
VAlignmentEnum
=
VAlignmentEnum
.
CENTER
}
},
ColumnHight
=
30
};
int
SYear2
=
startYear
;
while
(
true
)
{
header1
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
())
{
CellWidth
=
20
,
HAlignmentEnum
=
HAlignmentEnum
.
CENTER
,
VAlignmentEnum
=
VAlignmentEnum
.
CENTER
});
if
(
SYear2
>=
startYear
+
1
)
{
header1
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
()
+
"成長率"
)
{
CellWidth
=
20
,
HAlignmentEnum
=
HAlignmentEnum
.
CENTER
,
VAlignmentEnum
=
VAlignmentEnum
.
CENTER
});
}
if
(
SYear2
==
endYear
)
{
break
;
}
SYear2
=
Convert
.
ToDateTime
(
SYear2
+
"-01-01"
).
AddYears
(
1
).
Year
;
}
DataList
.
Add
(
header1
);
#
endregion
#
region
组装数据
List
<
string
>
DateRowList
=
new
List
<
string
>()
{
"PeopleNum|付款人數"
,
"OrderNum|付款單數"
,
"PayMoney|付款金額"
,
"BuyNum|購買件數"
,
"TotalPayPeople|會員总数"
,
"MAvgPeopleNum|累计付款人數"
,
"Profit|毛利"
,
"PXNum|普象"
,
"VipNum|VIP"
,
"YXNum|銀象"
,
"JXNum|金象"
,
"TotalMNum|會員總數"
};
foreach
(
var
item
in
DateRowList
)
{
var
fileNameArr
=
item
.
Split
(
'|'
);
ExcelDataSource
datarow2
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>(
23
)
{
new
ExcelColumn
(
value
:
fileNameArr
[
1
])
{
},
},
ColumnHight
=
30
};
foreach
(
var
qitem
in
YearSList
)
{
JObject
parms
=
JObject
.
Parse
(
JsonHelper
.
Serialize
(
qitem
));
string
mvalue
=
parms
.
GetStringValue
(
fileNameArr
[
0
]);
datarow2
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
mvalue
+
(
qitem
.
Date
.
Contains
(
"成長率"
)
?
"%"
:
""
))
{
});
}
DataList
.
Add
(
datarow2
);
}
#
endregion
#
endregion
#
region
第二表
#
region
组装标题
ExcelDataSource
header2
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>()
{
new
ExcelColumn
(
value
:
"年度"
){
}
},
ColumnHight
=
30
};
SYear2
=
startYear
;
while
(
true
)
{
header2
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
())
{
});
if
(
SYear2
>=
startYear
+
1
)
{
header2
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
()
+
"成長率"
)
{
});
}
if
(
SYear2
==
endYear
)
{
break
;
}
SYear2
=
Convert
.
ToDateTime
(
SYear2
+
"-01-01"
).
AddYears
(
1
).
Year
;
}
DataList
.
Add
(
header2
);
#
endregion
#
region
组装数据
List
<
string
>
DateRowList2
=
new
List
<
string
>()
{
"MAvgPeopleNum|平均付款人數"
,
"MAvgOrderNum|平均付款單數"
,
"MAvgPayMoney|平均付款金額"
,
"MAvgBuyNum|平均付款件數"
,
"PAvgOrderNum|平均每人購買單數"
,
"PAvgBuyNum|平均每人購買件數"
,
"PAvgUnitPrice|平均每單單價"
,
"PAvgBuyPrice|平均每人購買單價"
,
"PAvgMemberNum|平均會員數"
,
"PAvgPaymentNum|平均付款累計人數"
,
"PAvgMOrderRate|平均會員下訂單轉換率"
,
"PAvgReBuyNum|平均復夠人數"
,
"PAvgReBuyRate|平均復夠率"
,
"PAvgNewPeopleNum|平均新人下單"
,
"PAvgProfitRate|毛利率"
};
foreach
(
var
item
in
DateRowList2
)
{
var
fileNameArr
=
item
.
Split
(
'|'
);
ExcelDataSource
datarow2
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>(
23
)
{
new
ExcelColumn
(
value
:
fileNameArr
[
1
])
{
},
},
ColumnHight
=
30
};
foreach
(
var
qitem
in
YearAvgSList
)
{
JObject
parms
=
JObject
.
Parse
(
JsonHelper
.
Serialize
(
qitem
));
string
mvalue
=
parms
.
GetStringValue
(
fileNameArr
[
0
]);
datarow2
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
mvalue
+
(
qitem
.
Date
.
Contains
(
"成長率"
)
?
"%"
:
""
))
{
});
}
DataList
.
Add
(
datarow2
);
}
#
endregion
#
endregion
#
region
第三表
#
region
组装标题
ExcelDataSource
header3
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>()
{
new
ExcelColumn
(
value
:
"年度"
){
}
},
ColumnHight
=
30
};
SYear2
=
startYear
;
while
(
true
)
{
header3
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
())
{
});
if
(
SYear2
>=
startYear
+
1
)
{
header3
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
SYear2
.
ToString
()
+
"成長率"
)
{
});
}
if
(
SYear2
==
endYear
)
{
break
;
}
SYear2
=
Convert
.
ToDateTime
(
SYear2
+
"-01-01"
).
AddYears
(
1
).
Year
;
}
DataList
.
Add
(
header3
);
#
endregion
#
region
组装数据
List
<
string
>
DateRowList3
=
new
List
<
string
>()
{
"MAvgPeopleNum|平均付款人數成長率"
,
"MAvgOrderNum|平均付款單數成長率"
,
"MAvgPayMoney|平均付款金額成長率"
,
"MAvgBuyNum|平均付款件數成長率"
,
"PAvgOrderNum|平均每人購買單數成長率"
,
"PAvgBuyNum|平均每人購買件數成長率"
,
"PAvgUnitPrice|平均每單單價成長率"
,
"PAvgBuyPrice|平均每人購買單價成長率"
,
"PAvgProfit|毛利成長率"
,
"PAvgMOrderRate|會員下訂單成長率"
,
"PAvgPXNum|普象會員成長率"
,
"PAvgVipNum|VIP會員成長率"
,
"PAvgYXNum|銀象會員成長率"
,
"PAvgJXNum|金象會員成長率"
,
"PAvgTotalMNum|會員總成長率"
};
foreach
(
var
item
in
DateRowList3
)
{
var
fileNameArr
=
item
.
Split
(
'|'
);
ExcelDataSource
datarow2
=
new
ExcelDataSource
()
{
ExcelRows
=
new
List
<
ExcelColumn
>(
23
)
{
new
ExcelColumn
(
value
:
fileNameArr
[
1
])
{
},
},
ColumnHight
=
30
};
foreach
(
var
qitem
in
YearRateSList
)
{
JObject
parms
=
JObject
.
Parse
(
JsonHelper
.
Serialize
(
qitem
));
string
mvalue
=
parms
.
GetStringValue
(
fileNameArr
[
0
]);
datarow2
.
ExcelRows
.
Add
(
new
ExcelColumn
(
value
:
mvalue
+
(
qitem
.
Date
.
Contains
(
"成長率"
)
?
"%"
:
""
))
{
});
}
DataList
.
Add
(
datarow2
);
}
#
endregion
#
endregion
#
endregion
return
DataList
;
}
}
#
endregion
#
endregion
...
...
Mall.WebApi/Controllers/AppletWeChat/LiveHouseController.cs
View file @
db857b44
...
@@ -1633,6 +1633,47 @@ namespace Mall.WebApi.Controllers.AppletWeChat
...
@@ -1633,6 +1633,47 @@ namespace Mall.WebApi.Controllers.AppletWeChat
return
ApiResult
.
Success
(
""
,
Robj
);
return
ApiResult
.
Success
(
""
,
Robj
);
}
}
/// <summary>
/// 年度导出
/// </summary>
/// <param name="requestMsg"></param>
/// <returns></returns>
[
HttpPost
]
[
AllowAnonymous
]
public
FileContentResult
GetDSYearStartisticsToExcel
(
object
requestMsg
)
{
var
requestParm
=
JsonConvert
.
DeserializeObject
<
RequestParm
>(
requestMsg
.
ToString
());
JObject
parms
=
JObject
.
Parse
(
requestParm
.
msg
.
ToString
());
int
StartYear
=
parms
.
GetInt
(
"StartYear"
,
0
);
//开始时间 年
int
EndYear
=
parms
.
GetInt
(
"EndYear"
,
0
);
//结束时间 年
string
ExcelName
=
"电商年度统计"
+
DateTime
.
Now
.
ToString
(
"yyyyMMddHHmmss"
)
+
".xls"
;
List
<
ExcelDataSource
>
slist
=
new
List
<
ExcelDataSource
>();
if
(
StartYear
<=
0
||
EndYear
<=
0
)
{
var
byteData1
=
ExcelTempLateHelper
.
ToExcelExtend
(
slist
);
return
File
(
byteData1
,
"application/octet-stream"
,
ExcelName
);
}
if
(
StartYear
<
2019
||
StartYear
>
EndYear
)
{
var
byteData1
=
ExcelTempLateHelper
.
ToExcelExtend
(
slist
);
return
File
(
byteData1
,
"application/octet-stream"
,
ExcelName
);
}
try
{
List
<
ExcelDataSource
>
Rlist
=
statisticsModule
.
GetDSYearStartisticsToExcel
(
StartYear
,
EndYear
,
requestParm
.
TenantId
,
requestParm
.
MallBaseId
);
slist
.
AddRange
(
Rlist
);
var
byteData
=
ExcelTempLateHelper
.
ToExcelExtend
(
slist
);
return
File
(
byteData
,
"application/octet-stream"
,
ExcelName
);
}
catch
(
Exception
ex
)
{
LogHelper
.
Write
(
ex
,
string
.
Format
(
"GetFileFromWebApi_requestData: {0}"
,
JsonHelper
.
Serialize
(
requestMsg
.
ToString
())));
var
byteData1
=
ExcelTempLateHelper
.
ToExcelExtend
(
slist
);
return
File
(
byteData1
,
"application/octet-stream"
,
ExcelName
);
}
}
#
endregion
#
endregion
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment