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
eb46e0a0
Commit
eb46e0a0
authored
Jun 22, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
搜索,排行榜,直播课
parent
f86f7eca
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
374 additions
and
10 deletions
+374
-10
Course.php
app/api/controller/Course.php
+3
-2
CourseProgress.php
app/api/controller/CourseProgress.php
+4
-2
Search.php
app/api/controller/Search.php
+243
-0
User.php
app/api/controller/User.php
+11
-0
Project.php
app/api/controller/project/Project.php
+14
-0
ProjectService.php
app/api/service/ProjectService.php
+58
-0
UserService.php
app/api/service/UserService.php
+32
-0
Cert.php
app/model/Cert.php
+3
-2
Course.php
app/model/Course.php
+6
-4
No files found.
app/api/controller/Course.php
View file @
eb46e0a0
...
...
@@ -85,7 +85,7 @@ class Course extends BaseController
}
$data
=
$request
->
param
();
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
];
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
,
'is_zb'
=>
1
];
$list
=
CourseModel
::
where
(
$where
)
->
where
(
'title'
,
'like'
,
'%'
.
$data
[
'searchKeyWords'
]
.
'%'
)
->
field
(
'id,thumb,title,createtime,description,price,content'
)
...
...
@@ -113,8 +113,9 @@ class Course extends BaseController
$page
=
$request
->
param
(
'page/d'
,
1
);
$pageSize
=
$request
->
param
(
'pageSize/d'
,
10
);
$is_zb
=
$request
->
param
(
'is_zb'
,
0
);
$list
=
(
new
CourseModel
())
->
getCourseListSecond
(
$data
[
'category_id'
],
$data
[
'second_category_id'
],
$page
,
$pageSize
,
$data
[
'searchKeyWords'
]
??
null
);
$list
=
(
new
CourseModel
())
->
getCourseListSecond
(
$data
[
'category_id'
],
$data
[
'second_category_id'
],
$page
,
$pageSize
,
$data
[
'searchKeyWords'
]
??
null
,
$is_zb
);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
...
...
app/api/controller/CourseProgress.php
View file @
eb46e0a0
...
...
@@ -40,7 +40,8 @@ class CourseProgress extends BaseController
'id'
=>
$data
[
'course_id'
],
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
'is_del'
=>
0
,
'is_zb'
=>
0
])
->
find
();
if
(
!
$course
)
{
...
...
@@ -123,7 +124,8 @@ class CourseProgress extends BaseController
'id'
=>
$data
[
'course_id'
],
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
'is_del'
=>
0
,
'is_zb'
=>
0
])
->
find
();
if
(
!
$course
)
{
...
...
app/api/controller/Search.php
0 → 100644
View file @
eb46e0a0
<?php
namespace
app\api\controller
;
use
app\BaseController
;
use
think\facade\Cache
;
use
think\facade\Db
;
class
Search
extends
BaseController
{
public
function
searchPlus
()
{
$keyword
=
$this
->
request
->
param
(
'searchKeyWords'
,
''
);
$page
=
$this
->
request
->
param
(
'page/d'
,
1
);
$pageSize
=
$this
->
request
->
param
(
'pageSize/d'
,
10
);
$cacheKey
=
'search_plus_'
.
md5
(
$keyword
.
'_'
.
$page
.
'_'
.
$pageSize
);
$cacheData
=
Cache
::
get
(
$cacheKey
);
if
(
$cacheData
!==
null
)
{
return
$this
->
returnMsg
(
'success'
,
1
,
$cacheData
);
}
$currentTime
=
time
();
// 构建UNION ALL查询
$baseQuery
=
'(SELECT a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, c.nickname as username, "kc" AS source
FROM fj_course a
LEFT JOIN fj_system_upload_file b ON a.thumb = b.fileid
LEFT JOIN fj_course_teacher c ON a.teacher_id = c.id
WHERE a.is_sell = 1 AND a.is_del = 0 AND a.status = 3 AND a.is_zb = 0'
;
if
(
!
empty
(
$keyword
))
{
$baseQuery
.=
' AND a.title LIKE "%'
.
addslashes
(
$keyword
)
.
'%"'
;
}
$baseQuery
.=
' UNION ALL
SELECT a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, "" as username, "xm" AS source
FROM fj_project a
LEFT JOIN fj_system_upload_file b ON a.thumb = b.fileid
WHERE a.sh_status = 2 AND a.status = 1 AND a.put_end_time > '
.
$currentTime
;
if
(
!
empty
(
$keyword
))
{
$baseQuery
.=
' AND a.title LIKE "%'
.
addslashes
(
$keyword
)
.
'%"'
;
}
$baseQuery
.=
' UNION ALL
SELECT a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, "" as username, "zs" AS source
FROM fj_cert a
LEFT JOIN fj_system_upload_file b ON a.thumb_id = b.fileid
WHERE a.is_sell = 1 AND a.is_del = 0'
;
if
(
!
empty
(
$keyword
))
{
$baseQuery
.=
' AND a.title LIKE "%'
.
addslashes
(
$keyword
)
.
'%"'
;
}
$baseQuery
.=
' UNION ALL
SELECT a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, c.username as username, "xxzl" AS source
FROM fj_study_information a
LEFT JOIN fj_system_upload_file b ON a.thumb = b.fileid
LEFT JOIN fj_user c ON a.user_id = c.id
WHERE a.is_sell = 1 AND a.deletetime IS NULL AND a.status = 2'
;
if
(
!
empty
(
$keyword
))
{
$baseQuery
.=
' AND a.title LIKE "%'
.
addslashes
(
$keyword
)
.
'%"'
;
}
$baseQuery
.=
') AS combined'
;
$query
=
Db
::
table
(
$baseQuery
)
->
order
(
'createtime'
,
'desc'
);
$list
=
$query
->
paginate
([
'list_rows'
=>
$pageSize
,
'page'
=>
$page
,
]);
$paginateData
=
$list
->
toArray
();
Cache
::
set
(
$cacheKey
,
$paginateData
,
300
);
return
$this
->
returnMsg
(
'success'
,
1
,
$paginateData
);
}
public
function
searchCourse
()
{
$keyword
=
$this
->
request
->
param
(
'searchKeyWords'
,
''
);
$page
=
$this
->
request
->
param
(
'page/d'
,
1
);
$pageSize
=
$this
->
request
->
param
(
'pageSize/d'
,
10
);
$cacheKey
=
'search_course_'
.
md5
(
$keyword
.
'_'
.
$page
.
'_'
.
$pageSize
);
$cacheData
=
Cache
::
get
(
$cacheKey
);
if
(
$cacheData
!==
null
)
{
return
$this
->
returnMsg
(
'success'
,
1
,
$cacheData
);
}
$query
=
Db
::
table
(
'fj_course a'
)
->
leftJoin
(
'fj_system_upload_file b'
,
'a.thumb = b.fileid'
)
->
leftJoin
(
'fj_course_teacher c'
,
'a.teacher_id = c.id'
)
->
field
(
'a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, c.nickname as username, "kc" AS source'
)
->
where
(
'a.is_sell'
,
1
)
->
where
(
'a.is_del'
,
0
)
->
where
(
'a.status'
,
3
)
->
where
(
'a.is_zb'
,
0
)
->
order
(
'a.createtime'
,
'desc'
);
if
(
!
empty
(
$keyword
))
{
$query
->
where
(
'a.title'
,
'like'
,
"%
{
$keyword
}
%"
);
}
$list
=
$query
->
paginate
([
'list_rows'
=>
$pageSize
,
'page'
=>
$page
,
]);
$paginateData
=
$list
->
toArray
();
Cache
::
set
(
$cacheKey
,
$paginateData
,
300
);
return
$this
->
returnMsg
(
'success'
,
1
,
$paginateData
);
}
public
function
searchStudy
()
{
$keyword
=
$this
->
request
->
param
(
'searchKeyWords'
,
''
);
$page
=
$this
->
request
->
param
(
'page/d'
,
1
);
$pageSize
=
$this
->
request
->
param
(
'pageSize/d'
,
10
);
$cacheKey
=
'search_study_'
.
md5
(
$keyword
.
'_'
.
$page
.
'_'
.
$pageSize
);
$cacheData
=
Cache
::
get
(
$cacheKey
);
if
(
$cacheData
!==
null
)
{
return
$this
->
returnMsg
(
'success'
,
1
,
$cacheData
);
}
$query
=
Db
::
table
(
'fj_study_information a'
)
->
leftJoin
(
'fj_system_upload_file b'
,
'a.thumb = b.fileid'
)
->
leftJoin
(
'fj_user c'
,
'a.user_id = c.id'
)
->
field
(
'a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, c.username as username, "xxzl" AS source'
)
->
where
(
'a.is_sell'
,
1
)
->
whereNull
(
'a.deletetime'
)
->
where
(
'a.status'
,
2
)
->
order
(
'a.createtime'
,
'desc'
);
if
(
!
empty
(
$keyword
))
{
$query
->
where
(
'a.title'
,
'like'
,
"%
{
$keyword
}
%"
);
}
$list
=
$query
->
paginate
([
'list_rows'
=>
$pageSize
,
'page'
=>
$page
,
]);
$paginateData
=
$list
->
toArray
();
Cache
::
set
(
$cacheKey
,
$paginateData
,
300
);
return
$this
->
returnMsg
(
'success'
,
1
,
$paginateData
);
}
public
function
searchProject
()
{
$keyword
=
$this
->
request
->
param
(
'searchKeyWords'
,
''
);
$page
=
$this
->
request
->
param
(
'page/d'
,
1
);
$pageSize
=
$this
->
request
->
param
(
'pageSize/d'
,
10
);
$currentTime
=
time
();
$cacheKey
=
'search_project_'
.
md5
(
$keyword
.
'_'
.
$page
.
'_'
.
$pageSize
);
$cacheData
=
Cache
::
get
(
$cacheKey
);
if
(
$cacheData
!==
null
)
{
return
$this
->
returnMsg
(
'success'
,
1
,
$cacheData
);
}
$query
=
Db
::
table
(
'fj_project a'
)
->
leftJoin
(
'fj_system_upload_file b'
,
'a.thumb = b.fileid'
)
->
field
(
'a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, "" as username, "xm" AS source'
)
->
where
(
'a.sh_status'
,
2
)
->
where
(
'a.status'
,
1
)
->
where
(
'a.put_end_time'
,
'>'
,
$currentTime
)
->
order
(
'a.createtime'
,
'desc'
);
if
(
!
empty
(
$keyword
))
{
$query
->
where
(
'a.title'
,
'like'
,
"%
{
$keyword
}
%"
);
}
$list
=
$query
->
paginate
([
'list_rows'
=>
$pageSize
,
'page'
=>
$page
,
]);
$paginateData
=
$list
->
toArray
();
Cache
::
set
(
$cacheKey
,
$paginateData
,
300
);
return
$this
->
returnMsg
(
'success'
,
1
,
$paginateData
);
}
public
function
searchCert
()
{
$keyword
=
$this
->
request
->
param
(
'searchKeyWords'
,
''
);
$page
=
$this
->
request
->
param
(
'page/d'
,
1
);
$pageSize
=
$this
->
request
->
param
(
'pageSize/d'
,
10
);
$cacheKey
=
'search_cert_'
.
md5
(
$keyword
.
'_'
.
$page
.
'_'
.
$pageSize
);
$cacheData
=
Cache
::
get
(
$cacheKey
);
if
(
$cacheData
!==
null
)
{
return
$this
->
returnMsg
(
'success'
,
1
,
$cacheData
);
}
$query
=
Db
::
table
(
'fj_cert a'
)
->
leftJoin
(
'fj_system_upload_file b'
,
'a.thumb_id = b.fileid'
)
->
field
(
'a.id, a.title, a.description, IFNULL(b.fileurl, "") as thumb, a.createtime, "" as username, "zs" AS source'
)
->
where
(
'a.is_sell'
,
1
)
->
where
(
'a.is_del'
,
0
)
->
order
(
'a.createtime'
,
'desc'
);
if
(
!
empty
(
$keyword
))
{
$query
->
where
(
'a.title'
,
'like'
,
"%
{
$keyword
}
%"
);
}
$list
=
$query
->
paginate
([
'list_rows'
=>
$pageSize
,
'page'
=>
$page
,
]);
$paginateData
=
$list
->
toArray
();
Cache
::
set
(
$cacheKey
,
$paginateData
,
300
);
return
$this
->
returnMsg
(
'success'
,
1
,
$paginateData
);
}
/**
* 清除搜索缓存
*/
public
function
clearSearchCache
()
{
$pattern
=
'search_plus_*'
;
Cache
::
tag
(
'search_plus'
)
->
clear
();
return
$this
->
returnMsg
(
'缓存清除成功'
,
1
);
}
}
\ No newline at end of file
app/api/controller/User.php
View file @
eb46e0a0
...
...
@@ -216,6 +216,17 @@ class User extends BaseController
}
public
function
rankUserExperience
(
Request
$request
)
{
$limit
=
$request
->
param
(
'limit/d'
,
1
);
$type
=
$request
->
param
(
'type'
,
'all'
);
$list
=
UserService
::
rankUserExperience
(
$limit
,
$type
);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
}
\ No newline at end of file
app/api/controller/project/Project.php
View file @
eb46e0a0
...
...
@@ -2,6 +2,7 @@
namespace
app\api\controller\project
;
use
app\api\service\ProjectService
;
use
app\api\service\UserService
;
use
app\api\validate\ProjectValidate
;
use
app\BaseController
;
...
...
@@ -164,6 +165,19 @@ class Project extends BaseController
return
$this
->
returnMsg
(
'success'
,
1
,
$tags
);
}
//获取项目完成率排行
public
function
rankProjectCompletionList
(
Request
$request
)
{
$limit
=
$request
->
param
(
'limit/d'
,
1
);
$type
=
$request
->
param
(
'type'
,
'all'
);
$list
=
ProjectService
::
getUserProjectCompletionRanking
(
$limit
,
$type
);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
}
\ No newline at end of file
app/api/service/ProjectService.php
View file @
eb46e0a0
...
...
@@ -196,4 +196,62 @@ class ProjectService
trace
(
'项目招募超时处理任务结束'
,
'project'
);
return
$result
;
}
/**
* 获取项目完成率
* @param $limit
* @param $timeRange 时间范围: 'all'-全部, 'month'-本月, 'week'-本周, 'day'-今天, 'three_month'-近三月
* @return mixed
*/
public
static
function
getUserProjectCompletionRanking
(
$limit
=
10
,
$timeRange
=
'all'
)
{
// 查询接单总数和完成数量
$query
=
Db
::
name
(
'project_put'
)
->
field
(
'user_id,
COUNT(*) as total_puts,
SUM(CASE WHEN complete_status = 3 THEN 1 ELSE 0 END) as completed_projects,
ROUND((SUM(CASE WHEN complete_status = 3 THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2) as completion_rate'
)
->
where
(
'status'
,
2
)
// 只统计接单成功的记录
->
group
(
'user_id'
)
->
having
(
'total_puts > 0'
)
// 确保分母不为零
->
order
(
'completion_rate'
,
'DESC'
)
->
limit
(
$limit
);
// 按时间范围筛选
switch
(
$timeRange
)
{
case
'month'
:
$query
->
whereTime
(
'put_time'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'put_time'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'put_time'
,
'today'
);
break
;
case
'three_month'
:
$threeMonthAgo
=
strtotime
(
'-3 months'
);
$query
->
where
(
'put_time'
,
'>='
,
$threeMonthAgo
);
break
;
}
$ranking
=
$query
->
select
()
->
toArray
();
// 获取用户信息
if
(
!
empty
(
$ranking
))
{
$userIds
=
array_column
(
$ranking
,
'user_id'
);
$users
=
Db
::
name
(
'user'
)
->
whereIn
(
'id'
,
$userIds
)
->
where
(
'is_del'
,
0
)
->
column
(
'username,realname,headico'
,
'id'
);
foreach
(
$ranking
as
&
$item
)
{
$item
[
'user_info'
]
=
$users
[
$item
[
'user_id'
]]
??
[];
// 确保完成率有值,如果没有则为0
$item
[
'completion_rate'
]
=
$item
[
'completion_rate'
]
??
0
;
}
}
return
$ranking
;
}
}
\ No newline at end of file
app/api/service/UserService.php
View file @
eb46e0a0
...
...
@@ -35,5 +35,37 @@ class UserService
return
User
::
where
(
'id'
,
\request
()
->
userId
)
->
update
([
$filed
=>
$value
]);
}
public
static
function
rankUserExperience
(
$limit
=
10
,
$timeRange
=
'all'
)
{
// 基础查询
$query
=
userModel
::
field
(
'id, username, realname, headico, experience'
)
->
with
([
'headico'
])
->
where
(
'is_del'
,
0
)
->
where
(
'experience'
,
'>'
,
0
)
->
order
(
'experience'
,
'DESC'
)
->
limit
(
$limit
);
// 按时间范围筛选(如果需要基于注册时间筛选)
switch
(
$timeRange
)
{
case
'month'
:
$query
->
whereTime
(
'register_time'
,
'month'
);
break
;
case
'week'
:
$query
->
whereTime
(
'register_time'
,
'week'
);
break
;
case
'day'
:
$query
->
whereTime
(
'register_time'
,
'today'
);
break
;
case
'three_month'
:
$threeMonthAgo
=
strtotime
(
'-3 months'
);
$query
->
where
(
'register_time'
,
'>='
,
$threeMonthAgo
);
break
;
}
$ranking
=
$query
->
select
()
->
toArray
();
return
$ranking
;
}
}
\ No newline at end of file
app/model/Cert.php
View file @
eb46e0a0
...
...
@@ -11,7 +11,7 @@
namespace
app\model
;
use
app\api\service\UtilService
;
use
\
app\model\CertCategory
;
use
app\model\CertCategory
;
use
app\model\system\SystemUploadFile
;
use
think\facade\Db
;
use
think\Model
;
...
...
@@ -130,7 +130,8 @@ class Cert extends Model
$query
->
whereIn
(
'cate_id'
,
array_merge
([
$first_category_id
],
$son_ids
));
}
// 如果一级分类为0,则不限制分类(查询全部)
if
(
$searchKeyWords
)
{
$query
->
where
(
'title'
,
'like'
,
'%'
.
$searchKeyWords
.
'%'
);
...
...
app/model/Course.php
View file @
eb46e0a0
...
...
@@ -30,7 +30,8 @@ class Course extends Model
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
,
'is_tj'
=>
1
'is_tj'
=>
1
,
'is_zb'
=>
0
]);
if
(
!
empty
(
$category_id
))
{
...
...
@@ -61,7 +62,8 @@ class Course extends Model
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
,
'is_hot'
=>
1
'is_hot'
=>
1
,
'is_zb'
=>
0
]);
if
(
!
empty
(
$category_id
))
{
...
...
@@ -111,9 +113,9 @@ class Course extends Model
}
// 6.20 两级分类查询
public
function
getCourseListSecond
(
$first_category_id
,
$second_category_id
,
$page
,
$pageSize
,
$searchKeyWords
=
null
)
public
function
getCourseListSecond
(
$first_category_id
,
$second_category_id
,
$page
,
$pageSize
,
$searchKeyWords
=
null
,
$is_zb
=
0
)
{
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
];
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
,
'is_zb'
=>
$is_zb
];
$query
=
self
::
where
(
$where
);
...
...
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