41 lines
		
	
	
		
			1002 B
		
	
	
	
		
			PHP
		
	
	
		
		
			
		
	
	
			41 lines
		
	
	
		
			1002 B
		
	
	
	
		
			PHP
		
	
	
|  | <?php | ||
|  | namespace app\model; | ||
|  | 
 | ||
|  | use think\Model; | ||
|  | 
 | ||
|  | class Base extends Model | ||
|  | { | ||
|  |     protected $autoWriteTimestamp = false; | ||
|  |     //根据Id列表获取列表
 | ||
|  |     public static function getListByIds($ids) | ||
|  |     { | ||
|  |         if(count($ids) == 0 || empty($ids)) { | ||
|  |             return []; | ||
|  |         } | ||
|  |         return self::where('id', 'in', $ids)->select()->toArray(); | ||
|  |     } | ||
|  |     //根据ID获取单条数据
 | ||
|  |     public static function getById($id) | ||
|  |     { | ||
|  |         if($id <= 0){ | ||
|  |             return []; | ||
|  |         } | ||
|  |         return self::where('id', $id)->findOrEmpty()->toArray(); | ||
|  |     } | ||
|  | 
 | ||
|  |     //根据ID更新数据
 | ||
|  |     public static function updateById($id, $data) | ||
|  |     { | ||
|  |         return self::where('id', $id)->update($data); | ||
|  |     } | ||
|  | 
 | ||
|  |     //根据where条件和排序获取记录
 | ||
|  |     public static function getListByWhereAndOrder($where, $order, $limit = 1) | ||
|  |     { | ||
|  |         return self::where($where) | ||
|  |         ->order($order) | ||
|  |         ->limit($limit) | ||
|  |         ->select() | ||
|  |         ->toArray(); | ||
|  |     } | ||
|  | } |