quanwei
2025-12-12 b8961f178740f99ce54cfcbfd88235eaf8b79872
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
 
namespace app\api\model\plus\article;
 
use app\common\exception\BaseException;
use app\common\model\plus\article\Article as ArticleModel;
 
/**
 * 文章模型
 */
class Article extends ArticleModel
{
    /**
     * 追加字段
     */
    protected $append = [
        'view_time'
    ];
 
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'is_delete',
        'app_id',
        'update_time'
    ];
 
    /**
     * 文章详情:HTML实体转换回普通字符
     */
    public function getArticleContentAttr($value)
    {
        return htmlspecialchars_decode($value);
    }
 
    public function getViewTimeAttr($value, $data)
    {
        return $data['virtual_views'] + $data['actual_views'];
    }
 
    /**
     * 文章详情
     */
    public static function detail($article_id)
    {
        if (!$model = parent::detail($article_id)) {
            throw new BaseException(['msg' => '文章不存在']);
        }
        // 累积阅读数
        $model->where('article_id', '=', $article_id)->inc('actual_views', 1)->update();
        return $model;
    }
 
    /**
     * 获取文章列表
     */
    public function getList($category_id = 0, $params,$shop_supplier_id=-1)
    {
        $model = $this;
        $shop_supplier_id >= 0 && $model = $model->where('shop_supplier_id', '=', $shop_supplier_id);
        $category_id > 0 && $model = $model->where('category_id', '=', $category_id);
        return $model ->with(['image', 'category'])
            ->where('article_status', '=', 1)
            ->where('is_delete', '=', 0)
            ->order(['article_sort' => 'asc', 'create_time' => 'desc'])
            ->paginate($params);
    }
 
}