32 lines
		
	
	
		
			873 B
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			873 B
		
	
	
	
		
			PHP
		
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								namespace app\model;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class Honour 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,
							 | 
						||
| 
								 | 
							
								            'query'     => ['category_id' => $categoryId]
							 | 
						||
| 
								 | 
							
								        ];
							 | 
						||
| 
								 | 
							
								        return self::where('category_id', $categoryId)->order('sort', 'asc')->paginate($paginate, $isSample);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public static function getByCategoryId($categoryId, $onlyVisible = false, $pre = 50)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $items = self::where('category_id', $categoryId)
							 | 
						||
| 
								 | 
							
								        ->when($onlyVisible, function($query){
							 | 
						||
| 
								 | 
							
								            $query->where('visible', 1);
							 | 
						||
| 
								 | 
							
								        })
							 | 
						||
| 
								 | 
							
								        ->order('sort', 'asc')
							 | 
						||
| 
								 | 
							
								        ->limit($pre)
							 | 
						||
| 
								 | 
							
								        ->select();
							 | 
						||
| 
								 | 
							
								        return $items->toArray();
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								}
							 |