用户列表搜索条件

This commit is contained in:
unknown 2023-09-21 15:31:01 +08:00
parent 017cb43219
commit 6fcf58424d
4 changed files with 115 additions and 40 deletions

View File

@ -0,0 +1,67 @@
<?php
namespace app\adminapi\controller;
use think\facade\Db;
use think\response\Json;
class GeoController extends BaseAdminController
{
// 获取省份
public function provinces(): Json
{
$data = Db::name('geo_province')->field('province_code as province,province_name')->select();
return $this->success('请求成功',$data->toArray());
}
// 获取城市
public function cities(): Json
{
$param = $this->request->get('province');
if(empty($param)){
return $this->fail('请选择省份');
}
$data = Db::name('geo_city')->field('city_code as city,city_name')->where('province_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取区县
public function areas(): Json
{
$param = $this->request->get('city');
if(empty($param)){
return $this->fail('请选择城市');
}
$data = Db::name('geo_area')->field('area_code as area,area_name')->where('city_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取镇街
public function streets(): Json
{
$param = $this->request->get('area');
if(empty($param)){
return $this->fail('请选择区县');
}
$data = Db::name('geo_street')->field('street_code as street,street_name')->where('area_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取村社
public function villages(): Json
{
$param = $this->request->get('street');
if(empty($param)){
return $this->fail('请选择镇街');
}
$data = Db::name('geo_village')->field('village_code as village,village_name')->where('street_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取小组
public function brigades(): Json
{
$data = Db::name('geo_brigade')->field('id as brigade,brigade_name')->select();
return $this->success('请求成功',$data->toArray());
}
}

View File

@ -5,6 +5,7 @@ namespace app\adminapi\controller\user;
use app\adminapi\controller\BaseAdminController; use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\user\UserLists; use app\adminapi\lists\user\UserLists;
use app\adminapi\logic\user\UserLogic; use app\adminapi\logic\user\UserLogic;
use app\common\model\systems\System;
use app\common\validate\user\UserBalanceValidate; use app\common\validate\user\UserBalanceValidate;
use app\common\validate\user\UserIntegralValidate; use app\common\validate\user\UserIntegralValidate;
use app\common\validate\user\UserValidate; use app\common\validate\user\UserValidate;
@ -43,4 +44,11 @@ class UserController extends BaseAdminController
$data = UserLogic::integralList($params); $data = UserLogic::integralList($params);
return $this->success('', $data); return $this->success('', $data);
} }
// 获取应用列表
public function apps(): Json
{
$data = System::field('id as appid,name')->select();
return $this->success('请求成功',$data->toArray());
}
} }

View File

@ -12,7 +12,7 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array public function setSearch(): array
{ {
return [ return [
'=' => ['status','age','gender'], '=' => ['status','province','city','area','street','village','brigade'],
'%like%' => ['nick_name','real_name','phone'], '%like%' => ['nick_name','real_name','phone'],
]; ];
} }
@ -20,49 +20,20 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface
// 获取用户列表 // 获取用户列表
public function lists(): array public function lists(): array
{ {
$params = $this->params; $field = "id,phone,avatar,nick_name,real_name,id_card,gender,age,total_balance,total_integral,province,city,area,street,village,brigade,address,status,create_time";
$field = "u.id,phone,avatar,nick_name,real_name,id_card,gender,age,total_balance,total_integral,CONCAT(province_name,city_name,area_name,street_name,village_name,brigade_name,address) as address,status,create_time"; return User::field($field)->where('status','<>',2)->where($this->searchWhere)
return User::alias('u')->field($field) ->limit($this->limitOffset, $this->limitLength)->order('id desc')
->leftJoin('geo_province p','u.province = p.province_code')
->leftJoin('geo_city c','u.city = c.city_code')
->leftJoin('geo_area a','u.area = a.area_code')
->leftJoin('geo_street s','u.street = s.street_code')
->leftJoin('geo_village v','u.village = v.village_code')
->leftJoin('geo_brigade b','u.brigade = b.id')
->where('status','<>',2)
->where($this->searchWhere)
->where(function($query) use ($params){
if(isset($params['address'])){
$query->where('CONCAT(province_name,city_name,area_name,street_name,village_name,brigade_name,address) LIKE "%'.$params['address'].'%"');
}
})
->limit($this->limitOffset, $this->limitLength)
->order('u.id desc')
->select()->each(function($item){ ->select()->each(function($item){
$item['address'] = $item->province_text.$item->city_text.$item->area_text.$item->street_text.$item->village_text.$item->brigade_text.$item->address;
$item['gender_text'] = $item->gender_text; $item['gender_text'] = $item->gender_text;
$item['status_text'] = $item->status_text; $item['status_text'] = $item->status_text;
unset($item['province'],$item['city'],$item['area'],$item['street'],$item['village'],$item['brigade']);
})->toArray(); })->toArray();
} }
// 获取数量 // 获取数量
public function count(): int public function count(): int
{ {
$params = $this->params; return User::field('id')->where('status','<>',2)->where($this->searchWhere)->count();
$field = "u.id,CONCAT(province_name,city_name,area_name,street_name,village_name,brigade_name,address) as address,status,create_time";
return User::alias('u')->field($field)
->leftJoin('geo_province p','u.province = p.province_code')
->leftJoin('geo_city c','u.city = c.city_code')
->leftJoin('geo_area a','u.area = a.area_code')
->leftJoin('geo_street s','u.street = s.street_code')
->leftJoin('geo_village v','u.village = v.village_code')
->leftJoin('geo_brigade b','u.brigade = b.id')
->where('status','<>',2)
->where($this->searchWhere)
->where(function($query) use ($params){
if(isset($params['address'])){
$query->where('CONCAT(province_name,city_name,area_name,street_name,village_name,brigade_name,address) LIKE "%'.$params['address'].'%"');
}
})
->count();
} }
} }

View File

@ -38,15 +38,31 @@ class UserLogic extends BaseLogic
//用户余额列表 //用户余额列表
public static function balanceList($params): array public static function balanceList($params): array
{ {
$search = [];
if(isset($params['record_id'])){
$search[] = ['record_id','=',$params['record_id']];
}
if(isset($params['mark'])){
$search[] = ['mark','like','%'.$params['mark'].'%'];
}
if(isset($params['appid'])){
$app = System::field('app_id')->where('id',$params['appid'])->findOrEmpty();
if(!$app->isEmpty()){
$search[] = ['appid','=',$app['app_id']];
}
}
if(isset($params['pay_type']) && in_array($params['pay_type'],[0,1,2,3,4])){
$search[] = ['pay_type','=',$params['pay_type']];
}
//获取用户余额列表 //获取用户余额列表
$fields = 'id,record_id,amount,total_amount,type,pay_type,mark,appid,create_time'; $fields = 'id,record_id,amount,total_amount,type,pay_type,mark,appid,create_time';
$lists = UserBalance::field($fields)->where('user_id',$params['uid'])->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){ $lists = UserBalance::field($fields)->where('user_id',$params['uid'])->where($search)->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){
$item['app'] = System::where('app_id',$item['appid'])->value('name'); $item['app'] = System::where('app_id',$item['appid'])->value('name');
$item['type_text'] = $item->type_text; $item['type_text'] = $item->type_text;
$item['pay_type_text'] = $item->pay_type_text; $item['pay_type_text'] = $item->pay_type_text;
unset($item['appid']); unset($item['appid']);
})->toArray(); })->toArray();
$count = UserBalance::field('id')->where('user_id',$params['uid'])->count(); $count = UserBalance::field('id')->where('user_id',$params['uid'])->where($search)->count();
return [ return [
'count' => $count, 'count' => $count,
'page_no' => $params['page_no'], 'page_no' => $params['page_no'],
@ -58,13 +74,26 @@ class UserLogic extends BaseLogic
//用户积分列表 //用户积分列表
public static function integralList($params): array public static function integralList($params): array
{ {
$search = [];
if(isset($params['mark'])){
$search[] = ['mark','like','%'.$params['mark'].'%'];
}
if(isset($params['appid'])){
$app = System::field('app_id')->where('id',$params['appid'])->findOrEmpty();
if(!$app->isEmpty()){
$search[] = ['appid','=',$app['app_id']];
}
}
if(isset($params['type']) && in_array($params['type'],[0,1])){
$search[] = ['type','=',$params['type']];
}
//获取用户积分列表 //获取用户积分列表
$fields = 'id,record_id,amount,total_amount,type,mark,appid,create_time'; $fields = 'id,record_id,amount,total_amount,type,mark,appid,create_time';
$lists = UserIntegral::field($fields)->where('user_id',$params['uid'])->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){ $lists = UserIntegral::field($fields)->where('user_id',$params['uid'])->where($search)->page($params['page_no'],$params['page_size'])->order('create_time desc')->select()->each(function($item){
$item['app'] = System::where('app_id',$item['appid'])->value('name'); $item['app'] = System::where('app_id',$item['appid'])->value('name');
$item['type_text'] = $item->type_text; $item['type_text'] = $item->type_text;
})->toArray(); })->toArray();
$count = UserIntegral::field('id')->where('user_id',$params['uid'])->count(); $count = UserIntegral::field('id')->where('user_id',$params['uid'])->where($search)->count();
return [ return [
'count' => $count, 'count' => $count,
'page_no' => $params['page_no'], 'page_no' => $params['page_no'],