diff --git a/app/Builders/Builder.php b/app/Builders/Builder.php
index 02cd4f2f..5e8401e6 100644
--- a/app/Builders/Builder.php
+++ b/app/Builders/Builder.php
@@ -9,9 +9,7 @@ class Builder extends Component
public function arrayToObject($array)
{
- $result = kg_array_object($array);
-
- return $result;
+ return kg_array_object($array);
}
}
diff --git a/app/Builders/ChapterTreeList.php b/app/Builders/ChapterTreeList.php
index afc2c29e..dfe8d79a 100644
--- a/app/Builders/ChapterTreeList.php
+++ b/app/Builders/ChapterTreeList.php
@@ -56,7 +56,7 @@ class ChapterTreeList extends Builder
unset($attrs['file_id'], $attrs['file_status']);
}
- $result = [
+ return [
'id' => $chapter['id'],
'title' => $chapter['title'],
'summary' => $chapter['summary'],
@@ -64,8 +64,6 @@ class ChapterTreeList extends Builder
'free' => $chapter['free'],
'attrs' => $attrs,
];
-
- return $result;
}
}
diff --git a/app/Builders/CourseChapterUser.php b/app/Builders/CourseChapterUser.php
index 9adece6d..49401f26 100644
--- a/app/Builders/CourseChapterUser.php
+++ b/app/Builders/CourseChapterUser.php
@@ -7,7 +7,6 @@ use App\Models\Course as CourseModel;
class CourseChapterUser extends Builder
{
-
/**
* 处理课时进度
*
@@ -69,8 +68,7 @@ class CourseChapterUser extends Builder
}
}
-
- $result = [
+ return [
'id' => $chapter['id'],
'title' => $chapter['title'],
'summary' => $chapter['summary'],
@@ -79,8 +77,6 @@ class CourseChapterUser extends Builder
'attrs' => $attrs,
'me' => $me,
];
-
- return $result;
}
}
diff --git a/app/Builders/UserList.php b/app/Builders/UserList.php
index 20d19a04..14ff13bf 100644
--- a/app/Builders/UserList.php
+++ b/app/Builders/UserList.php
@@ -60,7 +60,7 @@ class UserList extends Builder
protected function getEduRoles()
{
- $result = [
+ return [
UserModel::EDU_ROLE_STUDENT => [
'id' => UserModel::EDU_ROLE_STUDENT,
'name' => '学员',
@@ -70,8 +70,6 @@ class UserList extends Builder
'name' => '讲师',
],
];
-
- return $result;
}
}
diff --git a/app/Caches/AccessToken.php b/app/Caches/AccessToken.php
new file mode 100644
index 00000000..b4a80a4a
--- /dev/null
+++ b/app/Caches/AccessToken.php
@@ -0,0 +1,33 @@
+lifetime;
+ }
+
+ public function getKey($id = null)
+ {
+ return "access_token:{$id}";
+ }
+
+ public function getContent($id = null)
+ {
+ $categoryRepo = new CategoryRepo();
+
+ $category = $categoryRepo->findById($id);
+
+ if (!$category) {
+ return new \stdClass();
+ }
+
+ return $category;
+ }
+
+}
diff --git a/app/Caches/CategoryTreeList.php b/app/Caches/CategoryTreeList.php
index 6ae7eb71..2854d648 100644
--- a/app/Caches/CategoryTreeList.php
+++ b/app/Caches/CategoryTreeList.php
@@ -47,9 +47,7 @@ class CategoryTreeList extends Cache
$builder = new CategoryTreeListBuilder();
- $content = $builder->handleTreeList($items);
-
- return $content;
+ return $builder->handleTreeList($items);
}
}
diff --git a/app/Caches/ChapterTreeList.php b/app/Caches/ChapterTreeList.php
index e1221404..2cc7bd79 100644
--- a/app/Caches/ChapterTreeList.php
+++ b/app/Caches/ChapterTreeList.php
@@ -47,9 +47,7 @@ class ChapterTreeList extends Cache
$builder = new ChapterTreeListBuilder();
- $content = $builder->handleTreeList($items);
-
- return $content;
+ return $builder->handleTreeList($items);
}
}
diff --git a/app/Caches/Config.php b/app/Caches/Config.php
deleted file mode 100644
index 4b13dd6a..00000000
--- a/app/Caches/Config.php
+++ /dev/null
@@ -1,72 +0,0 @@
-get();
-
- $result = [];
-
- if (!$items) {
- return $result;
- }
-
- foreach ($items as $item) {
- if ($item['section'] == $section) {
- $result[$item['item_key']] = $item['item_value'];
- }
- }
-
- return $result;
- }
-
- /**
- * 获取某个配置项的值
- *
- * @param string $section
- * @param string $key
- * @return string|null
- */
- public function getItemValue($section, $key)
- {
- $config = $this->getSectionConfig($section);
-
- $result = $config[$key] ?? null;
-
- return $result;
- }
-
- public function getLifetime()
- {
- return $this->lifetime;
- }
-
- public function getKey($id = null)
- {
- return 'config';
- }
-
- public function getContent($id = null)
- {
- $configRepo = new ConfigRepo();
-
- $items = $configRepo->findAll();
-
- return $items->toArray();
- }
-
-}
diff --git a/app/Caches/Counter.php b/app/Caches/Counter.php
index 340783ce..f023b40b 100644
--- a/app/Caches/Counter.php
+++ b/app/Caches/Counter.php
@@ -83,18 +83,14 @@ abstract class Counter extends Component
$this->get($id);
}
- $value = $this->redis->hGet($key, $hashKey);
-
- return $value;
+ return $this->redis->hGet($key, $hashKey);
}
public function hDel($id, $hashKey)
{
$key = $this->getKey($id);
- $value = $this->redis->hDel($key, $hashKey);
-
- return $value;
+ return $this->redis->hDel($key, $hashKey);
}
public function hIncrBy($id, $hashKey, $value = 1)
diff --git a/app/Caches/CourseCategoryList.php b/app/Caches/CourseCategoryList.php
index f3d0d173..fbaf2a0e 100644
--- a/app/Caches/CourseCategoryList.php
+++ b/app/Caches/CourseCategoryList.php
@@ -2,8 +2,8 @@
namespace App\Caches;
+use App\Models\Category as CategoryModel;
use App\Repos\Course as CourseRepo;
-use Phalcon\Mvc\Model\Resultset;
class CourseCategoryList extends Cache
{
@@ -24,9 +24,6 @@ class CourseCategoryList extends Cache
{
$courseRepo = new CourseRepo();
- /**
- * @var Resultset $categories
- */
$categories = $courseRepo->findCategories($id);
if ($categories->count() == 0) {
@@ -37,7 +34,7 @@ class CourseCategoryList extends Cache
}
/**
- * @param Resultset $categories
+ * @param CategoryModel[] $categories
* @return array
*/
public function handleContent($categories)
diff --git a/app/Caches/CoursePackageList.php b/app/Caches/CoursePackageList.php
index 81b2101d..36033b11 100644
--- a/app/Caches/CoursePackageList.php
+++ b/app/Caches/CoursePackageList.php
@@ -5,7 +5,6 @@ namespace App\Caches;
use App\Models\Package as PackageModel;
use App\Repos\Course as CourseRepo;
use App\Repos\Package as PackageRepo;
-use Phalcon\Mvc\Model\Resultset;
class CoursePackageList extends Cache
{
@@ -26,9 +25,6 @@ class CoursePackageList extends Cache
{
$courseRepo = new CourseRepo();
- /**
- * @var Resultset $packages
- */
$packages = $courseRepo->findPackages($id);
if ($packages->count() == 0) {
diff --git a/app/Caches/CourseRelatedList.php b/app/Caches/CourseRelatedList.php
index 6a4788ea..ff658bfd 100644
--- a/app/Caches/CourseRelatedList.php
+++ b/app/Caches/CourseRelatedList.php
@@ -4,7 +4,6 @@ namespace App\Caches;
use App\Models\Course as CourseModel;
use App\Repos\Course as CourseRepo;
-use Phalcon\Mvc\Model\Resultset;
class CourseRelatedList extends Cache
{
@@ -25,9 +24,6 @@ class CourseRelatedList extends Cache
{
$courseRepo = new CourseRepo();
- /**
- * @var Resultset $courses
- */
$courses = $courseRepo->findRelatedCourses($id);
if ($courses->count() == 0) {
@@ -37,7 +33,6 @@ class CourseRelatedList extends Cache
return $this->handleContent($courses);
}
-
/**
* @param CourseModel[] $courses
* @return array
diff --git a/app/Caches/CourseTeacherList.php b/app/Caches/CourseTeacherList.php
index 41fb85cc..eb143150 100644
--- a/app/Caches/CourseTeacherList.php
+++ b/app/Caches/CourseTeacherList.php
@@ -4,7 +4,6 @@ namespace App\Caches;
use App\Models\User as UserModel;
use App\Repos\Course as CourseRepo;
-use Phalcon\Mvc\Model\Resultset;
class CourseTeacherList extends Cache
{
@@ -25,9 +24,6 @@ class CourseTeacherList extends Cache
{
$courseRepo = new CourseRepo();
- /**
- * @var Resultset $users
- */
$users = $courseRepo->findTeachers($id);
if ($users->count() == 0) {
diff --git a/app/Caches/HotCourseList.php b/app/Caches/HotCourseList.php
index 4e4e9cd9..c488bbb2 100644
--- a/app/Caches/HotCourseList.php
+++ b/app/Caches/HotCourseList.php
@@ -3,8 +3,8 @@
namespace App\Caches;
use App\Models\Course as CourseModel;
-use App\Repos\Course as CourseRepo;
use Phalcon\Mvc\Model\Resultset;
+use Phalcon\Mvc\Model\ResultsetInterface;
class HotCourseList extends Cache
{
@@ -23,12 +23,7 @@ class HotCourseList extends Cache
public function getContent($id = null)
{
- $courseRepo = new CourseRepo();
-
- /**
- * @var Resultset $courses
- */
- $courses = $courseRepo->findRelatedCourses($id);
+ $courses = $this->findHotCourses($id);
if ($courses->count() == 0) {
return [];
@@ -61,4 +56,17 @@ class HotCourseList extends Cache
return $result;
}
+ /**
+ * @param int $limit
+ * @return ResultsetInterface|Resultset|CourseModel[]
+ */
+ protected function findHotCourses($limit = 10)
+ {
+ return CourseModel::query()
+ ->where('deleted = 0')
+ ->orderBy('score DESC')
+ ->limit($limit)
+ ->execute();
+ }
+
}
diff --git a/app/Caches/LatestCourseList.php b/app/Caches/LatestCourseList.php
index 8874dc11..03e5b31e 100644
--- a/app/Caches/LatestCourseList.php
+++ b/app/Caches/LatestCourseList.php
@@ -3,8 +3,8 @@
namespace App\Caches;
use App\Models\Course as CourseModel;
-use App\Repos\Course as CourseRepo;
use Phalcon\Mvc\Model\Resultset;
+use Phalcon\Mvc\Model\ResultsetInterface;
class LatestCourseList extends Cache
{
@@ -23,12 +23,7 @@ class LatestCourseList extends Cache
public function getContent($id = null)
{
- $courseRepo = new CourseRepo();
-
- /**
- * @var Resultset $courses
- */
- $courses = $courseRepo->findRelatedCourses($id);
+ $courses = $this->findLatestCourses(5);
if ($courses->count() == 0) {
return [];
@@ -37,7 +32,6 @@ class LatestCourseList extends Cache
return $this->handleContent($courses);
}
-
/**
* @param CourseModel[] $courses
* @return array
@@ -67,4 +61,17 @@ class LatestCourseList extends Cache
return $result;
}
+ /**
+ * @param int $limit
+ * @return ResultsetInterface|Resultset|CourseModel[]
+ */
+ protected function findLatestCourses($limit = 10)
+ {
+ return CourseModel::query()
+ ->where('deleted = 0')
+ ->orderBy('created_at DESC')
+ ->limit($limit)
+ ->execute();
+ }
+
}
diff --git a/app/Caches/NavTreeList.php b/app/Caches/NavTreeList.php
index 32260510..abda0cbd 100644
--- a/app/Caches/NavTreeList.php
+++ b/app/Caches/NavTreeList.php
@@ -59,12 +59,10 @@ class NavTreeList extends Cache
$builder = new NavTreeListBuilder();
- $content = [
+ return [
'top' => $builder->handleTreeList($list['top']),
'bottom' => $builder->handleTreeList($list['bottom']),
];
-
- return $content;
}
}
diff --git a/app/Caches/SlideList.php b/app/Caches/SlideList.php
index 91f962ba..9acaf2ea 100644
--- a/app/Caches/SlideList.php
+++ b/app/Caches/SlideList.php
@@ -23,7 +23,7 @@ class SlideList extends Cache
public function getContent($id = null)
{
/**
- * @var Resultset $slides
+ * @var Resultset|SlideModel[] $slides
*/
$slides = SlideModel::query()
->columns(['id', 'title', 'cover', 'summary', 'target', 'content'])
diff --git a/app/Caches/UserDailyCounter.php b/app/Caches/UserDailyCounter.php
index f2b8a55b..513c63fa 100644
--- a/app/Caches/UserDailyCounter.php
+++ b/app/Caches/UserDailyCounter.php
@@ -11,9 +11,7 @@ class UserDailyCounter extends Counter
{
$tomorrow = strtotime('tomorrow');
- $lifetime = $tomorrow - time();
-
- return $lifetime;
+ return $tomorrow - time();
}
public function getKey($id = null)
@@ -23,7 +21,7 @@ class UserDailyCounter extends Counter
public function getContent($id = null)
{
- $content = [
+ return [
'favorite_count' => 0,
'comment_count' => 0,
'consult_count' => 0,
@@ -33,8 +31,6 @@ class UserDailyCounter extends Counter
'consult_vote_count' => 0,
'review_vote_count' => 0,
];
-
- return $content;
}
}
diff --git a/app/Console/Tasks/CloseOrderTask.php b/app/Console/Tasks/CloseOrderTask.php
index f925f0dd..f85c3175 100644
--- a/app/Console/Tasks/CloseOrderTask.php
+++ b/app/Console/Tasks/CloseOrderTask.php
@@ -36,13 +36,11 @@ class CloseOrderTask extends Task
$createdAt = time() - 12 * 3600;
- $orders = OrderModel::query()
+ return OrderModel::query()
->where('status = :status:', ['status' => $status])
->andWhere('created_at < :created_at:', ['created_at' => $createdAt])
->limit($limit)
->execute();
-
- return $orders;
}
}
diff --git a/app/Console/Tasks/CloseTradeTask.php b/app/Console/Tasks/CloseTradeTask.php
index 38f34192..b31c0c03 100644
--- a/app/Console/Tasks/CloseTradeTask.php
+++ b/app/Console/Tasks/CloseTradeTask.php
@@ -75,13 +75,11 @@ class CloseTradeTask extends Task
$createdAt = time() - 15 * 60;
- $trades = TradeModel::query()
+ return TradeModel::query()
->where('status = :status:', ['status' => $status])
->andWhere('created_at < :created_at:', ['created_at' => $createdAt])
->limit($limit)
->execute();
-
- return $trades;
}
}
diff --git a/app/Console/Tasks/CountCourseTask.php b/app/Console/Tasks/CountCourseTask.php
index dfcd3e4f..61687c82 100644
--- a/app/Console/Tasks/CountCourseTask.php
+++ b/app/Console/Tasks/CountCourseTask.php
@@ -2,7 +2,6 @@
namespace App\Console\Tasks;
-use App\Models\Category as CategoryModel;
use App\Repos\Category as CategoryRepo;
use Phalcon\Cli\Task;
@@ -15,9 +14,6 @@ class CountCourseTask extends Task
$mapping = [];
- /**
- * @var CategoryModel[] $subCategories
- */
$subCategories = $categoryRepo->findAll(['level' => 2, 'deleted' => 0]);
foreach ($subCategories as $category) {
@@ -35,9 +31,6 @@ class CountCourseTask extends Task
}
}
- /**
- * @var CategoryModel[] $topCategories
- */
$topCategories = $categoryRepo->findAll(['level' => 1, 'deleted' => 0]);
foreach ($topCategories as $category) {
diff --git a/app/Console/Tasks/LiveNoticeProviderTask.php b/app/Console/Tasks/LiveNoticeProviderTask.php
index 022b266f..9c1b7bc0 100644
--- a/app/Console/Tasks/LiveNoticeProviderTask.php
+++ b/app/Console/Tasks/LiveNoticeProviderTask.php
@@ -68,24 +68,20 @@ class LiveNoticeProviderTask extends Task
CourseUserModel::SOURCE_IMPORT,
];
- $rows = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns(['cu.course_id', 'cu.user_id', 'cl.chapter_id', 'cl.start_time'])
->addFrom(ChapterLiveModel::class, 'cl')
->join(CourseUserModel::class, 'cl.course_id = cu.course_id', 'cu')
->inWhere('cu.source_type', $sourceTypes)
->betweenWhere('start_time', $beginTime, $endTime)
->getQuery()->execute();
-
- return $rows;
}
public function getLifetime()
{
$tomorrow = strtotime('tomorrow');
- $lifetime = $tomorrow - time();
-
- return $lifetime;
+ return $tomorrow - time();
}
public function getCacheKey()
diff --git a/app/Console/Tasks/ManageCourseIndexTask.php b/app/Console/Tasks/ManageCourseIndexTask.php
index b2e459cd..36f049c6 100644
--- a/app/Console/Tasks/ManageCourseIndexTask.php
+++ b/app/Console/Tasks/ManageCourseIndexTask.php
@@ -110,23 +110,19 @@ class ManageCourseIndexTask extends Task
{
$searcher = new CourseSearch();
- $result = $searcher->search($query);
-
- return $result;
+ return $searcher->search($query);
}
/**
* 查找课程
*
- * @return Resultset|ResultsetInterface
+ * @return ResultsetInterface|Resultset|CourseModel[]
*/
protected function findCourses()
{
- $courses = CourseModel::query()
+ return CourseModel::query()
->where('published = 1')
->execute();
-
- return $courses;
}
}
diff --git a/app/Console/Tasks/OrderTask.php b/app/Console/Tasks/OrderTask.php
index 3f640456..15943105 100644
--- a/app/Console/Tasks/OrderTask.php
+++ b/app/Console/Tasks/OrderTask.php
@@ -225,13 +225,11 @@ class OrderTask extends Task
{
$status = TradeModel::STATUS_FINISHED;
- $result = TradeModel::findFirst([
+ return TradeModel::findFirst([
'conditions' => ['order_id = :order_id: AND status = :status:'],
'bind' => ['order_id' => $orderId, 'status' => $status],
'order' => 'id DESC',
]);
-
- return $result;
}
/**
@@ -244,15 +242,13 @@ class OrderTask extends Task
$status = TaskModel::STATUS_PENDING;
$tryCount = self::TRY_COUNT;
- $tasks = TaskModel::query()
+ return TaskModel::query()
->where('item_type = :item_type:', ['item_type' => $itemType])
->andWhere('status = :status:', ['status' => $status])
->andWhere('try_count < :try_count:', ['try_count' => $tryCount])
->orderBy('priority ASC')
->limit($limit)
->execute();
-
- return $tasks;
}
}
diff --git a/app/Console/Tasks/RebuildChapterCacheTask.php b/app/Console/Tasks/RebuildChapterCacheTask.php
index 7eefc278..a1763e33 100644
--- a/app/Console/Tasks/RebuildChapterCacheTask.php
+++ b/app/Console/Tasks/RebuildChapterCacheTask.php
@@ -4,6 +4,7 @@ namespace App\Console\Tasks;
use App\Caches\Chapter as ChapterCache;
use App\Caches\ChapterCounter as ChapterCounterCache;
+use App\Library\Cache\Backend\Redis as RedisCache;
use App\Repos\Chapter as ChapterRepo;
use App\Services\ChapterCacheSyncer;
use Phalcon\Mvc\Model\Resultset;
@@ -12,7 +13,7 @@ class RebuildChapterCacheTask extends Task
{
/**
- * @var \App\Library\Cache\Backend\Redis
+ * @var RedisCache
*/
protected $cache;
diff --git a/app/Console/Tasks/RefundTask.php b/app/Console/Tasks/RefundTask.php
index 22b3f265..e890759e 100644
--- a/app/Console/Tasks/RefundTask.php
+++ b/app/Console/Tasks/RefundTask.php
@@ -277,15 +277,13 @@ class RefundTask extends Task
$status = TaskModel::STATUS_PENDING;
$tryCount = self::TRY_COUNT;
- $tasks = TaskModel::query()
+ return TaskModel::query()
->where('item_type = :item_type:', ['item_type' => $itemType])
->andWhere('status = :status:', ['status' => $status])
->andWhere('try_count < :try_count:', ['try_count' => $tryCount])
->orderBy('priority ASC')
->limit($limit)
->execute();
-
- return $tasks;
}
}
diff --git a/app/Console/Tasks/RevokeVipTask.php b/app/Console/Tasks/RevokeVipTask.php
index ce30a64a..56a11e1d 100644
--- a/app/Console/Tasks/RevokeVipTask.php
+++ b/app/Console/Tasks/RevokeVipTask.php
@@ -34,13 +34,11 @@ class RevokeVipTask extends Task
{
$time = time();
- $users = UserModel::query()
+ return UserModel::query()
->where('vip = 1')
- ->andWhere('vip_expiry < :time:', ['time' => $time])
+ ->andWhere('vip_expiry_time < :time:', ['time' => $time])
->limit($limit)
->execute();
-
- return $users;
}
}
diff --git a/app/Console/Tasks/UnlockUserTask.php b/app/Console/Tasks/UnlockUserTask.php
index ee316cf1..0f21f6a0 100644
--- a/app/Console/Tasks/UnlockUserTask.php
+++ b/app/Console/Tasks/UnlockUserTask.php
@@ -28,19 +28,17 @@ class UnlockUserTask extends Task
* 查找待解锁用户
*
* @param int $limit
- * @return UserModel[]|Resultset|ResultsetInterface
+ * @return ResultsetInterface|Resultset|UserModel[]
*/
protected function findUsers($limit = 1000)
{
$time = time() - 6 * 3600;
- $users = UserModel::query()
+ return UserModel::query()
->where('locked = 1')
- ->andWhere('lock_expiry < :time:', ['time' => $time])
+ ->andWhere('lock_expiry_time < :time:', ['time' => $time])
->limit($limit)
->execute();
-
- return $users;
}
}
diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php
index 150c1c4e..b3ee9621 100644
--- a/app/Console/Tasks/VodEventTask.php
+++ b/app/Console/Tasks/VodEventTask.php
@@ -127,27 +127,21 @@ class VodEventTask extends Task
{
$vodService = new VodService();
- $result = $vodService->pullEvents();
-
- return $result;
+ return $vodService->pullEvents();
}
protected function confirmEvents($handles)
{
$vodService = new VodService();
- $result = $vodService->confirmEvents($handles);
-
- return $result;
+ return $vodService->confirmEvents($handles);
}
protected function isAudioFile($format)
{
$formats = ['mp3', 'm4a', 'wav', 'flac', 'ogg'];
- $result = in_array(strtolower($format), $formats);
-
- return $result;
+ return in_array(strtolower($format), $formats);
}
protected function updateVodAttrs($courseId)
diff --git a/app/Http/Admin/Controllers/TestController.php b/app/Http/Admin/Controllers/TestController.php
index 1d95ac89..118c78c6 100644
--- a/app/Http/Admin/Controllers/TestController.php
+++ b/app/Http/Admin/Controllers/TestController.php
@@ -61,7 +61,7 @@ class TestController extends Controller
$pushUrl = $liveService->getPushUrl('test');
$codeUrl = $this->url->get(
- ['for' => 'home.qr.img'],
+ ['for' => 'web.qr.img'],
['text' => urlencode($pushUrl)]
);
@@ -178,7 +178,7 @@ class TestController extends Controller
if ($code) {
$codeUrl = $this->url->get(
- ['for' => 'home.qr.img'],
+ ['for' => 'web.qr.img'],
['text' => urlencode($code)]
);
}
diff --git a/app/Http/Admin/Module.php b/app/Http/Admin/Module.php
index c083f249..d9090772 100644
--- a/app/Http/Admin/Module.php
+++ b/app/Http/Admin/Module.php
@@ -27,8 +27,7 @@ class Module implements ModuleDefinitionInterface
});
$di->setShared('auth', function () {
- $authUser = new AdminAuthUser();
- return $authUser;
+ return new AdminAuthUser();
});
}
diff --git a/app/Http/Admin/Views/course/list.volt b/app/Http/Admin/Views/course/list.volt
index b9acbb6c..59a03619 100644
--- a/app/Http/Admin/Views/course/list.volt
+++ b/app/Http/Admin/Views/course/list.volt
@@ -43,6 +43,7 @@
课程 |
课时数 |
+ 用户数 |
价格 |
发布 |
操作 |
@@ -60,6 +61,11 @@
{{ item.lesson_count }}
+
+
+ {{ item.user_count }}
+
+ |
市场:¥{{ item.market_price }}
会员:¥{{ item.vip_price }}
diff --git a/app/Http/Admin/Views/index/index.volt b/app/Http/Admin/Views/index/index.volt
index b42e183d..e6fd7d7d 100644
--- a/app/Http/Admin/Views/index/index.volt
+++ b/app/Http/Admin/Views/index/index.volt
@@ -37,7 +37,7 @@
- 前台
+ 前台
diff --git a/app/Http/Api/Controllers/IndexController.php b/app/Http/Api/Controllers/IndexController.php
index e7822807..aae9808f 100644
--- a/app/Http/Api/Controllers/IndexController.php
+++ b/app/Http/Api/Controllers/IndexController.php
@@ -34,7 +34,7 @@ class IndexController extends Controller
}
}
- dd($definitions);
+ return $this->jsonSuccess(['routes' => $definitions]);
}
}
diff --git a/app/Http/Api/Module.php b/app/Http/Api/Module.php
index 49f43c50..4cfa2df9 100644
--- a/app/Http/Api/Module.php
+++ b/app/Http/Api/Module.php
@@ -2,7 +2,7 @@
namespace App\Http\Api;
-use App\Services\AuthUser\Home as ApiAuthUser;
+use App\Services\AuthUser\Web as ApiAuthUser;
use Phalcon\DiInterface;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Mvc\View;
@@ -24,8 +24,8 @@ class Module implements ModuleDefinitionInterface
});
$di->setShared('auth', function () {
- $authUser = new ApiAuthUser();
- return $authUser;
+ return new ApiAuthUser();
});
}
+
}
diff --git a/app/Services/Frontend/Account/Login.php b/app/Http/Api/Services/Login.php
similarity index 63%
rename from app/Services/Frontend/Account/Login.php
rename to app/Http/Api/Services/Login.php
index ecac97f9..23054fbf 100644
--- a/app/Services/Frontend/Account/Login.php
+++ b/app/Http/Api/Services/Login.php
@@ -1,10 +1,9 @@
checkUserLogin($account, $password);
-
- return $user;
}
public function loginByVerify($account, $code)
{
- $validator = new SecurityValidator();
+ $validator = new AccountValidator();
+
+ $user = $validator->checkVerifyLogin($account, $code);
+ }
+
+ protected function grantAuthToken()
+ {
- $validator->checkVerifyCode($account, $code);
}
}
diff --git a/app/Services/Frontend/Account/Logout.php b/app/Http/Api/Services/Logout.php
similarity index 100%
rename from app/Services/Frontend/Account/Logout.php
rename to app/Http/Api/Services/Logout.php
diff --git a/app/Http/Html5/Controllers/Controller.php b/app/Http/Html5/Controllers/Controller.php
new file mode 100644
index 00000000..f8722e24
--- /dev/null
+++ b/app/Http/Html5/Controllers/Controller.php
@@ -0,0 +1,17 @@
+router->getRoutes();
+
+ foreach ($routes as $route) {
+ if (strpos($route->getPattern(), '/api') !== false) {
+ $definitions[] = [
+ 'pattern' => $route->getPattern(),
+ 'methods' => $route->getHttpMethods(),
+ ];
+ }
+ }
+
+ return $this->jsonSuccess(['routes' => $definitions]);
+ }
+
+}
diff --git a/app/Http/Html5/Module.php b/app/Http/Html5/Module.php
new file mode 100644
index 00000000..b492a3af
--- /dev/null
+++ b/app/Http/Html5/Module.php
@@ -0,0 +1,31 @@
+setShared('view', function () {
+ $view = new View();
+ $view->disable();
+ return $view;
+ });
+
+ $di->setShared('auth', function () {
+ return new Html5AuthUser();
+ });
+ }
+
+}
diff --git a/app/Http/Html5/Services/Login.php b/app/Http/Html5/Services/Login.php
new file mode 100644
index 00000000..45cbb402
--- /dev/null
+++ b/app/Http/Html5/Services/Login.php
@@ -0,0 +1,29 @@
+checkUserLogin($account, $password);
+ }
+
+ public function loginByVerify($account, $code)
+ {
+ $validator = new AccountValidator();
+
+ $user = $validator->checkVerifyLogin($account, $code);
+ }
+
+ protected function grantAuthToken()
+ {
+
+ }
+
+}
diff --git a/app/Http/Html5/Services/Logout.php b/app/Http/Html5/Services/Logout.php
new file mode 100644
index 00000000..baa0e3cb
--- /dev/null
+++ b/app/Http/Html5/Services/Logout.php
@@ -0,0 +1,18 @@
+logout();
- $this->response->redirect(['for' => 'home.index']);
+ $this->response->redirect(['for' => 'web.index']);
}
/**
- * @Route("/password/reset", name="home.account.reset_password")
+ * @Route("/password/reset", name="web.account.reset_password")
*/
public function resetPasswordAction()
{
@@ -63,7 +63,7 @@ class AccountController extends Controller
}
/**
- * @Post("/mobile/update", name="home.account.update_mobile")
+ * @Post("/mobile/update", name="web.account.update_mobile")
*/
public function updateMobileAction()
{
@@ -75,7 +75,7 @@ class AccountController extends Controller
}
/**
- * @Post("/password/update", name="home.account.update_password")
+ * @Post("/password/update", name="web.account.update_password")
*/
public function updatePasswordAction()
{
@@ -87,7 +87,7 @@ class AccountController extends Controller
}
/**
- * @Post("/captcha/send", name="home.account.send_captcha")
+ * @Post("/captcha/send", name="web.account.send_captcha")
*/
public function sendCaptchaAction()
{
diff --git a/app/Http/Home/Controllers/ChapterController.php b/app/Http/Web/Controllers/ChapterController.php
similarity index 72%
rename from app/Http/Home/Controllers/ChapterController.php
rename to app/Http/Web/Controllers/ChapterController.php
index 312dc312..a76bc088 100644
--- a/app/Http/Home/Controllers/ChapterController.php
+++ b/app/Http/Web/Controllers/ChapterController.php
@@ -1,8 +1,8 @@
jsonError(['msg' => '会话已过期,请重新登录']);
}
- $this->response->redirect(['for' => 'home.login']);
+ $this->response->redirect(['for' => 'web.login']);
}
/**
- * @Route("/robot", name="home.robot")
+ * @Route("/robot", name="web.robot")
*/
public function robotAction()
{
@@ -35,7 +35,7 @@ class PublicController extends \Phalcon\Mvc\Controller
}
/**
- * @Route("/forbidden", name="home.forbidden")
+ * @Route("/forbidden", name="web.forbidden")
*/
public function forbiddenAction()
{
@@ -45,7 +45,7 @@ class PublicController extends \Phalcon\Mvc\Controller
}
/**
- * @Get("/content/img/{id:[0-9]+}", name="home.content.img")
+ * @Get("/content/img/{id:[0-9]+}", name="web.content.img")
*/
public function contentImageAction($id)
{
@@ -66,7 +66,7 @@ class PublicController extends \Phalcon\Mvc\Controller
}
/**
- * @Get("/qr/img", name="home.qr.img")
+ * @Get("/qr/img", name="web.qr.img")
*/
public function qrImageAction()
{
diff --git a/app/Http/Home/Controllers/ReviewController.php b/app/Http/Web/Controllers/ReviewController.php
similarity index 75%
rename from app/Http/Home/Controllers/ReviewController.php
rename to app/Http/Web/Controllers/ReviewController.php
index 2e4e2572..ca05ce10 100644
--- a/app/Http/Home/Controllers/ReviewController.php
+++ b/app/Http/Web/Controllers/ReviewController.php
@@ -1,8 +1,8 @@
setShared('auth', function () {
- $authUser = new HomeAuthUser();
- return $authUser;
+ return new WebAuthUser();
});
}
+
}
diff --git a/app/Http/Web/Services/Service.php b/app/Http/Web/Services/Service.php
new file mode 100644
index 00000000..7f2424ec
--- /dev/null
+++ b/app/Http/Web/Services/Service.php
@@ -0,0 +1,12 @@
+params['page'] = $page;
- $queryUrl = $this->url . '?' . http_build_query($this->params);
-
- return $queryUrl;
+ return $this->url . '?' . http_build_query($this->params);
}
}
diff --git a/app/Library/Paginator/Query.php b/app/Library/Paginator/Query.php
index 1e61f837..095b959c 100644
--- a/app/Library/Paginator/Query.php
+++ b/app/Library/Paginator/Query.php
@@ -11,39 +11,29 @@ class Query extends Component
{
$page = $this->request->get('page', 'int', 1);
- $result = $page > 1000 ? 1000 : $page;
-
- return $result;
+ return $page > 1000 ? 1000 : $page;
}
public function getLimit()
{
$limit = $this->request->get('limit', 'int', 15);
- $result = $limit > 100 ? 100 : $limit;
-
- return $result;
+ return $limit > 100 ? 100 : $limit;
}
public function getSort()
{
- $sort = $this->request->get('sort', 'trim', '');
-
- return $sort;
+ return $this->request->get('sort', 'trim', '');
}
public function getUrl()
{
- $url = $this->request->get('_url', 'trim', '');
-
- return $url;
+ return $this->request->get('_url', 'trim', '');
}
public function getParams()
{
- $params = $this->request->get();
-
- return $params;
+ return $this->request->get();
}
}
diff --git a/app/Library/Security.php b/app/Library/Security.php
index 87b6f7ea..fd7fe161 100644
--- a/app/Library/Security.php
+++ b/app/Library/Security.php
@@ -31,6 +31,7 @@ class Security
$this->options['lifetime'] = $options['lifetime'] ?? 3600;
$this->cache = Di::getDefault()->get('cache');
+
$this->session = Di::getDefault()->get('session');
$this->generateToken();
diff --git a/app/Library/Util/Word.php b/app/Library/Util/Word.php
index 73e74afd..06009f2b 100644
--- a/app/Library/Util/Word.php
+++ b/app/Library/Util/Word.php
@@ -51,9 +51,7 @@ class Word
public static function filterChineseWords($str)
{
- $result = preg_replace(self::CHINESE_PATTERN, '', $str);
-
- return $result;
+ return preg_replace(self::CHINESE_PATTERN, '', $str);
}
public static function filterChineseSymbols($str)
@@ -65,9 +63,7 @@ class Word
'?', '!', ':', ';', '“ ', '”', '‘', '’',
];
- $result = str_replace($search, '', $str);
-
- return $result;
+ return str_replace($search, '', $str);
}
}
diff --git a/app/Listeners/Listener.php b/app/Listeners/Listener.php
index 1da3ee12..dfbb0b19 100644
--- a/app/Listeners/Listener.php
+++ b/app/Listeners/Listener.php
@@ -2,7 +2,7 @@
namespace App\Listeners;
-use App\Caches\Config as ConfigCache;
+use App\Caches\SectionConfig as SectionConfigCache;
use App\Library\Logger as AppLogger;
use Phalcon\Logger\Adapter\File as FileLogger;
use Phalcon\Mvc\User\Plugin as UserPlugin;
@@ -33,11 +33,9 @@ class Listener extends UserPlugin
*/
public function getSectionConfig($section)
{
- $configCache = new ConfigCache();
+ $cache = new SectionConfigCache();
- $result = $configCache->getSectionConfig($section);
-
- return $result;
+ return $cache->get($section);
}
}
diff --git a/app/Models/AccessToken.php b/app/Models/AccessToken.php
new file mode 100644
index 00000000..dc411e09
--- /dev/null
+++ b/app/Models/AccessToken.php
@@ -0,0 +1,95 @@
+addBehavior(
+ new SoftDelete([
+ 'field' => 'deleted',
+ 'value' => 1,
+ ])
+ );
+ }
+
+ public function beforeCreate()
+ {
+ $this->id = $this->getRandId($this->user_id);
+
+ $this->expired_at = strtotime('+2 hours');
+ }
+
+ public function beforeUpdate()
+ {
+ $this->updated_at = time();
+ }
+
+ public function afterCreate()
+ {
+ $refreshToken = new RefreshToken();
+
+ $refreshToken->user_id = $this->user_id;
+
+ $refreshToken->create();
+ }
+
+ protected function getRandId($userId, $prefix = 'AT')
+ {
+ return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999));
+ }
+
+}
diff --git a/app/Models/CourseUser.php b/app/Models/CourseUser.php
index 7fbffd34..ce5735cb 100644
--- a/app/Models/CourseUser.php
+++ b/app/Models/CourseUser.php
@@ -133,23 +133,19 @@ class CourseUser extends Model
public static function roleTypes()
{
- $list = [
+ return [
self::ROLE_STUDENT => '学员',
self::ROLE_TEACHER => '讲师',
];
-
- return $list;
}
public static function sourceTypes()
{
- $list = [
+ return [
self::SOURCE_FREE => '免费',
self::SOURCE_CHARGE => '付费',
self::SOURCE_IMPORT => '导入',
];
-
- return $list;
}
}
diff --git a/app/Models/Nav.php b/app/Models/Nav.php
index 30affc89..78cacb34 100644
--- a/app/Models/Nav.php
+++ b/app/Models/Nav.php
@@ -164,22 +164,18 @@ class Nav extends Model
public static function positionTypes()
{
- $list = [
+ return [
self::POSITION_TOP => '顶部',
self::POSITION_BOTTOM => '底部',
];
-
- return $list;
}
public static function targetTypes()
{
- $list = [
+ return [
self::TARGET_BLANK => '新窗口',
self::TARGET_SELF => '原窗口',
];
-
- return $list;
}
}
diff --git a/app/Models/Order.php b/app/Models/Order.php
index c879f87a..429d7dfe 100644
--- a/app/Models/Order.php
+++ b/app/Models/Order.php
@@ -181,38 +181,32 @@ class Order extends Model
public static function itemTypes()
{
- $list = [
+ return [
self::ITEM_COURSE => '课程',
self::ITEM_PACKAGE => '套餐',
self::ITEM_REWARD => '赞赏',
self::ITEM_VIP => '会员',
self::ITEM_TEST => '测试',
];
-
- return $list;
}
public static function sourceTypes()
{
- $list = [
+ return [
self::SOURCE_DESKTOP => 'desktop',
self::SOURCE_ANDROID => 'android',
self::SOURCE_IOS => 'ios',
];
-
- return $list;
}
public static function statusTypes()
{
- $list = [
+ return [
self::STATUS_PENDING => '待支付',
self::STATUS_FINISHED => '已完成',
self::STATUS_CLOSED => '已关闭',
self::STATUS_REFUNDED => '已退款',
];
-
- return $list;
}
}
diff --git a/app/Models/RefreshToken.php b/app/Models/RefreshToken.php
new file mode 100644
index 00000000..c476e191
--- /dev/null
+++ b/app/Models/RefreshToken.php
@@ -0,0 +1,87 @@
+addBehavior(
+ new SoftDelete([
+ 'field' => 'deleted',
+ 'value' => 1,
+ ])
+ );
+ }
+
+ public function beforeCreate()
+ {
+ $this->id = $this->getRandId($this->user_id);
+
+ $this->expired_at = strtotime('+30 days');
+
+ $this->created_at = time();
+ }
+
+ public function beforeUpdate()
+ {
+ $this->updated_at = time();
+ }
+
+ protected function getRandId($userId, $prefix = 'RT')
+ {
+ return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999));
+ }
+}
diff --git a/app/Models/Refund.php b/app/Models/Refund.php
index 6b455ed3..b5e4ae49 100644
--- a/app/Models/Refund.php
+++ b/app/Models/Refund.php
@@ -146,7 +146,7 @@ class Refund extends Model
public static function statusTypes()
{
- $list = [
+ return [
self::STATUS_PENDING => '待处理',
self::STATUS_CANCELED => '已取消',
self::STATUS_APPROVED => '已审核',
@@ -154,8 +154,6 @@ class Refund extends Model
self::STATUS_FINISHED => '已完成',
self::STATUS_FAILED => '已失败',
];
-
- return $list;
}
}
diff --git a/app/Models/Role.php b/app/Models/Role.php
index 2d55e067..50301358 100644
--- a/app/Models/Role.php
+++ b/app/Models/Role.php
@@ -128,24 +128,20 @@ class Role extends Model
public static function types()
{
- $list = [
+ return [
self::TYPE_SYSTEM => '内置',
self::TYPE_CUSTOM => '自定',
];
-
- return $list;
}
public static function sysRoleTypes()
{
- $list = [
+ return [
self::ROLE_ROOT => '管理人员',
self::ROLE_OPERATOR => '运营人员',
self::ROLE_EDITOR => '编辑人员',
self::ROLE_FINANCE => '财务人员',
];
-
- return $list;
}
}
diff --git a/app/Models/Slide.php b/app/Models/Slide.php
index cd9fae00..1041b6b6 100644
--- a/app/Models/Slide.php
+++ b/app/Models/Slide.php
@@ -137,13 +137,11 @@ class Slide extends Model
public static function targetTypes()
{
- $list = [
+ return [
self::TARGET_COURSE => '课程',
self::TARGET_PAGE => '单页',
self::TARGET_LINK => '链接',
];
-
- return $list;
}
}
diff --git a/app/Models/Trade.php b/app/Models/Trade.php
index b7af37f4..2b3da8ba 100644
--- a/app/Models/Trade.php
+++ b/app/Models/Trade.php
@@ -143,24 +143,20 @@ class Trade extends Model
public static function channelTypes()
{
- $list = [
+ return [
self::CHANNEL_ALIPAY => '支付宝',
self::CHANNEL_WXPAY => '微信',
];
-
- return $list;
}
public static function statusTypes()
{
- $list = [
+ return [
self::STATUS_PENDING => '待支付',
self::STATUS_FINISHED => '已完成',
self::STATUS_CLOSED => '已关闭',
self::STATUS_REFUNDED => '已退款',
];
-
- return $list;
}
}
diff --git a/app/Models/User.php b/app/Models/User.php
index 409e62c9..90bd40e4 100644
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -183,23 +183,19 @@ class User extends Model
public static function genderTypes()
{
- $list = [
+ return [
self::GENDER_MALE => '男',
self::GENDER_FEMALE => '女',
self::GENDER_NONE => '保密',
];
-
- return $list;
}
public static function eduRoleTypes()
{
- $list = [
+ return [
self::EDU_ROLE_STUDENT => '学员',
self::EDU_ROLE_TEACHER => '讲师',
];
-
- return $list;
}
}
diff --git a/app/Providers/Cache.php b/app/Providers/Cache.php
index 50ccd4e9..2043ec16 100644
--- a/app/Providers/Cache.php
+++ b/app/Providers/Cache.php
@@ -20,7 +20,7 @@ class Cache extends Provider
'lifetime' => $config->redis->lifetime,
]);
- $backend = new RedisBackend($frontend, [
+ return new RedisBackend($frontend, [
'host' => $config->redis->host,
'port' => $config->redis->port,
'auth' => $config->redis->auth,
@@ -28,8 +28,6 @@ class Cache extends Provider
'prefix' => $config->redis->prefix,
'persistent' => $config->redis->persistent,
]);
-
- return $backend;
});
}
diff --git a/app/Providers/Config.php b/app/Providers/Config.php
index 6205e56f..a129e018 100644
--- a/app/Providers/Config.php
+++ b/app/Providers/Config.php
@@ -15,9 +15,7 @@ class Config extends Provider
$options = require config_path() . '/config.php';
- $config = new PhalconConfig($options);
-
- return $config;
+ return new PhalconConfig($options);
});
}
diff --git a/app/Providers/Provider.php b/app/Providers/Provider.php
index d5277c58..8f9da9eb 100644
--- a/app/Providers/Provider.php
+++ b/app/Providers/Provider.php
@@ -5,13 +5,9 @@ namespace App\Providers;
use Phalcon\DiInterface;
use Phalcon\Mvc\User\Component;
-/**
- * \App\Providers\Provider
- *
- * @package App\Providers
- */
abstract class Provider extends Component implements ProviderInterface
{
+
/**
* Service name
*
@@ -38,4 +34,5 @@ abstract class Provider extends Component implements ProviderInterface
{
return $this->serviceName;
}
+
}
\ No newline at end of file
diff --git a/app/Providers/ProviderInterface.php b/app/Providers/ProviderInterface.php
index 1d1a674a..d87b6eff 100644
--- a/app/Providers/ProviderInterface.php
+++ b/app/Providers/ProviderInterface.php
@@ -4,13 +4,9 @@ namespace App\Providers;
use Phalcon\Di\InjectionAwareInterface;
-/**
- * \App\Providers\ServiceProviderInterface
- *
- * @package App\Providers
- */
interface ProviderInterface extends InjectionAwareInterface
{
+
/**
* Register application service.
*
@@ -24,4 +20,5 @@ interface ProviderInterface extends InjectionAwareInterface
* @return string
*/
public function getName();
+
}
\ No newline at end of file
diff --git a/app/Providers/Router.php b/app/Providers/Router.php
index dd8bb0a1..03d4f3cc 100644
--- a/app/Providers/Router.php
+++ b/app/Providers/Router.php
@@ -16,28 +16,28 @@ class Router extends Provider
$router = new AnnotationsRouter(false);
$router->removeExtraSlashes(true);
- $router->setDefaultNamespace('App\Http\Home\Controllers');
+ $router->setDefaultNamespace('App\Http\Web\Controllers');
$router->notFound([
- 'module' => 'home',
+ 'module' => 'web',
'controller' => 'error',
'action' => 'show404',
]);
- $homeFiles = scandir(app_path('Http/Home/Controllers'));
+ $webFiles = scandir(app_path('Http/Web/Controllers'));
- foreach ($homeFiles as $file) {
+ foreach ($webFiles as $file) {
if (strpos($file, 'Controller.php')) {
$className = str_replace('Controller.php', '', $file);
- $router->addModuleResource('home', 'App\Http\Home\Controllers\\' . $className);
+ $router->addModuleResource('home', 'App\Http\Web\Controllers\\' . $className);
}
}
- $adminFiles = scandir(app_path('Http/Admin/Controllers'));
+ $html5Files = scandir(app_path('Http/Html5/Controllers'));
- foreach ($adminFiles as $file) {
+ foreach ($html5Files as $file) {
if (strpos($file, 'Controller.php')) {
$className = str_replace('Controller.php', '', $file);
- $router->addModuleResource('admin', 'App\Http\Admin\Controllers\\' . $className);
+ $router->addModuleResource('html5', 'App\Http\Html5\Controllers\\' . $className);
}
}
@@ -50,6 +50,15 @@ class Router extends Provider
}
}
+ $adminFiles = scandir(app_path('Http/Admin/Controllers'));
+
+ foreach ($adminFiles as $file) {
+ if (strpos($file, 'Controller.php')) {
+ $className = str_replace('Controller.php', '', $file);
+ $router->addModuleResource('admin', 'App\Http\Admin\Controllers\\' . $className);
+ }
+ }
+
return $router;
});
}
diff --git a/app/Providers/Security.php b/app/Providers/Security.php
index 79079c28..0ce21a81 100644
--- a/app/Providers/Security.php
+++ b/app/Providers/Security.php
@@ -12,10 +12,7 @@ class Security extends Provider
public function register()
{
$this->di->setShared($this->serviceName, function () {
-
- $security = new AppSecurity();
-
- return $security;
+ return new AppSecurity();
});
}
diff --git a/app/Repos/AccessToken.php b/app/Repos/AccessToken.php
new file mode 100644
index 00000000..8c218f43
--- /dev/null
+++ b/app/Repos/AccessToken.php
@@ -0,0 +1,42 @@
+where('user_id = :user_id:', ['user_id' => $userId])
+ ->andWhere('deleted = 0')
+ ->execute();
+ }
+
+ public function countByUserId($userId)
+ {
+ return AccessTokenModel::count([
+ 'conditions' => 'user_id = :user_id: AND deleted = 0',
+ 'bind' => ['user_id' => $userId],
+ ]);
+ }
+
+}
diff --git a/app/Repos/Account.php b/app/Repos/Account.php
index 58cbe735..680ab79c 100644
--- a/app/Repos/Account.php
+++ b/app/Repos/Account.php
@@ -16,9 +16,7 @@ class Account extends Repository
*/
public function findById($id)
{
- $result = AccountModel::findFirst($id);
-
- return $result;
+ return AccountModel::findFirst($id);
}
/**
@@ -27,12 +25,10 @@ class Account extends Repository
*/
public function findByPhone($phone)
{
- $result = AccountModel::findFirst([
+ return AccountModel::findFirst([
'conditions' => 'phone = :phone:',
'bind' => ['phone' => $phone],
]);
-
- return $result;
}
/**
@@ -41,12 +37,10 @@ class Account extends Repository
*/
public function findByEmail($email)
{
- $result = AccountModel::findFirst([
+ return AccountModel::findFirst([
'conditions' => 'email = :email:',
'bind' => ['email' => $email],
]);
-
- return $result;
}
/**
@@ -56,12 +50,10 @@ class Account extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = AccountModel::query()
+ return AccountModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/Audit.php b/app/Repos/Audit.php
index 20ef3e87..3c3b8cb1 100644
--- a/app/Repos/Audit.php
+++ b/app/Repos/Audit.php
@@ -11,13 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Audit extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return object
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -71,9 +64,7 @@ class Audit extends Repository
*/
public function findById($id)
{
- $result = AuditModel::findFirst($id);
-
- return $result;
+ return AuditModel::findFirst($id);
}
/**
@@ -83,13 +74,10 @@ class Audit extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = AuditModel::query()
+ return AuditModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
-
}
diff --git a/app/Repos/Category.php b/app/Repos/Category.php
index 49a6188c..a00c5bfc 100644
--- a/app/Repos/Category.php
+++ b/app/Repos/Category.php
@@ -12,32 +12,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Category extends Repository
{
- /**
- * @param int $id
- * @return CategoryModel|Model|bool
- */
- public function findById($id)
- {
- $result = CategoryModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param array|string $columns
- * @return ResultsetInterface|Resultset|CategoryModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = CategoryModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|CategoryModel[]
@@ -66,9 +40,29 @@ class Category extends Repository
$query->orderBy('priority ASC');
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $id
+ * @return CategoryModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return CategoryModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param array|string $columns
+ * @return ResultsetInterface|Resultset|CategoryModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return CategoryModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
}
/**
@@ -76,13 +70,11 @@ class Category extends Repository
*/
public function findTopCategories()
{
- $result = CategoryModel::query()
+ return CategoryModel::query()
->where('parent_id = 0')
->andWhere('deleted = 0')
->andWhere('published = 1')
->execute();
-
- return $result;
}
/**
@@ -91,29 +83,25 @@ class Category extends Repository
*/
public function findChildCategories($categoryId)
{
- $result = CategoryModel::query()
+ return CategoryModel::query()
->where('parent_id = :parent_id:', ['parent_id' => $categoryId])
->andWhere('deleted = 0')
->andWhere('published = 1')
->execute();
-
- return $result;
}
public function countChildCategories($categoryId)
{
- $count = CategoryModel::count([
+ return CategoryModel::count([
'conditions' => 'parent_id = :parent_id: AND deleted = 0 AND published = 1',
'bind' => ['parent_id' => $categoryId],
]);
-
- return $count;
}
public function countCourses($categoryId)
{
- $phql = "SELECT COUNT(*) AS total FROM %s cc JOIN %s c ON cc.course_id = c.id
- WHERE cc.category_id = :category_id: AND c.published = 1 AND c.deleted = 0";
+ $phql = 'SELECT COUNT(*) AS total FROM %s cc JOIN %s c ON cc.course_id = c.id
+ WHERE cc.category_id = :category_id: AND c.published = 1 AND c.deleted = 0';
$phql = sprintf($phql, CourseCategoryModel::class, CourseModel::class);
diff --git a/app/Repos/Chapter.php b/app/Repos/Chapter.php
index ee3628ee..efd27b37 100644
--- a/app/Repos/Chapter.php
+++ b/app/Repos/Chapter.php
@@ -17,32 +17,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Chapter extends Repository
{
- /**
- * @param int $id
- * @return ChapterModel|Model|bool
- */
- public function findById($id)
- {
- $result = ChapterModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param string|array $columns
- * @return ResultsetInterface|Resultset|ChapterModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = ChapterModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|ChapterModel[]
@@ -69,9 +43,29 @@ class Chapter extends Repository
$query->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]);
}
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $id
+ * @return ChapterModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return ChapterModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param string|array $columns
+ * @return ResultsetInterface|Resultset|ChapterModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return ChapterModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
}
/**
@@ -87,9 +81,7 @@ class Chapter extends Repository
if (!$vod) return false;
- $result = ChapterModel::findFirst($vod->chapter_id);
-
- return $result;
+ return ChapterModel::findFirst($vod->chapter_id);
}
/**
@@ -98,12 +90,10 @@ class Chapter extends Repository
*/
public function findChapterVod($chapterId)
{
- $result = ChapterVodModel::findFirst([
+ return ChapterVodModel::findFirst([
'conditions' => 'chapter_id = :chapter_id:',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $result;
}
/**
@@ -112,12 +102,10 @@ class Chapter extends Repository
*/
public function findChapterLive($chapterId)
{
- $result = ChapterLiveModel::findFirst([
+ return ChapterLiveModel::findFirst([
'conditions' => 'chapter_id = :chapter_id:',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $result;
}
/**
@@ -126,12 +114,10 @@ class Chapter extends Repository
*/
public function findChapterRead($chapterId)
{
- $result = ChapterReadModel::findFirst([
+ return ChapterReadModel::findFirst([
'conditions' => 'chapter_id = :chapter_id:',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $result;
}
/**
@@ -141,101 +127,83 @@ class Chapter extends Repository
*/
public function findUserCommentVotes($chapterId, $userId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('cv.*')
->addFrom(CommentModel::class, 'c')
->join(CommentVoteModel::class, 'c.id = cv.comment_id', 'cv')
->where('c.chapter_id = :chapter_id:', ['chapter_id' => $chapterId])
->andWhere('cv.user_id = :user_id:', ['user_id' => $userId])
->getQuery()->execute();
-
- return $result;
}
public function maxChapterPriority($courseId)
{
- $result = ChapterModel::maximum([
+ return ChapterModel::maximum([
'column' => 'priority',
'conditions' => 'course_id = :course_id: AND parent_id = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $result;
}
public function maxLessonPriority($chapterId)
{
- $result = ChapterModel::maximum([
+ return ChapterModel::maximum([
'column' => 'priority',
'conditions' => 'parent_id = :parent_id:',
'bind' => ['parent_id' => $chapterId],
]);
-
- return $result;
}
public function countLessons($chapterId)
{
- $result = ChapterModel::count([
+ return ChapterModel::count([
'conditions' => 'parent_id = :chapter_id: AND deleted = 0',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $result;
}
public function countUsers($chapterId)
{
- $count = ChapterUserModel::count([
+ return ChapterUserModel::count([
'conditions' => 'chapter_id = :chapter_id: AND deleted = 0',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $count;
}
public function countComments($chapterId)
{
- $count = CommentModel::count([
+ return CommentModel::count([
'conditions' => 'chapter_id = :chapter_id: AND deleted = 0',
'bind' => ['chapter_id' => $chapterId],
]);
-
- return $count;
}
public function countAgrees($chapterId)
{
$type = ChapterVoteModel::TYPE_AGREE;
- $count = ChapterVoteModel::count([
+ return ChapterVoteModel::count([
'conditions' => 'chapter_id = :chapter_id: AND type = :type: AND deleted = 0',
'bind' => ['chapter_id' => $chapterId, 'type' => $type],
]);
-
- return $count;
}
public function countOpposes($chapterId)
{
$type = ChapterVoteModel::TYPE_OPPOSE;
- $count = ChapterVoteModel::count([
+ return ChapterVoteModel::count([
'conditions' => 'chapter_id = :chapter_id: AND type = :type: AND deleted = 0',
'bind' => ['chapter_id' => $chapterId, 'type' => $type],
]);
-
- return $count;
}
public function countUserComments($chapterId, $userId)
{
- $count = CommentModel::count([
+ return CommentModel::count([
'conditions' => 'chapter_id = :chapter_id: AND user_id = :user_id:',
'bind' => ['chapter_id' => $chapterId, 'user_id' => $userId],
]);
-
- return $count;
}
}
diff --git a/app/Repos/ChapterUser.php b/app/Repos/ChapterUser.php
index dbe58e68..ff671552 100644
--- a/app/Repos/ChapterUser.php
+++ b/app/Repos/ChapterUser.php
@@ -10,21 +10,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class ChapterUser extends Repository
{
- /**
- * @param int $chapterId
- * @param int $userId
- * @return ChapterUserModel|Model|bool
- */
- public function findChapterUser($chapterId, $userId)
- {
- $result = ChapterUserModel::findFirst([
- 'conditions' => 'chapter_id = ?1 AND user_id = ?2 AND deleted = 0',
- 'bind' => [1 => $chapterId, 2 => $userId],
- ]);
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|ChapterUserModel[]
@@ -47,9 +32,20 @@ class ChapterUser extends Repository
$query->andWhere('user_id = :user_id:', ['user_id' => $where['user_id']]);
}
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $chapterId
+ * @param int $userId
+ * @return ChapterUserModel|Model|bool
+ */
+ public function findChapterUser($chapterId, $userId)
+ {
+ return ChapterUserModel::findFirst([
+ 'conditions' => 'chapter_id = ?1 AND user_id = ?2 AND deleted = 0',
+ 'bind' => [1 => $chapterId, 2 => $userId],
+ ]);
}
}
diff --git a/app/Repos/ChapterVote.php b/app/Repos/ChapterVote.php
index fad79926..48fd83d6 100644
--- a/app/Repos/ChapterVote.php
+++ b/app/Repos/ChapterVote.php
@@ -15,12 +15,10 @@ class ChapterVote extends Repository
*/
public function findChapterVote($chapterId, $userId)
{
- $result = ChapterVoteModel::findFirst([
+ return ChapterVoteModel::findFirst([
'conditions' => 'chapter_id = :chapter_id: AND user_id = :user_id:',
'bind' => ['chapter_id' => $chapterId, 'user_id' => $userId],
]);
-
- return $result;
}
}
diff --git a/app/Repos/Comment.php b/app/Repos/Comment.php
index 413c4434..710cffcb 100644
--- a/app/Repos/Comment.php
+++ b/app/Repos/Comment.php
@@ -12,13 +12,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Comment extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -78,9 +71,7 @@ class Comment extends Repository
*/
public function findById($id)
{
- $result = CommentModel::findFirst($id);
-
- return $result;
+ return CommentModel::findFirst($id);
}
/**
@@ -90,46 +81,38 @@ class Comment extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = CommentModel::query()
+ return CommentModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
public function countReplies($commentId)
{
- $count = CommentModel::count([
+ return CommentModel::count([
'conditions' => 'parent_id = :parent_id: AND deleted = 0',
'bind' => ['parent_id' => $commentId],
]);
-
- return $count;
}
public function countAgrees($commentId)
{
$type = CommentVoteModel::TYPE_AGREE;
- $count = CommentVoteModel::count([
+ return CommentVoteModel::count([
'conditions' => 'comment_id = :comment_id: AND type = :type: AND deleted = 0',
'bind' => ['comment_id' => $commentId, 'type' => $type],
]);
-
- return $count;
}
public function countOpposes($commentId)
{
$type = CommentVoteModel::TYPE_OPPOSE;
- $count = CommentVoteModel::count([
+ return CommentVoteModel::count([
'conditions' => 'comment_id = :comment_id: AND type = :type: AND deleted = 0',
'bind' => ['comment_id' => $commentId, 'type' => $type],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Config.php b/app/Repos/Config.php
index 8765d680..7319f236 100644
--- a/app/Repos/Config.php
+++ b/app/Repos/Config.php
@@ -10,36 +10,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Config extends Repository
{
- /**
- * @param string $section
- * @param string $itemKey
- * @return ConfigModel|Model|bool
- */
- public function findItem($section, $itemKey)
- {
- $result = ConfigModel::findFirst([
- 'conditions' => 'section = :section: AND item_key = :item_key:',
- 'bind' => ['section' => $section, 'item_key' => $itemKey],
- ]);
-
- return $result;
- }
-
- /**
- * @param string $section
- * @return Resultset|ResultsetInterface|ConfigModel[]
- */
- public function findBySection($section)
- {
- $query = ConfigModel::query();
-
- $query->where('section = :section:', ['section' => $section]);
-
- $result = $query->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return Resultset|ResultsetInterface|ConfigModel[]
@@ -54,9 +24,33 @@ class Config extends Repository
$query->andWhere('section = :section:', ['section' => $where['section']]);
}
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param string $section
+ * @param string $itemKey
+ * @return ConfigModel|Model|bool
+ */
+ public function findItem($section, $itemKey)
+ {
+ return ConfigModel::findFirst([
+ 'conditions' => 'section = :section: AND item_key = :item_key:',
+ 'bind' => ['section' => $section, 'item_key' => $itemKey],
+ ]);
+ }
+
+ /**
+ * @param string $section
+ * @return Resultset|ResultsetInterface|ConfigModel[]
+ */
+ public function findBySection($section)
+ {
+ $query = ConfigModel::query();
+
+ $query->where('section = :section:', ['section' => $section]);
+
+ return $query->execute();
}
}
diff --git a/app/Repos/Consult.php b/app/Repos/Consult.php
index 605cb010..05cf3ddc 100644
--- a/app/Repos/Consult.php
+++ b/app/Repos/Consult.php
@@ -12,32 +12,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Consult extends Repository
{
- /**
- * @param int $id
- * @return ConsultModel|Model|bool
- */
- public function findById($id)
- {
- $result = ConsultModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param array|string $columns
- * @return ResultsetInterface|Resultset|ConsultModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = ConsultModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -83,6 +57,28 @@ class Consult extends Repository
return $pager->paginate();
}
+ /**
+ * @param int $id
+ * @return ConsultModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return ConsultModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param array|string $columns
+ * @return ResultsetInterface|Resultset|ConsultModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return ConsultModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
+ }
+
public function countAgrees($consultId)
{
$type = ConsultVoteModel::TYPE_AGREE;
diff --git a/app/Repos/ConsultVote.php b/app/Repos/ConsultVote.php
index e298e484..ab3c8653 100644
--- a/app/Repos/ConsultVote.php
+++ b/app/Repos/ConsultVote.php
@@ -15,12 +15,10 @@ class ConsultVote extends Repository
*/
public function findConsultVote($consultId, $userId)
{
- $result = ConsultVoteModel::findFirst([
+ return ConsultVoteModel::findFirst([
'conditions' => 'consult_id = :consult_id: AND user_id = :user_id:',
'bind' => ['consult_id' => $consultId, 'user_id' => $userId],
]);
-
- return $result;
}
}
diff --git a/app/Repos/Course.php b/app/Repos/Course.php
index b6a10dff..e64a27d6 100644
--- a/app/Repos/Course.php
+++ b/app/Repos/Course.php
@@ -26,13 +26,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Course extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -115,9 +108,7 @@ class Course extends Repository
*/
public function findById($id)
{
- $result = CourseModel::findFirst($id);
-
- return $result;
+ return CourseModel::findFirst($id);
}
/**
@@ -127,12 +118,10 @@ class Course extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = CourseModel::query()
+ return CourseModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -143,7 +132,7 @@ class Course extends Repository
{
$roleType = CourseUserModel::ROLE_TEACHER;
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('u.*')
->addFrom(UserModel::class, 'u')
->join(CourseUserModel::class, 'u.id = cu.user_id', 'cu')
@@ -151,8 +140,6 @@ class Course extends Repository
->andWhere('cu.role_type = :role_type:', ['role_type' => $roleType])
->andWhere('u.deleted = 0')
->getQuery()->execute();
-
- return $result;
}
/**
@@ -161,15 +148,13 @@ class Course extends Repository
*/
public function findCategories($courseId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('c.*')
->addFrom(CategoryModel::class, 'c')
->join(CourseCategoryModel::class, 'c.id = cc.category_id', 'cc')
->where('cc.course_id = :course_id:', ['course_id' => $courseId])
->andWhere('c.deleted = 0')
->getQuery()->execute();
-
- return $result;
}
/**
@@ -178,15 +163,13 @@ class Course extends Repository
*/
public function findPackages($courseId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('p.*')
->addFrom(PackageModel::class, 'p')
->join(CoursePackageModel::class, 'p.id = cp.package_id', 'cp')
->where('cp.course_id = :course_id:', ['course_id' => $courseId])
->andWhere('p.deleted = 0')
->getQuery()->execute();
-
- return $result;
}
/**
@@ -195,15 +178,13 @@ class Course extends Repository
*/
public function findRelatedCourses($courseId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('c.*')
->addFrom(CourseModel::class, 'c')
->join(CourseRelatedModel::class, 'c.id = cr.related_id', 'cr')
->where('cr.course_id = :course_id:', ['course_id' => $courseId])
->andWhere('c.deleted = 0')
->getQuery()->execute();
-
- return $result;
}
/**
@@ -212,12 +193,10 @@ class Course extends Repository
*/
public function findChapters($courseId)
{
- $result = ChapterModel::query()
+ return ChapterModel::query()
->where('course_id = :course_id:', ['course_id' => $courseId])
->andWhere('deleted = 0')
->execute();
-
- return $result;
}
/**
@@ -226,13 +205,11 @@ class Course extends Repository
*/
public function findLessons($courseId)
{
- $result = ChapterModel::query()
+ return ChapterModel::query()
->where('course_id = :course_id:', ['course_id' => $courseId])
->andWhere('parent_id > 0')
->andWhere('deleted = 0')
->execute();
-
- return $result;
}
/**
@@ -242,13 +219,11 @@ class Course extends Repository
*/
public function findUserLearnings($courseId, $userId)
{
- $result = ChapterUserModel::query()
+ return ChapterUserModel::query()
->where('course_id = :course_id:', ['course_id' => $courseId])
->andWhere('user_id = :user_id:', ['user_id' => $userId])
->andWhere('deleted = 0')
->execute();
-
- return $result;
}
/**
@@ -258,13 +233,11 @@ class Course extends Repository
*/
public function findConsumedUserLearnings($courseId, $userId)
{
- $result = ChapterUserModel::query()
+ return ChapterUserModel::query()
->where('course_id = :course_id:', ['course_id' => $courseId])
->andWhere('user_id = :user_id:', ['user_id' => $userId])
->andWhere('consumed = 1 AND deleted = 0')
->execute();
-
- return $result;
}
/**
@@ -274,15 +247,13 @@ class Course extends Repository
*/
public function findUserConsultVotes($courseId, $userId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('cv.*')
->addFrom(ConsultModel::class, 'c')
->join(ConsultVoteModel::class, 'c.id = cv.consult_id', 'cv')
->where('c.course_id = :course_id:', ['course_id' => $courseId])
->andWhere('cv.user_id = :user_id:', ['user_id' => $userId])
->getQuery()->execute();
-
- return $result;
}
/**
@@ -292,85 +263,61 @@ class Course extends Repository
*/
public function findUserReviewVotes($courseId, $userId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('rv.*')
->addFrom(ReviewModel::class, 'r')
->join(ReviewVoteModel::class, 'r.id = rv.review_id', 'rv')
->where('r.course_id = :course_id:', ['course_id' => $courseId])
->andWhere('rv.user_id = :user_id:', ['user_id' => $userId])
->getQuery()->execute();
-
- return $result;
}
public function countLessons($courseId)
{
- $count = ChapterModel::count([
+ return ChapterModel::count([
'conditions' => 'course_id = :course_id: AND parent_id > 0 AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
}
public function countUsers($courseId)
{
- $count = CourseUserModel::count([
+ return CourseUserModel::count([
'conditions' => 'course_id = :course_id: AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
}
public function countConsults($courseId)
{
- $count = ConsultModel::count([
+ return ConsultModel::count([
'conditions' => 'course_id = :course_id: AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
}
public function countReviews($courseId)
{
- $count = ReviewModel::count([
+ return ReviewModel::count([
'conditions' => 'course_id = :course_id: AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
}
public function countComments($courseId)
{
- $count = CommentModel::count([
+ return CommentModel::count([
'conditions' => 'course_id = :course_id: AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
}
public function countFavorites($courseId)
{
- $count = CourseFavoriteModel::count([
+ return CourseFavoriteModel::count([
'conditions' => 'course_id = :course_id: AND deleted = 0',
'bind' => ['course_id' => $courseId],
]);
-
- return $count;
- }
-
- public function countUserConsults($courseId, $userId)
- {
- $count = ConsultModel::count([
- 'conditions' => 'course_id = :course_id: AND user_id = :user_id:',
- 'bind' => ['course_id' => $courseId, 'user_id' => $userId],
- ]);
-
- return $count;
}
}
diff --git a/app/Repos/CourseCategory.php b/app/Repos/CourseCategory.php
index 6ffd63f6..94cefb3f 100644
--- a/app/Repos/CourseCategory.php
+++ b/app/Repos/CourseCategory.php
@@ -17,12 +17,10 @@ class CourseCategory extends Repository
*/
public function findCourseCategory($courseId, $categoryId)
{
- $result = CourseCategoryModel::findFirst([
+ return CourseCategoryModel::findFirst([
'conditions' => 'course_id = :course_id: AND category_id = :category_id:',
'bind' => ['course_id' => $courseId, 'category_id' => $categoryId],
]);
-
- return $result;
}
/**
@@ -31,11 +29,9 @@ class CourseCategory extends Repository
*/
public function findByCategoryIds($categoryIds)
{
- $result = CourseCategoryModel::query()
+ return CourseCategoryModel::query()
->inWhere('category_id', $categoryIds)
->execute();
-
- return $result;
}
/**
@@ -44,11 +40,9 @@ class CourseCategory extends Repository
*/
public function findByCourseIds($courseIds)
{
- $result = CourseCategoryModel::query()
+ return CourseCategoryModel::query()
->inWhere('course_id', $courseIds)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/CourseFavorite.php b/app/Repos/CourseFavorite.php
index a1d44981..8ea512b9 100644
--- a/app/Repos/CourseFavorite.php
+++ b/app/Repos/CourseFavorite.php
@@ -9,13 +9,6 @@ use Phalcon\Mvc\Model;
class CourseFavorite extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -60,12 +53,10 @@ class CourseFavorite extends Repository
*/
public function findCourseFavorite($courseId, $userId)
{
- $result = CourseFavoriteModel::findFirst([
+ return CourseFavoriteModel::findFirst([
'conditions' => 'course_id = :course_id: AND user_id = :user_id:',
'bind' => ['course_id' => $courseId, 'user_id' => $userId],
]);
-
- return $result;
}
}
diff --git a/app/Repos/CoursePackage.php b/app/Repos/CoursePackage.php
index ebc38df0..38fed772 100644
--- a/app/Repos/CoursePackage.php
+++ b/app/Repos/CoursePackage.php
@@ -17,12 +17,10 @@ class CoursePackage extends Repository
*/
public function findCoursePackage($courseId, $packageId)
{
- $result = CoursePackageModel::findFirst([
+ return CoursePackageModel::findFirst([
'conditions' => 'course_id = :course_id: AND package_id = :package_id:',
'bind' => ['course_id' => $courseId, 'package_id' => $packageId],
]);
-
- return $result;
}
/**
@@ -31,11 +29,9 @@ class CoursePackage extends Repository
*/
public function findByCourseId($courseId)
{
- $result = CoursePackageModel::query()
+ return CoursePackageModel::query()
->where('course_id = :course_id:', ['course_id' => $courseId])
->execute();
-
- return $result;
}
/**
@@ -44,11 +40,9 @@ class CoursePackage extends Repository
*/
public function findByPackageId($packageId)
{
- $result = CoursePackageModel::query()
+ return CoursePackageModel::query()
->where('package_id = :package_id:', ['package_id' => $packageId])
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/CourseRelated.php b/app/Repos/CourseRelated.php
index 5caa2f01..15f69488 100644
--- a/app/Repos/CourseRelated.php
+++ b/app/Repos/CourseRelated.php
@@ -17,12 +17,10 @@ class CourseRelated extends Repository
*/
public function findCourseRelated($courseId, $relatedId)
{
- $result = CourseRelatedModel::findFirst([
+ return CourseRelatedModel::findFirst([
'conditions' => 'course_id = :course_id: AND related_id = :related_id:',
'bind' => ['course_id' => $courseId, 'related_id' => $relatedId],
]);
-
- return $result;
}
/**
@@ -31,11 +29,9 @@ class CourseRelated extends Repository
*/
public function findByRelatedIds($relatedIds)
{
- $result = CourseRelatedModel::query()
+ return CourseRelatedModel::query()
->inWhere('related_id', $relatedIds)
->execute();
-
- return $result;
}
/**
@@ -44,11 +40,9 @@ class CourseRelated extends Repository
*/
public function findByCourseIds($courseIds)
{
- $result = CourseRelatedModel::query()
+ return CourseRelatedModel::query()
->inWhere('course_id', $courseIds)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/CourseTopic.php b/app/Repos/CourseTopic.php
index 1851e8b7..5ae55624 100644
--- a/app/Repos/CourseTopic.php
+++ b/app/Repos/CourseTopic.php
@@ -17,12 +17,10 @@ class CourseTopic extends Repository
*/
public function findCourseTopic($courseId, $topicId)
{
- $result = CourseTopicModel::findFirst([
+ return CourseTopicModel::findFirst([
'conditions' => 'course_id = :course_id: AND topic_id = :topic_id:',
'bind' => ['course_id' => $courseId, 'topic_id' => $topicId],
]);
-
- return $result;
}
/**
@@ -31,11 +29,9 @@ class CourseTopic extends Repository
*/
public function findByTopicIds($topicIds)
{
- $result = CourseTopicModel::query()
+ return CourseTopicModel::query()
->inWhere('topic_id', $topicIds)
->execute();
-
- return $result;
}
/**
@@ -44,11 +40,9 @@ class CourseTopic extends Repository
*/
public function findByCourseIds($courseIds)
{
- $result = CourseTopicModel::query()
+ return CourseTopicModel::query()
->inWhere('course_id', $courseIds)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/CourseUser.php b/app/Repos/CourseUser.php
index 2fe5bfd0..fdd2073e 100644
--- a/app/Repos/CourseUser.php
+++ b/app/Repos/CourseUser.php
@@ -9,13 +9,6 @@ use Phalcon\Mvc\Model;
class CourseUser extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -67,9 +60,7 @@ class CourseUser extends Repository
*/
public function findById($id)
{
- $result = CourseUserModel::findFirst($id);
-
- return $result;
+ return CourseUserModel::findFirst($id);
}
/**
@@ -79,13 +70,11 @@ class CourseUser extends Repository
*/
public function findCourseUser($courseId, $userId)
{
- $result = CourseUserModel::findFirst([
+ return CourseUserModel::findFirst([
'conditions' => 'course_id = ?1 AND user_id = ?2 AND deleted = 0',
'bind' => [1 => $courseId, 2 => $userId],
'order' => 'id DESC',
]);
-
- return $result;
}
/**
@@ -97,9 +86,7 @@ class CourseUser extends Repository
{
$roleType = CourseUserModel::ROLE_TEACHER;
- $result = $this->findRoleCourseUser($courseId, $userId, $roleType);
-
- return $result;
+ return $this->findRoleCourseUser($courseId, $userId, $roleType);
}
/**
@@ -111,9 +98,7 @@ class CourseUser extends Repository
{
$roleType = CourseUserModel::ROLE_STUDENT;
- $result = $this->findRoleCourseUser($courseId, $userId, $roleType);
-
- return $result;
+ return $this->findRoleCourseUser($courseId, $userId, $roleType);
}
/**
@@ -124,13 +109,11 @@ class CourseUser extends Repository
*/
protected function findRoleCourseUser($courseId, $userId, $roleType)
{
- $result = CourseUserModel::findFirst([
+ return CourseUserModel::findFirst([
'conditions' => 'course_id = ?1 AND user_id = ?2 AND role_type = ?3 AND deleted = 0',
'bind' => [1 => $courseId, 2 => $userId, 3 => $roleType],
'order' => 'id DESC',
]);
-
- return $result;
}
}
diff --git a/app/Repos/Help.php b/app/Repos/Help.php
index 7ab3d69d..4b406669 100644
--- a/app/Repos/Help.php
+++ b/app/Repos/Help.php
@@ -16,9 +16,7 @@ class Help extends Repository
*/
public function findById($id)
{
- $result = HelpModel::findFirst($id);
-
- return $result;
+ return HelpModel::findFirst($id);
}
/**
@@ -28,12 +26,10 @@ class Help extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = HelpModel::query()
+ return HelpModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -56,9 +52,7 @@ class Help extends Repository
$query->orderBy('priority ASC');
- $result = $query->execute();
-
- return $result;
+ return $query->execute();
}
}
diff --git a/app/Repos/Learning.php b/app/Repos/Learning.php
index 56a54fe1..44dad7e5 100644
--- a/app/Repos/Learning.php
+++ b/app/Repos/Learning.php
@@ -9,13 +9,6 @@ use Phalcon\Mvc\Model;
class Learning extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -59,9 +52,7 @@ class Learning extends Repository
*/
public function findById($id)
{
- $result = LearningModel::findFirst($id);
-
- return $result;
+ return LearningModel::findFirst($id);
}
/**
@@ -70,12 +61,10 @@ class Learning extends Repository
*/
public function findByRequestId($requestId)
{
- $result = LearningModel::findFirst([
+ return LearningModel::findFirst([
'conditions' => 'request_id = :request_id:',
'bind' => ['request_id' => $requestId],
]);
-
- return $result;
}
}
diff --git a/app/Repos/Nav.php b/app/Repos/Nav.php
index e5060170..4167de8f 100644
--- a/app/Repos/Nav.php
+++ b/app/Repos/Nav.php
@@ -10,32 +10,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Nav extends Repository
{
- /**
- * @param int $id
- * @return NavModel|Model|bool
- */
- public function findById($id)
- {
- $result = NavModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param array|string $columns
- * @return ResultsetInterface|Resultset|NavModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = NavModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|NavModel[]
@@ -68,19 +42,37 @@ class Nav extends Repository
$query->orderBy('position DESC,priority ASC');
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $id
+ * @return NavModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return NavModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param array|string $columns
+ * @return ResultsetInterface|Resultset|NavModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return NavModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
}
public function countChildNavs($navId)
{
- $count = NavModel::count([
+ return NavModel::count([
'conditions' => 'parent_id = :parent_id: AND published = 1 AND deleted = 0',
'bind' => ['parent_id' => $navId],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Order.php b/app/Repos/Order.php
index 72202f6e..49fd663b 100644
--- a/app/Repos/Order.php
+++ b/app/Repos/Order.php
@@ -13,13 +13,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Order extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -81,9 +74,7 @@ class Order extends Repository
*/
public function findById($id)
{
- $result = OrderModel::findFirst($id);
-
- return $result;
+ return OrderModel::findFirst($id);
}
/**
@@ -92,12 +83,10 @@ class Order extends Repository
*/
public function findBySn($sn)
{
- $result = OrderModel::findFirst([
+ return OrderModel::findFirst([
'conditions' => 'sn = :sn:',
'bind' => ['sn' => $sn],
]);
-
- return $result;
}
/**
@@ -110,13 +99,11 @@ class Order extends Repository
{
$status = OrderModel::STATUS_FINISHED;
- $result = OrderModel::findFirst([
+ return OrderModel::findFirst([
'conditions' => 'user_id = ?1 AND item_id = ?2 AND item_type = ?3 AND status = ?4',
'bind' => [1 => $userId, 2 => $itemId, 3 => $itemType, 4 => $status],
'order' => 'id DESC',
]);
-
- return $result;
}
/**
@@ -129,13 +116,11 @@ class Order extends Repository
{
$status = OrderModel::STATUS_PENDING;
- $result = OrderModel::findFirst([
+ return OrderModel::findFirst([
'conditions' => 'user_id = ?1 AND item_id = ?2 AND item_type = ?3 AND status= ?4',
'bind' => [1 => $userId, 2 => $itemId, 3 => $itemType, 4 => $status],
'order' => 'id DESC',
]);
-
- return $result;
}
/**
@@ -145,12 +130,10 @@ class Order extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = OrderModel::query()
+ return OrderModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -159,12 +142,10 @@ class Order extends Repository
*/
public function findTrades($orderId)
{
- $result = TradeModel::query()
+ return TradeModel::query()
->where('order_id = :order_id:', ['order_id' => $orderId])
->andWhere('deleted = 0')
->execute();
-
- return $result;
}
/**
@@ -173,24 +154,10 @@ class Order extends Repository
*/
public function findRefunds($orderId)
{
- $result = RefundModel::query()
+ return RefundModel::query()
->where('order_id = :order_id:', ['order_id' => $orderId])
->andWhere('deleted = 0')
->execute();
-
- return $result;
- }
-
- public function countUserDailyOrders($userId)
- {
- $createdAt = strtotime(date('Y-m-d'));
-
- $count = OrderModel::count([
- 'conditions' => 'user_id = :user_id: AND created_at > :created_at:',
- 'bind' => ['user_id' => $userId, 'created_at' => $createdAt],
- ]);
-
- return $count;
}
}
diff --git a/app/Repos/Package.php b/app/Repos/Package.php
index 28274e3a..52bf3a44 100644
--- a/app/Repos/Package.php
+++ b/app/Repos/Package.php
@@ -13,13 +13,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Package extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -63,9 +56,7 @@ class Package extends Repository
*/
public function findById($id)
{
- $result = PackageModel::findFirst($id);
-
- return $result;
+ return PackageModel::findFirst($id);
}
/**
@@ -75,12 +66,10 @@ class Package extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = PackageModel::query()
+ return PackageModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -89,7 +78,7 @@ class Package extends Repository
*/
public function findCourses($packageId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('c.*')
->addFrom(CourseModel::class, 'c')
->join(CoursePackageModel::class, 'c.id = cp.course_id', 'cp')
@@ -97,18 +86,14 @@ class Package extends Repository
->andWhere('c.deleted = 0')
->getQuery()
->execute();
-
- return $result;
}
public function countCourses($packageId)
{
- $count = CoursePackageModel::count([
+ return CoursePackageModel::count([
'conditions' => 'package_id = :package_id:',
'bind' => ['package_id' => $packageId],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Page.php b/app/Repos/Page.php
index b4367e84..a2f81017 100644
--- a/app/Repos/Page.php
+++ b/app/Repos/Page.php
@@ -11,13 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Page extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -57,9 +50,7 @@ class Page extends Repository
*/
public function findById($id)
{
- $result = PageModel::findFirst($id);
-
- return $result;
+ return PageModel::findFirst($id);
}
/**
@@ -69,12 +60,10 @@ class Page extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = PageModel::query()
+ return PageModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/RefreshToken.php b/app/Repos/RefreshToken.php
new file mode 100644
index 00000000..47d3fb9f
--- /dev/null
+++ b/app/Repos/RefreshToken.php
@@ -0,0 +1,42 @@
+where('user_id = :user_id:', ['user_id' => $userId])
+ ->andWhere('deleted = 0')
+ ->execute();
+ }
+
+ public function countByUserId($userId)
+ {
+ return RefreshTokenModel::count([
+ 'conditions' => 'user_id = :user_id: AND deleted = 0',
+ 'bind' => ['user_id' => $userId],
+ ]);
+ }
+
+}
diff --git a/app/Repos/Refund.php b/app/Repos/Refund.php
index f25965f2..85ec6495 100644
--- a/app/Repos/Refund.php
+++ b/app/Repos/Refund.php
@@ -11,13 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Refund extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -67,9 +60,7 @@ class Refund extends Repository
*/
public function findById($id)
{
- $result = RefundModel::findFirst($id);
-
- return $result;
+ return RefundModel::findFirst($id);
}
/**
@@ -78,12 +69,10 @@ class Refund extends Repository
*/
public function findBySn($sn)
{
- $result = RefundModel::findFirst([
+ return RefundModel::findFirst([
'conditions' => 'sn = :sn:',
'bind' => ['sn' => $sn],
]);
-
- return $result;
}
/**
@@ -93,12 +82,10 @@ class Refund extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = RefundModel::query()
+ return RefundModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/Review.php b/app/Repos/Review.php
index 5f517566..0b9aaa59 100644
--- a/app/Repos/Review.php
+++ b/app/Repos/Review.php
@@ -12,13 +12,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Review extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -84,9 +77,7 @@ class Review extends Repository
*/
public function findById($id)
{
- $result = ReviewModel::findFirst($id);
-
- return $result;
+ return ReviewModel::findFirst($id);
}
/**
@@ -96,12 +87,10 @@ class Review extends Repository
*/
public function findReview($courseId, $userId)
{
- $result = ReviewModel::findFirst([
+ return ReviewModel::findFirst([
'conditions' => 'course_id = :course_id: AND user_id = :user_id:',
'bind' => ['course_id' => $courseId, 'user_id' => $userId],
]);
-
- return $result;
}
/**
@@ -111,36 +100,30 @@ class Review extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = ReviewModel::query()
+ return ReviewModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
public function countAgrees($reviewId)
{
$type = ReviewVoteModel::TYPE_AGREE;
- $count = ReviewVoteModel::count([
+ return ReviewVoteModel::count([
'conditions' => 'review_id = :review_id: AND type = :type: AND deleted = 0',
'bind' => ['review_id' => $reviewId, 'type' => $type],
]);
-
- return $count;
}
public function countOpposes($reviewId)
{
$type = ReviewVoteModel::TYPE_OPPOSE;
- $count = ReviewVoteModel::count([
+ return ReviewVoteModel::count([
'conditions' => 'review_id = :review_id: AND type = :type: AND deleted = 0',
'bind' => ['review_id' => $reviewId, 'type' => $type],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Role.php b/app/Repos/Role.php
index 20274883..c01d1c9b 100644
--- a/app/Repos/Role.php
+++ b/app/Repos/Role.php
@@ -11,32 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Role extends Repository
{
- /**
- * @param int $id
- * @return RoleModel|Model|bool
- */
- public function findById($id)
- {
- $result = RoleModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param array|string $columns
- * @return ResultsetInterface|Resultset|RoleModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = RoleModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|RoleModel[]
@@ -51,19 +25,37 @@ class Role extends Repository
$query->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]);
}
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $id
+ * @return RoleModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return RoleModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param array|string $columns
+ * @return ResultsetInterface|Resultset|RoleModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return RoleModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
}
public function countUsers($roleId)
{
- $count = UserModel::count([
+ return UserModel::count([
'conditions' => 'admin_role = :role_id:',
'bind' => ['role_id' => $roleId],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Slide.php b/app/Repos/Slide.php
index ffec9d24..4c9e568b 100644
--- a/app/Repos/Slide.php
+++ b/app/Repos/Slide.php
@@ -11,13 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Slide extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'priority', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -61,9 +54,7 @@ class Slide extends Repository
*/
public function findById($id)
{
- $result = SlideModel::findFirst($id);
-
- return $result;
+ return SlideModel::findFirst($id);
}
/**
@@ -73,12 +64,10 @@ class Slide extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = SlideModel::query()
+ return SlideModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -87,14 +76,12 @@ class Slide extends Repository
*/
public function findTopSlides($limit = 5)
{
- $result = SlideModel::query()
+ return SlideModel::query()
->andWhere('published = :published:', ['published' => 1])
->andWhere('deleted = :deleted:', ['deleted' => 0])
->orderBy('priority ASC')
->limit($limit)
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/Topic.php b/app/Repos/Topic.php
index 56b38600..6081b976 100644
--- a/app/Repos/Topic.php
+++ b/app/Repos/Topic.php
@@ -13,13 +13,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Topic extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -63,9 +56,7 @@ class Topic extends Repository
*/
public function findById($id)
{
- $result = TopicModel::findFirst($id);
-
- return $result;
+ return TopicModel::findFirst($id);
}
/**
@@ -75,12 +66,10 @@ class Topic extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = TopicModel::query()
+ return TopicModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -89,25 +78,21 @@ class Topic extends Repository
*/
public function findCourses($topicId)
{
- $result = $this->modelsManager->createBuilder()
+ return $this->modelsManager->createBuilder()
->columns('c.*')
->addFrom(CourseModel::class, 'c')
->join(CourseTopicModel::class, 'c.id = ct.course_id', 'ct')
->where('ct.topic_id = :topic_id:', ['topic_id' => $topicId])
->andWhere('c.deleted = 0')
->getQuery()->execute();
-
- return $result;
}
public function countCourses($topicId)
{
- $count = CourseTopicModel::count([
+ return CourseTopicModel::count([
'conditions' => 'topic_id = :topic_id:',
'bind' => ['topic_id' => $topicId],
]);
-
- return $count;
}
}
diff --git a/app/Repos/Trade.php b/app/Repos/Trade.php
index 310d824a..86babebf 100644
--- a/app/Repos/Trade.php
+++ b/app/Repos/Trade.php
@@ -12,13 +12,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Trade extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -74,9 +67,7 @@ class Trade extends Repository
*/
public function findById($id)
{
- $result = TradeModel::findFirst($id);
-
- return $result;
+ return TradeModel::findFirst($id);
}
/**
@@ -85,12 +76,10 @@ class Trade extends Repository
*/
public function findBySn($sn)
{
- $result = TradeModel::findFirst([
+ return TradeModel::findFirst([
'conditions' => 'sn = :sn:',
'bind' => ['sn' => $sn],
]);
-
- return $result;
}
/**
@@ -100,12 +89,10 @@ class Trade extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = TradeModel::query()
+ return TradeModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -114,11 +101,9 @@ class Trade extends Repository
*/
public function findRefunds($tradeId)
{
- $result = RefundModel::query()
+ return RefundModel::query()
->where('trade_id = :trade_id:', ['trade_id' => $tradeId])
->execute();
-
- return $result;
}
/**
@@ -127,13 +112,11 @@ class Trade extends Repository
*/
public function findLastRefund($tradeId)
{
- $result = RefundModel::findFirst([
+ return RefundModel::findFirst([
'conditions' => 'trade_id = :trade_id:',
'bind' => ['trade_id' => $tradeId],
'order' => 'id DESC',
]);
-
- return $result;
}
}
diff --git a/app/Repos/User.php b/app/Repos/User.php
index 8a404480..0b80136c 100644
--- a/app/Repos/User.php
+++ b/app/Repos/User.php
@@ -11,13 +11,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class User extends Repository
{
- /**
- * @param array $where
- * @param string $sort
- * @param int $page
- * @param int $limit
- * @return \stdClass
- */
public function paginate($where = [], $sort = 'latest', $page = 1, $limit = 15)
{
$builder = $this->modelsManager->createBuilder();
@@ -77,9 +70,7 @@ class User extends Repository
*/
public function findById($id)
{
- $result = UserModel::findFirst($id);
-
- return $result;
+ return UserModel::findFirst($id);
}
/**
@@ -88,12 +79,10 @@ class User extends Repository
*/
public function findByName($name)
{
- $result = UserModel::findFirst([
+ return UserModel::findFirst([
'conditions' => 'name = :name:',
'bind' => ['name' => $name],
]);
-
- return $result;
}
/**
@@ -103,12 +92,10 @@ class User extends Repository
*/
public function findByIds($ids, $columns = '*')
{
- $result = UserModel::query()
+ return UserModel::query()
->columns($columns)
->inWhere('id', $ids)
->execute();
-
- return $result;
}
/**
@@ -118,12 +105,10 @@ class User extends Repository
{
$eduRole = UserModel::EDU_ROLE_TEACHER;
- $result = UserModel::query()
+ return UserModel::query()
->where('edu_role = :edu_role:', ['edu_role' => $eduRole])
->andWhere('deleted = 0')
->execute();
-
- return $result;
}
}
diff --git a/app/Repos/Vip.php b/app/Repos/Vip.php
index 6339a6bf..35c2de15 100644
--- a/app/Repos/Vip.php
+++ b/app/Repos/Vip.php
@@ -10,32 +10,6 @@ use Phalcon\Mvc\Model\ResultsetInterface;
class Vip extends Repository
{
- /**
- * @param int $id
- * @return VipModel|Model|bool
- */
- public function findById($id)
- {
- $result = VipModel::findFirst($id);
-
- return $result;
- }
-
- /**
- * @param array $ids
- * @param array|string $columns
- * @return ResultsetInterface|Resultset|VipModel[]
- */
- public function findByIds($ids, $columns = '*')
- {
- $result = VipModel::query()
- ->columns($columns)
- ->inWhere('id', $ids)
- ->execute();
-
- return $result;
- }
-
/**
* @param array $where
* @return ResultsetInterface|Resultset|VipModel[]
@@ -50,9 +24,29 @@ class Vip extends Repository
$query->andWhere('deleted = :deleted:', ['deleted' => $where['deleted']]);
}
- $result = $query->execute();
+ return $query->execute();
+ }
- return $result;
+ /**
+ * @param int $id
+ * @return VipModel|Model|bool
+ */
+ public function findById($id)
+ {
+ return VipModel::findFirst($id);
+ }
+
+ /**
+ * @param array $ids
+ * @param array|string $columns
+ * @return ResultsetInterface|Resultset|VipModel[]
+ */
+ public function findByIds($ids, $columns = '*')
+ {
+ return VipModel::query()
+ ->columns($columns)
+ ->inWhere('id', $ids)
+ ->execute();
}
}
diff --git a/app/Searchers/CourseDocument.php b/app/Searchers/CourseDocument.php
index ea58837c..dc2dd57c 100644
--- a/app/Searchers/CourseDocument.php
+++ b/app/Searchers/CourseDocument.php
@@ -37,7 +37,7 @@ class CourseDocument extends Component
$course->attrs = kg_json_encode($course->attrs);
}
- $data = [
+ return [
'id' => $course->id,
'title' => $course->title,
'cover' => $course->cover,
@@ -55,8 +55,6 @@ class CourseDocument extends Component
'lesson_count' => $course->lesson_count,
'created_at' => $course->created_at,
];
-
- return $data;
}
}
diff --git a/app/Searchers/CourseSearch.php b/app/Searchers/CourseSearch.php
index 8a40fe88..b5520655 100644
--- a/app/Searchers/CourseSearch.php
+++ b/app/Searchers/CourseSearch.php
@@ -61,12 +61,10 @@ class CourseSearch extends Component
$items[] = $item;
}
- $result = [
+ return [
'total' => $total,
'items' => $items,
];
-
- return $result;
}
/**
@@ -83,9 +81,7 @@ class CourseSearch extends Component
$search->setQuery($query);
- $result = $search->getRelatedQuery($query, $limit);
-
- return $result;
+ return $search->getRelatedQuery($query, $limit);
}
}
diff --git a/app/Services/AuthUser/Admin.php b/app/Services/AuthUser/Admin.php
index 49cd2abd..1dc4dab0 100644
--- a/app/Services/AuthUser/Admin.php
+++ b/app/Services/AuthUser/Admin.php
@@ -65,7 +65,7 @@ class Admin extends AuthUser
*/
public function getAuthKey()
{
- return 'admin_info';
+ return 'admin_user_info';
}
/**
diff --git a/app/Services/AuthUser/Api.php b/app/Services/AuthUser/Api.php
index 65d904b0..b4bc2183 100644
--- a/app/Services/AuthUser/Api.php
+++ b/app/Services/AuthUser/Api.php
@@ -52,9 +52,7 @@ class Api extends AuthUser
public function getAuthToken()
{
- $authToken = $this->request->getHeader('Authorization');
-
- return $authToken;
+ return $this->request->getHeader('Authorization');
}
public function getCacheKey($token)
@@ -64,9 +62,7 @@ class Api extends AuthUser
public function getRandToken($userId)
{
- $token = md5($userId . time() . rand(1000, 9999));
-
- return $token;
+ return md5($userId . time() . rand(1000, 9999));
}
/**
@@ -74,9 +70,7 @@ class Api extends AuthUser
*/
public function getCache()
{
- $cache = $this->getDI()->get('cache');
-
- return $cache;
+ return $this->getDI()->get('cache');
}
}
diff --git a/app/Services/AuthUser/Html5.php b/app/Services/AuthUser/Html5.php
new file mode 100644
index 00000000..bc1a25ec
--- /dev/null
+++ b/app/Services/AuthUser/Html5.php
@@ -0,0 +1,63 @@
+getAuthKey();
+
+ $authUser = new \stdClass();
+
+ $authUser->id = $user->id;
+ $authUser->name = $user->name;
+ $authUser->avatar = $user->avatar;
+ $authUser->admin_role = $user->admin_role;
+ $authUser->edu_role = $user->edu_role;
+
+ $this->session->set($authKey, $authUser);
+ }
+
+ /**
+ * 清除会话
+ */
+ public function clearAuthInfo()
+ {
+ $authKey = $this->getAuthKey();
+
+ $this->session->remove($authKey);
+ }
+
+ /**
+ * 读取会话
+ *
+ * @return mixed
+ */
+ public function getAuthInfo()
+ {
+ $authKey = $this->getAuthKey();
+
+ return $this->session->get($authKey);
+ }
+
+ /**
+ * 获取会话键值
+ *
+ * @return string
+ */
+ public function getAuthKey()
+ {
+ return 'html5_user_info';
+ }
+
+}
diff --git a/app/Services/AuthUser/Home.php b/app/Services/AuthUser/Web.php
similarity index 94%
rename from app/Services/AuthUser/Home.php
rename to app/Services/AuthUser/Web.php
index 721b4856..c17311bf 100644
--- a/app/Services/AuthUser/Home.php
+++ b/app/Services/AuthUser/Web.php
@@ -5,7 +5,7 @@ namespace App\Services\AuthUser;
use App\Models\User as UserModel;
use App\Services\AuthUser;
-class Home extends AuthUser
+class Web extends AuthUser
{
/**
@@ -57,7 +57,7 @@ class Home extends AuthUser
*/
public function getAuthKey()
{
- return 'user_info';
+ return 'web_user_info';
}
}
diff --git a/app/Services/Captcha.php b/app/Services/Captcha.php
index 4b051def..489be400 100644
--- a/app/Services/Captcha.php
+++ b/app/Services/Captcha.php
@@ -120,9 +120,7 @@ class Captcha extends Service
$clientProfile->setHttpProfile($httpProfile);
- $client = new CaptchaClient($credential, $region, $clientProfile);
-
- return $client;
+ return new CaptchaClient($credential, $region, $clientProfile);
}
}
diff --git a/app/Services/CourseStats.php b/app/Services/CourseStats.php
index 76f4b154..1877235e 100644
--- a/app/Services/CourseStats.php
+++ b/app/Services/CourseStats.php
@@ -2,9 +2,7 @@
namespace App\Services;
-use App\Models\Chapter as ChapterModel;
use App\Repos\Course as CourseRepo;
-use Phalcon\Mvc\Model\Resultset;
class CourseStats extends Service
{
@@ -41,9 +39,6 @@ class CourseStats extends Service
$course = $courseRepo->findById($courseId);
- /**
- * @var Resultset|ChapterModel[] $lessons
- */
$lessons = $courseRepo->findLessons($courseId);
if ($lessons->count() == 0) {
@@ -87,9 +82,6 @@ class CourseStats extends Service
$course = $courseRepo->findById($courseId);
- /**
- * @var Resultset|ChapterModel[] $lessons
- */
$lessons = $courseRepo->findLessons($course->id);
if ($lessons->count() == 0) {
@@ -129,9 +121,6 @@ class CourseStats extends Service
$course = $courseRepo->findById($courseId);
- /**
- * @var Resultset|ChapterModel[] $lessons
- */
$lessons = $courseRepo->findChapters($course->id);
if ($lessons->count() == 0) {
diff --git a/app/Services/Live.php b/app/Services/Live.php
index 9015fc29..911783e9 100644
--- a/app/Services/Live.php
+++ b/app/Services/Live.php
@@ -106,12 +106,10 @@ class Live extends Service
$txSecret = md5($authKey . $streamName . $txTime);
- $authParams = http_build_query([
+ return http_build_query([
'txSecret' => $txSecret,
'txTime' => $txTime
]);
-
- return $authParams;
}
}
diff --git a/app/Services/Mailer.php b/app/Services/Mailer.php
index 48d90135..14ff760a 100644
--- a/app/Services/Mailer.php
+++ b/app/Services/Mailer.php
@@ -51,9 +51,7 @@ abstract class Mailer extends Service
$config['password'] = $opt['smtp_password'];
}
- $manager = new MailerManager($config);
-
- return $manager;
+ return new MailerManager($config);
}
}
diff --git a/app/Services/Mailer/Test.php b/app/Services/Mailer/Test.php
index b43331ee..e18772ed 100644
--- a/app/Services/Mailer/Test.php
+++ b/app/Services/Mailer/Test.php
@@ -7,6 +7,10 @@ use App\Services\Mailer;
class Test extends Mailer
{
+ /**
+ * @param string $email
+ * @return bool
+ */
public function handle($email)
{
try {
diff --git a/app/Services/Mailer/Verify.php b/app/Services/Mailer/Verify.php
index f496dae3..1d04c723 100644
--- a/app/Services/Mailer/Verify.php
+++ b/app/Services/Mailer/Verify.php
@@ -3,22 +3,26 @@
namespace App\Services\Mailer;
use App\Services\Mailer;
-use App\Services\Verification;
+use App\Services\VerifyCode;
class Verify extends Mailer
{
+ /**
+ * @param string $email
+ * @return bool
+ */
public function handle($email)
{
try {
$message = $this->manager->createMessage();
- $verification = new Verification();
+ $verifyCode = new VerifyCode();
$minutes = 5;
- $code = $verification->getSmsCode($email, 60 * $minutes);
+ $code = $verifyCode->getSmsCode($email, 60 * $minutes);
$subject = '邮件验证码';
@@ -46,9 +50,7 @@ class Verify extends Mailer
protected function formatContent($code, $minutes)
{
- $content = sprintf('验证码:%s,%s 分钟内有效,如非本人操作请忽略。', $code, $minutes);
-
- return $content;
+ return sprintf('验证码:%s,%s 分钟内有效,如非本人操作请忽略。', $code, $minutes);
}
}
diff --git a/app/Services/Payment/Alipay.php b/app/Services/Payment/Alipay.php
index fb94aafc..0a35fa86 100644
--- a/app/Services/Payment/Alipay.php
+++ b/app/Services/Payment/Alipay.php
@@ -261,9 +261,7 @@ class Alipay extends Payment
$payConfig['mode'] = 'dev';
}
- $gateway = Pay::alipay($payConfig);
-
- return $gateway;
+ return Pay::alipay($payConfig);
}
}
diff --git a/app/Services/Payment/Wxpay.php b/app/Services/Payment/Wxpay.php
index d52b86ff..30a5e33f 100644
--- a/app/Services/Payment/Wxpay.php
+++ b/app/Services/Payment/Wxpay.php
@@ -176,9 +176,7 @@ class Wxpay extends Payment
*/
public function cancel($outTradeNo)
{
- $result = $this->close($outTradeNo);
-
- return $result;
+ return $this->close($outTradeNo);
}
/**
@@ -245,9 +243,7 @@ class Wxpay extends Payment
$payConfig['mode'] = 'dev';
}
- $gateway = Pay::wechat($payConfig);
-
- return $gateway;
+ return Pay::wechat($payConfig);
}
}
diff --git a/app/Services/Refund.php b/app/Services/Refund.php
index c5c6331a..54889bae 100644
--- a/app/Services/Refund.php
+++ b/app/Services/Refund.php
@@ -129,9 +129,7 @@ class Refund extends Service
$consumedCount = count($consumedLessonIds);
$refundCount = $totalCount - $consumedCount;
- $percent = round($refundCount / $totalCount, 4);
-
- return $percent;
+ return round($refundCount / $totalCount, 4);
}
}
diff --git a/app/Services/Service.php b/app/Services/Service.php
index e012149b..6b6305cb 100644
--- a/app/Services/Service.php
+++ b/app/Services/Service.php
@@ -35,9 +35,7 @@ class Service extends Component
{
$cache = new SectionConfigCache();
- $result = $cache->get($section);
-
- return $result;
+ return $cache->get($section);
}
}
diff --git a/app/Services/Smser.php b/app/Services/Smser.php
index 4b6515c0..e94a9d8a 100644
--- a/app/Services/Smser.php
+++ b/app/Services/Smser.php
@@ -64,18 +64,14 @@ Abstract class Smser extends Service
protected function createSingleSender()
{
- $sender = new SmsSingleSender($this->config['app_id'], $this->config['app_key']);
-
- return $sender;
+ return new SmsSingleSender($this->config['app_id'], $this->config['app_key']);
}
protected function getTemplateId($code)
{
$template = json_decode($this->config['template'], true);
- $templateId = $template[$code]['id'] ?? null;
-
- return $templateId;
+ return $template[$code]['id'] ?? null;
}
protected function getSignature()
diff --git a/app/Services/Smser/Live.php b/app/Services/Smser/Live.php
index 2e558371..bae920f6 100644
--- a/app/Services/Smser/Live.php
+++ b/app/Services/Smser/Live.php
@@ -16,7 +16,7 @@ class Live extends Smser
* @param int $chapterId
* @param int $userId
* @param int $startTime
- * @return bool|null
+ * @return bool
*/
public function handle($chapterId, $userId, $startTime)
{
@@ -25,7 +25,7 @@ class Live extends Smser
$account = $accountRepo->findById($userId);
if (!$account->phone) {
- return null;
+ return false;
}
$chapterRepo = new ChapterRepo();
diff --git a/app/Services/Smser/Order.php b/app/Services/Smser/Order.php
index d7f4577a..ec722cc4 100644
--- a/app/Services/Smser/Order.php
+++ b/app/Services/Smser/Order.php
@@ -11,6 +11,10 @@ class Order extends Smser
protected $templateCode = 'order';
+ /**
+ * @param OrderModel $order
+ * @return bool
+ */
public function handle(OrderModel $order)
{
$accountRepo = new AccountRepo();
@@ -18,7 +22,7 @@ class Order extends Smser
$account = $accountRepo->findById($order->user_id);
if (!$account->phone) {
- return null;
+ return false;
}
$templateId = $this->getTemplateId($this->templateCode);
diff --git a/app/Services/Smser/Refund.php b/app/Services/Smser/Refund.php
index 175d3315..99e9394a 100644
--- a/app/Services/Smser/Refund.php
+++ b/app/Services/Smser/Refund.php
@@ -11,6 +11,10 @@ class Refund extends Smser
protected $templateCode = 'refund';
+ /**
+ * @param RefundModel $refund
+ * @return bool
+ */
public function handle(RefundModel $refund)
{
$accountRepo = new AccountRepo();
@@ -18,7 +22,7 @@ class Refund extends Smser
$account = $accountRepo->findById($refund->user_id);
if (!$account->phone) {
- return null;
+ return false;
}
$templateId = $this->getTemplateId($this->templateCode);
diff --git a/app/Services/Smser/Test.php b/app/Services/Smser/Test.php
index b331e60e..8f5e05da 100644
--- a/app/Services/Smser/Test.php
+++ b/app/Services/Smser/Test.php
@@ -7,13 +7,15 @@ use App\Services\Smser;
class Test extends Smser
{
- public function handle($phoneNumber)
+ /**
+ * @param string $phone
+ * @return bool
+ */
+ public function handle($phone)
{
$identity = new Verify();
- $result = $identity->handle($phoneNumber);
-
- return $result;
+ return $identity->handle($phone);
}
}
diff --git a/app/Services/Smser/Verify.php b/app/Services/Smser/Verify.php
index e40a96bf..dc4c5f01 100644
--- a/app/Services/Smser/Verify.php
+++ b/app/Services/Smser/Verify.php
@@ -3,16 +3,20 @@
namespace App\Services\Smser;
use App\Services\Smser;
-use App\Services\Verification;
+use App\Services\VerifyCode;
class Verify extends Smser
{
protected $templateCode = 'verify';
+ /**
+ * @param string $phone
+ * @return bool
+ */
public function handle($phone)
{
- $verifyCode = new Verification();
+ $verifyCode = new VerifyCode();
$minutes = 5;
diff --git a/app/Services/Storage.php b/app/Services/Storage.php
index c0281980..f257e889 100644
--- a/app/Services/Storage.php
+++ b/app/Services/Storage.php
@@ -43,9 +43,7 @@ class Storage extends Service
$key = 'hello_world.txt';
$value = 'hello world';
- $result = $this->putString($key, $value);
-
- return $result;
+ return $this->putString($key, $value);
}
/**
@@ -55,9 +53,7 @@ class Storage extends Service
*/
public function uploadCoverImage()
{
- $result = $this->uploadImage('/img/cover/');
-
- return $result;
+ return $this->uploadImage('/img/cover/');
}
/**
@@ -77,12 +73,10 @@ class Storage extends Service
$contentImage->create();
- $result = $this->url->get([
- 'for' => 'home.content.img',
+ return $this->url->get([
+ 'for' => 'web.content.img',
'id' => $contentImage->id,
]);
-
- return $result;
}
/**
@@ -92,9 +86,7 @@ class Storage extends Service
*/
public function uploadAvatarImage()
{
- $result = $this->uploadImage('/img/avatar/');
-
- return $result;
+ return $this->uploadImage('/img/avatar/');
}
/**
@@ -121,9 +113,7 @@ class Storage extends Service
}
}
- $result = !empty($paths[0]) ? $paths[0] : false;
-
- return $result;
+ return !empty($paths[0]) ? $paths[0] : false;
}
/**
@@ -196,9 +186,7 @@ class Storage extends Service
*/
public function getBucketFileUrl($key)
{
- $result = $this->getBucketBaseUrl() . $key;
-
- return $result;
+ return $this->getBucketBaseUrl() . $key;
}
/**
@@ -210,9 +198,7 @@ class Storage extends Service
*/
public function getCiImageUrl($key, $width = 0, $height = 0)
{
- $result = $this->getCiBaseUrl() . $key;
-
- return $result;
+ return $this->getCiBaseUrl() . $key;
}
/**
@@ -225,9 +211,7 @@ class Storage extends Service
$protocol = $this->config['bucket_protocol'];
$domain = $this->config['bucket_domain'];
- $result = $protocol . '://' . $domain;
-
- return $result;
+ return $protocol . '://' . $domain;
}
/**
@@ -240,9 +224,7 @@ class Storage extends Service
$protocol = $this->config['ci_protocol'];
$domain = $this->config['ci_domain'];
- $result = $protocol . '://' . $domain;
-
- return $result;
+ return $protocol . '://' . $domain;
}
/**
@@ -256,9 +238,7 @@ class Storage extends Service
{
$randName = date('YmdHis') . rand(1000, 9999);
- $result = $prefix . $randName . '.' . $extension;
-
- return $result;
+ return $prefix . $randName . '.' . $extension;
}
/**
@@ -269,9 +249,9 @@ class Storage extends Service
*/
protected function getFileExtension($fileName)
{
- $result = pathinfo($fileName, PATHINFO_EXTENSION);
+ $extension = pathinfo($fileName, PATHINFO_EXTENSION);
- return strtolower($result);
+ return strtolower($extension);
}
/**
@@ -283,15 +263,13 @@ class Storage extends Service
{
$secret = $this->getSectionConfig('secret');
- $client = new CosClient([
+ return new CosClient([
'region' => $this->config['bucket_region'],
'schema' => $this->config['bucket_protocol'],
'credentials' => [
'secretId' => $secret['secret_id'],
'secretKey' => $secret['secret_key'],
]]);
-
- return $client;
}
}
diff --git a/app/Services/Verification.php b/app/Services/VerifyCode.php
similarity index 93%
rename from app/Services/Verification.php
rename to app/Services/VerifyCode.php
index 698a18a2..7f2acf05 100644
--- a/app/Services/Verification.php
+++ b/app/Services/VerifyCode.php
@@ -2,16 +2,16 @@
namespace App\Services;
+use App\Library\Cache\Backend\Redis as RedisCache;
use App\Services\Mailer\Verify as VerifyMailer;
use App\Services\Smser\Verify as VerifySmser;
-use Phalcon\Cache\Backend\Redis;
use Phalcon\Text;
-class Verification extends Service
+class VerifyCode extends Service
{
/**
- * @var Redis
+ * @var RedisCache
*/
protected $cache;
diff --git a/app/Services/Vod.php b/app/Services/Vod.php
index db545ee7..34bfdc4e 100644
--- a/app/Services/Vod.php
+++ b/app/Services/Vod.php
@@ -99,10 +99,10 @@ class Vod extends Service
];
$original = http_build_query($params);
- $hash = hash_hmac('SHA1', $original, $secretKey, true);
- $signature = base64_encode($hash . $original);
- return $signature;
+ $hash = hash_hmac('SHA1', $original, $secretKey, true);
+
+ return base64_encode($hash . $original);
}
/**
@@ -191,11 +191,10 @@ class Vod extends Service
}
$query['us'] = $random;
+
$query['sign'] = md5($sign);
- $result = $url . '?' . http_build_query($query);
-
- return $result;
+ return $url . '?' . http_build_query($query);
}
/**
@@ -534,15 +533,13 @@ class Vod extends Service
$metaData = $response['MediaInfoSet'][0]['MetaData'];
- $result = [
+ return [
'bit_rate' => $metaData['Bitrate'],
'size' => $metaData['Size'],
'width' => $metaData['Width'],
'height' => $metaData['Height'],
'duration' => $metaData['Duration'],
];
-
- return $result;
}
/**
@@ -559,15 +556,13 @@ class Vod extends Service
$metaData = $response['MediaInfoSet'][0]['MetaData'];
- $result = [
+ return [
'bit_rate' => $metaData['Bitrate'],
'size' => $metaData['Size'],
'width' => $metaData['Width'],
'height' => $metaData['Height'],
'duration' => $metaData['Duration'],
];
-
- return $result;
}
/**
@@ -607,9 +602,7 @@ class Vod extends Service
$format = $this->config['video_format'];
- $result = $format == 'hls' ? $hls : $mp4;
-
- return $result;
+ return $format == 'hls' ? $hls : $mp4;
}
/**
@@ -628,9 +621,7 @@ class Vod extends Service
1010 => ['bit_rate' => 128, 'sample_rate' => 44100],
];
- $result = $this->config['audio_format'] == 'm4a' ? $m4a : $mp3;
-
- return $result;
+ return $this->config['audio_format'] == 'm4a' ? $m4a : $mp3;
}
/**
@@ -657,9 +648,7 @@ class Vod extends Service
$clientProfile->setHttpProfile($httpProfile);
- $client = new VodClient($credential, $region, $clientProfile);
-
- return $client;
+ return new VodClient($credential, $region, $clientProfile);
}
}
diff --git a/app/Traits/Auth.php b/app/Traits/Auth.php
index cea0842e..58b23fca 100644
--- a/app/Traits/Auth.php
+++ b/app/Traits/Auth.php
@@ -6,6 +6,7 @@ use App\Models\User as UserModel;
use App\Repos\User as UserRepo;
use App\Services\AuthUser as AuthUserService;
use App\Validators\Validator as AppValidator;
+use Phalcon\Di;
trait Auth
{
@@ -20,9 +21,7 @@ trait Auth
$userRepo = new UserRepo();
- $user = $userRepo->findById($authUser->id);
-
- return $user;
+ return $userRepo->findById($authUser->id);
}
public function getLoginUser()
@@ -35,9 +34,7 @@ trait Auth
$userRepo = new UserRepo();
- $user = $userRepo->findById($authUser->id);
-
- return $user;
+ return $userRepo->findById($authUser->id);
}
public function getGuestUser()
@@ -55,7 +52,7 @@ trait Auth
/**
* @var AuthUserService $auth
*/
- $auth = $this->getDI()->get('auth');
+ $auth = Di::getDefault()->get('auth');
return $auth->getAuthInfo();
}
diff --git a/app/Traits/Client.php b/app/Traits/Client.php
index 17fb5991..4bec3862 100644
--- a/app/Traits/Client.php
+++ b/app/Traits/Client.php
@@ -16,9 +16,7 @@ trait Client
*/
$request = Di::getDefault()->get('request');
- $clientIp = $request->getClientAddress();
-
- return $clientIp;
+ return $request->getClientAddress();
}
public function getClientType()
diff --git a/app/Traits/Response.php b/app/Traits/Response.php
index d85ac0c2..cd4fc8d3 100644
--- a/app/Traits/Response.php
+++ b/app/Traits/Response.php
@@ -61,9 +61,7 @@ trait Response
{
$errors = require config_path() . '/errors.php';
- $message = $errors[$code] ?? $code;
-
- return $message;
+ return $errors[$code] ?? $code;
}
}
\ No newline at end of file
diff --git a/app/Traits/Security.php b/app/Traits/Security.php
index babd8e1b..681d573b 100644
--- a/app/Traits/Security.php
+++ b/app/Traits/Security.php
@@ -23,9 +23,7 @@ trait Security
*/
$security = Di::getDefault()->get('security');
- $checkToken = $security->checkToken($tokenKey, $tokenValue);
-
- return $checkToken;
+ return $security->checkToken($tokenKey, $tokenValue);
}
public function checkHttpReferer()
@@ -37,9 +35,7 @@ trait Security
$httpHost = parse_url($request->getHttpReferer(), PHP_URL_HOST);
- $checkHost = $httpHost == $request->getHttpHost();
-
- return $checkHost;
+ return $httpHost == $request->getHttpHost();
}
public function isNotSafeRequest()
@@ -53,9 +49,7 @@ trait Security
$list = ['post', 'put', 'patch', 'delete'];
- $result = in_array(strtolower($method), $list);
-
- return $result;
+ return in_array(strtolower($method), $list);
}
}
\ No newline at end of file
diff --git a/app/Validators/Account.php b/app/Validators/Account.php
index 12888c7d..972980d6 100644
--- a/app/Validators/Account.php
+++ b/app/Validators/Account.php
@@ -89,6 +89,19 @@ class Account extends Validator
}
}
+ public function checkVerifyLogin($name, $code)
+ {
+ $security = new Security();
+
+ $security->checkVerifyCode($name, $code);
+
+ $account = $this->checkLoginAccount($name);
+
+ $userRepo = new UserRepo();
+
+ return $userRepo->findById($account->id);
+ }
+
public function checkUserLogin($name, $password)
{
$accountRepo = new AccountRepo();
@@ -113,9 +126,7 @@ class Account extends Validator
$userRepo = new UserRepo();
- $user = $userRepo->findById($account->id);
-
- return $user;
+ return $userRepo->findById($account->id);
}
public function checkAdminLogin($name, $password)
@@ -123,7 +134,7 @@ class Account extends Validator
$user = $this->checkUserLogin($name, $password);
if ($user->admin_role == 0) {
- throw new ForbiddenException('account.admin_not_authorized');
+ throw new ForbiddenException('sys.access_denied');
}
return $user;
diff --git a/app/Validators/ChapterRead.php b/app/Validators/ChapterRead.php
index 6fd58a45..d3a7b478 100644
--- a/app/Validators/ChapterRead.php
+++ b/app/Validators/ChapterRead.php
@@ -23,4 +23,5 @@ class ChapterRead extends Validator
return $value;
}
+
}
diff --git a/app/Validators/Comment.php b/app/Validators/Comment.php
index 6d0f9a60..4946fbb7 100644
--- a/app/Validators/Comment.php
+++ b/app/Validators/Comment.php
@@ -93,15 +93,4 @@ class Comment extends Validator
return $status;
}
- public function checkRateLimit($chapterId, $userId)
- {
- $chapterRepo = new ChapterRepo();
-
- $count = $chapterRepo->countUserComments($chapterId, $userId);
-
- if ($count >= 50) {
- throw new BadRequestException('comment.reach_rate_limit');
- }
- }
-
}
diff --git a/app/Validators/Consult.php b/app/Validators/Consult.php
index 9ac78920..48261844 100644
--- a/app/Validators/Consult.php
+++ b/app/Validators/Consult.php
@@ -78,15 +78,4 @@ class Consult extends Validator
return $status;
}
- public function checkRateLimit($courseId, $userId)
- {
- $courseRepo = new CourseRepo();
-
- $count = $courseRepo->countUserConsults($courseId, $userId);
-
- if ($count >= 10) {
- throw new BadRequestException('consult.reach_rate_limit');
- }
- }
-
}
diff --git a/app/Validators/Course.php b/app/Validators/Course.php
index af15ed05..d7b1eeb5 100644
--- a/app/Validators/Course.php
+++ b/app/Validators/Course.php
@@ -81,9 +81,7 @@ class Course extends Validator
throw new BadRequestException('course.invalid_cover');
}
- $result = parse_url($value, PHP_URL_PATH);
-
- return $result;
+ return parse_url($value, PHP_URL_PATH);
}
public function checkTitle($title)
@@ -105,16 +103,12 @@ class Course extends Validator
public function checkDetails($details)
{
- $value = $this->filter->sanitize($details, ['trim']);
-
- return $value;
+ return $this->filter->sanitize($details, ['trim']);
}
public function checkSummary($summary)
{
- $value = $this->filter->sanitize($summary, ['trim', 'string']);
-
- return $value;
+ return $this->filter->sanitize($summary, ['trim', 'string']);
}
public function checkKeywords($keywords)
diff --git a/app/Validators/Role.php b/app/Validators/Role.php
index 1a2aed03..111ad94d 100644
--- a/app/Validators/Role.php
+++ b/app/Validators/Role.php
@@ -42,6 +42,12 @@ class Role extends Validator
{
$value = $this->filter->sanitize($summary, ['trim', 'string']);
+ $length = kg_strlen($value);
+
+ if ($length > 255) {
+ throw new BadRequestException('role.summary_too_long');
+ }
+
return $value;
}
diff --git a/app/Validators/Security.php b/app/Validators/Security.php
index 13d70295..a030bb37 100644
--- a/app/Validators/Security.php
+++ b/app/Validators/Security.php
@@ -5,21 +5,21 @@ namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator;
use App\Services\Captcha as CaptchaService;
-use App\Services\Verification as VerificationService;
+use App\Services\VerifyCode as VerifyCodeService;
class Security extends Validator
{
public function checkVerifyCode($key, $code)
{
- $verification = new VerificationService();
+ $verifyCodeService = new VerifyCodeService();
$result = false;
if (CommonValidator::email($key)) {
- $result = $verification->checkMailCode($key, $code);
+ $result = $verifyCodeService->checkMailCode($key, $code);
} elseif (CommonValidator::phone($key)) {
- $result = $verification->checkSmsCode($key, $code);
+ $result = $verifyCodeService->checkSmsCode($key, $code);
}
if (!$result) {
@@ -29,9 +29,9 @@ class Security extends Validator
public function checkCaptchaCode($ticket, $rand)
{
- $captcha = new CaptchaService();
+ $captchaService = new CaptchaService();
- $result = $captcha->verify($ticket, $rand);
+ $result = $captchaService->verify($ticket, $rand);
if (!$result) {
throw new BadRequestException('security.invalid_captcha_code');
diff --git a/app/Validators/Slide.php b/app/Validators/Slide.php
index 2141266e..2d1ef007 100644
--- a/app/Validators/Slide.php
+++ b/app/Validators/Slide.php
@@ -63,9 +63,7 @@ class Slide extends Validator
throw new BadRequestException('slide.invalid_cover');
}
- $result = parse_url($value, PHP_URL_PATH);
-
- return $result;
+ return parse_url($value, PHP_URL_PATH);
}
public function checkTarget($target)
diff --git a/bootstrap/HttpErrorHandler.php b/bootstrap/HttpErrorHandler.php
index b1a548cf..7967232b 100644
--- a/bootstrap/HttpErrorHandler.php
+++ b/bootstrap/HttpErrorHandler.php
@@ -39,7 +39,7 @@ class HttpErrorHandler extends Component
if ($this->router->getModuleName() == 'api') {
$this->apiError($e);
} else if ($this->isAjax()) {
- $this->jsonError($e);
+ $this->ajaxError($e);
} else {
$this->pageError($e);
}
@@ -110,7 +110,7 @@ class HttpErrorHandler extends Component
$code = $this->response->getStatusCode();
- $for = "home.error.{$code}";
+ $for = "web.error.{$code}";
$this->response->redirect(['for' => $for])->send();
}
@@ -119,12 +119,10 @@ class HttpErrorHandler extends Component
{
$errors = require config_path() . '/errors.php';
- $content = [
+ return [
'code' => $code,
'msg' => $errors[$code] ?? $code,
];
-
- return $content;
}
protected function isAjax()
diff --git a/bootstrap/HttpKernel.php b/bootstrap/HttpKernel.php
index 752db759..e2772c80 100644
--- a/bootstrap/HttpKernel.php
+++ b/bootstrap/HttpKernel.php
@@ -101,8 +101,12 @@ class HttpKernel extends Kernel
'path' => app_path('Http/Admin/Module.php'),
],
'home' => [
- 'className' => 'App\Http\Home\Module',
- 'path' => app_path('Http/Home/Module.php'),
+ 'className' => 'App\Http\Web\Module',
+ 'path' => app_path('Http/Web/Module.php'),
+ ],
+ 'mobile' => [
+ 'className' => 'App\Http\Html5\Module',
+ 'path' => app_path('Http/Html5/Module.php'),
],
];
diff --git a/composer.json b/composer.json
index 1665f1b3..d9ca405e 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,8 @@
{
"require": {
- "ext-redis": "*",
+ "ext-phalcon": "~3.4",
+ "ext-redis": "~4.3",
+ "ext-pdo": "*",
"ext-json": "*",
"phalcon/incubator": "^3.4",
"guzzlehttp/guzzle": "^6.3",
diff --git a/config/errors.php b/config/errors.php
index 3a711668..6fbc0a6a 100644
--- a/config/errors.php
+++ b/config/errors.php
@@ -6,11 +6,9 @@ $error = [];
* 通用相关
*/
$error['sys.uri_not_found'] = '资源地址不存在';
-$error['sys.invalid_auth_token'] = '无效的auth_token';
$error['sys.invalid_referer'] = '无效的请求来源';
$error['sys.auth_user_failed'] = '用户认证失败';
$error['sys.access_denied'] = '访问被拒绝';
-$error['sys.session_expired'] = '会话已过期';
$error['sys.unknown_error'] = '未知错误';
/**
@@ -32,7 +30,6 @@ $error['account.invalid_password'] = '无效的密码(字母或数字6-16位
$error['account.email_taken'] = '邮箱被占用';
$error['account.phone_taken'] = '手机号被占用';
$error['account.origin_password_incorrect'] = '原密码不正确';
-$error['account.admin_not_authorized'] = '账号没有登录后台的授权';
/**
* 用户相关
@@ -268,6 +265,7 @@ $error['refund.invalid_review_status'] = '无效的审核状态';
$error['role.not_found'] = '角色不存在';
$error['role.name_too_short'] = '名称太短(少于2个字符)';
$error['role.name_too_long'] = '名称太长(超过30个字符)';
+$error['role.summary_too_long'] = '描述太长(超过255个字符)';
$error['role.routes_required'] = '角色权限不能为空';
/**
diff --git a/config/events.php b/config/events.php
index 44050cd8..a45ef269 100644
--- a/config/events.php
+++ b/config/events.php
@@ -6,7 +6,7 @@ use App\Listeners\Payment;
use App\Listeners\Profiler;
use App\Listeners\UserDailyCounter;
-$events = [
+return [
'db' => Profiler::class,
'payment' => Payment::class,
@@ -14,6 +14,4 @@ $events = [
'courseAdmin' => CourseAdmin::class,
'chapterAdmin' => ChapterAdmin::class,
-];
-
-return $events;
\ No newline at end of file
+];
\ No newline at end of file
|