298 lines
14 KiB
PHP
298 lines
14 KiB
PHP
<?php
|
||
|
||
namespace app\NewReedaw\controller\app;
|
||
|
||
use think\Controller;
|
||
use think\Db;
|
||
use think\Cache;
|
||
use think\Log;
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
use app\NewReedaw\controller\app\Role;
|
||
|
||
class Index extends Base{
|
||
|
||
protected $index_db_name = [
|
||
'zhanghao'=>'app_account_number',
|
||
'juese'=>'app_user_data',
|
||
'body_data'=>'app_card_body_data',
|
||
|
||
];
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
|
||
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
################################################################接口################################################################
|
||
|
||
// 配置信息
|
||
public function config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||
return $this->msg(10005);
|
||
}
|
||
return $this->config_action($data);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
// 遗传身高
|
||
public function genetic_height(){
|
||
try {
|
||
$data = input('post.');
|
||
if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['momHeight'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
|
||
// 直接开始业务,请求外部接口start
|
||
$url = 'https://ybapi.pcxbc.com/api/child/predictheight';
|
||
$temporary_parameter = [
|
||
'dadHeight'=>$data['dadHeight'],
|
||
'momHeight'=>$data['momHeight'],
|
||
'birthday'=>$data['birthday'],
|
||
'sex'=>$data['sex'],
|
||
];
|
||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||
// 直接开始业务,请求外部接口end
|
||
return json($request_result);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
// BMI测评
|
||
public function bmi_evaluation(){
|
||
try {
|
||
$data = input('post.');
|
||
if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
unset($data['token']);
|
||
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['height'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['sex'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
|
||
// 直接开始业务,请求外部接口start
|
||
$url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
|
||
$temporary_parameter = [
|
||
'height'=>$data['height'],
|
||
'weight'=>$data['weight'],
|
||
'birthday'=>$data['birthday'],
|
||
'sex'=>$data['sex'],
|
||
];
|
||
$request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
|
||
// 直接开始业务,请求外部接口end
|
||
|
||
// 处理进度点
|
||
$return_result =$this->bmi_evaluation_action($request_result);
|
||
return $return_result;
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
// 获取首页角色信息
|
||
public function get_user_data_information(){
|
||
try {
|
||
$data = input('post.');
|
||
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||
return $this->msg(10005,'token type error');
|
||
}
|
||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||
return $this->msg(10005,'aud_id type error');
|
||
}
|
||
return $this->get_user_data_information_action($data);
|
||
} catch (\Exception $e) {
|
||
// 捕获异常
|
||
$logContent["flie"] = $e->getFile();
|
||
$logContent["line"] = $e->getLine();
|
||
$logContent['all_content'] = "异常信息:\n";
|
||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||
$this->record_api_log($data, $logContent, null);
|
||
return $this->msg(99999);
|
||
}
|
||
}
|
||
|
||
################################################################action################################################################
|
||
################################################################action################################################################
|
||
|
||
public function config_action($data){
|
||
$return_data = [
|
||
'literature'=>[
|
||
'index'=>[
|
||
'*数据参考:',
|
||
'《中华人民共和国卫生行业标准WS/T 423-2022》',
|
||
'《中华人民共和国卫生行业标准WS/T 612-2018》',
|
||
'《中华人民共和国卫生行业标准WS/T 586-2018》',
|
||
'《WHO 5~19岁身高/体重判定标准》',
|
||
],
|
||
'bmi_evaluation'=>[
|
||
'*数据参考:',
|
||
'《WHO 5~19岁身高/体重判定标准》'
|
||
],
|
||
'height_prediction'=>[
|
||
'*数据参考:',
|
||
'Khamis-Roche方法',
|
||
'北京积水潭医院儿科临床参考公式',
|
||
'《中国妇幼保健》等相关学术期刊文献',
|
||
],
|
||
'warning'=>[
|
||
'此测量数据仅供参考,不可替代医学专业测试!'
|
||
]
|
||
],
|
||
'king_kong_region'=>[
|
||
['title'=>'增量对比','icon'=>'','jump'=>''],
|
||
['title'=>'中招估分','icon'=>'','jump'=>''],
|
||
['title'=>'遗传身高','icon'=>'','jump'=>''],
|
||
['title'=>'BMI测评','icon'=>'','jump'=>''],
|
||
],
|
||
'role_list'=>[
|
||
]
|
||
];
|
||
$role = new Role;
|
||
$return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
|
||
return $this->msg($return_data);
|
||
}
|
||
public function bmi_evaluation_action($data){
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){
|
||
return $this->msg(99999,'网络异常,请稍后重试1');
|
||
}
|
||
if($data['code'] != 0){
|
||
return $this->msg(99999,'网络异常,请稍后重试2');
|
||
}
|
||
if(!is_array($data['data'])){
|
||
return $this->msg(99999,'网络异常,请稍后重试3');
|
||
}
|
||
if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){
|
||
return $this->msg(99999,'网络异常,请稍后重试4');
|
||
}
|
||
if(!is_array($data['data']['bmilevellist'])){
|
||
return $this->msg(99999,'网络异常,请稍后重试5');
|
||
}
|
||
$num = 0;
|
||
$subsection_val = 0;
|
||
$temporary_subsection_val = null;
|
||
foreach ($data['data']['bmilevellist'] as $key => $value) {
|
||
if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){
|
||
return $this->msg(99999,'网络异常,请稍后重试6');
|
||
}
|
||
// 判断是否可以进行比较,规则是否正确
|
||
if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){
|
||
if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){
|
||
// 在落点内
|
||
$subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差
|
||
$temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差
|
||
$temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比
|
||
$subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比
|
||
$temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比
|
||
$temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1);
|
||
}else{
|
||
$num = $num + 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
if($temporary_subsection_val === null){
|
||
if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){
|
||
$temporary_subsection_val = 100;
|
||
}else{
|
||
return $this->msg(99999,'网络异常,请稍后重试7');
|
||
}
|
||
}
|
||
$data['data']['offset'] = $temporary_subsection_val;
|
||
$data = $data['data'];
|
||
// 处理key名称一致start
|
||
foreach ($data['bmilevellist'] as $key => $value) {
|
||
$data['bmilevellist'][$key]['max_val'] = $value['maxvalue'];
|
||
$data['bmilevellist'][$key]['min_val'] = $value['minvalue'];
|
||
unset($data['bmilevellist'][$key]['minvalue']);
|
||
unset($data['bmilevellist'][$key]['maxvalue']);
|
||
}
|
||
// 处理key名称一致end
|
||
return $this->msg($data);
|
||
}
|
||
public function get_user_data_information_action($data){
|
||
$return_result = [
|
||
'body_data'=>[],
|
||
'kcal_data'=>[],
|
||
'card_data'=>[]
|
||
];
|
||
$aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
|
||
|
||
$body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
|
||
|
||
|
||
}
|
||
|
||
|
||
} |