You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.6 KiB
79 lines
2.6 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\api\controller\apiController;
|
|
|
|
use app\Request;
|
|
use app\service\api\apiService\StudentCourseService;
|
|
use core\base\BaseApiService;
|
|
|
|
/**
|
|
* 学员课程相关接口
|
|
* Class StudentCourse
|
|
* @package app\api\controller\apiController
|
|
*/
|
|
class StudentCourse extends BaseApiService
|
|
{
|
|
/**
|
|
* 获取课程详情
|
|
* @param Request $request
|
|
* @return \think\Response
|
|
*/
|
|
public function courseDetail(Request $request)
|
|
{
|
|
$course_id = $request->param('course_id', '');
|
|
$resource_id = $request->param('resource_id', '');
|
|
|
|
if (empty($course_id)) {
|
|
return fail('课程ID不能为空');
|
|
}
|
|
|
|
// 如果没有传resource_id,尝试从当前登录用户获取
|
|
if (empty($resource_id)) {
|
|
// 这里需要根据实际情况获取当前学员的resource_id
|
|
// 可能需要从member_id获取对应的resource_id
|
|
$resource_id = $this->getResourceIdByMemberId($this->member_id);
|
|
}
|
|
|
|
if (empty($resource_id)) {
|
|
return fail('资源ID不能为空');
|
|
}
|
|
|
|
$where = [
|
|
'course_id' => $course_id,
|
|
'resource_id' => $resource_id
|
|
];
|
|
|
|
try {
|
|
$res = (new StudentCourseService())->getCourseDetail($where);
|
|
if (!$res['code']) {
|
|
return fail($res['msg']);
|
|
}
|
|
|
|
return success($res['data']);
|
|
} catch (\Exception $e) {
|
|
return fail('获取课程详情失败:' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据会员ID获取资源ID
|
|
* @param int $member_id
|
|
* @return int|string
|
|
*/
|
|
private function getResourceIdByMemberId($member_id)
|
|
{
|
|
// 这里根据实际业务逻辑实现
|
|
// 从customer_resources表中根据member_id获取resource_id
|
|
$customerResource = \app\model\customer_resources\CustomerResources::where('member_id', $member_id)->find();
|
|
return $customerResource ? $customerResource->id : '';
|
|
}
|
|
}
|