Files
2025-07-27 21:42:34 +08:00

110 lines
3.8 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载:https://gitee.com/likeshop_gitee
// | github下载:https://github.com/likeshop-github
// | 访问官网:https://www.likeshop.cn
// | 访问社区:https://home.likeshop.cn
// | 访问手册:http://doc.likeshop.cn
// | 微信公众号:likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\api\logic;
use app\common\server\UrlServer;
use think\Db;
class ArticleLogic
{
public static function lists($id, $page, $size)
{
$where[] = [
['a.del', '=', 0],
['a.is_show', '=', 1],
['c.del', '=', 0],
['c.is_show', '=', 1],
];
if (!empty($id)) {
$where[] = ['cid', '=', $id];
}
$res = DB::name('article')->alias('a')
->join('article_category c', 'c.id = a.cid')
->where($where)
->field('a.id,a.title,a.synopsis,a.image,a.visit,a.create_time')
->order(['a.id' => 'desc']);
$count = $res->count();
$article = $res->page($page, $size)->select();
foreach ($article as &$item) {
$item['create_time'] = date('Y-m-d ', $item['create_time']);
$item['image'] = UrlServer::getFileUrl($item['image']);
}
$more = is_more($count, $page, $size);
return [
'list' => $article,
'count' => $count,
'page_no' => $page,
'page_size' => $size,
'more' => $more
];
}
public static function CategoryLists()
{
$res = DB::name('article_category')
->where(['del' => 0])
->where('is_show', 1)
->field('id,name')
->select();
return $res;
}
public static function getArticleDetail($id,$client)
{
DB::name('article')
->where(['id' => $id, 'del' => 0])
->setInc('visit');
$res = DB::name('article')
->where(['del' => 0, 'id' => $id])
->field('id,title,image,visit,create_time,content')
->order(['create_time' => 'desc'])
->find();
$preg = '/<img.*?src="((?!(https|http)).*?)".*?\/?>/i';
$local_url = UrlServer::getFileUrl();
$res['content'] = preg_replace($preg, '<img src="' . $local_url . '${1}" />', $res['content']);
$res['create_time'] = date('Y-m-d ', $res['create_time']);
$res['image'] = UrlServer::getFileUrl($res['image']);
$recommend_list = [];
if(2 == $client){
$recommend_list = Db::name('article')
->where([['del','=','0'], ['id','<>',$id], ['is_show', '=', 1]])
->field('id,title,image,visit')
->order('visit desc')
->limit(5)
->select();
foreach ($recommend_list as $key => $recommend){
$recommend_list[$key]['image'] = UrlServer::getFileUrl($recommend['image']);
}
}
$res['recommend_list'] = $recommend_list;
return $res;
}
}