62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\model;
|
||
|
|
||
|
class Store extends Base
|
||
|
{
|
||
|
/**
|
||
|
* 获取文章列表
|
||
|
* @param int $per 每页数量
|
||
|
* @param string $keyword 关键词
|
||
|
* @return \think\Paginator
|
||
|
* @throws \think\db\exception\DbException
|
||
|
*/
|
||
|
public static function getList($per = 20, $keyword = '')
|
||
|
{
|
||
|
$whereMap = [];
|
||
|
$pageParam = [];
|
||
|
|
||
|
if (!empty($keyword)) {
|
||
|
$whereMap[] = ['title', 'like', '%' . $keyword . '%'];
|
||
|
$pageParam['keyword'] = $keyword;
|
||
|
}
|
||
|
|
||
|
$paginate = [
|
||
|
'list_rows' => $per,
|
||
|
'query' => $pageParam
|
||
|
];
|
||
|
return self::when(count($whereMap) > 0, function ($query) use ($whereMap) {
|
||
|
$query->where($whereMap);
|
||
|
})
|
||
|
->order("sort desc")
|
||
|
->paginate($paginate, false);
|
||
|
}
|
||
|
|
||
|
public static function onAfterInsert($article)
|
||
|
{
|
||
|
$article->sort = $article->id;
|
||
|
$article->create_time = time();
|
||
|
$article->save();
|
||
|
}
|
||
|
|
||
|
|
||
|
public static function getWebList()
|
||
|
{
|
||
|
$keyword = input("keyword/s");
|
||
|
return self::when(!empty($keyword), function ($query) use ($keyword) {
|
||
|
$query->where("title|address", "like", "%" . $keyword . "%");
|
||
|
})
|
||
|
->order("sort desc")
|
||
|
->select()
|
||
|
->withAttr("imgs", function ($name) {
|
||
|
$imgs = json_decode($name, true);
|
||
|
if (!empty($imgs)) {
|
||
|
$imgs = array_values($imgs);
|
||
|
return $imgs;
|
||
|
}
|
||
|
return [];
|
||
|
})
|
||
|
->toArray();
|
||
|
}
|
||
|
}
|