大概在176,280,291,328行4个地方。
@176行修改为: $condition['a.title|a.aid|c.content'] = array('LIKE', "%{$param[$key]}%");
280行增加:->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT'),语句最后改为->count('a.aid');
291行增加:->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT'),语句最后改为->count('a.aid');
328行增加:->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT')结束
代码如下:
修改application/admin/controller/Archives.php的index_archives()函数
文件修改:
public function index_archives()
{
$assign_data = array();
$condition = [];
if (is_dir('./weapp/MultiMerchant/')) {
$condition['a.merchant_id'] = 0;
}
// 获取到所有URL参数
$param = input('param.');
$flag = input('flag/s');
$typeid = input('typeid/d', 0);
//跳转到指定栏目的文档列表
if (0 < intval($typeid)) {
$row = Db::name('arctype')
->alias('a')
->field('b.ctl_name,b.id')
->join('__CHANNELTYPE__ b', 'a.current_channel = b.id', 'LEFT')
->where('a.id', 'eq', $typeid)
->find();
$ctl_name = $row['ctl_name'];
$current_channel = $row['id'];
if (6 == $current_channel) {
$gourl = url('Arctype/single_edit', array('typeid'=>$typeid));
$gourl = url("Arctype/single_edit", array('typeid'=>$typeid,'gourl'=>$gourl));
$this->redirect($gourl);
} else if (8 == $current_channel) {
$gourl = url("Guestbook/index", array('typeid'=>$typeid));
$this->redirect($gourl);
}
}
foreach (['keywords','typeid','flag','is_release','province_id','city_id','area_id'] as $key) {
$param[$key] = !empty($param[$key]) ? addslashes(trim($param[$key])):"";
if (isset($param[$key]) && $param[$key] !== '') {
if ($key == 'keywords') {
$condition['a.title|a.aid|c.content'] = array('LIKE', "%{$param[$key]}%");
} else if ($key == 'typeid') {
$typeid = $param[$key];
$hasRow = model('Arctype')->getHasChildren($typeid);
$typeids = get_arr_column($hasRow, 'id');
//权限控制 by 小虎哥
$admin_info = session('admin_info');
if (0 < intval($admin_info['role_id'])) {
$auth_role_info = $admin_info['auth_role_info'];
if(! empty($auth_role_info)){
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
$condition['a.admin_id'] = $admin_info['admin_id'];
}
if(! empty($auth_role_info['permission']['arctype'])){
if (!empty($typeid)) {
$typeids = array_intersect($typeids, $auth_role_info['permission']['arctype']);
}
}
}
}
$condition['a.typeid'] = array('IN', $typeids);
} else if ($key == 'flag') {
if ('is_release' == $param[$key]) {
$condition['a.users_id'] = array('gt', 0);
} else {
$FlagNew = $param[$key];
$condition['a.'.$param[$key]] = array('eq', 1);
}
// } else if ($key == 'is_release') {
// if (0 < intval($param[$key])) {
// $condition['a.users_id'] = array('gt', intval($param[$key]));
// }
} else if (in_array($key, ['province_id','city_id','area_id'])) {
$citysiteNew = '';
if (!empty($param['province_id'])) {
$condition['a.province_id'] = $param['province_id'];
$citysiteNew .= $param['province_id'];
}
if (!empty($param['city_id'])) {
$condition['a.city_id'] = $param['city_id'];
$citysiteNew .= !empty($citysiteNew) ? '_' . $param['city_id'] : $param['city_id'];
}
if (!empty($param['area_id'])) {
$condition['a.area_id'] = $param['area_id'];
$citysiteNew .= !empty($citysiteNew) ? '_' . $param['area_id'] : $param['area_id'];
}
} else {
$condition['a.'.$key] = array('eq', $param[$key]);
}
}
}
//权限控制 by 小虎哥
if (empty($typeid)) {
$typeids = [];
$admin_info = session('admin_info');
if (0 < intval($admin_info['role_id'])) {
$auth_role_info = $admin_info['auth_role_info'];
if(! empty($auth_role_info)){
if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
$condition['a.admin_id'] = $admin_info['admin_id'];
}
if(! empty($auth_role_info['permission']['arctype'])){
$typeids = $auth_role_info['permission']['arctype'];
}
}
}
if (!empty($typeids)) {
$condition['a.typeid'] = array('IN', $typeids);
}
}
$channelIds = [];
if (empty($typeid)) {
$id_tmp = [6,8];
// 只显示允许发布文档的模型,且是开启状态
$channelIds = Db::name('channeltype')->where('status',0)->whereOr('id','IN',$id_tmp)->column('id');
$condition['a.channel'] = array('NOT IN', $channelIds);
} else {
// 只显示当前栏目对应模型下的文档
$current_channel = Db::name('arctype')->where('id', $typeid)->getField('current_channel');
$condition['a.channel'] = array('eq', $current_channel);
}
$condition['a.lang'] = array('eq', $this->admin_lang);
$condition['a.is_del'] = array('eq', 0);
$condition['a.arcrank'] = array('egt', -1);
$continueNew = "(a.users_id = 0 OR (a.users_id > 0 AND a.arcrank >= 0))";
$orderby = input('param.orderby/s');
$orderway = input('param.orderway/s');
if (!empty($orderby)) {
$orderby = "a.{$orderby} {$orderway}, a.aid desc";
} else {
$orderby = "a.aid desc";
}
// 手机端后台管理插件特定使用参数
$isMobile = input('param.isMobile/d', 0);
if (!empty($isMobile)) $condition['a.channel'] = 1;
// 数据查询,搜索出主键ID的值
$SqlQuery = Db::name('archives')->alias('a')
->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT')
->where($condition)
->where($continueNew)
->fetchSql()
->count('a.aid');
$count = Db::name('sql_cache_table')->where(['sql_md5'=>md5($SqlQuery)])->getField('sql_result');
if (!isset($count) && empty($count)) {
$count = (intval($count) < 0) ? 0 : intval($count);
$count = Db::name('archives')->alias('a')
->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT')
->where($condition)
->where($continueNew)
->count('a.aid');
/*添加查询执行语句到mysql缓存表*/
$SqlCacheTable = [
'sql_name' => '|archives|!=' . implode(',', $channelIds) . '|',
'sql_result' => $count,
'sql_md5' => md5($SqlQuery),
'sql_query' => $SqlQuery,
'add_time' => getTime(),
'update_time' => getTime(),
];
if (!empty($FlagNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . $FlagNew . '|';
if (!empty($citysiteNew)) $SqlCacheTable['sql_name'] = $SqlCacheTable['sql_name'] . 'citysite_' . $citysiteNew . '|';
if (!empty($typeid)) {
$channeltype_list = config('global.channeltype_list');
foreach ($channeltype_list as $key => $value) {
if ($value == $current_channel) {
$ModelMark = $key;
break;
}
}
$SqlCacheTable['sql_name'] = '|' . $ModelMark . '|' . $current_channel . '|' . $typeid . '|';
}
Db::name('sql_cache_table')->insertGetId($SqlCacheTable);
/*END*/
}
$Page = new Page($count, config('paginate.list_rows'));
$list = [];
if (0 < $count) {
$limit = $count > config('paginate.list_rows') ? $Page->firstRow.','.$Page->listRows : $count;
$list = Db::name('archives')
->field("a.aid, a.channel")
->alias('a')
->join('__ARTICLE_CONTENT__ c', 'c.aid = a.aid', 'LEFT')
->where($condition)
->where($continueNew)
->order($orderby)
->limit($limit)
->getAllWithIndex('aid');
// 在数据量大的情况下,经过优化的搜索逻辑,先搜索出主键ID,再通过ID将其他信息补充完整;
if ($list) {
$aids = array_keys($list);
$fields = "b.*, a.*, a.aid as aid";
$row = Db::name('archives')
->field($fields)
->alias('a')
->join('__ARCTYPE__ b', 'a.typeid = b.id', 'LEFT')
->where('a.aid', 'in', $aids)
->getAllWithIndex('aid');
/*获取当页文档的所有模型*/
$channelIds = get_arr_column($list, 'channel');
$channelRow = Db::name('channeltype')->field('id, ctl_name, ifsystem')
->where('id','IN',$channelIds)
->getAllWithIndex('id');
$assign_data['channelRow'] = $channelRow;
foreach ($list as $key => $val) {
$row[$val['aid']]['arcurl'] = get_arcurl($row[$val['aid']]);
$row[$val['aid']]['litpic'] = handle_subdir_pic($row[$val['aid']]['litpic']); // 支持子目录
$list[$key] = $row[$val['aid']];
}
}
}
$show = $Page->show();
$assign_data['page'] = $show;
$assign_data['list'] = $list;
$assign_data['pager'] = $Page;
$assign_data['typeid'] = $typeid; // 栏目ID
//当前栏目信息
$arctype_info = array();
if ($typeid > 0) {
$arctype_info = Db::name('arctype')->field('topid,typename,current_channel')->find($typeid);
}
$assign_data['arctype_info'] = $arctype_info;
// $assign_data['arctype_html'] = allow_release_arctype($typeid, array());//允许发布文档列表的栏目,可以废弃
$assign_data['seo_pseudo'] = tpCache('global.seo_pseudo');//前台URL模式
$assign_data['archives_flags'] = model('ArchivesFlag')->getList();//文档属性
$assign_data['shop_open'] = getUsersConfigData('shop.shop_open');//商城开关
//是否存在栏目
$assign_data['is_arctype'] = Db::name('arctype')->where([
'is_del' => 0,
'lang' => get_current_lang(),
])->count();
$this->assign($assign_data);
// 如果安装手机端后台管理插件并且在手机端访问时执行
if (is_dir('./weapp/Mbackend/') && !empty($isMobile)) {
$mbPage = input('param.p/d', 1);
$nullShow = intval($pageObj->totalPages) === intval($mbPage) ? 1 : 0;
$this->assign('nullShow', $nullShow);
if ($mbPage >= 2) {
return $this->display('archives/archives_list');
} else {
return $this->display('archives/index_archives');
}
} else {
return $this->fetch('index_archives');
}
}
希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 lecms, classcms, fastadmin, pbootcms, phpcms, eyoucms, yzmcms, xunruicms, jizhicms, wordpress, hkcms, yzncms, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。