mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-07-05 00:11:30 +08:00
增强缓存
This commit is contained in:
parent
576be9b61e
commit
6215802ee9
@ -25,11 +25,7 @@ class Chapter extends Cache
|
|||||||
|
|
||||||
$chapter = $chapterRepo->findById($id);
|
$chapter = $chapterRepo->findById($id);
|
||||||
|
|
||||||
if (!$chapter) {
|
return $chapter ?: null;
|
||||||
return new \stdClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $chapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use App\Repos\Chapter as ChapterRepo;
|
|||||||
class ChapterCounter extends Counter
|
class ChapterCounter extends Counter
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 7 * 86400;
|
protected $lifetime = 1 * 86400;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -25,11 +25,9 @@ class Course extends Cache
|
|||||||
|
|
||||||
$course = $courseRepo->findById($id);
|
$course = $courseRepo->findById($id);
|
||||||
|
|
||||||
$course->cover = kg_ci_img_url($course->cover);
|
if (!$course) return null;
|
||||||
|
|
||||||
if (!$course) {
|
$course->cover = kg_ci_img_url($course->cover);
|
||||||
return new \stdClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $course;
|
return $course;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use App\Repos\Course as CourseRepo;
|
|||||||
class CourseCounter extends Counter
|
class CourseCounter extends Counter
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 7 * 86400;
|
protected $lifetime = 1 * 86400;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
|
@ -4,8 +4,6 @@ namespace App\Caches;
|
|||||||
|
|
||||||
use App\Models\Package as PackageModel;
|
use App\Models\Package as PackageModel;
|
||||||
use App\Repos\Course as CourseRepo;
|
use App\Repos\Course as CourseRepo;
|
||||||
use App\Repos\Package as PackageRepo;
|
|
||||||
use Phalcon\Mvc\Model\Resultset;
|
|
||||||
|
|
||||||
class CoursePackageList extends Cache
|
class CoursePackageList extends Cache
|
||||||
{
|
{
|
||||||
@ -28,68 +26,27 @@ class CoursePackageList extends Cache
|
|||||||
|
|
||||||
$packages = $courseRepo->findPackages($id);
|
$packages = $courseRepo->findPackages($id);
|
||||||
|
|
||||||
return $this->handleContent($packages);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Resultset|PackageModel[] $packages
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function handleContent($packages)
|
|
||||||
{
|
|
||||||
if ($packages->count() == 0) {
|
if ($packages->count() == 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->handleContent($packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PackageModel[] $packages
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function handleContent($packages)
|
||||||
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
|
|
||||||
$courses = $this->getPackageCourses($package->id);
|
|
||||||
|
|
||||||
$result[] = [
|
$result[] = [
|
||||||
'id' => $package->id,
|
'id' => $package->id,
|
||||||
'title' => $package->title,
|
'title' => $package->title,
|
||||||
'market_price' => $package->market_price,
|
'market_price' => $package->market_price,
|
||||||
'vip_price' => $package->vip_price,
|
'vip_price' => $package->vip_price,
|
||||||
'courses' => $courses,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPackageCourses($packageId)
|
|
||||||
{
|
|
||||||
$packageRepo = new PackageRepo();
|
|
||||||
|
|
||||||
$courses = $packageRepo->findCourses($packageId);
|
|
||||||
|
|
||||||
if ($courses->count() == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
$baseUrl = kg_ci_base_url();
|
|
||||||
|
|
||||||
foreach ($courses as $course) {
|
|
||||||
|
|
||||||
$course->cover = $baseUrl . $course->cover;
|
|
||||||
|
|
||||||
$result[] = [
|
|
||||||
'id' => $course->id,
|
|
||||||
'title' => $course->title,
|
|
||||||
'cover' => $course->cover,
|
|
||||||
'summary' => $course->summary,
|
|
||||||
'market_price' => $course->market_price,
|
|
||||||
'vip_price' => $course->vip_price,
|
|
||||||
'model' => $course->model,
|
|
||||||
'level' => $course->level,
|
|
||||||
'user_count' => $course->user_count,
|
|
||||||
'lesson_count' => $course->lesson_count,
|
|
||||||
'review_count' => $course->review_count,
|
|
||||||
'favorite_count' => $course->favorite_count,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
app/Caches/MaxCategoryId.php
Normal file
29
app/Caches/MaxCategoryId.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Models\Category as CategoryModel;
|
||||||
|
|
||||||
|
class MaxCategoryId extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 365 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return 'max_category_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$category = CategoryModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
|
return $category->id ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -23,7 +23,7 @@ class MaxChapterId extends Cache
|
|||||||
{
|
{
|
||||||
$chapter = ChapterModel::findFirst(['order' => 'id DESC']);
|
$chapter = ChapterModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
return $chapter->id;
|
return $chapter->id ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class MaxCourseId extends Cache
|
|||||||
{
|
{
|
||||||
$course = CourseModel::findFirst(['order' => 'id DESC']);
|
$course = CourseModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
return $course->id;
|
return $course->id ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
29
app/Caches/MaxPackageId.php
Normal file
29
app/Caches/MaxPackageId.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Models\Package as PackageModel;
|
||||||
|
|
||||||
|
class MaxPackageId extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 365 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return 'max_package_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$package = PackageModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
|
return $package->id ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
app/Caches/MaxTopicId.php
Normal file
29
app/Caches/MaxTopicId.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Models\Topic as TopicModel;
|
||||||
|
|
||||||
|
class MaxTopicId extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 365 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return 'max_topic_id';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$topic = TopicModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
|
return $topic->id ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,9 +21,9 @@ class MaxUserId extends Cache
|
|||||||
|
|
||||||
public function getContent($id = null)
|
public function getContent($id = null)
|
||||||
{
|
{
|
||||||
$course = UserModel::findFirst(['order' => 'id DESC']);
|
$user = UserModel::findFirst(['order' => 'id DESC']);
|
||||||
|
|
||||||
return $course->id;
|
return $user->id ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
31
app/Caches/Package.php
Normal file
31
app/Caches/Package.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Repos\Package as PackageRepo;
|
||||||
|
|
||||||
|
class Package extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 7 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return "package:{$id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$packageRepo = new PackageRepo();
|
||||||
|
|
||||||
|
$package = $packageRepo->findById($id);
|
||||||
|
|
||||||
|
return $package ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
57
app/Caches/PackageCourseList.php
Normal file
57
app/Caches/PackageCourseList.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Models\Course as CourseModel;
|
||||||
|
use App\Repos\Package as PackageRepo;
|
||||||
|
|
||||||
|
class PackageCourseList extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 1 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return "package_course_list:{$id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$packageRepo = new PackageRepo();
|
||||||
|
|
||||||
|
$courses = $packageRepo->findCourses($id);
|
||||||
|
|
||||||
|
if ($courses->count() == 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->handleContent($courses);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CourseModel[] $courses
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handleContent($courses)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($courses as $course) {
|
||||||
|
$result[] = [
|
||||||
|
'id' => $course->id,
|
||||||
|
'title' => $course->title,
|
||||||
|
'cover' => $course->cover,
|
||||||
|
'market_price' => $course->market_price,
|
||||||
|
'vip_price' => $course->vip_price,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
app/Caches/Topic.php
Normal file
31
app/Caches/Topic.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Repos\Topic as TopicRepo;
|
||||||
|
|
||||||
|
class Topic extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 7 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return "topic:{$id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$topicRepo = new TopicRepo();
|
||||||
|
|
||||||
|
$topic = $topicRepo->findById($id);
|
||||||
|
|
||||||
|
return $topic ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
57
app/Caches/TopicCourseList.php
Normal file
57
app/Caches/TopicCourseList.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Caches;
|
||||||
|
|
||||||
|
use App\Models\Course as CourseModel;
|
||||||
|
use App\Repos\Topic as TopicRepo;
|
||||||
|
|
||||||
|
class TopicCourseList extends Cache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $lifetime = 1 * 86400;
|
||||||
|
|
||||||
|
public function getLifetime()
|
||||||
|
{
|
||||||
|
return $this->lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey($id = null)
|
||||||
|
{
|
||||||
|
return "topic_course_list:{$id}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent($id = null)
|
||||||
|
{
|
||||||
|
$topicRepo = new TopicRepo();
|
||||||
|
|
||||||
|
$courses = $topicRepo->findCourses($id);
|
||||||
|
|
||||||
|
if ($courses->count() == 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->handleContent($courses);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CourseModel[] $courses
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function handleContent($courses)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($courses as $course) {
|
||||||
|
$result[] = [
|
||||||
|
'id' => $course->id,
|
||||||
|
'title' => $course->title,
|
||||||
|
'cover' => $course->cover,
|
||||||
|
'market_price' => $course->market_price,
|
||||||
|
'vip_price' => $course->vip_price,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,7 +7,7 @@ use App\Repos\User as UserRepo;
|
|||||||
class User extends Cache
|
class User extends Cache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $lifetime = 7 * 86400;
|
protected $lifetime = 1 * 86400;
|
||||||
|
|
||||||
public function getLifetime()
|
public function getLifetime()
|
||||||
{
|
{
|
||||||
@ -25,11 +25,7 @@ class User extends Cache
|
|||||||
|
|
||||||
$user = $userRepo->findById($id);
|
$user = $userRepo->findById($id);
|
||||||
|
|
||||||
if (!$user) {
|
return $user ?: null;
|
||||||
return new \stdClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Admin\Services;
|
namespace App\Http\Admin\Services;
|
||||||
|
|
||||||
|
use App\Caches\Package as PackageCache;
|
||||||
|
use App\Caches\PackageCourseList as PackageCourseListCache;
|
||||||
use App\Library\Paginator\Query as PagerQuery;
|
use App\Library\Paginator\Query as PagerQuery;
|
||||||
use App\Models\CoursePackage as CoursePackageModel;
|
use App\Models\CoursePackage as CoursePackageModel;
|
||||||
use App\Models\Package as PackageModel;
|
use App\Models\Package as PackageModel;
|
||||||
@ -9,6 +11,7 @@ use App\Repos\Course as CourseRepo;
|
|||||||
use App\Repos\CoursePackage as CoursePackageRepo;
|
use App\Repos\CoursePackage as CoursePackageRepo;
|
||||||
use App\Repos\Package as PackageRepo;
|
use App\Repos\Package as PackageRepo;
|
||||||
use App\Validators\Package as PackageValidator;
|
use App\Validators\Package as PackageValidator;
|
||||||
|
use Yansongda\Supports\Collection;
|
||||||
|
|
||||||
class Package extends Service
|
class Package extends Service
|
||||||
{
|
{
|
||||||
@ -50,6 +53,8 @@ class Package extends Service
|
|||||||
|
|
||||||
$package->create($data);
|
$package->create($data);
|
||||||
|
|
||||||
|
$this->rebuildPackageCache($package);
|
||||||
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +96,8 @@ class Package extends Service
|
|||||||
|
|
||||||
$this->updateCourseCount($package);
|
$this->updateCourseCount($package);
|
||||||
|
|
||||||
|
$this->rebuildPackageCache($package);
|
||||||
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +109,8 @@ class Package extends Service
|
|||||||
|
|
||||||
$package->update();
|
$package->update();
|
||||||
|
|
||||||
|
$this->rebuildPackageCache($package);
|
||||||
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +122,8 @@ class Package extends Service
|
|||||||
|
|
||||||
$package->update();
|
$package->update();
|
||||||
|
|
||||||
|
$this->rebuildPackageCache($package);
|
||||||
|
|
||||||
return $package;
|
return $package;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,11 +152,10 @@ class Package extends Service
|
|||||||
$sgtMarketPrice = sprintf('%0.2f', intval($totalMarketPrice * 0.9));
|
$sgtMarketPrice = sprintf('%0.2f', intval($totalMarketPrice * 0.9));
|
||||||
$sgtVipPrice = sprintf('%0.2f', intval($totalVipPrice * 0.8));
|
$sgtVipPrice = sprintf('%0.2f', intval($totalVipPrice * 0.8));
|
||||||
|
|
||||||
$price = new \stdClass();
|
return new Collection([
|
||||||
$price->market_price = $sgtMarketPrice;
|
'market_price' => $sgtMarketPrice,
|
||||||
$price->vip_price = $sgtVipPrice;
|
'vip_price' => $sgtVipPrice,
|
||||||
|
]);
|
||||||
return $price;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getXmCourses($id)
|
public function getXmCourses($id)
|
||||||
@ -220,6 +230,17 @@ class Package extends Service
|
|||||||
$package->update();
|
$package->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rebuildPackageCache(PackageModel $package)
|
||||||
|
{
|
||||||
|
$cache = new PackageCache();
|
||||||
|
|
||||||
|
$cache->rebuild($package->id);
|
||||||
|
|
||||||
|
$cache = new PackageCourseListCache();
|
||||||
|
|
||||||
|
$cache->rebuild($package->id);
|
||||||
|
}
|
||||||
|
|
||||||
protected function findOrFail($id)
|
protected function findOrFail($id)
|
||||||
{
|
{
|
||||||
$validator = new PackageValidator();
|
$validator = new PackageValidator();
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Http\Admin\Services;
|
namespace App\Http\Admin\Services;
|
||||||
|
|
||||||
|
use App\Caches\Topic as TopicCache;
|
||||||
|
use App\Caches\TopicCourseList as TopicCourseListCache;
|
||||||
use App\Library\Paginator\Query as PagerQuery;
|
use App\Library\Paginator\Query as PagerQuery;
|
||||||
use App\Models\CourseTopic as CourseTopicModel;
|
use App\Models\CourseTopic as CourseTopicModel;
|
||||||
use App\Models\Topic as TopicModel;
|
use App\Models\Topic as TopicModel;
|
||||||
@ -49,6 +51,8 @@ class Topic extends Service
|
|||||||
|
|
||||||
$topic->create($data);
|
$topic->create($data);
|
||||||
|
|
||||||
|
$this->rebuildTopicCache($topic);
|
||||||
|
|
||||||
return $topic;
|
return $topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +86,8 @@ class Topic extends Service
|
|||||||
|
|
||||||
$this->updateCourseCount($topic);
|
$this->updateCourseCount($topic);
|
||||||
|
|
||||||
|
$this->rebuildTopicCache($topic);
|
||||||
|
|
||||||
return $topic;
|
return $topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +99,8 @@ class Topic extends Service
|
|||||||
|
|
||||||
$topic->update();
|
$topic->update();
|
||||||
|
|
||||||
|
$this->rebuildTopicCache($topic);
|
||||||
|
|
||||||
return $topic;
|
return $topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +112,8 @@ class Topic extends Service
|
|||||||
|
|
||||||
$topic->update();
|
$topic->update();
|
||||||
|
|
||||||
|
$this->rebuildTopicCache($topic);
|
||||||
|
|
||||||
return $topic;
|
return $topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +189,17 @@ class Topic extends Service
|
|||||||
$topic->update();
|
$topic->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function rebuildTopicCache(TopicModel $topic)
|
||||||
|
{
|
||||||
|
$cache = new TopicCache();
|
||||||
|
|
||||||
|
$cache->rebuild($topic->id);
|
||||||
|
|
||||||
|
$cache = new TopicCourseListCache();
|
||||||
|
|
||||||
|
$cache->rebuild($topic->id);
|
||||||
|
}
|
||||||
|
|
||||||
protected function findOrFail($id)
|
protected function findOrFail($id)
|
||||||
{
|
{
|
||||||
$validator = new TopicValidator();
|
$validator = new TopicValidator();
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
<label class="layui-form-label">封面</label>
|
<label class="layui-form-label">封面</label>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
{% if course.cover %}
|
{% if course.cover %}
|
||||||
<img id="cover-img" class="kg-cover" src="{{ ci_img(course.cover) }}">
|
<img id="cover-img" class="kg-cover" src="{{ course.cover }}">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img id="cover-img" class="kg-cover" src="{{ image('admin/img/default_cover.png') }}">
|
<img id="cover-img" class="kg-cover" src="{{ image('admin/img/default_cover.png') }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<input type="hidden" name="cover" value="{{ ci_img(course.cover) }}">
|
<input type="hidden" name="cover" value="{{ course.cover }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-input-inline" style="padding-top:35px;">
|
<div class="layui-input-inline" style="padding-top:35px;">
|
||||||
<a href="javascript:" class="layui-btn layui-btn-sm" id="choose-cover">编辑</a>
|
<a href="javascript:" class="layui-btn layui-btn-sm" id="choose-cover">编辑</a>
|
||||||
|
@ -18,11 +18,11 @@
|
|||||||
<label class="layui-form-label">封面</label>
|
<label class="layui-form-label">封面</label>
|
||||||
<div class="layui-input-inline">
|
<div class="layui-input-inline">
|
||||||
{% if slide.cover %}
|
{% if slide.cover %}
|
||||||
<img id="cover-img" class="kg-cover" src="{{ ci_img(slide.cover) }}">
|
<img id="cover-img" class="kg-cover" src="{{ slide.cover }}">
|
||||||
{% else %}
|
{% else %}
|
||||||
<img id="cover-img" class="kg-cover" src="{{ image('admin/img/default_cover.png') }}">
|
<img id="cover-img" class="kg-cover" src="{{ image('admin/img/default_cover.png') }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<input type="hidden" name="cover" value="{{ ci_img(slide.cover) }}">
|
<input type="hidden" name="cover" value="{{ slide.cover }}">
|
||||||
</div>
|
</div>
|
||||||
<div class="layui-input-inline" style="padding-top:35px;">
|
<div class="layui-input-inline" style="padding-top:35px;">
|
||||||
<a href="javascript:" class="layui-btn layui-btn-sm" id="choose-cover">编辑</a>
|
<a href="javascript:" class="layui-btn layui-btn-sm" id="choose-cover">编辑</a>
|
||||||
|
@ -13,7 +13,7 @@ class Json extends \Phalcon\Cache\Frontend\Json
|
|||||||
*/
|
*/
|
||||||
public function beforeStore($data)
|
public function beforeStore($data)
|
||||||
{
|
{
|
||||||
$options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
|
$options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION;
|
||||||
|
|
||||||
return json_encode($data, $options);
|
return json_encode($data, $options);
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,8 @@ function kg_ci_base_url()
|
|||||||
*/
|
*/
|
||||||
function kg_ci_img_url($path, $width = 0, $height = 0)
|
function kg_ci_img_url($path, $width = 0, $height = 0)
|
||||||
{
|
{
|
||||||
|
if (!$path) return '';
|
||||||
|
|
||||||
$storage = new StorageService();
|
$storage = new StorageService();
|
||||||
|
|
||||||
return $storage->getCiImageUrl($path, $width, $height);
|
return $storage->getCiImageUrl($path, $width, $height);
|
||||||
|
@ -292,6 +292,10 @@ class Course extends Model
|
|||||||
$this->rating = (float)$this->rating;
|
$this->rating = (float)$this->rating;
|
||||||
$this->score = (float)$this->score;
|
$this->score = (float)$this->score;
|
||||||
|
|
||||||
|
if (!empty($this->cover)) {
|
||||||
|
$this->cover = kg_ci_img_url($this->cover);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($this->attrs)) {
|
if (!empty($this->attrs)) {
|
||||||
$this->attrs = json_decode($this->attrs, true);
|
$this->attrs = json_decode($this->attrs, true);
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,13 @@ class Slide extends Model
|
|||||||
$this->update_time = time();
|
$this->update_time = time();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function afterFetch()
|
||||||
|
{
|
||||||
|
if (!empty($this->cover)) {
|
||||||
|
$this->cover = kg_ci_img_url($this->cover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static function targetTypes()
|
public static function targetTypes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -38,7 +38,7 @@ class Volt extends Provider
|
|||||||
return 'kg_js_include(' . $resolvedArgs . ')';
|
return 'kg_js_include(' . $resolvedArgs . ')';
|
||||||
});
|
});
|
||||||
|
|
||||||
$compiler->addFunction('ci_img', function ($resolvedArgs) {
|
$compiler->addFunction('ci_image', function ($resolvedArgs) {
|
||||||
return 'kg_ci_img_url(' . $resolvedArgs . ')';
|
return 'kg_ci_img_url(' . $resolvedArgs . ')';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -27,6 +27,13 @@ trait ChapterTrait
|
|||||||
return $validator->checkChapter($id);
|
return $validator->checkChapter($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkChapterCache($id)
|
||||||
|
{
|
||||||
|
$validator = new ChapterValidator();
|
||||||
|
|
||||||
|
return $validator->checkChapterCache($id);
|
||||||
|
}
|
||||||
|
|
||||||
public function setChapterUser(ChapterModel $chapter, UserModel $user)
|
public function setChapterUser(ChapterModel $chapter, UserModel $user)
|
||||||
{
|
{
|
||||||
$chapterUserRepo = new ChapterUserRepo();
|
$chapterUserRepo = new ChapterUserRepo();
|
||||||
|
@ -7,7 +7,6 @@ use App\Repos\Course as CourseRepo;
|
|||||||
use App\Repos\Package as PackageRepo;
|
use App\Repos\Package as PackageRepo;
|
||||||
use App\Services\Frontend\CourseTrait;
|
use App\Services\Frontend\CourseTrait;
|
||||||
use App\Services\Frontend\Service;
|
use App\Services\Frontend\Service;
|
||||||
use Phalcon\Mvc\Model\Resultset;
|
|
||||||
|
|
||||||
class PackageList extends Service
|
class PackageList extends Service
|
||||||
{
|
{
|
||||||
@ -22,19 +21,19 @@ class PackageList extends Service
|
|||||||
|
|
||||||
$packages = $courseRepo->findPackages($course->id);
|
$packages = $courseRepo->findPackages($course->id);
|
||||||
|
|
||||||
return $this->handlePackages($packages);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Resultset|PackageModel[] $packages
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function handlePackages($packages)
|
|
||||||
{
|
|
||||||
if ($packages->count() == 0) {
|
if ($packages->count() == 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->handlePackages($packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param PackageModel[] $packages
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function handlePackages($packages)
|
||||||
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
|
|
||||||
foreach ($packages as $package) {
|
foreach ($packages as $package) {
|
||||||
|
@ -33,6 +33,13 @@ trait CourseTrait
|
|||||||
return $validator->checkCourse($id);
|
return $validator->checkCourse($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkCourseCache($id)
|
||||||
|
{
|
||||||
|
$validator = new CourseValidator();
|
||||||
|
|
||||||
|
return $validator->checkCourseCache($id);
|
||||||
|
}
|
||||||
|
|
||||||
public function setCourseUser(CourseModel $course, UserModel $user)
|
public function setCourseUser(CourseModel $course, UserModel $user)
|
||||||
{
|
{
|
||||||
$courseUserRepo = new CourseUserRepo();
|
$courseUserRepo = new CourseUserRepo();
|
||||||
|
@ -11,10 +11,10 @@ use App\Repos\Package as PackageRepo;
|
|||||||
use App\Services\Frontend\Service;
|
use App\Services\Frontend\Service;
|
||||||
use App\Validators\Order as OrderValidator;
|
use App\Validators\Order as OrderValidator;
|
||||||
|
|
||||||
class OrderConfirm extends Service
|
class OrderConfirmInfo extends Service
|
||||||
{
|
{
|
||||||
|
|
||||||
public function confirmOrder()
|
public function getConfirmInfo()
|
||||||
{
|
{
|
||||||
$query = $this->request->getQuery();
|
$query = $this->request->getQuery();
|
||||||
|
|
||||||
@ -75,20 +75,7 @@ class OrderConfirm extends Service
|
|||||||
|
|
||||||
protected function handleCourseInfo(CourseModel $course)
|
protected function handleCourseInfo(CourseModel $course)
|
||||||
{
|
{
|
||||||
$course->cover = kg_ci_img_url($course->cover);
|
return $this->formatCourseInfo($course);
|
||||||
|
|
||||||
return [
|
|
||||||
'id' => $course->id,
|
|
||||||
'title' => $course->title,
|
|
||||||
'cover' => $course->cover,
|
|
||||||
'summary' => $course->summary,
|
|
||||||
'model' => $course->model,
|
|
||||||
'level' => $course->level,
|
|
||||||
'study_expiry' => $course->study_expiry,
|
|
||||||
'refund_expiry' => $course->refund_expiry,
|
|
||||||
'market_price' => $course->market_price,
|
|
||||||
'vip_price' => $course->vip_price,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handlePackageInfo(PackageModel $package)
|
protected function handlePackageInfo(PackageModel $package)
|
||||||
@ -105,24 +92,8 @@ class OrderConfirm extends Service
|
|||||||
|
|
||||||
$courses = $packageRepo->findCourses($package->id);
|
$courses = $packageRepo->findCourses($package->id);
|
||||||
|
|
||||||
$baseUrl = kg_ci_base_url();
|
|
||||||
|
|
||||||
foreach ($courses as $course) {
|
foreach ($courses as $course) {
|
||||||
|
$result['courses'][] = $this->formatCourseInfo($course);
|
||||||
$course->cover = $baseUrl . $course->cover;
|
|
||||||
|
|
||||||
$result['courses'][] = [
|
|
||||||
'id' => $course->id,
|
|
||||||
'title' => $course->title,
|
|
||||||
'cover' => $course->cover,
|
|
||||||
'summary' => $course->summary,
|
|
||||||
'model' => $course->model,
|
|
||||||
'level' => $course->level,
|
|
||||||
'study_expiry' => $course->study_expiry,
|
|
||||||
'refund_expiry' => $course->refund_expiry,
|
|
||||||
'market_price' => $course->market_price,
|
|
||||||
'vip_price' => $course->vip_price,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@ -147,4 +118,22 @@ class OrderConfirm extends Service
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function formatCourseInfo(CourseModel $course)
|
||||||
|
{
|
||||||
|
$course->cover = kg_ci_img_url($course->cover);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $course->id,
|
||||||
|
'title' => $course->title,
|
||||||
|
'cover' => $course->cover,
|
||||||
|
'summary' => $course->summary,
|
||||||
|
'model' => $course->model,
|
||||||
|
'level' => $course->level,
|
||||||
|
'study_expiry' => $course->study_expiry,
|
||||||
|
'refund_expiry' => $course->refund_expiry,
|
||||||
|
'market_price' => $course->market_price,
|
||||||
|
'vip_price' => $course->vip_price,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user