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
3018043d
Commit
3018043d
authored
Jul 04, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
看板
parent
6b64b200
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
9 deletions
+66
-9
Index.php
app/api/controller/manage/Index.php
+2
-3
Payment.php
app/model/Payment.php
+64
-6
No files found.
app/api/controller/manage/Index.php
View file @
3018043d
...
...
@@ -11,7 +11,7 @@ use app\model\ProjectTag;
use
think\facade\Cache
;
use
think\facade\Db
;
use
think\Request
;
use
app\model\
p
roject
as
projectModel
;
use
app\model\
P
roject
as
projectModel
;
use
app\model\project\User
as
userModel
;
class
Index
extends
BaseController
...
...
@@ -233,14 +233,13 @@ class Index extends BaseController
if
(
empty
(
$userId
))
{
return
$this
->
returnMsg
(
'用户ID不能为空'
);
}
try
{
// 查询该高校下的所有作业
$works
=
Db
::
name
(
'course_work'
)
->
alias
(
'zy'
)
->
join
(
'course kc'
,
'zy.course_id=kc.id'
)
->
join
(
'course_category kcfl'
,
'kc.cate_id=kcfl.id'
)
->
where
(
'user_id'
,
$userId
)
->
where
(
'
zy.
user_id'
,
$userId
)
->
where
(
'zy.is_del'
,
0
)
->
field
(
'zy.id, zy.title, zy.course_id,kc.title as course_name,kc.cate_id,kcfl.title as course_category'
)
->
select
()
...
...
app/model/Payment.php
View file @
3018043d
...
...
@@ -83,12 +83,19 @@ class Payment extends Model
}
return
$title
;
}
public
function
getOrderStatistics
(
$range
=
'month'
,
$userId
=
0
)
/**
* 获取订单统计信息
* @param string $range 时间范围: month(近一个月), quarter(近三个月), halfyear(近半年), year(近一年), all(全部)
* @param int $userId 用户ID
* @return array
*/
public
function
getOrderStatistics
(
$range
=
'month'
,
$userId
=
0
)
{
// 基础查询条件:支付成功(1)且订单类型为课程(1)
$query
=
$this
->
where
(
'pay_status'
,
1
)
->
where
(
'order_type'
,
1
);
->
where
(
'order_type'
,
1
)
->
where
(
'store_user_id'
,
$userId
);
// 根据时间范围设置条件
switch
(
$range
)
{
...
...
@@ -110,7 +117,7 @@ class Payment extends Model
break
;
case
'all'
:
default
:
$startTime
=
null
;
$startTime
=
strtotime
(
'-5 year'
);
// 默认统计最近5年
$timeFormat
=
"%Y-%m"
;
// 按月
break
;
}
...
...
@@ -127,14 +134,65 @@ class Payment extends Model
])
->
group
(
"time_period"
)
->
order
(
"time_period ASC"
)
->
where
(
'userId'
,
$userId
)
->
select
()
->
toArray
();
if
(
$range
!=
'all'
)
{
// 自动补全缺失的时间段数据
$filledData
=
$this
->
fillMissingTimePeriods
(
$result
,
$timeFormat
,
$startTime
);
}
else
{
$filledData
=
$result
;
}
return
[
'data'
=>
$
result
,
'data'
=>
$
filledData
,
'format'
=>
$timeFormat
===
"%Y-%m-%d"
?
'day'
:
'month'
];
}
/**
* 补全缺失的时间段数据(私有方法确保不会重复)
*/
private
function
fillMissingTimePeriods
(
$data
,
$timeFormat
,
$startTime
)
{
if
(
empty
(
$data
))
{
return
[];
}
$filledData
=
[];
$current
=
$startTime
?:
strtotime
(
$data
[
0
][
'time_period'
]);
$end
=
strtotime
(
'today 23:59:59'
);
// 根据格式确定时间间隔
$isDaily
=
(
$timeFormat
===
"%Y-%m-%d"
);
$interval
=
$isDaily
?
'1 day'
:
'1 month'
;
$dateFormat
=
$isDaily
?
'Y-m-d'
:
'Y-m'
;
while
(
$current
<=
$end
)
{
$period
=
date
(
$dateFormat
,
$current
);
$found
=
false
;
foreach
(
$data
as
$item
)
{
if
(
$item
[
'time_period'
]
===
$period
)
{
$filledData
[]
=
$item
;
$found
=
true
;
break
;
}
}
if
(
!
$found
)
{
$filledData
[]
=
[
'time_period'
=>
$period
,
'order_count'
=>
0
,
'total_amount'
=>
0.00
];
}
$current
=
strtotime
(
"+
{
$interval
}
"
,
$current
);
}
return
$filledData
;
}
}
\ 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