mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-17 13:46:21 +08:00
增加第三方登录设计
整理代码
This commit is contained in:
parent
92d9395065
commit
cf5e50f402
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Admin\Services;
|
namespace App\Http\Admin\Services;
|
||||||
|
|
||||||
use Phalcon\Mvc\User\Component;
|
class Service extends \App\Services\Service
|
||||||
|
|
||||||
class Service extends Component
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
{% set course = order.item_info['course'] %}
|
{% set course = order.item_info['course'] %}
|
||||||
{% set reward = order.item_info['reward'] %}
|
{% set reward = order.item_info['reward'] %}
|
||||||
<div class="kg-order-item">
|
<div class="kg-order-item">
|
||||||
<p>课程名称:{{ course['title'] }}</p>
|
<p>商品名称:{{ order.subject }}</p>
|
||||||
<p>打赏金额:¥{{ reward['price'] }}</p>
|
<p>商品价格:¥{{ order.amount }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% elseif order.item_type == 'test' %}
|
{% elseif order.item_type == 'test' %}
|
||||||
<div class="kg-order-item">
|
<div class="kg-order-item">
|
||||||
|
@ -2,12 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Api\Services;
|
namespace App\Http\Api\Services;
|
||||||
|
|
||||||
use App\Traits\Auth as AuthTrait;
|
class Service extends \App\Services\Service
|
||||||
use Phalcon\Mvc\User\Component;
|
|
||||||
|
|
||||||
class Service extends Component
|
|
||||||
{
|
{
|
||||||
|
|
||||||
use AuthTrait;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Html5\Services;
|
namespace App\Http\Html5\Services;
|
||||||
|
|
||||||
use App\Traits\Auth as AuthTrait;
|
class Service extends \App\Services\Service
|
||||||
use Phalcon\Mvc\User\Component;
|
|
||||||
|
|
||||||
class Service extends Component
|
|
||||||
{
|
{
|
||||||
|
|
||||||
use AuthTrait;
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Web\Services;
|
namespace App\Http\Web\Services;
|
||||||
|
|
||||||
use App\Traits\Auth as AuthTrait;
|
class Service extends \App\Services\Service
|
||||||
use Phalcon\Mvc\User\Component;
|
|
||||||
|
|
||||||
class Service extends Component
|
|
||||||
{
|
{
|
||||||
|
|
||||||
use AuthTrait;
|
|
||||||
}
|
}
|
||||||
|
93
app/Models/AccountBind.php
Normal file
93
app/Models/AccountBind.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Phalcon\Mvc\Model\Behavior\SoftDelete;
|
||||||
|
|
||||||
|
class AccountBind extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务商类型
|
||||||
|
*/
|
||||||
|
const PROVIDER_QQ = 'qq';
|
||||||
|
const PROVIDER_WEIXIN = 'weixin';
|
||||||
|
const PROVIDER_WEIBO = 'weibo';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键编号
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务商
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 外部用户编号
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $open_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内部用户编号
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $user_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标识
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $deleted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $create_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新时间
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $update_time;
|
||||||
|
|
||||||
|
public function getSource()
|
||||||
|
{
|
||||||
|
return 'kg_account_bind';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
parent::initialize();
|
||||||
|
|
||||||
|
$this->addBehavior(
|
||||||
|
new SoftDelete([
|
||||||
|
'field' => 'deleted',
|
||||||
|
'value' => 1,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function beforeCreate()
|
||||||
|
{
|
||||||
|
$this->create_time = time();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function beforeUpdate()
|
||||||
|
{
|
||||||
|
$this->update_time = time();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Repos;
|
namespace App\Repos;
|
||||||
|
|
||||||
use App\Models\Account as AccountModel;
|
use App\Models\Account as AccountModel;
|
||||||
|
use App\Models\AccountBind as AccountBindModel;
|
||||||
use Phalcon\Mvc\Model;
|
use Phalcon\Mvc\Model;
|
||||||
use Phalcon\Mvc\Model\Resultset;
|
use Phalcon\Mvc\Model\Resultset;
|
||||||
use Phalcon\Mvc\Model\ResultsetInterface;
|
use Phalcon\Mvc\Model\ResultsetInterface;
|
||||||
@ -43,6 +44,23 @@ class Account extends Repository
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $provider
|
||||||
|
* @param string $openId
|
||||||
|
* @return AccountModel|Model|bool
|
||||||
|
*/
|
||||||
|
public function findByOpenId($provider, $openId)
|
||||||
|
{
|
||||||
|
$bind = AccountBindModel::findFirst([
|
||||||
|
'conditions' => 'provider = ?1 AND open_id = ?2',
|
||||||
|
'bind' => [1 => $provider, 2 => $openId],
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$bind) return false;
|
||||||
|
|
||||||
|
return AccountModel::findFirst($bind->user_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $ids
|
* @param array $ids
|
||||||
* @param array|string $columns
|
* @param array|string $columns
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Frontend;
|
namespace App\Services\Frontend\Account;
|
||||||
|
|
||||||
use App\Repos\Account as AccountRepo;
|
use App\Repos\Account as AccountRepo;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -45,41 +45,31 @@ class ChapterInfo extends Service
|
|||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
||||||
$this->setCourseUser($course, $user);
|
$this->setCourseUser($course, $user);
|
||||||
|
|
||||||
$this->setChapterUser($chapter, $user);
|
$this->setChapterUser($chapter, $user);
|
||||||
|
|
||||||
$this->handleCourseUser($course, $user);
|
$this->handleCourseUser($course, $user);
|
||||||
|
|
||||||
$this->handleChapterUser($chapter, $user);
|
$this->handleChapterUser($chapter, $user);
|
||||||
|
|
||||||
return $this->handleChapter($chapter, $user);
|
return $this->handleChapter($chapter, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @param UserModel $user
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function handleChapter(ChapterModel $chapter, UserModel $user)
|
protected function handleChapter(ChapterModel $chapter, UserModel $user)
|
||||||
{
|
{
|
||||||
$result = $this->formatChapter($chapter);
|
$result = $this->formatChapter($chapter);
|
||||||
|
|
||||||
$me = [
|
$me = [
|
||||||
'agreed' => false,
|
'agreed' => 0,
|
||||||
'opposed' => false,
|
'opposed' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
$me['owned'] = $this->ownedChapter;
|
$me['owned'] = $this->ownedChapter;
|
||||||
|
|
||||||
if ($user->id > 0) {
|
if ($user->id > 0) {
|
||||||
|
|
||||||
$chapterVoteRepo = new ChapterVoteRepo();
|
$chapterVoteRepo = new ChapterVoteRepo();
|
||||||
|
|
||||||
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $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 ? 1 : 0;
|
||||||
$me['opposed'] = $chapterVote->type == ChapterVoteModel::TYPE_OPPOSE;
|
$me['opposed'] = $chapterVote->type == ChapterVoteModel::TYPE_OPPOSE ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,10 +78,6 @@ class ChapterInfo extends Service
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatChapter(ChapterModel $chapter)
|
protected function formatChapter(ChapterModel $chapter)
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = [];
|
||||||
@ -111,10 +97,6 @@ class ChapterInfo extends Service
|
|||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatChapterVod(ChapterModel $chapter)
|
protected function formatChapterVod(ChapterModel $chapter)
|
||||||
{
|
{
|
||||||
$chapterVodService = new ChapterVodService();
|
$chapterVodService = new ChapterVodService();
|
||||||
@ -123,7 +105,7 @@ class ChapterInfo extends Service
|
|||||||
|
|
||||||
$course = $this->formatCourse($this->course);
|
$course = $this->formatCourse($this->course);
|
||||||
|
|
||||||
$item = [
|
return [
|
||||||
'id' => $chapter->id,
|
'id' => $chapter->id,
|
||||||
'title' => $chapter->title,
|
'title' => $chapter->title,
|
||||||
'summary' => $chapter->summary,
|
'summary' => $chapter->summary,
|
||||||
@ -134,14 +116,8 @@ class ChapterInfo extends Service
|
|||||||
'comment_count' => $chapter->comment_count,
|
'comment_count' => $chapter->comment_count,
|
||||||
'user_count' => $chapter->user_count,
|
'user_count' => $chapter->user_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatChapterLive(ChapterModel $chapter)
|
protected function formatChapterLive(ChapterModel $chapter)
|
||||||
{
|
{
|
||||||
$headers = getallheaders();
|
$headers = getallheaders();
|
||||||
@ -162,7 +138,7 @@ class ChapterInfo extends Service
|
|||||||
|
|
||||||
$live = $chapterRepo->findChapterLive($chapter->id);
|
$live = $chapterRepo->findChapterLive($chapter->id);
|
||||||
|
|
||||||
$item = [
|
return [
|
||||||
'id' => $chapter->id,
|
'id' => $chapter->id,
|
||||||
'title' => $chapter->title,
|
'title' => $chapter->title,
|
||||||
'summary' => $chapter->summary,
|
'summary' => $chapter->summary,
|
||||||
@ -175,14 +151,8 @@ class ChapterInfo extends Service
|
|||||||
'comment_count' => $chapter->comment_count,
|
'comment_count' => $chapter->comment_count,
|
||||||
'user_count' => $chapter->user_count,
|
'user_count' => $chapter->user_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatChapterRead(ChapterModel $chapter)
|
protected function formatChapterRead(ChapterModel $chapter)
|
||||||
{
|
{
|
||||||
$chapterRepo = new ChapterRepo();
|
$chapterRepo = new ChapterRepo();
|
||||||
@ -191,7 +161,7 @@ class ChapterInfo extends Service
|
|||||||
|
|
||||||
$course = $this->formatCourse($this->course);
|
$course = $this->formatCourse($this->course);
|
||||||
|
|
||||||
$item = [
|
return [
|
||||||
'id' => $chapter->id,
|
'id' => $chapter->id,
|
||||||
'title' => $chapter->title,
|
'title' => $chapter->title,
|
||||||
'summary' => $chapter->summary,
|
'summary' => $chapter->summary,
|
||||||
@ -202,28 +172,16 @@ class ChapterInfo extends Service
|
|||||||
'comment_count' => $chapter->comment_count,
|
'comment_count' => $chapter->comment_count,
|
||||||
'user_count' => $chapter->user_count,
|
'user_count' => $chapter->user_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param CourseModel $course
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatCourse(CourseModel $course)
|
protected function formatCourse(CourseModel $course)
|
||||||
{
|
{
|
||||||
$result = [
|
return [
|
||||||
'id' => $course->id,
|
'id' => $course->id,
|
||||||
'title' => $course->title,
|
'title' => $course->title,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param CourseModel $course
|
|
||||||
* @param UserModel $user
|
|
||||||
*/
|
|
||||||
protected function handleCourseUser(CourseModel $course, UserModel $user)
|
protected function handleCourseUser(CourseModel $course, UserModel $user)
|
||||||
{
|
{
|
||||||
if ($user->id == 0) return;
|
if ($user->id == 0) return;
|
||||||
@ -247,10 +205,6 @@ class ChapterInfo extends Service
|
|||||||
$course->update();
|
$course->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ChapterModel $chapter
|
|
||||||
* @param UserModel $user
|
|
||||||
*/
|
|
||||||
protected function handleChapterUser(ChapterModel $chapter, UserModel $user)
|
protected function handleChapterUser(ChapterModel $chapter, UserModel $user)
|
||||||
{
|
{
|
||||||
if ($user->id == 0) return;
|
if ($user->id == 0) return;
|
||||||
@ -272,5 +226,4 @@ class ChapterInfo extends Service
|
|||||||
$chapter->update();
|
$chapter->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,7 @@ trait ChapterTrait
|
|||||||
{
|
{
|
||||||
$validator = new ChapterValidator();
|
$validator = new ChapterValidator();
|
||||||
|
|
||||||
$chapter = $validator->checkChapter($id);
|
return $validator->checkChapter($id);
|
||||||
|
|
||||||
return $chapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Frontend\Chapter;
|
namespace App\Services\Frontend\Comment;
|
||||||
|
|
||||||
use App\Models\Comment as CommentModel;
|
use App\Models\Comment as CommentModel;
|
||||||
use App\Models\User as UserModel;
|
use App\Models\User as UserModel;
|
||||||
@ -15,16 +15,10 @@ class CommentCreate extends Service
|
|||||||
|
|
||||||
use ChapterTrait;
|
use ChapterTrait;
|
||||||
|
|
||||||
public function createComment($id)
|
public function createComment()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
$chapter = $this->checkChapter($id);
|
|
||||||
|
|
||||||
$courseRepo = new CourseRepo();
|
|
||||||
|
|
||||||
$course = $courseRepo->findById($chapter->course_id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
$validator = new UserDailyLimitValidator();
|
||||||
@ -33,12 +27,19 @@ class CommentCreate extends Service
|
|||||||
|
|
||||||
$validator = new CommentValidator();
|
$validator = new CommentValidator();
|
||||||
|
|
||||||
|
$chapter = $validator->checkChapter($post['chapter_id']);
|
||||||
|
|
||||||
|
$courseRepo = new CourseRepo();
|
||||||
|
|
||||||
|
$course = $courseRepo->findById($chapter->course_id);
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
|
||||||
$data['content'] = $validator->checkContent($post['content']);
|
$data['content'] = $validator->checkContent($post['content']);
|
||||||
|
|
||||||
if (isset($post['parent_id'])) {
|
if (isset($post['parent_id'])) {
|
||||||
$data['parent_id'] = $validator->checkParentId($post['parent_id']);
|
$parent = $validator->checkParent($post['parent_id']);
|
||||||
|
$data['parent_id'] = $parent->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($post['mentions'])) {
|
if (isset($post['mentions'])) {
|
||||||
|
@ -11,9 +11,7 @@ trait CommentTrait
|
|||||||
{
|
{
|
||||||
$validator = new CommentValidator();
|
$validator = new CommentValidator();
|
||||||
|
|
||||||
$comment = $validator->checkComment($id);
|
return $validator->checkComment($id);
|
||||||
|
|
||||||
return $comment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Frontend\Course;
|
namespace App\Services\Frontend\Consult;
|
||||||
|
|
||||||
use App\Models\Consult as ConsultModel;
|
use App\Models\Consult as ConsultModel;
|
||||||
use App\Models\User as UserModel;
|
use App\Models\User as UserModel;
|
||||||
@ -14,12 +14,10 @@ class ConsultCreate extends Service
|
|||||||
|
|
||||||
use CourseTrait;
|
use CourseTrait;
|
||||||
|
|
||||||
public function createConsult($id)
|
public function createConsult()
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
$course = $this->checkCourse($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
$validator = new UserDailyLimitValidator();
|
||||||
@ -28,6 +26,7 @@ class ConsultCreate extends Service
|
|||||||
|
|
||||||
$validator = new ConsultValidator();
|
$validator = new ConsultValidator();
|
||||||
|
|
||||||
|
$course = $validator->checkCourse($post['course_id']);
|
||||||
$question = $validator->checkQuestion($post['question']);
|
$question = $validator->checkQuestion($post['question']);
|
||||||
|
|
||||||
$consult = new ConsultModel();
|
$consult = new ConsultModel();
|
||||||
|
@ -11,9 +11,7 @@ trait ConsultTrait
|
|||||||
{
|
{
|
||||||
$validator = new ConsultValidator();
|
$validator = new ConsultValidator();
|
||||||
|
|
||||||
$consult = $validator->checkConsult($id);
|
return $validator->checkConsult($id);
|
||||||
|
|
||||||
return $consult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,20 +24,15 @@ class CourseInfo extends Service
|
|||||||
return $this->handleCourse($course, $user);
|
return $this->handleCourse($course, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function handleCourse(CourseModel $course, UserModel $user)
|
||||||
* @param CourseModel $course
|
|
||||||
* @param UserModel $user
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function handleCourse($course, $user)
|
|
||||||
{
|
{
|
||||||
$result = $this->formatCourse($course);
|
$result = $this->formatCourse($course);
|
||||||
|
|
||||||
$me = [
|
$me = [
|
||||||
'joined' => false,
|
'joined' => 0,
|
||||||
'owned' => false,
|
'owned' => 0,
|
||||||
'reviewed' => false,
|
'reviewed' => 0,
|
||||||
'favorited' => false,
|
'favorited' => 0,
|
||||||
'progress' => 0,
|
'progress' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -48,16 +43,16 @@ class CourseInfo extends Service
|
|||||||
$favorite = $favoriteRepo->findCourseFavorite($course->id, $user->id);
|
$favorite = $favoriteRepo->findCourseFavorite($course->id, $user->id);
|
||||||
|
|
||||||
if ($favorite && $favorite->deleted == 0) {
|
if ($favorite && $favorite->deleted == 0) {
|
||||||
$me['favorited'] = true;
|
$me['favorited'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->courseUser) {
|
if ($this->courseUser) {
|
||||||
$me['reviewed'] = $this->courseUser->reviewed;
|
$me['reviewed'] = $this->courseUser->reviewed ? 1 : 0;
|
||||||
$me['progress'] = $this->courseUser->progress;
|
$me['progress'] = $this->courseUser->progress ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$me['joined'] = $this->joinedCourse;
|
$me['joined'] = $this->joinedCourse ? 1 : 0;
|
||||||
$me['owned'] = $this->ownedCourse;
|
$me['owned'] = $this->ownedCourse ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result['me'] = $me;
|
$result['me'] = $me;
|
||||||
@ -65,13 +60,9 @@ class CourseInfo extends Service
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param CourseModel $course
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function formatCourse($course)
|
protected function formatCourse($course)
|
||||||
{
|
{
|
||||||
$result = [
|
return [
|
||||||
'id' => $course->id,
|
'id' => $course->id,
|
||||||
'title' => $course->title,
|
'title' => $course->title,
|
||||||
'cover' => kg_ci_img_url($course->cover),
|
'cover' => kg_ci_img_url($course->cover),
|
||||||
@ -82,7 +73,8 @@ class CourseInfo extends Service
|
|||||||
'vip_price' => (float)$course->vip_price,
|
'vip_price' => (float)$course->vip_price,
|
||||||
'study_expiry' => $course->study_expiry,
|
'study_expiry' => $course->study_expiry,
|
||||||
'refund_expiry' => $course->refund_expiry,
|
'refund_expiry' => $course->refund_expiry,
|
||||||
'score' => $course->score,
|
'rating' => (float)$course->rating,
|
||||||
|
'score' => (float)$course->score,
|
||||||
'model' => $course->model,
|
'model' => $course->model,
|
||||||
'level' => $course->level,
|
'level' => $course->level,
|
||||||
'attrs' => $course->attrs,
|
'attrs' => $course->attrs,
|
||||||
@ -91,8 +83,6 @@ class CourseInfo extends Service
|
|||||||
'review_count' => $course->review_count,
|
'review_count' => $course->review_count,
|
||||||
'favorite_count' => $course->favorite_count,
|
'favorite_count' => $course->favorite_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,7 @@ trait CourseTrait
|
|||||||
{
|
{
|
||||||
$validator = new CourseValidator();
|
$validator = new CourseValidator();
|
||||||
|
|
||||||
$course = $validator->checkCourse($id);
|
return $validator->checkCourse($id);
|
||||||
|
|
||||||
return $course;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,9 +11,7 @@ trait OrderTrait
|
|||||||
{
|
{
|
||||||
$validator = new OrderValidator();
|
$validator = new OrderValidator();
|
||||||
|
|
||||||
$order = $validator->checkOrderBySn($sn);
|
return $validator->checkOrderBySn($sn);
|
||||||
|
|
||||||
return $order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Frontend\Course;
|
namespace App\Services\Frontend\Review;
|
||||||
|
|
||||||
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\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;
|
||||||
@ -12,14 +11,10 @@ use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
|||||||
class ReviewCreate extends Service
|
class ReviewCreate extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
use CourseTrait;
|
public function createReview()
|
||||||
|
|
||||||
public function createReview($id)
|
|
||||||
{
|
{
|
||||||
$post = $this->request->getPost();
|
$post = $this->request->getPost();
|
||||||
|
|
||||||
$course = $this->checkCourse($id);
|
|
||||||
|
|
||||||
$user = $this->getLoginUser();
|
$user = $this->getLoginUser();
|
||||||
|
|
||||||
$validator = new UserDailyLimitValidator();
|
$validator = new UserDailyLimitValidator();
|
||||||
@ -28,11 +23,12 @@ class ReviewCreate extends Service
|
|||||||
|
|
||||||
$validator = new ReviewValidator();
|
$validator = new ReviewValidator();
|
||||||
|
|
||||||
$validator->checkIfReviewed($course->id, $user->id);
|
$course = $validator->checkCourse($post['course_id']);
|
||||||
|
|
||||||
$content = $validator->checkContent($post['content']);
|
$content = $validator->checkContent($post['content']);
|
||||||
$rating = $validator->checkRating($post['rating']);
|
$rating = $validator->checkRating($post['rating']);
|
||||||
|
|
||||||
|
$validator->checkIfReviewed($course->id, $user->id);
|
||||||
|
|
||||||
$review = new ReviewModel();
|
$review = new ReviewModel();
|
||||||
|
|
||||||
$review->course_id = $course->id;
|
$review->course_id = $course->id;
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Services\Frontend;
|
namespace App\Services\Frontend\Review;
|
||||||
|
|
||||||
use App\Models\ReviewVote as ReviewVoteModel;
|
use App\Models\ReviewVote as ReviewVoteModel;
|
||||||
use App\Models\User as UserModel;
|
use App\Models\User as UserModel;
|
||||||
use App\Repos\ReviewVote as ReviewVoteRepo;
|
use App\Repos\ReviewVote as ReviewVoteRepo;
|
||||||
|
use App\Services\Frontend\ReviewTrait;
|
||||||
|
use App\Services\Frontend\Service;
|
||||||
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
use App\Validators\UserDailyLimit as UserDailyLimitValidator;
|
||||||
|
|
||||||
class ReviewVote extends Service
|
class ReviewVote extends Service
|
||||||
|
@ -11,9 +11,7 @@ trait ReviewTrait
|
|||||||
{
|
{
|
||||||
$validator = new ReviewValidator();
|
$validator = new ReviewValidator();
|
||||||
|
|
||||||
$review = $validator->checkReview($id);
|
return $validator->checkReview($id);
|
||||||
|
|
||||||
return $review;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Services\Frontend;
|
namespace App\Services\Frontend;
|
||||||
|
|
||||||
use App\Traits\Auth as AuthTrait;
|
class Service extends \App\Services\Service
|
||||||
use Phalcon\Mvc\User\Component;
|
|
||||||
|
|
||||||
class Service extends Component
|
|
||||||
{
|
{
|
||||||
|
|
||||||
use AuthTrait;
|
|
||||||
}
|
}
|
@ -28,7 +28,7 @@ class TeacherInfo extends Service
|
|||||||
$user->vip = $user->vip == 1;
|
$user->vip = $user->vip == 1;
|
||||||
$user->locked = $user->locked == 1;
|
$user->locked = $user->locked == 1;
|
||||||
|
|
||||||
$result = [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'avatar' => $user->avatar,
|
'avatar' => $user->avatar,
|
||||||
@ -45,8 +45,6 @@ class TeacherInfo extends Service
|
|||||||
'notice_count' => $user->notice_count,
|
'notice_count' => $user->notice_count,
|
||||||
'msg_count' => $user->msg_count,
|
'msg_count' => $user->msg_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class UserInfo extends Service
|
|||||||
$user->vip = $user->vip == 1;
|
$user->vip = $user->vip == 1;
|
||||||
$user->locked = $user->locked == 1;
|
$user->locked = $user->locked == 1;
|
||||||
|
|
||||||
$result = [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
'name' => $user->name,
|
'name' => $user->name,
|
||||||
'avatar' => $user->avatar,
|
'avatar' => $user->avatar,
|
||||||
@ -45,8 +45,6 @@ class UserInfo extends Service
|
|||||||
'notice_count' => $user->notice_count,
|
'notice_count' => $user->notice_count,
|
||||||
'msg_count' => $user->msg_count,
|
'msg_count' => $user->msg_count,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,7 @@ trait UserTrait
|
|||||||
{
|
{
|
||||||
$validator = new UserValidator();
|
$validator = new UserValidator();
|
||||||
|
|
||||||
$user = $validator->checkUser($id);
|
return $validator->checkUser($id);
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use App\Exceptions\Unauthorized as UnauthorizedException;
|
|
||||||
use App\Models\User as UserModel;
|
use App\Models\User as UserModel;
|
||||||
use App\Repos\User as UserRepo;
|
use App\Repos\User as UserRepo;
|
||||||
use App\Services\Auth as AuthService;
|
use App\Services\Auth as AuthService;
|
||||||
@ -31,7 +30,6 @@ trait Auth
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return UserModel
|
* @return UserModel
|
||||||
* @throws UnauthorizedException
|
|
||||||
*/
|
*/
|
||||||
public function getLoginUser()
|
public function getLoginUser()
|
||||||
{
|
{
|
||||||
|
@ -23,20 +23,7 @@ class Comment extends Validator
|
|||||||
return $comment;
|
return $comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkCourseId($courseId)
|
public function checkChapter($chapterId)
|
||||||
{
|
|
||||||
$courseRepo = new CourseRepo();
|
|
||||||
|
|
||||||
$course = $courseRepo->findById($courseId);
|
|
||||||
|
|
||||||
if (!$course) {
|
|
||||||
throw new BadRequestException('comment.invalid_course_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $course->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkChapterId($chapterId)
|
|
||||||
{
|
{
|
||||||
$chapterRepo = new ChapterRepo();
|
$chapterRepo = new ChapterRepo();
|
||||||
|
|
||||||
@ -46,20 +33,20 @@ class Comment extends Validator
|
|||||||
throw new BadRequestException('comment.invalid_chapter_id');
|
throw new BadRequestException('comment.invalid_chapter_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $chapter->id;
|
return $chapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkParentId($parentId)
|
public function checkParent($parentId)
|
||||||
{
|
{
|
||||||
$commentRepo = new CourseRepo();
|
$commentRepo = new CourseRepo();
|
||||||
|
|
||||||
$comment = $commentRepo->findById($parentId);
|
$parent = $commentRepo->findById($parentId);
|
||||||
|
|
||||||
if (!$comment) {
|
if (!$parent) {
|
||||||
throw new BadRequestException('comment.invalid_parent_id');
|
throw new BadRequestException('comment.invalid_parent_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $comment->id;
|
return $parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkContent($content)
|
public function checkContent($content)
|
||||||
|
@ -22,7 +22,7 @@ class Consult extends Validator
|
|||||||
return $consult;
|
return $consult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkCourseId($courseId)
|
public function checkCourse($courseId)
|
||||||
{
|
{
|
||||||
$courseRepo = new CourseRepo();
|
$courseRepo = new CourseRepo();
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class Consult extends Validator
|
|||||||
throw new BadRequestException('consult.invalid_course_id');
|
throw new BadRequestException('consult.invalid_course_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $course->id;
|
return $course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkQuestion($question)
|
public function checkQuestion($question)
|
||||||
|
@ -23,7 +23,7 @@ class Review extends Validator
|
|||||||
return $review;
|
return $review;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkCourseId($courseId)
|
public function checkCourse($courseId)
|
||||||
{
|
{
|
||||||
$courseRepo = new CourseRepo();
|
$courseRepo = new CourseRepo();
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class Review extends Validator
|
|||||||
throw new BadRequestException('review.course_not_found');
|
throw new BadRequestException('review.course_not_found');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $courseId;
|
return $course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkContent($content)
|
public function checkContent($content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user