quanwei
2025-10-31 f226d5fe6327e31bb471a96b7370cf94689c6608
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
 
namespace app\common\model\plus\article;
 
use app\common\model\BaseModel;
 
/**
 * 文章模型
 */
class Article extends BaseModel
{
    protected $name = 'article';
    protected $pk = 'article_id';
 
    /**
     * 关联文章封面图
     * @return \think\model\relation\HasOne
     */
    public function image()
    {
        return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'image_id');
    }
 
    /**
     * 关联文章分类表
     * @return \think\model\relation\BelongsTo
     */
    public function category()
    {
        $module = self::getCalledModule() ?: 'common';
        return $this->BelongsTo("app\\{$module}\\model\\plus\\article\\Category", 'category_id', 'category_id');
    }
 
    /**
     * 展示的浏览次数
     * @param $data
     * @return mixed
     */
    public function getShowViewsAttr($data)
    {
        return $data['virtual_views'] + $data['actual_views'];
    }
 
    /**
     * 文章详情
     */
    public static function detail($article_id)
    {
        return (new static())->with(['image', 'category'])->find($article_id);
    }
}