2024-03-15 18:15:17 +08:00
< ? php
namespace app\app\controller ;
use think\Controller ;
use think\Db ;
use app\bj\controller\Common ;
use think\Log ;
use \think\Validate ;
2024-04-20 17:38:31 +08:00
use app\app\controller\Calculatebody ;
2024-03-15 18:15:17 +08:00
class Card extends Controller {
2024-04-20 17:38:31 +08:00
protected $color = [ '#FF5656' , '#FFAB00' , '#5AD06D' , '#6492F6' , '#3967D6' ];
protected $age_limit = 16 ;
protected $unit_symbol = [ 'score' => '分' , 'height' => 'CM' , 'weight' => '公斤' , 'fat_r' => '%' , 'fat_w' => 'kg' , 'muscle' => '%' , 'muscleval' => 'kg' , 'water' => 'kg' , 'bone' => 'kg' , 'protein' => '%' , 'proteinval' => 'kg' , 'kcal' => 'kcal' , 'sfr' => '%' ,];
protected $unit_name = [ 'score' => '身体得分' , 'height' => '身高' , 'weight' => '体重' , 'bmi' => 'BMI' , 'fat_r' => '脂肪率' , 'fat_w' => '脂肪量' , 'muscle' => '肌肉率' , 'muscleval' => '肌肉量' , 'water' => '水分' , 'bone' => '骨重' , 'protein' => '蛋白率' , 'proteinval' => '蛋白量' , 'kcal' => '基础代谢' , 'visceral' => '内脏指数' , 'sfr' => '皮下脂肪' , 'body_level' => '肥胖等级' , 'body_type' => '身体类型' ];
protected $bhw_list = [
'bmi' => [
[ 'min_val' => '0' , 'max_val' => '' , 'text' => '消瘦' , 'color' => '#ffda69' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '正常' , 'color' => '#5ad06d' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '偏重' , 'color' => '#ffab00' ],
[ 'min_val' => '' , 'max_val' => '50' , 'text' => '肥胖' , 'color' => '#ff5656' ],
],
'height' => [
[ 'min_val' => '0' , 'max_val' => '' , 'text' => '矮' , 'color' => '#ff5656' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '偏矮' , 'color' => '#ffab00' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '标准' , 'color' => '#5ad06d' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '偏高' , 'color' => '#6492f6' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '高' , 'color' => '#3967d6' ],
],
'weight' => [
[ 'min_val' => '0' , 'max_val' => '' , 'text' => '低' , 'color' => '#ff5656' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '偏低' , 'color' => '#ffab00' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '标准' , 'color' => '#5ad06d' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '偏高' , 'color' => '#ffab00' ],
[ 'min_val' => '' , 'max_val' => '' , 'text' => '高' , 'color' => '#ff5656' ],
]
];
protected $standard_color = [
'fat_r' => [ '偏低' => '#FFAB00' , '标准' => '#5AD06D' , '偏高' => '#6492F6' , '高' => '#3967D6' ],
'fat_w' => [ '偏低' => '#FFAB00' , '标准' => '#5AD06D' , '偏高' => '#6492F6' , '高' => '#3967D6' ],
'muscle' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'muscleval' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'water' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'proteinval' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'bone' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'protein' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '优' => '#3967D6' ],
'kcal' => [ '偏低' => '#FF5656' , '优' => '#3967D6' ],
'visceral' => [ '标准' => '#5AD06D' , '警惕' => '#FFAB00' , '危险' => '#FF5656' ],
'sfr' => [ '不足' => '#FF5656' , '标准' => '#5AD06D' , '偏高' => '#6492F6' ],
];
protected $result_end_data_mould = [
'name' => '' ,
'value' => '' ,
'unit' => '' ,
'standard' => '' ,
'color' => '' ,
'list' => []
];
2024-03-15 18:15:17 +08:00
2024-03-29 18:34:01 +08:00
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 存储卡片顺序
2024-04-20 17:38:31 +08:00
// $data = ['aud_id'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]]
2024-03-29 18:34:01 +08:00
public function save_card_order (){
$data = input ();
2024-04-03 18:15:07 +08:00
if ( ! array_key_exists ( 'order_list' , $data ) || ! array_key_exists ( 'user_token' , $data )){
2024-03-29 18:34:01 +08:00
return $this -> msg ( 10001 , '数据格式错误' );
}
if ( ! $this -> isNumericArray ( $data [ 'order_list' ])){
return $this -> msg ( 10002 , '数据内参数格式或值错误' );
}
$data [ 'order_list' ] = json_encode ( $data [ 'order_list' ]);
2024-04-20 17:38:31 +08:00
$result = Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> update ([ 'card_order' => $data [ 'order_list' ]]);
2024-03-29 18:34:01 +08:00
if ( $result ){
return $this -> msg ( 0 , 'success' );
2024-03-15 18:15:17 +08:00
} else {
2024-03-29 18:34:01 +08:00
return $this -> msg ( 10003 , '修改失败' );
2024-03-15 18:15:17 +08:00
}
}
2024-04-03 18:15:07 +08:00
// 获取卡片列表
// $data = ['id'=>'2','time'=>'1991-04-20',content=>'15个']
public function get_card_list (){
$data = input ();
if ( ! array_key_exists ( 'ann_id' , $data ) || ! array_key_exists ( 'time' , $data ) || ! array_key_exists ( 'content' , $data )){
return $this -> msg ( 10001 , '数据格式错误' );
}
$result = Db :: table ( 'app_card_data_log' ) -> insert ([ 'aud_id' => $data [ 'id' ], 'log_time' => $data [ 'time' ], 'content' => $data [ 'content' ], 'create_time' => date ( 'Y-m-d H:i:s' )]);
if ( $result ){
return $this -> msg ( 0 , 'success' );
} else {
return $this -> msg ( 10003 , '添加失败' );
}
}
2024-04-20 17:38:31 +08:00
// 获取基础卡片信息
// $data = ['id'=>'2']
public function card_data_base (){
2024-03-29 18:34:01 +08:00
$data = input ();
2024-04-20 17:38:31 +08:00
if ( ! array_key_exists ( 'id' , $data )){
2024-03-29 18:34:01 +08:00
return $this -> msg ( 10001 , '数据格式错误' );
}
2024-04-20 17:38:31 +08:00
$result = Db :: table ( 'app_card_body_data' ) -> where ([ 'aud_id' => $data [ 'id' ]]) -> order ( 'record_time desc' ) -> field ( 'record_time,height,weight,bmi' ) -> find ();
if ( ! $result ){
return $this -> msg ( 10002 , '未找到数据' );
2024-03-15 18:15:17 +08:00
} else {
2024-04-20 17:38:31 +08:00
return $this -> msg ( 0 , 'success' , $result );
2024-03-15 18:15:17 +08:00
}
}
2024-04-20 17:38:31 +08:00
// 详细卡片信息
// $data = ['id'=>'2']
public function card_data_detailed ( $data = [ 'id' => '7' , 'acd_id' => '2' ]){
// public function body_data_detailed($data=['id'=>'9','acd_id'=>'2']){
// $data = input();
if ( ! array_key_exists ( 'id' , $data ) || ! array_key_exists ( 'acd_id' , $data )){
return $this -> msg ( 10001 , '关键参数缺失' );
}
if ( $data [ 'acd_id' ] == '2' ){
// 基础身体信息卡片
return $this -> get_user_body_data ( $data );
2024-04-03 18:15:07 +08:00
}
2024-04-20 17:38:31 +08:00
}
// 手动记录
// $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1']
public function card_manual_recording ( $data = [ 'acd_id' => '2' , 'aud_id' => '11' , 'time' => '2024-04-11 10:10:10' , 'data' => [ 'height' => '175.1' , 'weight' => '77.1' ]]){
if ( ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'aud_id' , $data )){
return $this -> msg ( 10001 , '关键参数缺失' );
}
$afferent_data = [];
foreach ( $data as $key => $value ) {
if ( is_array ( $value )){
foreach ( $value as $k => $v ) {
$afferent_data [ $k ] = $v ;
}
} else {
$afferent_data [ $key ] = $value ;
}
}
if ( $data [ 'acd_id' ] == '2' ){
return $this -> set_user_body_data ( $data );
} else if ( $data [ 'acd_id' ] == '6' ){
2024-04-03 18:15:07 +08:00
}
}
2024-04-20 17:38:31 +08:00
// 获取记录信息列表
function get_card_record_data ( $data = [ 'acd_id' => '2' , 'aud_id' => '11' , 's_time' => '2024-04-01 10:10:10' , 'e_time' => '2024-04-12 10:10:10' ]){
if ( ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data )){
return $this -> msg ( 10001 , '关键参数缺失' );
}
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
if ( $data [ 'acd_id' ] == '2' ){
return $this -> get_body_record_data ( $data );
} else if ( $data [ 'acd_id' ] == '6' ){
2024-03-29 18:34:01 +08:00
2024-04-20 17:38:31 +08:00
}
}
2024-03-29 18:34:01 +08:00
2024-04-20 17:38:31 +08:00
// 数据对比
function card_data_contrast ( $data = [ 'acd_id' => '2' , 'aud_id' => '11' , 's_time' => '2024-04-01 10:10:10' , 'e_time' => '2024-04-12 10:10:10' ]){
if ( ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data )){
return $this -> msg ( 10001 , '关键参数缺失' );
}
if ( $data [ 'acd_id' ] == '2' ){
return $this -> body_data_contrast ( $data );
} else if ( $data [ 'acd_id' ] == '6' ){
}
}
################################################################身体数据卡片接口################################################################
################################################################身体数据卡片接口################################################################
2024-03-29 18:34:01 +08:00
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
// weight height muscle fat
// 查询曲线数据
public function body_curve_data ( $data = [ 'aud_id' => '11' , 'acd_id' => '2' , 'type' => 'weight' , 's_time' => '2024-04-01 10:10:10' , 'e_time' => '2024-04-11 10:10:10' ]){
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'acd_id' , $data ) || ! array_key_exists ( 'type' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data )){
return $this -> msg ( 10001 , '关键参数缺失' );
}
$user_data = Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'target_weight,initial_weight,initial_date' ) -> find ();
// dump($user_data);
if ( $user_data ){
if ( $user_data [ 'initial_date' ]){
$result_data [ 'target_weight' ] = $user_data [ 'target_weight' ] . 'kg' ;
$result_data [ 'initial_weight' ] = $user_data [ 'initial_weight' ] . 'kg' ;
$result_data [ 'initial_date' ] = $this -> daysSince ( $user_data [ 'initial_date' ]) . '天' ;
} else {
$result_data [ 'target_weight' ] = '' ;
$result_data [ 'initial_weight' ] = '' ;
$result_data [ 'initial_date' ] = '' ;
}
} else {
return $this -> msg ( 10002 , '未找到用户数据' );
}
$user_data_list = Db :: query ( " select record_time,weight,bmi,muscleval,fat_w from app_card_body_data where aud_id=' " . $data [ 'aud_id' ] . " 'and record_time between ' " . $data [ 's_time' ] . " ' and ' " . $data [ 'e_time' ] . " ' order by record_time desc " );
if ( in_array ( $data [ 'type' ], [ 'weight' , 'muscleval' , 'fat_w' , 'bmi' ])){
$data_arr = [];
foreach ( $user_data_list as $key => $value ) {
$data_arr [] = [ $value [ $data [ 'type' ]], $value [ 'record_time' ]];
}
}
// dump($result_data['target_weight']);
// dump($result_data['initial_weight']);
// die;
$cumulative_weight = $user_data [ 'target_weight' ] - $user_data [ 'initial_weight' ];
if ( $cumulative_weight >= 0 ){
$result_data [ 'cumulative_weight' ] = [ $cumulative_weight . 'kg' , '累计减重' ];
} else {
$result_data [ 'cumulative_weight' ] = [ abs ( $cumulative_weight ) . 'kg' , '累计增重' ];
}
// if($user_data){
// }
$result_data [ 'list' ] = $data_arr ;
return $this -> msg ( 0 , 'success' , $result_data );
}
// 获取身体数据记录信息列表
function get_body_record_data ( $data ){
$result = Db :: query ( "
select
id ,
CONVERT ( varchar ( 10 ), record_time , 120 ) AS r_t ,
CONVERT ( varchar ( 19 ), record_time , 120 ) AS record_time ,
height ,
weight ,
bmi
from app_card_body_data
where aud_id = '".$data[' aud_id ']."'
and record_time between '".$data[' s_time ']."' and '".$data[' e_time ']."'
order by record_time desc " );
$return_result = [];
foreach ( $result as $key => $value ) {
if ( array_key_exists ( $value [ 'r_t' ], $return_result )){
array_push ( $return_result [ $value [ 'r_t' ]], [ 'id' => $value [ 'id' ], 'height' => $value [ 'height' ], 'weight' => $value [ 'weight' ], 'bmi' => $value [ 'bmi' ]]);
} else {
$return_result [ $value [ 'r_t' ]] = [[ 'id' => $value [ 'id' ], 'height' => $value [ 'height' ], 'weight' => $value [ 'weight' ], 'bmi' => $value [ 'bmi' ]]];
}
}
dump ([ 'original' => $result , 'optimization' => $return_result ]);
die ;
return [ 'original' => $result , 'optimization' => $return_result ];
}
// 身体数据对比
function body_data_contrast ( $data = [ 'acd_id' => '2' , 'data' => [ 1 , 10 ]]){
$between_num = implode ( ',' , $data [ 'data' ]);
2024-04-20 18:13:06 +08:00
$calculate_arr = [];
2024-04-20 17:38:31 +08:00
$result = Db :: query ( "
select
acbd . id ,
acbd . height ,
acbd . weight ,
acbd . bmi ,
2024-04-20 18:13:06 +08:00
acbd . fat_w ,
acbd . record_time ,
REPLACE ( CONVERT ( varchar ( 10 ), acbd . record_time , 23 ), '-' , '/' ) AS b_time ,
2024-04-20 17:38:31 +08:00
aud . nickname ,
aud . gender ,
aud . birthday
from app_card_body_data as acbd
left join app_user_data as aud on acbd . aud_id = aud . id
where acbd . id in ( " . $between_num . " )
" );
2024-04-20 18:13:06 +08:00
if ( ! $result || count ( $result ) < 2 ){
return $this -> msg ( 10001 , '数据查询错误' );
}
foreach ( $data [ 'data' ] as $key => $value ) {
foreach ( $result as $k => $v ) {
if ( $value == $v [ 'id' ]){
array_push ( $calculate_arr , $v );
}
}
}
$return_data [ 'nickname' ] = $calculate_arr [ 0 ][ 'nickname' ];
if ( $calculate_arr [ 0 ][ 'gender' ] == 1 ){
$return_data [ 'gender' ] = '男' ;
} else if ( $calculate_arr [ 0 ][ 'gender' ] == 2 ) {
$return_data [ 'gender' ] = '女' ;
} else {
$return_data [ 'gender' ] = '保密' ;
}
// bcsub(,,20)
$return_data [ 'age' ] = $this -> calculate_age ( $calculate_arr [ 0 ][ 'birthday' ]);
$return_data [ 'time' ] = $this -> daysSince ( $calculate_arr [ 0 ][ 'record_time' ], $calculate_arr [ 1 ][ 'record_time' ]);
$return_data [ 'weight_loss' ] = bcsub ( $calculate_arr [ 1 ][ 'weight' ], $calculate_arr [ 0 ][ 'weight' ], 1 );
$return_data [ 'reduce_fat' ] = bcsub ( explode ( ',' , $calculate_arr [ 1 ][ 'fat_w' ])[ 0 ], explode ( ',' , $calculate_arr [ 0 ][ 'fat_w' ])[ 0 ], 2 );
$return_data [ 'between_time' ] = $calculate_arr [ 0 ][ 'b_time' ] . '-' . $calculate_arr [ 1 ][ 'b_time' ];
$return_data [ 'execl_data' ][ 'height' ] = [ '身高' , bcsub ( $calculate_arr [ 1 ][ 'height' ], $calculate_arr [ 0 ][ 'height' ], 1 ), $calculate_arr [ 0 ][ 'height' ], $calculate_arr [ 1 ][ 'height' ]];
$return_data [ 'execl_data' ][ 'weight' ] = [ '体重' , bcsub ( $calculate_arr [ 1 ][ 'weight' ], $calculate_arr [ 0 ][ 'weight' ], 1 ), $calculate_arr [ 0 ][ 'weight' ], $calculate_arr [ 1 ][ 'weight' ]];
$return_data [ 'execl_data' ][ 'bmi' ] = [ 'BMI' , bcsub ( $calculate_arr [ 1 ][ 'bmi' ], $calculate_arr [ 0 ][ 'bmi' ], 1 ), $calculate_arr [ 0 ][ 'bmi' ], $calculate_arr [ 1 ][ 'bmi' ]];
// dump($return_data);
// die;
return $this -> msg ( 0 , 'success' , $return_data );
2024-04-20 17:38:31 +08:00
}
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
################################################################身体数据卡片业务
// 用户身体数据卡片记录
function set_user_body_data ( $data ){
if ( ! array_key_exists ( 'time' , $data ) || ! array_key_exists ( 'height' , $data ) || ! array_key_exists ( 'weight' , $data )){
return $this -> msg ( 10001 , '数据格式错误' );
}
$user_data = Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'birthday,gender' ) -> find ();
$result_data [ 'height' ] = $data [ 'height' ];
$result_data [ 'weight' ] = $data [ 'weight' ];
$result_data [ 'age' ] = $this -> calculate_age ( $user_data [ 'birthday' ]);
$result_data [ 'gender' ] = $user_data [ 'gender' ];
$result_data [ 'adc' ] = array_key_exists ( 'impedance' , $data ) ? $data [ 'impedance' ] : 550 ;
$calculate_body_formula = new Calculatebody ();
$get_body_value = $calculate_body_formula -> calculate_body_data_result ( $result_data );
$set_user_data = Db :: table ( 'app_card_body_data' ) -> insert ([
'acd_id' => $data [ 'acd_id' ],
'aud_id' => $data [ 'aud_id' ],
'record_time' => $data [ 'time' ],
'create_time' => date ( 'Y-m-d H:i:s' ),
'last_update_time' => date ( 'Y-m-d H:i:s' ),
'age' => $get_body_value [ 'age' ],
'height' => $get_body_value [ '身高' ],
'weight' => $get_body_value [ '体重' ],
'bmi' => $get_body_value [ 'BMI' ],
'score' => $get_body_value [ '身体得分' ],
'fat_r' => implode ( ',' , $get_body_value [ '脂肪率' ]),
'fat_w' => implode ( ',' , $get_body_value [ '脂肪量' ]),
'muscle' => implode ( ',' , $get_body_value [ '肌肉率' ]),
'muscleval' => implode ( ',' , $get_body_value [ '肌肉量' ]),
'water' => implode ( ',' , $get_body_value [ '水分' ]),
'proteinval' => implode ( ',' , $get_body_value [ '蛋白量' ]),
'bone' => implode ( ',' , $get_body_value [ '骨重' ]),
'protein' => implode ( ',' , $get_body_value [ '蛋白率' ]),
'kcal' => implode ( ',' , $get_body_value [ '基础代谢' ]),
'visceral' => implode ( ',' , $get_body_value [ '内脏指数' ]),
'sfr' => implode ( ',' , $get_body_value [ '皮下脂肪' ]),
'body_level' => $get_body_value [ '肥胖等级' ],
'body_type' => $get_body_value [ '身体类型' ]
]);
if ( $set_user_data ){
// 返回简要数据
if ( $data [ 'type' ] == 1 ){
return $this -> msg ( 0 , 'success' ,[ 'acd_id' => 2 , 'height' => $get_body_value [ '身高' ] . 'CM' , 'weight' => $get_body_value [ '体重' ] . '公斤' , 'bmi' => $get_body_value [ 'BMI' ]]);
}
} else {
return $this -> msg ( 10002 , '数据存储失败' );
}
}
// 用户身体数据卡片获取
function get_user_body_data ( $data ){
$result = Db :: table ( 'app_card_body_data' )
-> alias ( 'acbd' )
-> join ( 'app_user_data aud' , 'acbd.aud_id = aud.id' , 'LEFT' )
-> where ([ 'acbd.id' => $data [ 'id' ]])
-> field ( 'acbd.*,aud.birthday,aud.gender' )
-> find ();
if ( ! $result ){
return $this -> msg ( 10002 , '未找到数据' );
} else {
$result_end = $this -> processing_return_data ( $result );
// dump($result_end);
// die;
return $this -> msg ( 0 , 'success' , $result_end );
}
}
// 返回数据处理
function processing_return_data ( $data ){
$result_end_data = [];
$month_num = $this -> calculateAgeInMonthsWithPrecision ( $data [ 'birthday' ]) * 100 ;
$gender_val = $data [ 'gender' ];
foreach ( $data as $key => $value ) {
if ( $key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday' ){
// 如果大于16岁( 成人)
if ( $data [ 'age' ] >= $this -> age_limit ){
$result_end_data [ $key ] = $this -> result_end_data_mould ;
if ( array_key_exists ( $key , $this -> unit_name )){
$result_end_data [ $key ][ 'name' ] = $this -> unit_name [ $key ];
}
if ( array_key_exists ( $key , $this -> unit_symbol )){
$result_end_data [ $key ][ 'unit' ] = $this -> unit_symbol [ $key ];
}
$result_end_data [ $key ][ 'value' ] = explode ( ',' , $value )[ 0 ];
if ( strpos ( $value , ',' )){
$result_end_data [ $key ][ 'standard' ] = explode ( ',' , $value )[ 1 ];
}
if ( array_key_exists ( $key , $this -> standard_color )){
$result_end_data [ $key ][ 'color' ] = $this -> standard_color [ $key ][ $result_end_data [ $key ][ 'standard' ]];
}
} else {
if ( array_key_exists ( $key , $this -> bhw_list )){
$result_end_data [ $key ] = $this -> result_end_data_mould ;
$result_end_data [ $key ][ 'list' ] = $this -> bhw_list [ $key ];
if ( array_key_exists ( $key , $this -> unit_name )){
$result_end_data [ $key ][ 'name' ] = $this -> unit_name [ $key ];
}
if ( array_key_exists ( $key , $this -> unit_symbol )){
$result_end_data [ $key ][ 'unit' ] = $this -> unit_symbol [ $key ];
}
$result_end_data [ $key ][ 'value' ] = explode ( ',' , $value )[ 0 ];
if ( strpos ( $value , ',' )){
$result_end_data [ $key ][ 'standard' ] = explode ( ',' , $value )[ 1 ];
}
if ( array_key_exists ( $key , $this -> standard_color )){
$result_end_data [ $key ][ 'color' ] = $this -> standard_color [ $key ][ $result_end_data [ $key ][ 'standard' ]];
}
if ( $key == 'bmi' ){
// dump($month_num);
$bhw_date = Db :: table ( 'pc_bmistand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
if ( $bhw_date ){
$result_end_data [ $key ][ 'list' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$result_end_data [ $key ][ 'list' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
}
} else if ( $key == 'height' ){
$bhw_date = Db :: table ( 'pc_heightstand2' ) -> where ( " month >= $month_num " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
if ( $bhw_date ){
$result_end_data [ $key ][ 'list' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 3 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$result_end_data [ $key ][ 'list' ][ 4 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$result_end_data [ $key ][ 'list' ][ 4 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z3sd' ];
}
} else if ( $key == 'weight' ){
$bhw_date = Db :: table ( 'pc_weightstand2' ) -> where ( " month >= $month_num " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
// dump($value);
// dump($bhw_date);/
if ( $bhw_date ){
$result_end_data [ $key ][ 'list' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$result_end_data [ $key ][ 'list' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$result_end_data [ $key ][ 'list' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$result_end_data [ $key ][ 'list' ][ 3 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$result_end_data [ $key ][ 'list' ][ 4 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$result_end_data [ $key ][ 'list' ][ 4 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z3sd' ];
}
}
}
}
}
}
return $result_end_data ;
}
2024-03-15 18:15:17 +08:00
################################################################other################################################################
################################################################other################################################################
################################################################other################################################################
2024-03-29 18:34:01 +08:00
// 检查变量是否是一个只有数字的一维数组
2024-04-20 17:38:31 +08:00
function isNumericArray ( $array = [ 1 , 2 , 3 ]) {
2024-03-29 18:34:01 +08:00
if ( ! is_array ( $array )) {
return false ; // 变量不是数组
2024-03-15 18:15:17 +08:00
}
2024-03-29 18:34:01 +08:00
foreach ( $array as $value ) {
if ( ! is_numeric ( $value )) {
return false ; // 数组中包含非数字元素
}
}
2024-04-20 17:38:31 +08:00
// $result = Db::table('app_card_data')->where(['is_del'=>1])->cache(true,3600)->column('id');//查询结果缓存3600秒
$result = Db :: table ( 'app_card_data' ) -> where ([ 'is_del' => 0 ]) -> cache ( true , 3600 ) -> select (); //查询结果缓存3600秒
// dump(array_column($result, 'id'));
// die;
if ( empty ( array_diff ( $array , array_column ( $result , 'id' )))){
2024-03-29 18:34:01 +08:00
return true ; // 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效
} else {
return false ; //跟数据库比对过,存在无效数值
}
}
2024-04-20 17:38:31 +08:00
// 计算年龄
function calculate_age ( $data = '1991-04-20' ){
$today = time (); // 获取当前时间的 Unix 时间戳
$birthDate = strtotime ( $data ); // 将出生日期字符串转换为 Unix 时间戳
if ( $birthDate !== false ) {
$age = date ( 'Y' , $today ) - date ( 'Y' , $birthDate );
// 如果当前年份的月份和日期小于出生年份的月份和日期,那么年龄减一
if ( date ( 'm-d' , $today ) < date ( 'm-d' , $birthDate )) {
$age -- ;
}
return $age ;
} else {
return false ;
}
}
// 计算天数
function daysSince ( $pastDate , $now = false )
{
// 创建一个表示过去日期的 DateTime 对象
$past = new \DateTime ( $pastDate );
if ( $now === false ){
// 创建一个表示当前日期的 DateTime 对象
$now = new \DateTime ();
} else {
$now = new \DateTime ( $now );
}
// 使用 DateTime::diff() 方法计算两个日期之间的差值
$interval = $past -> diff ( $now );
// 返回相差的天数
return $interval -> format ( '%a' );
}
// 计算月份
function calculateAgeInMonthsWithPrecision ( $birthDateStr ) {
// 获取当前日期
$now = new \DateTime ();
// 将出生日期字符串转换为 DateTime 对象
$birthDate = \DateTime :: createFromFormat ( 'Y-m-d' , $birthDateStr );
// 计算两者之间的差距(以月为单位,包含部分月份的小数)
$interval = $now -> diff ( $birthDate );
$ageInMonths = $interval -> y * 12 + $interval -> m ; // 年份乘以12加上月份
$remainingDays = $interval -> d ; // 当前月内的剩余天数
// 将剩余天数转换为小数月份( 假设一个月为30天, 进行近似计算)
$partialMonth = $remainingDays / 30 ;
// 结果精确到小数点后两位
$ageInMonthsPrecise = round ( $ageInMonths + $partialMonth , 2 );
return $ageInMonthsPrecise ;
}
// 计算肌肉率 删
function calculate_jiroulv (){
phpinfo ();
die ;
$result = $result = Db :: table ( 'pc_weightstand' ) -> order ( 'Month' ) -> select ();
for ( $i = 0 ; $i < count ( $result ); $i ++ ) {
$data [ $i ][ 'month' ] = $result [ $i ][ 'Month' ] * 100 / 100 ;
$data [ $i ][ 'sex' ] = $result [ $i ][ 'Sex' ];
$data [ $i ][ 'f3sd' ] = $result [ $i ][ 'f1sd' ] * 100 / 100 ;
$data [ $i ][ 'f2sd' ] = $result [ $i ][ 'f1sd' ] * 100 / 100 ;
$data [ $i ][ 'f1sd' ] = $result [ $i ][ 'f1sd' ] * 100 / 100 ;
$data [ $i ][ 'median' ] = $result [ $i ][ 'median' ] * 100 / 100 ;
$data [ $i ][ 'z1sd' ] = $result [ $i ][ 'z1sd' ] * 100 / 100 ;
$data [ $i ][ 'z2sd' ] = $result [ $i ][ 'z2sd' ] * 100 / 100 ;
$data [ $i ][ 'z3sd' ] = $result [ $i ][ 'z3sd' ] * 100 / 100 ;
$data [ $i ][ 'isdel' ] = $result [ $i ][ 'IsDeleted' ];
$data [ $i ][ 'create_time' ] = date ( 'Y-m-d H:i:s' );
}
$result = $result = Db :: table ( 'pc_weightstand2' ) -> insertAll ( $data );
dump ( $result );
dump ( $data );
die ;
}
// 计算骨重
function calculate_guzhong (){
}
// 计算蛋白率
function calculate_danbailv (){
}
// 计算基础代谢
function calculate_jichudaixie (){
}
// 计算内脏指数
function calculate_neizangzhishu (){
}
// 计算皮下脂肪
function calculate_pixiazhifang (){
}
// 计算肥胖等级
function calculate_feipangdengji (){
}
2024-03-15 18:15:17 +08:00
public function msg ( $code , $msg = '' , $data = []){
return json ([ 'code' => $code , 'msg' => $msg , 'data' => $data ]);
}
}