zzwy2/app/model/Link.php

53 lines
1.2 KiB
PHP
Executable File

<?php
namespace app\model;
class Link extends Base
{
public static function delByIds($ids)
{
return self::whereIn('id', $ids)->delete();
}
//获取友情链接
public static function getList($limit=0)
{
return self::order('sort asc')
->when($limit > 0, function($q) use ($limit) {
$q->limit($limit);
})
->select()
->toArray();
}
public static function onAfterInsert($item)
{
$item->sort = $item->id;
$item->save();
}
//获取友情链接涉及到的文件
public static function getFilesInUse()
{
$items = self::select()->toArray();
$data = [];
foreach($items as $item){
$src = trim($item['src']);
if(!empty($src)){
$key = getKeyByPath($src);
$data[$key] = $src;
}
}
return $data;
}
// 分页查询
public static function getListWithPaginate($where=[], $limit=10, $simplePage = false)
{
return self::where($where)
->order('sort asc')
->paginate([
'list_rows' => $limit
], $simplePage);
}
}