55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
||
|
||
namespace app\api\model;
|
||
|
||
use think\Db;
|
||
use think\Model;
|
||
|
||
class Topic extends Model
|
||
{
|
||
// 获取话题列表
|
||
public function get_topic_list($page, $page_limit)
|
||
{
|
||
$list = $this->field('id as topic_id,content,pic,title')->where(['is_delete'=>1,'type'=>1])->page($page, $page_limit)->select();
|
||
return $list;
|
||
}
|
||
|
||
//获取动态引用最多的话题
|
||
public function get_zone_topic()
|
||
{
|
||
//查询动态表fa_user_zone_topic里面 topic_id 字段 使用次数最多的12条
|
||
$list = db::name('user_zone_topic')
|
||
->field('topic_id,count(topic_id) as count')
|
||
->where('topic_id', '<>', 0)
|
||
->order('count desc')->limit(12)
|
||
->group('topic_id')
|
||
->select();
|
||
|
||
//获取数组中topic_id
|
||
$topic_ids = array_column((array)$list, 'topic_id');
|
||
|
||
//不够12条,查询话题表fa_topic里面最新的补够12条
|
||
if(count($list) < 12){
|
||
$topic_list = $this->field('id as topic_id')
|
||
->where(['is_delete'=>1,'type'=>1,'id'=>['not in',$topic_ids]])
|
||
->order('id desc')->limit(12 - count($list))
|
||
->select();
|
||
$topic_list = array_map(function($item){
|
||
$item['count'] = 0;
|
||
return $item;
|
||
}, (array)$topic_list);
|
||
$list = array_merge((array)$list,$topic_list);
|
||
}
|
||
|
||
if($list){
|
||
foreach ($list as &$item){
|
||
$item['content'] = $this->where(['id'=>$item['topic_id']])->value('content');
|
||
$item['pic'] = $this->where(['id'=>$item['topic_id']])->value('pic') ?? get_system_config_value('web_site').'/data/avatar/head_pic.png';;
|
||
$item['title'] = $this->where(['id'=>$item['topic_id']])->value('title');
|
||
}
|
||
}
|
||
return $list;
|
||
}
|
||
|
||
|
||
} |