62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
namespace app\controller;
|
|
|
|
use think\facade\Db;
|
|
|
|
class Search
|
|
{
|
|
public function keywords()
|
|
{
|
|
$post = $GLOBALS['data']['data'];
|
|
if(empty($post['keywords'])){
|
|
return show("请输入搜索关键字");
|
|
}
|
|
$lastIndex = $GLOBALS['data']['data']["lastindex"]??0;
|
|
$KEY = $post['keywords'];
|
|
$where = "(nickname like '{$KEY}%' or city like '{$KEY}%' or school like '{$KEY}%')";
|
|
|
|
if($lastIndex == 0){
|
|
$where .= " and id > 0";
|
|
}else{
|
|
$where .= " and id < ".$lastIndex;
|
|
}
|
|
$types = [1,2,3,4];
|
|
if(!empty($GLOBALS['data']['data']["type"])){
|
|
$type = $GLOBALS['data']['data']["type"];
|
|
if(!in_array($type, $types)){
|
|
return show("上传的类型不正确");
|
|
}
|
|
|
|
if($type == 1) $where .= " and type = 1";
|
|
if($type == 2) $where .= " and type = 2";
|
|
if($type == 3) $where .= " and disabled = 1";
|
|
}
|
|
|
|
$result = [];
|
|
|
|
// $list = Db::name("student")->where($where)->order('hot desc')->limit(env("page_count"))->where($where)->select()->toArray();
|
|
|
|
$list = Db::name("student")->where($where)->order('hot desc')->limit(env("page_count"))->paginate([
|
|
"list_rows" => env("PAGE_COUNT"),
|
|
"page" => $lastIndex
|
|
]);
|
|
|
|
if (empty($list)) {
|
|
return show("获取成功", SUCCESS_CODE, $result);
|
|
}
|
|
|
|
if ($list->currentPage() < $list->lastPage()) {
|
|
$result['lastIndex'] = $lastIndex + 1;
|
|
} else {
|
|
$result['lastIndex'] = 0;
|
|
}
|
|
|
|
|
|
$result = StudentToArray($list);
|
|
|
|
|
|
return show(SUCCESS_MESSAGE.'!',SUCCESS_CODE,$result);
|
|
}
|
|
|
|
}
|