diff --git a/app/adminapi/controller/GeoController.php b/app/adminapi/controller/GeoController.php new file mode 100644 index 00000000..55a1af6d --- /dev/null +++ b/app/adminapi/controller/GeoController.php @@ -0,0 +1,67 @@ +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()); + } +} \ No newline at end of file diff --git a/app/adminapi/controller/user/UserController.php b/app/adminapi/controller/user/UserController.php index f9e06294..441ddfb5 100644 --- a/app/adminapi/controller/user/UserController.php +++ b/app/adminapi/controller/user/UserController.php @@ -5,6 +5,7 @@ namespace app\adminapi\controller\user; use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\user\UserLists; use app\adminapi\logic\user\UserLogic; +use app\common\model\systems\System; use app\common\validate\user\UserBalanceValidate; use app\common\validate\user\UserIntegralValidate; use app\common\validate\user\UserValidate; @@ -43,4 +44,11 @@ class UserController extends BaseAdminController $data = UserLogic::integralList($params); return $this->success('', $data); } + + // 获取应用列表 + public function apps(): Json + { + $data = System::field('id as appid,name')->select(); + return $this->success('请求成功',$data->toArray()); + } } \ No newline at end of file diff --git a/app/adminapi/lists/user/UserLists.php b/app/adminapi/lists/user/UserLists.php index 959487e7..e509b0ed 100644 --- a/app/adminapi/lists/user/UserLists.php +++ b/app/adminapi/lists/user/UserLists.php @@ -12,7 +12,7 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['status','age','gender'], + '=' => ['status','province','city','area','street','village','brigade'], '%like%' => ['nick_name','real_name','phone'], ]; } @@ -20,49 +20,20 @@ class UserLists extends BaseAdminDataLists implements ListsSearchInterface // 获取用户列表 public function lists(): array { - $params = $this->params; - $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::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'].'%"'); - } - }) - ->limit($this->limitOffset, $this->limitLength) - ->order('u.id desc') + $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"; + return User::field($field)->where('status','<>',2)->where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength)->order('id desc') ->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['status_text'] = $item->status_text; + unset($item['province'],$item['city'],$item['area'],$item['street'],$item['village'],$item['brigade']); })->toArray(); } // 获取数量 public function count(): int { - $params = $this->params; - $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(); + return User::field('id')->where('status','<>',2)->where($this->searchWhere)->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/user/UserLogic.php b/app/adminapi/logic/user/UserLogic.php index 9842426f..1c6a2ed4 100644 --- a/app/adminapi/logic/user/UserLogic.php +++ b/app/adminapi/logic/user/UserLogic.php @@ -38,15 +38,31 @@ class UserLogic extends BaseLogic //用户余额列表 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'; - $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['type_text'] = $item->type_text; $item['pay_type_text'] = $item->pay_type_text; unset($item['appid']); })->toArray(); - $count = UserBalance::field('id')->where('user_id',$params['uid'])->count(); + $count = UserBalance::field('id')->where('user_id',$params['uid'])->where($search)->count(); return [ 'count' => $count, 'page_no' => $params['page_no'], @@ -58,13 +74,26 @@ class UserLogic extends BaseLogic //用户积分列表 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'; - $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['type_text'] = $item->type_text; })->toArray(); - $count = UserIntegral::field('id')->where('user_id',$params['uid'])->count(); + $count = UserIntegral::field('id')->where('user_id',$params['uid'])->where($search)->count(); return [ 'count' => $count, 'page_no' => $params['page_no'],