Commit bd67e1a2 authored by wangzhengwen's avatar wangzhengwen

作业我的课程修改

parent ceaa7084
...@@ -35,6 +35,23 @@ class CourseProgress extends BaseController ...@@ -35,6 +35,23 @@ class CourseProgress extends BaseController
$data = Request::only(['course_id', 'class_id', 'current_time']); $data = Request::only(['course_id', 'class_id', 'current_time']);
$userId = $this->request->userId; $userId = $this->request->userId;
// 获取课程信息
$course = CourseModel::where([
'id' => $data['course_id'],
'status' => 3,
'is_sell' => 1,
'is_del' => 0
])->find();
if (!$course) {
return $this->returnMsg('课程不存在');
}
// 验证购买状态(1表示视频类型)添加作业不验证试看
if ($course['price'] > 0 && !UtilService::checkPurchase($userId, $data['course_id'], 1,0)) {
return $this->returnMsg('操作成功', 1);
}
$result = CourseProgressService::updateProgress( $result = CourseProgressService::updateProgress(
$userId, $userId,
$data['course_id'], $data['course_id'],
...@@ -91,36 +108,36 @@ class CourseProgress extends BaseController ...@@ -91,36 +108,36 @@ class CourseProgress extends BaseController
public function addUserWork() public function addUserWork()
{ {
return $this->returnMsg('操作成功',1); // return $this->returnMsg('操作成功',1);
// $vo = (new CourseValidate())->goCheck(['course_id']); $vo = (new CourseValidate())->goCheck(['course_id']);
// if ($vo !== true) { if ($vo !== true) {
// return $vo; return $vo;
// } }
//
// $userId = $this->request->userId; $userId = $this->request->userId;
// $data = Request::only(['course_id']); $data = Request::only(['course_id']);
//
// // 获取课程信息 // 获取课程信息
// $course = CourseModel::where([ $course = CourseModel::where([
// 'id' => $data['course_id'], 'id' => $data['course_id'],
// 'status' => 3, 'status' => 3,
// 'is_sell' => 1, 'is_sell' => 1,
// 'is_del' => 0 'is_del' => 0
// ])->find(); ])->find();
//
// if (!$course) { if (!$course) {
// return $this->returnMsg('课程不存在'); return $this->returnMsg('课程不存在');
// } }
//
// // 验证购买状态(1表示视频类型) // 验证购买状态(1表示视频类型)添加作业不验证试看
// if ($course['price'] > 0 && !UtilService::checkPurchase($userId, $data['course_id'], 1)) { if ($course['price'] > 0 && !UtilService::checkPurchase($userId, $data['course_id'], 1,0)) {
// return $this->returnMsg('课程未购买', 202); return $this->returnMsg('操作成功', 1);
// } }
//
// $userWork = CourseProgressService::addUserWork($userId, $data['course_id']); $userWork = CourseProgressService::addUserWork($userId, $data['course_id']);
//
// return $this->returnMsg('操作成功',1,$userWork); return $this->returnMsg('操作成功',1,$userWork);
} }
//视频播放 //视频播放
...@@ -156,7 +173,7 @@ class CourseProgress extends BaseController ...@@ -156,7 +173,7 @@ class CourseProgress extends BaseController
CourseClass::where('id', $class_id)->inc('tvclick')->update(); CourseClass::where('id', $class_id)->inc('tvclick')->update();
//添加作业 //添加作业
CourseProgressService::addUserWork($userId, $courseId); // CourseProgressService::addUserWork($userId, $courseId);
return $this->returnMsg('操作成功', 1); return $this->returnMsg('操作成功', 1);
} }
......
...@@ -6,6 +6,7 @@ use app\model\CourseClass; ...@@ -6,6 +6,7 @@ use app\model\CourseClass;
use app\model\CourseProgress; use app\model\CourseProgress;
use app\model\CourseUserWork; use app\model\CourseUserWork;
use app\model\CourseWork; use app\model\CourseWork;
use app\model\Payment;
class CourseProgressService class CourseProgressService
{ {
...@@ -95,8 +96,9 @@ class CourseProgressService ...@@ -95,8 +96,9 @@ class CourseProgressService
{ {
$workIds = CourseWork::where([ $workIds = CourseWork::where([
'user_id' => $userId, // 'user_id' => $userId,
'course_id' => $courseId, 'course_id' => $courseId,
'is_del'=>0
])->column('id'); ])->column('id');
if (empty($workIds)) { if (empty($workIds)) {
...@@ -140,6 +142,9 @@ class CourseProgressService ...@@ -140,6 +142,9 @@ class CourseProgressService
$courseIds = CourseProgress::where('user_id', $userId) $courseIds = CourseProgress::where('user_id', $userId)
->distinct(true) ->distinct(true)
->column('course_id'); ->column('course_id');
//获取所有已购买的课程id
$buyCourseIds = Payment::where(['user_id' => $userId,'pay_status'=>1,'order_type'=>1])->column('order_id');
$courseIds = array_unique(array_merge($courseIds, $buyCourseIds));
// 如果没有学习记录,返回空分页 // 如果没有学习记录,返回空分页
if (empty($courseIds)) { if (empty($courseIds)) {
......
...@@ -107,14 +107,15 @@ class UtilService ...@@ -107,14 +107,15 @@ class UtilService
* @param int $userId 用户ID * @param int $userId 用户ID
* @param int $productId 产品ID * @param int $productId 产品ID
* @param int $orderType 订单类型(1:视频 2:证书) * @param int $orderType 订单类型(1:视频 2:证书)
* @param int $isCheckSk 验证试看(0:不验证 1:验证) 添加作业,上报进度不验证
*/ */
public static function checkPurchase($userId, $productId, $orderType) public static function checkPurchase($userId, $productId, $orderType,$isCheckSk=1)
{ {
//如果是课程课时存在试看的情况下 //如果是课程课时存在试看的情况下
if($orderType==1) if($orderType==1 and $isCheckSk==1)
{ {
$course_class_id = input('course_class'); // 尝试从多个可能的参数名获取课时ID
$course_class_id = input('course_class', input('class_id', 0)); // 后备参数名
if ($course_class_id) if ($course_class_id)
{ {
$is_sk = CourseClass::where(['course_id'=>$productId,'id'=>$course_class_id])->value('is_sk'); $is_sk = CourseClass::where(['course_id'=>$productId,'id'=>$course_class_id])->value('is_sk');
...@@ -126,10 +127,10 @@ class UtilService ...@@ -126,10 +127,10 @@ class UtilService
} }
return Payment::where([ return Payment::where([
'user_id' => $userId, 'user_id' => $userId,
'order_type' => $orderType, 'order_type' => $orderType,
'pay_status' => 1, 'pay_status' => 1,
'order_id' => $productId 'order_id' => $productId
])->count(); ])->count();
} }
} }
\ No newline at end of file
...@@ -18,6 +18,7 @@ class AdvertCate extends Model ...@@ -18,6 +18,7 @@ class AdvertCate extends Model
{ {
return $this->hasMany(Advert::class, 'p_id', 'id') return $this->hasMany(Advert::class, 'p_id', 'id')
->where('is_del',0) ->where('is_del',0)
->where('is_show',1)
->field('id,name,type,url,p_id,url,cover_img_id') ->field('id,name,type,url,p_id,url,cover_img_id')
->order('sort desc'); ->order('sort 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