45 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			PHP
		
	
	
<?php
 | 
						|
namespace app\model;
 | 
						|
 | 
						|
class History extends Base
 | 
						|
{
 | 
						|
    public static function onAfterInsert($item)
 | 
						|
    {
 | 
						|
        $item->sort  = $item->id;
 | 
						|
        $item->save();
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getPaginateList($categoryId, $per = 20,  $isSample = false)
 | 
						|
    {
 | 
						|
        $paginate = [
 | 
						|
            'list_rows' => $per
 | 
						|
        ];
 | 
						|
        $items = self::where('category_id', $categoryId)->order('sort', 'asc')->paginate($paginate, $isSample);
 | 
						|
        if(!$items->isEmpty()) {
 | 
						|
            $ids = $items->column('id');
 | 
						|
            $infoList = HistoryInfo::getByHistoryIds($ids);
 | 
						|
            foreach ($items as $k => $item) {
 | 
						|
                $items[$k]['info'] = $infoList[$item['id']] ?? [];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return $items;
 | 
						|
    }
 | 
						|
 | 
						|
    public static function getByCategoryId($categoryId, $onlyVisible = false)
 | 
						|
    {
 | 
						|
        $items = self::where('category_id', $categoryId)
 | 
						|
            ->when($onlyVisible, function($query){
 | 
						|
                $query->where('visible', 1);
 | 
						|
            })
 | 
						|
            ->order('sort', 'asc')
 | 
						|
            ->select();
 | 
						|
        if(!$items->isEmpty()) {
 | 
						|
            $ids = $items->column('id');
 | 
						|
            $infoList = HistoryInfo::getByHistoryIds($ids, $onlyVisible);
 | 
						|
            foreach ($items as $k => $item) {
 | 
						|
                $items[$k]['info'] = $infoList[$item['id']] ?? [];
 | 
						|
            }
 | 
						|
        }
 | 
						|
        return $items->toArray();
 | 
						|
    }
 | 
						|
} |