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
150d90b1
Commit
150d90b1
authored
Jul 04, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
看板
parent
36dc0447
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
219 additions
and
1 deletion
+219
-1
Index.php
app/api/controller/manage/Index.php
+164
-0
Course.php
app/model/Course.php
+2
-1
Payment.php
app/model/Payment.php
+53
-0
No files found.
app/api/controller/manage/Index.php
View file @
150d90b1
...
...
@@ -5,9 +5,13 @@ namespace app\api\controller\manage;
use
app\api\middleware\Auth
;
use
app\api\service\UtilService
;
use
app\BaseController
;
use
app\model\Course
as
courseModel
;
use
app\model\Payment
;
use
app\model\ProjectTag
;
use
think\facade\Db
;
use
think\Request
;
use
app\model\project
as
projectModel
;
use
app\model\project\User
as
userModel
;
class
Index
extends
BaseController
{
...
...
@@ -117,4 +121,164 @@ class Index extends BaseController
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
public
function
card
(
Request
$request
)
{
$userId
=
$request
->
userId
;
$courseCount
=
courseModel
::
where
([
'user_id'
=>
$userId
,
'is_del'
=>
0
,
'status'
=>
3
])
->
count
();
$projectCount
=
projectModel
::
where
([
'user_id'
=>
$userId
,
'sh_status'
=>
2
])
->
count
();
$orderMoneySum
=
Payment
::
where
([
'store_user_id'
=>
$userId
,
'order_type'
=>
1
,
'pay_status'
=>
1
])
->
sum
(
'order_price'
);
$projectCreditoney
=
userModel
::
where
(
'id'
,
$userId
)
->
value
(
'credit_money'
);
return
$this
->
returnMsg
(
'success'
,
1
,
[
'courseCount'
=>
$courseCount
,
'projectCount'
=>
$projectCount
,
'orderMoneySum'
=>
$orderMoneySum
,
'projectCreditoney'
=>
$projectCreditoney
]
);
}
//图表统计
public
function
getStatistics
(
Request
$request
)
{
$range
=
$request
->
param
(
'range'
,
'month'
);
$validRanges
=
[
'month'
,
'quarter'
,
'halfyear'
,
'all'
,
'year'
];
if
(
!
in_array
(
$range
,
$validRanges
))
{
return
$this
->
returnMsg
(
'无效时间范围'
);
}
$userId
=
$request
->
userId
;
$payment
=
new
Payment
();
$result
=
$payment
->
getOrderStatistics
(
$range
,
$userId
);
// 格式化数据
$formattedData
=
$this
->
formatStatisticsData
(
$result
[
'data'
],
$result
[
'format'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
[
'data'
=>
$formattedData
,
'time_format'
=>
$result
[
'format'
]
]);
}
/**
* 格式化统计结果
*/
protected
function
formatStatisticsData
(
$data
,
$format
)
{
$result
=
[
'time_periods'
=>
[],
'order_counts'
=>
[],
'total_amounts'
=>
[]
];
foreach
(
$data
as
$item
)
{
$result
[
'time_periods'
][]
=
$item
[
'time_period'
];
$result
[
'order_counts'
][]
=
$item
[
'order_count'
];
$result
[
'total_amounts'
][]
=
(
float
)
$item
[
'total_amount'
];
}
// 如果是按月统计,添加月份显示格式
if
(
$format
===
'month'
)
{
$result
[
'display_periods'
]
=
array_map
(
function
(
$period
)
{
return
date
(
'Y年m月'
,
strtotime
(
$period
.
'-01'
));
},
$result
[
'time_periods'
]);
}
else
{
$result
[
'display_periods'
]
=
array_map
(
function
(
$period
)
{
return
date
(
'm月d日'
,
strtotime
(
$period
));
},
$result
[
'time_periods'
]);
}
return
$result
;
}
public
function
pendingWorkList
(
Request
$request
)
{
// 获取高校/企业用户ID
$userId
=
$request
->
userId
;
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.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
()
->
toArray
();
if
(
empty
(
$works
))
{
return
$this
->
returnMsg
(
'success'
,
1
,[]);
}
$workIds
=
array_column
(
$works
,
'id'
);
// 查询每个作业的提交情况
$submissions
=
Db
::
name
(
'course_user_work'
)
->
where
(
'work_id'
,
'in'
,
$workIds
)
->
where
(
'is_del'
,
0
)
->
field
(
'work_id, status, COUNT(*) as count'
)
->
group
(
'work_id, status'
)
->
select
()
->
toArray
();
// 组织统计数据
$stats
=
[];
foreach
(
$submissions
as
$sub
)
{
$workId
=
$sub
[
'work_id'
];
if
(
!
isset
(
$stats
[
$workId
]))
{
$stats
[
$workId
]
=
[
'submitted'
=>
0
,
// 已提交人数
'pending'
=>
0
// 待批改人数(已提交但未批改)
];
}
if
(
$sub
[
'status'
]
==
1
)
{
// 已提交
$stats
[
$workId
][
'submitted'
]
+=
$sub
[
'count'
];
$stats
[
$workId
][
'pending'
]
+=
$sub
[
'count'
];
}
elseif
(
$sub
[
'status'
]
>=
2
)
{
// 已批改(通过或未通过)
$stats
[
$workId
][
'submitted'
]
+=
$sub
[
'count'
];
}
}
// 构建返回数据
$result
=
[];
foreach
(
$works
as
$work
)
{
$workId
=
$work
[
'id'
];
$result
[]
=
[
'work_id'
=>
$workId
,
'title'
=>
$work
[
'title'
],
'course_id'
=>
$work
[
'course_id'
],
'submitted_count'
=>
$stats
[
$workId
][
'submitted'
]
??
0
,
'pending_count'
=>
$stats
[
$workId
][
'pending'
]
??
0
,
'course_name'
=>
$work
[
'course_name'
],
'course_category'
=>
$work
[
'course_category'
]
];
}
return
$this
->
returnMsg
(
'success'
,
1
,
$result
);
}
catch
(
\Exception
$e
)
{
return
$this
->
returnMsg
(
$e
->
getMessage
());
}
}
}
\ No newline at end of file
app/model/Course.php
View file @
150d90b1
...
...
@@ -69,6 +69,7 @@ class Course extends Model
if
(
!
empty
(
$category_id
))
{
$query
->
where
(
'cate_id'
,
$category_id
);
}
$query
->
order
(
'createtime'
,
'desc'
);
$list
=
$query
->
order
(
'click,tvclick,createtime'
,
'desc'
)
->
field
(
'id,thumb,title,description,tag_ids,teacher_id,description,content'
)
...
...
@@ -131,7 +132,7 @@ class Course extends Model
}
// 如果一级分类为0,则不限制分类(查询全部)
$query
->
order
(
'createtime'
,
'desc'
);
if
(
$searchKeyWords
)
{
$query
->
where
(
'title'
,
'like'
,
'%'
.
$searchKeyWords
.
'%'
);
}
...
...
app/model/Payment.php
View file @
150d90b1
...
...
@@ -84,4 +84,57 @@ class Payment extends Model
return
$title
;
}
public
function
getOrderStatistics
(
$range
=
'month'
,
$userId
=
0
)
{
// 基础查询条件:支付成功(1)且订单类型为课程(1)
$query
=
$this
->
where
(
'pay_status'
,
1
)
->
where
(
'order_type'
,
1
);
// 根据时间范围设置条件
switch
(
$range
)
{
case
'month'
:
$startTime
=
strtotime
(
'-1 month'
);
$timeFormat
=
"%Y-%m-%d"
;
// 按天
break
;
case
'quarter'
:
$startTime
=
strtotime
(
'-3 month'
);
$timeFormat
=
"%Y-%m"
;
// 按月
break
;
case
'halfyear'
:
$startTime
=
strtotime
(
'-6 month'
);
$timeFormat
=
"%Y-%m"
;
// 按月
break
;
case
'year'
:
$startTime
=
strtotime
(
'-12 month'
);
$timeFormat
=
"%Y-%m"
;
// 按月
break
;
case
'all'
:
default
:
$startTime
=
null
;
$timeFormat
=
"%Y-%m"
;
// 按月
break
;
}
if
(
$startTime
)
{
$query
->
where
(
'pay_time'
,
'>='
,
$startTime
);
}
// 按时间分组统计
$result
=
$query
->
field
([
"FROM_UNIXTIME(pay_time, '
{
$timeFormat
}
') as time_period"
,
"COUNT(*) as order_count"
,
"SUM(pay_amount) as total_amount"
])
->
group
(
"time_period"
)
->
order
(
"time_period ASC"
)
// ->where('userId',$userId)
->
select
()
->
toArray
();
return
[
'data'
=>
$result
,
'format'
=>
$timeFormat
===
"%Y-%m-%d"
?
'day'
:
'month'
];
}
}
\ 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