1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-07-15 12:52:21 +08:00

优化语法相关

This commit is contained in:
xiaochong0302 2023-05-03 15:18:54 +08:00
parent 56bbb7d6fe
commit 14b2e1df20
16 changed files with 71 additions and 44 deletions

View File

@ -39,7 +39,7 @@ class LiveController extends Controller
$stats = $service->getStats($id);
return $this->jsonSuccess($stats);
return $this->jsonSuccess(['stats' => $stats]);
}
/**

View File

@ -68,10 +68,14 @@
</div>
{% endif %}
{% if article.source_type == 1 %}
<div class="source-tips">本作品系原创,转载请注明出处</div>
<div class="source-tips">
<i class="layui-icon layui-icon-tips"></i> 本文系原创,转载请注明出处
</div>
{% elseif article.source_url %}
<div class="source-tips">
<a href="{{ article.source_url }}" target="_blank">前往阅读原文</a>
<a href="{{ article.source_url }}" target="_blank">
<i class="layui-icon layui-icon-website"></i> 本文系转载,前往阅读原文
</a>
</div>
{% endif %}
</div>

View File

@ -62,8 +62,8 @@
</div>
<div id="answer-anchor"></div>
{% if question.closed == 1 %}
<div class="answer-wrap wrap">
<button class="layui-btn layui-btn-fluid layui-btn-disabled">问题已关闭</button>
<div class="wrap center gray">
<i class="layui-icon layui-icon-close-fill"></i> 问题已关闭
</div>
{% endif %}
{% if answer_id > 0 %}

View File

@ -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')

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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) {

View File

@ -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,

View File

@ -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',

View File

@ -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',

View File

@ -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' => '',

View File

@ -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',

View File

@ -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',

View File

@ -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' => '',

View File

@ -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',

View File

@ -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);
});
}