Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projecttwo
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
wangtao
projecttwo
Commits
6b64b200
Commit
6b64b200
authored
Jul 04, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
看板
parent
cc006d51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
Index.php
app/api/controller/manage/Index.php
+27
-6
Payment.php
app/model/Payment.php
+1
-1
No files found.
app/api/controller/manage/Index.php
View file @
6b64b200
...
...
@@ -8,6 +8,7 @@ use app\BaseController;
use
app\model\Course
as
courseModel
;
use
app\model\Payment
;
use
app\model\ProjectTag
;
use
think\facade\Cache
;
use
think\facade\Db
;
use
think\Request
;
use
app\model\project
as
projectModel
;
...
...
@@ -150,25 +151,45 @@ class Index extends BaseController
{
$range
=
$request
->
param
(
'range'
,
'month'
);
$validRanges
=
[
'month'
,
'quarter'
,
'halfyear'
,
'all'
,
'year'
];
$validRanges
=
[
'month'
,
'quarter'
,
'halfyear'
,
'all'
,
'year'
];
$userId
=
$request
->
userId
;
if
(
!
in_array
(
$range
,
$validRanges
))
{
return
$this
->
returnMsg
(
'无效时间范围'
);
}
$userId
=
$request
->
userId
;
// 构建缓存键,包含用户ID和时间范围
$cacheKey
=
'payment_stats:'
.
$userId
.
':'
.
$range
;
// 尝试从缓存获取数据
if
(
Cache
::
has
(
$cacheKey
))
{
$cachedData
=
Cache
::
get
(
$cacheKey
);
return
$this
->
returnMsg
(
'success'
,
1
,
$cachedData
);
}
// 缓存不存在,从数据库获取
$payment
=
new
Payment
();
$result
=
$payment
->
getOrderStatistics
(
$range
,
$userId
);
$result
=
$payment
->
getOrderStatistics
(
$range
,
$userId
);
// 格式化数据
$formattedData
=
$this
->
formatStatisticsData
(
$result
[
'data'
],
$result
[
'format'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
[
$returnData
=
[
'data'
=>
$formattedData
,
'time_format'
=>
$result
[
'format'
]
]);
];
// 设置缓存,不同范围设置不同过期时间
$expireTimes
=
[
'month'
=>
3600
,
// 1小时
'quarter'
=>
3600
,
// 3小时
'halfyear'
=>
3600
,
// 6小时
'year'
=>
3600
,
// 12小时
'all'
=>
3600
// 24小时
];
Cache
::
set
(
$cacheKey
,
$returnData
,
$expireTimes
[
$range
]);
return
$this
->
returnMsg
(
'success'
,
1
,
$returnData
);
}
...
...
app/model/Payment.php
View file @
6b64b200
...
...
@@ -127,7 +127,7 @@ class Payment extends Model
])
->
group
(
"time_period"
)
->
order
(
"time_period ASC"
)
//
->where('userId',$userId)
->
where
(
'userId'
,
$userId
)
->
select
()
->
toArray
();
...
...
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