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-04-29 16:42:30 +08:00
use app\app\controller\Skip ;
2024-03-15 18:15:17 +08:00
2024-04-22 17:29:33 +08:00
class Card extends Base {
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
protected $color = [ '#FF5656' , '#FFAB00' , '#5AD06D' , '#6492F6' , '#3967D6' ];
2024-05-23 18:49:55 +08:00
// protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data'];
// protected $db_content = [
// '2'=>'height as v1,weight as v2,bmi as v3',
// '6'=>'jump_num as v1,jump_time as v2,jump_kcal as v3'
// ];
2024-04-20 17:38:31 +08:00
protected $age_limit = 16 ;
2024-05-23 18:49:55 +08:00
protected $unit_symbol = [ 'score' => '分' , 'height' => 'CM' , 'weight' => '公斤' , 'bmi' => '' , 'fat_r' => '%' , 'fat_w' => 'kg' , 'muscle' => '%' , 'muscleval' => 'kg' , 'water' => 'kg' , 'bone' => 'kg' , 'protein' => '%' , 'proteinval' => 'kg' , 'kcal' => 'kcal' , 'visceral' => '' , 'sfr' => '%' ,];
2024-04-20 17:38:31 +08:00
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-05-22 18:36:27 +08:00
protected $card_body_curve_arr = [ 'weight' , 'bmi' , 'muscle' , 'fat_r' ];
protected $card_body_curve_arr2 = [ '体重' , 'BMI' , '肌肉率' , '脂肪率' ];
protected $card_body_curve_arr3 = [ '#fb7b92' , '#6bb0fe' , '#ff9f40' , '#3fcba7' ];
2024-05-23 18:49:55 +08:00
2024-03-15 18:15:17 +08:00
2024-03-29 18:34:01 +08:00
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
// 详细卡片信息
// $data = ['id'=>'2']
2024-05-23 18:49:55 +08:00
public function card_data_detailed ( $data = [ 'aud_id' => '25' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
2024-05-20 18:49:27 +08:00
}
2024-05-21 18:43:56 +08:00
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
2024-05-20 18:49:27 +08:00
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
2024-05-21 18:43:56 +08:00
return $this -> msg ( 20001 );
2024-05-20 18:49:27 +08:00
}
unset ( $data [ 'token' ]);
return $this -> get_user_body_data ( $data );
2024-04-03 18:15:07 +08:00
2024-04-20 17:38:31 +08:00
}
2024-05-21 18:43:56 +08:00
// 曲线页面-曲线接口
2024-05-22 18:36:27 +08:00
public function card_curve_chart ( $data = [ 'aud_id' => '25' , 's_time' => '2024-04-01 10:10:10' , 'e_time' => '2024-07-30 10:10:10' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
2024-05-21 18:43:56 +08:00
}
2024-05-22 18:36:27 +08:00
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 's_time' , $data ) || ! array_key_exists ( 'e_time' , $data ) || ! array_key_exists ( 'token' , $data )){
2024-05-21 18:43:56 +08:00
return $this -> msg ( 10001 );
}
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
return $this -> msg ( 20001 );
}
unset ( $data [ 'token' ]);
return $this -> curve_chart_action ( $data );
}
2024-05-22 18:36:27 +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']
2024-05-22 18:36:27 +08:00
public function card_manual_recording ( $data = [ 'aud_id' => '25' , 'time' => '2024-04-11 10:10:15' , 'height' => '165.3' , 'weight' => '66.1' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
2024-04-20 17:38:31 +08:00
}
2024-05-21 18:43:56 +08:00
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'time' , $data ) || ! array_key_exists ( 'height' , $data ) || ! array_key_exists ( 'weight' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
2024-05-20 18:49:27 +08:00
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
2024-05-21 18:43:56 +08:00
return $this -> msg ( 20001 );
2024-04-20 17:38:31 +08:00
}
2024-05-20 18:49:27 +08:00
unset ( $data [ 'token' ]);
$data [ 'acd_id' ] = '2' ;
return $this -> set_user_body_data ( $data );
2024-04-03 18:15:07 +08:00
}
2024-05-22 21:37:39 +08:00
// 修改初始体重/目标体重
2024-05-23 18:49:55 +08:00
public function card_modify_weight ( $data = [ 'aud_id' => '25' , 'weight' => '25' , 'type' => 1 , 'time' => '' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
}
2024-05-23 18:49:55 +08:00
if ( ! is_array ( $data )){
return $this -> msg ( 10005 );
}
if ( ! array_key_exists ( 'aud_id' , $data ) || ! array_key_exists ( 'weight' , $data ) || ! array_key_exists ( 'type' , $data ) || ! array_key_exists ( 'time' , $data ) || ! array_key_exists ( 'token' , $data )){
2024-05-22 21:37:39 +08:00
return $this -> msg ( 10001 );
}
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
return $this -> msg ( 20001 );
}
unset ( $data [ 'token' ]);
return $this -> modify_weight_action ( $data );
}
2024-05-23 18:49:55 +08:00
// // 获取记录信息列表
// public function get_card_record_data_group($data = ['aud_id'=>'25','s_time'=>'2024-04-01 10:10:10','e_time'=>'2024-06-12 10:10:10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
// 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('token', $data)){
// return $this->msg(10001);
// }
// if($this->token_time_validate($data['token']) === false){
// return $this->msg(20001);
// }
// unset($data['token']);
// $data['acd_id'] = '2';
// return $this->get_all_record_data($data,'group');
2024-05-21 18:43:56 +08:00
2024-05-23 18:49:55 +08:00
// }
// // 获取记录信息列表
// public function get_card_record_data_page($data = ['aud_id'=>'25','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){
// if(count(input('post.')) > 0){
// $data = input('post.');
// }
2024-05-20 18:49:27 +08:00
2024-05-23 18:49:55 +08:00
// if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data)){
// return $this->msg(10001);
// }
// if($this->token_time_validate($data['token']) === false){
// return $this->msg(20001);
// }
// unset($data['token']);
// $data['acd_id'] = '2';
// return $this->get_all_record_data($data,'page');
// }
2024-05-21 18:43:56 +08:00
// 删除历史数据
public function card_del_record_data ( $data = [ 'id' => '16' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
2024-05-21 18:43:56 +08:00
}
if ( ! array_key_exists ( 'id' , $data ) || ! array_key_exists ( 'token' , $data )){
return $this -> msg ( 10001 );
}
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
return $this -> msg ( 20001 );
}
unset ( $data [ 'token' ]);
$user_data = Db :: table ( 'app_card_body_data' ) -> where ([ 'id' => $data [ 'id' ]]) -> update ([ 'is_del' => 1 ]);
if ( $user_data ){
return $this -> msg ([]);
} else {
return $this -> msg ( 10002 );
}
}
2024-03-29 18:34:01 +08:00
2024-04-20 17:38:31 +08:00
// 数据对比
2024-05-23 18:49:55 +08:00
public function card_data_contrast ( $data = [ 'before_id' => '24' , 'after_id' => '25' , 'token' => '0dafb98a10995c98b5a33b7d59d986ca' ]){
2024-05-22 21:37:39 +08:00
if ( count ( input ( 'post.' )) > 0 ){
$data = input ( 'post.' );
2024-05-21 18:43:56 +08:00
}
2024-05-23 18:49:55 +08:00
if ( ! array_key_exists ( 'before_id' , $data ) || ! array_key_exists ( 'after_id' , $data ) || ! array_key_exists ( 'token' , $data )){
2024-05-21 18:43:56 +08:00
return $this -> msg ( 10001 );
}
if ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
return $this -> msg ( 20001 );
2024-04-20 17:38:31 +08:00
}
2024-05-21 18:43:56 +08:00
unset ( $data [ 'token' ]);
2024-05-22 22:11:10 +08:00
// $data = explode(',',$data['id_arr']);
// dump($data);
// die;
return $this -> body_data_contrast ( $data );
2024-04-20 17:38:31 +08:00
}
2024-05-22 18:36:27 +08:00
################################################################业务接口################################################################
################################################################业务接口################################################################
2024-04-20 17:38:31 +08:00
2024-05-22 18:36:27 +08:00
################################################card_data_detailed
2024-04-20 17:38:31 +08:00
// 用户身体数据卡片获取
2024-05-22 18:36:27 +08:00
public function get_user_body_data ( $data ){
2024-05-23 18:49:55 +08:00
// $result = Db::table('app_card_body_data')
// ->alias('acbd')
// ->join('app_user_data aud','acbd.aud_id = aud.id','LEFT')
// ->where(['acbd.aud_id'=>$data['aud_id']])
// ->order('acbd.record_time desc')
// ->field('acbd.*,aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date')
// ->find();
// dump($data);
$result = Db :: query ( "
select
Top 1
acbd .* , aud . birthday , aud . gender , aud . target_weight , aud . initial_weight , aud . initial_date
from app_card_body_data as acbd
left join app_user_data as aud on acbd . aud_id = aud . id
where acbd . aud_id = '".$data[' aud_id ']."'
order by acbd . record_time desc
" );
// dump($result);
// die;
2024-04-20 17:38:31 +08:00
if ( ! $result ){
2024-05-22 18:36:27 +08:00
return $this -> msg ( 10004 );
2024-04-20 17:38:31 +08:00
} else {
2024-05-22 18:36:27 +08:00
// $curve_bottom = $this->card_curve_target_action($result);
2024-05-23 18:49:55 +08:00
$result_end = $this -> processing_return_data_new ( $result [ 0 ]);
2024-05-21 18:43:56 +08:00
return $this -> msg ( $result_end );
2024-04-20 17:38:31 +08:00
}
}
// 返回数据处理
2024-05-21 18:43:56 +08:00
public function processing_return_data_new ( $data ){
// dump($data);
2024-04-20 17:38:31 +08:00
$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' ){
2024-05-20 18:49:27 +08:00
// 设置单个数据格式
$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' ]];
}
2024-05-21 18:43:56 +08:00
// 如果小于16岁( 儿童)
2024-05-20 18:49:27 +08:00
if ( $data [ 'age' ] < $this -> age_limit ){
2024-04-20 17:38:31 +08:00
if ( array_key_exists ( $key , $this -> bhw_list )){
$result_end_data [ $key ][ 'list' ] = $this -> bhw_list [ $key ];
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 ();
2024-05-20 18:49:27 +08:00
// dump($bhw_date);
2024-04-20 17:38:31 +08:00
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' ){
2024-05-21 18:43:56 +08:00
$bhw_date = Db :: table ( 'pc_heightstand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
2024-04-20 17:38:31 +08:00
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' ){
2024-05-21 18:43:56 +08:00
$bhw_date = Db :: table ( 'pc_weightstand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
2024-04-20 17:38:31 +08:00
// 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' ];
}
}
}
}
}
}
2024-05-21 18:43:56 +08:00
// dump($data['age']);
// dump($result_end_data);
// die;
2024-04-20 17:38:31 +08:00
return $result_end_data ;
}
2024-05-21 18:43:56 +08:00
2024-05-22 18:36:27 +08:00
########################################################card_curve_chart
// 曲线图动作函数
public function curve_chart_action ( $data ){
$card_body_curve_arr = implode ( ',' , $this -> card_body_curve_arr );
2024-05-23 18:49:55 +08:00
// $user_data_list = Db::query("
// select
// record_time,
// $card_body_curve_arr
// 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
// ");
$user_data_list = Db :: table ( 'app_card_body_data' )
-> where ( 'aud_id' , $data [ 'aud_id' ])
-> whereTime ( 'record_time' , 'between' , [ $data [ 's_time' ], $data [ 'e_time' ]])
-> field ( " record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '/') AS b_time, $card_body_curve_arr " )
-> order ( 'record_time desc' )
-> select ();
2024-05-22 18:36:27 +08:00
$data_arr = [];
2024-05-23 18:49:55 +08:00
$record_arr1 = [];
$record_arr2 = [];
2024-05-22 18:36:27 +08:00
if ( count ( $user_data_list ) > 0 ){
2024-05-23 18:49:55 +08:00
foreach ( $user_data_list as $key => $value ) {
if ( ! in_array ( $value [ 'b_time' ], $record_arr1 )){
array_push ( $record_arr1 , $value [ 'b_time' ]);
$user_data_list [ $key ][ 'muscle' ] = explode ( ',' , $user_data_list [ $key ][ 'muscle' ])[ 0 ];
$user_data_list [ $key ][ 'fat_r' ] = explode ( ',' , $user_data_list [ $key ][ 'fat_r' ])[ 0 ];
array_push ( $record_arr2 , $user_data_list [ $key ]);
}
}
2024-05-22 18:36:27 +08:00
foreach ( $this -> card_body_curve_arr as $key => $value ) {
$temporary_arr = [];
$temporary_arr [ 'title' ] = $this -> card_body_curve_arr2 [ $key ];
$temporary_arr [ 'key' ] = $value ;
$temporary_arr [ 'line' ][ 'categories' ] = [];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'color' ] = $this -> card_body_curve_arr3 [ $key ];
$temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ] = [];
2024-05-23 18:49:55 +08:00
foreach ( $record_arr2 as $k => $v ) {
array_push ( $temporary_arr [ 'line' ][ 'categories' ], $record_arr2 [ $k ][ 'b_time' ]);
array_push ( $temporary_arr [ 'line' ][ 'series' ][ 0 ][ 'data' ], $record_arr2 [ $k ][ $value ]);
2024-05-22 18:36:27 +08:00
}
array_push ( $data_arr , $temporary_arr );
}
}
return $this -> msg ( $data_arr );
}
################################################card_manual_recording
// 用户身体数据卡片记录
public function set_user_body_data ( $data ){
$data [ 'type' ] = 1 ;
2024-05-22 21:37:39 +08:00
$user_data = Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> field ( 'birthday,gender,target_weight,initial_weight,initial_date' ) -> find ();
2024-05-22 18:36:27 +08:00
if ( ! $user_data ){
return $this -> msg ( 10003 );
}
2024-05-22 21:37:39 +08:00
if ( $user_data [ 'initial_date' ] == null ){
Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> update ([ 'initial_weight' => $data [ 'weight' ], 'initial_date' => $data [ 'time' ]]);
$target_current = $this -> base_target_initial_cumulative_weight ([
'weight' => $data [ 'weight' ],
'target_weight' => $user_data [ 'target_weight' ],
'initial_weight' => $data [ 'weight' ],
'initial_date' => $data [ 'time' ],
]);
} else {
$target_current = $this -> base_target_initial_cumulative_weight ([
'weight' => $data [ 'weight' ],
'target_weight' => $user_data [ 'target_weight' ],
'initial_weight' => $user_data [ 'initial_weight' ],
'initial_date' => $user_data [ 'initial_date' ],
]);
}
2024-05-22 18:36:27 +08:00
$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 );
$get_body_value [ 'gender' ] = $user_data [ 'gender' ];
$get_body_value [ 'birthday' ] = $user_data [ 'birthday' ];
$get_body_value = $this -> hwb_standard ( $get_body_value );
// dump($get_body_value);
// dump($get_body_value['脂肪率']);
// dump(implode(',',$get_body_value['脂肪率']));
// die;
$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 [ '身高' ],
'height_data' => $get_body_value [ '身高2' ],
'weight' => $get_body_value [ '体重' ],
'weight_data' => $get_body_value [ '体重2' ],
'bmi' => $get_body_value [ 'BMI' ],
'bmi_data' => $get_body_value [ 'BMI2' ],
'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 ){
2024-05-22 21:37:39 +08:00
return $this -> msg ([
'acd_id' => 2 ,
'height' => $get_body_value [ '身高' ] . ',CM' ,
'weight' => $get_body_value [ '体重' ] . ',公斤' ,
'bmi' => $get_body_value [ 'BMI' ],
'target_current' => $target_current ,
]);
2024-05-22 18:36:27 +08:00
}
} else {
return $this -> msg ( 10002 );
}
}
2024-05-21 18:43:56 +08:00
// 添加身高体重bmi的标准
public function hwb_standard ( $data ){
$linshi_data = [];
$month_num = $this -> calculateAgeInMonthsWithPrecision ( $data [ 'birthday' ]) * 100 ;
$gender_val = $data [ 'gender' ];
if ( $data [ 'age' ] < $this -> age_limit ){
foreach ( $data as $key => $value ) {
if ( $key == '身高' ){
$linshi_data [ '身高' ] = $this -> bhw_list [ 'height' ];
$bhw_date = Db :: table ( 'pc_heightstand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
if ( $bhw_date ){
$linshi_data [ '身高' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$linshi_data [ '身高' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$linshi_data [ '身高' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ '身高' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ '身高' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ '身高' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ '身高' ][ 3 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$linshi_data [ '身高' ][ 4 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$linshi_data [ '身高' ][ 4 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z3sd' ];
}
} else if ( $key == '体重' ){
$linshi_data [ '体重' ] = $this -> bhw_list [ 'weight' ];
$bhw_date = Db :: table ( 'pc_weightstand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
if ( $bhw_date ){
$linshi_data [ '体重' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$linshi_data [ '体重' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f2sd' ];
$linshi_data [ '体重' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ '体重' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ '体重' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ '体重' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ '体重' ][ 3 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$linshi_data [ '体重' ][ 4 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$linshi_data [ '体重' ][ 4 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z3sd' ];
}
} else if ( $key == 'BMI' ){
$linshi_data [ 'BMI' ] = $this -> bhw_list [ 'bmi' ];
$bhw_date = Db :: table ( 'pc_bmistand2' ) -> where ( " month >= $month_num and sex = ' $gender_val ' " ) -> order ( 'month' ) -> limit ( 1 ) -> select ();
// dump($bhw_date);
if ( $bhw_date ){
$linshi_data [ 'BMI' ][ 0 ][ 'max_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ 'BMI' ][ 1 ][ 'min_val' ] = $bhw_date [ 0 ][ 'f1sd' ];
$linshi_data [ 'BMI' ][ 1 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ 'BMI' ][ 2 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z1sd' ];
$linshi_data [ 'BMI' ][ 2 ][ 'max_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
$linshi_data [ 'BMI' ][ 3 ][ 'min_val' ] = $bhw_date [ 0 ][ 'z2sd' ];
}
}
}
2024-05-22 18:36:27 +08:00
// dump($linshi_data);
// die;
2024-05-21 18:43:56 +08:00
foreach ( $linshi_data as $key => $value ) {
2024-05-22 18:36:27 +08:00
// dump($value);
2024-05-21 18:43:56 +08:00
foreach ( $value as $k => $v ) {
2024-05-22 18:36:27 +08:00
if ( $data [ $key ] >= $v [ 'min_val' ] && $data [ $key ] < $v [ 'max_val' ]){
// 如果落在区间内
2024-05-21 18:43:56 +08:00
$data [ $key . '2' ] = $data [ $key ] . ',' . $v [ 'text' ] . ',' . $v [ 'color' ];
}
2024-05-22 18:36:27 +08:00
}
if ( $data [ $key ] < $value [ 0 ][ 'min_val' ]){
// 如果小于最小值
$data [ $key . '2' ] = $data [ $key ] . ',' . $value [ 0 ][ 'text' ] . ',' . $value [ 0 ][ 'color' ];
} else if ( $data [ $key ] >= $value [ count ( $value ) - 1 ][ 'max_val' ]){
// 如果大于最大值
$data [ $key . '2' ] = $data [ $key ] . ',' . $value [ count ( $value ) - 1 ][ 'text' ] . ',' . $value [ count ( $value ) - 1 ][ 'color' ];
2024-05-21 18:43:56 +08:00
}
}
2024-05-22 18:36:27 +08:00
// die;
2024-05-21 18:43:56 +08:00
} else {
$data [ '身高2' ] = $data [ '身高' ] . ',无,无' ;
$data [ '体重2' ] = $data [ '身高' ] . ',无,无' ;
$data [ 'BMI2' ] = $data [ '身高' ] . ',无,无' ;
}
// dump($data);
return $data ;
// dump($data);
}
2024-05-22 21:37:39 +08:00
################################################card_modify_weight
public function modify_weight_action ( $data ){
2024-05-23 18:49:55 +08:00
// $data['aud_id'] = 26;
// $data['weight'] = 60;
// dump($data);
// die;
2024-05-22 21:37:39 +08:00
$result = Db :: query ( "
select
TOP 1
acbd . weight ,
aud . target_weight ,
aud . initial_weight ,
aud . initial_date
from app_card_body_data as acbd
left join app_user_data as aud on acbd . aud_id = aud . id
where acbd . aud_id = " . $data['aud_id'] . "
order by acbd . record_time desc
" );
if ( $data [ 'type' ] == 1 ){
// 修改目标体重
2024-05-23 18:49:55 +08:00
$bhw_date = [ 'target_weight' => $data [ 'weight' ]];
2024-05-22 21:37:39 +08:00
} else if ( $data [ 'type' ] == 2 ){
// 修改原始体重
2024-05-23 18:49:55 +08:00
$bhw_date = [ 'initial_weight' => $data [ 'weight' ], 'initial_date' => $data [ 'time' ]];
} else {
return $this -> msg ( 10005 );
2024-05-22 21:37:39 +08:00
}
$result_update = Db :: table ( 'app_user_data' ) -> where ([ 'id' => $data [ 'aud_id' ]]) -> update ( $bhw_date );
2024-05-23 18:49:55 +08:00
// dump($result_update);
// dump($result[0]['weight']);
// dump($result);
2024-05-22 21:37:39 +08:00
if ( $result_update ){
$target_current = $this -> base_target_initial_cumulative_weight ([
2024-05-23 18:49:55 +08:00
'weight' => $result [ 0 ][ 'weight' ],
'target_weight' => $data [ 'type' ] == 1 ? $data [ 'weight' ] : $result [ 0 ][ 'target_weight' ],
'initial_weight' => $data [ 'type' ] == 1 ? $result [ 0 ][ 'initial_weight' ] : $data [ 'weight' ],
'initial_date' => $data [ 'type' ] == 1 ? $result [ 0 ][ 'initial_date' ] : $data [ 'time' ],
2024-05-22 21:37:39 +08:00
]);
2024-05-23 18:49:55 +08:00
// die;
// dump($target_current);
2024-05-22 21:37:39 +08:00
return $this -> msg ( $target_current );
} else {
return $this -> msg ( 10002 );
}
}
2024-05-22 18:36:27 +08:00
################################################get_card_record_data
// 获取历史数据记录信息列表
2024-05-23 18:49:55 +08:00
// public function get_all_record_data($data,$type){
// $return_result = [];
// if($type == 'group'){
// $result = Db::query("
// select
// id,
// CONVERT(varchar(10), record_time, 120) AS r_t,
// CONVERT(varchar(19), record_time, 120) AS record_time,
// height as v1,
// weight as v2,
// bmi as v3
// from app_card_body_data
// 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) {
// if(array_key_exists($value['r_t'], $return_result)){
// array_push($return_result[$value['r_t']], ['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']);
// }else{
// $return_result[$value['r_t']] = [['id'=>$value['id'],'v1'=>$value['v1'],'v2'=>$value['v2'],'v3'=>$value['v3'],'v1_name'=>'身高','v2_name'=>'体重','v3_name'=>'BMI']];
// }
// }
// }else{
// $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->field('id,record_time,height,weight,bmi')->order('record_time desc')->page($data['page'],$this->pagesize)->select();
// $return_result['totalrows'] = Db::table('app_card_body_data')->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_name'=>'身高',
// 'v1'=>$value['height'],
// 'v2_name'=>'体重',
// 'v2'=>$value['weight'],
// 'v3_name'=>'BMI',
// 'v3'=>$value['bmi'],
// ]);
// }
// }
// return $this->msg($return_result);
// }
2024-05-22 18:36:27 +08:00
2024-04-20 17:38:31 +08:00
2024-05-22 18:36:27 +08:00
################################################################其他接口################################################################
################################################################其他接口################################################################
2024-03-15 18:15:17 +08:00
2024-05-22 18:36:27 +08:00
// 身体数据对比
2024-05-22 22:11:10 +08:00
public function body_data_contrast ( $data ){
2024-05-23 18:49:55 +08:00
// dump($data);
$data2 = [ $data [ 'before_id' ], $data [ 'after_id' ]];
$data3 = implode ( ',' , $data2 );
2024-05-22 22:11:10 +08:00
// dump($data2);
// die;
2024-05-22 18:36:27 +08:00
$calculate_arr = [];
$result = Db :: query ( "
select
acbd . id ,
2024-05-23 18:49:55 +08:00
acbd . height_data as height ,
acbd . weight_data as weight ,
acbd . bmi_data as bmi ,
acbd . fat_r ,
2024-05-22 18:36:27 +08:00
acbd . fat_w ,
2024-05-23 18:49:55 +08:00
acbd . muscle ,
acbd . muscleval ,
acbd . water ,
acbd . proteinval ,
acbd . bone ,
acbd . protein ,
acbd . kcal ,
acbd . visceral ,
acbd . sfr ,
2024-05-22 18:36:27 +08:00
acbd . record_time ,
REPLACE ( CONVERT ( varchar ( 10 ), acbd . record_time , 23 ), '-' , '/' ) AS b_time ,
aud . nickname ,
aud . gender ,
2024-05-23 18:49:55 +08:00
aud . birthday ,
aud . head_pic
2024-05-22 18:36:27 +08:00
from app_card_body_data as acbd
left join app_user_data as aud on acbd . aud_id = aud . id
2024-05-23 18:49:55 +08:00
where acbd . id in ( $data3 )
2024-05-22 18:36:27 +08:00
" );
2024-05-23 18:49:55 +08:00
// dump($result);
// die;
2024-05-22 18:36:27 +08:00
if ( ! $result || count ( $result ) < 2 ){
2024-05-22 22:11:10 +08:00
return $this -> msg ( 10004 );
2024-05-22 18:36:27 +08:00
}
2024-05-23 18:49:55 +08:00
// 调整顺序
foreach ( $result as $key => $value ) {
if ( $value [ 'id' ] == $data2 [ 0 ]){
$calculate_arr [ 'before' ] = $value ;
} else {
$calculate_arr [ 'after' ] = $value ;
2024-05-22 18:36:27 +08:00
}
}
2024-05-23 18:49:55 +08:00
// dump($calculate_arr);
// die;
2024-05-22 18:36:27 +08:00
2024-05-23 18:49:55 +08:00
$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 , [ 'height' , 'weight' , 'bmi' , 'fat_r' , 'fat_w' , 'muscle' , 'muscleval' , 'water' , 'proteinval' , 'bone' , 'protein' , 'kcal' , 'visceral' , 'sfr' ])){
$before_arr = explode ( ',' , $value );
$after_arr = explode ( ',' , $calculate_arr [ 'after' ][ $key ]);
// $calculate_arr['before'][$key] = explode(',', $value);
array_push ( $return_data [ 'list' ], [
'firstresult' => [
'color' => '' ,
'level' => $before_arr [ 1 ],
'value' => $before_arr [ 0 ],
'title' => $this -> unit_name [ $key ],
'unit' => $this -> unit_symbol [ $key ],
'name' => $key ,
],
'secondresult' => [
'color' => '' ,
'level' => $after_arr [ 1 ],
'value' => $after_arr [ 0 ],
'title' => $this -> unit_name [ $key ],
'unit' => $this -> unit_symbol [ $key ],
'name' => $key ,
],
'diffval' => $before_arr [ 0 ] - $after_arr [ 0 ],
]);
}
}
2024-05-22 22:11:10 +08:00
2024-05-22 18:36:27 +08:00
// dump($return_data);
// die;
return $this -> msg ( $return_data );
}
2024-03-15 18:15:17 +08:00
2024-04-20 17:38:31 +08:00
2024-03-15 18:15:17 +08:00
}