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
44a5c681
Commit
44a5c681
authored
May 30, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5.30
parent
51ebe32a
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
223 additions
and
23 deletions
+223
-23
CourseComment.php
app/api/controller/CourseComment.php
+76
-0
UtilService.php
app/api/service/UtilService.php
+16
-0
CourseValidate.php
app/api/validate/CourseValidate.php
+38
-19
Course.php
app/model/Course.php
+1
-1
CourseComment.php
app/model/CourseComment.php
+29
-3
CourseCommentLike.php
app/model/CourseCommentLike.php
+24
-0
CourseCommentReport.php
app/model/CourseCommentReport.php
+39
-0
No files found.
app/api/controller/CourseComment.php
View file @
44a5c681
...
...
@@ -7,6 +7,8 @@ use app\api\validate\CourseValidate;
use
app\BaseController
;
use
think\facade\Request
;
use
app\model\CourseComment
as
courseCommentModel
;
use
app\model\CourseCommentLike
;
use
app\model\CourseCommentReport
;
class
CourseComment
extends
BaseController
{
...
...
@@ -96,4 +98,78 @@ class CourseComment extends BaseController
}
//点赞评论
public
function
like
()
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'comment_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$userId
=
$this
->
request
->
userId
;
$commentId
=
Request
::
param
(
'comment_id/d'
,
0
);
// 检查评论是否存在
$comment
=
courseCommentModel
::
where
(
'id'
,
$commentId
)
->
find
();
if
(
!
$comment
)
{
return
$this
->
returnMsg
(
'评论不存在'
);
}
// 检查是否已经点赞
$like
=
CourseCommentLike
::
where
(
'comment_id'
,
$commentId
)
->
where
(
'user_id'
,
$userId
)
->
find
();
if
(
$like
)
{
// 如果已经点赞,则取消点赞
$like
->
delete
();
return
$this
->
returnMsg
(
'取消点赞成功'
,
1
);
}
else
{
// 如果未点赞,则添加点赞
CourseCommentLike
::
create
([
'comment_id'
=>
$commentId
,
'user_id'
=>
$userId
]);
return
$this
->
returnMsg
(
'点赞成功'
,
1
);
}
}
// 举报评论
public
function
report
()
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'comment_id'
,
'reason'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$userId
=
$this
->
request
->
userId
;
$commentId
=
Request
::
param
(
'comment_id/d'
,
0
);
$reason
=
Request
::
param
(
'reason/s'
,
''
);
// 检查评论是否存在
$comment
=
courseCommentModel
::
where
(
'id'
,
$commentId
)
->
find
();
if
(
!
$comment
)
{
return
$this
->
returnMsg
(
'评论不存在'
);
}
// 检查是否已经举报过
$existReport
=
CourseCommentReport
::
where
(
'comment_id'
,
$commentId
)
->
where
(
'user_id'
,
$userId
)
->
find
();
if
(
$existReport
)
{
return
$this
->
returnMsg
(
'您已经举报过该评论'
);
}
// 创建举报
CourseCommentReport
::
create
([
'comment_id'
=>
$commentId
,
'user_id'
=>
$userId
,
'reason'
=>
$reason
,
'status'
=>
0
]);
return
$this
->
returnMsg
(
'举报成功'
,
1
);
}
}
\ No newline at end of file
app/api/service/UtilService.php
View file @
44a5c681
...
...
@@ -2,6 +2,7 @@
namespace
app\api\service
;
use
app\model\CourseClass
;
use
app\model\Payment
;
use
think\facade\Cache
;
...
...
@@ -110,6 +111,21 @@ class UtilService
*/
public
static
function
checkPurchase
(
$userId
,
$productId
,
$orderType
)
{
//如果是课程课时存在试看的情况下
if
(
$productId
==
1
)
{
$course_class_id
=
input
(
'course_class'
);
if
(
$course_class_id
)
{
$is_sk
=
CourseClass
::
where
([
'course_id'
=>
$productId
,
'id'
=>
$course_class_id
])
->
value
(
'is_sk'
);
if
(
$is_sk
)
{
return
true
;
}
}
}
return
Payment
::
where
([
'user_id'
=>
$userId
,
'order_type'
=>
$orderType
,
...
...
app/api/validate/CourseValidate.php
View file @
44a5c681
...
...
@@ -2,27 +2,46 @@
namespace
app\api\validate
;
use
think\Validate
;
class
CourseValidate
extends
BaseValidate
{
protected
$rule
=
[
'searchKeyWords'
=>
'require'
,
'category_id'
=>
'require|number'
,
'course_id'
=>
'require|number'
,
'class_id'
=>
'require|number'
,
'current_time'
=>
'require|number'
,
'attachment_ids'
=>
'require'
,
'work_id'
=>
'require|number'
,
'content'
=>
'require'
,
protected
$rule
=
[
'searchKeyWords'
=>
'require'
,
'category_id'
=>
'require|number'
,
'course_id'
=>
'require|number'
,
'class_id'
=>
'require|number'
,
'current_time'
=>
'require|number'
,
'attachment_ids'
=>
'require'
,
'work_id'
=>
'require|number'
,
'content'
=>
'require'
,
'comment_id'
=>
'require|number'
,
'reason'
=>
'require|length:1,255'
];
protected
$message
=
[
'name.require'
=>
'名称必须'
,
'mobile.require'
=>
'手机号不能为空'
,
'mobile.mobile'
=>
'手机号格式不正确'
,
'password.require'
=>
'密码必须'
,
'code.require'
=>
'验证码必须'
,
'token.require'
=>
'token必须'
,
'str.require'
=>
'必填项不能为空'
,
'confirm_password.checkPasswordEqual'
=>
'两次输入的密码不一致'
,
'reason.require'
=>
'举报原因不能为空'
,
'reason.length'
=>
'举报原因长度必须在1-255个字符之间'
];
// protected $message = [
// 'name.require' => '名称必须',
// 'mobile.require' => '手机号不能为空',
// 'mobile.mobile' => '手机号格式不正确',
// 'password.require' => '密码必须',
// 'code.require' => '验证码必须',
// 'token.require' => 'token必须',
// 'str.require' => '必填项不能为空',
// 'confirm_password.checkPasswordEqual' => '两次输入的密码不一致'
// ];
protected
$scene
=
[
'searchKeyWords'
=>
[
'searchKeyWords'
],
'category_id'
=>
[
'category_id'
],
'course_id'
=>
[
'course_id'
],
'class_id'
=>
[
'class_id'
],
'current_time'
=>
[
'current_time'
],
'attachment_ids'
=>
[
'attachment_ids'
],
'work_id'
=>
[
'work_id'
],
'content'
=>
[
'content'
],
'comment_id'
=>
[
'comment_id'
],
'reason'
=>
[
'reason'
]
];
}
\ No newline at end of file
app/model/Course.php
View file @
44a5c681
...
...
@@ -113,7 +113,7 @@ class Course extends Model
}
$detail
=
self
::
where
(
$where
)
->
with
([
'getTeacher'
])
->
with
([
'getTeacher'
=>
[
'thumb'
]
])
->
field
(
'id,thumb,title,createtime,description,price,content,teacher_id,tvclick,click'
)
->
find
();
$detail
[
'is_learned'
]
=
0
;
//是否学习
...
...
app/model/CourseComment.php
View file @
44a5c681
...
...
@@ -17,10 +17,12 @@ class CourseComment extends Model
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
// 指定软删除字段
protected
$deleteTime
=
'deletetime'
;
// 追加字段
protected
$append
=
[
'user_like'
,
'likes_count'
];
// 用户关联
public
function
user
()
{
...
...
@@ -36,13 +38,37 @@ class CourseComment extends Model
->
order
(
'createtime'
,
'asc'
);
}
// 获取课程评论列表
// 点赞关联
public
function
likes
()
{
return
$this
->
hasMany
(
CourseCommentLike
::
class
,
'comment_id'
,
'id'
);
}
// 获取用户是否点赞
public
function
getUserLikeAttr
(
$value
,
$data
)
{
$userId
=
request
()
->
userId
??
0
;
return
CourseCommentLike
::
where
(
'comment_id'
,
$data
[
'id'
])
->
where
(
'user_id'
,
$userId
)
->
count
()
>
0
;
}
// 获取点赞数
public
function
getLikesCountAttr
(
$value
,
$data
)
{
return
CourseCommentLike
::
where
(
'comment_id'
,
$data
[
'id'
])
->
count
();
}
// 获取评论列表
public
static
function
getCommentList
(
$courseId
,
$page
=
1
,
$pageSize
=
10
)
{
return
self
::
with
([
'user'
=>
[
'headico'
],
'replies'
])
return
self
::
with
([
'user'
,
'replies'
=>
function
(
$query
)
{
$query
->
with
([
'user'
])
->
append
([
'user_like'
,
'likes_count'
]);
}])
->
where
(
'course_id'
,
$courseId
)
->
where
(
'parent_id'
,
0
)
->
order
(
'createtime'
,
'desc'
)
->
append
([
'user_like'
,
'likes_count'
])
->
paginate
([
'page'
=>
$page
,
'list_rows'
=>
$pageSize
...
...
app/model/CourseCommentLike.php
0 → 100644
View file @
44a5c681
<?php
namespace
app\model
;
use
think\Model
;
class
CourseCommentLike
extends
Model
{
// 设置表名
protected
$name
=
'course_comment_likes'
;
// 设置时间字段
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
false
;
// 设置字段
protected
$schema
=
[
'id'
=>
'int'
,
'comment_id'
=>
'int'
,
'user_id'
=>
'int'
,
'createtime'
=>
'int'
,
];
}
\ No newline at end of file
app/model/CourseCommentReport.php
0 → 100644
View file @
44a5c681
<?php
namespace
app\model
;
use
think\Model
;
class
CourseCommentReport
extends
Model
{
// 设置表名
protected
$table
=
'fj_course_comment_reports'
;
// 设置时间字段
protected
$autoWriteTimestamp
=
true
;
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
// 设置字段
protected
$schema
=
[
'id'
=>
'int'
,
'comment_id'
=>
'int'
,
'user_id'
=>
'int'
,
'reason'
=>
'string'
,
'status'
=>
'int'
,
'createtime'
=>
'int'
,
'updatetime'
=>
'int'
];
// 关联评论
public
function
comment
()
{
return
$this
->
belongsTo
(
CourseComment
::
class
,
'comment_id'
,
'id'
);
}
// 关联用户
public
function
user
()
{
return
$this
->
belongsTo
(
User
::
class
,
'user_id'
,
'id'
);
}
}
\ 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