Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
workbiu-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gxx
workbiu-admin
Commits
fd1aeda1
Commit
fd1aeda1
authored
Nov 13, 2017
by
gxx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
回访用户、用户留存 完成
parent
9f7989c8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
8 deletions
+77
-8
StatisticsServiceContract.php
app/Contracts/StatisticsServiceContract.php
+4
-0
StatisticsController.php
app/Http/Controllers/StatisticsController.php
+16
-1
StatisticsService.php
app/Services/StatisticsService.php
+55
-7
web.php
routes/web.php
+2
-0
No files found.
app/Contracts/StatisticsServiceContract.php
View file @
fd1aeda1
...
@@ -12,8 +12,12 @@ namespace App\Contracts;
...
@@ -12,8 +12,12 @@ namespace App\Contracts;
interface
StatisticsServiceContract
interface
StatisticsServiceContract
{
{
public
function
UserTotal
();
public
function
UserIncrease
();
public
function
UserIncrease
();
public
function
ActiveUser
();
public
function
ActiveUser
();
public
function
OutflowUser
();
public
function
OutflowUser
();
public
function
ReturnVisit
();
public
function
UserRetention
();
}
}
\ No newline at end of file
app/Http/Controllers/StatisticsController.php
View file @
fd1aeda1
...
@@ -57,11 +57,26 @@ class StatisticsController extends Controller
...
@@ -57,11 +57,26 @@ class StatisticsController extends Controller
}
}
// 流失用户
public
function
OutflowUser
()
public
function
OutflowUser
()
{
{
$outflowUsers
=
$this
->
mStatistics
->
OutflowUser
();
$outflowUsers
=
$this
->
mStatistics
->
OutflowUser
();
return
$outflowUsers
;
return
$outflowUsers
;
}
}
// 回访用户
public
function
ReturnVisit
()
{
$returnVisitUsersCount
=
$this
->
mStatistics
->
ReturnVisit
();
return
$returnVisitUsersCount
;
}
public
function
UserRetention
()
{
$data
=
$this
->
mStatistics
->
UserRetention
();
return
$data
;
}
}
}
app/Services/StatisticsService.php
View file @
fd1aeda1
...
@@ -18,6 +18,15 @@ use Carbon\Carbon;
...
@@ -18,6 +18,15 @@ use Carbon\Carbon;
class
StatisticsService
implements
StatisticsServiceContract
class
StatisticsService
implements
StatisticsServiceContract
{
{
public
function
UserTotal
()
{
$users
=
User
::
all
();
$date
=
[
'全部用户'
=>
count
(
$users
)];
return
$date
;
}
public
function
UserIncrease
()
public
function
UserIncrease
()
{
{
$startTime
=
strtotime
(
date
(
'Ymd'
))
-
86400
;
$startTime
=
strtotime
(
date
(
'Ymd'
))
-
86400
;
...
@@ -46,11 +55,12 @@ class StatisticsService implements StatisticsServiceContract
...
@@ -46,11 +55,12 @@ class StatisticsService implements StatisticsServiceContract
$month
=
count
(
$monthUsers
);
$month
=
count
(
$monthUsers
);
}
}
$day
=
round
(
$day
/
$users
*
100
,
2
)
;
$day
=
ceil
(
round
(
$day
/
$users
*
100
,
2
))
;
$week
=
round
(
$week
/
$users
*
100
,
2
)
;
$week
=
ceil
(
round
(
$week
/
$users
*
100
,
2
))
;
$month
=
round
(
$month
/
$users
*
100
,
2
)
;
$month
=
ceil
(
round
(
$month
/
$users
*
100
,
2
))
;
$date
=
array
(
$day
.
'%'
,
$week
.
'%'
,
$month
.
'%'
,
$users
);
$date
=
array
(
$day
.
'%'
,
$week
.
'%'
,
$month
.
'%'
);
// $date = array(['昨日新增用户占比'=>$day.'%','上一周新增用户占比'=>$week.'%','上一个月新增用户占比'=>$month.'%']);
return
$date
;
return
$date
;
}
}
...
@@ -142,7 +152,7 @@ class StatisticsService implements StatisticsServiceContract
...
@@ -142,7 +152,7 @@ class StatisticsService implements StatisticsServiceContract
}
}
}
}
$date
=
array
(
$yesterdayActiveUser
,
$LastMonthActiveUser
,
$LastWeekActiveUser
)
;
$date
=
[
'昨日活跃用户'
=>
$yesterdayActiveUser
,
'上一个月活跃用户'
=>
$LastMonthActiveUser
,
'上一周活跃用户'
=>
$LastWeekActiveUser
]
;
return
$date
;
return
$date
;
}
}
...
@@ -156,14 +166,52 @@ class StatisticsService implements StatisticsServiceContract
...
@@ -156,14 +166,52 @@ class StatisticsService implements StatisticsServiceContract
if
(
!
$userLogin
->
isEmpty
()){
if
(
!
$userLogin
->
isEmpty
()){
foreach
(
$userLogin
as
$user
){
foreach
(
$userLogin
as
$user
){
$timeDifference
=
strtotime
(
date
(
'Ymd'
))
-
strtotime
(
$user
[
'last_login_time'
]);
$timeDifference
=
strtotime
(
date
(
'Ymd'
))
-
strtotime
(
$user
[
'last_login_time'
]);
$days
=
floor
(
$timeDifference
/
84600
)
;
$days
=
ceil
(
floor
(
$timeDifference
/
84600
))
;
if
(
$days
>
7
){
if
(
$days
>
7
){
$outflowUsers
+=
1
;
$outflowUsers
+=
1
;
}
}
}
}
};
};
$date
=
[
'流失用户'
=>
$outflowUsers
];
return
$date
;
}
// 回访用户
public
function
ReturnVisit
()
{
$returnVisitUsers
=
UserInfo
::
where
(
'return_visit'
,
'1'
)
->
get
();
$returnVisitUsersCount
=
0
;
if
(
!
$returnVisitUsers
->
isEmpty
()){
$returnVisitUsersCount
=
count
(
$returnVisitUsers
);
}
$date
=
[
'回访用户'
=>
$returnVisitUsersCount
];
return
$date
;
}
// 用户存留
public
function
UserRetention
()
{
$activeUsers
=
$this
->
ActiveUser
();
$outflowUsers
=
$this
->
OutflowUser
();
$userTotals
=
$this
->
UserTotal
();
$outflow
=
ceil
(
round
(
$outflowUsers
[
'流失用户'
]
/
$userTotals
[
'全部用户'
]
*
100
,
2
))
;
$dayActive
=
ceil
(
round
(
$activeUsers
[
'昨日活跃用户'
]
/
$userTotals
[
'全部用户'
]
*
100
,
2
))
;
$monthActive
=
ceil
(
round
(
$activeUsers
[
'上一个月活跃用户'
]
/
$userTotals
[
'全部用户'
]
*
100
,
2
))
;
$weekActive
=
ceil
(
round
(
$activeUsers
[
'上一周活跃用户'
]
/
$userTotals
[
'全部用户'
]
*
100
,
2
))
;
$data
=
[
'昨日活跃占比'
=>
$dayActive
.
'%'
,
'上一个月活跃占比'
=>
$monthActive
.
'%'
,
'上一周活跃占比'
=>
$weekActive
.
'%'
,
'流失用户占比'
=>
$outflow
.
'%'
];
return
$data
;
}
public
function
AverageUserOperation
()
{
return
$outflowUsers
;
}
}
...
...
routes/web.php
View file @
fd1aeda1
...
@@ -84,6 +84,8 @@ Route::group(['prefix'=> 'statistics'],function (){
...
@@ -84,6 +84,8 @@ Route::group(['prefix'=> 'statistics'],function (){
Route
::
get
(
'user_increase'
,
'StatisticsController@UserIncrease'
)
->
name
(
'statistics.UserIncrease'
);
Route
::
get
(
'user_increase'
,
'StatisticsController@UserIncrease'
)
->
name
(
'statistics.UserIncrease'
);
Route
::
get
(
'active_user'
,
'StatisticsController@ActiveUser'
)
->
name
(
'statistics.ActiveUser'
);
Route
::
get
(
'active_user'
,
'StatisticsController@ActiveUser'
)
->
name
(
'statistics.ActiveUser'
);
Route
::
get
(
'outflow_user'
,
'StatisticsController@OutflowUser'
)
->
name
(
'statistics.OutflowUser'
);
Route
::
get
(
'outflow_user'
,
'StatisticsController@OutflowUser'
)
->
name
(
'statistics.OutflowUser'
);
Route
::
get
(
'return_visit'
,
'StatisticsController@ReturnVisit'
)
->
name
(
'statistics.ReturnVisit'
);
Route
::
get
(
'user_retention'
,
'StatisticsController@UserRetention'
)
->
name
(
'statistics.UserRetention'
);
});
});
...
...
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