1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-27 21:10:24 +08:00

精简判断

This commit is contained in:
xiaochong0302 2024-12-24 10:56:02 +08:00
parent 6614cdc8d2
commit 3a6d295aa1
20 changed files with 45 additions and 59 deletions

View File

@ -48,8 +48,8 @@ Tips: 请用手机注册一个新账号,用户中心 -> 关注订阅,扫码
### 项目组件
- 后台框架:[phalcon 3.4.5](https://phalcon.io)
- 前端框架:[layui 2.9.10](https://layui.dev)
- 后台框架:[phalcon 3.4](https://phalcon.io)
- 前端框架:[layui 2.9.20](https://layui.dev)
- 全文检索:[xunsearch 1.4.17](http://www.xunsearch.com)
- 基础依赖:[php7.3](https://php.net) [mysql5.7](https://mysql.com) [redis5.0](https://redis.io)

View File

@ -168,12 +168,12 @@ class Course extends Service
}
}
if (isset($post['category_id']) && !empty($post['category_id'])) {
if (!empty($post['category_id'])) {
$category = $validator->checkCategory($post['category_id']);
$data['category_id'] = $category->id;
}
if (isset($post['teacher_id']) && !empty($post['teacher_id'])) {
if (!empty($post['teacher_id'])) {
$teacher = $validator->checkTeacher($post['teacher_id']);
$data['teacher_id'] = $teacher->id;
}

View File

@ -59,9 +59,8 @@ class Package extends Service
$result = [];
foreach ($items as $item) {
$price = $item->market_price > 0 ? sprintf("¥%0.2f", $item->market_price) : '免费';
$result[] = [
'name' => sprintf('%s - %s¥%0.2f', $item->id, $item->title, $price),
'name' => sprintf('%s - %s¥%0.2f', $item->id, $item->title, $item->market_price),
'value' => $item->id,
'selected' => in_array($item->id, $courseIds),
];
@ -152,7 +151,7 @@ class Package extends Service
$package->update($data);
$this->handlePackagedCourses($package->id);
$this->updatePackageCourseCount($package->id);
$this->recountPackageCourses($package->id);
$this->rebuildPackageCache($package->id);
return $package;
@ -217,7 +216,7 @@ class Package extends Service
'course_id' => $courseId,
'package_id' => $package->id,
]);
$this->updateCoursePackageCount($courseId);
$this->recountCoursePackages($courseId);
$this->rebuildCoursePackageCache($courseId);
}
}
@ -229,7 +228,7 @@ class Package extends Service
foreach ($deletedCourseIds as $courseId) {
$coursePackage = $coursePackageRepo->findCoursePackage($courseId, $package->id);
$coursePackage->delete();
$this->updateCoursePackageCount($courseId);
$this->recountCoursePackages($courseId);
$this->rebuildCoursePackageCache($courseId);
}
}
@ -249,7 +248,7 @@ class Package extends Service
}
}
protected function updatePackageCourseCount($packageId)
protected function recountPackageCourses($packageId)
{
$packageRepo = new PackageRepo();
@ -262,7 +261,7 @@ class Package extends Service
$package->update();
}
protected function updateCoursePackageCount($courseId)
protected function recountCoursePackages($courseId)
{
$courseRepo = new CourseRepo();
@ -293,15 +292,4 @@ class Package extends Service
$cache->rebuild($courseId);
}
protected function recountCoursePackages($courseId)
{
$courseRepo = new CourseRepo();
$course = $courseRepo->findById($courseId);
$course->package_count = $courseRepo->countPackages($courseId);
$course->update();
}
}

View File

@ -253,7 +253,7 @@ class Article extends Model
$this->cover = self::getCoverPath($this->cover);
}
if (is_array($this->tags) || is_object($this->tags)) {
if (is_array($this->tags)) {
$this->tags = kg_json_encode($this->tags);
}
}

View File

@ -232,7 +232,7 @@ class Chapter extends Model
}
}
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}
@ -241,7 +241,7 @@ class Chapter extends Model
public function beforeUpdate()
{
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}

View File

@ -75,11 +75,11 @@ class ChapterVod extends Model
public function beforeCreate()
{
if (is_array($this->file_transcode) || is_object($this->file_transcode)) {
if (is_array($this->file_transcode)) {
$this->file_transcode = kg_json_encode($this->file_transcode);
}
if (is_array($this->file_remote) || is_object($this->file_remote)) {
if (is_array($this->file_remote)) {
$this->file_remote = kg_json_encode($this->file_remote);
}
@ -88,11 +88,11 @@ class ChapterVod extends Model
public function beforeUpdate()
{
if (is_array($this->file_transcode) || is_object($this->file_transcode)) {
if (is_array($this->file_transcode)) {
$this->file_transcode = kg_json_encode($this->file_transcode);
}
if (is_array($this->file_remote) || is_object($this->file_remote)) {
if (is_array($this->file_remote)) {
$this->file_remote = kg_json_encode($this->file_remote);
}

View File

@ -321,7 +321,7 @@ class Course extends Model
}
}
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}
@ -338,7 +338,7 @@ class Course extends Model
$sync->addItem($this->id);
}
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}
@ -355,17 +355,13 @@ class Course extends Model
$this->cover = self::getCoverPath($this->cover);
}
if (is_array($this->tags) || is_object($this->tags)) {
if (is_array($this->tags)) {
$this->tags = kg_json_encode($this->tags);
}
if (empty($this->summary)) {
$this->summary = kg_parse_summary($this->details);
}
if (empty($this->origin_price)) {
$this->origin_price = 1.5 * $this->market_price;
}
}
public function afterCreate()

View File

@ -186,7 +186,7 @@ class Notification extends Model
public function beforeSave()
{
if (is_array($this->event_info) || is_object($this->event_info)) {
if (is_array($this->event_info)) {
$this->event_info = kg_json_encode($this->event_info);
}
}

View File

@ -161,7 +161,7 @@ class Order extends Model
public function beforeSave()
{
if (is_array($this->item_info) || is_object($this->item_info)) {
if (is_array($this->item_info)) {
$this->item_info = kg_json_encode($this->item_info);
}
}

View File

@ -181,7 +181,7 @@ class PointGift extends Model
}
}
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}
@ -190,7 +190,7 @@ class PointGift extends Model
public function beforeUpdate()
{
if (is_array($this->attrs) || is_object($this->attrs)) {
if (is_array($this->attrs)) {
$this->attrs = kg_json_encode($this->attrs);
}

View File

@ -110,7 +110,7 @@ class PointHistory extends Model
public function beforeSave()
{
if (is_array($this->event_info) || is_object($this->event_info)) {
if (is_array($this->event_info)) {
$this->event_info = kg_json_encode($this->event_info);
}
}

View File

@ -281,7 +281,7 @@ class Question extends Model
$this->cover = self::getCoverPath($this->cover);
}
if (is_array($this->tags) || is_object($this->tags)) {
if (is_array($this->tags)) {
$this->tags = kg_json_encode($this->tags);
}
}
@ -295,6 +295,9 @@ class Question extends Model
public function afterFetch()
{
/**
* 问题封面非必要,有则处理,无则略过
*/
if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) {
$this->cover = kg_cos_article_cover_url($this->cover);
}

View File

@ -118,7 +118,7 @@ class Role extends Model
public function beforeSave()
{
if (is_array($this->routes) || is_object($this->routes)) {
if (is_array($this->routes)) {
$this->routes = kg_json_encode($this->routes);
}
}

View File

@ -146,7 +146,7 @@ class Slide extends Model
$this->cover = self::getCoverPath($this->cover);
}
if (is_array($this->target_attrs) || is_object($this->target_attrs)) {
if (is_array($this->target_attrs)) {
$this->target_attrs = kg_json_encode($this->target_attrs);
}
}

View File

@ -154,7 +154,7 @@ class Tag extends Model
$this->icon = self::getIconPath($this->icon);
}
if (is_array($this->scopes) || is_object($this->scopes)) {
if (is_array($this->scopes)) {
$this->scopes = kg_json_encode($this->scopes);
}
}

View File

@ -141,7 +141,7 @@ class Task extends Model
public function beforeSave()
{
if (is_array($this->item_info) || is_object($this->item_info)) {
if (is_array($this->item_info)) {
$this->item_info = kg_json_encode($this->item_info);
}
}

View File

@ -95,22 +95,21 @@ class Vip extends Model
public function beforeCreate()
{
if (empty($this->cover)) {
$this->cover = kg_default_vip_cover_path();
} elseif (Text::startsWith($this->cover, 'http')) {
$this->cover = self::getCoverPath($this->cover);
}
$this->create_time = time();
}
public function beforeUpdate()
{
if (Text::startsWith($this->cover, 'http')) {
$this->update_time = time();
}
public function beforeSave()
{
if (empty($this->cover)) {
$this->cover = kg_default_vip_cover_path();
} elseif (Text::startsWith($this->cover, 'http')) {
$this->cover = self::getCoverPath($this->cover);
}
$this->update_time = time();
}
public function afterFetch()

View File

@ -41,7 +41,7 @@ class ArticleDocument extends Injectable
*/
public function formatDocument(ArticleModel $article)
{
if (is_array($article->tags) || is_object($article->tags)) {
if (is_array($article->tags)) {
$article->tags = kg_json_encode($article->tags);
}

View File

@ -41,11 +41,11 @@ class CourseDocument extends Injectable
*/
public function formatDocument(CourseModel $course)
{
if (is_array($course->attrs) || is_object($course->attrs)) {
if (is_array($course->attrs)) {
$course->attrs = kg_json_encode($course->attrs);
}
if (is_array($course->tags) || is_object($course->tags)) {
if (is_array($course->tags)) {
$course->tags = kg_json_encode($course->tags);
}

View File

@ -42,7 +42,7 @@ class QuestionDocument extends Injectable
*/
public function formatDocument(QuestionModel $question)
{
if (is_array($question->tags) || is_object($question->tags)) {
if (is_array($question->tags)) {
$question->tags = kg_json_encode($question->tags);
}