From 9ea7afeb292781f7c29f7ef4e66a53dca084a393 Mon Sep 17 00:00:00 2001 From: tsf <460834639@qq.com> Date: Fri, 24 May 2024 10:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=950524?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/app/controller/Base.php | 12 +- application/app/controller/Calculatebody.php | 10 +- application/app/controller/Card.php | 23 +- application/app/controller/Cardparts.php | 85 +++++-- application/app/controller/Index.php | 51 ++-- application/app/controller/Skip.php | 239 +++++++++++-------- application/route.php | 14 +- 7 files changed, 270 insertions(+), 164 deletions(-) diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index e31ae53..20e3b2a 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -10,7 +10,7 @@ use think\Log; class Base extends Controller{ protected $base_call_method = ['内部']; - protected $token_time = 86400*1; + protected $token_time = 86400*3; protected $return_data_all = [ // '0' => ['success',[]], '10001'=>'关键参数缺失', @@ -65,7 +65,14 @@ class Base extends Controller{ }else{ return false;//跟数据库比对过,存在无效数值 } - + } + public function validate_user_identity($data) { + $validate_user = Db::table('app_user_data')->where(['id'=>$data])->count(); + if($validate_user<=0){ + return false; + }else{ + return true; + } } // 判断字符串是手机还是邮箱 public function is_tel_email($str) { @@ -116,6 +123,7 @@ class Base extends Controller{ return false; } $diff_time = time() - $time; + // dump($diff_time); if($diff_time > $this->token_time){ return false; } diff --git a/application/app/controller/Calculatebody.php b/application/app/controller/Calculatebody.php index 62e8709..b9cb4ba 100644 --- a/application/app/controller/Calculatebody.php +++ b/application/app/controller/Calculatebody.php @@ -51,17 +51,17 @@ class Calculatebody extends Controller{ $return_data['脂肪量'][0] = $result['fat_w']; - $return_data['脂肪率'][0] = $result['sfr']; - if(($data['gender']==1 && $data['age']<30 && $result['sfr']<10) || ($data['gender']==1 && $data['age']>=30 && $result['sfr']<11) || ($data['gender']==2 && $data['age']<30 && $result['sfr']<20) || ($data['gender']==2 && $data['age']>=30 && $result['sfr']<21)){ + $return_data['脂肪率'][0] = $result['fat_r']; + if(($data['gender']==1 && $data['age']<30 && $result['fat_r']<10) || ($data['gender']==1 && $data['age']>=30 && $result['fat_r']<11) || ($data['gender']==2 && $data['age']<30 && $result['fat_r']<20) || ($data['gender']==2 && $data['age']>=30 && $result['fat_r']<21)){ $return_data['脂肪率'][1] = '偏低'; $return_data['脂肪量'][1] = '偏低'; - }else if(($data['gender']==1 && $data['age']<30 && $result['sfr']>=10 && $result['sfr']<21) || ($data['gender']==1 && $data['age']>=30 && $result['sfr']>=11 && $result['sfr']<22) || ($data['gender']==2 && $data['age']<30 && $result['sfr']>=20 && $result['sfr']<31) || ($data['gender']==2 && $data['age']>=30 && $result['sfr']>=21 && $result['sfr']<32)){ + }else if(($data['gender']==1 && $data['age']<30 && $result['fat_r']>=10 && $result['fat_r']<21) || ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=11 && $result['fat_r']<22) || ($data['gender']==2 && $data['age']<30 && $result['fat_r']>=20 && $result['fat_r']<31) || ($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=21 && $result['fat_r']<32)){ $return_data['脂肪率'][1] = '标准'; $return_data['脂肪量'][1] = '标准'; - }else if(($data['gender']==1 && $data['age']<30 && $result['sfr']>=21 && $result['sfr']<26) || ($data['gender']==1 && $data['age']>=30 && $result['sfr']>=22 && $result['sfr']<27) || ($data['gender']==2 && $data['age']<30 && $result['sfr']>=31 && $result['sfr']<38) || ($data['gender']==2 && $data['age']>=30 && $result['sfr']>=32 && $result['sfr']<39)){ + }else if(($data['gender']==1 && $data['age']<30 && $result['fat_r']>=21 && $result['fat_r']<26) || ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=22 && $result['fat_r']<27) || ($data['gender']==2 && $data['age']<30 && $result['fat_r']>=31 && $result['fat_r']<38) || ($data['gender']==2 && $data['age']>=30 && $result['fat_r']>=32 && $result['fat_r']<39)){ $return_data['脂肪率'][1] = '偏高'; $return_data['脂肪量'][1] = '偏高'; - }else if(($data['gender']==1 && $data['age']<30 && $result['sfr']>=26) || ($data['gender']==1 && $data['age']>=30 && $result['sfr']>=27) || ($data['gender']==2 && $data['age']<30 && $result['sfr']<38) || ($data['gender']==2 && $data['age']>=30 && $result['sfr']<39)){ + }else if(($data['gender']==1 && $data['age']<30 && $result['fat_r']>=26) || ($data['gender']==1 && $data['age']>=30 && $result['fat_r']>=27) || ($data['gender']==2 && $data['age']<30 && $result['fat_r']<38) || ($data['gender']==2 && $data['age']>=30 && $result['fat_r']<39)){ $return_data['脂肪率'][1] = '高'; $return_data['脂肪量'][1] = '高'; } diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index c91209d..ab5fb57 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -8,6 +8,7 @@ use app\bj\controller\Common; use think\Log; use \think\Validate; use app\app\controller\Calculatebody; +use app\app\controller\Cardparts; use app\app\controller\Skip; class Card extends Base{ @@ -82,13 +83,17 @@ class Card extends Base{ if(count(input('post.')) > 0){ $data = input('post.'); } - + $bhw_date = Db::table('app_card_body_data')->where("height >= 170")->select(); + // cache($data['token']); + dump($bhw_date); + die; if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } if($this->token_time_validate($data['token']) === false){ return $this->msg(20001); } + // die; unset($data['token']); return $this->get_user_body_data($data); @@ -113,11 +118,14 @@ class Card extends Base{ // 手动记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording($data = ['aud_id'=>'25','time'=>'2024-04-11 10:10:15','height'=>'165.3','weight'=>'66.1','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function card_manual_recording($data = ['aud_id'=>'25','time'=>'2024-04-11 10:10:15','height'=>'175.6','weight'=>'70.2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input('post.')) > 0){ $data = input('post.'); + }else{ + $data['time'] = date('Y-m-d H:i:s'); } - + // dump($data); + // die; 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); } @@ -248,6 +256,12 @@ class Card extends Base{ }else{ // $curve_bottom = $this->card_curve_target_action($result); $result_end = $this->processing_return_data_new($result[0]); + $cardparts = new Cardparts; + // dump($result); + // die; + $result_end['gender'] = $result[0]['gender']; + $result_end = $cardparts->conversion_interval($result_end); + die; return $this->msg($result_end); } } @@ -275,8 +289,6 @@ class Card extends Base{ if(array_key_exists($key, $this->standard_color)){ $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; } - - // 如果小于16岁(儿童) if($data['age'] < $this->age_limit){ if(array_key_exists($key, $this->bhw_list)){ @@ -326,6 +338,7 @@ class Card extends Base{ } } } + // $result_end_data['age'] = $data['age']; // dump($data['age']); // dump($result_end_data); // die; diff --git a/application/app/controller/Cardparts.php b/application/app/controller/Cardparts.php index 2b78726..2afff83 100644 --- a/application/app/controller/Cardparts.php +++ b/application/app/controller/Cardparts.php @@ -13,16 +13,37 @@ use app\app\controller\Skip; class Cardparts extends Base{ protected $color = ['#FF5656','#FF5656','#5AD06D','#6492F6','#3967D6']; + protected $parameter_aggregate_top = [ + 'weight'=>'反映和衡量一个人健康状况的重要标志之一', + 'height'=>'人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大', + 'bmi'=>'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' + ]; + protected $parameter_aggregate_bottom = [ + 'fat_r'=>'体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。', + 'fat_w'=>'人体脂肪的重量', + 'muscle'=>'根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。', + 'muscleval'=>'肌肉量=实际体重*肌肉率', + 'water'=>'指人体内水分比例。', + 'proteinval'=>'蛋白量=实际体重*蛋白率', + 'bone'=>'单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。', + 'protein'=>'人体内蛋白率含量。', + 'kcal'=>'指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率', + 'visceral'=>'内脏脂肪指数', + 'sfr'=>'皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织', + 'body_level'=>'肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' + ]; + protected $parameter_aggregate_bottom_out = ['body_level']; + protected $parameter_aggregate_bottom_condition = ['body_level']; // 脂肪率&脂肪量 protected $fat_r_w = [ 'man'=>[ - 'young'=>[ + '29'=>[ ['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#ff5656'], ['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#ffab00'], ['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#5ad06d'], ['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#6492f6'], ], - 'aging'=>[ + '30'=>[ ['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#ff5656'], ['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#ffab00'], ['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#5ad06d'], @@ -30,13 +51,13 @@ class Cardparts extends Base{ ], ], 'woman'=>[ - 'young'=>[ + '29'=>[ ['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#ff5656'], ['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#ffab00'], ['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#5ad06d'], ['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#6492f6'], ], - 'aging'=>[ + '30'=>[ ['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#ff5656'], ['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#ffab00'], ['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#5ad06d'], @@ -120,7 +141,6 @@ class Cardparts extends Base{ ], ] ]; - // 基础代谢 protected $kcal = [ 'man'=>[ @@ -168,15 +188,6 @@ class Cardparts extends Base{ ], ] ]; - - // BMR标准值(男) BMR标准值(女) - // 60.9*体重(kg)-54 61.0*体重(kg)-51 - // 22.7*体重(kg)+495 22.5*体重(kg)+499 - // 17.5*体重(kg)+651 12.2*体重(kg)+746 - // 15.3*体重(kg)+679 14.7*体重(kg)+496 - // 11.6*体重(kg)+879 8.7*体重(kg)+820 - - // 内脏指数 protected $visceral = [ 'man'=>[ @@ -204,11 +215,53 @@ class Cardparts extends Base{ ] ]; - + // BMR标准值(男) BMR标准值(女) + // 60.9*体重(kg)-54 61.0*体重(kg)-51 + // 22.7*体重(kg)+495 22.5*体重(kg)+499 + // 17.5*体重(kg)+651 12.2*体重(kg)+746 + // 15.3*体重(kg)+679 14.7*体重(kg)+496 + // 11.6*体重(kg)+879 8.7*体重(kg)+820 // 计算部分内容的横线标准以及说明文字 public function conversion_interval($data){ - + // dump($data); + // $data['gender'] = $data['gender']==2?'woman':'man'; + $gender = $data['gender']==2?'woman':'man'; + $age = $data['age']['value']; + $temporary_arr = [ + 'top_list'=>[], + 'bottom_list'=>[], + ]; + // dump($data); + // dump($temporary_arr); + // 处理格式 + foreach ($this->parameter_aggregate_top as $key => $value) { + $data[$key]['key_name'] = $key; + $data[$key]['desc'] = $value; + array_push($temporary_arr['top_list'],$data[$key]); + } + foreach ($this->parameter_aggregate_bottom as $key => $value) { + $data[$key]['key_name'] = $key; + $data[$key]['desc'] = $value; + array_push($temporary_arr['bottom_list'],$data[$key]); + } + foreach ($temporary_arr['bottom_list'] as $key => $value) { + // 脂肪率&脂肪量 + if($value['key_name'] == 'fat_r' || $value['key_name'] == 'fat_w'){ + if($age < 30){ + $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['29']; + }else{ + $temporary_arr['bottom_list'][$key]['list'] = $this->fat_r_w[$gender]['30']; + } + $num = count($temporary_arr['bottom_list'][$key]['list'])-1; + $temporary_arr['bottom_list'][$key]['offset'] = bcdiv($temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['list'][$num]['max_val'],4)*100; + } + } + dump($data['gender']); + dump($data['age']['value']); + // dump($temporary_arr['top_list']); + dump($temporary_arr['bottom_list']); + die; } } \ No newline at end of file diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 92e0533..1de5291 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -106,7 +106,7 @@ class Index extends Base{ } // 获取指定用户详细信息 - public function get_user_data_information($data = ['aud_id'=>25,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function get_user_data_information($data = ['aud_id'=>26,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ if(count(input('post.')) > 0){ $data = input('post.'); } @@ -136,6 +136,7 @@ class Index extends Base{ $result['card_order'] = explode(',',$result['card_order']); $calculation_results = $this->get_user_card_data_list($result,$result['id']); // dump($calculation_results); + // die; $result['card_data_list'] = $calculation_results[0]; $result['target_current'] = $calculation_results[1]; } @@ -144,7 +145,11 @@ class Index extends Base{ // die; $result['birthday'] = str_replace('-', '/', $result['birthday']); foreach ($result['card_data_list'] as $key => $value) { - $result['card_data_list'][$key]['record_time'] = str_replace('-', '/', $result['card_data_list'][$key]['record_time']); + // dump($key); + if($key == 'record_time' && $value != ''){ + // dump(111); + $result['card_data_list'][$key] = str_replace('-', '/', $result['card_data_list'][$key]); + } } unset($result['target_weight']); unset($result['initial_weight']); @@ -241,35 +246,34 @@ class Index extends Base{ } } - - // 添加目标体重于当前体重差数据 - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - - // if($data['initial_date'] == null){ - // $target_current = $this->base_target_initial_cumulative_weight([]); - // }else{ - // $target_current = $this->base_target_initial_cumulative_weight([ - // 'weight'=>$db_arr['2']['weight'], - // 'target_weight'=>$data['target_weight'], - // 'initial_weight'=>$data['initial_weight'], - // 'initial_date'=>$data['initial_date'], - // ]); - // } - // dump($target_current); + // dump($db_arr); // die; + // 添加目标体重于当前体重差数据 + if(array_key_exists('2', $db_arr)){ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, + 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + ]); + }else{ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>0, + 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + ]); + } if(count($db_arr) <= 0){ // 没有数据,传递一个空的卡片 + // $ return [ [ 'id'=>'', 'acd_id'=>'2', 'record_time'=>'', 'card_name'=>'身体数据', + 'card_key'=>'', 'inside_data'=>[ [ 'key'=>'', @@ -296,7 +300,8 @@ class Index extends Base{ 'color'=>'', ], ] - ] + ], + $target_current ]; } // dump($db_arr); diff --git a/application/app/controller/Skip.php b/application/app/controller/Skip.php index 8933641..3593e4c 100644 --- a/application/app/controller/Skip.php +++ b/application/app/controller/Skip.php @@ -21,61 +21,116 @@ class Skip extends Base{ ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ - - // 查找设备 - // $data = ['device_code'=>'asdkljiouoi'] - public function skip_device_check($data = ['device_code'=>'asdkljiouoi']){ - // $data = input(); - $result = Db::query(" - select - adcd.id, - adcd.bind_account_id as activation_state, - adds.is_del as device_state - from app_device_code_data as adcd - left join app_device_data as adds on adds.id = adcd.add_id - where - adcd.machine_code = '".$data['device_code']."' - "); - - if(count($result) == 1){ - return $this->msg(0,'success',['device_state'=>$result[0]['device_state'],'activation_state'=>$result[0]['activation_state']]); - }else if(count($result) < 1){ - return $this->msg(10001,'未找到设备'); - }else{ - $this->abnormal_data_log_action(0,'device_check-设备查询出错,结果为'.count($result).',合理值应为1或0','app_device_code_data,app_device_data'); - return $this->msg(10002,'未找到设备'); + // 手动记录 + public function skip_manual_recording($data = ['aud_id'=>'25','r_time'=>'2024-04-11 10:10:15','num'=>'856','time'=>'137','type'=>'free','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input('post.')) > 0){ + $data = input('post.'); } + if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time', $data) || !array_key_exists('type', $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']); + if($this->validate_user_identity($data['aud_id']) === false){ + return $this->msg(10003); + } + return $this->skip_manual_recording_action($data); } - - // 绑定设备 - public function skip_bind_device(){ - - } - // 今日数据 - public function skip_today_data($data = ['aud_id'=>11]){ - $result = Db::query(" - select - jump_num, - jump_time, - jump_kcal, - aud_id, - CAST(GETDATE() AS DATE) as today_date - from app_card_skip_data - where - CAST(record_time AS DATE) = CAST(GETDATE() AS DATE) - and aud_id = ".$data['aud_id']." - "); - - $return_data = ['jump_num'=>0,'jump_time'=>0,'jump_kcal'=>0]; - foreach ($result as $key => $value) { - $return_data['jump_num'] = $value['jump_num']+$return_data['jump_num']; - $return_data['jump_time'] = $value['jump_time']+$return_data['jump_time']; - $return_data['jump_kcal'] = $value['jump_kcal']+$return_data['jump_kcal']; + public function skip_today_data($data = ['aud_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + if(count(input('post.')) > 0){ + $data = input('post.'); } - - return $this->msg(0,'success',$return_data); + if(!array_key_exists('aud_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']); + // dump($data); + // die; + return $this->skip_today_data_action($data); } + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################skip_manual_recording + public function skip_manual_recording_action($data){ + $last_data_body = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->field('weight')->find(); + $data_set = [ + 'create_time'=>date('Y-m-d H:i:s'), + 'last_update_time'=>date('Y-m-d H:i:s'), + 'jump_num'=>$data['num'], + 'jump_time'=>$data['time'], + 'jump_kcal'=>$this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight'])['totalCalories'], + 'aud_id'=>$data['aud_id'], + 'record_time'=>$data['r_time'], + 'jump_type'=>$data['type'] + ]; + $last_data_body = Db::table('app_card_skip_data')->insert($data_set); + + $result = [ + 'today_jump_num'=>0, + 'today_jump_time'=>0, + 'today_jump_kcal'=>0, + ]; + $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + foreach ($all_data as $key => $value) { + $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num']; + $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time']; + $result['today_jump_kcal'] = $result['today_jump_kcal']+$value['jump_kcal']; + } + $result['jump_num'] = $data['num']; + $result['jump_time'] = $data['time']; + $result['jump_kcal'] = $data_set['jump_kcal']; + return $this->msg($result); + } + ################################################################skip_today_data + public function skip_today_data_action($data){ + $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + $last_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('jump_num,jump_time,jump_kcal,record_time')->find(); + $result = [ + 'today_jump_num'=>0, + 'today_jump_time'=>0, + 'today_jump_kcal'=>0, + ]; + foreach ($all_data as $key => $value) { + $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num']; + $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time']; + $result['today_jump_kcal'] = $result['today_jump_kcal']+$value['jump_kcal']; + } + $result['jump_num'] = $last_data['jump_num']; + $result['jump_time'] = $last_data['jump_time']; + $result['jump_kcal'] = $last_data['jump_kcal']; + return $this->msg($result); + } + // 今日数据 + // public function skip_today_data($data = ['aud_id'=>11]){ + // $result = Db::query(" + // select + // jump_num, + // jump_time, + // jump_kcal, + // aud_id, + // CAST(GETDATE() AS DATE) as today_date + // from app_card_skip_data + // where + // CAST(record_time AS DATE) = CAST(GETDATE() AS DATE) + // and aud_id = ".$data['aud_id']." + // "); + + // $return_data = ['jump_num'=>0,'jump_time'=>0,'jump_kcal'=>0]; + // foreach ($result as $key => $value) { + // $return_data['jump_num'] = $value['jump_num']+$return_data['jump_num']; + // $return_data['jump_time'] = $value['jump_time']+$return_data['jump_time']; + // $return_data['jump_kcal'] = $value['jump_kcal']+$return_data['jump_kcal']; + // } + + // return $this->msg(0,'success',$return_data); + // } // 数据记录 public function skip_record_data($data = ['aud_id'=>11,'num'=>50,'time'=>60,'kcal'=>150,'record_time'=>'','jump_type'=>'free']){ @@ -191,61 +246,35 @@ class Skip extends Base{ ################################################################other################################################################ ################################################################other################################################################ - // 假随机数据插入 - public function generateRandomJumpData($n = 666) { - $return_data = []; - $startDate = new \DateTime('2024-01-01 00:00:00'); - $endDate = new \DateTime('2024-12-31 23:59:59'); - - // 为了保证在$startDate和$endDate之间随机生成日期,先确定两个日期之间的天数差 - $diff = $endDate->diff($startDate)->format('%a'); - - $startTime = strtotime('2024-01-01 00:00:00'); - $endTime = strtotime('2024-12-31 23:59:59'); - - - - for ($i = 0; $i < $n; $i++) { - // 生成随机日期 - $randomSeconds = random_int($startTime, $endTime); - $randomDateTime = date('Y-m-d H:i:s', $randomSeconds); - - // 生成随机jump_num - $jump_num = rand(30, 70); - - // 生成随机jump_time - $jump_time = rand(60, 150); - - // 生成随机jump_kcal - $jump_kcal = rand(100, 400); - - // 生成随机jump_type - $jump_types = ['free', 'time', 'num']; - $jump_type = $jump_types[array_rand($jump_types)]; - - // 固定的aud_id和acd_id - $aud_id = 11; - $acd_id = 5; - - // 将生成的数据存入数组 - $return_data[] = [ - 'create_time' => date('Y-m-d H:i:s'), - 'record_time' => $randomDateTime, - 'jump_num' => $jump_num, - 'jump_time' => $jump_time, - 'jump_kcal' => $jump_kcal, - 'aud_id' => $aud_id, - 'acd_id' => $acd_id, - 'jump_type' => $jump_type - ]; - } - // dump($return_data); - // die; - $user_data = Db::table('app_card_skip_data')->insertAll($return_data); - dump($user_data); - dump($return_data); - die; - } + // 跳绳卡路里计算 + public function skip_kcal_calculate($num=466, $time=166, $weight=70) { + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 将时间从秒转换为分钟 + $minutes = bcdiv($time,60,20); + // 计算每分钟的跳绳次数 + $jumpsPerMinute = bcdiv($num,$minutes,20); + // 根据跳绳次数确定MET值 + $met; + if ($jumpsPerMinute < 100) { + $met = 8.8; + } else if ($jumpsPerMinute >= 100 && $jumpsPerMinute < 120) { + $met = 11.8; + } else { + $met = 12.3; + } + // 计算每分钟燃烧的卡路里 + $caloriesPerMinute = bcdiv(bcmul(bcmul($met,$weight,20),3.5,20),200,2); + // 计算总卡路里消耗 + $totalCalories = bcmul($caloriesPerMinute,$minutes,2); + // 返回结果 + return [ + 'caloriesPerMinute' => $caloriesPerMinute, + 'totalCalories' => $totalCalories + ]; + } } \ No newline at end of file diff --git a/application/route.php b/application/route.php index 257e2a3..b3164cb 100644 --- a/application/route.php +++ b/application/route.php @@ -88,12 +88,10 @@ Route::any('/card_curve_target', 'app/card/card_curve_target'); Route::any('/card_data_contrast', 'app/card/card_data_contrast'); // ################################跳绳接口################################ -// 查找设备 -Route::any('/skip_device_check', 'app/skip/skip_device_check'); +// 手动记录 +Route::any('/skip_manual_recording', 'app/skip/skip_manual_recording'); // 今日数据 Route::any('/skip_today_data', 'app/skip/skip_today_data'); -// 数据记录 -Route::any('/skip_record_data', 'app/skip/skip_record_data'); // 运动曲线 Route::any('/skip_motion_curve', 'app/skip/skip_motion_curve'); // Route::any('/generateRandomJumpData', 'app/skip/generateRandomJumpData'); @@ -114,10 +112,10 @@ Route::any('/vitalcapacity_data_set', 'app/vitalcapacity/vitalcapacity_data_set' // // ################################################################其它测试################################################################ // // ################################################################其它测试################################################################ -Route::any('/generateRandomJumpData', 'app/skip/generateRandomJumpData'); -Route::any('/setdb', 'app/skip/setdb'); -Route::any('/readexcel', 'admin/execlaa/readexcel'); -Route::any('/card_curve_target_action', 'app/card/card_curve_target_action'); +// Route::any('/generateRandomJumpData', 'app/skip/generateRandomJumpData'); +// Route::any('/skip_kcal_calculate', 'app/skip/skip_kcal_calculate'); +// Route::any('/readexcel', 'admin/execlaa/readexcel'); +// Route::any('/skip_kcal_calculate', 'app/card/skip_kcal_calculate'); // Route::any('/isNumericArray', 'app/base/isNumericArray');