chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace addon\forum\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
class ForumTopic extends Model
|
||||
{
|
||||
protected $name = 'forum_topic';
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'create_at';
|
||||
protected $updateTime = 'update_at';
|
||||
|
||||
// 帖子类型(对应 Fly 专栏 class 值)
|
||||
const TYPE_ASK = 0; // 提问
|
||||
const TYPE_SHARE = 99; // 分享
|
||||
const TYPE_DISCUSS = 100; // 讨论
|
||||
const TYPE_SUGGEST = 101; // 建议
|
||||
const TYPE_NOTICE = 168; // 公告
|
||||
const TYPE_DYNAMIC = 169; // 动态
|
||||
|
||||
public static $typeMap = [
|
||||
self::TYPE_ASK => '提问',
|
||||
self::TYPE_SHARE => '分享',
|
||||
self::TYPE_DISCUSS => '讨论',
|
||||
self::TYPE_SUGGEST => '建议',
|
||||
self::TYPE_NOTICE => '公告',
|
||||
self::TYPE_DYNAMIC => '动态',
|
||||
];
|
||||
|
||||
/**
|
||||
* 前台列表查询(返回普通集合,便于模板直接 volist)
|
||||
* @param int $boardId
|
||||
* @param string $type 空=全部
|
||||
* @param string $order hot|new
|
||||
* @param int $size 返回条数
|
||||
*/
|
||||
public static function listFront(int $boardId = 0, string $type = '', string $order = 'new', int $page = 1, int $size = 20)
|
||||
{
|
||||
$q = self::where('status', 1);
|
||||
if ($boardId > 0) {
|
||||
$q->where('board_id', $boardId);
|
||||
}
|
||||
if ($type !== '' && isset(self::$typeMap[(int) $type])) {
|
||||
$q->where('type', (int) $type);
|
||||
}
|
||||
if ($order === 'hot') {
|
||||
$q->order('reply_count desc, views desc');
|
||||
} else {
|
||||
$q->order('is_top desc, id desc');
|
||||
}
|
||||
return $q->limit($size)->select();
|
||||
}
|
||||
|
||||
public static function findById(int $id)
|
||||
{
|
||||
return self::where('id', $id)->where('status', '>=', 0)->find();
|
||||
}
|
||||
|
||||
public static function addViews(int $id)
|
||||
{
|
||||
self::where('id', $id)->inc('views', 1)->update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user