158 lines
5.5 KiB
PHP
158 lines
5.5 KiB
PHP
<?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,
|
||
'type_id' => ['<>',6],
|
||
'room_status' => 1
|
||
];
|
||
}else{
|
||
$where = [
|
||
'room_name' => ['like', '%'.$search . '%'],
|
||
'apply_status' => 2,
|
||
'type_id' => ['<>',6],
|
||
'room_status' => 1
|
||
];
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
|
||
//搜索
|
||
public function search_list()
|
||
{
|
||
$search = input('search', '');
|
||
|
||
if(is_numeric($search)){
|
||
$where = [
|
||
'user_code' => $search,
|
||
'status' => 1
|
||
];
|
||
$where1 = [
|
||
'room_number' => $search,
|
||
'apply_status' => 2,
|
||
'type_id' => ['<>',6],
|
||
'room_status' => 1
|
||
];
|
||
}else{
|
||
$where = [
|
||
'nickname' => ['like', '%'.$search . '%'],
|
||
'status' => 1
|
||
];
|
||
$where1 = [
|
||
'room_name' => ['like', '%'.$search . '%'],
|
||
'apply_status' => 2,
|
||
'type_id' => ['<>',6],
|
||
'room_status' => 1
|
||
];
|
||
}
|
||
|
||
$users = db::name('user')->field('id as user_id,nickname,avatar,user_code,sex')->where($where)->select();
|
||
|
||
if(isset($users)){
|
||
foreach ($users as &$v){
|
||
$v['room_id'] = 0;
|
||
//是否在房间
|
||
$is_room = db::name('vs_room_visitor')->where(['user_id' => $v['user_id'], 'is_delete' => 1])->order('id desc')->value('room_id');
|
||
if ($is_room) {
|
||
$v['room_id'] = $is_room;
|
||
}
|
||
$v['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
|
||
$v['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
|
||
}
|
||
}
|
||
|
||
$rooms = db::name('vs_room')->field('id as room_id,room_name,room_cover,room_number,label_id,today_hot_value')->where($where1)->select();
|
||
if(isset($rooms)){
|
||
foreach ($rooms as $vv){
|
||
$vv['label_icon'] = db::name('vs_room_label')->where('id', $vv['label_id'])->value('label_icon');
|
||
$vv['hot_value'] = $vv['today_hot_value'];
|
||
}
|
||
}
|
||
return V(1, '获取成功', ['users' => $users, 'rooms' => $rooms]);
|
||
}
|
||
} |