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
b2ab6b8c
Commit
b2ab6b8c
authored
May 13, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
课程
parent
9df090fa
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
341 additions
and
15 deletions
+341
-15
Course.php
app/api/controller/Course.php
+2
-2
CourseProgress.php
app/api/controller/CourseProgress.php
+41
-2
User.php
app/api/controller/User.php
+5
-0
Work.php
app/api/controller/mine/Work.php
+69
-0
Auth.php
app/api/middleware/Auth.php
+9
-3
CourseProgressService.php
app/api/service/CourseProgressService.php
+52
-4
CourseValidate.php
app/api/validate/CourseValidate.php
+6
-2
Course.php
app/model/Course.php
+25
-1
CourseProgress.php
app/model/CourseProgress.php
+1
-1
CourseUserWork.php
app/model/CourseUserWork.php
+110
-0
CourseWork.php
app/model/CourseWork.php
+21
-0
No files found.
app/api/controller/Course.php
View file @
b2ab6b8c
...
...
@@ -86,7 +86,7 @@ class Course extends BaseController
}
/**获取课
时
详情
/**获取课
程
详情
* @param Request $request
* @return \app\html|\think\response\Json|true
*/
...
...
@@ -120,7 +120,7 @@ class Course extends BaseController
$data
=
$request
->
param
();
$data
=
(
new
CourseModel
())
->
with
([
'get
Teacher'
,
'get
Sections'
=>
[
'getCourseClass'
],
'getCourseClass'
])
->
with
([
'getSections'
=>
[
'getCourseClass'
],
'getCourseClass'
])
->
where
(
'id'
,
$data
[
'course_id'
])
->
field
(
'id,thumb,title,createtime,description,price,content,teacher_id,tvclick,click'
)
->
find
();
...
...
app/api/controller/CourseProgress.php
View file @
b2ab6b8c
...
...
@@ -4,6 +4,7 @@ namespace app\api\controller;
use
app\api\middleware\Auth
;
use
app\api\service\UserService
;
use
app\api\validate\CourseValidate
;
use
app\BaseController
;
use
think\facade\Request
;
use
app\api\service\CourseProgressService
;
...
...
@@ -22,6 +23,11 @@ class CourseProgress extends BaseController
*/
public
function
reportProgress
()
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'course_id'
,
'current_time'
,
'class_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
Request
::
only
([
'course_id'
,
'class_id'
,
'current_time'
]);
$token
=
Request
::
header
(
'token'
);
...
...
@@ -47,12 +53,20 @@ class CourseProgress extends BaseController
*/
public
function
getProgress
()
{
// $vo = (new CourseValidate())->goCheck(['course_id']);
// if ($vo !== true) {
// return $vo;
// }
$token
=
Request
::
header
(
'token'
);
$userId
=
UserService
::
getUserInfo
(
$token
)[
'id'
];
$data
=
Request
::
only
([
'course_id'
,
'page'
,
'pageSize'
]);
// $data = Request::only(['course_id','page','pageSize']);
$page
=
Request
::
param
(
'page'
,
1
);
$pageSize
=
Request
::
param
(
'pageSize'
,
10
);
$progress
=
CourseProgressService
::
getUserAllCoursesProgress
(
$userId
,
$
data
[
'page'
],
$data
[
'pageSize'
]
);
$progress
=
CourseProgressService
::
getUserAllCoursesProgress
(
$userId
,
$
page
,
$pageSize
);
return
$this
->
returnMsg
(
'操作成功'
,
1
,
$progress
);
...
...
@@ -63,6 +77,11 @@ class CourseProgress extends BaseController
*/
public
function
getLastLearn
()
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'course_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$token
=
Request
::
header
(
'token'
);
$userId
=
UserService
::
getUserInfo
(
$token
)[
'id'
];
...
...
@@ -72,4 +91,24 @@ class CourseProgress extends BaseController
return
$this
->
returnMsg
(
'操作成功'
,
1
,
$lastLearn
);
}
/**添加用户作业
*
*/
public
function
addUserWork
()
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'course_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$token
=
Request
::
header
(
'token'
);
$userId
=
UserService
::
getUserInfo
(
$token
)[
'id'
];
$data
=
Request
::
only
([
'course_id'
]);
$userWork
=
CourseProgressService
::
addUserWork
(
$userId
,
$data
[
'course_id'
]);
return
$this
->
returnMsg
(
'操作成功'
,
1
,
$userWork
);
}
}
\ No newline at end of file
app/api/controller/User.php
View file @
b2ab6b8c
...
...
@@ -32,6 +32,11 @@ class User extends BaseController
{
return
$this
->
returnMsg
(
'密码不正确'
,
0
);
}
if
(
$user
[
'status'
]
!=
1
)
{
return
$this
->
returnMsg
(
'账号禁止登录'
,
0
);
}
$token
=
TokenService
::
generateToken
(
$user
[
'id'
],
$user
->
toArray
());
$update
[
'token'
]
=
$token
;
...
...
app/api/controller/mine/Work.php
0 → 100644
View file @
b2ab6b8c
<?php
namespace
app\api\controller\mine
;
use
app\api\middleware\Auth
;
use
app\api\service\UserService
;
use
app\api\validate\CourseValidate
;
use
app\BaseController
;
use
app\model\CourseUserWork
;
use
app\Request
;
class
Work
extends
BaseController
{
protected
$middleware
=
[
Auth
::
class
,
];
/**我的作业列表
* @param Request $request
* @return \app\html
*/
public
function
workList
(
Request
$request
)
{
$page
=
$request
->
param
(
'page'
,
1
);
$pageSize
=
$request
->
param
(
'pageSize'
,
10
);
$workList
=
CourseUserWork
::
workList
(
$request
->
userId
,
$page
,
$pageSize
);
return
$this
->
returnMsg
(
'success'
,
1
,
$workList
);
}
/**我的作业详情
* @param Request $request
* @return \app\html
*/
public
function
workDetail
(
Request
$request
)
{
$workId
=
$request
->
param
(
'workId'
);
$detail
=
CourseUserWork
::
workDetail
(
$workId
);
return
$this
->
returnMsg
(
'success'
,
1
,
$detail
);
}
/**上传作业
* @param Request $request
* @return \app\html
*/
public
function
uploadWork
(
Request
$request
)
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'attachment_ids'
,
'work_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$uploadWork
=
CourseUserWork
::
uploadWork
(
$data
[
'work_id'
],
$data
[
'attachment_ids'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
$uploadWork
);
}
}
\ No newline at end of file
app/api/middleware/Auth.php
View file @
b2ab6b8c
...
...
@@ -13,20 +13,20 @@ class Auth extends BaseController
// 在这里编写你的验证逻辑
$token
=
$request
->
header
(
'token'
);
if
(
!
$this
->
checkToken
(
$token
))
{
if
(
!
$this
->
checkToken
(
$
request
,
$
token
))
{
return
$this
->
returnMsg
(
'Unauthorized'
,
201
);
}
$request
->
token
=
$token
;
return
$next
(
$request
);
}
protected
function
checkToken
(
$token
)
protected
function
checkToken
(
$
request
,
$
token
)
{
if
(
!
$token
)
{
return
false
;
}
$user
=
TokenService
::
verifyToken
(
$token
);
...
...
@@ -34,6 +34,12 @@ class Auth extends BaseController
{
return
false
;
}
if
(
$user
[
'status'
]
!=
1
)
{
return
false
;
}
$request
->
userId
=
$user
[
'user_id'
];
return
true
;
}
...
...
app/api/service/CourseProgressService.php
View file @
b2ab6b8c
...
...
@@ -4,6 +4,9 @@ namespace app\api\service;
use
app\model\Course
;
use
app\model\CourseClass
;
use
app\model\CourseProgress
;
use
app\model\CourseUserWork
;
use
app\model\CourseWork
;
class
CourseProgressService
{
/**
...
...
@@ -60,6 +63,7 @@ class CourseProgressService
$progress
->
save
(
$updateData
);
}
return
[
'progress'
=>
$progress
->
look_tvtime
,
'duration'
=>
$progress
->
tvtime
,
...
...
@@ -67,9 +71,51 @@ class CourseProgressService
];
}
/**添加作业
* @param $userId
* @param $courseId
* @return true
*/
public
static
function
addUserWork
(
$userId
,
$courseId
)
{
$workIds
=
CourseWork
::
where
([
'user_id'
=>
$userId
,
'course_id'
=>
$courseId
,
])
->
column
(
'id'
);
if
(
empty
(
$workIds
))
{
return
true
;
}
$existingWorks
=
CourseUserWork
::
where
([
'user_id'
=>
$userId
,
'course_id'
=>
$courseId
,
])
->
whereIn
(
'work_id'
,
$workIds
)
->
column
(
'work_id'
);
$newWorkIds
=
array_diff
(
$workIds
,
$existingWorks
);
if
(
!
empty
(
$newWorkIds
))
{
$insertData
=
array_map
(
function
(
$workId
)
use
(
$userId
,
$courseId
)
{
return
[
'user_id'
=>
$userId
,
'course_id'
=>
$courseId
,
'work_id'
=>
$workId
,
'createtime'
=>
time
()
];
},
$newWorkIds
);
CourseUserWork
::
insertAll
(
$insertData
);
}
return
true
;
}
/** 获取当前用户所有课程进度统计
* @param $userId
*
@return void
*
*/
public
static
function
getUserAllCoursesProgress
(
$userId
,
$page
=
1
,
$pageSize
=
10
)
{
...
...
@@ -88,8 +134,11 @@ class CourseProgressService
];
}
// 分页查询课程基本信息
$query
=
Course
::
where
(
'id'
,
'in'
,
$courseIds
)
->
with
([
'thumb'
])
->
field
(
'id,title,description,thumb'
);
$paginator
=
$query
->
paginate
([
...
...
@@ -127,7 +176,6 @@ class CourseProgressService
->
where
(
'user_id'
,
$userId
)
->
where
(
'course_id'
,
$courseId
)
->
select
();
// 统计计算
$finishedCount
=
0
;
$totalDuration
=
0
;
...
...
@@ -145,7 +193,8 @@ class CourseProgressService
'progress'
=>
$item
->
look_tvtime
,
'duration'
=>
$item
->
tvtime
,
'is_finished'
=>
$item
->
is_wc_look
,
'last_learn'
=>
$item
->
createtime
'last_learn'
=>
$item
->
createtime
,
'class_id'
=>
$item
->
class_id
//课时id,
];
}
...
...
@@ -216,7 +265,6 @@ class CourseProgressService
if
(
empty
(
$progressList
))
{
return
[];
}
// 返回所有记录(按时间倒序)
return
array_map
(
function
(
$progress
)
{
return
[
...
...
app/api/validate/CourseValidate.php
View file @
b2ab6b8c
...
...
@@ -6,8 +6,12 @@ class CourseValidate extends BaseValidate
{
protected
$rule
=
[
'searchKeyWords'
=>
'require'
,
'category_id'
=>
'require'
,
'course_id'
=>
'require'
,
'category_id'
=>
'require|number'
,
'course_id'
=>
'require|number'
,
'class_id'
=>
'require|number'
,
'current_time'
=>
'require|number'
,
'attachment_ids'
=>
'require'
,
'work_id'
=>
'require|number'
,
];
// protected $message = [
...
...
app/model/Course.php
View file @
b2ab6b8c
...
...
@@ -10,6 +10,8 @@
namespace
app\model
;
use
app\api\service\UserService
;
use
app\model\system\SystemUploadFile
;
use
think\facade\Db
;
use
think\Model
;
...
...
@@ -54,6 +56,7 @@ class Course extends Model
->
select
();
}
//获取课程详情
public
function
getCouresDetail
(
$course_id
=
0
)
{
// $where = ['status'=>3,'is_sell'=>1,'is_del'=>0];
...
...
@@ -62,10 +65,24 @@ class Course extends Model
$where
[
'id'
]
=
$course_id
;
}
return
self
::
where
(
$where
)
$detail
=
self
::
where
(
$where
)
->
with
([
'getTeacher'
])
->
field
(
'id,thumb,title,createtime,description,price,content,teacher_id,tvclick,click'
)
->
find
();
$detail
[
'is_learned'
]
=
0
;
//是否学习
$detail
[
'is_buy'
]
=
0
;
//是否购买
$token
=
request
()
->
header
(
'token'
);
$user
=
UserService
::
getUserInfo
(
$token
);
if
(
$user
)
{
$detail
[
'is_learned'
]
=
CourseProgress
::
where
([
'course_id'
=>
$detail
[
'id'
],
'user_id'
=>
$user
[
'id'
]])
->
count
();
}
return
$detail
;
}
//关联教师
...
...
@@ -92,5 +109,12 @@ class Course extends Model
->
order
(
'sort'
,
'asc'
);
}
//封面图
public
function
thumb
()
{
return
$this
->
hasOne
(
SystemUploadFile
::
class
,
'fileid'
,
'thumb'
)
->
field
(
'fileid,filename,filesize,fileurl,filetype'
);
}
}
\ No newline at end of file
app/model/CourseProgress.php
View file @
b2ab6b8c
...
...
@@ -14,7 +14,7 @@ class CourseProgress extends Model
// 自动时间戳(将createtime转换为时间戳自动管理)
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
// 不需要更新时间字段
protected
$updateTime
=
'updatetime'
;
// 关联课程
public
function
course
()
...
...
app/model/CourseUserWork.php
0 → 100644
View file @
b2ab6b8c
<?php
namespace
app\model
;
use
app\model\system\SystemUploadFile
;
use
think\Model
;
class
CourseUserWork
extends
Model
{
// 设置完整表名
protected
$table
=
'fj_course_user_work'
;
// 自动时间戳(将createtime转换为时间戳自动管理)
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
/** 作业列表
* @param $userId
* @param $page
* @param $pageSize
* @return array
* @throws \think\db\exception\DbException
*/
public
static
function
workList
(
$userId
,
$page
=
1
,
$pageSize
=
10
)
{
return
self
::
where
([
'user_id'
=>
$userId
])
->
with
([
'course'
,
'courseWork'
])
->
field
(
'id,user_id,work_id,status,course_id,createtime'
)
->
paginate
([
'page'
=>
$page
,
'list_rows'
=>
$pageSize
])
->
toArray
();
}
/**作业详情
* @param $id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
static
function
workDetail
(
$id
)
{
$detail
=
self
::
where
([
'id'
=>
$id
])
->
with
([
'course'
,
'courseWork'
])
->
field
(
'id,user_id,work_id,status,course_id,createtime'
)
->
findOrEmpty
();
if
(
$detail
->
isEmpty
())
{
return
[];
}
$detail
=
$detail
->
toArray
();
// 处理 courseWork 文件 课程作业附件
if
(
!
empty
(
$detail
[
'courseWork'
][
'file_id_str'
]))
{
$fileIds
=
is_string
(
$detail
[
'courseWork'
][
'file_id_str'
])
?
explode
(
','
,
$detail
[
'courseWork'
][
'file_id_str'
])
:
(
array
)
$detail
[
'courseWork'
][
'file_id_str'
];
$detail
[
'courseWork'
][
'file'
]
=
SystemUploadFile
::
whereIn
(
'fileid'
,
$fileIds
)
->
field
(
'fileurl,fileid,filename,filetype'
)
->
select
()
->
toArray
();
}
else
{
$detail
[
'courseWork'
][
'file'
]
=
[];
}
// 处理 attachment 文件 学生上传附件
$attachmentIds
=
!
empty
(
$detail
[
'attachment_ids'
])
?
(
is_string
(
$detail
[
'attachment_ids'
])
?
explode
(
','
,
$detail
[
'attachment_ids'
])
:
(
array
)
$detail
[
'attachment_ids'
])
:
[];
$detail
[
'attachment_file'
]
=
!
empty
(
$attachmentIds
)
?
SystemUploadFile
::
whereIn
(
'fileid'
,
$attachmentIds
)
->
field
(
'fileurl,fileid,filename,filetype'
)
->
select
()
->
toArray
()
:
[];
return
$detail
;
}
/**用户作业上传
* @param $workId
* @param $attachment_ids
* @return CourseUserWork
*/
public
static
function
uploadWork
(
$workId
,
$attachment_ids
)
{
return
self
::
where
([
'id'
=>
$workId
,
'status'
=>
0
])
->
update
([
'attachment_ids'
=>
$attachment_ids
,
'status'
=>
1
]);
}
//关联作业
public
function
courseWork
()
{
return
$this
->
hasOne
(
CourseWork
::
class
,
'id'
,
'work_id'
)
->
field
(
'id,title,file_id_str'
);
}
//关联课程
public
function
course
()
{
return
$this
->
hasOne
(
Course
::
class
,
'id'
,
'course_id'
)
->
field
(
'id,title'
);
}
}
\ No newline at end of file
app/model/CourseWork.php
0 → 100644
View file @
b2ab6b8c
<?php
namespace
app\model
;
use
think\Model
;
class
CourseWork
extends
Model
{
// 设置完整表名
protected
$table
=
'fj_course_work'
;
// 自动时间戳(将createtime转换为时间戳自动管理)
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
public
function
getFilelistAttr
(
$value
,
$data
)
{
return
get_upload_file
(
$data
[
'file_id_str'
],
'list'
);
}
}
\ 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