48 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
 | 
						|
namespace app\repository;
 | 
						|
 | 
						|
use think\Model;
 | 
						|
use app\model\Block;
 | 
						|
use app\model\Category;
 | 
						|
use app\service\Repository;
 | 
						|
 | 
						|
/**
 | 
						|
 * 自定义领域 相关
 | 
						|
 *
 | 
						|
 * Class BlockRepository
 | 
						|
 * @package app\repository
 | 
						|
 * @method self getInstance(Model $model = null) static
 | 
						|
 */
 | 
						|
class BlockRepository extends Repository
 | 
						|
{
 | 
						|
    public const CATEGORY_DTC     = 'dtc'; //dtc认证
 | 
						|
    public const CATEGORY_NEWS    = 'news'; //活动信息
 | 
						|
    public const CATEGORY_CONTACT = 'contact'; //联系我们
 | 
						|
    public const CATEGORY_ABOUT   = 'about'; //关于我们
 | 
						|
 | 
						|
 | 
						|
    /**
 | 
						|
     * @param  int  $cateId
 | 
						|
     * @return array
 | 
						|
     */
 | 
						|
    public function getByCateId(int $cateId): array
 | 
						|
    {
 | 
						|
        return Block::getByCategoryId($cateId);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * 分类标识
 | 
						|
     *
 | 
						|
     * @param  string  $name  通过栏目分类标识获取Block
 | 
						|
     * @return array
 | 
						|
     */
 | 
						|
    public function getByCateName(string $name): array
 | 
						|
    {
 | 
						|
        $categoryId = Category::where('name', $name)->value('id');
 | 
						|
        if ($categoryId) {
 | 
						|
            return Block::getByCategoryId($categoryId);
 | 
						|
        }
 | 
						|
        return [];
 | 
						|
    }
 | 
						|
} |