1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-16 21:26:13 +08:00

1.去除模型中删除关联发布操作

2.整理查询逻辑
This commit is contained in:
koogua 2021-10-06 17:01:49 +08:00
parent 8cfcc74b2a
commit d94001a4a4
114 changed files with 708 additions and 380 deletions

View File

@ -58,7 +58,7 @@ class AnswerList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -71,7 +71,7 @@ class ArticleList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -69,6 +69,7 @@ class CategoryTreeList extends Builder
$query->where('parent_id = 0'); $query->where('parent_id = 0');
$query->andWhere('published = 1'); $query->andWhere('published = 1');
$query->andWhere('deleted = 0');
$query->andWhere('type = :type:', ['type' => $type]); $query->andWhere('type = :type:', ['type' => $type]);
$query->orderBy('priority ASC'); $query->orderBy('priority ASC');
@ -84,6 +85,7 @@ class CategoryTreeList extends Builder
$query = CategoryModel::query(); $query = CategoryModel::query();
$query->where('published = 1'); $query->where('published = 1');
$query->where('deleted = 0');
$query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]); $query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]);
$query->orderBy('priority ASC'); $query->orderBy('priority ASC');

View File

@ -32,7 +32,7 @@ class CommentList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -79,7 +79,7 @@ class ConsultList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -62,7 +62,7 @@ class CourseList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -87,7 +87,7 @@ class DanmuList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -29,7 +29,7 @@ class ImMessageList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -48,7 +48,7 @@ class LiveList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($teacherIds, ['id', 'name', 'title', 'avatar', 'about']); $users = $userRepo->findShallowUserByIds($teacherIds);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -68,6 +68,7 @@ class NavTreeList extends Builder
return NavModel::query() return NavModel::query()
->where('parent_id = :parent_id:', ['parent_id' => $navId]) ->where('parent_id = :parent_id:', ['parent_id' => $navId])
->andWhere('published = 1') ->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->execute(); ->execute();
} }
@ -80,7 +81,9 @@ class NavTreeList extends Builder
{ {
return NavModel::query() return NavModel::query()
->where('position = :position:', ['position' => $position]) ->where('position = :position:', ['position' => $position])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->execute(); ->execute();
} }

View File

@ -32,7 +32,7 @@ class NotificationList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -186,7 +186,7 @@ class OrderList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name']); $users = $userRepo->findShallowUserByIds($ids);
$result = []; $result = [];

View File

@ -72,7 +72,7 @@ class QuestionFavoriteList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -74,7 +74,7 @@ class QuestionList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -58,11 +58,14 @@ class RefundList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url();
$result = []; $result = [];
foreach ($users->toArray() as $user) { foreach ($users->toArray() as $user) {
$user['avatar'] = $baseUrl . $user['avatar'];
$result[$user['id']] = $user; $result[$user['id']] = $user;
} }

View File

@ -29,7 +29,7 @@ class ReportList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -58,7 +58,7 @@ class ReviewList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url(); $baseUrl = kg_cos_url();

View File

@ -58,11 +58,14 @@ class TradeList extends Builder
$userRepo = new UserRepo(); $userRepo = new UserRepo();
$users = $userRepo->findByIds($ids, ['id', 'name']); $users = $userRepo->findShallowUserByIds($ids);
$baseUrl = kg_cos_url();
$result = []; $result = [];
foreach ($users->toArray() as $user) { foreach ($users->toArray() as $user) {
$user['avatar'] = $baseUrl . $user['avatar'];
$result[$user['id']] = $user; $result[$user['id']] = $user;
} }

View File

@ -38,6 +38,7 @@ class CategoryList extends Cache
->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path']) ->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path'])
->where('type = :type:', ['type' => $type]) ->where('type = :type:', ['type' => $type])
->andWhere('published = 1') ->andWhere('published = 1')
->andWhere('deleted = 0')
->execute(); ->execute();
if ($categories->count() == 0) { if ($categories->count() == 0) {

View File

@ -70,7 +70,9 @@ class CourseRecommendedList extends Cache
public function findCourses($limit = 5) public function findCourses($limit = 5)
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1 AND market_price > 0') ->where('market_price > 0')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('RAND()') ->orderBy('RAND()')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -51,6 +51,7 @@ class CourseTeacherList extends Cache
'id' => $user->id, 'id' => $user->id,
'name' => $user->name, 'name' => $user->name,
'avatar' => $user->avatar, 'avatar' => $user->avatar,
'vip' => $user->vip,
'title' => $user->title, 'title' => $user->title,
'about' => $user->about, 'about' => $user->about,
]; ];

View File

@ -73,7 +73,9 @@ class HelpList extends Cache
{ {
return CategoryModel::query() return CategoryModel::query()
->where('type = :type:', ['type' => CategoryModel::TYPE_HELP]) ->where('type = :type:', ['type' => CategoryModel::TYPE_HELP])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->execute(); ->execute();
} }
@ -87,6 +89,7 @@ class HelpList extends Cache
return HelpModel::query() return HelpModel::query()
->where('category_id = :category_id:', ['category_id' => $categoryId]) ->where('category_id = :category_id:', ['category_id' => $categoryId])
->andWhere('published = 1') ->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->execute(); ->execute();
} }

View File

@ -111,7 +111,8 @@ class HotQuestionList extends Cache
{ {
return QuestionModel::query() return QuestionModel::query()
->where('create_time > :create_time:', ['create_time' => $createTime]) ->where('create_time > :create_time:', ['create_time' => $createTime])
->andWhere('published = 1 AND deleted = 0') ->andWhere('published = :published:', ['published' => QuestionModel::PUBLISH_APPROVED])
->andWhere('deleted = 0')
->orderBy('score DESC') ->orderBy('score DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -72,6 +72,8 @@ class ImActiveGroupList extends Cache
->orderBy('total_count DESC') ->orderBy('total_count DESC')
->where('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) ->where('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP])
->betweenWhere('create_time', $startTime, $endTime) ->betweenWhere('create_time', $startTime, $endTime)
->andWhere('published = 1')
->andWhere('deleted = 0')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -70,6 +70,7 @@ class ImNewGroupList extends Cache
{ {
return ImGroupModel::query() return ImGroupModel::query()
->where('published = 1') ->where('published = 1')
->andWhere('deleted = 0')
->orderBy('id DESC') ->orderBy('id DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -30,7 +30,10 @@ class IndexArticleList extends Cache
{ {
$articleRepo = new ArticleRepo(); $articleRepo = new ArticleRepo();
$where = ['published' => ArticleModel::PUBLISH_APPROVED]; $where = [
'published' => ArticleModel::PUBLISH_APPROVED,
'deleted' => 0,
];
$pager = $articleRepo->paginate($where, 'latest', 1, 10); $pager = $articleRepo->paginate($where, 'latest', 1, 10);

View File

@ -94,7 +94,9 @@ class IndexFeaturedCourseList extends Cache
{ {
return CategoryModel::query() return CategoryModel::query()
->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->limit($limit) ->limit($limit)
->execute(); ->execute();
@ -113,8 +115,9 @@ class IndexFeaturedCourseList extends Cache
return CourseModel::query() return CourseModel::query()
->inWhere('category_id', $categoryIds) ->inWhere('category_id', $categoryIds)
->andWhere('published = 1')
->andWhere('featured = 1') ->andWhere('featured = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('id DESC') ->orderBy('id DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -94,7 +94,9 @@ class IndexFreeCourseList extends Cache
{ {
return CategoryModel::query() return CategoryModel::query()
->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->limit($limit) ->limit($limit)
->execute(); ->execute();
@ -113,8 +115,9 @@ class IndexFreeCourseList extends Cache
return CourseModel::query() return CourseModel::query()
->inWhere('category_id', $categoryIds) ->inWhere('category_id', $categoryIds)
->andWhere('published = 1')
->andWhere('market_price = 0') ->andWhere('market_price = 0')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('score DESC') ->orderBy('score DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -132,6 +132,8 @@ class IndexLiveList extends Cache
->addFrom(ChapterLiveModel::class, 'cl') ->addFrom(ChapterLiveModel::class, 'cl')
->join(ChapterModel::class, 'cl.chapter_id = c.id', 'c') ->join(ChapterModel::class, 'cl.chapter_id = c.id', 'c')
->betweenWhere('start_time', $startTime, $endTime) ->betweenWhere('start_time', $startTime, $endTime)
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('start_time ASC') ->orderBy('start_time ASC')
->getQuery() ->getQuery()
->execute(); ->execute();

View File

@ -94,7 +94,9 @@ class IndexNewCourseList extends Cache
{ {
return CategoryModel::query() return CategoryModel::query()
->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->limit($limit) ->limit($limit)
->execute(); ->execute();
@ -114,6 +116,7 @@ class IndexNewCourseList extends Cache
return CourseModel::query() return CourseModel::query()
->inWhere('category_id', $categoryIds) ->inWhere('category_id', $categoryIds)
->andWhere('published = 1') ->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('id DESC') ->orderBy('id DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -30,7 +30,10 @@ class IndexQuestionList extends Cache
{ {
$questionRepo = new QuestionRepo(); $questionRepo = new QuestionRepo();
$where = ['published' => QuestionModel::PUBLISH_APPROVED]; $where = [
'published' => QuestionModel::PUBLISH_APPROVED,
'deleted' => 0,
];
$pager = $questionRepo->paginate($where, 'latest', 1, 10); $pager = $questionRepo->paginate($where, 'latest', 1, 10);

View File

@ -65,8 +65,9 @@ class IndexSimpleFeaturedCourseList extends Cache
protected function findCourses($limit = 8) protected function findCourses($limit = 8)
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1') ->where('featured = 1')
->andWhere('featured = 1') ->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('id DESC') ->orderBy('id DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -65,8 +65,9 @@ class IndexSimpleFreeCourseList extends Cache
protected function findCourses($limit = 8) protected function findCourses($limit = 8)
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1') ->where('market_price = 0')
->andWhere('market_price = 0') ->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('score DESC') ->orderBy('score DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -66,6 +66,7 @@ class IndexSimpleNewCourseList extends Cache
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1') ->where('published = 1')
->andWhere('deleted = 0')
->orderBy('id DESC') ->orderBy('id DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -65,9 +65,10 @@ class IndexSimpleVipCourseList extends Cache
protected function findCourses($limit = 8) protected function findCourses($limit = 8)
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1') ->where('market_price > vip_price')
->andWhere('market_price > vip_price')
->andWhere('vip_price >= 0') ->andWhere('vip_price >= 0')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('score DESC') ->orderBy('score DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -68,6 +68,7 @@ class IndexSlideList extends Cache
{ {
return SlideModel::query() return SlideModel::query()
->where('published = 1') ->where('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -60,6 +60,7 @@ class IndexTeacherList extends Cache
{ {
return UserModel::query() return UserModel::query()
->where('edu_role = :edu_role:', ['edu_role' => UserModel::EDU_ROLE_TEACHER]) ->where('edu_role = :edu_role:', ['edu_role' => UserModel::EDU_ROLE_TEACHER])
->andWhere('deleted = 0')
->orderBy('RAND()') ->orderBy('RAND()')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -94,7 +94,9 @@ class IndexVipCourseList extends Cache
{ {
return CategoryModel::query() return CategoryModel::query()
->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE])
->andWhere('level = 1 AND published = 1') ->andWhere('level = 1')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('priority ASC') ->orderBy('priority ASC')
->limit($limit) ->limit($limit)
->execute(); ->execute();
@ -113,9 +115,10 @@ class IndexVipCourseList extends Cache
return CourseModel::query() return CourseModel::query()
->inWhere('category_id', $categoryIds) ->inWhere('category_id', $categoryIds)
->andWhere('published = 1')
->andWhere('market_price > vip_price') ->andWhere('market_price > vip_price')
->andWhere('vip_price >= 0') ->andWhere('vip_price >= 0')
->andWhere('published = 1')
->andWhere('deleted = 0')
->orderBy('score DESC') ->orderBy('score DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -76,6 +76,7 @@ class PointHotGiftList extends Cache
{ {
return PointGiftModel::query() return PointGiftModel::query()
->where('published = 1') ->where('published = 1')
->andWhere('deleted = 0')
->orderBy('redeem_count DESC') ->orderBy('redeem_count DESC')
->limit($limit) ->limit($limit)
->execute(); ->execute();

View File

@ -34,6 +34,7 @@ class TaggedArticleList extends Cache
$where = [ $where = [
'tag_id' => $id, 'tag_id' => $id,
'published' => ArticleModel::PUBLISH_APPROVED, 'published' => ArticleModel::PUBLISH_APPROVED,
'deleted' => 0,
]; ];
$pager = $articleRepo->paginate($where); $pager = $articleRepo->paginate($where);

View File

@ -35,6 +35,7 @@ class TaggedQuestionList extends Cache
$where = [ $where = [
'tag_id' => $id, 'tag_id' => $id,
'published' => QuestionModel::PUBLISH_APPROVED, 'published' => QuestionModel::PUBLISH_APPROVED,
'deleted' => 0,
]; ];
$pager = $questionRepo->paginate($where); $pager = $questionRepo->paginate($where);

View File

@ -124,6 +124,7 @@ class ArticleIndexTask extends Task
{ {
return ArticleModel::query() return ArticleModel::query()
->where('published = :published:', ['published' => ArticleModel::PUBLISH_APPROVED]) ->where('published = :published:', ['published' => ArticleModel::PUBLISH_APPROVED])
->andWhere('deleted = 0')
->execute(); ->execute();
} }

View File

@ -124,6 +124,7 @@ class CourseIndexTask extends Task
{ {
return CourseModel::query() return CourseModel::query()
->where('published = 1') ->where('published = 1')
->where('deleted = 0')
->execute(); ->execute();
} }

View File

@ -124,6 +124,7 @@ class GroupIndexTask extends Task
{ {
return GroupModel::query() return GroupModel::query()
->where('published = 1') ->where('published = 1')
->andWhere('deleted = 0')
->execute(); ->execute();
} }

View File

@ -124,6 +124,7 @@ class QuestionIndexTask extends Task
{ {
return QuestionModel::query() return QuestionModel::query()
->where('published = :published:', ['published' => QuestionModel::PUBLISH_APPROVED]) ->where('published = :published:', ['published' => QuestionModel::PUBLISH_APPROVED])
->andWhere('deleted = 0')
->execute(); ->execute();
} }

View File

@ -139,6 +139,7 @@ class UserIndexTask extends Task
protected function findUsers($limit, $offset) protected function findUsers($limit, $offset)
{ {
return UserModel::query() return UserModel::query()
->where('deleted = 0')
->limit($limit, $offset) ->limit($limit, $offset)
->execute(); ->execute();
} }

View File

@ -7,6 +7,7 @@
namespace App\Http\Api\Controllers; namespace App\Http\Api\Controllers;
use App\Models\Answer as AnswerModel;
use App\Services\Logic\Answer\AnswerAccept as AnswerAcceptService; use App\Services\Logic\Answer\AnswerAccept as AnswerAcceptService;
use App\Services\Logic\Answer\AnswerCreate as AnswerCreateService; use App\Services\Logic\Answer\AnswerCreate as AnswerCreateService;
use App\Services\Logic\Answer\AnswerDelete as AnswerDeleteService; use App\Services\Logic\Answer\AnswerDelete as AnswerDeleteService;
@ -30,6 +31,17 @@ class AnswerController extends Controller
$answer = $service->handle($id); $answer = $service->handle($id);
if ($answer['deleted'] == 1) {
$this->notFound();
}
$approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED;
$owned = $answer['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
return $this->jsonSuccess(['answer' => $answer]); return $this->jsonSuccess(['answer' => $answer]);
} }

View File

@ -7,6 +7,7 @@
namespace App\Http\Api\Controllers; namespace App\Http\Api\Controllers;
use App\Models\Article as ArticleModel;
use App\Services\Logic\Article\ArticleClose as ArticleCloseService; use App\Services\Logic\Article\ArticleClose as ArticleCloseService;
use App\Services\Logic\Article\ArticleDelete as ArticleDeleteService; use App\Services\Logic\Article\ArticleDelete as ArticleDeleteService;
use App\Services\Logic\Article\ArticleFavorite as ArticleFavoriteService; use App\Services\Logic\Article\ArticleFavorite as ArticleFavoriteService;
@ -56,6 +57,22 @@ class ArticleController extends Controller
$article = $service->handle($id); $article = $service->handle($id);
if ($article['deleted'] == 1) {
$this->notFound();
}
$approved = $article['published'] == ArticleModel::PUBLISH_APPROVED;
$owned = $article['me']['owned'] == 1;
$private = $article['private'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
if ($private && !$owned) {
$this->forbidden();
}
return $this->jsonSuccess(['article' => $article]); return $this->jsonSuccess(['article' => $article]);
} }

View File

@ -65,8 +65,16 @@ class ChapterController extends Controller
$chapter = $service->handle($id); $chapter = $service->handle($id);
if ($chapter['deleted'] == 1) {
$this->notFound();
}
if ($chapter['published'] == 0) {
$this->notFound();
}
if ($chapter['me']['owned'] == 0) { if ($chapter['me']['owned'] == 0) {
return $this->jsonError(['msg' => '没有访问章节权限']); $this->forbidden();
} }
return $this->jsonSuccess(['chapter' => $chapter]); return $this->jsonSuccess(['chapter' => $chapter]);

View File

@ -7,6 +7,7 @@
namespace App\Http\Api\Controllers; namespace App\Http\Api\Controllers;
use App\Models\Consult as ConsultModel;
use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService; use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService;
use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService; use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService;
use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService; use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService;
@ -28,6 +29,17 @@ class ConsultController extends Controller
$consult = $service->handle($id); $consult = $service->handle($id);
if ($consult['deleted'] == 1) {
$this->notFound();
}
$approved = $consult['published'] == ConsultModel::PUBLISH_APPROVED;
$owned = $consult['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
return $this->jsonSuccess(['consult' => $consult]); return $this->jsonSuccess(['consult' => $consult]);
} }

View File

@ -55,6 +55,14 @@ class CourseController extends Controller
$course = $service->handle($id); $course = $service->handle($id);
if ($course['deleted'] == 1) {
$this->notFound();
}
if ($course['published'] == 0) {
$this->notFound();
}
return $this->jsonSuccess(['course' => $course]); return $this->jsonSuccess(['course' => $course]);
} }

View File

@ -37,6 +37,14 @@ class HelpController extends Controller
$help = $service->handle($id); $help = $service->handle($id);
if ($help['deleted'] == 1) {
$this->notFound();
}
if ($help['published'] == 0) {
$this->notFound();
}
return $this->jsonSuccess(['help' => $help]); return $this->jsonSuccess(['help' => $help]);
} }

View File

@ -39,6 +39,14 @@ class ImGroupController extends Controller
$group = $service->handle($id); $group = $service->handle($id);
if ($group['deleted'] == 1) {
$this->notFound();
}
if ($group['published'] == 0) {
$this->notFound();
}
return $this->jsonSuccess(['group' => $group]); return $this->jsonSuccess(['group' => $group]);
} }

View File

@ -29,6 +29,10 @@ class OrderController extends Controller
$order = $service->handle($sn); $order = $service->handle($sn);
if ($order['deleted'] == 1) {
$this->notFound();
}
return $this->jsonSuccess(['order' => $order]); return $this->jsonSuccess(['order' => $order]);
} }

View File

@ -24,6 +24,14 @@ class PageController extends Controller
$page = $service->handle($id); $page = $service->handle($id);
if ($page['deleted'] == 1) {
$this->notFound();
}
if ($page['published'] == 0) {
$this->notFound();
}
return $this->jsonSuccess(['page' => $page]); return $this->jsonSuccess(['page' => $page]);
} }

View File

@ -7,6 +7,7 @@
namespace App\Http\Api\Controllers; namespace App\Http\Api\Controllers;
use App\Models\Question as QuestionModel;
use App\Services\Logic\Question\AnswerList as AnswerListService; use App\Services\Logic\Question\AnswerList as AnswerListService;
use App\Services\Logic\Question\CategoryList as CategoryListService; use App\Services\Logic\Question\CategoryList as CategoryListService;
use App\Services\Logic\Question\CommentList as CommentListService; use App\Services\Logic\Question\CommentList as CommentListService;
@ -55,6 +56,17 @@ class QuestionController extends Controller
$question = $service->handle($id); $question = $service->handle($id);
if ($question['deleted'] == 1) {
$this->notFound();
}
$approved = $question['published'] == QuestionModel::PUBLISH_APPROVED;
$owned = $question['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
return $this->jsonSuccess(['question' => $question]); return $this->jsonSuccess(['question' => $question]);
} }

View File

@ -43,6 +43,14 @@ class RefundController extends Controller
$refund = $service->handle($sn); $refund = $service->handle($sn);
if ($refund['deleted'] == 1) {
$this->notFound();
}
if ($refund['me']['owned'] == 0) {
$this->forbidden();
}
return $this->jsonSuccess(['refund' => $refund]); return $this->jsonSuccess(['refund' => $refund]);
} }

View File

@ -7,6 +7,7 @@
namespace App\Http\Api\Controllers; namespace App\Http\Api\Controllers;
use App\Models\Review as ReviewModel;
use App\Services\Logic\Review\ReviewCreate as ReviewCreateService; use App\Services\Logic\Review\ReviewCreate as ReviewCreateService;
use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService; use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService;
use App\Services\Logic\Review\ReviewInfo as ReviewInfoService; use App\Services\Logic\Review\ReviewInfo as ReviewInfoService;
@ -28,6 +29,17 @@ class ReviewController extends Controller
$review = $service->handle($id); $review = $service->handle($id);
if ($review['deleted'] == 1) {
$this->notFound();
}
$approved = $review['published'] == ReviewModel::PUBLISH_APPROVED;
$owned = $review['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
return $this->jsonSuccess(['review' => $review]); return $this->jsonSuccess(['review' => $review]);
} }

View File

@ -27,6 +27,14 @@ class TradeController extends Controller
$trade = $service->handle($sn); $trade = $service->handle($sn);
if ($trade['deleted'] == 1) {
$this->notFound();
}
if ($trade['me']['owned'] == 0) {
$this->forbidden();
}
return $this->jsonSuccess(['trade' => $trade]); return $this->jsonSuccess(['trade' => $trade]);
} }

View File

@ -30,6 +30,10 @@ class UserController extends Controller
$user = $service->handle($id); $user = $service->handle($id);
if ($user['deleted'] == 1) {
$this->notFound();
}
return $this->jsonSuccess(['user' => $user]); return $this->jsonSuccess(['user' => $user]);
} }

View File

@ -57,8 +57,15 @@ class AnswerController extends Controller
$answer = $service->handle($id); $answer = $service->handle($id);
if ($answer['published'] != AnswerModel::PUBLISH_APPROVED) { if ($answer['deleted'] == 1) {
return $this->notFound(); $this->notFound();
}
$approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED;
$owned = $answer['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
} }
$questionId = $answer['question']['id']; $questionId = $answer['question']['id'];

View File

@ -105,16 +105,20 @@ class ArticleController extends Controller
$article = $service->handle($id); $article = $service->handle($id);
if ($article['published'] != ArticleModel::PUBLISH_APPROVED) { if ($article['deleted'] == 1) {
return $this->notFound(); $this->notFound();
} }
$approved = $article['published'] == ArticleModel::PUBLISH_APPROVED;
$owned = $article['me']['owned'] == 1;
$private = $article['private'] == 1; $private = $article['private'] == 1;
$owned = $this->authUser->id == $article['owner']['id']; if (!$approved && !$owned) {
$this->notFound();
}
if ($private && !$owned) { if ($private && !$owned) {
return $this->forbidden(); $this->forbidden();
} }
$this->seo->prependTitle(['专栏', $article['title']]); $this->seo->prependTitle(['专栏', $article['title']]);

View File

@ -39,20 +39,24 @@ class ChapterController extends Controller
*/ */
public function showAction($id) public function showAction($id)
{ {
$service = new ChapterInfoService();
$chapter = $service->handle($id);
if ($chapter['published'] == 0) {
return $this->notFound();
}
if ($this->authUser->id == 0) { if ($this->authUser->id == 0) {
return $this->response->redirect(['for' => 'home.account.login']); return $this->response->redirect(['for' => 'home.account.login']);
} }
$service = new ChapterInfoService();
$chapter = $service->handle($id);
if ($chapter['deleted'] == 1) {
$this->notFound();
}
if ($chapter['published'] == 0) {
$this->notFound();
}
if ($chapter['me']['owned'] == 0) { if ($chapter['me']['owned'] == 0) {
return $this->forbidden(); $this->forbidden();
} }
$service = new CourseInfoService(); $service = new CourseInfoService();

View File

@ -7,6 +7,7 @@
namespace App\Http\Home\Controllers; namespace App\Http\Home\Controllers;
use App\Models\Consult as ConsultModel;
use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService; use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService;
use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService; use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService;
use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService; use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService;
@ -37,6 +38,17 @@ class ConsultController extends Controller
$consult = $service->handle($id); $consult = $service->handle($id);
if ($consult['deleted'] == 1) {
$this->notFound();
}
$approved = $consult['published'] == ConsultModel::PUBLISH_APPROVED;
$owned = $consult['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
$this->view->setVar('consult', $consult); $this->view->setVar('consult', $consult);
} }

View File

@ -77,8 +77,12 @@ class CourseController extends Controller
$course = $service->handle($id); $course = $service->handle($id);
if ($course['deleted'] == 1) {
$this->notFound();
}
if ($course['published'] == 0) { if ($course['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$service = new CourseChapterListService(); $service = new CourseChapterListService();

View File

@ -40,8 +40,12 @@ class HelpController extends Controller
$help = $service->handle($id); $help = $service->handle($id);
if ($help['deleted'] == 1) {
$this->notFound();
}
if ($help['published'] == 0) { if ($help['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$featuredCourses = $this->getFeaturedCourses(); $featuredCourses = $this->getFeaturedCourses();

View File

@ -51,8 +51,12 @@ class ImGroupController extends Controller
$group = $service->getGroup($id); $group = $service->getGroup($id);
if ($group['deleted'] == 1) {
$this->notFound();
}
if ($group['published'] == 0) { if ($group['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$this->seo->prependTitle(['群组', $group['name']]); $this->seo->prependTitle(['群组', $group['name']]);

View File

@ -45,6 +45,14 @@ class OrderController extends Controller
$order = $service->handle($sn); $order = $service->handle($sn);
if ($order['deleted'] == 1) {
$this->notFound();
}
if ($order['me']['owned'] == 0) {
$this->forbidden();
}
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$this->view->setVar('order', $order); $this->view->setVar('order', $order);
} }

View File

@ -27,7 +27,7 @@ class PackageController extends Controller
$package = $service->handle($id); $package = $service->handle($id);
if ($package['published'] == 0) { if ($package['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$this->seo->prependTitle(['套餐', $package['title']]); $this->seo->prependTitle(['套餐', $package['title']]);

View File

@ -25,8 +25,12 @@ class PageController extends Controller
$page = $service->handle($id); $page = $service->handle($id);
if ($page['deleted'] == 1) {
$this->notFound();
}
if ($page['published'] == 0) { if ($page['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$featuredCourses = $this->getFeaturedCourses(); $featuredCourses = $this->getFeaturedCourses();

View File

@ -68,8 +68,12 @@ class PointGiftController extends Controller
$gift = $service->handle($id); $gift = $service->handle($id);
if ($gift['deleted'] == 1) {
$this->notFound();
}
if ($gift['published'] == 0) { if ($gift['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$hotGifts = $this->getHotGifts(); $hotGifts = $this->getHotGifts();

View File

@ -102,8 +102,15 @@ class QuestionController extends Controller
$question = $service->handle($id); $question = $service->handle($id);
if ($question['published'] != QuestionModel::PUBLISH_APPROVED) { if ($question['deleted'] == 1) {
return $this->notFound(); $this->notFound();
}
$approved = $question['published'] == QuestionModel::PUBLISH_APPROVED;
$owned = $question['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
} }
$this->seo->prependTitle(['问答', $question['title']]); $this->seo->prependTitle(['问答', $question['title']]);

View File

@ -63,6 +63,14 @@ class RefundController extends Controller
$refund = $service->handle($sn); $refund = $service->handle($sn);
if ($refund['deleted'] == 1) {
$this->notFound();
}
if ($refund['me']['owned'] == 0) {
$this->forbidden();
}
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$this->view->setVar('refund', $refund); $this->view->setVar('refund', $refund);
} }

View File

@ -7,6 +7,7 @@
namespace App\Http\Home\Controllers; namespace App\Http\Home\Controllers;
use App\Models\Review as ReviewModel;
use App\Services\Logic\Review\ReviewCreate as ReviewCreateService; use App\Services\Logic\Review\ReviewCreate as ReviewCreateService;
use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService; use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService;
use App\Services\Logic\Review\ReviewInfo as ReviewInfoService; use App\Services\Logic\Review\ReviewInfo as ReviewInfoService;
@ -50,6 +51,17 @@ class ReviewController extends Controller
$review = $service->handle($id); $review = $service->handle($id);
if ($review['deleted'] == 1) {
$this->notFound();
}
$approved = $review['published'] == ReviewModel::PUBLISH_APPROVED;
$owned = $review['me']['owned'] == 1;
if (!$approved && !$owned) {
$this->notFound();
}
return $this->jsonSuccess(['review' => $review]); return $this->jsonSuccess(['review' => $review]);
} }

View File

@ -27,7 +27,7 @@ class TopicController extends Controller
$topic = $service->handle($id); $topic = $service->handle($id);
if ($topic['published'] == 0) { if ($topic['published'] == 0) {
return $this->notFound(); $this->notFound();
} }
$this->seo->prependTitle(['专题', $topic['title']]); $this->seo->prependTitle(['专题', $topic['title']]);

View File

@ -32,7 +32,7 @@ class UserController extends Controller
$user = $service->handle($id); $user = $service->handle($id);
if ($user['deleted'] == 1) { if ($user['deleted'] == 1) {
return $this->notFound(); $this->notFound();
} }
$this->seo->prependTitle(['空间', $user['name']]); $this->seo->prependTitle(['空间', $user['name']]);

View File

@ -21,7 +21,7 @@
</table> </table>
<br> <br>
<div class="center"> <div class="center">
{% if refund.status == 3 %} {% if refund.me.allow_cancel == 1 %}
<button class="kg-refund layui-btn" data-sn="{{ refund.sn }}" data-url="{{ cancel_url }}">取消退款</button> <button class="kg-refund layui-btn" data-sn="{{ refund.sn }}" data-url="{{ cancel_url }}">取消退款</button>
{% endif %} {% endif %}
</div> </div>

View File

@ -144,10 +144,6 @@ class Category extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -253,10 +253,6 @@ class Chapter extends Model
$this->attrs = kg_json_encode($this->attrs); $this->attrs = kg_json_encode($this->attrs);
} }
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -183,10 +183,6 @@ class Consult extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -342,10 +342,6 @@ class Course extends Model
$this->attrs = kg_json_encode($this->attrs); $this->attrs = kg_json_encode($this->attrs);
} }
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -149,10 +149,6 @@ class Danmu extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -135,10 +135,6 @@ class FlashSale extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -100,10 +100,6 @@ class Help extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -142,10 +142,6 @@ class ImGroup extends Model
$sync->addItem($this->id); $sync->addItem($this->id);
} }
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -146,10 +146,6 @@ class Nav extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -115,10 +115,6 @@ class Package extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -93,10 +93,6 @@ class Page extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -180,10 +180,6 @@ class PointGift extends Model
$this->attrs = kg_json_encode($this->attrs); $this->attrs = kg_json_encode($this->attrs);
} }
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -169,10 +169,6 @@ class Review extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -135,10 +135,6 @@ class Slide extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -143,10 +143,6 @@ class Tag extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -93,10 +93,6 @@ class Topic extends Model
public function beforeUpdate() public function beforeUpdate()
{ {
if ($this->deleted == 1) {
$this->published = 0;
}
$this->update_time = time(); $this->update_time = time();
} }

View File

@ -31,6 +31,13 @@ class WeChatSubscribe extends Model
*/ */
public $open_id = ''; public $open_id = '';
/**
* 删除标识
*
* @var int
*/
public $deleted = 0;
/** /**
* 创建时间 * 创建时间
* *

View File

@ -103,7 +103,10 @@ class Comment extends Repository
public function countComments() public function countComments()
{ {
return (int)CommentModel::count(['conditions' => 'deleted = 0']); return (int)CommentModel::count([
'conditions' => 'published = :published: AND deleted = 0',
'bind' => ['published' => CommentModel::PUBLISH_APPROVED],
]);
} }
} }

View File

@ -118,7 +118,10 @@ class Consult extends Repository
public function countConsults() public function countConsults()
{ {
return (int)ConsultModel::count(['conditions' => 'deleted = 0']); return (int)ConsultModel::count([
'conditions' => 'published = :published: AND deleted = 0',
'bind' => ['published' => ConsultModel::PUBLISH_APPROVED],
]);
} }
public function countLikes($consultId) public function countLikes($consultId)

View File

@ -128,7 +128,9 @@ class ImGroup extends Repository
public function countGroups() public function countGroups()
{ {
return (int)ImGroupModel::count(['conditions' => 'published = 1']); return (int)ImGroupModel::count([
'conditions' => 'published = 1 AND deleted = 0',
]);
} }
public function countUsers($groupId) public function countUsers($groupId)

View File

@ -111,13 +111,16 @@ class Package extends Repository
->join(CoursePackageModel::class, 'c.id = cp.course_id', 'cp') ->join(CoursePackageModel::class, 'c.id = cp.course_id', 'cp')
->where('cp.package_id = :package_id:', ['package_id' => $packageId]) ->where('cp.package_id = :package_id:', ['package_id' => $packageId])
->andWhere('c.published = 1') ->andWhere('c.published = 1')
->andWhere('c.deleted = 0')
->getQuery() ->getQuery()
->execute(); ->execute();
} }
public function countPackages() public function countPackages()
{ {
return (int)PackageModel::count(['conditions' => 'deleted = 0']); return (int)PackageModel::count([
'conditions' => 'published = 1 AND deleted = 0',
]);
} }
public function countCourses($packageId) public function countCourses($packageId)

View File

@ -116,7 +116,10 @@ class Review extends Repository
public function countReviews() public function countReviews()
{ {
return (int)ReviewModel::count(['conditions' => 'deleted = 0']); return (int)ReviewModel::count([
'conditions' => 'published = :published: AND deleted = 0',
'bind' => ['published' => ReviewModel::PUBLISH_APPROVED],
]);
} }
public function countLikes($reviewId) public function countLikes($reviewId)

View File

@ -96,12 +96,15 @@ class Topic extends Repository
->join(CourseTopicModel::class, 'c.id = ct.course_id', 'ct') ->join(CourseTopicModel::class, 'c.id = ct.course_id', 'ct')
->where('ct.topic_id = :topic_id:', ['topic_id' => $topicId]) ->where('ct.topic_id = :topic_id:', ['topic_id' => $topicId])
->andWhere('c.published = 1') ->andWhere('c.published = 1')
->andWhere('c.deleted = 0')
->getQuery()->execute(); ->getQuery()->execute();
} }
public function countTopics() public function countTopics()
{ {
return (int)TopicModel::count(['conditions' => 'deleted = 0']); return (int)TopicModel::count([
'conditions' => 'published = 1 AND deleted = 0',
]);
} }
public function countCourses($topicId) public function countCourses($topicId)

Some files were not shown because too many files have changed in this diff Show More