1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-28 05:11:39 +08:00

v1.4.4 preview

This commit is contained in:
koogua 2021-09-07 17:29:23 +08:00
parent c1d3a98620
commit b9d78da1ce
17 changed files with 96 additions and 76 deletions

View File

@ -55,11 +55,9 @@ class CourseUserList extends Builder
$result = [];
foreach ($courses->toArray() as $course) {
if ($course['deleted'] == 0) {
$course['cover'] = $baseUrl . $course['cover'];
$course['attrs'] = json_decode($course['attrs'], true);
$result[$course['id']] = $course;
}
$course['cover'] = $baseUrl . $course['cover'];
$course['attrs'] = json_decode($course['attrs'], true);
$result[$course['id']] = $course;
}
return $result;

View File

@ -36,6 +36,11 @@ class ResourceList extends Builder
$result = [];
foreach ($uploads->toArray() as $upload) {
$id = $this->crypt->encryptBase64($upload['id'], null, true);
$upload['url'] = $this->url->get(['for' => 'home.download', 'id' => $id]);
$result[$upload['id']] = $upload;
}

View File

@ -17,6 +17,7 @@ use App\Models\Trade as TradeModel;
use App\Repos\Course as CourseRepo;
use App\Repos\ImGroup as ImGroupRepo;
use App\Repos\ImGroupUser as ImGroupUserRepo;
use App\Repos\ImUser as ImUserRepo;
use App\Repos\Order as OrderRepo;
use App\Repos\User as UserRepo;
use App\Services\Logic\Notice\OrderFinish as OrderFinishNotice;
@ -134,9 +135,7 @@ class DeliverTask extends Task
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->source_type = CourseUserModel::SOURCE_CHARGE;
if ($courseUser->create() === false) {
throw new \RuntimeException('Create Course User Failed');
}
$courseUser->create();
$courseRepo = new CourseRepo();
@ -150,6 +149,10 @@ class DeliverTask extends Task
$group = $groupRepo->findByCourseId($course->id);
$imUserRepo = new ImUserRepo();
$imUser = $imUserRepo->findById($order->owner_id);
$groupUserRepo = new ImGroupUserRepo();
$groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id);
@ -160,10 +163,13 @@ class DeliverTask extends Task
$groupUser->group_id = $group->id;
$groupUser->user_id = $order->owner_id;
$groupUser->create();
if ($groupUser->create() === false) {
throw new \RuntimeException('Create Group User Failed');
}
$imUser->group_count += 1;
$imUser->update();
$group->user_count += 1;
$group->update();
}
}
@ -181,9 +187,7 @@ class DeliverTask extends Task
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->source_type = CourseUserModel::SOURCE_CHARGE;
if ($courseUser->create() === false) {
throw new \RuntimeException('Create Course User Failed');
}
$courseUser->create();
$courseRepo = new CourseRepo();
@ -197,6 +201,10 @@ class DeliverTask extends Task
$group = $groupRepo->findByCourseId($course->id);
$imUserRepo = new ImUserRepo();
$imUser = $imUserRepo->findById($order->owner_id);
$groupUserRepo = new ImGroupUserRepo();
$groupUser = $groupUserRepo->findGroupUser($group->id, $order->owner_id);
@ -207,10 +215,13 @@ class DeliverTask extends Task
$groupUser->group_id = $group->id;
$groupUser->user_id = $order->owner_id;
$groupUser->create();
if ($groupUser->create() === false) {
throw new \RuntimeException('Create Group User Failed');
}
$imUser->group_count += 1;
$imUser->update();
$group->user_count += 1;
$group->update();
}
}
}
@ -224,11 +235,10 @@ class DeliverTask extends Task
$user = $userRepo->findById($order->owner_id);
$user->vip_expiry_time = $itemInfo['vip']['expiry_time'];
$user->vip = 1;
if ($user->update() === false) {
throw new \RuntimeException('Update Vip Expiry Failed');
}
$user->update();
}
protected function handleOrderConsumePoint(OrderModel $order)

View File

@ -23,8 +23,6 @@ class VodEventTask extends Task
$handles = [];
$count = 0;
foreach ($events as $event) {
$handles[] = $event['EventHandle'];
@ -36,10 +34,6 @@ class VodEventTask extends Task
} elseif ($event['EventType'] == 'FileDeleted') {
$this->handleFileDeletedEvent($event);
}
$count++;
if ($count >= 12) break;
}
$this->confirmEvents($handles);

View File

@ -124,6 +124,20 @@ class Resource extends Service
$chapter->resource_count = $chapterRepo->countResources($chapter->id);
$chapter->update();
$parent = $chapterRepo->findById($chapter->parent_id);
$lessons = $chapterRepo->findLessons($parent->id);
$resourceCount = 0;
foreach ($lessons as $lesson) {
$resourceCount += $chapterRepo->countResources($lesson->id);
}
$parent->resource_count = $resourceCount;
$parent->update();
}
protected function recountCourseResources(CourseModel $course)

View File

@ -103,7 +103,7 @@ class Student extends Service
$data['user_id'] = $user->id;
$data['expiry_time'] = $expiryTime;
$validator->checkIfJoined($post['course_id'], $post['user_id']);
$validator->checkIfImported($post['course_id'], $post['user_id']);
$courseUser = new CourseUserModel();

View File

@ -7,12 +7,12 @@
namespace App\Http\Api\Controllers;
use App\Services\Logic\Article\CommentList as CommentListService;
use App\Services\Logic\Chapter\ChapterInfo as ChapterInfoService;
use App\Services\Logic\Chapter\ChapterLike as ChapterLikeService;
use App\Services\Logic\Chapter\ConsultList as ChapterConsultListService;
use App\Services\Logic\Chapter\Learning as ChapterLearningService;
use App\Services\Logic\Chapter\ResourceList as ChapterResourceListService;
use App\Services\Logic\Chapter\CommentList as CommentListService;
use App\Services\Logic\Chapter\ConsultList as ConsultListService;
use App\Services\Logic\Chapter\Learning as LearningService;
use App\Services\Logic\Chapter\ResourceList as ResourceListService;
/**
* @RoutePrefix("/api/chapter")
@ -37,7 +37,7 @@ class ChapterController extends Controller
*/
public function consultsAction($id)
{
$service = new ChapterConsultListService();
$service = new ConsultListService();
$pager = $service->handle($id);
@ -49,7 +49,7 @@ class ChapterController extends Controller
*/
public function resourcesAction($id)
{
$service = new ChapterResourceListService();
$service = new ResourceListService();
$resources = $service->handle($id);
@ -91,7 +91,7 @@ class ChapterController extends Controller
*/
public function learningAction($id)
{
$service = new ChapterLearningService();
$service = new LearningService();
$service->handle($id);

View File

@ -25,13 +25,15 @@ class PublicController extends \Phalcon\Mvc\Controller
use SecurityTrait;
/**
* @Get("/download/{md5}", name="home.download")
* @Get("/download/{id}", name="home.download")
*/
public function downloadAction($md5)
public function downloadAction($id)
{
$id = $this->crypt->decryptBase64($id, null, true);
$repo = new UploadRepo();
$file = $repo->findByMd5($md5);
$file = $repo->findById($id);
if ($file) {

View File

@ -9,11 +9,10 @@
<th width="15%">操作</th>
</tr>
{% for item in items %}
{% set download_url = url({'for':'home.download','md5':item.md5}) %}
<tr>
<td>{{ item.name }}</td>
<td>{{ item.size|human_size }}</td>
<td><a class="layui-btn layui-btn-sm" href="{{ download_url }}" target="_blank">下载</a></td>
<td><a class="layui-btn layui-btn-sm" href="{{ item.url }}" target="_blank">下载</a></td>
</tr>
{% endfor %}
</table>

View File

@ -34,8 +34,8 @@
<div class="course-tab-wrap wrap">
<div class="layui-tab layui-tab-brief course-tab">
<ul class="layui-tab-title">
<li class="layui-this">目录</li>
<li>详情</li>
<li class="layui-this">详情</li>
<li>目录</li>
{% if show_tab_packages %}
<li>套餐<span class="tab-count">{{ course.package_count }}</span></li>
{% endif %}
@ -48,10 +48,10 @@
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
{{ partial('course/show_catalog') }}
<div class="course-details markdown-body">{{ course.details }}</div>
</div>
<div class="layui-tab-item">
<div class="course-details markdown-body">{{ course.details }}</div>
{{ partial('course/show_catalog') }}
</div>
{% if show_tab_packages %}
{% set packages_url = url({'for':'home.course.packages','id':course.id}) %}

View File

@ -42,7 +42,7 @@
{% endif %}
{% if auth_user.id > 0 %}
<li class="layui-nav-item">
<a href="javascript:">创建</a>
<a href="javascript:"><i class="layui-icon layui-icon-add-circle"></i> 发布</a>
<dl class="layui-nav-child">
<dd><a href="{{ url({'for':'home.question.add'}) }}" target="_blank">提问题</a></dd>
<dd><a href="{{ url({'for':'home.article.add'}) }}" target="_blank">写文章</a></dd>

View File

@ -78,6 +78,18 @@ class Chapter extends Repository
->execute();
}
/**
* @param int $id
* @return ResultsetInterface|Resultset|ChapterModel[]
*/
public function findLessons($id)
{
return ChapterModel::query()
->where('parent_id = :parent_id:', ['parent_id' => $id])
->andWhere('deleted = 0')
->execute();
}
/**
* @param string $fileId
* @return ChapterModel|Model|bool

View File

@ -64,7 +64,12 @@ class ConsultCreate extends LogicService
$validator = new ConsultValidator();
$question = $validator->checkQuestion($post['question']);
$private = $validator->checkPrivateStatus($post['private']);
$private = 0;
if (isset($post['private'])) {
$private = $validator->checkPrivateStatus($post['private']);
}
$validator->checkIfDuplicated($course->id, $user->id, $question);
@ -101,7 +106,12 @@ class ConsultCreate extends LogicService
$validator = new ConsultValidator();
$question = $validator->checkQuestion($post['question']);
$private = $validator->checkPrivateStatus($post['private']);
$private = 0;
if (isset($post['private'])) {
$private = $validator->checkPrivateStatus($post['private']);
}
$validator->checkIfDuplicated($course->id, $user->id, $question);

View File

@ -205,7 +205,7 @@ class Chapter extends Validator
if ($attrs['word_count'] == 0) {
throw new BadRequestException('chapter.read_not_ready');
}
} elseif ($chapter->model == CourseModel::MODEL_READ) {
} elseif ($chapter->model == CourseModel::MODEL_OFFLINE) {
if ($attrs['start_time'] == 0) {
throw new BadRequestException('chapter.offline_time_empty');
}

View File

@ -246,29 +246,6 @@ class Course extends Validator
if ($course->teacher_id == 0) {
throw new BadRequestException('course.teacher_not_assigned');
}
$courseRepo = new CourseRepo();
$chapters = $courseRepo->findChapters($course->id);
$totalCount = $publishedCount = 0;
foreach ($chapters as $chapter) {
if ($chapter->parent_id > 0 && $chapter->published == 1) {
$publishedCount++;
}
if ($chapter->parent_id > 0) {
$totalCount++;
}
}
if ($publishedCount == 0) {
throw new BadRequestException('course.pub_chapter_not_found');
}
if ($publishedCount / $totalCount < 0.2) {
throw new BadRequestException('course.pub_chapter_not_enough');
}
}
}

View File

@ -9,6 +9,7 @@ namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validators\Common as CommonValidator;
use App\Models\CourseUser as CourseUserModel;
use App\Repos\CourseUser as CourseUserRepo;
class CourseUser extends Validator
@ -65,14 +66,14 @@ class CourseUser extends Validator
return strtotime($value);
}
public function checkIfJoined($courseId, $userId)
public function checkIfImported($courseId, $userId)
{
$repo = new CourseUserRepo();
$courseUser = $repo->findCourseStudent($courseId, $userId);
if ($courseUser) {
throw new BadRequestException('course_user.has_joined');
if ($courseUser && $courseUser->source_type == CourseUserModel::SOURCE_IMPORT) {
throw new BadRequestException('course_user.has_imported');
}
}

View File

@ -184,8 +184,6 @@ $error['course.invalid_refund_expiry'] = '无效的退款期限';
$error['course.invalid_feature_status'] = '无效的推荐状态';
$error['course.invalid_publish_status'] = '无效的发布状态';
$error['course.teacher_not_assigned'] = '尚未指定授课教师';
$error['course.pub_chapter_not_found'] = '尚未发现已发布的课时';
$error['course.pub_chapter_not_enough'] = '已发布的课时太少小于20%';
/**
* 面授课程相关
@ -240,7 +238,7 @@ $error['package.invalid_expiry'] = '无效的期限范围1~60';
$error['course_user.not_found'] = '课程学员关系不存在';
$error['course_user.invalid_expiry_time'] = '无效的过期时间';
$error['course_user.review_not_allowed'] = '当前不允许评价课程';
$error['course_user.has_joined'] = '已经加入过该课程';
$error['course_user.has_imported'] = '已经加入过该课程';
$error['course_user.has_reviewed'] = '已经评价过该课程';
/**