SchoolPhysicalExamination/application/app/controller/Index.php

178 lines
5.9 KiB
PHP
Raw Normal View History

2024-03-06 16:58:11 +08:00
<?php
namespace app\app\controller;
use think\Controller;
use think\Db;
use app\bj\controller\Common;
use think\Log;
use \think\Validate;
class Index extends Controller{
################################################################个人资料卡################################################################
################################################################个人资料卡################################################################
################################################################个人资料卡################################################################
// 个人信息
public function personal_information(){
// phpinfo();
dump(123);
$result = Db::table('admin_user')->select();
dump($result);
}
// 创建用户卡片
2024-03-15 18:15:17 +08:00
public function create_user_data(){
2024-03-06 16:58:11 +08:00
$data = input();
2024-03-29 18:34:01 +08:00
$verify_result = $this->verify_parameters($data,'register');
2024-03-15 18:15:17 +08:00
$result = Db::table('app_user_data')->insert($verify_result);
if($result){
return $this->msg(0,'success');
}else{
return $this->msg(10001,'创建失败');
}
}
// 切换用户
public function switch_user(){
$data = input();
$verify_result = $this->verify_parameters($data,'register');
$result = Db::table('app_user_data')->insert($verify_result);
2024-03-06 16:58:11 +08:00
if($result){
return $this->msg(0,'success');
}else{
return $this->msg(10001,'创建失败');
}
}
2024-03-15 18:15:17 +08:00
// 获取账号下用户列表
2024-03-06 16:58:11 +08:00
// $type 1获取列表2获取详细信息
2024-03-15 18:15:17 +08:00
public function user_card_list($aan_id,$type=1){
$result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->select();
// $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->field('id,nickname')->select();
2024-03-06 16:58:11 +08:00
$data = [];
if($type == 1){
for ($i=0; $i < count($result); $i++) {
array_push($data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname']]);
}
}else{
$data = $result;
}
2024-03-15 18:15:17 +08:00
return $this->msg(0,'success',$data);
2024-03-06 16:58:11 +08:00
}
2024-03-15 18:15:17 +08:00
// 获取账号下用户详细信息
2024-03-06 16:58:11 +08:00
public function user_card_information($id){
$result = Db::table('app_user_card')->where(['id'=>$id])->find();
if($result){
2024-03-15 18:15:17 +08:00
return $this->msg(0,'success',$result);
2024-03-06 16:58:11 +08:00
}else{
2024-03-15 18:15:17 +08:00
return $this->msg(10001,'error');
2024-03-06 16:58:11 +08:00
}
}
2024-03-15 18:15:17 +08:00
2024-03-06 16:58:11 +08:00
// 创建身体数据
public function create_body_data(){
$data = input();
$result = Db::table('app_body_data')->insert([
'auc_id'=>$data['id'],
'height'=>$data['height'],
'weight'=>$data['weight'],
'bmi'=>$data['bmi'],
'create_time'=>date('Y-m-d H:i:s'),
'last_update_time'=>date('Y-m-d H:i:s'),
]);
if($result){
return $this->msg(0,'success');
}else{
return $this->msg(10001,'创建失败');
}
}
// 获取账号下用户卡片身体数据
// $type 1获取列表2获取详细信息
public function body_data_list($auc_id = 1,$type=1){
$result = Db::table('app_body_data')->where(['auc_id'=>$auc_id])->select();
$data = [];
if($type == 1){
for ($i=0; $i < count($result); $i++) {
array_push($data,['id'=>$result[$i]['id'],'create_time'=>$result[$i]['create_time']]);
}
}else{
$data = $result;
}
return $data;
}
// 获取账号下用户卡片身体数据详细信息
public function body_data_information($id){
$result = Db::table('app_body_data')->where(['id'=>$id])->find();
if($result){
return $result;
}else{
return false;
}
}
public function data_card(){
}
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
2024-03-15 18:15:17 +08:00
public function verify_parameters($data,$type){
// 设置验证
$rule = [
'aan_id' => 'require|number',
'nickname' => 'require|chsAlpha',
'birthday' => 'require|date',
'gender' => 'require|number|in:0,1,2',
2024-03-29 18:34:01 +08:00
'grade' => 'require',
2024-03-15 18:15:17 +08:00
];
$msg = [
'aan_id.require' => '账号信息缺失',
'nickname.require' => '昵称缺失',
'birthday.require' => '生日缺失',
'gender.require' => '性别缺失',
2024-03-29 18:34:01 +08:00
'grade.require' => '年级缺失',
2024-03-15 18:15:17 +08:00
'aan_id.number' => '账号信息格式错误',
'nickname.chsAlpha' => '昵称只能是只能是汉字、字母',
'birthday.date' => '生日信息格式错误',
'gender.number' => '性别格式错误',
'gender.in' => '性别信息错误',
];
$validate = new Validate($rule,$msg);
$result = $validate->check($data);
if(!$result){
return $validate->getError();
}
$parameter['aan_id'] = $data['aan_id'];
$parameter['nickname'] = $data['nickname'];
$parameter['birthday'] = $data['birthday'];
$parameter['gender'] = $data['gender'];
2024-03-29 18:34:01 +08:00
$parameter['grade'] = $data['grade'];
2024-03-15 18:15:17 +08:00
$parameter['create_time'] = date('Y-m-d H:i:s');
$parameter['last_update_time'] = date('Y-m-d H:i:s');
return $parameter;
}
2024-03-29 18:34:01 +08:00
2024-03-15 18:15:17 +08:00
2024-03-06 16:58:11 +08:00
public function msg($code,$msg='',$data=[]){
return json(['code'=>$code,'msg'=>$msg,'data'=>$data]);
}
}