Commit abf68cfb authored by wangzhengwen's avatar wangzhengwen

5.12

parent 1d93fb65
<?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
......@@ -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']);
}
......
......@@ -22,8 +22,6 @@ class Auth extends BaseController
protected function checkToken($token)
{
// 实现你的token验证逻辑
// 返回true或false
if (!$token)
{
......
<?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
......@@ -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
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment