1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 04:01:31 +08:00

修复没有生成MaxImGroupId的问题,增加课程默认群主的逻辑

This commit is contained in:
xiaochong0302 2020-12-14 16:16:25 +08:00
parent d60d748c28
commit 6f955bff84
3 changed files with 51 additions and 11 deletions

View File

@ -15,12 +15,14 @@ use App\Models\CourseRating as CourseRatingModel;
use App\Models\CourseRelated as CourseRelatedModel;
use App\Models\CourseUser as CourseUserModel;
use App\Models\ImGroup as ImGroupModel;
use App\Models\ImGroupUser as ImGroupUserModel;
use App\Repos\Category as CategoryRepo;
use App\Repos\Chapter as ChapterRepo;
use App\Repos\Course as CourseRepo;
use App\Repos\CourseCategory as CourseCategoryRepo;
use App\Repos\CourseRelated as CourseRelatedRepo;
use App\Repos\CourseUser as CourseUserRepo;
use App\Repos\ImGroup as ImGroupRepo;
use App\Repos\User as UserRepo;
use App\Services\Sync\CourseIndex as CourseIndexSync;
use App\Validators\Course as CourseValidator;
@ -94,6 +96,7 @@ class Course extends Service
$imGroup = new ImGroupModel();
$imGroup->type = ImGroupModel::TYPE_COURSE;
$imGroup->course_id = $course->id;
$imGroup->name = $course->title;
$imGroup->about = $course->summary;
@ -190,6 +193,8 @@ class Course extends Service
$course->update($data);
$this->updateImGroup($course);
return $course;
}
@ -199,6 +204,12 @@ class Course extends Service
$course->deleted = 1;
$course->update();
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($course->id);
$group->deleted = 1;
$group->update();
return $course;
}
@ -208,6 +219,12 @@ class Course extends Service
$course->deleted = 0;
$course->update();
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($course->id);
$group->deleted = 0;
$group->update();
return $course;
}
@ -545,6 +562,32 @@ class Course extends Service
$cache->rebuild($course->id);
}
protected function updateImGroup(CourseModel $course)
{
$groupRepo = new ImGroupRepo();
$group = $groupRepo->findByCourseId($course->id);
$data = [];
if ($course->title != $group->name) {
$data['name'] = $course->title;
}
if ($course->teacher_id > 0 && $group->owner_id == 0) {
$groupUser = new ImGroupUserModel();
$groupUser->group_id = $group->id;
$groupUser->user_id = $course->teacher_id;
$groupUser->create();
$data['owner_id'] = $course->teacher_id;
$data['user_count'] = $group->user_count + 1;
}
$group->update($data);
}
protected function handleCourses($pager)
{
if ($pager->total_items > 0) {

View File

@ -326,17 +326,6 @@ class Course extends Model
$cache->rebuild();
}
public function afterUpdate()
{
/**
* 群组名称和课程标题保持一致
*/
if ($this->hasUpdated('title')) {
$imGroup = ImGroup::findFirst(['course_id' => $this->id]);
$imGroup->update(['name' => $this->title]);
}
}
public function afterFetch()
{
$this->market_price = (float)$this->market_price;

View File

@ -2,6 +2,7 @@
namespace App\Models;
use App\Caches\MaxImGroupId as MaxImGroupIdCache;
use App\Services\Sync\GroupIndex as GroupIndexSync;
use Phalcon\Mvc\Model\Behavior\SoftDelete;
use Phalcon\Text;
@ -153,6 +154,13 @@ class ImGroup extends Model
$this->update_time = time();
}
public function afterCreate()
{
$cache = new MaxImGroupIdCache();
$cache->rebuild();
}
public function afterFetch()
{
if (!Text::startsWith($this->avatar, 'http')) {