update some route
This commit is contained in:
parent
33350cfd47
commit
f083e2ba80
@ -30,6 +30,11 @@ abstract class ApiController extends BaseController
|
||||
$this->currentUserInfo = $this->request->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前请求api的用户信息,
|
||||
* 前提为必须有参数open_id
|
||||
* @return UserInfo
|
||||
*/
|
||||
protected function getCurrentUserInfo()
|
||||
{
|
||||
if (empty($this->currentUserInfo)) {
|
||||
|
@ -14,6 +14,7 @@ use app\model\AdminInfo;
|
||||
use app\Request;
|
||||
use app\service\AdminService;
|
||||
use app\service\EvaluationService;
|
||||
use app\service\UserService;
|
||||
use app\util\ErrorCode;
|
||||
use app\util\ErrorResponse;
|
||||
use app\util\StringUtil;
|
||||
@ -95,6 +96,25 @@ class Admin extends BaseController
|
||||
return AdminInfo::find(4);
|
||||
}
|
||||
|
||||
public function searchUser()
|
||||
{
|
||||
// 获取参数
|
||||
$isFirst = $this->request->get('is_first', UserService::AllData);
|
||||
$gender = $this->request->get('gender', UserService::AllData);
|
||||
$province = $this->request->get('province', UserService::AllData);
|
||||
$city = $this->request->get('city', UserService::AllData);
|
||||
list($page, $size) = $this->getPageParam();
|
||||
|
||||
$data = UserService::search(
|
||||
intval($isFirst),
|
||||
intval($gender),
|
||||
intval($province),
|
||||
intval($city),
|
||||
$this->request->get('name'),
|
||||
$page, $size
|
||||
);
|
||||
return SuccessResponse::create($data->toArray());
|
||||
}
|
||||
|
||||
public function searchEvaluation()
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\controller;
|
||||
|
||||
use app\BaseController;
|
||||
use think\facade\Config;
|
||||
use think\response\Json;
|
||||
|
||||
class Index extends BaseController
|
||||
@ -14,6 +15,12 @@ class Index extends BaseController
|
||||
"message" => "running"
|
||||
]);
|
||||
}
|
||||
public function test($name = 'ThinkPHP6')
|
||||
{
|
||||
return \json(
|
||||
Config::get("app.evaluation.subject")
|
||||
);
|
||||
}
|
||||
|
||||
public function hello($name = 'ThinkPHP6')
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ namespace app\controller;
|
||||
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\ApiController;
|
||||
use app\model\UserInfo;
|
||||
use app\util\ErrorCode;
|
||||
use app\util\ErrorResponse;
|
||||
@ -17,8 +18,12 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Csv;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class User extends BaseController
|
||||
class User extends ApiController
|
||||
{
|
||||
protected $middleware = [
|
||||
'\app\middleware\ApiCheck' => ['except' => ['create']],
|
||||
];
|
||||
|
||||
|
||||
public function search()
|
||||
{
|
||||
@ -59,7 +64,7 @@ class User extends BaseController
|
||||
if ($dataType == 'xlsx') {
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$filename .= '.xlsx';
|
||||
}else {
|
||||
} else {
|
||||
$filename .= '.csv';
|
||||
}
|
||||
header('Content-Disposition: attachment;filename=' . $filename);
|
||||
@ -67,31 +72,48 @@ class User extends BaseController
|
||||
exit;
|
||||
}
|
||||
|
||||
public function getExport()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function detail(int $id)
|
||||
public function info()
|
||||
{
|
||||
if ($id < 1) {
|
||||
return ErrorResponse::createError(
|
||||
ErrorCode::ERROR_PARAM_ERROR, '用户编号错误'
|
||||
);
|
||||
}
|
||||
$user = UserInfo::find($id);
|
||||
if (empty($user)) {
|
||||
return ErrorResponse::createError(
|
||||
ErrorCode::ERROR_USER_NOT_EXISTS, '用户不存在'
|
||||
);
|
||||
}
|
||||
$userData = $user->getData();
|
||||
$userData['detail'] = $user->getParsedDetail();
|
||||
return json($userData);
|
||||
// if (empty($open_id)) {
|
||||
// return ErrorResponse::createError(
|
||||
// ErrorCode::ERROR_PARAM_ERROR, '用户open_id错误'
|
||||
// );
|
||||
// }
|
||||
// $user = UserInfo::where('open_id', $open_id)->find();
|
||||
// if (empty($user)) {
|
||||
// return ErrorResponse::createError(
|
||||
// ErrorCode::ERROR_USER_NOT_EXISTS, '用户不存在'
|
||||
// );
|
||||
// }
|
||||
|
||||
return $this->getCurrentUserInfo();
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
// if ($id < 1) {
|
||||
// return ErrorResponse::createError(
|
||||
// ErrorCode::ERROR_PARAM_ERROR, '用户编号错误'
|
||||
// );
|
||||
// }
|
||||
// $user = UserInfo::find($id);
|
||||
// if (empty($user)) {
|
||||
// return ErrorResponse::createError(
|
||||
// ErrorCode::ERROR_USER_NOT_EXISTS, '用户不存在'
|
||||
// );
|
||||
// }
|
||||
// $userData = $this->getCurrentUser()->getData();
|
||||
// $userData['detail'] = $this->getCurrentUser()->getParsedDetail();
|
||||
return json(
|
||||
array_merge(
|
||||
$this->getCurrentUserInfo()->toArray(),
|
||||
$this->getCurrentUserInfo()->getParsedDetail()->toArray()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ class ApiCheck
|
||||
*/
|
||||
public function handle(Request $request, \Closure $next)
|
||||
{
|
||||
$open_id = Env::get('app_debug') ? 'wxaffadsf31Dfaf93' : $request->param('open_id');//'wxaffadsf31Dfaf93';
|
||||
$open_id = Env::get('app_debug') ? 'wxaffadsf31Dfaf93wxaffadsf31Dfaf93' : $request->param('open_id');//'wxaffadsf31Dfaf93';
|
||||
|
||||
if (empty($open_id)) {
|
||||
return ErrorResponse::createError(
|
||||
|
@ -14,6 +14,13 @@ use app\BaseModel;
|
||||
class UserInfo extends BaseModel
|
||||
{
|
||||
protected $table = 'user_info';
|
||||
protected $globalScope = ['status'];
|
||||
|
||||
|
||||
public function scopeStatus($query)
|
||||
{
|
||||
$query->where('status', 1);
|
||||
}
|
||||
|
||||
public function detail()
|
||||
{
|
||||
|
82
app/service/UserService.php
Normal file
82
app/service/UserService.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: home
|
||||
* Date: 2019/6/21
|
||||
* Time: 14:13
|
||||
*/
|
||||
|
||||
namespace app\service;
|
||||
|
||||
|
||||
use app\model\UserDetail;
|
||||
use app\model\UserInfo;
|
||||
use app\util\ListCountData;
|
||||
use think\facade\Config;
|
||||
|
||||
class UserService
|
||||
{
|
||||
const AllData = -1;
|
||||
|
||||
|
||||
public static function search(
|
||||
int $isFirst = -1, int $gender = -1, int $province = -1, int $city = -1, string $name = null, int $page = 1, int $pageSize = 20
|
||||
)
|
||||
{
|
||||
$userDetail = new UserDetail();
|
||||
$userInfo = new UserInfo();
|
||||
|
||||
$model = $userDetail->db()->alias('d')
|
||||
->join($userInfo->getTableName() . ' u', 'u.id = d.uid');
|
||||
|
||||
// 首次进藏
|
||||
if ($isFirst != self::AllData) {
|
||||
$model->where('is_first_to_tibet', $isFirst);
|
||||
}
|
||||
// 性别
|
||||
if ($gender != self::AllData) {
|
||||
$model->where('gender', $gender);
|
||||
}
|
||||
// 性别
|
||||
if ($province != self::AllData) {
|
||||
$model->where('province', $province);
|
||||
}
|
||||
// 性别
|
||||
if ($city != self::AllData) {
|
||||
$model->where('city', $city);
|
||||
}
|
||||
if (!empty($name)) {
|
||||
//, ['name' => ""]
|
||||
$model->where("(u.nickname LIKE '%{$name}%' OR d.realname LIKE '%{$name}%')");
|
||||
}
|
||||
|
||||
$dataArray = $model->limit(($page - 1) & $pageSize, $pageSize)// 分页
|
||||
->field('u.nickname,u.open_id,u.avatar,d.*')// 查询字段
|
||||
->select()->toArray(); // 获取结果
|
||||
$count = $userInfo->count(); // 查询总数
|
||||
self::parseArray($dataArray);
|
||||
|
||||
return ListCountData::Create($count, $dataArray);
|
||||
}
|
||||
|
||||
private static function parseArray(&$dataArray)
|
||||
{
|
||||
$userData = Config::get('app.user.subject');
|
||||
foreach ($dataArray as $key => &$item) {
|
||||
// $item['is_first_to_tibet'] = $item['is_first_to_tibet'] == 1 ? '是' : '否';
|
||||
$item['smoke'] = $userData['smoke'][$item['smoke']];
|
||||
$item['medical_history'] = empty($item['medical_history']) ?[]: self::getDataFromArray(
|
||||
$userData['medical_history'],
|
||||
explode(',', $item['medical_history'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static function getDataFromArray(array $datas, array $keys)
|
||||
{
|
||||
foreach ($keys as $key => $v) {
|
||||
$keys[$key] = $datas[$v];
|
||||
}
|
||||
return $keys;
|
||||
}
|
||||
}
|
@ -48,6 +48,9 @@ return [
|
||||
'evaluation' => [
|
||||
'subject' => include(__DIR__.'/evaluation_subject.php'),
|
||||
],
|
||||
'user' => [
|
||||
'subject' => include(__DIR__.'/person_data.php'),
|
||||
],
|
||||
'admin' =>[
|
||||
'multi_login' => Env::get('app.admin_multi_login', true),
|
||||
// 过期时间:1小时
|
||||
|
26
config/person_data.php
Normal file
26
config/person_data.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: home
|
||||
* Date: 2019/6/21
|
||||
* Time: 18:01
|
||||
*/
|
||||
return [
|
||||
'smoke' => [
|
||||
'不吸烟',
|
||||
'10支/天以下',
|
||||
'10~20支/天',
|
||||
'20支/天以上',
|
||||
],
|
||||
'drink' => [
|
||||
'否','是'
|
||||
],
|
||||
'medical_history'=>[
|
||||
'慢性支气管炎、支气管哮喘、支气管扩张病、肺心病',
|
||||
'高血压、冠心病、心肌病、先天性心脏病、风湿性心脏病',
|
||||
'反流性食道炎、慢性胃炎、胃溃疡、慢性胰腺炎、肠易激惹综合征、结肠炎',
|
||||
'3个月内脑梗塞和/或脑出血、癫痫、脑炎、脑膜炎',
|
||||
'特发性或继发性肺动脉高压症',
|
||||
'其他疾病'
|
||||
]
|
||||
];
|
@ -13,4 +13,5 @@ use think\facade\Route;
|
||||
Route::get('hello', function () {
|
||||
return 'hello!';
|
||||
});
|
||||
Route::get('user/detail/:id','User/detail');
|
||||
//Route::get('user/detail/:id','User/detail');
|
||||
//Route::get('user/info/:open_id','User/info');
|
Loading…
x
Reference in New Issue
Block a user