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

99 lines
3.3 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\controller;
use app\common\controller\BaseCom;
use think\Db;
class Search extends BaseCom
{
//搜索
public function search()
{
$search = input('search', '');
$type = input('type', 1);//1用户2房间3公会
//根据类型进行搜索
switch ($type) {
case 1:
$table = 'user';
//判断是否纯数字
if(is_numeric($search)){
$where = [
'user_code' => $search,
'status' => 1
];
}else{
$where = [
'nickname' => ['like', '%'.$search . '%'],
'status' => 1
];
}
break;
case 2:
$table = 'vs_room';
if(is_numeric($search)){
$where = [
'room_number' => $search,
'apply_status' => 2
];
}else{
$where = [
'room_name' => ['like', '%'.$search . '%'],
'apply_status' => 2
];
}
break;
case 3:
$table = 'vs_guild';
if(is_numeric($search)){
$where = [
'guild_special_id' => $search,
'is_show' => 1,
'delete_time' => 0
];
}else{
$where = [
'guild_name' => ['like', '%'.$search . '%'],
'is_show' => 1,
'delete_time' => 0
];
}
break;
}
if($search == '' || $search == null){
return V(0, '请输入搜索内容');
}
$lists = [];
$reslut = db::name($table)->where($where)->select();
if(isset($reslut)){
foreach ($reslut as $k=>$v){
if($type == 1){
$lists[$k]['id'] = $v['id'];
$lists[$k]['name'] = $v['nickname'];
$lists[$k]['picture'] = $v['avatar'];
$lists[$k]['code'] = $v['user_code'];
$lists[$k]['icon'][0] = model('UserData')->user_wealth_icon($v['id']);//财富图标
$lists[$k]['icon'][1] = model('UserData')->user_charm_icon($v['id']);//魅力图标
}elseif($type == 2){
$lists[$k]['id'] = $v['id'];
$lists[$k]['name'] = $v['room_name'];
$lists[$k]['picture'] = $v['room_cover'];
$lists[$k]['code'] = $v['room_number'];
$lists[$k]['label_icon'] = db::name('vs_room_label')->where('id', $v['label_id'])->value('label_icon');
$lists[$k]['hot_value'] = $v['today_hot_value'];
}elseif($type == 3){
$lists[$k]['id'] = $v['id'];
$lists[$k]['name'] = $v['guild_name'];
$lists[$k]['picture'] = $v['cover'];
$lists[$k]['code'] = $v['guild_special_id'];
}
}
}
return V(1, '获取成功', $lists);
}
}