802 lines
38 KiB
PHP
802 lines
38 KiB
PHP
<?php
|
||
|
||
namespace app\testapp\controller;
|
||
|
||
use think\Db;
|
||
|
||
class Pagingcontrast extends Base{
|
||
|
||
protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6'];
|
||
protected $db_name = ['2'=>'test_app_card_body_data','6'=>'test_app_card_skip_data','8'=>'test_app_card_vitalcapacity_data'];
|
||
protected $pagingcontrast_use_db_name = [
|
||
'1'=>'test_app_card_body_data',
|
||
'2'=>'test_app_card_skip_data',
|
||
'3'=>'test_app_card_vitalcapacity_data',
|
||
'4'=>'test_app_user_data',
|
||
// '4'=>'test_app_user_data',
|
||
];
|
||
protected $request_result = [
|
||
'2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'head'=>['头围',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']],
|
||
'6'=>['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']],
|
||
'8'=>['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']]
|
||
];
|
||
protected $pagesize = 10;
|
||
################################################请求接口################################################
|
||
################################################请求接口################################################
|
||
################################################请求接口################################################
|
||
// 获取记录信息(分组)(包含身体、跳绳、肺活量)
|
||
public function get_all_record_data_group($data = ['aud_id'=>'202','s_time'=>'2024-04-01','e_time'=>'2025-06-12','type'=>'2']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('type', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(array_key_exists($data['type'],$this->db_name)){
|
||
$return_data = $this->jump_transfer_interface_record($data,'group');
|
||
}else{
|
||
$return_data = $this->msg(10005);
|
||
}
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_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 get_all_record_data_page($data = ['aud_id'=>'11','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){
|
||
$return_data = $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['page'],'num')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
unset($data['token']);
|
||
if(array_key_exists($data['type'],$this->db_name)){
|
||
$return_data = $this->jump_transfer_interface_record($data,'page');
|
||
}else{
|
||
$return_data = $this->msg(10005);
|
||
}
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_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 get_all_record_detailed_information($data = ['id'=>'36','type'=>'8','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->jump_transfer_interface_detailed($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_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 get_all_card_data_contrast($data = ['before_id'=>'171','after_id'=>'174','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['before_id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['after_id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
unset($data['token']);
|
||
$return_data = $this->jump_transfer_interface_data_contrast($data);
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_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 del_all_record_data($data = ['id'=>'29','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
|
||
try {
|
||
// 你的业务逻辑
|
||
if(count(input('post.')) > 0){
|
||
$data = input('post.');
|
||
}
|
||
if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){
|
||
return $this->msg(10001);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['id'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
if(!$this->verify_data_is_ok($data['type'],'intnum')){
|
||
return $this->msg(10005);
|
||
}
|
||
unset($data['token']);
|
||
$user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]);
|
||
if($user_data){
|
||
$return_data = $this->msg([]);
|
||
}else{
|
||
$return_data = $this->msg(10002);
|
||
}
|
||
|
||
// 成功
|
||
$this->record_api_log($data, null, $return_data);
|
||
return $return_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 jump_transfer_interface_record($data,$str){
|
||
if($data['type'] == '2'){
|
||
return $this->get_body_record_data($data,$str);
|
||
}else if($data['type'] == '6'){
|
||
return $this->get_skip_record_data($data,$str);
|
||
}else if($data['type'] == '8'){
|
||
return $this->get_vitalcapacity_record_data($data,$str);
|
||
}
|
||
}
|
||
public function jump_transfer_interface_detailed($data){
|
||
return $this->get_all_detaile_data_msg($data);
|
||
}
|
||
public function jump_transfer_interface_data_contrast($data){
|
||
if($data['type'] == '2'){
|
||
return $this->get_body_data_contrast($data);
|
||
}else if($data['type'] == '6'){
|
||
return $this->get_skip_data_contrast($data);
|
||
}else if($data['type'] == '8'){
|
||
return $this->get_vitalcapacity_data_contrast($data);
|
||
}
|
||
}
|
||
|
||
################################################业务部分################################################
|
||
|
||
|
||
// 获取记录信息列表(分组)-身体
|
||
// 获取记录信息列表(分页)-身体
|
||
public function get_body_record_data($data,$type){
|
||
$return_result = [];
|
||
|
||
if($type == 'group'){
|
||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||
$result = Db::query("
|
||
select
|
||
id,
|
||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||
height_val as v1,
|
||
weight_val as v2,
|
||
bmi_val as v3
|
||
from ".$this->pagingcontrast_use_db_name['1']."
|
||
where aud_id='".$data['aud_id']."'
|
||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||
and is_del = 0
|
||
order by record_time desc");
|
||
foreach ($result as $key => $value) {
|
||
array_push($return_result, [
|
||
'id'=>$value['id'],
|
||
'v1'=>floatval(sprintf("%.2f", $value['v1'])),
|
||
'v2'=>floatval(sprintf("%.2f", $value['v2'])),
|
||
'v3'=>floatval(sprintf("%.2f", $value['v3'])),
|
||
'v1_name'=>'身高',
|
||
'v2_name'=>'体重',
|
||
'v3_name'=>'BMI',
|
||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||
'r_t'=>$value['r_t']
|
||
]);
|
||
}
|
||
}else{
|
||
$result = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||
$return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->count();
|
||
$return_result['rows'] = [];
|
||
$return_result['pageno'] = $data['page'];
|
||
$return_result['pagesize'] = $this->pagesize;
|
||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||
foreach ($result as $key => $value) {
|
||
array_push($return_result['rows'],[
|
||
'id'=>$value['id'],
|
||
'v1'=>floatval(sprintf("%.2f", $value['height_val'])),
|
||
'v2'=>floatval(sprintf("%.2f", $value['weight_val'])),
|
||
'v3'=>floatval(sprintf("%.2f", $value['bmi_val'])),
|
||
'v1_name'=>'身高',
|
||
'v2_name'=>'体重',
|
||
'v3_name'=>'BMI',
|
||
'record_time'=>$value['b_time'],
|
||
]);
|
||
}
|
||
}
|
||
return $this->msg($return_result);
|
||
}
|
||
// 获取记录信息列表(分组)-跳绳
|
||
// 获取记录信息列表(分页)-跳绳
|
||
public function get_skip_record_data($data,$type){
|
||
$return_result = [];
|
||
|
||
if($type == 'group'){
|
||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||
$result = Db::query("
|
||
select
|
||
id,
|
||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||
jump_num as v1,
|
||
jump_time as v2,
|
||
jump_kcal as v3
|
||
from ".$this->pagingcontrast_use_db_name['2']."
|
||
where aud_id='".$data['aud_id']."'
|
||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||
and is_del = 0
|
||
order by record_time desc");
|
||
foreach ($result as $key => $value) {
|
||
$time_t = $this->handle_hour_branch_second($value['v2']);
|
||
array_push($return_result, [
|
||
'id'=>$value['id'],
|
||
'v1'=>$value['v1'],
|
||
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
|
||
'v3'=>$value['v3'],
|
||
'v1_name'=>'个数',
|
||
'v2_name'=>'时长',
|
||
'v3_name'=>'卡路里',
|
||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||
'r_t'=>$value['r_t']
|
||
]);
|
||
}
|
||
}else{
|
||
$result = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||
$return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count();
|
||
$return_result['rows'] = [];
|
||
$return_result['pageno'] = $data['page'];
|
||
$return_result['pagesize'] = $this->pagesize;
|
||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||
foreach ($result as $key => $value) {
|
||
$time_t = $this->handle_hour_branch_second($value['jump_time']);
|
||
array_push($return_result['rows'],[
|
||
'id'=>$value['id'],
|
||
'v1'=>$value['jump_num'],
|
||
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
|
||
'v3'=>$value['jump_kcal'],
|
||
'v1_name'=>'个数',
|
||
'v2_name'=>'时长',
|
||
'v3_name'=>'卡路里',
|
||
'record_time'=>$value['b_time'],
|
||
]);
|
||
}
|
||
}
|
||
return $this->msg($return_result);
|
||
}
|
||
// 获取记录信息列表(分组)-肺活量
|
||
// 获取记录信息列表(分页)-肺活量
|
||
public function get_vitalcapacity_record_data($data,$type){
|
||
$return_result = [];
|
||
|
||
if($type == 'group'){
|
||
$data['s_time'] = $data['s_time'].' 00:00:00';
|
||
$data['e_time'] = $data['e_time'].' 23:59:59';
|
||
$result = Db::query("
|
||
select
|
||
id,
|
||
CONVERT(varchar(10), record_time, 120) AS r_t,
|
||
CONVERT(varchar(19), record_time, 120) AS record_time,
|
||
one_val as v1,
|
||
two_val as v2,
|
||
three_val as v3,
|
||
average_val as v4,
|
||
score as v5
|
||
from ".$this->pagingcontrast_use_db_name['3']."
|
||
where aud_id='".$data['aud_id']."'
|
||
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
|
||
and is_del = 0
|
||
order by record_time desc");
|
||
foreach ($result as $key => $value) {
|
||
// $time_t = $this->handle_hour_branch_second($value['v2']);
|
||
array_push($return_result, [
|
||
'id'=>$value['id'],
|
||
'v1'=>$value['v1'] == '.00'?'0':$value['v1'],
|
||
'v2'=>$value['v2'] == '.00'?'0':$value['v2'],
|
||
'v3'=>$value['v3'] == '.00'?'0':$value['v3'],
|
||
'v4'=>$value['v4'] == '.00'?'0':$value['v4'],
|
||
'v5'=>explode(',',$value['v5'])[0],
|
||
'v1_name'=>'第一次',
|
||
'v2_name'=>'第二次',
|
||
'v3_name'=>'第三次',
|
||
'v4_name'=>'平均',
|
||
'v5_name'=>'成绩',
|
||
// 'r_t'=>str_replace('-', '/', $value['r_t'])
|
||
'r_t'=>$value['r_t']
|
||
]);
|
||
}
|
||
}else{
|
||
$result = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select();
|
||
$return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id']])->count();
|
||
$return_result['rows'] = [];
|
||
$return_result['pageno'] = $data['page'];
|
||
$return_result['pagesize'] = $this->pagesize;
|
||
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
|
||
foreach ($result as $key => $value) {
|
||
// $time_t = $this->handle_hour_branch_second($value['jump_time']);
|
||
array_push($return_result['rows'],[
|
||
'id'=>$value['id'],
|
||
'v1'=>$value['one_val'] == '.00'?'0':$value['one_val'],
|
||
'v2'=>$value['two_val'] == '.00'?'0':$value['two_val'],
|
||
'v3'=>$value['three_val'] == '.00'?'0':$value['three_val'],
|
||
'v4'=>$value['average_val'] == '.00'?'0':$value['average_val'],
|
||
'v5'=>explode(',',$value['score'])[0],
|
||
'v1_name'=>'第一次',
|
||
'v2_name'=>'第二次',
|
||
'v3_name'=>'第三次',
|
||
'v4_name'=>'平均',
|
||
'v5_name'=>'成绩',
|
||
'record_time'=>$value['b_time']
|
||
]);
|
||
}
|
||
}
|
||
return $this->msg($return_result);
|
||
}
|
||
|
||
|
||
// 获取详细历史数据信息
|
||
public function get_all_detaile_data_msg($data){
|
||
// 加 bcadd(,,20)
|
||
// 减 bcsub(,,20)
|
||
// 乘 bcmul(,,20)
|
||
// 除 bcdiv(,,20)
|
||
// 设置排除在外的数据类型start
|
||
// $exclude_data_arr = ['height','weight','age','bmi','body_level','body_type'];
|
||
$exclude_data_arr = ['height','weight','age','bmi'];
|
||
// 设置排除在外的数据类型end
|
||
$result = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->find();
|
||
$for_data_arr = $this->request_result[$data['type']];
|
||
|
||
if($result){
|
||
// if($data['type'] == 2 && $result['record_type'] != 'by_device_adc'){
|
||
// $for_data_arr = ['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI','']];
|
||
// }
|
||
$result_data = [];
|
||
foreach ($for_data_arr as $key => $value) {
|
||
$temporary_arr['key_name'] = $key;
|
||
$temporary_arr['name'] = $value[0];
|
||
if($data['type'] == 2){
|
||
// 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr
|
||
if($result['record_type'] != 'by_device_adc'){
|
||
|
||
if(!in_array($key, $exclude_data_arr)){
|
||
continue;
|
||
}else{
|
||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||
}
|
||
}else{
|
||
if($key == 'un_fat_w_weight'){
|
||
$temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2);
|
||
}else{
|
||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||
}
|
||
}
|
||
|
||
}else{
|
||
$temporary_arr['value'] = explode(',',$result[$key])[0];
|
||
}
|
||
$temporary_arr['unit'] = $value[1];
|
||
array_push($result_data,$temporary_arr);
|
||
}
|
||
//
|
||
// 添加头围详细start
|
||
if($data['type'] == 2){
|
||
if($result['head_circumference'] != null){
|
||
array_unshift($result_data,[
|
||
'key_name'=>'head_circumference',
|
||
'name'=>'头围',
|
||
'value'=>json_decode($result['head_circumference'],true)['value'] == 0?"0":json_decode($result['head_circumference'],true)['value'],
|
||
'unit'=>'cm',
|
||
]);
|
||
}
|
||
}
|
||
// 添加头围详细end
|
||
return $this->msg($result_data);
|
||
}else{
|
||
return $this->msg(10004);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
// 数据对比
|
||
public function get_body_data_contrast($data){
|
||
$data2 = [$data['before_id'],$data['after_id']];
|
||
$data3 = implode(',',$data2);
|
||
$calculate_arr = [];
|
||
$result = Db::query("
|
||
select
|
||
acbd.id,
|
||
acbd.height,
|
||
acbd.weight,
|
||
acbd.bmi,
|
||
acbd.fat_r,
|
||
acbd.fat_w,
|
||
acbd.muscle,
|
||
acbd.muscleval,
|
||
acbd.water,
|
||
acbd.proteinval,
|
||
acbd.bone,
|
||
acbd.protein,
|
||
acbd.kcal,
|
||
acbd.visceral,
|
||
acbd.sfr,
|
||
acbd.record_time,
|
||
acbd.record_type,
|
||
acbd.head_circumference,
|
||
REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '-') AS b_time,
|
||
aud.nickname,
|
||
aud.gender,
|
||
aud.birthday,
|
||
aud.head_pic
|
||
from ".$this->pagingcontrast_use_db_name['1']." as acbd
|
||
left join ".$this->pagingcontrast_use_db_name['4']." as aud on acbd.aud_id=aud.id
|
||
where acbd.id in ($data3)
|
||
and acbd.is_del = 0
|
||
");
|
||
|
||
if(!$result || count($result)<2){
|
||
return $this->msg(10004);
|
||
}
|
||
// 调整顺序
|
||
foreach ($result as $key => $value) {
|
||
if($value['id'] == $data2[0]){
|
||
$calculate_arr['before'] = $value;
|
||
}else{
|
||
$calculate_arr['after'] = $value;
|
||
}
|
||
}
|
||
|
||
$return_data['time'] = $calculate_arr['before']['b_time'].'与'.$calculate_arr['after']['b_time'];
|
||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||
$return_data['list'] = [];
|
||
// 处理如果没有阻抗的数据为0,显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
|
||
if($calculate_arr['before']['record_type'] != 'by_device_adc' && $calculate_arr['after']['record_type'] != 'by_device_adc'){
|
||
foreach ($calculate_arr['before'] as $key => $value) {
|
||
if(!in_array($key, ['height','weight','bmi','head_circumference'])){
|
||
unset($calculate_arr['before'][$key]);
|
||
unset($calculate_arr['after'][$key]);
|
||
}
|
||
}
|
||
if($return_data['age']>=3){
|
||
unset($calculate_arr['before']['head_circumference']);
|
||
unset($calculate_arr['after']['head_circumference']);
|
||
}else{
|
||
$calculate_arr['before']['head_circumference'] = json_decode($calculate_arr['before']['head_circumference'],true);
|
||
$calculate_arr['after']['head_circumference'] = json_decode($calculate_arr['after']['head_circumference'],true);
|
||
foreach ($calculate_arr as $key => $value) {
|
||
if(array_key_exists('value',$value['head_circumference'])){
|
||
$calculate_arr[$key]['head'][0] = $value['head_circumference']['value'];
|
||
}else{
|
||
$calculate_arr[$key]['head'][0] = 0;
|
||
}
|
||
if(array_key_exists('level',$value['head_circumference'])){
|
||
$calculate_arr[$key]['head'][1] = $value['head_circumference']['level'];
|
||
}else{
|
||
$calculate_arr[$key]['head'][1] = '异常';
|
||
}
|
||
if(array_key_exists('color',$value['head_circumference'])){
|
||
$calculate_arr[$key]['head'][2] = $value['head_circumference']['color'];
|
||
}else{
|
||
$calculate_arr[$key]['head'][2] = '';
|
||
}
|
||
$calculate_arr[$key]['head'] = implode(',',$calculate_arr[$key]['head']);
|
||
unset($calculate_arr['before']['head_circumference']);
|
||
unset($calculate_arr['after']['head_circumference']);
|
||
}
|
||
}
|
||
}else{
|
||
foreach ($calculate_arr as $key => $value) {
|
||
if($value['record_type'] != 'by_device_adc'){
|
||
$calculate_arr[$key]['fat_r'] = "0,异常";
|
||
$calculate_arr[$key]['fat_w'] = "0,异常";
|
||
$calculate_arr[$key]['muscle'] = "0,异常";
|
||
$calculate_arr[$key]['muscleval'] = "0,异常";
|
||
$calculate_arr[$key]['water'] = "0,异常";
|
||
$calculate_arr[$key]['proteinval'] = "0,异常";
|
||
$calculate_arr[$key]['bone'] = "0,异常";
|
||
$calculate_arr[$key]['protein'] = "0,异常";
|
||
$calculate_arr[$key]['kcal'] = "0,异常";
|
||
$calculate_arr[$key]['visceral'] = "0,异常";
|
||
$calculate_arr[$key]['sfr'] = "0,异常";
|
||
}
|
||
}
|
||
}
|
||
// 处理如果没有阻抗的数据为0,显示异常end;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息
|
||
foreach ($calculate_arr['before'] as $key => $value) {
|
||
if(in_array($key, ['height','weight','bmi','head','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){
|
||
$before_arr = explode(',', $value);
|
||
$after_arr = explode(',', $calculate_arr['after'][$key]);
|
||
array_push($return_data['list'], [
|
||
'firstresult'=>[
|
||
'color'=>'',
|
||
'level'=>$before_arr[1],
|
||
'value'=>$before_arr[0],
|
||
'title'=>$this->request_result['2'][$key][0],
|
||
'unit'=>$this->request_result['2'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'secondresult'=>[
|
||
'color'=>'',
|
||
'level'=>$after_arr[1],
|
||
'value'=>$after_arr[0],
|
||
'title'=>$this->request_result['2'][$key][0],
|
||
'unit'=>$this->request_result['2'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'diffval'=>bcsub($after_arr[0],$before_arr[0],2),
|
||
]);
|
||
}
|
||
}
|
||
|
||
// 添加头围数据(如果需要的话)start
|
||
// if($calculate_arr['before']['head_circumference'] != null || $calculate_arr['after']['head_circumference'] != null){
|
||
|
||
// }
|
||
// 添加头围数据(如果需要的话)end
|
||
return $this->msg($return_data);
|
||
}
|
||
// 数据对比
|
||
public function get_skip_data_contrast($data){
|
||
$data2 = [$data['before_id'],$data['after_id']];
|
||
$data3 = implode(',',$data2);
|
||
$calculate_arr = [];
|
||
$result = Db::query("
|
||
select
|
||
acsd.id,
|
||
acsd.jump_num,
|
||
acsd.jump_time,
|
||
acsd.jump_kcal,
|
||
acsd.record_time,
|
||
REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
|
||
aud.nickname,
|
||
aud.gender,
|
||
aud.birthday,
|
||
aud.head_pic
|
||
from ".$this->pagingcontrast_use_db_name['2']." as acsd
|
||
left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id
|
||
where acsd.id in ($data3)
|
||
and acsd.is_del = 0
|
||
");
|
||
|
||
if(!$result || count($result)<2){
|
||
return $this->msg(10004);
|
||
}
|
||
// 调整顺序
|
||
foreach ($result as $key => $value) {
|
||
if($value['id'] == $data2[0]){
|
||
$calculate_arr['before'] = $value;
|
||
}else{
|
||
$calculate_arr['after'] = $value;
|
||
}
|
||
}
|
||
$return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
|
||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||
|
||
$return_data['list'] = [];
|
||
foreach ($calculate_arr['before'] as $key => $value) {
|
||
if(in_array($key, ['jump_num','jump_time','jump_kcal'])){
|
||
$before_arr = $value;
|
||
$after_arr = $calculate_arr['after'][$key];
|
||
$temporary_arr = [
|
||
'firstresult'=>[
|
||
'color'=>'',
|
||
'level'=>'',
|
||
'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($before_arr)):$before_arr,
|
||
'title'=>$this->request_result['6'][$key][0],
|
||
'unit'=>$this->request_result['6'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'secondresult'=>[
|
||
'color'=>'',
|
||
'level'=>'',
|
||
'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($after_arr)):$after_arr,
|
||
'title'=>$this->request_result['6'][$key][0],
|
||
'unit'=>$this->request_result['6'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'diffval'=>bcsub($after_arr,$before_arr,2)
|
||
];
|
||
if($key=='jump_time'){
|
||
$temporary_arr['diffval'] = $temporary_arr['diffval'] >= 0?implode(':',$this->handle_hour_branch_second($temporary_arr['diffval'])):'-'.implode(':',$this->handle_hour_branch_second($temporary_arr['diffval']));
|
||
}
|
||
array_push($return_data['list'], $temporary_arr);
|
||
|
||
}
|
||
|
||
}
|
||
return $this->msg($return_data);
|
||
}
|
||
// 数据对比
|
||
public function get_vitalcapacity_data_contrast($data){
|
||
$data2 = [$data['before_id'],$data['after_id']];
|
||
$data3 = implode(',',$data2);
|
||
$calculate_arr = [];
|
||
$result = Db::query("
|
||
select
|
||
acsd.id,
|
||
acsd.one_val,
|
||
acsd.two_val,
|
||
acsd.three_val,
|
||
acsd.average_val,
|
||
acsd.score_val as score,
|
||
acsd.record_time,
|
||
REPLACE(CONVERT(varchar(10), acsd.record_time, 23), '-', '-') AS b_time,
|
||
aud.nickname,
|
||
aud.gender,
|
||
aud.birthday,
|
||
aud.head_pic
|
||
from ".$this->pagingcontrast_use_db_name['3']." as acsd
|
||
left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id
|
||
where acsd.id in ($data3)
|
||
and acsd.is_del = 0
|
||
");
|
||
|
||
if(!$result || count($result)<2){
|
||
return $this->msg(10004);
|
||
}
|
||
// 调整顺序
|
||
foreach ($result as $key => $value) {
|
||
if($value['id'] == $data2[0]){
|
||
$calculate_arr['before'] = $value;
|
||
}else{
|
||
$calculate_arr['after'] = $value;
|
||
}
|
||
}
|
||
$return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time'];
|
||
$return_data['headimg'] = $calculate_arr['before']['head_pic'];
|
||
$return_data['name'] = $calculate_arr['before']['nickname'];
|
||
$return_data['gender'] = $calculate_arr['before']['gender'];
|
||
$return_data['age'] = $this->calculate_age($calculate_arr['before']['birthday']);
|
||
$return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time']));
|
||
|
||
$return_data['list'] = [];
|
||
foreach ($calculate_arr['before'] as $key => $value) {
|
||
if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){
|
||
$before_arr = $value;
|
||
$after_arr = $calculate_arr['after'][$key];
|
||
$temporary_arr = [
|
||
'firstresult'=>[
|
||
'color'=>'',
|
||
'level'=>'',
|
||
'value'=>$before_arr,
|
||
'title'=>$this->request_result['8'][$key][0],
|
||
'unit'=>$this->request_result['8'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'secondresult'=>[
|
||
'color'=>'',
|
||
'level'=>'',
|
||
'value'=>$after_arr,
|
||
'title'=>$this->request_result['8'][$key][0],
|
||
'unit'=>$this->request_result['8'][$key][1],
|
||
'name'=>$key,
|
||
],
|
||
'diffval'=>bcsub($after_arr,$before_arr,2)
|
||
];
|
||
array_push($return_data['list'], $temporary_arr);
|
||
|
||
}
|
||
|
||
}
|
||
return $this->msg($return_data);
|
||
}
|
||
|
||
|
||
|
||
} |