mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-25 04:07:17 +08:00
删除多余文件
This commit is contained in:
parent
d8a1c1474b
commit
2195904e65
@ -1,87 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2023 深圳市酷瓜软件有限公司
|
|
||||||
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
||||||
* @link https://www.koogua.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Console\Migrations;
|
|
||||||
|
|
||||||
use App\Models\ChapterUser as ChapterUserModel;
|
|
||||||
use App\Models\CourseUser as CourseUserModel;
|
|
||||||
use Phalcon\Mvc\Model\ResultsetInterface;
|
|
||||||
|
|
||||||
class V20231201101515 extends Migration
|
|
||||||
{
|
|
||||||
|
|
||||||
public function run()
|
|
||||||
{
|
|
||||||
$this->handleCourseUsers();
|
|
||||||
$this->handleChapterUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function handleCourseUsers()
|
|
||||||
{
|
|
||||||
$courseUsers = $this->findCourseUsers();
|
|
||||||
|
|
||||||
if ($courseUsers->count() == 0) return;
|
|
||||||
|
|
||||||
$mappings = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 只保留第一条记录
|
|
||||||
*/
|
|
||||||
foreach ($courseUsers as $courseUser) {
|
|
||||||
$key = $courseUser->course_id . '-' . $courseUser->user_id;
|
|
||||||
if (!isset($mappings[$key])) {
|
|
||||||
$mappings[$key] = 1;
|
|
||||||
} else {
|
|
||||||
$courseUser->deleted = 1;
|
|
||||||
$courseUser->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function handleChapterUsers()
|
|
||||||
{
|
|
||||||
$chapterUsers = $this->findChapterUsers();
|
|
||||||
|
|
||||||
if ($chapterUsers->count() == 0) return;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 只保留第一条记录
|
|
||||||
*/
|
|
||||||
foreach ($chapterUsers as $chapterUser) {
|
|
||||||
$key = $chapterUser->chapter_id . '-' . $chapterUser->user_id;
|
|
||||||
if (!isset($mappings[$key])) {
|
|
||||||
$mappings[$key] = 1;
|
|
||||||
} else {
|
|
||||||
$chapterUser->deleted = 1;
|
|
||||||
$chapterUser->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return ResultsetInterface|CourseUserModel[]
|
|
||||||
*/
|
|
||||||
protected function findCourseUsers()
|
|
||||||
{
|
|
||||||
return CourseUserModel::query()
|
|
||||||
->where('deleted = 0')
|
|
||||||
->orderBy('id DESC')
|
|
||||||
->execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return ResultsetInterface|ChapterUserModel[]
|
|
||||||
*/
|
|
||||||
protected function findChapterUsers()
|
|
||||||
{
|
|
||||||
return ChapterUserModel::query()
|
|
||||||
->where('deleted = 0')
|
|
||||||
->orderBy('id DESC')
|
|
||||||
->execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ namespace App\Repos;
|
|||||||
|
|
||||||
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
||||||
use App\Models\Consult as ConsultModel;
|
use App\Models\Consult as ConsultModel;
|
||||||
use App\Models\CourseUser as CourseUserModel;
|
use App\Models\Course as CourseModel;
|
||||||
|
|
||||||
class TeacherConsult extends Repository
|
class TeacherConsult extends Repository
|
||||||
{
|
{
|
||||||
@ -17,35 +17,34 @@ class TeacherConsult extends Repository
|
|||||||
public function paginate($where, $sort = 'latest', $page = 1, $limit = 15)
|
public function paginate($where, $sort = 'latest', $page = 1, $limit = 15)
|
||||||
{
|
{
|
||||||
$builder = $this->modelsManager->createBuilder()
|
$builder = $this->modelsManager->createBuilder()
|
||||||
->columns('c.*')
|
->columns('consult.*')
|
||||||
->addFrom(ConsultModel::class, 'c')
|
->addFrom(ConsultModel::class, 'consult')
|
||||||
->join(CourseUserModel::class, 'c.course_id = cu.course_id', 'cu')
|
->join(CourseModel::class, 'consult.course_id = course.id', 'course')
|
||||||
->where('1 = 1');
|
->where('1 = 1');
|
||||||
|
|
||||||
if (!empty($where['user_id'])) {
|
if (!empty($where['teacher_id'])) {
|
||||||
$builder->andWhere('cu.user_id = :user_id:', ['user_id' => $where['user_id']]);
|
$builder->andWhere('course.teacher_id = :teacher_id:', ['teacher_id' => $where['teacher_id']]);
|
||||||
$builder->andWhere('cu.role_type = :role_type:', ['role_type' => CourseUserModel::ROLE_TEACHER]);
|
$builder->andWhere('course.published = 1');
|
||||||
$builder->andWhere('cu.deleted = 0');
|
$builder->andWhere('course.deleted = 0');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($where['replied'])) {
|
if (isset($where['replied'])) {
|
||||||
if ($where['replied'] == 1) {
|
if ($where['replied'] == 1) {
|
||||||
$builder->andWhere('c.reply_time > 0');
|
$builder->andWhere('consult.reply_time > 0');
|
||||||
} else {
|
} else {
|
||||||
$builder->andWhere('c.reply_time = 0');
|
$builder->andWhere('consult.reply_time = 0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$builder->andWhere('c.published = :published:', ['published' => ConsultModel::PUBLISH_APPROVED]);
|
$builder->andWhere('consult.published = :published:', ['published' => ConsultModel::PUBLISH_APPROVED]);
|
||||||
|
$builder->andWhere('consult.deleted = 0');
|
||||||
$builder->andWhere('c.deleted = 0');
|
|
||||||
|
|
||||||
switch ($sort) {
|
switch ($sort) {
|
||||||
case 'oldest':
|
case 'oldest':
|
||||||
$orderBy = 'c.id ASC';
|
$orderBy = 'consult.id ASC';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$orderBy = 'c.id DESC';
|
$orderBy = 'consult.id DESC';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
|
|
||||||
* @license https://opensource.org/licenses/GPL-2.0
|
|
||||||
* @link https://www.koogua.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Repos;
|
|
||||||
|
|
||||||
use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder;
|
|
||||||
use App\Models\Course as CourseModel;
|
|
||||||
use App\Models\CourseUser as CourseUserModel;
|
|
||||||
|
|
||||||
class TeacherCourse extends Repository
|
|
||||||
{
|
|
||||||
|
|
||||||
public function paginate($userId, $page = 1, $limit = 15)
|
|
||||||
{
|
|
||||||
|
|
||||||
$builder = $this->modelsManager->createBuilder()
|
|
||||||
->columns('course.*')
|
|
||||||
->addFrom(CourseModel::class, 'course')
|
|
||||||
->join(CourseUserModel::class, 'course.id = cu.course_id', 'cu')
|
|
||||||
->where('cu.user_id = :user_id:', ['user_id' => $userId])
|
|
||||||
->andWhere('cu.role_type = :role_type:', ['role_type' => CourseUserModel::ROLE_TEACHER])
|
|
||||||
->andWhere('course.published = 1')
|
|
||||||
->andWhere('course.deleted = 0')
|
|
||||||
->orderBy('cu.id DESC');
|
|
||||||
|
|
||||||
$pager = new PagerQueryBuilder([
|
|
||||||
'builder' => $builder,
|
|
||||||
'page' => $page,
|
|
||||||
'limit' => $limit,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $pager->paginate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user