diff --git a/app/Http/Admin/Services/Service.php b/app/Http/Admin/Services/Service.php
index e6093909..8dd70bd3 100644
--- a/app/Http/Admin/Services/Service.php
+++ b/app/Http/Admin/Services/Service.php
@@ -2,9 +2,7 @@
namespace App\Http\Admin\Services;
-use Phalcon\Mvc\User\Component;
-
-class Service extends Component
+class Service extends \App\Services\Service
{
}
diff --git a/app/Http/Admin/Views/order/macro.volt b/app/Http/Admin/Views/order/macro.volt
index 3d9fe1af..836d0d77 100644
--- a/app/Http/Admin/Views/order/macro.volt
+++ b/app/Http/Admin/Views/order/macro.volt
@@ -25,8 +25,8 @@
{% set course = order.item_info['course'] %}
{% set reward = order.item_info['reward'] %}
-
课程名称:{{ course['title'] }}
-
打赏金额:¥{{ reward['price'] }}
+
商品名称:{{ order.subject }}
+
商品价格:¥{{ order.amount }}
{% elseif order.item_type == 'test' %}
diff --git a/app/Http/Api/Services/Service.php b/app/Http/Api/Services/Service.php
index f2575fb4..b97b2327 100644
--- a/app/Http/Api/Services/Service.php
+++ b/app/Http/Api/Services/Service.php
@@ -2,12 +2,7 @@
namespace App\Http\Api\Services;
-use App\Traits\Auth as AuthTrait;
-use Phalcon\Mvc\User\Component;
-
-class Service extends Component
+class Service extends \App\Services\Service
{
- use AuthTrait;
-
}
diff --git a/app/Http/Html5/Services/Service.php b/app/Http/Html5/Services/Service.php
index 850f50ae..b156c13f 100644
--- a/app/Http/Html5/Services/Service.php
+++ b/app/Http/Html5/Services/Service.php
@@ -2,11 +2,7 @@
namespace App\Http\Html5\Services;
-use App\Traits\Auth as AuthTrait;
-use Phalcon\Mvc\User\Component;
-
-class Service extends Component
+class Service extends \App\Services\Service
{
- use AuthTrait;
}
diff --git a/app/Http/Web/Services/Service.php b/app/Http/Web/Services/Service.php
index 7f2424ec..30362c00 100644
--- a/app/Http/Web/Services/Service.php
+++ b/app/Http/Web/Services/Service.php
@@ -2,11 +2,7 @@
namespace App\Http\Web\Services;
-use App\Traits\Auth as AuthTrait;
-use Phalcon\Mvc\User\Component;
-
-class Service extends Component
+class Service extends \App\Services\Service
{
- use AuthTrait;
}
diff --git a/app/Models/AccountBind.php b/app/Models/AccountBind.php
new file mode 100644
index 00000000..fd2fac5e
--- /dev/null
+++ b/app/Models/AccountBind.php
@@ -0,0 +1,93 @@
+addBehavior(
+ new SoftDelete([
+ 'field' => 'deleted',
+ 'value' => 1,
+ ])
+ );
+ }
+
+ public function beforeCreate()
+ {
+ $this->create_time = time();
+ }
+
+ public function beforeUpdate()
+ {
+ $this->update_time = time();
+ }
+
+}
diff --git a/app/Repos/Account.php b/app/Repos/Account.php
index 680ab79c..fb1cf58d 100644
--- a/app/Repos/Account.php
+++ b/app/Repos/Account.php
@@ -3,6 +3,7 @@
namespace App\Repos;
use App\Models\Account as AccountModel;
+use App\Models\AccountBind as AccountBindModel;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Resultset;
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|string $columns
diff --git a/app/Services/Frontend/Account/EmailUpdate.php b/app/Services/Frontend/Account/EmailUpdate.php
index 1adedb11..c856716f 100644
--- a/app/Services/Frontend/Account/EmailUpdate.php
+++ b/app/Services/Frontend/Account/EmailUpdate.php
@@ -1,8 +1,9 @@
user = $user;
$this->setCourseUser($course, $user);
-
$this->setChapterUser($chapter, $user);
$this->handleCourseUser($course, $user);
-
$this->handleChapterUser($chapter, $user);
return $this->handleChapter($chapter, $user);
}
- /**
- * @param ChapterModel $chapter
- * @param UserModel $user
- * @return array
- */
protected function handleChapter(ChapterModel $chapter, UserModel $user)
{
$result = $this->formatChapter($chapter);
$me = [
- 'agreed' => false,
- 'opposed' => false,
+ 'agreed' => 0,
+ 'opposed' => 0,
];
$me['owned'] = $this->ownedChapter;
if ($user->id > 0) {
-
$chapterVoteRepo = new ChapterVoteRepo();
-
$chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id);
-
if ($chapterVote) {
- $me['agreed'] = $chapterVote->type == ChapterVoteModel::TYPE_AGREE;
- $me['opposed'] = $chapterVote->type == ChapterVoteModel::TYPE_OPPOSE;
+ $me['agreed'] = $chapterVote->type == ChapterVoteModel::TYPE_AGREE ? 1 : 0;
+ $me['opposed'] = $chapterVote->type == ChapterVoteModel::TYPE_OPPOSE ? 1 : 0;
}
}
@@ -88,10 +78,6 @@ class ChapterInfo extends Service
return $result;
}
- /**
- * @param ChapterModel $chapter
- * @return array
- */
protected function formatChapter(ChapterModel $chapter)
{
$item = [];
@@ -111,10 +97,6 @@ class ChapterInfo extends Service
return $item;
}
- /**
- * @param ChapterModel $chapter
- * @return array
- */
protected function formatChapterVod(ChapterModel $chapter)
{
$chapterVodService = new ChapterVodService();
@@ -123,7 +105,7 @@ class ChapterInfo extends Service
$course = $this->formatCourse($this->course);
- $item = [
+ return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
@@ -134,14 +116,8 @@ class ChapterInfo extends Service
'comment_count' => $chapter->comment_count,
'user_count' => $chapter->user_count,
];
-
- return $item;
}
- /**
- * @param ChapterModel $chapter
- * @return array
- */
protected function formatChapterLive(ChapterModel $chapter)
{
$headers = getallheaders();
@@ -162,7 +138,7 @@ class ChapterInfo extends Service
$live = $chapterRepo->findChapterLive($chapter->id);
- $item = [
+ return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
@@ -175,14 +151,8 @@ class ChapterInfo extends Service
'comment_count' => $chapter->comment_count,
'user_count' => $chapter->user_count,
];
-
- return $item;
}
- /**
- * @param ChapterModel $chapter
- * @return array
- */
protected function formatChapterRead(ChapterModel $chapter)
{
$chapterRepo = new ChapterRepo();
@@ -191,7 +161,7 @@ class ChapterInfo extends Service
$course = $this->formatCourse($this->course);
- $item = [
+ return [
'id' => $chapter->id,
'title' => $chapter->title,
'summary' => $chapter->summary,
@@ -202,28 +172,16 @@ class ChapterInfo extends Service
'comment_count' => $chapter->comment_count,
'user_count' => $chapter->user_count,
];
-
- return $item;
}
- /**
- * @param CourseModel $course
- * @return array
- */
protected function formatCourse(CourseModel $course)
{
- $result = [
+ return [
'id' => $course->id,
'title' => $course->title,
];
-
- return $result;
}
- /**
- * @param CourseModel $course
- * @param UserModel $user
- */
protected function handleCourseUser(CourseModel $course, UserModel $user)
{
if ($user->id == 0) return;
@@ -247,10 +205,6 @@ class ChapterInfo extends Service
$course->update();
}
- /**
- * @param ChapterModel $chapter
- * @param UserModel $user
- */
protected function handleChapterUser(ChapterModel $chapter, UserModel $user)
{
if ($user->id == 0) return;
@@ -272,5 +226,4 @@ class ChapterInfo extends Service
$chapter->update();
}
-
}
diff --git a/app/Services/Frontend/ChapterTrait.php b/app/Services/Frontend/ChapterTrait.php
index 126e4a62..3a80464b 100644
--- a/app/Services/Frontend/ChapterTrait.php
+++ b/app/Services/Frontend/ChapterTrait.php
@@ -24,9 +24,7 @@ trait ChapterTrait
{
$validator = new ChapterValidator();
- $chapter = $validator->checkChapter($id);
-
- return $chapter;
+ return $validator->checkChapter($id);
}
/**
diff --git a/app/Services/Frontend/Comment/CommentCreate.php b/app/Services/Frontend/Comment/CommentCreate.php
index a98f4fcc..e5edaf3c 100644
--- a/app/Services/Frontend/Comment/CommentCreate.php
+++ b/app/Services/Frontend/Comment/CommentCreate.php
@@ -1,6 +1,6 @@
request->getPost();
- $chapter = $this->checkChapter($id);
-
- $courseRepo = new CourseRepo();
-
- $course = $courseRepo->findById($chapter->course_id);
-
$user = $this->getLoginUser();
$validator = new UserDailyLimitValidator();
@@ -33,12 +27,19 @@ class CommentCreate extends Service
$validator = new CommentValidator();
+ $chapter = $validator->checkChapter($post['chapter_id']);
+
+ $courseRepo = new CourseRepo();
+
+ $course = $courseRepo->findById($chapter->course_id);
+
$data = [];
$data['content'] = $validator->checkContent($post['content']);
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'])) {
diff --git a/app/Services/Frontend/CommentTrait.php b/app/Services/Frontend/CommentTrait.php
index 0878a84c..0a98fbc3 100644
--- a/app/Services/Frontend/CommentTrait.php
+++ b/app/Services/Frontend/CommentTrait.php
@@ -11,9 +11,7 @@ trait CommentTrait
{
$validator = new CommentValidator();
- $comment = $validator->checkComment($id);
-
- return $comment;
+ return $validator->checkComment($id);
}
}
diff --git a/app/Services/Frontend/Consult/ConsultCreate.php b/app/Services/Frontend/Consult/ConsultCreate.php
index fb5f1ad1..62ec39ad 100644
--- a/app/Services/Frontend/Consult/ConsultCreate.php
+++ b/app/Services/Frontend/Consult/ConsultCreate.php
@@ -1,6 +1,6 @@
request->getPost();
- $course = $this->checkCourse($id);
-
$user = $this->getLoginUser();
$validator = new UserDailyLimitValidator();
@@ -28,6 +26,7 @@ class ConsultCreate extends Service
$validator = new ConsultValidator();
+ $course = $validator->checkCourse($post['course_id']);
$question = $validator->checkQuestion($post['question']);
$consult = new ConsultModel();
diff --git a/app/Services/Frontend/ConsultTrait.php b/app/Services/Frontend/ConsultTrait.php
index 0a746f46..6eb691da 100644
--- a/app/Services/Frontend/ConsultTrait.php
+++ b/app/Services/Frontend/ConsultTrait.php
@@ -11,9 +11,7 @@ trait ConsultTrait
{
$validator = new ConsultValidator();
- $consult = $validator->checkConsult($id);
-
- return $consult;
+ return $validator->checkConsult($id);
}
}
diff --git a/app/Services/Frontend/Course/CourseInfo.php b/app/Services/Frontend/Course/CourseInfo.php
index 12d31914..3b34d3c0 100644
--- a/app/Services/Frontend/Course/CourseInfo.php
+++ b/app/Services/Frontend/Course/CourseInfo.php
@@ -24,20 +24,15 @@ class CourseInfo extends Service
return $this->handleCourse($course, $user);
}
- /**
- * @param CourseModel $course
- * @param UserModel $user
- * @return array
- */
- protected function handleCourse($course, $user)
+ protected function handleCourse(CourseModel $course, UserModel $user)
{
$result = $this->formatCourse($course);
$me = [
- 'joined' => false,
- 'owned' => false,
- 'reviewed' => false,
- 'favorited' => false,
+ 'joined' => 0,
+ 'owned' => 0,
+ 'reviewed' => 0,
+ 'favorited' => 0,
'progress' => 0,
];
@@ -48,16 +43,16 @@ class CourseInfo extends Service
$favorite = $favoriteRepo->findCourseFavorite($course->id, $user->id);
if ($favorite && $favorite->deleted == 0) {
- $me['favorited'] = true;
+ $me['favorited'] = 1;
}
if ($this->courseUser) {
- $me['reviewed'] = $this->courseUser->reviewed;
- $me['progress'] = $this->courseUser->progress;
+ $me['reviewed'] = $this->courseUser->reviewed ? 1 : 0;
+ $me['progress'] = $this->courseUser->progress ? 1 : 0;
}
- $me['joined'] = $this->joinedCourse;
- $me['owned'] = $this->ownedCourse;
+ $me['joined'] = $this->joinedCourse ? 1 : 0;
+ $me['owned'] = $this->ownedCourse ? 1 : 0;
}
$result['me'] = $me;
@@ -65,13 +60,9 @@ class CourseInfo extends Service
return $result;
}
- /**
- * @param CourseModel $course
- * @return array
- */
protected function formatCourse($course)
{
- $result = [
+ return [
'id' => $course->id,
'title' => $course->title,
'cover' => kg_ci_img_url($course->cover),
@@ -82,7 +73,8 @@ class CourseInfo extends Service
'vip_price' => (float)$course->vip_price,
'study_expiry' => $course->study_expiry,
'refund_expiry' => $course->refund_expiry,
- 'score' => $course->score,
+ 'rating' => (float)$course->rating,
+ 'score' => (float)$course->score,
'model' => $course->model,
'level' => $course->level,
'attrs' => $course->attrs,
@@ -91,8 +83,6 @@ class CourseInfo extends Service
'review_count' => $course->review_count,
'favorite_count' => $course->favorite_count,
];
-
- return $result;
}
}
diff --git a/app/Services/Frontend/CourseTrait.php b/app/Services/Frontend/CourseTrait.php
index 128a1964..1e71d9a6 100644
--- a/app/Services/Frontend/CourseTrait.php
+++ b/app/Services/Frontend/CourseTrait.php
@@ -30,9 +30,7 @@ trait CourseTrait
{
$validator = new CourseValidator();
- $course = $validator->checkCourse($id);
-
- return $course;
+ return $validator->checkCourse($id);
}
/**
diff --git a/app/Services/Frontend/OrderTrait.php b/app/Services/Frontend/OrderTrait.php
index 0230baaa..3280962d 100644
--- a/app/Services/Frontend/OrderTrait.php
+++ b/app/Services/Frontend/OrderTrait.php
@@ -11,9 +11,7 @@ trait OrderTrait
{
$validator = new OrderValidator();
- $order = $validator->checkOrderBySn($sn);
-
- return $order;
+ return $validator->checkOrderBySn($sn);
}
}
diff --git a/app/Services/Frontend/Review/ReviewCreate.php b/app/Services/Frontend/Review/ReviewCreate.php
index c1e23b4d..518552c8 100644
--- a/app/Services/Frontend/Review/ReviewCreate.php
+++ b/app/Services/Frontend/Review/ReviewCreate.php
@@ -1,10 +1,9 @@
request->getPost();
- $course = $this->checkCourse($id);
-
$user = $this->getLoginUser();
$validator = new UserDailyLimitValidator();
@@ -28,11 +23,12 @@ class ReviewCreate extends Service
$validator = new ReviewValidator();
- $validator->checkIfReviewed($course->id, $user->id);
-
+ $course = $validator->checkCourse($post['course_id']);
$content = $validator->checkContent($post['content']);
$rating = $validator->checkRating($post['rating']);
+ $validator->checkIfReviewed($course->id, $user->id);
+
$review = new ReviewModel();
$review->course_id = $course->id;
diff --git a/app/Services/Frontend/Review/ReviewVote.php b/app/Services/Frontend/Review/ReviewVote.php
index b15a834d..8fa47246 100644
--- a/app/Services/Frontend/Review/ReviewVote.php
+++ b/app/Services/Frontend/Review/ReviewVote.php
@@ -1,10 +1,12 @@
checkReview($id);
-
- return $review;
+ return $validator->checkReview($id);
}
}
diff --git a/app/Services/Frontend/Service.php b/app/Services/Frontend/Service.php
index afe1a4d7..bf3f58de 100644
--- a/app/Services/Frontend/Service.php
+++ b/app/Services/Frontend/Service.php
@@ -2,11 +2,7 @@
namespace App\Services\Frontend;
-use App\Traits\Auth as AuthTrait;
-use Phalcon\Mvc\User\Component;
-
-class Service extends Component
+class Service extends \App\Services\Service
{
- use AuthTrait;
}
\ No newline at end of file
diff --git a/app/Services/Frontend/Teacher/TeacherInfo.php b/app/Services/Frontend/Teacher/TeacherInfo.php
index dc4098b3..ebfdd6f3 100644
--- a/app/Services/Frontend/Teacher/TeacherInfo.php
+++ b/app/Services/Frontend/Teacher/TeacherInfo.php
@@ -28,7 +28,7 @@ class TeacherInfo extends Service
$user->vip = $user->vip == 1;
$user->locked = $user->locked == 1;
- $result = [
+ return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar,
@@ -45,8 +45,6 @@ class TeacherInfo extends Service
'notice_count' => $user->notice_count,
'msg_count' => $user->msg_count,
];
-
- return $result;
}
}
diff --git a/app/Services/Frontend/User/UserInfo.php b/app/Services/Frontend/User/UserInfo.php
index 882da54d..8c6d9cea 100644
--- a/app/Services/Frontend/User/UserInfo.php
+++ b/app/Services/Frontend/User/UserInfo.php
@@ -28,7 +28,7 @@ class UserInfo extends Service
$user->vip = $user->vip == 1;
$user->locked = $user->locked == 1;
- $result = [
+ return [
'id' => $user->id,
'name' => $user->name,
'avatar' => $user->avatar,
@@ -45,8 +45,6 @@ class UserInfo extends Service
'notice_count' => $user->notice_count,
'msg_count' => $user->msg_count,
];
-
- return $result;
}
}
diff --git a/app/Services/Frontend/UserTrait.php b/app/Services/Frontend/UserTrait.php
index 01f0b71e..b75c79b1 100644
--- a/app/Services/Frontend/UserTrait.php
+++ b/app/Services/Frontend/UserTrait.php
@@ -11,9 +11,7 @@ trait UserTrait
{
$validator = new UserValidator();
- $user = $validator->checkUser($id);
-
- return $user;
+ return $validator->checkUser($id);
}
}
diff --git a/app/Traits/Auth.php b/app/Traits/Auth.php
index 4dc80334..a8ff51c4 100644
--- a/app/Traits/Auth.php
+++ b/app/Traits/Auth.php
@@ -2,7 +2,6 @@
namespace App\Traits;
-use App\Exceptions\Unauthorized as UnauthorizedException;
use App\Models\User as UserModel;
use App\Repos\User as UserRepo;
use App\Services\Auth as AuthService;
@@ -31,7 +30,6 @@ trait Auth
/**
* @return UserModel
- * @throws UnauthorizedException
*/
public function getLoginUser()
{
diff --git a/app/Validators/Comment.php b/app/Validators/Comment.php
index 4946fbb7..5555d72e 100644
--- a/app/Validators/Comment.php
+++ b/app/Validators/Comment.php
@@ -23,20 +23,7 @@ class Comment extends Validator
return $comment;
}
- public function checkCourseId($courseId)
- {
- $courseRepo = new CourseRepo();
-
- $course = $courseRepo->findById($courseId);
-
- if (!$course) {
- throw new BadRequestException('comment.invalid_course_id');
- }
-
- return $course->id;
- }
-
- public function checkChapterId($chapterId)
+ public function checkChapter($chapterId)
{
$chapterRepo = new ChapterRepo();
@@ -46,20 +33,20 @@ class Comment extends Validator
throw new BadRequestException('comment.invalid_chapter_id');
}
- return $chapter->id;
+ return $chapter;
}
- public function checkParentId($parentId)
+ public function checkParent($parentId)
{
$commentRepo = new CourseRepo();
- $comment = $commentRepo->findById($parentId);
+ $parent = $commentRepo->findById($parentId);
- if (!$comment) {
+ if (!$parent) {
throw new BadRequestException('comment.invalid_parent_id');
}
- return $comment->id;
+ return $parent;
}
public function checkContent($content)
diff --git a/app/Validators/Consult.php b/app/Validators/Consult.php
index 48261844..19bd4f56 100644
--- a/app/Validators/Consult.php
+++ b/app/Validators/Consult.php
@@ -22,7 +22,7 @@ class Consult extends Validator
return $consult;
}
- public function checkCourseId($courseId)
+ public function checkCourse($courseId)
{
$courseRepo = new CourseRepo();
@@ -32,7 +32,7 @@ class Consult extends Validator
throw new BadRequestException('consult.invalid_course_id');
}
- return $course->id;
+ return $course;
}
public function checkQuestion($question)
diff --git a/app/Validators/Review.php b/app/Validators/Review.php
index 3e203619..18e8c2e2 100644
--- a/app/Validators/Review.php
+++ b/app/Validators/Review.php
@@ -23,7 +23,7 @@ class Review extends Validator
return $review;
}
- public function checkCourseId($courseId)
+ public function checkCourse($courseId)
{
$courseRepo = new CourseRepo();
@@ -33,7 +33,7 @@ class Review extends Validator
throw new BadRequestException('review.course_not_found');
}
- return $courseId;
+ return $course;
}
public function checkContent($content)