• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / article / 13100242920

02 Feb 2025 03:42PM UTC coverage: 54.519% (-0.5%) from 55.06%
13100242920

push

github

semantic-release-bot
chore(release): publish

See CHANGELOG.md for more details.

14 of 72 branches covered (19.44%)

187 of 343 relevant lines covered (54.52%)

7.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/Service/ArticleCategoryModel.php
1
<?php
2

3
namespace Miaoxing\Article\Service;
4

5
use Miaoxing\Plugin\BaseModel;
6
use Miaoxing\Plugin\Model\HasAppIdTrait;
7
use Miaoxing\Plugin\Model\ModelTrait;
8
use Miaoxing\Plugin\Model\ReqQueryTrait;
9
use Miaoxing\Plugin\Model\SnowflakeTrait;
10
use Wei\Model\SoftDeleteTrait;
11
use Wei\Model\TreeTrait;
12
use Wei\Ret;
13

14
/**
15
 * @property string|null $id 编号
16
 * @property string $appId 应用编号
17
 * @property string $parentId 父分类编号
18
 * @property int $level 层级
19
 * @property string $path 路径
20
 * @property string $name 名称
21
 * @property string $image 图片
22
 * @property string $description 简介
23
 * @property string $listTpl 列表模板
24
 * @property string $link 链接配置
25
 * @property bool $isEnabled 是否启用
26
 * @property int $pv 查看人数
27
 * @property int $uv 查看次数
28
 * @property int $sort 顺序,从大到小排列
29
 * @property string|null $createdAt
30
 * @property string|null $updatedAt
31
 * @property string $createdBy
32
 * @property string $updatedBy
33
 * @property string|null $deletedAt
34
 * @property string $deletedBy
35
 * @property self|self[] $children
36
 */
37
class ArticleCategoryModel extends BaseModel
38
{
39
    use HasAppIdTrait;
40
    use ModelTrait;
41
    use ReqQueryTrait;
42
    use SnowflakeTrait;
43
    use SoftDeleteTrait;
44
    use TreeTrait;
45

46
    protected $parentIdColumn = 'parentId';
47

48
    protected $columns = [
49
        'link' => [
50
            'cast' => 'json',
51
            'default' => [],
52
        ],
53
    ];
54

55
    /**
56
     * @Relation
57
     * @return self|self[]
58
     */
59
    public function children(): self
60
    {
61
        return $this->hasMany(static::class, 'parent_id')->desc('sort');
6✔
62
    }
63

64
    public function checkParentId($parentId): Ret
65
    {
66
        if (!$parentId) {
30✔
67
            return suc();
12✔
68
        }
69

70
        if ((string) $parentId === $this->id) {
18✔
71
            return err('不能使用自己作为父级分类');
6✔
72
        }
73

74
        $parent = static::new()->findOrFail($parentId);
12✔
75
        if ($this->isAncestorOf($parent)) {
12✔
76
            return err('不能使用子分类作为父级分类');
6✔
77
        }
78

79
        return suc();
6✔
80
    }
81

82
    public function checkDestroy(): Ret
83
    {
84
        if (ArticleModel::findBy('categoryId', $this->id)) {
12✔
85
            return err(['很抱歉,该%s已被%s使用,不能删除', '分类', '图文']);
×
86
        }
87
        return suc();
12✔
88
    }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc