1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-24 00:41:43 +08:00

重新划分目录

This commit is contained in:
xiaochong0302 2020-03-27 19:41:51 +08:00
parent 1d40766a2a
commit 66b1861ba0
55 changed files with 392 additions and 333 deletions

View File

@ -179,7 +179,9 @@ class RefundTask extends Task
$courseUser = $courseUserRepo->findCourseStudent($order->item_id, $order->user_id); $courseUser = $courseUserRepo->findCourseStudent($order->item_id, $order->user_id);
if ($courseUser) { if ($courseUser) {
$courseUser->deleted = 1; $courseUser->deleted = 1;
if ($courseUser->update() === false) { if ($courseUser->update() === false) {
throw new \RuntimeException('Delete Course User Failed'); throw new \RuntimeException('Delete Course User Failed');
} }
@ -205,7 +207,9 @@ class RefundTask extends Task
$courseUser = $courseUserRepo->findCourseStudent($course['id'], $order->user_id); $courseUser = $courseUserRepo->findCourseStudent($course['id'], $order->user_id);
if ($courseUser) { if ($courseUser) {
$courseUser->deleted = 1; $courseUser->deleted = 1;
if ($courseUser->update() === false) { if ($courseUser->update() === false) {
throw new \RuntimeException('Delete Course User Failed'); throw new \RuntimeException('Delete Course User Failed');
} }

View File

@ -94,7 +94,7 @@ class Refund extends Service
$data = []; $data = [];
$validator->checkReviewAction($refund); $validator->checkIfAllowReview($refund);
$data['status'] = $validator->checkReviewStatus($post['status']); $data['status'] = $validator->checkReviewStatus($post['status']);
$data['review_note'] = $validator->checkReviewNote($post['review_note']); $data['review_note'] = $validator->checkReviewNote($post['review_note']);

View File

@ -3,10 +3,10 @@
namespace App\Http\Home\Controllers; namespace App\Http\Home\Controllers;
use App\Services\Frontend\Course as CourseService; use App\Services\Frontend\Course as CourseService;
use App\Services\Frontend\CourseFavorite as CourseFavoriteService;
use App\Services\Frontend\CourseList as CourseListService; use App\Services\Frontend\CourseList as CourseListService;
use App\Services\Frontend\CourseRelated as CourseRelatedService; use App\Services\Frontend\CourseRelated as CourseRelatedService;
use App\Services\Frontend\CourseReview as CourseReviewService; use App\Services\Frontend\Favorite as CourseFavoriteService;
use App\Services\Frontend\ReviewCreate as CourseReviewService;
/** /**
* @RoutePrefix("/course") * @RoutePrefix("/course")

View File

@ -13,12 +13,4 @@ class IndexController extends Controller
} }
/**
* @Get("/phpinfo", name="home.phpinfo")
*/
public function phpinfoAction()
{
echo phpinfo(); exit;
}
} }

View File

@ -2,9 +2,9 @@
namespace App\Listeners; namespace App\Listeners;
use App\Caches\Chapter as ChapterCache;
use App\Caches\MaxChapterId as MaxChapterIdCache; use App\Caches\MaxChapterId as MaxChapterIdCache;
use App\Models\Chapter as ChapterModel; use App\Models\Chapter as ChapterModel;
use App\Services\ChapterCacheSyncer;
use Phalcon\Events\Event; use Phalcon\Events\Event;
class ChapterAdmin extends Listener class ChapterAdmin extends Listener
@ -76,9 +76,9 @@ class ChapterAdmin extends Listener
protected function syncCache(ChapterModel $chapter) protected function syncCache(ChapterModel $chapter)
{ {
$cacheSyncer = new ChapterCacheSyncer(); $chapterCache = new ChapterCache();
$cacheSyncer->addItem($chapter->id); $chapterCache->rebuild($chapter->id);
} }
} }

View File

@ -2,9 +2,9 @@
namespace App\Listeners; namespace App\Listeners;
use App\Caches\Course as CourseCache;
use App\Caches\MaxCourseId as MaxCourseIdCache; use App\Caches\MaxCourseId as MaxCourseIdCache;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Services\CourseCacheSyncer;
use App\Services\CourseIndexSyncer; use App\Services\CourseIndexSyncer;
use Phalcon\Events\Event; use Phalcon\Events\Event;
@ -84,9 +84,9 @@ class CourseAdmin extends Listener
protected function syncCache(CourseModel $course) protected function syncCache(CourseModel $course)
{ {
$cacheSyncer = new CourseCacheSyncer(); $courseCache = new CourseCache();
$cacheSyncer->addItem($course->id); $courseCache->rebuild($course->id);
} }
protected function syncIndex(CourseModel $course) protected function syncIndex(CourseModel $course)

View File

@ -133,14 +133,17 @@ class Category extends Model
public function rebuildCache() public function rebuildCache()
{ {
$categoryCache = new CategoryCache(); $cache = new CategoryCache();
$categoryCache->rebuild($this->id);
$categoryListCache = new CategoryListCache(); $cache->rebuild($this->id);
$categoryListCache->rebuild();
$categoryTreeListCache = new CategoryTreeListCache(); $listCache = new CategoryListCache();
$categoryTreeListCache->rebuild();
$listCache->rebuild();
$treeListCache = new CategoryTreeListCache();
$treeListCache->rebuild();
} }
} }

View File

@ -103,7 +103,7 @@ class ChapterVod extends Model
$this->update(); $this->update();
/** /**
* afterUpdate事件会序列化属性,需再次重设属性 * afterUpdate事件触发序列化,故重设属性
*/ */
$this->file_transcode = $transcode; $this->file_transcode = $transcode;
} }

View File

@ -158,6 +158,7 @@ class Nav extends Model
public function rebuildCache() public function rebuildCache()
{ {
$cache = new NavTreeListCache(); $cache = new NavTreeListCache();
$cache->rebuild(); $cache->rebuild();
} }

View File

@ -177,6 +177,7 @@ class User extends Model
public function afterCreate() public function afterCreate()
{ {
$maxUserIdCache = new MaxUserIdCache(); $maxUserIdCache = new MaxUserIdCache();
$maxUserIdCache->rebuild(); $maxUserIdCache->rebuild();
} }
@ -201,16 +202,4 @@ class User extends Model
return $list; return $list;
} }
public static function vipTypes()
{
$list = [
1 => '1个月',
3 => '3个月',
6 => '6个月',
12 => '12个月',
];
return $list;
}
} }

View File

@ -125,7 +125,7 @@ class Order extends Repository
* @param string $itemType * @param string $itemType
* @return OrderModel|Model|bool * @return OrderModel|Model|bool
*/ */
public function findLastUserItem($userId, $itemId, $itemType) public function findLastUserOrder($userId, $itemId, $itemType)
{ {
$result = OrderModel::findFirst([ $result = OrderModel::findFirst([
'conditions' => 'user_id = ?1 AND item_id = ?2 AND item_type = ?3', 'conditions' => 'user_id = ?1 AND item_id = ?2 AND item_type = ?3',

View File

@ -1,143 +0,0 @@
<?php
namespace App\Services\Frontend;
use App\Models\Account as AccountModel;
use App\Repos\Account as AccountRepo;
use App\Validators\Account as AccountValidator;
use App\Validators\Security as SecurityValidator;
class Account extends Service
{
public function createAccount()
{
$post = $this->request->getPost();
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['phone'], $post['verify_code']);
$accountValidator = new AccountValidator();
$data = [];
$data['phone'] = $accountValidator->checkPhone($post['phone']);
$data['password'] = $accountValidator->checkPassword($post['password']);
$accountValidator->checkIfPhoneTaken($post['phone']);
$account = new AccountModel();
$account->create($data);
return $account;
}
public function updateEmail()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$email = $accountValidator->checkEmail($post['email']);
if ($email != $account->email) {
$accountValidator->checkIfEmailTaken($post['email']);
}
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['email'], $post['verify_code']);
$account->email = $email;
$account->update();
return $account;
}
public function updatePhone()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$phone = $accountValidator->checkPhone($post['phone']);
if ($phone != $account->phone) {
$accountValidator->checkIfPhoneTaken($post['phone']);
}
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['phone'], $post['verify_code']);
$account->phone = $phone;
$account->update();
return $account;
}
public function updatePassword()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$newPassword = $accountValidator->checkPassword($post['new_password']);
$account->password = $newPassword;
$account->update();
return $account;
}
public function resetPassword()
{
$post = $this->request->getPost();
$accountValidator = new AccountValidator();
$account = $accountValidator->checkLoginAccount($post['account']);
$accountValidator->checkPassword($post['new_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['account'], $post['verify_code']);
$account->password = $post['new_password'];
$account->update();
return $account;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Services\Frontend\Account;
use App\Models\Account as AccountModel;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Security as SecurityValidator;
class AccountCreate extends Service
{
public function createAccount()
{
$post = $this->request->getPost();
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['phone'], $post['verify_code']);
$accountValidator = new AccountValidator();
$data = [];
$data['phone'] = $accountValidator->checkPhone($post['phone']);
$data['password'] = $accountValidator->checkPassword($post['password']);
$accountValidator->checkIfPhoneTaken($post['phone']);
$account = new AccountModel();
$account->create($data);
return $account;
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Services\Frontend;
use App\Repos\Account as AccountRepo;
use App\Validators\Account as AccountValidator;
use App\Validators\Security as SecurityValidator;
class EmailUpdate extends Service
{
public function updateEmail()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$email = $accountValidator->checkEmail($post['email']);
if ($email != $account->email) {
$accountValidator->checkIfEmailTaken($post['email']);
}
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['email'], $post['verify_code']);
$account->email = $email;
$account->update();
return $account;
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Services\Frontend\Account;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Security as SecurityValidator;
class PasswordReset extends Service
{
public function resetPassword()
{
$post = $this->request->getPost();
$accountValidator = new AccountValidator();
$account = $accountValidator->checkLoginAccount($post['account']);
$accountValidator->checkPassword($post['new_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['account'], $post['verify_code']);
$account->password = $post['new_password'];
$account->update();
return $account;
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Services\Frontend\Account;
use App\Repos\Account as AccountRepo;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
class PasswordUpdate extends Service
{
public function updatePassword()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$newPassword = $accountValidator->checkPassword($post['new_password']);
$account->password = $newPassword;
$account->update();
return $account;
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace App\Services\Frontend\Account;
use App\Repos\Account as AccountRepo;
use App\Services\Frontend\Service;
use App\Validators\Account as AccountValidator;
use App\Validators\Security as SecurityValidator;
class PhoneUpdate extends Service
{
public function updatePhone()
{
$post = $this->request->getPost();
$user = $this->getLoginUser();
$accountRepo = new AccountRepo();
$account = $accountRepo->findById($user->id);
$accountValidator = new AccountValidator();
$phone = $accountValidator->checkPhone($post['phone']);
if ($phone != $account->phone) {
$accountValidator->checkIfPhoneTaken($post['phone']);
}
$accountValidator->checkOriginPassword($account, $post['origin_password']);
$securityValidator = new SecurityValidator();
$securityValidator->checkVerifyCode($post['phone'], $post['verify_code']);
$account->phone = $phone;
$account->update();
return $account;
}
}

View File

@ -1,19 +1,23 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Chapter;
use App\Models\Chapter as ChapterModel; use App\Models\Chapter as ChapterModel;
use App\Models\ChapterUser as ChapterUserModel; use App\Models\ChapterUser as ChapterUserModel;
use App\Models\ChapterVote as ChapterVoteModel; use App\Models\ChapterVote as ChapterVoteModel;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Models\CourseUser as CourseUserModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Chapter as ChapterRepo; use App\Repos\Chapter as ChapterRepo;
use App\Repos\ChapterVote as ChapterVoteRepo; use App\Repos\ChapterVote as ChapterVoteRepo;
use App\Services\ChapterVod as ChapterVodService; use App\Services\ChapterVod as ChapterVodService;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Services\Live as LiveService; use App\Services\Live as LiveService;
use WhichBrowser\Parser as BrowserParser; use WhichBrowser\Parser as BrowserParser;
class Chapter extends Service class ChapterInfo extends Service
{ {
/** /**
@ -32,24 +36,31 @@ class Chapter extends Service
{ {
$chapter = $this->checkChapter($id); $chapter = $this->checkChapter($id);
$this->course = $this->checkCourse($chapter->course_id); $course = $this->checkCourse($chapter->course_id);
$this->user = $this->getCurrentUser(); $this->course = $course;
$this->setCourseUser($this->course, $this->user); $user = $this->getCurrentUser();
$this->setChapterUser($chapter, $this->user); $this->user = $user;
$this->handleChapterUser($chapter); $this->setCourseUser($course, $user);
return $this->handleChapter($chapter); $this->setChapterUser($chapter, $user);
$this->handleCourseUser($course, $user);
$this->handleChapterUser($chapter, $user);
return $this->handleChapter($chapter, $user);
} }
/** /**
* @param ChapterModel $chapter * @param ChapterModel $chapter
* @param UserModel $user
* @return array * @return array
*/ */
protected function handleChapter(ChapterModel $chapter) protected function handleChapter(ChapterModel $chapter, UserModel $user)
{ {
$result = $this->formatChapter($chapter); $result = $this->formatChapter($chapter);
@ -60,11 +71,11 @@ class Chapter extends Service
$me['owned'] = $this->ownedChapter; $me['owned'] = $this->ownedChapter;
if ($this->user->id > 0) { if ($user->id > 0) {
$chapterVoteRepo = new ChapterVoteRepo(); $chapterVoteRepo = new ChapterVoteRepo();
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $this->user->id); $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
if ($chapterVote) { if ($chapterVote) {
$me['agreed'] = $chapterVote->type == ChapterVoteModel::TYPE_AGREE; $me['agreed'] = $chapterVote->type == ChapterVoteModel::TYPE_AGREE;
@ -210,28 +221,56 @@ class Chapter extends Service
} }
/** /**
* @param ChapterModel $chapter * @param CourseModel $course
* @param UserModel $user
*/ */
protected function handleChapterUser(ChapterModel $chapter) protected function handleCourseUser(CourseModel $course, UserModel $user)
{ {
if ($this->user->id == 0) return; if ($user->id == 0) return;
if (!$this->courseUser) return; if ($this->joinedCourse) return;
if ($this->ownedChapter && !$this->joinedChapter) { if (!$this->ownedCourse) return;
$chapterUser = new ChapterUserModel(); $courseUser = new CourseUserModel();
$chapterUser->course_id = $this->course->id; $courseUser->course_id = $course->id;
$chapterUser->chapter_id = $chapter->id; $courseUser->user_id = $user->id;
$chapterUser->user_id = $this->user->id; $courseUser->source_type = CourseUserModel::SOURCE_FREE;
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->expiry_time = strtotime('+3 years');
$chapterUser->create(); $courseUser->create();
$chapter->user_count += 1; $course->user_count += 1;
$chapter->update(); $course->update();
}
} }
/**
* @param ChapterModel $chapter
* @param UserModel $user
*/
protected function handleChapterUser(ChapterModel $chapter, UserModel $user)
{
if ($user->id == 0) return;
if ($this->joinedChapter) return;
if (!$this->ownedChapter) return;
$chapterUser = new ChapterUserModel();
$chapterUser->course_id = $chapter->course_id;
$chapterUser->chapter_id = $chapter->id;
$chapterUser->user_id = $user->id;
$chapterUser->create();
$chapter->user_count += 1;
$chapter->update();
}
} }

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Chapter;
use App\Models\ChapterVote as ChapterVoteModel; use App\Models\ChapterVote as ChapterVoteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\ChapterVote as ChapterVoteRepo; use App\Repos\ChapterVote as ChapterVoteRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ChapterVote extends Service class ChapterVote extends Service
@ -20,7 +22,7 @@ class ChapterVote extends Service
$validator = new UserDailyLimitValidator(); $validator = new UserDailyLimitValidator();
$validator->checkChapterVoteLimit($user->id); $validator->checkChapterVoteLimit($user);
$chapterVoteRepo = new ChapterVoteRepo(); $chapterVoteRepo = new ChapterVoteRepo();
@ -76,6 +78,10 @@ class ChapterVote extends Service
$user = $this->getLoginUser(); $user = $this->getLoginUser();
$validator = new UserDailyLimitValidator();
$validator->checkChapterVoteLimit($user);
$chapterVoteRepo = new ChapterVoteRepo(); $chapterVoteRepo = new ChapterVoteRepo();
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id); $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Chapter;
use App\Builders\CommentList as CommentListBuilder; use App\Builders\CommentList as CommentListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
@ -9,8 +9,10 @@ use App\Models\CommentVote as CommentVoteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Chapter as ChapterRepo; use App\Repos\Chapter as ChapterRepo;
use App\Repos\Comment as CommentRepo; use App\Repos\Comment as CommentRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
class ChapterCommentList extends Service class CommentList extends Service
{ {
/** /**

View File

@ -1,14 +1,16 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Chapter;
use App\Models\Comment as CommentModel; use App\Models\Comment as CommentModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\Service;
use App\Validators\Comment as CommentValidator; use App\Validators\Comment as CommentValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ChapterComment extends Service class CommentCreate extends Service
{ {
use ChapterTrait; use ChapterTrait;

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Comment;
use App\Repos\Chapter as ChapterRepo; use App\Repos\Chapter as ChapterRepo;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Validators\Comment as CommentValidator; use App\Validators\Comment as CommentValidator;
class Comment extends Service class CommentDelete extends Service
{ {
use CommentTrait; use CommentTrait;

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Comment;
use App\Models\CommentVote as CommentVoteModel; use App\Models\CommentVote as CommentVoteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\CommentVote as CommentVoteRepo; use App\Repos\CommentVote as CommentVoteRepo;
use App\Services\Frontend\CommentTrait;
use App\Services\Frontend\Service;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class CommentVote extends Service class CommentVote extends Service

View File

@ -1,13 +1,15 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Models\Consult as ConsultModel; use App\Models\Consult as ConsultModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Validators\Consult as ConsultValidator; use App\Validators\Consult as ConsultValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class CourseConsult extends Service class ConsultCreate extends Service
{ {
use CourseTrait; use CourseTrait;

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Consult;
use App\Models\ConsultVote as ConsultVoteModel; use App\Models\ConsultVote as ConsultVoteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\ConsultVote as ConsultVoteRepo; use App\Repos\ConsultVote as ConsultVoteRepo;
use App\Services\Frontend\ConsultTrait;
use App\Services\Frontend\Service;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class ConsultVote extends Service class ConsultVote extends Service

View File

@ -1,14 +1,16 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Builders\ChapterTreeList as ChapterListBuilder; use App\Builders\ChapterTreeList as ChapterListBuilder;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\Resultset;
class CourseChapterList extends Service class ChapterList extends Service
{ {
use CourseTrait; use CourseTrait;
@ -33,9 +35,6 @@ class CourseChapterList extends Service
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
/**
* @var Resultset $chapters
*/
$chapters = $courseRepo->findChapters($id); $chapters = $courseRepo->findChapters($id);
return $this->handleChapters($chapters); return $this->handleChapters($chapters);
@ -86,9 +85,6 @@ class CourseChapterList extends Service
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
/**
* @var Resultset $userLearnings
*/
$userLearnings = $courseRepo->findUserLearnings($course->id, $user->id); $userLearnings = $courseRepo->findUserLearnings($course->id, $user->id);
if ($userLearnings->count() == 0) { if ($userLearnings->count() == 0) {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Builders\ConsultList as ConsultListBuilder; use App\Builders\ConsultList as ConsultListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
@ -9,9 +9,11 @@ use App\Models\Course as CourseModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Consult as ConsultRepo; use App\Repos\Consult as ConsultRepo;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\Resultset;
class CourseConsultList extends Service class ConsultList extends Service
{ {
/** /**

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Models\CourseFavorite as FavoriteModel; use App\Models\CourseFavorite as FavoriteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\CourseFavorite as CourseFavoriteRepo; use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class CourseFavorite extends Service class CourseFavorite extends Service

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Models\Course as CourseModel; use App\Models\Course as CourseModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\CourseFavorite as CourseFavoriteRepo; use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
class Course extends Service class CourseInfo extends Service
{ {
use CourseTrait; use CourseTrait;

View File

@ -1,8 +1,10 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Caches\CourseRelatedList as CourseRelatedListCache; use App\Caches\CourseRelatedList as CourseRelatedListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
class CourseRelated extends Service class CourseRelated extends Service
{ {
@ -13,21 +15,21 @@ class CourseRelated extends Service
{ {
$course = $this->checkCourse($id); $course = $this->checkCourse($id);
$crListCache = new CourseRelatedListCache(); $listCache = new CourseRelatedListCache();
$relatedCourses = $crListCache->get($course->id); $courses = $listCache->get($course->id);
if (!$relatedCourses) { if (!$courses) {
return []; return [];
} }
$imgBaseUrl = kg_img_base_url(); $imgBaseUrl = kg_img_base_url();
foreach ($relatedCourses as &$course) { foreach ($courses as &$course) {
$course['cover'] = $imgBaseUrl . $course['cover']; $course['cover'] = $imgBaseUrl . $course['cover'];
} }
return $relatedCourses; return $courses;
} }
} }

View File

@ -1,13 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Models\Course as CourseModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Repos\Package as PackageRepo; use App\Repos\Package as PackageRepo;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use Phalcon\Mvc\Model\Resultset; use Phalcon\Mvc\Model\Resultset;
class CoursePackageList extends Service class PackageList extends Service
{ {
use CourseTrait; use CourseTrait;
@ -18,9 +19,6 @@ class CoursePackageList extends Service
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
/**
* @var Resultset $packages
*/
$packages = $courseRepo->findPackages($course->id); $packages = $courseRepo->findPackages($course->id);
return $this->handlePackages($packages); return $this->handlePackages($packages);
@ -58,9 +56,6 @@ class CoursePackageList extends Service
{ {
$packageRepo = new PackageRepo(); $packageRepo = new PackageRepo();
/**
* @var CourseModel[] $courses
*/
$courses = $packageRepo->findCourses($packageId); $courses = $packageRepo->findCourses($packageId);
$result = []; $result = [];

View File

@ -1,6 +1,6 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Builders\ReviewList as ReviewListBuilder; use App\Builders\ReviewList as ReviewListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
@ -9,9 +9,10 @@ use App\Models\ReviewVote as ReviewVoteModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Repos\Review as ReviewRepo; use App\Repos\Review as ReviewRepo;
use Phalcon\Mvc\Model\Resultset; use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
class CourseReviewList extends Service class ReviewList extends Service
{ {
/** /**
@ -101,9 +102,6 @@ class CourseReviewList extends Service
$courseRepo = new CourseRepo(); $courseRepo = new CourseRepo();
/**
* @var Resultset $votes
*/
$votes = $courseRepo->findUserReviewVotes($courseId, $userId); $votes = $courseRepo->findUserReviewVotes($courseId, $userId);
if ($votes->count() == 0) { if ($votes->count() == 0) {

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Caches\CourseTeacherList as CourseTeacherListCache; use App\Caches\CourseTeacherList as CourseTeacherListCache;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
class CourseTeacherList extends Service class TeacherList extends Service
{ {
use CourseTrait; use CourseTrait;
@ -13,9 +15,9 @@ class CourseTeacherList extends Service
{ {
$course = $this->checkCourse($id); $course = $this->checkCourse($id);
$ctListCache = new CourseTeacherListCache(); $listCache = new CourseTeacherListCache();
$teachers = $ctListCache->get($course->id); $teachers = $listCache->get($course->id);
if (!$teachers) return []; if (!$teachers) return [];

View File

@ -1,40 +0,0 @@
<?php
namespace App\Services\Frontend;
use App\Models\CourseUser as CourseUserModel;
use App\Validators\CourseUser as CourseUserValidator;
class CourseUser extends Service
{
use CourseTrait;
public function createUser($id)
{
$course = $this->checkCourse($id);
$user = $this->getLoginUser();
$validator = new CourseUserValidator();
$validator->checkIfAllowApply($course, $user);
$validator->checkIfJoined($course->id, $user->id);
$courseUser = new CourseUserModel();
$courseUser->course_id = $course->id;
$courseUser->user_id = $user->id;
$courseUser->source_type = CourseUserModel::SOURCE_FREE;
$courseUser->role_type = CourseUserModel::ROLE_STUDENT;
$courseUser->expiry_time = strtotime('+3 years');
$courseUser->create();
$course->user_count += 1;
$course->update();
}
}

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\My;
use App\Builders\ConsultList as ConsultListBuilder; use App\Builders\ConsultList as ConsultListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Consult as ConsultRepo; use App\Repos\Consult as ConsultRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class MyConsultList extends Service class ConsultList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -1,13 +1,15 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\My;
use App\Builders\CourseUserList as CourseUserListBuilder; use App\Builders\CourseUserList as CourseUserListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Models\CourseUser as CourseUserModel; use App\Models\CourseUser as CourseUserModel;
use App\Repos\CourseUser as CourseUserRepo; use App\Repos\CourseUser as CourseUserRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class MyCourseList extends Service class CourseList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\My;
use App\Builders\CourseFavoriteList as CourseFavoriteListBuilder; use App\Builders\CourseFavoriteList as CourseFavoriteListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Repos\CourseFavorite as CourseFavoriteRepo; use App\Repos\CourseFavorite as CourseFavoriteRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class MyFavoriteList extends Service class FavoriteList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\My;
use App\Builders\OrderList as OrderListBuilder; use App\Builders\OrderList as OrderListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Order as OrderRepo; use App\Repos\Order as OrderRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class MyOrderList extends Service class OrderList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -1,12 +1,14 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\My;
use App\Builders\RefundList as RefundListBuilder; use App\Builders\RefundList as RefundListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Repos\Refund as RefundRepo; use App\Repos\Refund as RefundRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class MyRefundList extends Service class RefundList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -34,7 +34,7 @@ class OrderCreate extends Service
$orderRepo = new OrderRepo(); $orderRepo = new OrderRepo();
$order = $orderRepo->findLastUserItem($user->id, $post['item_id'], $post['item_type']); $order = $orderRepo->findLastUserOrder($user->id, $post['item_id'], $post['item_type']);
/** /**
* 存在新鲜的未支付订单直接返回(减少订单记录) * 存在新鲜的未支付订单直接返回(减少订单记录)

View File

@ -1,13 +1,15 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\Course;
use App\Models\Review as ReviewModel; use App\Models\Review as ReviewModel;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service;
use App\Validators\Review as ReviewValidator; use App\Validators\Review as ReviewValidator;
use App\Validators\UserDailyLimit as UserDailyLimitValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator;
class CourseReview extends Service class ReviewCreate extends Service
{ {
use CourseTrait; use CourseTrait;

View File

@ -1,13 +1,15 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\User;
use App\Builders\CourseUserList as CourseUserListBuilder; use App\Builders\CourseUserList as CourseUserListBuilder;
use App\Library\Paginator\Query as PagerQuery; use App\Library\Paginator\Query as PagerQuery;
use App\Models\CourseUser as CourseUserModel; use App\Models\CourseUser as CourseUserModel;
use App\Repos\CourseUser as CourseUserRepo; use App\Repos\CourseUser as CourseUserRepo;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class UserCourseList extends Service class CourseList extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -1,10 +1,12 @@
<?php <?php
namespace App\Services\Frontend; namespace App\Services\Frontend\User;
use App\Models\User as UserModel; use App\Models\User as UserModel;
use App\Services\Frontend\Service;
use App\Services\Frontend\UserTrait;
class User extends Service class UserInfo extends Service
{ {
use UserTrait; use UserTrait;

View File

@ -4,8 +4,6 @@ namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException; use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator; use App\Library\Validator\Common as CommonValidator;
use App\Models\Course as CourseModel;
use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo; use App\Repos\Course as CourseRepo;
use App\Repos\CourseUser as CourseUserRepo; use App\Repos\CourseUser as CourseUserRepo;
use App\Repos\User as UserRepo; use App\Repos\User as UserRepo;
@ -67,16 +65,6 @@ class CourseUser extends Validator
return strtotime($value); return strtotime($value);
} }
public function checkIfAllowApply(CourseModel $course, UserModel $user)
{
$caseA = $course->market_price > 0;
$caseB = $user->vip == 0 && $course->vip_price > 0;
if ($caseA || $caseB) {
throw new BadRequestException('course_user.apply_not_allowed');
}
}
public function checkIfJoined($courseId, $userId) public function checkIfJoined($courseId, $userId)
{ {
$repo = new CourseUserRepo(); $repo = new CourseUserRepo();

View File

@ -84,6 +84,7 @@ class Order extends Validator
if (!$item) { if (!$item) {
throw new BadRequestException('order.item_not_found'); throw new BadRequestException('order.item_not_found');
} }
return $item; return $item;
} }
@ -101,7 +102,7 @@ class Order extends Validator
public function checkIfAllowCancel($order) public function checkIfAllowCancel($order)
{ {
if ($order->status != OrderModel::STATUS_PENDING) { if ($order->status != OrderModel::STATUS_PENDING) {
throw new BadRequestException('order.invalid_status_action'); throw new BadRequestException('order.cancel_not_allowed');
} }
} }

View File

@ -22,13 +22,6 @@ class Refund extends Validator
return $trade; return $trade;
} }
public function checkReviewAction($refund)
{
if ($refund->status != RefundModel::STATUS_PENDING) {
throw new BadRequestException('refund.invalid_review_action');
}
}
public function checkReviewStatus($status) public function checkReviewStatus($status)
{ {
$list = [RefundModel::STATUS_APPROVED, RefundModel::STATUS_REFUSED]; $list = [RefundModel::STATUS_APPROVED, RefundModel::STATUS_REFUSED];
@ -74,4 +67,11 @@ class Refund extends Validator
return $value; return $value;
} }
public function checkIfAllowReview($refund)
{
if ($refund->status != RefundModel::STATUS_PENDING) {
throw new BadRequestException('refund.review_not_allowed');
}
}
} }

View File

@ -259,7 +259,7 @@ $error['refund.apply_note_too_short'] = '退款原因太短少于2个字符
$error['refund.apply_note_too_long'] = '退款原因太长多于255个字符'; $error['refund.apply_note_too_long'] = '退款原因太长多于255个字符';
$error['refund.review_note_too_short'] = '审核备注太短少于2个字符'; $error['refund.review_note_too_short'] = '审核备注太短少于2个字符';
$error['refund.review_note_too_long'] = '审核备注太长多于255个字符'; $error['refund.review_note_too_long'] = '审核备注太长多于255个字符';
$error['refund.invalid_review_action'] = '无效的审核操作'; $error['refund.review_not_allowed'] = '当前不允许审核退款';
$error['refund.invalid_review_status'] = '无效的审核状态'; $error['refund.invalid_review_status'] = '无效的审核状态';
/** /**

View File

@ -13,7 +13,7 @@ $bin = '/usr/bin/php';
$scheduler->php($script, $bin, ['--task' => 'learning', '--action' => 'main']) $scheduler->php($script, $bin, ['--task' => 'learning', '--action' => 'main'])
->at('*/3 * * * *'); ->at('*/3 * * * *');
$scheduler->php($script, $bin, ['--task' => 'process_order', '--action' => 'main']) $scheduler->php($script, $bin, ['--task' => 'order', '--action' => 'main'])
->at('*/5 * * * *'); ->at('*/5 * * * *');
$scheduler->php($script, $bin, ['--task' => 'vod_event', '--action' => 'main']) $scheduler->php($script, $bin, ['--task' => 'vod_event', '--action' => 'main'])