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
abf68cfb
Commit
abf68cfb
authored
May 12, 2025
by
wangzhengwen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5.12
parent
1d93fb65
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
231 additions
and
10 deletions
+231
-10
Course.php
app/api/controller/Course.php
+118
-0
Sms.php
app/api/controller/Sms.php
+5
-1
Auth.php
app/api/middleware/Auth.php
+0
-2
CourseValidate.php
app/api/validate/CourseValidate.php
+23
-0
Course.php
app/model/Course.php
+49
-0
CourseCategory.php
app/model/CourseCategory.php
+23
-0
SendSms.php
extend/tool/SendSms.php
+13
-7
No files found.
app/api/controller/Course.php
0 → 100644
View file @
abf68cfb
<?php
namespace
app\api\controller
;
use
app\model\CourseTeacher
;
use
think\Request
;
use
app\api\validate\CourseValidate
;
use
app\BaseController
;
use
app\model\Course
as
CourseModel
;
use
app\model\CourseCategory
as
CourseCategoryModel
;
class
Course
extends
BaseController
{
/**获取推荐课程列表
* @return \app\html
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getRecommendList
()
{
$list
=
(
new
CourseModel
())
->
getRecommendList
();
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
/**获取课程分类列表
* @return \app\html
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getCourseCategoryList
()
{
$list
=
(
new
CourseCategoryModel
())
->
getCourseCategoryList
();
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
/**课程搜索
* @param Request $request
* @return \app\html|\think\response\Json|true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
searchCourse
(
Request
$request
)
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'searchKeyWords'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
];
$list
=
CourseModel
::
where
(
$where
)
->
where
(
'title'
,
'like'
,
'%'
.
$data
[
'searchKeyWords'
]
.
'%'
)
->
field
(
'id,thumb,title,createtime,description,price,content'
)
->
select
();
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
/**获取分类下的课程列表
* @param Request $request
* @return \app\html|\think\response\Json|true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getCourseList
(
Request
$request
)
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'category_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$list
=
(
new
CourseModel
())
->
getCourseList
(
$data
[
'category_id'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
$list
);
}
//关联教师
public
function
teacher
()
{
return
$this
->
hasOne
(
CourseTeacher
::
class
,
'teacher_id'
,
'id'
)
->
field
(
'id,nickname,description'
);
}
//关联章节
// public function sections()
// {
// return $this->hasMany(Course::class, 'course_id');
// }
public
function
getCourseDetail
(
Request
$request
)
{
$vo
=
(
new
CourseValidate
())
->
goCheck
([
'course_id'
]);
if
(
$vo
!==
true
)
{
return
$vo
;
}
$data
=
$request
->
param
();
$data
=
(
new
CourseModel
())
->
getCouresDetail
(
$data
[
'course_id'
]);
return
$this
->
returnMsg
(
'success'
,
1
,
$data
);
}
}
\ No newline at end of file
app/api/controller/Sms.php
View file @
abf68cfb
...
...
@@ -23,7 +23,11 @@ class Sms extends BaseController
$code
=
str_pad
(
random_int
(
0
,
9999
),
4
,
'0'
,
STR_PAD_LEFT
);
// halt($code);
$SMS
=
new
SendSms
();
return
$this
->
returnMsg
(
$SMS
->
aliyun_send
(
$data
[
'mobile'
],
$code
));
$res
=
$SMS
->
aliyun_send
(
$data
[
'mobile'
],
$code
);
return
$this
->
returnMsg
(
$res
[
'msg'
],
$res
[
'code'
]);
}
...
...
app/api/middleware/Auth.php
View file @
abf68cfb
...
...
@@ -22,8 +22,6 @@ class Auth extends BaseController
protected
function
checkToken
(
$token
)
{
// 实现你的token验证逻辑
// 返回true或false
if
(
!
$token
)
{
...
...
app/api/validate/CourseValidate.php
0 → 100644
View file @
abf68cfb
<?php
namespace
app\api\validate
;
class
CourseValidate
extends
BaseValidate
{
protected
$rule
=
[
'searchKeyWords'
=>
'require'
,
'category_id'
=>
'require'
,
'course_id'
=>
'require'
,
];
// protected $message = [
// 'name.require' => '名称必须',
// 'mobile.require' => '手机号不能为空',
// 'mobile.mobile' => '手机号格式不正确',
// 'password.require' => '密码必须',
// 'code.require' => '验证码必须',
// 'token.require' => 'token必须',
// 'str.require' => '必填项不能为空',
// 'confirm_password.checkPasswordEqual' => '两次输入的密码不一致'
// ];
}
\ No newline at end of file
app/model/Course.php
View file @
abf68cfb
...
...
@@ -19,5 +19,54 @@ use think\Model;
class
Course
extends
Model
{
/**获取推荐课程列表
* @return Course[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getRecommendList
()
{
return
self
::
where
([
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
])
->
order
(
'click,tvclick,createtime'
,
'desc'
)
->
field
(
'id,thumb,title'
)
->
limit
(
5
)
->
select
();
}
/**获取分类下的课程列表
* @param $cate_id
* @return Course[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getCourseList
(
$cate_id
=
0
)
{
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
];
if
(
$cate_id
)
{
$where
[
'cate_id'
]
=
$cate_id
;
}
return
self
::
where
(
$where
)
->
field
(
'id,thumb,title,createtime,description,price,content'
)
->
select
();
}
public
function
getCouresDetail
(
$course_id
=
0
)
{
$where
=
[
'status'
=>
3
,
'is_sell'
=>
1
,
'is_del'
=>
0
];
if
(
$course_id
)
{
$where
[
'course_id'
]
=
$course_id
;
}
return
self
::
where
(
$where
)
->
field
(
'id,thumb,title,createtime,description,price,content,teacher_id,tvclick,click'
)
->
find
();
}
}
\ No newline at end of file
app/model/CourseCategory.php
View file @
abf68cfb
...
...
@@ -40,7 +40,30 @@ class CourseCategory extends Model
return
get_upload_file
(
$data
[
'thumb'
]);
}
public
function
children
()
{
return
$this
->
hasMany
(
CourseCategory
::
class
,
'pid'
);
}
/**获取课程分类列表
* @return CourseCategory[]|array|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public
function
getCourseCategoryList
()
{
$where
[]
=
[
'is_del'
,
'='
,
0
];
return
$this
->
with
([
'children'
=>
function
(
$query
)
use
(
$where
)
{
$query
->
where
(
$where
);
$query
->
order
(
'sort'
,
'asc'
);
}])
->
where
(
'pid'
,
0
)
->
where
(
$where
)
->
order
(
'sort'
,
'asc'
)
->
select
();
}
}
\ No newline at end of file
extend/tool/SendSms.php
View file @
abf68cfb
...
...
@@ -181,12 +181,12 @@ class SendSms
* @return array
*/
public
function
aliyun_send
(
int
$mobile
=
0
,
int
$code
=
0
,
int
$tpid
=
0
,
string
$tips
=
''
,
int
$lent
=
0
)
public
function
aliyun_send
(
int
$mobile
=
0
,
int
$code
=
0
,
string
$tpid
=
''
,
string
$tips
=
''
,
int
$lent
=
0
)
{
$errMsg
=
''
;
$time
=
time
();
$res_code
=
0
;
$status
=
1
;
$status
=
0
;
//屏蔽频繁发送
$arr
=
cache
(
$this
->
cache_key
);
...
...
@@ -200,7 +200,6 @@ class SendSms
if
(
!
$mobile
)
return
[
'msg'
=>
'手机号不能为空'
,
'code'
=>
0
];
if
(
!
$code
)
return
[
'msg'
=>
'短信验证码不能为空'
,
'code'
=>
0
];
$template_id
=
$tpid
?
$tpid
:
$this
->
config
[
'sms_template_id'
];
...
...
@@ -233,9 +232,16 @@ class SendSms
->
timeout
(
10
)
// 请求超时(秒)
->
request
();
// 执行请求
$res_code
=
200
;
$errMsg
=
'success'
;
$status
=
1
;
if
(
$result
[
'Code'
]
===
'OK'
)
{
$res_code
=
200
;
$errMsg
=
'success'
;
$status
=
1
;
}
else
{
$res_code
=
500
;
$errMsg
=
$result
[
'Message'
];
}
cache
(
$this
->
cache_key
,[
'time'
=>
$time
]);
}
catch
(
ClientException
$e
)
{
$res_code
=
$e
->
getCode
();
...
...
@@ -255,7 +261,7 @@ class SendSms
'editor'
=>
'api'
,
'sendtime'
=>
$time
,
'code'
=>
$code
,
'err_msg'
=>
$errMsg
,
'res_code'
=>
$res_code
,
'status'
=>
$status
,];
Db
::
name
(
'system_sms'
)
->
data
(
$data
)
->
insert
();
return
[
'
res_code'
=>
$res_code
,
'status
'
=>
$status
];
return
[
'
msg'
=>
$errMsg
,
'code
'
=>
$status
];
}
}
\ 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