mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-12 19:39:10 +08:00
一个接口对应一个service
This commit is contained in:
parent
5ba8250f8a
commit
160700728e
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Caches;
|
|
||||||
|
|
||||||
class IndexHotTeacherList extends Cache
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $lifetime = 365 * 86400;
|
|
||||||
|
|
||||||
public function getLifetime()
|
|
||||||
{
|
|
||||||
return $this->lifetime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getKey($id = null)
|
|
||||||
{
|
|
||||||
return 'hot_teacher_list';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getContent($id = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function handleContent($users)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -26,9 +26,21 @@ class TestController extends Controller
|
|||||||
{
|
{
|
||||||
$storageService = new StorageService();
|
$storageService = new StorageService();
|
||||||
|
|
||||||
$result = $storageService->uploadTestFile();
|
$result = [];
|
||||||
|
|
||||||
if ($result) {
|
$result['hello'] = $storageService->uploadTestFile();
|
||||||
|
|
||||||
|
$avatarPath = public_path('static/admin/img/default_avatar.png');
|
||||||
|
$avatarKey = '/img/avatar/default.png';
|
||||||
|
|
||||||
|
$result['avatar'] = $storageService->putFile($avatarKey, $avatarPath);
|
||||||
|
|
||||||
|
$coverPath = public_path('static/admin/img/default_cover.png');
|
||||||
|
$coverKey = '/img/cover/default.png';
|
||||||
|
|
||||||
|
$result['cover'] = $storageService->putFile($coverKey, $coverPath);
|
||||||
|
|
||||||
|
if ($result['hello'] && $result['avatar'] && $result['cover']) {
|
||||||
return $this->jsonSuccess(['msg' => '上传文件成功,请到控制台确认']);
|
return $this->jsonSuccess(['msg' => '上传文件成功,请到控制台确认']);
|
||||||
} else {
|
} else {
|
||||||
return $this->jsonError(['msg' => '上传文件失败,请检查相关配置']);
|
return $this->jsonError(['msg' => '上传文件失败,请检查相关配置']);
|
||||||
|
@ -172,9 +172,7 @@ function kg_ci_base_url()
|
|||||||
*/
|
*/
|
||||||
function kg_ci_img_url($path, $width = 0, $height = 0)
|
function kg_ci_img_url($path, $width = 0, $height = 0)
|
||||||
{
|
{
|
||||||
if (empty($path)) {
|
if (!$path) return '';
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Text::startsWith($path, 'http')) {
|
if (Text::startsWith($path, 'http')) {
|
||||||
return $path;
|
return $path;
|
||||||
|
@ -306,7 +306,7 @@ class Course extends Model
|
|||||||
$this->score = (float)$this->score;
|
$this->score = (float)$this->score;
|
||||||
|
|
||||||
if (!Text::startsWith($this->cover, 'http')) {
|
if (!Text::startsWith($this->cover, 'http')) {
|
||||||
$this->cover = kg_ci_img_url($this->cover);
|
$this->cover = kg_ci_cover_img_url($this->cover);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->attrs)) {
|
if (!empty($this->attrs)) {
|
||||||
|
@ -130,7 +130,7 @@ class Slide extends Model
|
|||||||
public function afterFetch()
|
public function afterFetch()
|
||||||
{
|
{
|
||||||
if (!Text::startsWith($this->cover, 'http')) {
|
if (!Text::startsWith($this->cover, 'http')) {
|
||||||
$this->cover = kg_ci_img_url($this->cover);
|
$this->cover = kg_ci_cover_img_url($this->cover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ class User extends Model
|
|||||||
public function afterFetch()
|
public function afterFetch()
|
||||||
{
|
{
|
||||||
if (!Text::startsWith($this->avatar, 'http')) {
|
if (!Text::startsWith($this->avatar, 'http')) {
|
||||||
$this->avatar = kg_ci_img_url($this->avatar);
|
$this->avatar = kg_ci_avatar_img_url($this->avatar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ interface ProviderInterface extends InjectionAwareInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register application service.
|
* RegisterByPhone application service.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,7 @@ use App\Validators\Security as SecurityValidator;
|
|||||||
class EmailUpdate extends Service
|
class EmailUpdate extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function updateEmail()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use App\Validators\Security as SecurityValidator;
|
|||||||
class PasswordReset extends Service
|
class PasswordReset extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function resetPassword()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ use App\Validators\Account as AccountValidator;
|
|||||||
class PasswordUpdate extends Service
|
class PasswordUpdate extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function updatePassword()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use App\Validators\Security as SecurityValidator;
|
|||||||
class PhoneUpdate extends Service
|
class PhoneUpdate extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function updatePhone()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -7,34 +7,10 @@ use App\Services\Frontend\Service;
|
|||||||
use App\Validators\Account as AccountValidator;
|
use App\Validators\Account as AccountValidator;
|
||||||
use App\Validators\Security as SecurityValidator;
|
use App\Validators\Security as SecurityValidator;
|
||||||
|
|
||||||
class Register extends Service
|
class RegisterByEmail extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function registerByPhone()
|
public function handle()
|
||||||
{
|
|
||||||
$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 registerByEmail()
|
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
37
app/Services/Frontend/Account/RegisterByPhone.php
Normal file
37
app/Services/Frontend/Account/RegisterByPhone.php
Normal 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 RegisterByPhone extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
app/Services/Frontend/Chapter/AgreeVote.php
Normal file
73
app/Services/Frontend/Chapter/AgreeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Chapter;
|
||||||
|
|
||||||
|
use App\Models\ChapterVote as ChapterVoteModel;
|
||||||
|
use App\Repos\ChapterVote as ChapterVoteRepo;
|
||||||
|
use App\Services\Frontend\ChapterTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class AgreeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ChapterTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$chapter = $this->checkChapter($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkChapterVoteLimit($user);
|
||||||
|
|
||||||
|
$chapterVoteRepo = new ChapterVoteRepo();
|
||||||
|
|
||||||
|
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
|
||||||
|
|
||||||
|
if (!$chapterVote) {
|
||||||
|
|
||||||
|
$chapterVote = new ChapterVoteModel();
|
||||||
|
|
||||||
|
$chapterVote->chapter_id = $chapter->id;
|
||||||
|
$chapterVote->user_id = $user->id;
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$chapterVote->create();
|
||||||
|
|
||||||
|
$this->incrAgreeCount($chapter);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($chapter);
|
||||||
|
|
||||||
|
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($chapter);
|
||||||
|
|
||||||
|
$this->decrOpposeCount($chapter);
|
||||||
|
|
||||||
|
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chapterVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyChapterVoteCount($user);
|
||||||
|
|
||||||
|
return $chapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -32,7 +32,7 @@ class ChapterInfo extends Service
|
|||||||
|
|
||||||
use CourseTrait, ChapterTrait;
|
use CourseTrait, ChapterTrait;
|
||||||
|
|
||||||
public function getChapter($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$chapter = $this->checkChapter($id);
|
$chapter = $this->checkChapter($id);
|
||||||
|
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Frontend\Chapter;
|
|
||||||
|
|
||||||
use App\Models\Chapter as ChapterModel;
|
|
||||||
use App\Models\ChapterVote as ChapterVoteModel;
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use App\Repos\ChapterVote as ChapterVoteRepo;
|
|
||||||
use App\Services\Frontend\ChapterTrait;
|
|
||||||
use App\Services\Frontend\Service;
|
|
||||||
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|
||||||
|
|
||||||
class ChapterVote extends Service
|
|
||||||
{
|
|
||||||
|
|
||||||
use ChapterTrait;
|
|
||||||
|
|
||||||
public function agree($id)
|
|
||||||
{
|
|
||||||
$chapter = $this->checkChapter($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkChapterVoteLimit($user);
|
|
||||||
|
|
||||||
$chapterVoteRepo = new ChapterVoteRepo();
|
|
||||||
|
|
||||||
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
|
|
||||||
|
|
||||||
if (!$chapterVote) {
|
|
||||||
|
|
||||||
$chapterVote = new ChapterVoteModel();
|
|
||||||
|
|
||||||
$chapterVote->chapter_id = $chapter->id;
|
|
||||||
$chapterVote->user_id = $user->id;
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$chapterVote->create();
|
|
||||||
|
|
||||||
$this->incrAgreeCount($chapter);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($chapter);
|
|
||||||
|
|
||||||
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($chapter);
|
|
||||||
|
|
||||||
$this->decrOpposeCount($chapter);
|
|
||||||
|
|
||||||
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
$chapterVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyChapterVoteCount($user);
|
|
||||||
|
|
||||||
return $chapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function oppose($id)
|
|
||||||
{
|
|
||||||
$chapter = $this->checkChapter($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkChapterVoteLimit($user);
|
|
||||||
|
|
||||||
$chapterVoteRepo = new ChapterVoteRepo();
|
|
||||||
|
|
||||||
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
|
|
||||||
|
|
||||||
if (!$chapterVote) {
|
|
||||||
|
|
||||||
$chapterVote = new ChapterVoteModel();
|
|
||||||
|
|
||||||
$chapterVote->chapter_id = $chapter->id;
|
|
||||||
$chapterVote->user_id = $user->id;
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$chapterVote->create();
|
|
||||||
|
|
||||||
$this->incrOpposeCount($chapter);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($chapter);
|
|
||||||
|
|
||||||
$this->incrOpposeCount($chapter);
|
|
||||||
|
|
||||||
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrOpposeCount($chapter);
|
|
||||||
|
|
||||||
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->incrOpposeCount($chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
$chapterVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyChapterVoteCount($user);
|
|
||||||
|
|
||||||
return $chapter;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrAgreeCount(ChapterModel $chapter)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('chapterCounter:incrAgreeCount', $this, $chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrAgreeCount(ChapterModel $chapter)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('chapterCounter:decrAgreeCount', $this, $chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrOpposeCount(ChapterModel $chapter)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('chapterCounter:incrOpposeCount', $this, $chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrOpposeCount(ChapterModel $chapter)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('chapterCounter:decrOpposeCount', $this, $chapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrUserDailyChapterVoteCount(UserModel $user)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('userDailyCounter:incrChapterVoteCount', $this, $user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ class CommentList extends Service
|
|||||||
|
|
||||||
use ChapterTrait;
|
use ChapterTrait;
|
||||||
|
|
||||||
public function getComments($chapterId)
|
public function handle($chapterId)
|
||||||
{
|
{
|
||||||
$this->chapter = $this->checkChapter($chapterId);
|
$this->chapter = $this->checkChapter($chapterId);
|
||||||
|
|
||||||
|
73
app/Services/Frontend/Chapter/OpposeVote.php
Normal file
73
app/Services/Frontend/Chapter/OpposeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Chapter;
|
||||||
|
|
||||||
|
use App\Models\ChapterVote as ChapterVoteModel;
|
||||||
|
use App\Repos\ChapterVote as ChapterVoteRepo;
|
||||||
|
use App\Services\Frontend\ChapterTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class OpposeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ChapterTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$chapter = $this->checkChapter($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkChapterVoteLimit($user);
|
||||||
|
|
||||||
|
$chapterVoteRepo = new ChapterVoteRepo();
|
||||||
|
|
||||||
|
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
|
||||||
|
|
||||||
|
if (!$chapterVote) {
|
||||||
|
|
||||||
|
$chapterVote = new ChapterVoteModel();
|
||||||
|
|
||||||
|
$chapterVote->chapter_id = $chapter->id;
|
||||||
|
$chapterVote->user_id = $user->id;
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$chapterVote->create();
|
||||||
|
|
||||||
|
$this->incrOpposeCount($chapter);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($chapter);
|
||||||
|
|
||||||
|
$this->incrOpposeCount($chapter);
|
||||||
|
|
||||||
|
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrOpposeCount($chapter);
|
||||||
|
|
||||||
|
} elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$chapterVote->type = ChapterVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->incrOpposeCount($chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
$chapterVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyChapterVoteCount($user);
|
||||||
|
|
||||||
|
return $chapter;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
app/Services/Frontend/Chapter/VoteTrait.php
Normal file
36
app/Services/Frontend/Chapter/VoteTrait.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Chapter;
|
||||||
|
|
||||||
|
use App\Models\Chapter as ChapterModel;
|
||||||
|
use App\Models\User as UserModel;
|
||||||
|
|
||||||
|
trait VoteTrait
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function incrAgreeCount(ChapterModel $chapter)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('chapterCounter:incrAgreeCount', $this, $chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrAgreeCount(ChapterModel $chapter)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('chapterCounter:decrAgreeCount', $this, $chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrOpposeCount(ChapterModel $chapter)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('chapterCounter:incrOpposeCount', $this, $chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrOpposeCount(ChapterModel $chapter)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('chapterCounter:decrOpposeCount', $this, $chapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrUserDailyChapterVoteCount(UserModel $user)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('userDailyCounter:incrChapterVoteCount', $this, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
app/Services/Frontend/Comment/AgreeVote.php
Normal file
73
app/Services/Frontend/Comment/AgreeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Comment;
|
||||||
|
|
||||||
|
use App\Models\CommentVote as CommentVoteModel;
|
||||||
|
use App\Repos\CommentVote as CommentVoteRepo;
|
||||||
|
use App\Services\Frontend\CommentTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class AgreeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use CommentTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$comment = $this->checkComment($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkCommentVoteLimit($user);
|
||||||
|
|
||||||
|
$commentVoteRepo = new CommentVoteRepo();
|
||||||
|
|
||||||
|
$commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id);
|
||||||
|
|
||||||
|
if (!$commentVote) {
|
||||||
|
|
||||||
|
$commentVote = new CommentVoteModel();
|
||||||
|
|
||||||
|
$commentVote->comment_id = $comment->id;
|
||||||
|
$commentVote->user_id = $user->id;
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$commentVote->create();
|
||||||
|
|
||||||
|
$this->incrAgreeCount($comment);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($commentVote->type == CommentVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($comment);
|
||||||
|
|
||||||
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($comment);
|
||||||
|
|
||||||
|
$this->decrOpposeCount($comment);
|
||||||
|
|
||||||
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commentVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyCommentVoteCount($user);
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,7 +17,7 @@ class CommentCreate extends Service
|
|||||||
|
|
||||||
use ChapterTrait, CourseTrait;
|
use ChapterTrait, CourseTrait;
|
||||||
|
|
||||||
public function createComment()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class CommentDelete extends Service
|
|||||||
|
|
||||||
use CommentTrait, ChapterTrait, CourseTrait;
|
use CommentTrait, ChapterTrait, CourseTrait;
|
||||||
|
|
||||||
public function deleteComment($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$comment = $this->checkComment($id);
|
$comment = $this->checkComment($id);
|
||||||
|
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Frontend\Comment;
|
|
||||||
|
|
||||||
use App\Models\Comment as CommentModel;
|
|
||||||
use App\Models\CommentVote as CommentVoteModel;
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use App\Repos\CommentVote as CommentVoteRepo;
|
|
||||||
use App\Services\Frontend\CommentTrait;
|
|
||||||
use App\Services\Frontend\Service;
|
|
||||||
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|
||||||
|
|
||||||
class CommentVote extends Service
|
|
||||||
{
|
|
||||||
|
|
||||||
use CommentTrait;
|
|
||||||
|
|
||||||
public function agree($id)
|
|
||||||
{
|
|
||||||
$comment = $this->checkComment($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkCommentVoteLimit($user);
|
|
||||||
|
|
||||||
$commentVoteRepo = new CommentVoteRepo();
|
|
||||||
|
|
||||||
$commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id);
|
|
||||||
|
|
||||||
if (!$commentVote) {
|
|
||||||
|
|
||||||
$commentVote = new CommentVoteModel();
|
|
||||||
|
|
||||||
$commentVote->comment_id = $comment->id;
|
|
||||||
$commentVote->user_id = $user->id;
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$commentVote->create();
|
|
||||||
|
|
||||||
$this->incrAgreeCount($comment);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($commentVote->type == CommentVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($comment);
|
|
||||||
|
|
||||||
} elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($comment);
|
|
||||||
|
|
||||||
$this->decrOpposeCount($comment);
|
|
||||||
|
|
||||||
} elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
$commentVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyCommentVoteCount($user);
|
|
||||||
|
|
||||||
return $comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function oppose($id)
|
|
||||||
{
|
|
||||||
$comment = $this->checkComment($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkCommentVoteLimit($user);
|
|
||||||
|
|
||||||
$commentVoteRepo = new CommentVoteRepo();
|
|
||||||
|
|
||||||
$commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id);
|
|
||||||
|
|
||||||
if (!$commentVote) {
|
|
||||||
|
|
||||||
$commentVote = new CommentVoteModel();
|
|
||||||
|
|
||||||
$commentVote->comment_id = $comment->id;
|
|
||||||
$commentVote->user_id = $user->id;
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$commentVote->create();
|
|
||||||
|
|
||||||
$this->incrOpposeCount($comment);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($commentVote->type == CommentVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($comment);
|
|
||||||
|
|
||||||
$this->incrOpposeCount($comment);
|
|
||||||
|
|
||||||
} elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrOpposeCount($comment);
|
|
||||||
|
|
||||||
} elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->incrOpposeCount($comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
$commentVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyCommentVoteCount($user);
|
|
||||||
|
|
||||||
return $comment;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrAgreeCount(CommentModel $comment)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('commentCounter:incrAgreeCount', $this, $comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrAgreeCount(CommentModel $comment)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('commentCounter:decrAgreeCount', $this, $comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrOpposeCount(CommentModel $comment)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('commentCounter:incrOpposeCount', $this, $comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrOpposeCount(CommentModel $comment)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('commentCounter:decrOpposeCount', $this, $comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrUserDailyCommentVoteCount(UserModel $user)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('userDailyCounter:incrCommentVoteCount', $this, $user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
73
app/Services/Frontend/Comment/OpposeVote.php
Normal file
73
app/Services/Frontend/Comment/OpposeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Comment;
|
||||||
|
|
||||||
|
use App\Models\CommentVote as CommentVoteModel;
|
||||||
|
use App\Repos\CommentVote as CommentVoteRepo;
|
||||||
|
use App\Services\Frontend\CommentTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class OpposeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use CommentTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$comment = $this->checkComment($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkCommentVoteLimit($user);
|
||||||
|
|
||||||
|
$commentVoteRepo = new CommentVoteRepo();
|
||||||
|
|
||||||
|
$commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id);
|
||||||
|
|
||||||
|
if (!$commentVote) {
|
||||||
|
|
||||||
|
$commentVote = new CommentVoteModel();
|
||||||
|
|
||||||
|
$commentVote->comment_id = $comment->id;
|
||||||
|
$commentVote->user_id = $user->id;
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$commentVote->create();
|
||||||
|
|
||||||
|
$this->incrOpposeCount($comment);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($commentVote->type == CommentVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($comment);
|
||||||
|
|
||||||
|
$this->incrOpposeCount($comment);
|
||||||
|
|
||||||
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrOpposeCount($comment);
|
||||||
|
|
||||||
|
} elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$commentVote->type = CommentVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->incrOpposeCount($comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
$commentVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyCommentVoteCount($user);
|
||||||
|
|
||||||
|
return $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
app/Services/Frontend/Comment/VoteTrait.php
Normal file
36
app/Services/Frontend/Comment/VoteTrait.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Comment;
|
||||||
|
|
||||||
|
use App\Models\Comment as CommentModel;
|
||||||
|
use App\Models\User as UserModel;
|
||||||
|
|
||||||
|
trait VoteTrait
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function incrAgreeCount(CommentModel $comment)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('commentCounter:incrAgreeCount', $this, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrAgreeCount(CommentModel $comment)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('commentCounter:decrAgreeCount', $this, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrOpposeCount(CommentModel $comment)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('commentCounter:incrOpposeCount', $this, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrOpposeCount(CommentModel $comment)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('commentCounter:decrOpposeCount', $this, $comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrUserDailyCommentVoteCount(UserModel $user)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('userDailyCounter:incrCommentVoteCount', $this, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
app/Services/Frontend/Consult/AgreeVote.php
Normal file
73
app/Services/Frontend/Consult/AgreeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Consult;
|
||||||
|
|
||||||
|
use App\Models\ConsultVote as ConsultVoteModel;
|
||||||
|
use App\Repos\ConsultVote as ConsultVoteRepo;
|
||||||
|
use App\Services\Frontend\ConsultTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class AgreeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ConsultTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handleAgreeVote($id)
|
||||||
|
{
|
||||||
|
$consult = $this->checkConsult($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkConsultVoteLimit($user);
|
||||||
|
|
||||||
|
$consultVoteRepo = new ConsultVoteRepo();
|
||||||
|
|
||||||
|
$consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id);
|
||||||
|
|
||||||
|
if (!$consultVote) {
|
||||||
|
|
||||||
|
$consultVote = new ConsultVoteModel();
|
||||||
|
|
||||||
|
$consultVote->consult_id = $consult->id;
|
||||||
|
$consultVote->user_id = $user->id;
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$consultVote->create();
|
||||||
|
|
||||||
|
$this->incrAgreeCount($consult);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($consult);
|
||||||
|
|
||||||
|
} elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($consult);
|
||||||
|
|
||||||
|
$this->decrOpposeCount($consult);
|
||||||
|
|
||||||
|
} elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
$consultVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyConsultVoteCount($user);
|
||||||
|
|
||||||
|
return $consult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,7 +15,7 @@ class ConsultCreate extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function createConsult()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Frontend\Consult;
|
|
||||||
|
|
||||||
use App\Models\Consult as ConsultModel;
|
|
||||||
use App\Models\ConsultVote as ConsultVoteModel;
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use App\Repos\ConsultVote as ConsultVoteRepo;
|
|
||||||
use App\Services\Frontend\ConsultTrait;
|
|
||||||
use App\Services\Frontend\Service;
|
|
||||||
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|
||||||
|
|
||||||
class ConsultVote extends Service
|
|
||||||
{
|
|
||||||
|
|
||||||
use ConsultTrait;
|
|
||||||
|
|
||||||
public function agree($id)
|
|
||||||
{
|
|
||||||
$consult = $this->checkConsult($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkConsultVoteLimit($user);
|
|
||||||
|
|
||||||
$consultVoteRepo = new ConsultVoteRepo();
|
|
||||||
|
|
||||||
$consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id);
|
|
||||||
|
|
||||||
if (!$consultVote) {
|
|
||||||
|
|
||||||
$consultVote = new ConsultVoteModel();
|
|
||||||
|
|
||||||
$consultVote->consult_id = $consult->id;
|
|
||||||
$consultVote->user_id = $user->id;
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$consultVote->create();
|
|
||||||
|
|
||||||
$this->incrAgreeCount($consult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($consult);
|
|
||||||
|
|
||||||
} elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($consult);
|
|
||||||
|
|
||||||
$this->decrOpposeCount($consult);
|
|
||||||
|
|
||||||
} elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
$consultVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyConsultVoteCount($user);
|
|
||||||
|
|
||||||
return $consult;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function oppose($id)
|
|
||||||
{
|
|
||||||
$consult = $this->checkConsult($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkConsultVoteLimit($user);
|
|
||||||
|
|
||||||
$consultVoteRepo = new ConsultVoteRepo();
|
|
||||||
|
|
||||||
$consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id);
|
|
||||||
|
|
||||||
if (!$consultVote) {
|
|
||||||
|
|
||||||
$consultVote = new ConsultVoteModel();
|
|
||||||
|
|
||||||
$consultVote->consult_id = $consult->id;
|
|
||||||
$consultVote->user_id = $user->id;
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$consultVote->create();
|
|
||||||
|
|
||||||
$this->incrOpposeCount($consult);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($consult);
|
|
||||||
|
|
||||||
$this->incrOpposeCount($consult);
|
|
||||||
|
|
||||||
} elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrOpposeCount($consult);
|
|
||||||
|
|
||||||
} elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->incrOpposeCount($consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
$consultVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyConsultVoteCount($user);
|
|
||||||
|
|
||||||
return $consult;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrAgreeCount(ConsultModel $consult)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('consultCounter:incrAgreeCount', $this, $consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrAgreeCount(ConsultModel $consult)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('consultCounter:decrAgreeCount', $this, $consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrOpposeCount(ConsultModel $consult)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('consultCounter:incrOpposeCount', $this, $consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrOpposeCount(ConsultModel $consult)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('consultCounter:decrOpposeCount', $this, $consult);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrUserDailyConsultVoteCount(UserModel $user)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('userDailyCounter:incrConsultVoteCount', $this, $user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
73
app/Services/Frontend/Consult/OpposeVote.php
Normal file
73
app/Services/Frontend/Consult/OpposeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Consult;
|
||||||
|
|
||||||
|
use App\Models\ConsultVote as ConsultVoteModel;
|
||||||
|
use App\Repos\ConsultVote as ConsultVoteRepo;
|
||||||
|
use App\Services\Frontend\ConsultTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class OpposeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ConsultTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$consult = $this->checkConsult($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkConsultVoteLimit($user);
|
||||||
|
|
||||||
|
$consultVoteRepo = new ConsultVoteRepo();
|
||||||
|
|
||||||
|
$consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id);
|
||||||
|
|
||||||
|
if (!$consultVote) {
|
||||||
|
|
||||||
|
$consultVote = new ConsultVoteModel();
|
||||||
|
|
||||||
|
$consultVote->consult_id = $consult->id;
|
||||||
|
$consultVote->user_id = $user->id;
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$consultVote->create();
|
||||||
|
|
||||||
|
$this->incrOpposeCount($consult);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($consult);
|
||||||
|
|
||||||
|
$this->incrOpposeCount($consult);
|
||||||
|
|
||||||
|
} elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrOpposeCount($consult);
|
||||||
|
|
||||||
|
} elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$consultVote->type = ConsultVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->incrOpposeCount($consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
$consultVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyConsultVoteCount($user);
|
||||||
|
|
||||||
|
return $consult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
36
app/Services/Frontend/Consult/VoteTrait.php
Normal file
36
app/Services/Frontend/Consult/VoteTrait.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Consult;
|
||||||
|
|
||||||
|
use App\Models\Consult as ConsultModel;
|
||||||
|
use App\Models\User as UserModel;
|
||||||
|
|
||||||
|
trait VoteTrait
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function incrAgreeCount(ConsultModel $consult)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('consultCounter:incrAgreeCount', $this, $consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrAgreeCount(ConsultModel $consult)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('consultCounter:decrAgreeCount', $this, $consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrOpposeCount(ConsultModel $consult)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('consultCounter:incrOpposeCount', $this, $consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrOpposeCount(ConsultModel $consult)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('consultCounter:decrOpposeCount', $this, $consult);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrUserDailyConsultVoteCount(UserModel $user)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('userDailyCounter:incrConsultVoteCount', $this, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -28,7 +28,7 @@ class ConsultList extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function getConsults($courseId)
|
public function handle($courseId)
|
||||||
{
|
{
|
||||||
$this->course = $this->checkCourse($courseId);
|
$this->course = $this->checkCourse($courseId);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class CourseFavorite extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function saveFavorite($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$course = $this->checkCourse($id);
|
$course = $this->checkCourse($id);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class CourseInfo extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function getCourse($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$course = $this->checkCourseCache($id);
|
$course = $this->checkCourseCache($id);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ use App\Services\Frontend\Service;
|
|||||||
class CourseList extends Service
|
class CourseList extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function getCourses()
|
public function handle()
|
||||||
{
|
{
|
||||||
$pagerQuery = new PagerQuery();
|
$pagerQuery = new PagerQuery();
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class CourseRelated extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function getRelated($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$course = $this->checkCourse($id);
|
$course = $this->checkCourse($id);
|
||||||
|
|
||||||
|
@ -6,25 +6,21 @@ use App\Caches\CoursePackageList as CoursePackageListCache;
|
|||||||
use App\Caches\PackageCourseList as PackageCourseListCache;
|
use App\Caches\PackageCourseList as PackageCourseListCache;
|
||||||
use App\Services\Frontend\CourseTrait;
|
use App\Services\Frontend\CourseTrait;
|
||||||
use App\Services\Frontend\Service;
|
use App\Services\Frontend\Service;
|
||||||
use Yansongda\Supports\Collection;
|
|
||||||
|
|
||||||
class PackageList extends Service
|
class PackageList extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function getPackages($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$course = $this->checkCourseCache($id);
|
$course = $this->checkCourseCache($id);
|
||||||
|
|
||||||
$cache = new CoursePackageListCache();
|
$cache = new CoursePackageListCache();
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Collection $packages
|
|
||||||
*/
|
|
||||||
$packages = $cache->get($course->id);
|
$packages = $cache->get($course->id);
|
||||||
|
|
||||||
if ($packages->count() == 0) {
|
if (!$packages) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,12 +30,9 @@ class PackageList extends Service
|
|||||||
|
|
||||||
foreach ($packages->toArray() as $package) {
|
foreach ($packages->toArray() as $package) {
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Collection $courses
|
|
||||||
*/
|
|
||||||
$courses = $cache->get($package['id']);
|
$courses = $cache->get($package['id']);
|
||||||
|
|
||||||
$package['courses'] = $courses->count() > 0 ? $courses->toArray() : [];
|
$package['courses'] = $courses ?: [];
|
||||||
|
|
||||||
$result[] = $package;
|
$result[] = $package;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class ReviewList extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function getReviews($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$this->course = $this->checkCourse($id);
|
$this->course = $this->checkCourse($id);
|
||||||
|
|
||||||
|
@ -9,4 +9,10 @@ class CourseList extends Service
|
|||||||
{
|
{
|
||||||
|
|
||||||
use PackageTrait;
|
use PackageTrait;
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class PackageInfo extends Service
|
|||||||
|
|
||||||
use PackageTrait;
|
use PackageTrait;
|
||||||
|
|
||||||
public function getPackage($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$package = $this->checkPackageCache($id);
|
$package = $this->checkPackageCache($id);
|
||||||
|
|
||||||
|
73
app/Services/Frontend/Review/AgreeVote.php
Normal file
73
app/Services/Frontend/Review/AgreeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Review;
|
||||||
|
|
||||||
|
use App\Models\ReviewVote as ReviewVoteModel;
|
||||||
|
use App\Repos\ReviewVote as ReviewVoteRepo;
|
||||||
|
use App\Services\Frontend\ReviewTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class AgreeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ReviewTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$review = $this->checkReview($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkReviewVoteLimit($user);
|
||||||
|
|
||||||
|
$reviewVoteRepo = new ReviewVoteRepo();
|
||||||
|
|
||||||
|
$reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id);
|
||||||
|
|
||||||
|
if (!$reviewVote) {
|
||||||
|
|
||||||
|
$reviewVote = new ReviewVoteModel();
|
||||||
|
|
||||||
|
$reviewVote->review_id = $review->id;
|
||||||
|
$reviewVote->user_id = $user->id;
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$reviewVote->create();
|
||||||
|
|
||||||
|
$this->incrAgreeCount($review);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($review);
|
||||||
|
|
||||||
|
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($review);
|
||||||
|
|
||||||
|
$this->decrOpposeCount($review);
|
||||||
|
|
||||||
|
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
||||||
|
|
||||||
|
$this->incrAgreeCount($review);
|
||||||
|
}
|
||||||
|
|
||||||
|
$reviewVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyReviewVoteCount($user);
|
||||||
|
|
||||||
|
return $review;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
73
app/Services/Frontend/Review/OpposeVote.php
Normal file
73
app/Services/Frontend/Review/OpposeVote.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Review;
|
||||||
|
|
||||||
|
use App\Models\ReviewVote as ReviewVoteModel;
|
||||||
|
use App\Repos\ReviewVote as ReviewVoteRepo;
|
||||||
|
use App\Services\Frontend\ReviewTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
|
class OpposeVote extends Service
|
||||||
|
{
|
||||||
|
|
||||||
|
use ReviewTrait, VoteTrait;
|
||||||
|
|
||||||
|
public function handle($id)
|
||||||
|
{
|
||||||
|
$review = $this->checkReview($id);
|
||||||
|
|
||||||
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
|
$validator = new UserDailyLimitValidator();
|
||||||
|
|
||||||
|
$validator->checkReviewVoteLimit($user);
|
||||||
|
|
||||||
|
$reviewVoteRepo = new ReviewVoteRepo();
|
||||||
|
|
||||||
|
$reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id);
|
||||||
|
|
||||||
|
if (!$reviewVote) {
|
||||||
|
|
||||||
|
$reviewVote = new ReviewVoteModel();
|
||||||
|
|
||||||
|
$reviewVote->review_id = $review->id;
|
||||||
|
$reviewVote->user_id = $user->id;
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$reviewVote->create();
|
||||||
|
|
||||||
|
$this->incrOpposeCount($review);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->decrAgreeCount($review);
|
||||||
|
|
||||||
|
$this->incrOpposeCount($review);
|
||||||
|
|
||||||
|
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_NONE;
|
||||||
|
|
||||||
|
$this->decrOpposeCount($review);
|
||||||
|
|
||||||
|
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) {
|
||||||
|
|
||||||
|
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
||||||
|
|
||||||
|
$this->incrOpposeCount($review);
|
||||||
|
}
|
||||||
|
|
||||||
|
$reviewVote->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->incrUserDailyReviewVoteCount($user);
|
||||||
|
|
||||||
|
return $review;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,7 +15,7 @@ class ReviewCreate extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function createReview()
|
public function handle()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Services\Frontend\Review;
|
|
||||||
|
|
||||||
use App\Models\Review as ReviewModel;
|
|
||||||
use App\Models\ReviewVote as ReviewVoteModel;
|
|
||||||
use App\Models\User as UserModel;
|
|
||||||
use App\Repos\ReviewVote as ReviewVoteRepo;
|
|
||||||
use App\Services\Frontend\ReviewTrait;
|
|
||||||
use App\Services\Frontend\Service;
|
|
||||||
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|
||||||
|
|
||||||
class ReviewVote extends Service
|
|
||||||
{
|
|
||||||
|
|
||||||
use ReviewTrait;
|
|
||||||
|
|
||||||
public function agree($id)
|
|
||||||
{
|
|
||||||
$review = $this->checkReview($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkReviewVoteLimit($user);
|
|
||||||
|
|
||||||
$reviewVoteRepo = new ReviewVoteRepo();
|
|
||||||
|
|
||||||
$reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id);
|
|
||||||
|
|
||||||
if (!$reviewVote) {
|
|
||||||
|
|
||||||
$reviewVote = new ReviewVoteModel();
|
|
||||||
|
|
||||||
$reviewVote->review_id = $review->id;
|
|
||||||
$reviewVote->user_id = $user->id;
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$reviewVote->create();
|
|
||||||
|
|
||||||
$this->incrAgreeCount($review);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($review);
|
|
||||||
|
|
||||||
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($review);
|
|
||||||
|
|
||||||
$this->decrOpposeCount($review);
|
|
||||||
|
|
||||||
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_AGREE;
|
|
||||||
|
|
||||||
$this->incrAgreeCount($review);
|
|
||||||
}
|
|
||||||
|
|
||||||
$reviewVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyReviewVoteCount($user);
|
|
||||||
|
|
||||||
return $review;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function oppose($id)
|
|
||||||
{
|
|
||||||
$review = $this->checkReview($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
|
||||||
|
|
||||||
$validator->checkReviewVoteLimit($user);
|
|
||||||
|
|
||||||
$reviewVoteRepo = new ReviewVoteRepo();
|
|
||||||
|
|
||||||
$reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id);
|
|
||||||
|
|
||||||
if (!$reviewVote) {
|
|
||||||
|
|
||||||
$reviewVote = new ReviewVoteModel();
|
|
||||||
|
|
||||||
$reviewVote->review_id = $review->id;
|
|
||||||
$reviewVote->user_id = $user->id;
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$reviewVote->create();
|
|
||||||
|
|
||||||
$this->incrOpposeCount($review);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->decrAgreeCount($review);
|
|
||||||
|
|
||||||
$this->incrOpposeCount($review);
|
|
||||||
|
|
||||||
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_NONE;
|
|
||||||
|
|
||||||
$this->decrOpposeCount($review);
|
|
||||||
|
|
||||||
} elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) {
|
|
||||||
|
|
||||||
$reviewVote->type = ReviewVoteModel::TYPE_OPPOSE;
|
|
||||||
|
|
||||||
$this->incrOpposeCount($review);
|
|
||||||
}
|
|
||||||
|
|
||||||
$reviewVote->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->incrUserDailyReviewVoteCount($user);
|
|
||||||
|
|
||||||
return $review;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrAgreeCount(ReviewModel $review)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('reviewCounter:incrAgreeCount', $this, $review);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrAgreeCount(ReviewModel $review)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('reviewCounter:decrAgreeCount', $this, $review);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrOpposeCount(ReviewModel $review)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('reviewCounter:incrOpposeCount', $this, $review);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function decrOpposeCount(ReviewModel $review)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('reviewCounter:decrOpposeCount', $this, $review);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function incrUserDailyReviewVoteCount(UserModel $user)
|
|
||||||
{
|
|
||||||
$this->eventsManager->fire('userDailyCounter:incrReviewVoteCount', $this, $user);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
36
app/Services/Frontend/Review/VoteTrait.php
Normal file
36
app/Services/Frontend/Review/VoteTrait.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Frontend\Review;
|
||||||
|
|
||||||
|
use App\Models\Review as ReviewModel;
|
||||||
|
use App\Models\User as UserModel;
|
||||||
|
|
||||||
|
trait VoteTrait
|
||||||
|
{
|
||||||
|
|
||||||
|
protected function incrAgreeCount(ReviewModel $review)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('reviewCounter:incrAgreeCount', $this, $review);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrAgreeCount(ReviewModel $review)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('reviewCounter:decrAgreeCount', $this, $review);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrOpposeCount(ReviewModel $review)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('reviewCounter:incrOpposeCount', $this, $review);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decrOpposeCount(ReviewModel $review)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('reviewCounter:decrOpposeCount', $this, $review);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function incrUserDailyReviewVoteCount(UserModel $user)
|
||||||
|
{
|
||||||
|
$this->getEventsManager->fire('userDailyCounter:incrReviewVoteCount', $this, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ class CourseList extends Service
|
|||||||
|
|
||||||
use TopicTrait;
|
use TopicTrait;
|
||||||
|
|
||||||
public function getCourses($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$topic = $this->checkTopicCache($id);
|
$topic = $this->checkTopicCache($id);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class TopicInfo extends Service
|
|||||||
|
|
||||||
use TopicTrait;
|
use TopicTrait;
|
||||||
|
|
||||||
public function getTopic($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$topic = $this->checkTopicCache($id);
|
$topic = $this->checkTopicCache($id);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class CourseList extends Service
|
|||||||
|
|
||||||
use UserTrait;
|
use UserTrait;
|
||||||
|
|
||||||
public function getCourses($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$user = $this->checkUser($id);
|
$user = $this->checkUser($id);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ class UserInfo extends Service
|
|||||||
|
|
||||||
use UserTrait;
|
use UserTrait;
|
||||||
|
|
||||||
public function getUser($id)
|
public function handle($id)
|
||||||
{
|
{
|
||||||
$user = $this->checkUser($id);
|
$user = $this->checkUser($id);
|
||||||
|
|
||||||
|
@ -179,46 +179,12 @@ class Storage extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传对象
|
* 删除文件
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @param resource|string $body
|
* @return string|bool
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function putObject($key, $body)
|
public function deleteFile($key)
|
||||||
{
|
|
||||||
$bucket = $this->settings['bucket_name'];
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
$response = $this->client->putObject([
|
|
||||||
'Bucket' => $bucket,
|
|
||||||
'Key' => $key,
|
|
||||||
'Body' => $body,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$result = $response['Location'] ? $key : false;
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
|
|
||||||
$this->logger->error('Put Object Exception ' . kg_json_encode([
|
|
||||||
'code' => $e->getCode(),
|
|
||||||
'message' => $e->getMessage(),
|
|
||||||
]));
|
|
||||||
|
|
||||||
$result = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除对象
|
|
||||||
*
|
|
||||||
* @param string $key
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function deleteObject($key)
|
|
||||||
{
|
{
|
||||||
$bucket = $this->settings['bucket_name'];
|
$bucket = $this->settings['bucket_name'];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user