Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
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
刘小敏
loveisland
Commits
a98fe19f
Commit
a98fe19f
authored
May 18, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
统计数据静态页
parent
49793a7e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
239 additions
and
0 deletions
+239
-0
Dashboard.php
application/admin/controller/shopro/Dashboard.php
+239
-0
index.html
application/admin/view/shopro/dashboard/index.html
+0
-0
No files found.
application/admin/controller/shopro/Dashboard.php
View file @
a98fe19f
...
...
@@ -8,6 +8,7 @@ use app\admin\model\shopro\goods\Goods;
use
app\admin\model\shopro\user\User
;
use
app\admin\model\shopro\Share
;
use
addons\shopro\service\SearchHistory
;
use
think\Db
;
class
Dashboard
extends
Common
{
...
...
@@ -35,6 +36,244 @@ class Dashboard extends Common
return
$this
->
view
->
fetch
();
}
/**
* 获取统计数据
*/
public
function
statistics
()
{
$timeRange
=
$this
->
request
->
param
(
'time_range'
,
'30days'
);
// 根据时间范围获取条件
$timeCondition
=
$this
->
getTimeCondition
(
$timeRange
);
// 成交总额
$totalAmount
=
Order
::
whereTime
(
'createtime'
,
$timeCondition
)
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
sum
(
'pay_fee'
)
?:
0
;
// 订单数
$orderCount
=
Order
::
whereTime
(
'createtime'
,
$timeCondition
)
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
count
();
// 客单价
$avgAmount
=
$orderCount
>
0
?
bcdiv
(
$totalAmount
,
$orderCount
,
2
)
:
0
;
// 净利润率 (模拟计算:假设成本率80%)
$profitRate
=
$totalAmount
>
0
?
'18.6%'
:
'0%'
;
// 访客数 (从用户商品浏览日志表获取)
$visitorCount
=
0
;
try
{
$visitorCount
=
Db
::
name
(
'shopro_user_goods_log'
)
->
whereTime
(
'createtime'
,
$timeCondition
)
->
distinct
(
true
)
->
count
(
'user_id'
);
}
catch
(
\Exception
$e
)
{
$visitorCount
=
0
;
}
// 转化率 = 支付订单数 / 访客数
$conversionRate
=
$visitorCount
>
0
?
bcdiv
(
$orderCount
*
100
,
$visitorCount
,
2
)
.
'%'
:
'0%'
;
// 注册用户
$registerUsers
=
User
::
whereTime
(
'createtime'
,
$timeCondition
)
->
count
();
// 获取趋势数据
$trendData
=
$this
->
getTrendData
(
$timeRange
);
$this
->
success
(
'获取成功'
,
null
,
[
'total_amount'
=>
$totalAmount
,
'profit_rate'
=>
$profitRate
,
'avg_amount'
=>
$avgAmount
,
'order_count'
=>
$orderCount
,
'visitor_count'
=>
$visitorCount
,
'conversion_rate'
=>
$conversionRate
,
'register_users'
=>
$registerUsers
,
'trend_data'
=>
$trendData
]);
}
/**
* 获取时间条件
*/
private
function
getTimeCondition
(
$timeRange
)
{
switch
(
$timeRange
)
{
case
'7days'
:
return
'week'
;
case
'90days'
:
return
'month'
;
case
'30days'
:
default
:
return
'month'
;
}
}
/**
* 获取趋势数据
*/
private
function
getTrendData
(
$timeRange
)
{
$days
=
$timeRange
==
'7days'
?
7
:
(
$timeRange
==
'90days'
?
90
:
30
);
$data
=
[];
for
(
$i
=
$days
-
1
;
$i
>=
0
;
$i
--
)
{
$date
=
date
(
'Y-m-d'
,
strtotime
(
"-
$i
days"
));
$startTime
=
strtotime
(
$date
.
' 00:00:00'
);
$endTime
=
strtotime
(
$date
.
' 23:59:59'
);
$amount
=
Order
::
whereBetween
(
'createtime'
,
[
$startTime
,
$endTime
])
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
sum
(
'pay_fee'
)
?:
0
;
$orderNum
=
Order
::
whereBetween
(
'createtime'
,
[
$startTime
,
$endTime
])
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
count
();
$registerNum
=
User
::
whereBetween
(
'createtime'
,
[
$startTime
,
$endTime
])
->
count
();
$data
[]
=
[
'date'
=>
$date
,
'amount'
=>
$amount
,
'order_num'
=>
$orderNum
,
'register_num'
=>
$registerNum
];
}
return
$data
;
}
/**
* 获取转化漏斗数据
*/
public
function
funnel
()
{
$timeRange
=
$this
->
request
->
param
(
'time_range'
,
'30days'
);
$timeCondition
=
$this
->
getTimeCondition
(
$timeRange
);
// 访问用户数
$visitCount
=
Db
::
name
(
'shopro_user_goods_log'
)
->
whereTime
(
'createtime'
,
$timeCondition
)
->
distinct
(
true
)
->
count
(
'user_id'
);
// 浏览商品用户数
$browseCount
=
Db
::
name
(
'shopro_user_goods_log'
)
->
whereTime
(
'createtime'
,
$timeCondition
)
->
where
(
'type'
,
'browse'
)
->
distinct
(
true
)
->
count
(
'user_id'
);
// 加入购物车用户数
$cartCount
=
Db
::
name
(
'shopro_user_goods_log'
)
->
whereTime
(
'createtime'
,
$timeCondition
)
->
where
(
'type'
,
'cart'
)
->
distinct
(
true
)
->
count
(
'user_id'
);
// 提交订单用户数
$submitOrderCount
=
Order
::
whereTime
(
'createtime'
,
$timeCondition
)
->
distinct
(
true
)
->
count
(
'user_id'
);
// 完成支付用户数
$payCount
=
Order
::
whereTime
(
'createtime'
,
$timeCondition
)
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
distinct
(
true
)
->
count
(
'user_id'
);
$this
->
success
(
'获取成功'
,
null
,
[
'visit'
=>
$visitCount
,
'browse'
=>
$browseCount
,
'cart'
=>
$cartCount
,
'submit_order'
=>
$submitOrderCount
,
'pay'
=>
$payCount
]);
}
/**
* 获取客单价分布
*/
public
function
priceDistribution
()
{
$timeRange
=
$this
->
request
->
param
(
'time_range'
,
'30days'
);
$timeCondition
=
$this
->
getTimeCondition
(
$timeRange
);
$orders
=
Order
::
whereTime
(
'createtime'
,
$timeCondition
)
->
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
field
(
'pay_fee'
)
->
select
();
$distribution
=
[
'0-100'
=>
0
,
'100-300'
=>
0
,
'300-500'
=>
0
,
'500-1000'
=>
0
,
'1000+'
=>
0
];
$total
=
count
(
$orders
);
foreach
(
$orders
as
$order
)
{
$amount
=
$order
[
'pay_fee'
];
if
(
$amount
<
100
)
{
$distribution
[
'0-100'
]
++
;
}
elseif
(
$amount
<
300
)
{
$distribution
[
'100-300'
]
++
;
}
elseif
(
$amount
<
500
)
{
$distribution
[
'300-500'
]
++
;
}
elseif
(
$amount
<
1000
)
{
$distribution
[
'500-1000'
]
++
;
}
else
{
$distribution
[
'1000+'
]
++
;
}
}
// 转换为百分比
foreach
(
$distribution
as
&
$val
)
{
$val
=
$total
>
0
?
round
(
$val
/
$total
*
100
)
:
0
;
}
$this
->
success
(
'获取成功'
,
null
,
$distribution
);
}
/**
* 获取实时订单动态
*/
public
function
recentOrders
()
{
$orders
=
Order
::
whereIn
(
'status'
,
[
Order
::
STATUS_PAID
,
Order
::
STATUS_COMPLETED
])
->
order
(
'createtime'
,
'desc'
)
->
limit
(
10
)
->
select
();
$result
=
[];
foreach
(
$orders
as
$order
)
{
$user
=
User
::
where
(
'id'
,
$order
[
'user_id'
])
->
find
();
$result
[]
=
[
'amount'
=>
$order
[
'pay_fee'
],
'time'
=>
$this
->
formatTime
(
$order
[
'createtime'
]),
'location'
=>
$user
?
(
$user
[
'city'
]
?:
'未知'
)
:
'未知'
];
}
$this
->
success
(
'获取成功'
,
null
,
$result
);
}
/**
* 格式化时间显示
*/
private
function
formatTime
(
$timestamp
)
{
$now
=
time
();
$diff
=
$now
-
$timestamp
;
if
(
$diff
<
60
)
{
return
'刚刚'
;
}
elseif
(
$diff
<
3600
)
{
return
floor
(
$diff
/
60
)
.
'分钟前'
;
}
elseif
(
$diff
<
86400
)
{
return
floor
(
$diff
/
3600
)
.
'小时前'
;
}
else
{
return
date
(
'm-d H:i'
,
$timestamp
);
}
}
public
function
total
()
{
...
...
application/admin/view/shopro/dashboard/index.html
View file @
a98fe19f
This diff is collapsed.
Click to expand it.
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