diff --git a/app/Http/Home/Controllers/LiveController.php b/app/Http/Home/Controllers/LiveController.php
index 3908aceb..a6d572df 100644
--- a/app/Http/Home/Controllers/LiveController.php
+++ b/app/Http/Home/Controllers/LiveController.php
@@ -39,7 +39,7 @@ class LiveController extends Controller
$stats = $service->getStats($id);
- return $this->jsonSuccess($stats);
+ return $this->jsonSuccess(['stats' => $stats]);
}
/**
diff --git a/app/Http/Home/Views/article/show.volt b/app/Http/Home/Views/article/show.volt
index 2c40feb6..e4dda5af 100644
--- a/app/Http/Home/Views/article/show.volt
+++ b/app/Http/Home/Views/article/show.volt
@@ -68,10 +68,14 @@
{% endif %}
{% if article.source_type == 1 %}
-
-
+
+ 问题已关闭
{% endif %}
{% if answer_id > 0 %}
diff --git a/app/Library/Validators/Common.php b/app/Library/Validators/Common.php
index daa7fd2e..bfa7e8da 100644
--- a/app/Library/Validators/Common.php
+++ b/app/Library/Validators/Common.php
@@ -81,30 +81,30 @@ class Common
public static function phone($str)
{
- $pattern = '/^1(3|4|5|6|7|8|9)[0-9]{9}$/';
+ $pattern = '/^1[2-9][0-9]{9}$/';
- return preg_match($pattern, $str) ? true : false;
+ return (bool)preg_match($pattern, $str);
}
public static function name($str)
{
$pattern = '/^[\x{4e00}-\x{9fa5}A-Za-z0-9]{2,15}$/u';
- return preg_match($pattern, $str) ? true : false;
+ return (bool)preg_match($pattern, $str);
}
public static function password($str)
{
$pattern = '/^[[:graph:]]{6,16}$/';
- return preg_match($pattern, $str) ? true : false;
+ return (bool)preg_match($pattern, $str);
}
public static function birthday($str)
{
$pattern = '/^(19|20)\d{2}-(1[0-2]|0[1-9])-(0[1-9]|[1-2][0-9]|3[0-1])$/';
- return preg_match($pattern, $str) ? true : false;
+ return (bool)preg_match($pattern, $str);
}
public static function date($str, $format = 'Y-m-d')
diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php
index ac4d1189..d04fea92 100644
--- a/app/Models/Chapter.php
+++ b/app/Models/Chapter.php
@@ -222,9 +222,14 @@ class Chapter extends Model
public function beforeCreate()
{
+ /**
+ * @var Course $course
+ */
$course = Course::findFirst($this->course_id);
- $this->model = $course->model;
+ if (empty($this->model)) {
+ $this->model = $course->model;
+ }
if ($this->parent_id > 0) {
if (empty($this->attrs)) {
diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php
index 22260bb6..252d22ac 100644
--- a/app/Services/Logic/Chapter/ChapterInfo.php
+++ b/app/Services/Logic/Chapter/ChapterInfo.php
@@ -76,6 +76,7 @@ class ChapterInfo extends LogicService
$result['course'] = $service->handleCourseInfo($this->course);
$me = [
+ 'role_type' => 0,
'plan_id' => 0,
'position' => 0,
'joined' => 0,
@@ -83,8 +84,13 @@ class ChapterInfo extends LogicService
'liked' => 0,
];
- $me['joined'] = $this->joinedChapter ? 1 : 0;
- $me['owned'] = $this->ownedChapter ? 1 : 0;
+ if ($this->joinedChapter) {
+ $me['joined'] = 1;
+ }
+
+ if ($this->ownedChapter) {
+ $me['owned'] = 1;
+ }
if ($user->id > 0) {
@@ -97,6 +103,7 @@ class ChapterInfo extends LogicService
}
if ($this->courseUser) {
+ $me['role_type'] = $this->courseUser->role_type;
$me['plan_id'] = $this->courseUser->plan_id;
}
diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php
index 1134c57e..0ebd9fb8 100644
--- a/app/Services/Logic/Course/CourseInfo.php
+++ b/app/Services/Logic/Course/CourseInfo.php
@@ -46,23 +46,35 @@ class CourseInfo extends LogicService
'progress' => 0,
];
- $me['joined'] = $this->joinedCourse ? 1 : 0;
- $me['owned'] = $this->ownedCourse ? 1 : 0;
+ if ($this->joinedCourse) {
+ $me['joined'] = 1;
+ }
+
+ if ($this->ownedCourse) {
+ $me['owned'] = 1;
+ }
$caseOwned = $this->ownedCourse == false;
$casePrice = $course->market_price > 0;
+ $caseModel = true;
/**
* 过期直播不允许购买
*/
if ($course->model == CourseModel::MODEL_LIVE) {
$caseModel = $course->attrs['end_date'] < date('Y-m-d');
- } else {
- $caseModel = true;
}
- $me['allow_order'] = $caseOwned && $casePrice && $caseModel ? 1 : 0;
- $me['allow_reward'] = $course->market_price == 0 ? 1 : 0;
+ if ($caseOwned && $casePrice && $caseModel) {
+ $me['allow_order'] = 1;
+ }
+
+ /**
+ * 付款课程不允许打赏
+ */
+ if ($course->market_price == 0) {
+ $me['allow_reward'] = 1;
+ }
if ($user->id > 0) {
diff --git a/app/Services/Logic/FlashSale/SaleList.php b/app/Services/Logic/FlashSale/SaleList.php
index 9502501a..df80645e 100644
--- a/app/Services/Logic/FlashSale/SaleList.php
+++ b/app/Services/Logic/FlashSale/SaleList.php
@@ -78,7 +78,7 @@ class SaleList extends LogicService
$item = [
'id' => $sale->id,
'stock' => $sale->stock,
- 'price' => $sale->price,
+ 'price' => (float)$sale->price,
'item_id' => $sale->item_id,
'item_type' => $sale->item_type,
'item_info' => $sale->item_info,
diff --git a/db/migrations/20210324064239.php b/db/migrations/20210324064239.php
index 3c170df3..58dd3b3c 100644
--- a/db/migrations/20210324064239.php
+++ b/db/migrations/20210324064239.php
@@ -403,7 +403,7 @@ final class V20210324064239 extends AbstractMigration
])
->addColumn('tags', 'string', [
'null' => false,
- 'default' => '',
+ 'default' => '[]',
'limit' => 255,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
@@ -4484,7 +4484,7 @@ final class V20210324064239 extends AbstractMigration
])
->addColumn('tags', 'string', [
'null' => false,
- 'default' => '',
+ 'default' => '[]',
'limit' => 255,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
diff --git a/db/migrations/20210720153027.php b/db/migrations/20210720153027.php
index 0a980597..35e793be 100644
--- a/db/migrations/20210720153027.php
+++ b/db/migrations/20210720153027.php
@@ -88,10 +88,10 @@ final class V20210720153027 extends AbstractMigration
{
$table = $this->table('kg_course');
- if ($table->hasColumn('tags') == false) {
+ if (!$table->hasColumn('tags')) {
$table->addColumn('tags', 'string', [
'null' => false,
- 'default' => '',
+ 'default' => '[]',
'limit' => 255,
'collation' => 'utf8mb4_general_ci',
'encoding' => 'utf8mb4',
@@ -107,7 +107,7 @@ final class V20210720153027 extends AbstractMigration
{
$table = $this->table('kg_category');
- if ($table->hasColumn('alias') == false) {
+ if (!$table->hasColumn('alias')) {
$table->addColumn('alias', 'string', [
'null' => false,
'default' => '',
@@ -119,7 +119,7 @@ final class V20210720153027 extends AbstractMigration
]);
}
- if ($table->hasColumn('icon') == false) {
+ if (!$table->hasColumn('icon')) {
$table->addColumn('icon', 'string', [
'null' => false,
'default' => '',
@@ -138,8 +138,7 @@ final class V20210720153027 extends AbstractMigration
{
$table = $this->table('kg_tag');
- if ($table->hasColumn('scopes') == false) {
-
+ if (!$table->hasColumn('scopes')) {
$table->addColumn('scopes', 'string', [
'null' => false,
'default' => '',
@@ -151,7 +150,7 @@ final class V20210720153027 extends AbstractMigration
]);
}
- if ($table->hasColumn('course_count') == false) {
+ if (!$table->hasColumn('course_count')) {
$table->addColumn('course_count', 'integer', [
'null' => false,
'default' => '0',
@@ -162,7 +161,7 @@ final class V20210720153027 extends AbstractMigration
]);
}
- if ($table->hasColumn('article_count') == false) {
+ if (!$table->hasColumn('article_count')) {
$table->addColumn('article_count', 'integer', [
'null' => false,
'default' => '0',
@@ -173,7 +172,7 @@ final class V20210720153027 extends AbstractMigration
]);
}
- if ($table->hasColumn('question_count') == false) {
+ if (!$table->hasColumn('question_count')) {
$table->addColumn('question_count', 'integer', [
'null' => false,
'default' => '0',
diff --git a/db/migrations/20210802021814.php b/db/migrations/20210802021814.php
index 59f542dd..2ccabac9 100644
--- a/db/migrations/20210802021814.php
+++ b/db/migrations/20210802021814.php
@@ -19,7 +19,7 @@ final class V20210802021814 extends AbstractMigration
{
$table = $this->table('kg_page');
- if ($table->hasColumn('alias') == false) {
+ if (!$table->hasColumn('alias')) {
$table->addColumn('alias', 'string', [
'null' => false,
'default' => '',
diff --git a/db/migrations/20211017085325.php b/db/migrations/20211017085325.php
index f9f52167..2598d0ff 100644
--- a/db/migrations/20211017085325.php
+++ b/db/migrations/20211017085325.php
@@ -20,7 +20,7 @@ final class V20211017085325 extends AbstractMigration
{
$table = $this->table('kg_course');
- if ($table->hasColumn('fake_user_count') == false) {
+ if (!$table->hasColumn('fake_user_count')) {
$table->addColumn('fake_user_count', 'integer', [
'null' => false,
'default' => '0',
diff --git a/db/migrations/20211019093522.php b/db/migrations/20211019093522.php
index 9c9c2d0e..44aa2cfb 100644
--- a/db/migrations/20211019093522.php
+++ b/db/migrations/20211019093522.php
@@ -21,7 +21,7 @@ final class V20211019093522 extends AbstractMigration
{
$table = $this->table('kg_user_session');
- if ($table->hasColumn('deleted') == false) {
+ if (!$table->hasColumn('deleted')) {
$table->addColumn('deleted', 'integer', [
'null' => false,
'default' => '0',
@@ -39,7 +39,7 @@ final class V20211019093522 extends AbstractMigration
{
$table = $this->table('kg_user_token');
- if ($table->hasColumn('deleted') == false) {
+ if (!$table->hasColumn('deleted')) {
$table->addColumn('deleted', 'integer', [
'null' => false,
'default' => '0',
diff --git a/db/migrations/20220915084746.php b/db/migrations/20220915084746.php
index d7e42ac8..eebdcc2e 100644
--- a/db/migrations/20220915084746.php
+++ b/db/migrations/20220915084746.php
@@ -29,7 +29,7 @@ final class V20220915084746 extends AbstractMigration
{
$table = $this->table('kg_article');
- if ($table->hasColumn('keywords') == false) {
+ if (!$table->hasColumn('keywords')) {
$table->addColumn('keywords', 'string', [
'null' => false,
'default' => '',
@@ -48,7 +48,7 @@ final class V20220915084746 extends AbstractMigration
{
$table = $this->table('kg_question');
- if ($table->hasColumn('keywords') == false) {
+ if (!$table->hasColumn('keywords')) {
$table->addColumn('keywords', 'string', [
'null' => false,
'default' => '',
@@ -67,7 +67,7 @@ final class V20220915084746 extends AbstractMigration
{
$table = $this->table('kg_page');
- if ($table->hasColumn('keywords') == false) {
+ if (!$table->hasColumn('keywords')) {
$table->addColumn('keywords', 'string', [
'null' => false,
'default' => '',
@@ -86,7 +86,7 @@ final class V20220915084746 extends AbstractMigration
{
$table = $this->table('kg_help');
- if ($table->hasColumn('keywords') == false) {
+ if (!$table->hasColumn('keywords')) {
$table->addColumn('keywords', 'string', [
'null' => false,
'default' => '',
@@ -105,7 +105,7 @@ final class V20220915084746 extends AbstractMigration
{
$table = $this->table('kg_topic');
- if ($table->hasColumn('cover') == false) {
+ if (!$table->hasColumn('cover')) {
$table->addColumn('cover', 'string', [
'null' => false,
'default' => '',
diff --git a/db/migrations/20221021035953.php b/db/migrations/20221021035953.php
index f9498200..10f64d26 100644
--- a/db/migrations/20221021035953.php
+++ b/db/migrations/20221021035953.php
@@ -22,7 +22,7 @@ final class V20221021035953 extends AbstractMigration
{
$table = $this->table('kg_page');
- if ($table->hasColumn('view_count') == false) {
+ if (!$table->hasColumn('view_count')) {
$table->addColumn('view_count', 'integer', [
'null' => false,
'default' => '0',
@@ -40,7 +40,7 @@ final class V20221021035953 extends AbstractMigration
{
$table = $this->table('kg_help');
- if ($table->hasColumn('view_count') == false) {
+ if (!$table->hasColumn('view_count')) {
$table->addColumn('view_count', 'integer', [
'null' => false,
'default' => '0',
@@ -58,7 +58,7 @@ final class V20221021035953 extends AbstractMigration
{
$table = $this->table('kg_user');
- if ($table->hasColumn('notice_count') == false) {
+ if (!$table->hasColumn('notice_count')) {
$table->addColumn('notice_count', 'integer', [
'null' => false,
'default' => '0',
diff --git a/public/static/home/js/chapter.live.chat.js b/public/static/home/js/chapter.live.chat.js
index 2026caa5..77eb4522 100644
--- a/public/static/home/js/chapter.live.chat.js
+++ b/public/static/home/js/chapter.live.chat.js
@@ -97,7 +97,7 @@ layui.use(['jquery', 'form', 'helper'], function () {
function refreshLiveStats() {
var $count = $('#toolbar-online > .text');
$.get(liveStatsUrl, function (res) {
- $count.text(res.client_count);
+ $count.text(res.stats.client_count);
});
}