Commit 333c54f5 authored by wangzhengwen's avatar wangzhengwen

6.10

parent bfbd5862
...@@ -57,6 +57,19 @@ class Course extends BaseController ...@@ -57,6 +57,19 @@ class Course extends BaseController
return $this->returnMsg('success',1,$list); return $this->returnMsg('success',1,$list);
} }
public function getCourseCategoryChildrenList(Request $request)
{
$vo = (new CourseValidate())->goCheck(['pid']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$list = (new CourseCategoryModel())->getCourseCategoryList($data['pid'] ?? 0);
return $this->returnMsg('success',1,$list);
}
/**课程搜索 /**课程搜索
* @param Request $request * @param Request $request
* @return \app\html|\think\response\Json|true * @return \app\html|\think\response\Json|true
...@@ -101,7 +114,7 @@ class Course extends BaseController ...@@ -101,7 +114,7 @@ class Course extends BaseController
$page = $request->param('page/d', 1); $page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10); $pageSize = $request->param('pageSize/d', 10);
$list = (new CourseModel())->getCourseList($data['category_id'],$page,$pageSize); $list = (new CourseModel())->getCourseList($data['category_id'],$page,$pageSize,$data['searchKeyWords'] ?? null);
return $this->returnMsg('success',1,$list); return $this->returnMsg('success',1,$list);
......
...@@ -8,7 +8,7 @@ use app\api\service\UtilService; ...@@ -8,7 +8,7 @@ use app\api\service\UtilService;
use app\api\validate\CourseValidate; use app\api\validate\CourseValidate;
use app\BaseController; use app\BaseController;
use app\model\Payment; use app\model\Payment;
use think\Facade\Request; use think\facade\Request;
use app\api\service\CourseProgressService; use app\api\service\CourseProgressService;
use app\model\Course as CourseModel; use app\model\Course as CourseModel;
......
...@@ -65,12 +65,17 @@ class User extends BaseController ...@@ -65,12 +65,17 @@ class User extends BaseController
return $this->returnMsg('用户已存在',0); return $this->returnMsg('用户已存在',0);
} }
$checkSmsCode = UtilService::checkSmsCode($data['mobile'],$data['code']); //只有普通用户验证验证码
if (!$checkSmsCode) if ($data['role'] == 1)
{ {
return $this->returnMsg('验证码错误'); $checkSmsCode = UtilService::checkSmsCode($data['mobile'],$data['code']);
if (!$checkSmsCode)
{
return $this->returnMsg('验证码错误');
}
} }
$user['username'] = $data['name']; $user['username'] = $data['name'];
$user['mobile'] = $data['mobile']; $user['mobile'] = $data['mobile'];
$user['salt'] = random(4); $user['salt'] = random(4);
...@@ -168,6 +173,46 @@ class User extends BaseController ...@@ -168,6 +173,46 @@ class User extends BaseController
} }
/**验证验证码
* @param Request $request
* @return \app\html|\think\response\Json|true
*/
public function checkSmsCode(Request $request)
{
$vo = (new UserValidate())->goCheck(['mobile','code']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$checkSmsCode = UtilService::checkSmsCode($data['mobile'],$data['code']);
if (!$checkSmsCode)
{
return $this->returnMsg('验证码错误');
}
return $this->returnMsg('success',1);
}
public function checkMobile(Request $request)
{
$vo = (new UserValidate())->goCheck(['mobile']);
if ($vo !== true) {
return $vo;
}
$data = $request->param();
$count = userModel::where(['mobile' => $data['mobile']])->count();
if ($count > 0)
{
return $this->returnMsg('手机号已存在');
}
return $this->returnMsg('success',1);
}
} }
\ No newline at end of file
...@@ -47,7 +47,7 @@ class Cert extends BaseController ...@@ -47,7 +47,7 @@ class Cert extends BaseController
$page = $request->param('page/d', 1); $page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10); $pageSize = $request->param('pageSize/d', 10);
$list = (new CertModel())->getCertList($data['category_id'],$page,$pageSize,$data['type']); $list = (new CertModel())->getCertList($data['category_id'],$page,$pageSize,$data['type'],$data['searchKeyWords'] ?? null);
return $this->returnMsg('success',1,$list); return $this->returnMsg('success',1,$list);
} }
......
...@@ -47,7 +47,7 @@ class Project extends BaseController ...@@ -47,7 +47,7 @@ class Project extends BaseController
$page = $request->param('page/d', 1); $page = $request->param('page/d', 1);
$pageSize = $request->param('pageSize/d', 10); $pageSize = $request->param('pageSize/d', 10);
$list = (new ProjectModel())->getProjectList($data['category_id'],$page,$pageSize,$data['type']); $list = (new ProjectModel())->getProjectList($data['category_id'],$page,$pageSize,$data['type'],$data['searchKeyWords'] ?? null);
return $this->returnMsg('success',1,$list); return $this->returnMsg('success',1,$list);
} }
......
...@@ -9,6 +9,11 @@ use app\model\CourseWork; ...@@ -9,6 +9,11 @@ use app\model\CourseWork;
class CourseProgressService class CourseProgressService
{ {
// 常量定义
const MIN_CONSIDERED_FINISHED_SECONDS = 10; // 视为完成的最小观看秒数
const FINISHED_THRESHOLD_PERCENT = 95; // 视为完成的进度百分比阈值
/** /**
* 更新学习进度 * 更新学习进度
* @param int $userId 用户ID * @param int $userId 用户ID
...@@ -29,7 +34,7 @@ class CourseProgressService ...@@ -29,7 +34,7 @@ class CourseProgressService
// 判断是否看完(观看进度超过95%或最后10秒) // 判断是否看完(观看进度超过95%或最后10秒)
$isFinished = ($currentTime >= $duration - 10) || ($currentTime >= $duration * 0.95); $isFinished = ($currentTime >= $duration - self::MIN_CONSIDERED_FINISHED_SECONDS) || ($currentTime >= $duration * self::FINISHED_THRESHOLD_PERCENT);
// 查找或创建记录 // 查找或创建记录
$progress = CourseProgress::where([ $progress = CourseProgress::where([
...@@ -170,12 +175,50 @@ class CourseProgressService ...@@ -170,12 +175,50 @@ class CourseProgressService
]; ];
} }
/** // /**
* 获取用户课程进度统计 // * 获取用户课程进度统计
* @param int $userId 用户ID // * @param int $userId 用户ID
* @param int $courseId 课程ID // * @param int $courseId 课程ID
* @return array // * @return array
*/ // */
// public static function getCourseProgress($userId, $courseId)
// {
// // 获取所有课时进度
// $progressList = CourseProgress::with(['class'])
// ->where('user_id', $userId)
// ->where('course_id', $courseId)
// ->select();
// // 统计计算
// $finishedCount = 0;
// $totalDuration = 0;
// $learnedDuration = 0;
//
// $classProgress = [];
// foreach ($progressList as $item) {
// if ($item->is_wc_look) {
// $finishedCount++;
// }
// $totalDuration += $item->tvtime;
// $learnedDuration += min($item->look_tvtime, $item->tvtime);
//
// $classProgress[$item->class_id] = [
// 'progress' => $item->look_tvtime,
// 'duration' => $item->tvtime,
// 'is_finished' => $item->is_wc_look,
// 'last_learn' => $item->createtime,
// 'class_id' => $item->class_id//课时id,
// ];
// }
// $progress_percent = $totalDuration > 0 ? round($learnedDuration / $totalDuration * 100) : 0;
//
// return [
// 'finished_count' => $finishedCount,
// 'total_classes' => count($progressList),
// 'progress_percent' => $totalDuration > 0 ? round($learnedDuration / $totalDuration * 100) : 0,
// 'classes' => $classProgress
// ];
// }
public static function getCourseProgress($userId, $courseId) public static function getCourseProgress($userId, $courseId)
{ {
// 获取所有课时进度 // 获取所有课时进度
...@@ -183,6 +226,7 @@ class CourseProgressService ...@@ -183,6 +226,7 @@ class CourseProgressService
->where('user_id', $userId) ->where('user_id', $userId)
->where('course_id', $courseId) ->where('course_id', $courseId)
->select(); ->select();
// 统计计算 // 统计计算
$finishedCount = 0; $finishedCount = 0;
$totalDuration = 0; $totalDuration = 0;
...@@ -190,30 +234,48 @@ class CourseProgressService ...@@ -190,30 +234,48 @@ class CourseProgressService
$classProgress = []; $classProgress = [];
foreach ($progressList as $item) { foreach ($progressList as $item) {
if ($item->is_wc_look) { // 计算当前课时的观看比例
$currentProgress = ($item->tvtime > 0) ? ($item->look_tvtime / $item->tvtime) : 0;
// 判断是否满足"视为完成"的条件(观看时间<10s 或 进度>95%)
$isConsideredFinished = ($item->look_tvtime < self::MIN_CONSIDERED_FINISHED_SECONDS) || ($currentProgress > self::FINISHED_THRESHOLD_PERCENT);
if ($item->is_wc_look || $isConsideredFinished) {
$finishedCount++; $finishedCount++;
$learnedDuration += $item->tvtime; // 视为完成则计入全部时长
} else {
$learnedDuration += min($item->look_tvtime, $item->tvtime);
} }
$totalDuration += $item->tvtime; $totalDuration += $item->tvtime;
$learnedDuration += min($item->look_tvtime, $item->tvtime);
$classProgress[$item->class_id] = [ $classProgress[$item->class_id] = [
'progress' => $item->look_tvtime, 'progress' => $item->look_tvtime,
'duration' => $item->tvtime, 'duration' => $item->tvtime,
'is_finished' => $item->is_wc_look, 'is_finished' => $item->is_wc_look || $isConsideredFinished,
'last_learn' => $item->createtime, 'last_learn' => $item->createtime,
'class_id' => $item->class_id//课时id, 'class_id' => $item->class_id
]; ];
} }
// 计算总进度(如果满足条件则直接显示100%)
$progress_percent = ($totalDuration > 0)
? round($learnedDuration / $totalDuration * 100)
: 0;
// 应用优化规则:如果观看进度<10s或已完成>95%,则显示100%
if ($progress_percent > self::FINISHED_THRESHOLD_PERCENT || $learnedDuration < self::MIN_CONSIDERED_FINISHED_SECONDS) {
$progress_percent = 100;
}
return [ return [
'finished_count' => $finishedCount, 'finished_count' => $finishedCount,
'total_classes' => count($progressList), 'total_classes' => count($progressList),
'progress_percent' => $totalDuration > 0 ? round($learnedDuration / $totalDuration * 100) : 0, 'progress_percent' => min($progress_percent, 100), // 确保不超过100%
'classes' => $classProgress 'classes' => $classProgress
]; ];
} }
/** /**
* 获取课程最后学习时间 * 获取课程最后学习时间
*/ */
......
...@@ -16,7 +16,8 @@ class CourseValidate extends BaseValidate ...@@ -16,7 +16,8 @@ class CourseValidate extends BaseValidate
'work_id' => 'require|number', 'work_id' => 'require|number',
'content' => 'require', 'content' => 'require',
'comment_id' => 'require|number', 'comment_id' => 'require|number',
'reason' => 'require|length:1,255' 'reason' => 'require|length:1,255',
'pid'=>'require|number',
]; ];
protected $message = [ protected $message = [
......
...@@ -68,7 +68,7 @@ class Cert extends Model ...@@ -68,7 +68,7 @@ class Cert extends Model
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getCertList($category_id,$page,$pageSize,$type) public function getCertList($category_id,$page,$pageSize,$type,$searchKeyWords=null)
{ {
$where = ['is_sell' => 1, 'is_del' => 0]; $where = ['is_sell' => 1, 'is_del' => 0];
if ($category_id) { if ($category_id) {
...@@ -77,6 +77,11 @@ class Cert extends Model ...@@ -77,6 +77,11 @@ class Cert extends Model
$query = self::where($where); $query = self::where($where);
if ($searchKeyWords)
{
$query->where('title', 'like', '%' . $searchKeyWords . '%');
}
if ($type == 2) { if ($type == 2) {
$currentTime = time(); $currentTime = time();
$query->where('start_time', '<=', $currentTime) $query->where('start_time', '<=', $currentTime)
......
...@@ -87,16 +87,20 @@ class Course extends Model ...@@ -87,16 +87,20 @@ class Course extends Model
/**获取分类下的课程列表 /**获取分类下的课程列表
* *
*/ */
public function getCourseList($category_id,$page,$pageSize) public function getCourseList($category_id, $page, $pageSize, $searchKeyWords = null)
{ {
$where = ['status'=>3,'is_sell'=>1,'is_del'=>0]; $where = ['status' => 3, 'is_sell' => 1, 'is_del' => 0];
if ($category_id) if ($category_id) {
{
$where['cate_id'] = $category_id; $where['cate_id'] = $category_id;
} }
return self::where($where) $query = self::where($where);
->field('id,thumb,title,createtime,description,price,content')
if ($searchKeyWords) {
$query->where('title', 'like', '%' . $searchKeyWords . '%');
}
return $query->field('id,thumb,title,createtime,description,price,content')
->paginate([ ->paginate([
'page' => $page, 'page' => $page,
'list_rows' => $pageSize 'list_rows' => $pageSize
......
...@@ -51,14 +51,14 @@ class CourseCategory extends Model ...@@ -51,14 +51,14 @@ class CourseCategory extends Model
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
*/ */
public function getCourseCategoryList() public function getCourseCategoryList($pid = 0)
{ {
$where[] = ['is_del', '=', 0]; $where[] = ['is_del', '=', 0];
return $this->with(['children' => function($query) use($where) { return $this->with(['children' => function($query) use($where) {
$query->where($where); $query->where($where);
$query->order('sort', 'asc'); $query->order('sort', 'asc');
}]) }])
->where('pid', 0) ->where('pid', $pid)
->where($where) ->where($where)
->order('sort', 'asc') ->order('sort', 'asc')
->select(); ->select();
......
...@@ -46,7 +46,7 @@ class CourseUserWork extends Model ...@@ -46,7 +46,7 @@ class CourseUserWork extends Model
{ {
$detail = self::where(['id' => $id, 'is_del' => 0]) $detail = self::where(['id' => $id, 'is_del' => 0])
->with(['course', 'courseWork']) ->with(['course', 'courseWork'])
->field('id,user_id,work_id,status,course_id,createtime') ->field('id,user_id,work_id,status,course_id,createtime,attachment_ids,note')
->findOrEmpty(); ->findOrEmpty();
if ($detail->isEmpty()) { if ($detail->isEmpty()) {
...@@ -72,7 +72,6 @@ class CourseUserWork extends Model ...@@ -72,7 +72,6 @@ class CourseUserWork extends Model
$attachmentIds = !empty($detail['attachment_ids']) $attachmentIds = !empty($detail['attachment_ids'])
? (is_string($detail['attachment_ids']) ? explode(',', $detail['attachment_ids']) : (array)$detail['attachment_ids']) ? (is_string($detail['attachment_ids']) ? explode(',', $detail['attachment_ids']) : (array)$detail['attachment_ids'])
: []; : [];
$detail['attachment_file'] = !empty($attachmentIds) $detail['attachment_file'] = !empty($attachmentIds)
? SystemUploadFile::whereIn('fileid', $attachmentIds) ? SystemUploadFile::whereIn('fileid', $attachmentIds)
->field('fileurl,fileid,filename,filetype') ->field('fileurl,fileid,filename,filetype')
...@@ -98,7 +97,10 @@ class CourseUserWork extends Model ...@@ -98,7 +97,10 @@ class CourseUserWork extends Model
//关联作业 //关联作业
public function courseWork() public function courseWork()
{ {
return $this->hasOne(CourseWork::class, 'id', 'work_id')->append(['filelist'])->where('is_del', 0)->field('id,title,file_id_str'); return $this->hasOne(CourseWork::class, 'id', 'work_id')
// ->append(['filelist'])
->where('is_del', 0)
->field('id,title,file_id_str,content');
} }
//关联课程 //关联课程
......
...@@ -111,7 +111,7 @@ class Project extends Model ...@@ -111,7 +111,7 @@ class Project extends Model
return $statustxt; return $statustxt;
} }
public function getProjectList($category_id,$page,$pageSize,$type) public function getProjectList($category_id,$page,$pageSize,$type,$searchKeyWords = null)
{ {
$where = ['sh_status' => 2, 'status' => 1]; $where = ['sh_status' => 2, 'status' => 1];
...@@ -122,6 +122,11 @@ class Project extends Model ...@@ -122,6 +122,11 @@ class Project extends Model
$query = self::where($where); $query = self::where($where);
if ($searchKeyWords)
{
$query->where('title', 'like', '%' . $searchKeyWords . '%');
}
$query->order('createtime','desc'); $query->order('createtime','desc');
//热门项目 //热门项目
......
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