Files
midi-php/application/api/model/Topic.php
2025-08-13 10:43:56 +08:00

55 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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');
$item['title'] = $this->where(['id'=>$item['topic_id']])->value('title');
}
}
return $list;
}
}