diff --git a/application/DeviceEnter/controller/Appinterface.php b/application/DeviceEnter/controller/Appinterface.php
index 6606433..39cb351 100644
--- a/application/DeviceEnter/controller/Appinterface.php
+++ b/application/DeviceEnter/controller/Appinterface.php
@@ -10,6 +10,10 @@ class Appinterface extends Base{
protected $device_name_list = [
'C03',
+ 'C06',
+ 'C07',
+ 'C09',
+ 'C10',
];
################################################################接口################################################################
diff --git a/application/DeviceEnter/controller/Savemsg.php b/application/DeviceEnter/controller/Savemsg.php
index 61a8052..fe06d6a 100644
--- a/application/DeviceEnter/controller/Savemsg.php
+++ b/application/DeviceEnter/controller/Savemsg.php
@@ -10,7 +10,11 @@ class Savemsg extends Base{
// 设备名称列表
protected $name_list = [
- ['name'=>'PC-C02Pro']
+ ['name'=>'PC-C02Pro'],
+ ['name'=>'PC-C06Pro'],
+ ['name'=>'PC-C07Pro'],
+ ['name'=>'PC-C09Pro'],
+ ['name'=>'PC-C10Pro'],
// [
// 'name'=>'PC-C02Pro',
// ],
diff --git a/application/NewReedaw/controller/app/Base.php b/application/NewReedaw/controller/app/Base.php
index e9c6d28..044fdaa 100644
--- a/application/NewReedaw/controller/app/Base.php
+++ b/application/NewReedaw/controller/app/Base.php
@@ -285,38 +285,39 @@ class Base extends Controller{
if(!$grade){
return [];
}
- if($grade['grade'] == 'nothing'){
- // 计算年龄判断是属于哪个年级
- $user_age = $this->calculate_age($grade['birthday']);
- if($user_age <= 7){
- $grade['grade'] = 'grade_s_1';
- }else if($user_age == 8){
- $grade['grade'] = 'grade_s_2';
- }else if($user_age == 9){
- $grade['grade'] = 'grade_s_3';
- }else if($user_age == 10){
- $grade['grade'] = 'grade_s_4';
- }else if($user_age == 11){
- $grade['grade'] = 'grade_s_5';
- }else if($user_age == 12){
- $grade['grade'] = 'grade_s_6';
- }else if($user_age == 13){
- $grade['grade'] = 'grade_m_1';
- }else if($user_age == 14){
- $grade['grade'] = 'grade_m_2';
- }else if($user_age == 15){
- $grade['grade'] = 'grade_m_3';
- }else if($user_age == 16){
- $grade['grade'] = 'grade_h_1';
- }else if($user_age == 17){
- $grade['grade'] = 'grade_h_2';
- }else if($user_age == 18){
- $grade['grade'] = 'grade_h_3';
- }else if($user_age == 19 || $user_age == 20){
- $grade['grade'] = 'grade_u_12';
- }else if($user_age >= 21){
- $grade['grade'] = 'grade_u_34';
- }
+ // if($grade['grade'] == 'nothing'){
+ // // 计算年龄判断是属于哪个年级
+
+ // }
+ $user_age = $this->calculate_age($grade['birthday']);
+ if($user_age <= 7){
+ $grade['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $grade['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $grade['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $grade['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $grade['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $grade['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $grade['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $grade['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $grade['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $grade['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $grade['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $grade['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $grade['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $grade['grade'] = 'grade_u_34';
}
$sql_min = "WITH RankedGrades AS (
SELECT
@@ -666,6 +667,9 @@ class Base extends Controller{
];
$weightConversion = [
'kg' => 1,
+ '公斤' => 1,
+ 'g' => 0.001,
+ '克' => 0.001,
'斤' => 0.5, // 1斤 = 0.5kg
'st:lb' => function($value) {
list($st, $lb) = explode(':', $value);
@@ -707,7 +711,7 @@ class Base extends Controller{
// 处理 weight
- if (preg_match('/([\d.:]+)(kg|斤|st:lb|lb)/', $weight, $matches)) {
+ if (preg_match('/([\d.:]+)(kg|公斤|g|克|斤|st:lb|lb)/', $weight, $matches)) {
$weightValue = $matches[1];
$weightUnit = $matches[2];
if($weightUnit == 'st:lb'){
@@ -961,6 +965,8 @@ class Base extends Controller{
switch ($unit) {
case 'g':
case '克':
+ case 'ml':
+ case '毫升':
// 已经是克,直接返回
$result = $weight;
break;
@@ -999,35 +1005,120 @@ class Base extends Controller{
+
+ // 以下是测试时使用
- // public function ceshiyong($aa = 4,$gd = 0.2){
+ public function ceshiyong_page(){
+
+ }
+ public function ceshiyong(){
+
+ // 老身体数据并入新身体数据
+ $test_data = Db::table('app_card_body_data')->where(['test_type'=>null,'aud_id'=>61])->page('1,100')->select();
+ // $test_data = Db::table('app_card_body_data')->where(['id'=>30883])->page('1,10')->select();
+ // $insert_search_log = Db::table('app_card_body_data_new')->where(['aud_id'=>61])->select();
+ // dump($test_data);
+ // die;
+ $temporary_data = [];
- // phpinfo();
- // die;
- // $token = 'cd3f27cf4c4002170ea7bceeb723ac91';
+ $data = [];
+ foreach ($test_data as $key => $value) {
+ $data = [];
+ $data = [
+ 'bmi' => (float)$value['bmi_val'],
+ 'bmilevel' => '',
+ 'bm' => explode(',',$value['bone'])[0],
+ 'rom' => explode(',',$value['muscle'])[0],
+ 'vwc' => explode(',',$value['water'])[0],
+ 'bfr' => explode(',',$value['fat_r'])[0],
+ 'sfr' => explode(',',$value['sfr'])[0],
+ 'pp' => explode(',',$value['protein'])[0],
+ 'uvi' => explode(',',$value['visceral'])[0],
+ 'bmr' => explode(',',$value['kcal'])[0],
+ 'bodyage' => (float)$value['body_age'],
+ 'weight' => (float)$value['weight_val'],
+ 'height' => (float)$value['height_val'],
+ 'age' => $value['age'],
+ 'adc' => 550,
+ 'sex' => 0,
+ 'romval' => explode(',',$value['muscleval'])[0],
+ 'ppval' => explode(',',$value['proteinval'])[0],
+ 'bfrval' => explode(',',$value['fat_w'])[0],
+ 'lbm' => 0,
+ 'fatlevel' => 0,
+ 'fatlevelname' => $value['body_level'],
+ 'body' => $value['body_type'],
+ 'cmi' => $value['score'],
+ 'standardlist' => null
+ ];
+ $temporary_data[] = [
+ 'id'=>$value['id'],
+ 'create_time'=>$value['create_time'],
+ 'acd_id'=>$value['acd_id'],
+ 'aud_id'=>$value['aud_id'],
+ 'record_time'=>$value['record_time'],
+ 'age'=>$value['age'],
+ 'is_del'=>$value['is_del'],
+ 'record_type'=>$value['record_type'],
+ 'height'=>(float)$value['height_val'],
+ 'weight'=>(float)$value['weight_val'],
+ 'bmi'=>(float)$value['bmi_val'],
+ 'score'=>$value['score'],
+ 'fat_r'=> explode(',',$value['fat_r'])[0],
+ 'fat_w'=> explode(',',$value['fat_w'])[0],
+ 'muscle'=> explode(',',$value['muscle'])[0],
+ 'muscleval'=> explode(',',$value['muscleval'])[0],
+ 'water'=>explode(',',$value['water'])[0],
+ 'protein'=>explode(',',$value['protein'])[0],
+ 'proteinval'=>explode(',',$value['proteinval'])[0],
+ 'bone'=>explode(',',$value['bone'])[0],
+ 'kcal'=>explode(',',$value['kcal'])[0],
+ 'visceral'=>explode(',',$value['visceral'])[0],
+ 'sfr'=>explode(',',$value['sfr'])[0],
+ 'body_level'=>$value['body_level'],
+ 'body_type'=>$value['body_type'],
+ 'body_age'=>(float)$value['body_age'],
+ 'heart_rate'=>$value['heart_rate'],
+ 'head_circumference'=>$value['head_circumference'],
+ '8_electrode_data'=>null,
+ '4_electrode_data'=>json_encode($data),
+ 'head_circumference_val'=>$value['head_circumference']?json_decode($value['head_circumference'],true)['value']:null,
+ ];
+ }
- // $data = Db::table('pc_bmistand2')->select();
- // for ($i=0; $i < count($data); $i++) {
- // foreach ($data[$i] as $key => $value) {
- // $data[$i][$key] = str_replace(' ', '',$data[$i][$key]);
-
- // }
- // Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([
- // 'month'=>$data[$i]['month'],
- // 'sex'=>$data[$i]['sex'],
- // // 'f3sd'=>$data[$i]['f3sd'],
- // // 'f2sd'=>$data[$i]['f2sd'],
- // 'f1sd'=>$data[$i]['f1sd'],
- // 'median'=>$data[$i]['median'],
- // 'z1sd'=>$data[$i]['z1sd'],
- // 'z2sd'=>$data[$i]['z2sd'],
- // // 'z3sd'=>$data[$i]['z3sd'],
- // ]);
- // }
- // die;
- // // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']);
- // }
+ foreach ($temporary_data as $key => $value) {
+
+ $id = $value['id'];
+ $xh_data = $value;
+ unset($xh_data['id']);
+ // dump($xh_data);
+ // 启动事务
+ Db::startTrans();
+ try{
+ Db::table('app_card_body_data_new')->insert($xh_data);
+ Db::table('app_card_body_data')->where(['id'=>$id])->update(['test_type'=>'1']);
+ // 提交事务
+ Db::commit();
+ dump('OK');
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ dump($id);
+ // 记录异常信息
+ dump('事务回滚原因:' . $e->getMessage());
+ // dump('异常文件:' . $e->getFile());
+ // dump('异常行号:' . $e->getLine());
+ // dump('SQL错误代码:' . $e->getCode());
+ // dump('########################################################################################################');
+ // break;
+ }
+
+ }
+ // dump($temporary_data);
+ // die;
+ // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']);
+ }
}
\ No newline at end of file
diff --git a/application/NewReedaw/controller/app/Card.php b/application/NewReedaw/controller/app/Card.php
index 91bf732..a029aaa 100644
--- a/application/NewReedaw/controller/app/Card.php
+++ b/application/NewReedaw/controller/app/Card.php
@@ -351,38 +351,9 @@ class Card extends Base{
return $this->msg(10005,'token type error');
}
if (!is_array($data['data'])) {
- return $this->msg(10005,'data type error');
+ return $this->msg(10005,'data type error');
}
-
- // $data = [
- // 'aud_id' => '61',
- // 'type' => 'skip',
- // 'data' => [
- // [
- // 'name' => '日期',
- // 'key_word' => 'r_time',
- // 'type' => 'date',
- // 'unit' => '',
- // 'value' => '2026-03-18',
- // ],
- // [
- // 'name' => '时长',
- // 'key_word' => 'time_m_s',
- // 'type' => 'multiSelector',
- // 'unit' => '',
- // 'value' => '01:00',
- // ],
- // [
- // 'name' => '数量',
- // 'key_word' => 'num',
- // 'type' => 'number',
- // 'unit' => '个',
- // 'value' => '258',
- // ],
- // ],
- // 'token' => 'caadd1be045a65f30b92aa805f1de54a',
- // 'aan_id' => '100',
- // ];
+
if($data['type'] == 'skip'){//跳绳
@@ -1048,54 +1019,64 @@ class Card extends Base{
// 处理记录时间
$user_msg = Db::name($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find();
- // die;
+
if($user_msg){
- // 根据性别&年级&年龄查规则
- if($user_msg['grade'] == 'nothing'){
- // 计算年龄判断是属于哪个年级
- $user_age = $this->calculate_age($user_msg['birthday']);
- if($user_age <= 7){
- $user_msg['grade'] = 'grade_s_1';
- }else if($user_age == 8){
- $user_msg['grade'] = 'grade_s_2';
- }else if($user_age == 9){
- $user_msg['grade'] = 'grade_s_3';
- }else if($user_age == 10){
- $user_msg['grade'] = 'grade_s_4';
- }else if($user_age == 11){
- $user_msg['grade'] = 'grade_s_5';
- }else if($user_age == 12){
- $user_msg['grade'] = 'grade_s_6';
- }else if($user_age == 13){
- $user_msg['grade'] = 'grade_m_1';
- }else if($user_age == 14){
- $user_msg['grade'] = 'grade_m_2';
- }else if($user_age == 15){
- $user_msg['grade'] = 'grade_m_3';
- }else if($user_age == 16){
- $user_msg['grade'] = 'grade_h_1';
- }else if($user_age == 17){
- $user_msg['grade'] = 'grade_h_2';
- }else if($user_age == 18){
- $user_msg['grade'] = 'grade_h_3';
- }else if($user_age == 19 || $user_age == 20){
- $user_msg['grade'] = 'grade_u_12';
- }else if($user_age >= 21){
- $user_msg['grade'] = 'grade_u_34';
- }
+ // // 根据性别&年级&年龄查规则
+ // if($user_msg['grade'] == 'nothing' || $user_msg['grade'] == ''){
+
+ // }
+ // 计算年龄判断是属于哪个年级
+ $user_age = $this->calculate_age($user_msg['birthday']);
+ // dump($user_age);
+ if($user_age <= 7){
+ $user_msg['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $user_msg['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $user_msg['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $user_msg['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $user_msg['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $user_msg['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $user_msg['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $user_msg['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $user_msg['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $user_msg['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $user_msg['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $user_msg['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $user_msg['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $user_msg['grade'] = 'grade_u_34';
}
$sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val'];
+ // dump($user_age);
+ // dump($user_msg);
+
$user_achievement = Db::name($this->card_db_name['vitalcapacity_biaozhun'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->cache(86400)->select();
+
if(count($user_achievement)<=0){
$user_achievement[0] = ['level'=>'无效','score'=>'0'];
}
+
$temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->vitalcapacity_color[$user_achievement[0]['level']];
$temporary_arr['score_val'] = $user_achievement[0]['score'];
}else{
return $this->msg(10004,'未找到有效数据');
}
+ // dump($data);
$standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+
+
$temporary_arr['standard_data'] = json_encode($standard_data);
$result = Db::table($this->card_db_name['vitalcapacity'])->insert($temporary_arr);
diff --git a/application/NewReedaw/controller/app/Index.php b/application/NewReedaw/controller/app/Index.php
index 03b7c8e..8d79ac7 100644
--- a/application/NewReedaw/controller/app/Index.php
+++ b/application/NewReedaw/controller/app/Index.php
@@ -159,6 +159,14 @@ class Index extends Base{
}
+ // 隐私协议手机网页端
+ public function privacy_policy(){
+ return $this->fetch();
+ }
+
+
+
+
@@ -452,12 +460,12 @@ class Index extends Base{
public function get_user_list_action($data){
- $account_data = Db::table($this->index_db_name['zhanghao'])->where(['token' => $data['token'],'is_del' => 0])->cache(900)->field('token,id,default_user_id')->find();
+ $account_data = Db::table($this->index_db_name['zhanghao'])->where(['token' => $data['token'],'is_del' => 0])->field('token,id,default_user_id')->find();
if(!$account_data){
return $this->msg(10003);
}
- $user_list = Db::table($this->index_db_name['juese'])->where(['aan_id' => $account_data['id'],'is_del' => 0])->cache(900)->field('id,nickname,birthday,gender,card_order,head_pic,grade,weight,height,identity_name,identity_id')->select();
+ $user_list = Db::table($this->index_db_name['juese'])->where(['aan_id' => $account_data['id'],'is_del' => 0])->field('id,id as aud_id,activity_level,nickname,birthday,gender,card_order,head_pic,grade,weight,height,identity_name,identity_id')->select();
foreach ($user_list as $key => $value) {
$user_list[$key]['age'] = $this->calculate_age($value['birthday']);
@@ -762,39 +770,6 @@ class Index extends Base{
################################################################内部调用################################################################
################################################################内部调用################################################################
- // 添加IP信息获取方法
- protected function getIpInfo($ip) {
- // 默认IP
- $ip = $ip ?: request()->ip();
- try {
- $ip2region = new \Ip2Region();
- $info = $ip2region->memorySearch($ip);
- // 返回国家信息
- return $info['region'] ?: '未知';
- } catch (\Exception $e) {
- return '未知';
- }
- }
- public function pd_language($user_language,$isSupportedLanguage,$language){
- if(!$user_language){
- if($isSupportedLanguage){
- $result = $language;
- }else{
- $result = 'zh-Hans'; // 默认语言为中文
- }
- }else{
- $result = $user_language;
- }
- return $result;
- }
- // 处理返回的语言数组
- protected function process_Language(){
- $temporary_arr = [];
- foreach ($this->language_country as $key => $value) {
- array_push($temporary_arr,['key'=>$key,'value'=>$value]);
- }
- return $temporary_arr;
- }
diff --git a/application/NewReedaw/controller/app/Login.php b/application/NewReedaw/controller/app/Login.php
index 3772812..96477f1 100644
--- a/application/NewReedaw/controller/app/Login.php
+++ b/application/NewReedaw/controller/app/Login.php
@@ -131,8 +131,9 @@ class Login extends Base{
}
// 微信手机号快捷登录
public function wechat_quick_login(){
+ $data = input('post.');
try {
- $data = input('post.');
+
if(!array_key_exists('code', $data)){
// return $this->msg(10001,'');
return $this->msg(10001,'code is miss');
@@ -157,14 +158,17 @@ class Login extends Base{
// 调用Wechat服务类处理微信登录逻辑
$wechatService = new Wechat();
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
+
if($result['code'] == 0){
- $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->fidle('token,id,is_del')->find();
+ $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->field('token,id,is_del')->find();
+ // dump($result);
+ // die;
if($user_data){
if($user_data['is_del'] == 1){
return $this->msg(10002,'该账号已注销');
}
Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
- $return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
+ return $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
}else{
$set_data['password'] = '';
$set_data['tel'] = $result['data']['phoneNumber'];
diff --git a/application/NewReedaw/controller/app/Role.php b/application/NewReedaw/controller/app/Role.php
index 1f96d85..6058fff 100644
--- a/application/NewReedaw/controller/app/Role.php
+++ b/application/NewReedaw/controller/app/Role.php
@@ -217,9 +217,26 @@ class Role extends Base{
$data = input('post.');
try {
// 你的业务逻辑
-
- if(!array_key_exists('token', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('activity_level', $data)){
- return $this->msg(10001);
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is loss');
+ }
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'昵称缺失');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'生日缺失');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'性别缺失');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'身高缺失');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'体重缺失');
+ }
+ if(!array_key_exists('activity_level', $data)){
+ return $this->msg(10001,'活动系数缺失');
}
if(!$this->verify_data_is_ok($data['activity_level'],'num')){
return $this->msg(10005,'activity_level type error');
@@ -239,6 +256,9 @@ class Role extends Base{
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type error');
+ }
return $this->add_member_action($data);
} catch (\Exception $e) {
// 捕获异常
@@ -260,8 +280,29 @@ class Role extends Base{
try {
// 你的业务逻辑
- if(!array_key_exists('token', $data) || !array_key_exists('id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('activity_level', $data)){
- return $this->msg(10001);
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is loss');
+ }
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'昵称缺失');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'生日缺失');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'性别缺失');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'身高缺失');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'体重缺失');
+ }
+ if(!array_key_exists('activity_level', $data)){
+ return $this->msg(10001,'活动系数缺失');
+ }
+ if(!array_key_exists('id', $data)){
+ return $this->msg(10001,'id is loss');
}
if(!$this->verify_data_is_ok($data['activity_level'],'num')){
return $this->msg(10005,'activity_level type error');
@@ -269,8 +310,8 @@ class Role extends Base{
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
- if(!$this->verify_data_is_ok($data['id'],'intnum')){
- return $this->msg(10005,'id type error');
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
}
if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
return $this->msg(10005,'birthday type error');
@@ -284,6 +325,12 @@ class Role extends Base{
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
return $this->update_member_action($data);
} catch (\Exception $e) {
// 捕获异常
@@ -764,6 +811,7 @@ class Role extends Base{
if($user_account['set_kcal'] == '.00'){
$user_account['set_kcal'] = 0;
}
+ $user_all_data['id'] = $user_account['aud_id'];
$user_all_data['aud_id'] = $user_account['aud_id'];
$user_all_data['nickname'] = $user_account['nickname'];
$user_all_data['gender'] = $user_account['gender'];
diff --git a/application/NewReedaw/controller/app/Userbody.php b/application/NewReedaw/controller/app/Userbody.php
index 52e43ad..f3975c4 100644
--- a/application/NewReedaw/controller/app/Userbody.php
+++ b/application/NewReedaw/controller/app/Userbody.php
@@ -15,7 +15,7 @@ class Userbody extends Base{
'body_data_new'=>'app_card_body_data_new',
'bmi'=>'pc_bmistand',
'height'=>'pc_heightstand',
- 'weight'=>'pc_weightstand',
+ 'weight'=>'pc_weightstand2',
// 'chufang1'=>'pc_childrenprescription',
// 'chufang2'=>'pc_childprescriptionbyage',
];
@@ -108,10 +108,10 @@ class Userbody extends Base{
'肥胖' => '#FD5759'
],
'standard_list' => [
- ['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'],
- ['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#5BD068'],
- ['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FAAD01'],
- ['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FD5759'],
+ ['min_val'=>'0','max_val'=>'18.5','text'=>'消瘦','color'=>'#FDDA6B'],
+ ['min_val'=>'18.5','max_val'=>'24.0','text'=>'正常','color'=>'#5BD068'],
+ ['min_val'=>'24.0','max_val'=>'28.0','text'=>'偏重','color'=>'#FAAD01'],
+ ['min_val'=>'28.0','max_val'=>'100','text'=>'肥胖','color'=>'#FD5759'],
],
'key_name'=>'bmi',
],
@@ -648,6 +648,7 @@ class Userbody extends Base{
return $this->msg(10005,'adc type error');
}
$temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ // dump($temporary_data);
if($temporary_data['height_in_cm'] == false){
return $this->msg(10005,'身高单位错误');
}
@@ -670,6 +671,8 @@ class Userbody extends Base{
$data['height'] = $temporary_data['height_in_cm'];
$data['weight'] = $temporary_data['weight_in_kg'];
$data['time'] = date('Y-m-d H:i:s');
+ // dump($data);
+ // die;
return $this->set_user_body_data($data,'by_device');
// } catch (\Exception $e) {
// // 捕获异常
@@ -718,7 +721,7 @@ class Userbody extends Base{
// 获取角色报告(详细)
public function body_report_detailed(){
$data = input('post.');
- try {
+ // try {
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
}
@@ -729,20 +732,20 @@ class Userbody extends Base{
return $this->msg(10005,'aud_id type error');
}
return $this->body_report_detailed_action($data);
- } catch (\Exception $e) {
- // 捕获异常
- $logContent["flie"] = $e->getFile();
- $logContent["line"] = $e->getLine();
- $logContent['all_content'] = "异常信息:\n";
- $logContent['all_content'] .= "函数: body_report_detailed" . "\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);
- }
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: body_report_detailed" . "\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 body_report_depth(){
@@ -1016,15 +1019,12 @@ class Userbody extends Base{
return $this->msg(10005);
}
$db_data['head_circumference'] = $data['head_data'];
+ $send_data['head'] = $data['head_data'];
+ }else{
+ $send_data['head'] = $data['head_data'];
}
-
-
-
-
$send_data['adc'] = 550;
- $send_data['head'] = $data['head_data'];
-
// 发送请求获取照良那边的身体数据
$get_body_value = $this->send_body_data($send_data,'4_electrode');
if($get_body_value === false){
@@ -1077,6 +1077,8 @@ class Userbody extends Base{
if(array_key_exists('standardlist',$get_body_value)){
unset($get_body_value['standardlist']);
}
+ $db_data['head_circumference_val'] = null;
+ $db_data['head_circumference'] = null;
}
// 如果年纪小于三岁,处理头围数据end
@@ -1095,7 +1097,9 @@ class Userbody extends Base{
$db_data['record_type'] = 'by_device';
}
}else{
- return $this->msg(10001);
+ $send_data['adc'] = 550;
+ $db_data['record_type'] = 'by_device';
+ // return $this->msg(10001);
}
if(array_key_exists('lefthand', $data) && array_key_exists('righthand', $data) && array_key_exists('leftfoot', $data) && array_key_exists('rightfoot', $data)){
// 发送请求获取照良那边的身体数据
@@ -1129,8 +1133,11 @@ class Userbody extends Base{
return $this->msg(10005);
}
$db_data['head_circumference'] = $data['head_data'];
+ $send_data['head'] = $data['head_data'];
+ }else{
+ $send_data['head'] = 0;
}
- $send_data['head'] = $data['head_data'];
+
// 发送请求获取照良那边的身体数据
$get_body_value = $this->send_body_data($send_data,'4_electrode');
@@ -1156,7 +1163,7 @@ class Userbody extends Base{
// 如果年纪小于三岁,处理头围数据star
$standardlist = [];
- if($send_data['age'] < 3){
+ if($send_data['age'] < 3 && $send_data['head'] > 0){
if(array_key_exists('standardlist',$get_body_value)){
$standardlist = $get_body_value['standardlist'];
foreach ($standardlist as $key => $value) {
@@ -1281,7 +1288,7 @@ class Userbody extends Base{
$user_data = Db::table($this->body_db_name['juese'])
->where(['id'=>$data['aud_id'],'is_del'=>0])
- ->field('birthday,gender,target_weight,initial_weight,initial_date')
+ ->field('birthday,gender,target_weight,initial_weight,initial_date,activity_level')
->find();
if(!$user_data){
return $this->msg(10003);
@@ -1293,7 +1300,38 @@ class Userbody extends Base{
->find();
+ // 设置卡片顺序
+ $set_order = [
+ // 'ideal_weight', //体脂率
+ // 'ideal_height', //体脂率
+ // 'ideal_bmi', //体脂率
+ 'fat_r', //体脂率
+ 'fat_w', //脂肪量
+ 'muscle', //肌肉率
+ 'muscleval', //肌肉量
+ 'protein', //蛋白率
+ 'proteinval', //蛋白量
+ 'water', //水分
+ 'sfr', //皮下脂肪
+ 'body_level', //肥胖等级☆
+ 'visceral', //内脏指数
+ 'bone', //骨重
+ 'body_type', //身体类型☆
+ 'score', //身体得分☆
+ 'body_age', //身体年龄☆
+ ];
if(!$body_last_data){
+ foreach ($set_order as $key => $value) {
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>'--',
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>$value,
+ ];
+ }
return $this->msg($result_return);
}
@@ -1328,7 +1366,7 @@ class Userbody extends Base{
// 处理身高
$result_return['top_list'][1]['time'] = $record_time;
$result_return['top_list'][1]['value'] = floatval($body_last_data['height']);
- $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'height',$user_data);
+ $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][1]['value'],'height',$user_data);
$result_return['top_list'][1]['standard'] = $temporary_standard_color[1];
$result_return['top_list'][1]['standard_color'] = $temporary_standard_color[2];
$result_return['top_list'][1]['key_name'] = 'height';
@@ -1336,7 +1374,7 @@ class Userbody extends Base{
// 处理BMI
$result_return['top_list'][2]['time'] = $record_time;
$result_return['top_list'][2]['value'] = floatval($body_last_data['bmi']);
- $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'bmi',$user_data);
+ $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][2]['value'],'bmi',$user_data);
$result_return['top_list'][2]['standard'] = $temporary_standard_color[1];
$result_return['top_list'][2]['standard_color'] = $temporary_standard_color[2];
$result_return['top_list'][2]['key_name'] = 'bmi';
@@ -1401,26 +1439,26 @@ class Userbody extends Base{
'ideal_heart_rate' => $temporary_standard_color[3],
];
}
- // 设置卡片顺序
- $set_order = [
- // 'ideal_weight', //体脂率
- // 'ideal_height', //体脂率
- // 'ideal_bmi', //体脂率
- 'fat_r', //体脂率
- 'fat_w', //脂肪量
- 'muscle', //肌肉率
- 'muscleval', //肌肉量
- 'protein', //蛋白率
- 'proteinval', //蛋白量
- 'water', //水分
- 'sfr', //皮下脂肪
- 'body_level', //肥胖等级☆
- 'visceral', //内脏指数
- 'bone', //骨重
- 'body_type', //身体类型☆
- 'score', //身体得分☆
- 'body_age', //身体年龄☆
- ];
+ // // 设置卡片顺序
+ // $set_order = [
+ // // 'ideal_weight', //体脂率
+ // // 'ideal_height', //体脂率
+ // // 'ideal_bmi', //体脂率
+ // 'fat_r', //体脂率
+ // 'fat_w', //脂肪量
+ // 'muscle', //肌肉率
+ // 'muscleval', //肌肉量
+ // 'protein', //蛋白率
+ // 'proteinval', //蛋白量
+ // 'water', //水分
+ // 'sfr', //皮下脂肪
+ // 'body_level', //肥胖等级☆
+ // 'visceral', //内脏指数
+ // 'bone', //骨重
+ // 'body_type', //身体类型☆
+ // 'score', //身体得分☆
+ // 'body_age', //身体年龄☆
+ // ];
// 处理卡片数据
if($body_last_data['record_type'] == 'by_hand_means'){
foreach ($set_order as $key => $value) {
@@ -1436,26 +1474,6 @@ class Userbody extends Base{
}
return $this->msg($result_return);
}else{
- // 设置卡片顺序
- // $set_order = [
- // 'ideal_weight', //体脂率
- // 'ideal_height', //体脂率
- // 'ideal_bmi', //体脂率
- // 'fat_r', //体脂率
- // 'fat_w', //脂肪量
- // 'muscle', //肌肉率
- // 'muscleval', //肌肉量
- // 'protein', //蛋白率
- // 'proteinval', //蛋白量
- // 'water', //水分
- // 'sfr', //皮下脂肪
- // 'body_level', //肥胖等级☆
- // 'visceral', //内脏指数
- // 'bone', //骨重
- // 'body_type', //身体类型☆
- // 'score', //身体得分☆
- // 'body_age', //身体年龄☆
- // ];
$temporary_three = [];
foreach ($set_order as $key => $value) {
@@ -1499,13 +1517,14 @@ class Userbody extends Base{
}else{
if($value == 'fat_w' || $value == 'muscleval' || $value == 'proteinval'){
+ $temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
$result_return['card_list'][] = [
'name'=>$this->merged_data[$value]['name'],
'icon'=>$this->merged_data[$value]['icon'],
'value'=>floatval($body_last_data[$value]),
'unit'=>$this->merged_data[$value]['unit'],
- 'standard'=>$temporary_three[$value][0],
- 'standard_color'=>$temporary_three[$value][1],
+ 'standard'=>$temporary_standard_color[0],
+ 'standard_color'=>$temporary_standard_color[1],
'key_name'=>$value,
];
}else if($value == 'score'){
@@ -1520,7 +1539,8 @@ class Userbody extends Base{
'key_name'=>$value,
];
}else{
-
+ // dump($value);
+
$temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
// dump($temporary_standard_color);
if($temporary_standard_color){
@@ -1528,30 +1548,12 @@ class Userbody extends Base{
$result_return['card_list'][] = [
'name'=>$this->merged_data[$value]['name'],
'icon'=>$this->merged_data[$value]['icon'],
- 'value'=>floatval($temporary_standard_color[0]),
+ 'value'=>floatval($body_last_data[$value]),
'unit'=>$this->merged_data[$value]['unit'],
- 'standard'=>$temporary_standard_color[1],
- 'standard_color'=>$this->merged_data[$value]['list'][$temporary_standard_color[1]],
+ 'standard'=>$temporary_standard_color[0],
+ 'standard_color'=>$temporary_standard_color[1],
'key_name'=>$value,
];
- if($value == 'fat_r'){
- $temporary_three['fat_w'] = [
- $temporary_standard_color[1],
- $this->merged_data[$value]['list'][$temporary_standard_color[1]],
- ];
- }
- if($value == 'muscle'){
- $temporary_three['muscleval'] = [
- $temporary_standard_color[1],
- $this->merged_data[$value]['list'][$temporary_standard_color[1]],
- ];
- }
- if($value == 'protein'){
- $temporary_three['proteinval'] = [
- $temporary_standard_color[1],
- $this->merged_data[$value]['list'][$temporary_standard_color[1]],
- ];
- }
}
}
}
@@ -1559,6 +1561,15 @@ class Userbody extends Base{
}
}
}
+ $result_return['card_list'][] = [
+ 'name'=>'建议卡路里摄入量',
+ 'icon'=>'https://tc.pcxbc.com/new_reedaw/icon/suggestion_kcal.png',
+ 'value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal'],
+ 'unit'=>'kcal',
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>'suggestion_kcal',
+ ];
return $this->msg($result_return);
}
@@ -1568,7 +1579,7 @@ class Userbody extends Base{
$user_data = Db::table($this->body_db_name['juese'])
->where(['id'=>$data['aud_id'],'is_del'=>0])
- ->field('birthday,gender,target_weight,initial_weight,initial_date')
+ ->field('birthday,gender,target_weight,initial_weight,initial_date,activity_level')
->find();
if(!$user_data){
return $this->msg(10003);
@@ -1580,6 +1591,245 @@ class Userbody extends Base{
->find();
if(!$body_last_data){
+ $result_return = [
+ [
+ 'name' => '体重',
+ 'unit' => 'kg',
+ 'description' => '体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。',
+ 'smart_tip_description' => '保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'weight',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身高',
+ 'unit' => 'cm',
+ 'description' => '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/height.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'height',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => 'BMR',
+ 'unit' => 'kcal',
+ 'description' => 'BMR是基础代谢率(BasalMetabolicRate)的缩写,指人体在安静状态下,维持基本生命活动所需的最低能量消耗率。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'kcal',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => 'BMI',
+ 'unit' => '',
+ 'description' => 'BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi10.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'bmi',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '脂肪率',
+ 'unit' => '%',
+ 'description' => '体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_r.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'fat_r',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '脂肪量',
+ 'unit' => 'kg',
+ 'description' => '脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_w.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'fat_w',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肌肉率',
+ 'unit' => '%',
+ 'description' => '肌肉率指人体成分中肌肉占体重的百分比。肌肉率越高,BMR越大,消耗的热量越多,就不容易发胖。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscle.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'muscle',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肌肉量',
+ 'unit' => 'kg',
+ 'description' => '肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscleval.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'muscleval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '蛋白率',
+ 'unit' => '%',
+ 'description' => '蛋白质率指人体组织中蛋白质含量占总体重的百分比。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/protein.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'protein',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '蛋白量',
+ 'unit' => 'kg',
+ 'description' => '',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/proteinval.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'proteinval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '水分',
+ 'unit' => '%',
+ 'description' => '体水分率指人体组织中的水分占总体重的百分比,也称为身体水分含量。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/water.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'water',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '皮下脂肪',
+ 'unit' => '%',
+ 'description' => '皮下脂肪率指身体内皮下脂肪组织占身体总重量的百分比。皮下脂肪适量时对身体有益,但过量会使身体处于肥胖状态,并可能导致多种健康问题。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/sfr.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'sfr',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '内脏指数',
+ 'unit' => '',
+ 'description' => '内脏脂肪指围绕脏器的脂肪组织,主要分布于腹腔内,包括肝脏、心脏、肾脏、胰腺等器官周围的脂肪。身体内脏脂肪的增加会导致慢性代谢性疾病的风险增加。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/visceral.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'visceral',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '骨重',
+ 'unit' => 'kg',
+ 'description' => '身体骨量指人体骨骼所含的骨基质和矿物质的质量。骨量的大小直接影响骨骼健康,对身体的稳定性和功能起着至关重要的作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bone.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'bone',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肥胖等级',
+ 'unit' => '',
+ 'description' => '肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_level.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_level',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身体年龄',
+ 'unit' => '岁',
+ 'description' => '身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_age.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_age',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身体得分',
+ 'unit' => '分',
+ 'description' => '',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/score.png',
+ 'standard_list' => [],
+ 'key_name' => 'score',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ ];
return $this->msg($result_return);
}
$user_data['weight'] = $body_last_data['weight'];
@@ -1625,12 +1875,7 @@ class Userbody extends Base{
$result_return[] = $temporary_data_list;
}
}else{
- // $temporary_data_list = $this->merged_data[$value];
- // $temporary_data_list['list'] = [];
- // $temporary_data_list['standard_list'] = [];
- // $temporary_data_list['value'] = '--';
- // $result_return[] = $temporary_data_list;
- // continue;
+
if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
$temporary_data_list = $this->judgment_standard_color_detailed(null,$value,$user_data);
if($temporary_data_list){
@@ -1685,8 +1930,32 @@ class Userbody extends Base{
}
}
}
+
+ if($body_last_data['record_type'] != 'by_device_adc'){
+ foreach ($result_return as $key => $value) {
+ if(!in_array($value['name'],['体重','身高','BMI'])){
+ $result_return[$key]['standard'] = '';
+ $result_return[$key]['standard_color'] = '';
+ }
+ }
+ }
- //身体
+
+ $result_return[] = [
+ 'name' => '建议卡路里摄入量',
+ 'unit' => 'kcal',
+ 'description' => '根据BMR配合运动系数,大致估算的每日建议摄入的卡路里量',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/suggestion_kcal.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_level',
+ 'value' => $this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal'],
+ 'standard' => '',
+ 'standard_color' => '',
+ 'offset' => 0
+ ];
+
return $this->msg($result_return);
@@ -1697,7 +1966,7 @@ class Userbody extends Base{
$user_data = Db::table($this->body_db_name['juese'])
->where(['id'=>$data['aud_id'],'is_del'=>0])
- ->field('nickname,head_pic,birthday,gender,target_weight,initial_weight,initial_date')
+ ->field('nickname,head_pic,birthday,gender,target_weight,initial_weight,initial_date,activity_level')
->find();
if(!$user_data){
return $this->msg(10003);
@@ -1709,6 +1978,188 @@ class Userbody extends Base{
->find();
if(!$body_last_data){
+ $result_return = array(
+ 'user_data' => array(
+ 'title_name' => '',
+ 'nickname' => $user_data['nickname'],
+ 'head_pic' => $user_data['head_pic'],
+ 'gender' => $user_data['gender'],
+ 'record_time' => '',
+ 'age' => $this->calculate_age($user_data['birthday']),
+ 'height' => 0,
+ 'weight' => 0,
+ 'score' => 0
+ ),
+ 'body_data' => array(
+ 'title_name' => '身体成分分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_data.png',
+ 'title' => '体重',
+ 'standard' => '',
+ 'description' => '*总体重=体水分量+蛋白质量+脂肪量+其他',
+ 'list' => array(
+ array(
+ 'color' => '#3E7AF6',
+ 'name' => '体水分量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#FFB119',
+ 'name' => '蛋白质量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#31D4F5',
+ 'name' => '脂肪量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#999999',
+ 'name' => '其他',
+ 'scope' => '',
+ 'value' => '',
+ 'offset' => '100'
+ )
+ ),
+ 'value' => 0,
+ 'unit' => 'kg'
+ ),
+ 'muscle_fat' => array(
+ 'title_name' => '肌肉脂肪分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png',
+ 'list' => array(
+ array(
+ 'name' => '体重',
+ 'unit' => 'kg',
+ 'description' => '体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。',
+ 'smart_tip_description' => '保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'weight',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0
+ ),
+ array(
+ 'name' => '肌肉量',
+ 'unit' => 'kg',
+ 'description' => '肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscleval.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'muscleval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ ),
+ array(
+ 'name' => '脂肪量',
+ 'unit' => 'kg',
+ 'description' => '脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_w.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'fat_w',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ )
+ )
+ ),
+ 'fat_analysis' => array(
+ 'title_name' => '肥胖分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_analysis.png',
+ 'list' => array(
+ array(
+ 'name' => '脂肪率',
+ 'unit' => '%',
+ 'description' => '体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_r.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'fat_r',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ ),
+ array(
+ 'name' => 'BMI',
+ 'unit' => '',
+ 'description' => 'BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi10.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'bmi',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0
+ )
+ )
+ ),
+ 'weight_controller' => array(
+ 'title_name' => '体重控制',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png',
+ 'list' => array(
+ array(
+ 'name' => '数据',
+ 'value' => '测量值'
+ ),
+ array(
+ 'name' => '标准体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '控制体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => 'BMR',
+ 'value' => '--',
+ )
+ )
+ ),
+ 'other_data' => array(
+ 'title_name' => '其他指标',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/other_data.png',
+ 'list' => array(
+ array(
+ 'name' => '项目',
+ 'value' => '测量值'
+ ),
+ array(
+ 'name' => '去脂体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '皮下脂肪量',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '身体年龄',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '内脏脂肪',
+ 'value' => '--',
+ )
+ )
+ )
+ );
return $this->msg($result_return);
}
if($body_last_data['8_electrode_data']){
@@ -1749,8 +2200,6 @@ class Userbody extends Base{
'standard_list'=>$temporary_data_list_heart_rate['standard_list'],
'offset'=>$temporary_data_list_heart_rate['offset'],
];
- }else{
- $result_return['heart_rate'] = [];
}
// 处理身体成分分析板块
@@ -1758,10 +2207,6 @@ class Userbody extends Base{
$temporary_data_list_fat_w = $this->judgment_standard_color_detailed($body_last_data['fat_w'],'fat_w',$user_data);
$temporary_data_list_proteinval = $this->judgment_standard_color_detailed($body_last_data['proteinval'],'proteinval',$user_data);
$temporary_data_list_water = $this->judgment_standard_color_detailed($body_last_data['water'],'water',$user_data);
- // 加 bcadd(,,20)
- // 减 bcsub(,,20)
- // 乘 bcmul(,,20)
- // 除 bcdiv(,,20)
// 设置临时身体成分数据变量
$temporary_data_list = [];
// 体重获取标准信息以及标准描述
@@ -1812,23 +2257,39 @@ class Userbody extends Base{
$temporary_body_data['water']['standard_arr'] = '';
$temporary_body_data['water']['standard_str'] = bcdiv($body_last_data['water'],$body_last_data['weight'],2);
}
- $result_return['body_data'] = [
- 'title_name'=>'身体成分分析',
- "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
- "title"=>"体重".$temporary_body_data['weight']['standard_arr'],
- 'standard'=>$temporary_body_data['weight']['standard_str'] == ''?'':$temporary_body_data['weight']['standard_str'],
- "description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
- 'list'=>[
- ['color'=>'#3E7AF6','name'=>'体水分量','scope'=>$temporary_body_data['water']['standard_arr'],'value'=>(float)$body_last_data['water'],'offset'=>$temporary_body_data['water']['standard_str']],
- ['color'=>'#FFB119','name'=>'蛋白质量','scope'=>$temporary_body_data['proteinval']['standard_arr'],'value'=>(float)$body_last_data['proteinval'],'offset'=>$temporary_body_data['proteinval']['standard_str']],
- ['color'=>'#31D4F5','name'=>'脂肪量','scope'=>$temporary_body_data['fat_w']['standard_arr'],'value'=>(float)$body_last_data['fat_w'],'offset'=>$temporary_body_data['fat_w']['standard_str']],
- // ['color'=>'#E749F5','name'=>'肌肉量','scope'=>$temporary_body_data['muscleval'][0],'value'=>$body_last_data['muscleval'],'offset'=>$temporary_body_data['muscleval'][1]],
- // ['color'=>'#1EA04A','name'=>'骨重','scope'=>$temporary_body_data['bone'][0],'value'=>$body_last_data['bone'],'offset'=>$temporary_body_data['bone'][1]],
- ['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'','offset'=>bcsub(bcsub(bcsub(100,$temporary_body_data['water']['standard_str'],20),$temporary_body_data['proteinval']['standard_str'],20),$temporary_body_data['fat_w']['standard_str'],2)],
- ],
- 'value'=>(float)$body_last_data['weight'],
- 'unit'=>$temporary_data_list_weight['unit'],
- ];
+ if($body_last_data['record_type'] != 'by_hand_means'){
+ $result_return['body_data'] = [
+ 'title_name'=>'身体成分分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
+ "title"=>"体重".$temporary_body_data['weight']['standard_arr'],
+ 'standard'=>$temporary_body_data['weight']['standard_str'] == ''?'':$temporary_body_data['weight']['standard_str'],
+ "description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
+ 'list'=>[
+ ['color'=>'#3E7AF6','name'=>'体水分量','scope'=>$temporary_body_data['water']['standard_arr'],'value'=>(float)$body_last_data['water'],'offset'=>$temporary_body_data['water']['standard_str']],
+ ['color'=>'#FFB119','name'=>'蛋白质量','scope'=>$temporary_body_data['proteinval']['standard_arr'],'value'=>(float)$body_last_data['proteinval'],'offset'=>$temporary_body_data['proteinval']['standard_str']],
+ ['color'=>'#31D4F5','name'=>'脂肪量','scope'=>$temporary_body_data['fat_w']['standard_arr'],'value'=>(float)$body_last_data['fat_w'],'offset'=>$temporary_body_data['fat_w']['standard_str']],
+ ['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'','offset'=>bcsub(bcsub(bcsub(100,$temporary_body_data['water']['standard_str'],20),$temporary_body_data['proteinval']['standard_str'],20),$temporary_body_data['fat_w']['standard_str'],2)],
+ ],
+ 'value'=>(float)$body_last_data['weight'],
+ 'unit'=>$temporary_data_list_weight['unit'],
+ ];
+ }else{
+ $result_return['body_data'] = [
+ 'title_name'=>'身体成分分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
+ "title"=>"体重",
+ 'standard'=>'',
+ "description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
+ 'list'=>[
+ ['color'=>'#3E7AF6','name'=>'体水分量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#FFB119','name'=>'蛋白质量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#31D4F5','name'=>'脂肪量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'--','offset'=>100],
+ ],
+ 'value'=>(float)$body_last_data['weight'],
+ 'unit'=>$temporary_data_list_weight['unit'],
+ ];
+ }
// 处理肌肉脂肪分析
@@ -1844,79 +2305,18 @@ class Userbody extends Base{
foreach ($result_return['muscle_fat']['list'] as $key => $value) {
$result_return['muscle_fat']['list'][$key]['list'] = $value['standard_list'];
}
- //肌肉脂肪分析
- // $ceshi = [
- // // 'title_key'=>'muscle_fat',
- // 'title_name'=>'肌肉脂肪分析',
- // "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png",
- // // "title"=>$temporary_body_data['weight'][0],
- // 'list'=>[
- // [
- // 'name'=>'体重',
- // 'unit'=>'kg',
- // 'description'=>$this->merged_data['weight']['description'],
- // 'smart_tip_description'=>'',
- // 'icon'=>'',
- // 'list'=>$this->merged_data['weight']['standard_list'],
- // 'standard_list'=>[
- // ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
- // ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
- // ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
- // ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
- // ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
- // ],
- // 'key_name'=>'weight',
- // 'value'=>50,
- // 'standard'=>'标准',
- // 'standard_color'=>'#59D168',
- // 'offset'=>'50',
- // ],
- // [
- // 'name'=>'骨骼肌量(kg)',
- // 'unit'=>'kg',
- // 'description'=>$this->merged_data['weight']['description'],
- // 'smart_tip_description'=>'',
- // 'icon'=>'',
- // 'list'=>$this->merged_data['weight']['standard_list'],
- // 'standard_list'=>[
- // ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
- // ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
- // ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
- // ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
- // ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
- // ],
- // 'key_name'=>'weight',
- // 'value'=>45,
- // 'standard'=>'标准',
- // 'standard_color'=>'#59D168',
- // 'offset'=>'45',
- // ],
- // [
- // 'name'=>'脂肪量',
- // 'unit'=>'kg',
- // 'description'=>$this->merged_data['weight']['description'],
- // 'smart_tip_description'=>'',
- // 'icon'=>'',
- // 'list'=>$this->merged_data['weight']['standard_list'],
- // 'standard_list'=>[
- // ['min_val'=>'0','max_val'=>'20','text'=>'低','color'=>'#F8595D'],
- // ['min_val'=>'20','max_val'=>'40','text'=>'偏低','color'=>'#FFAF04'],
- // ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D168'],
- // ['min_val'=>'60','max_val'=>'80','text'=>'偏高','color'=>'#FFAF04'],
- // ['min_val'=>'80','max_val'=>'100','text'=>'高','color'=>'#F8595D'],
- // ],
- // 'key_name'=>'weight',
- // 'value'=>70,
- // 'standard'=>'偏高',
- // 'standard_color'=>'#FFAF04',
- // 'offset'=>'70',
- // ]
- // ],
- // ];
-
- // return $this->msg(['a'=>$result_return['muscle_fat'],'b'=>$ceshi]);
-
-
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ foreach ($result_return['muscle_fat']['list'] as $key => $value) {
+ if($value['name'] != '体重'){
+ $result_return['muscle_fat']['list'][$key]['offset'] = 0;
+ $result_return['muscle_fat']['list'][$key]['standard'] = '';
+ $result_return['muscle_fat']['list'][$key]['value'] = '--';
+ $result_return['muscle_fat']['list'][$key]['standard_color'] = '#FFFFFF';
+
+ }
+ }
+ }
+
// 处理节段脂肪分析(如果是8电极才有)
// return $this->msg($electrode_data_8);
@@ -2029,6 +2429,17 @@ class Userbody extends Base{
foreach ($result_return['fat_analysis']['list'] as $key => $value) {
$result_return['fat_analysis']['list'][$key]['list'] = $value['standard_list'];
}
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ foreach ($result_return['fat_analysis']['list'] as $key => $value) {
+ if($value['name'] != 'BMI'){
+ $result_return['fat_analysis']['list'][$key]['offset'] = 0;
+ $result_return['fat_analysis']['list'][$key]['standard'] = '';
+ $result_return['fat_analysis']['list'][$key]['value'] = '--';
+ $result_return['fat_analysis']['list'][$key]['standard_color'] = '#FFFFFF';
+
+ }
+ }
+ }
//体重控制
@@ -2051,6 +2462,7 @@ class Userbody extends Base{
['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
['name'=>'控制体重','value'=>bcsub($standard_weight['median'],$body_last_data['weight'],2).'kg'],
['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
+ ['name'=>'建议摄入Kcal','value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal']],
],
];
}else{
@@ -2065,6 +2477,7 @@ class Userbody extends Base{
['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
['name'=>'控制体重','value'=>bcsub($standard_weight,$body_last_data['weight'],2).'kg'],
['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
+ ['name'=>'建议摄入Kcal','value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal']],
],
];
}
@@ -2078,7 +2491,7 @@ class Userbody extends Base{
'l_line_color'=>['name'=>'脂肪率','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'偏高','color'=>'#dc0225']]],
'r_line_color'=>['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#299744']]],
'box_list'=>['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'],
- 'value'=>'浮肿肥胖型',
+ 'value'=>$body_last_data['body_type'],
];
//其他指标
@@ -2089,12 +2502,14 @@ class Userbody extends Base{
// "title"=>$temporary_body_data['weight'][0],
'list'=>[
['name'=>'项目','value'=>'测量值'],
- ['name'=>'去脂体重','value'=>bcsub($body_last_data['weight'],$body_last_data['fat_w'],2).'kg'],
- ['name'=>'皮下脂肪量','value'=>$body_last_data['sfr'].'kg'],
- ['name'=>'身体年龄','value'=>$body_last_data['body_age']],
- ['name'=>'内脏脂肪','value'=>$body_last_data['visceral']],
+ ['name'=>'去脂体重','value'=>$body_last_data['record_type'] != 'by_hand_means'?bcsub($body_last_data['weight'],$body_last_data['fat_w'],2).'kg':'--'],
+ ['name'=>'皮下脂肪量','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['sfr'].'kg':'--'],
+ ['name'=>'身体年龄','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['body_age']:'--'],
+ ['name'=>'内脏脂肪','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['visceral']:'--'],
],
];
+
+
return $this->msg($result_return);
@@ -2224,20 +2639,32 @@ class Userbody extends Base{
return $this->msg(10003);
}
+
$weight_result = null;
if($user_data['target_weight'] == null || $user_data['initial_weight'] == null){
$user_data['target_weight'] = $user_data['target_weight'] == null?0:$user_data['target_weight'];
$user_data['initial_weight'] = $user_data['initial_weight'] == null?0:$user_data['initial_weight'];
}else{
- $weight_result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,weight,record_time')->find();
+ $weight_result = Db::table($this->body_db_name['body_data_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field('id,weight,record_time')->find();
+
}
$return_data['target_weight'] = $user_data['target_weight'];
$return_data['initial_weight'] = $user_data['initial_weight'];
+
if($weight_result){
+
$return_data['calculate_time'] = $this->daysSince($user_data['initial_date']);
- $return_data['calculate_val'] = bcsub($weight_result['weight'],$data['initial_weight'],2);
+ // dump($weight_result['weight']);
+ // dump($data['initial_weight']);
+ // dump(bcsub($weight_result['weight'],$data['initial_weight'],2));
+
+ $return_data['calculate_val'] = bcsub($weight_result['weight'],$return_data['initial_weight'],2);
+
+ // dump($user_data['initial_date']);
+
+ // die;
}else{
$return_data['calculate_time'] = 0;
$return_data['calculate_val'] = 0;
@@ -2260,6 +2687,7 @@ class Userbody extends Base{
$temporary_arr = [];
$return_data['curve_list'] = [];
+ $bg_color = ['体重'=>'#f78814','身高'=>'#dab8f4','BMI'=>'#a8def6','心率'=>'#fb8587','头围'=>'#55d87b'];
foreach ($db_type as $key => $value) {
$temporary_arr = [];
// $temporary_arr['key'] = $value[0];
@@ -2267,7 +2695,8 @@ class Userbody extends Base{
$temporary_arr['line'] = [
'categories' => [],
'series' => [
- ['color' => "#000000",'data' => []]
+ ['color' => $bg_color[$value[1]],'data' => []]
+ // ['color' => '#000000','data' => []]
],
];
@@ -2442,7 +2871,8 @@ class Userbody extends Base{
if($type == 'weight'){
$linshi_data = $this->merged_data['weight'];
- $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
if($bhw_date){
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
@@ -2512,23 +2942,20 @@ class Userbody extends Base{
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
- foreach ($linshi_data['standard_list'] as $k => $v) {
- if($data >= $v['min_val'] && $data < $v['max_val']){
- // 如果落在区间内
- $return_data[] = $v['text'];
- $return_data[] = $v['color'];
- }
- }
- if(count($return_data) <= 1){
- $return_data[] = '异常';
- $return_data[] = '#000000';
- }
- return $return_data;
- }else{
- $return_data[] = '';
- $return_data[] = '';
- return $return_data;
+
}
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ }
+ }
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ }
+ return $return_data;
}else if($type == 'heart_rate'){
$linshi_data = $this->merged_data['heart_rate'];
foreach ($this->heart_rate as $key => $value) {
@@ -2556,7 +2983,8 @@ class Userbody extends Base{
}
return $return_data;
}else if($type == 'ideal_weight'){
- $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
if($bhw_date){
return $bhw_date[0]['median'];
}else{
@@ -2576,174 +3004,100 @@ class Userbody extends Base{
}else{
return false;
}
- }else if($type == 'fat_r'){//'fat_w'同一标准
- if(
- ($gender_val==1 && $age<30 && $data<10) ||
- ($gender_val==1 && $age>=30 && $data<11) ||
- ($gender_val==2 && $age<30 && $data<20) ||
- ($gender_val==2 && $age>=30 && $data<21)){
- $return_data[] = '偏低';
- $return_data[] = $this->merged_data[$type]['list']['偏低'];
- }else if(
- ($gender_val==1 && $age<30 && $data>=10 && $data<21) ||
- ($gender_val==1 && $age>=30 && $data>=11 && $data<22) ||
- ($gender_val==2 && $age<30 && $data>=20 && $data<31) ||
- ($gender_val==2 && $age>=30 && $data>=21 && $data<32)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $age<30 && $data>=21 && $data<26) ||
- ($gender_val==1 && $age>=30 && $data>=22 && $data<27) ||
- ($gender_val==2 && $age<30 && $data>=31 && $data<38) ||
- ($gender_val==2 && $age>=30 && $data>=32 && $data<39)){
- $return_data[] = '偏高';
- $return_data[] = $this->merged_data[$type]['list']['偏高'];
- }else if(
- ($gender_val==1 && $age<30 && $data>=26) ||
- ($gender_val==1 && $age>=30 && $data>=27) ||
- ($gender_val==2 && $age<30 && $data<38) ||
- ($gender_val==2 && $age>=30 && $data<39)){
- $return_data[] = '高';
- $return_data[] = $this->merged_data[$type]['list']['高'];
+ }else if($type == 'fat_r' || $type == 'fat_w'){//'fat_w'同一标准
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ if($age < 30){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['29'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['30'];
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
}else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
+ return false;
}
- return $return_data;
- }else if($type == 'muscle'){//'muscleval'同一标准
- if(
- ($gender_val==1 && $type<40) ||
- ($gender_val==2 && $type<30)){
- $return_data[] = '不足';
- $return_data[] = $this->merged_data[$type]['list']['不足'];
- }else if(
- ($gender_val==1 && $type>=40 && $type<60) ||
- ($gender_val==2 && $type>=30 && $type<50)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $type>=60) ||
- ($gender_val==2 && $type>=50)){
- $return_data[] = '优';
- $return_data[] = $this->merged_data[$type]['list']['优'];
+ // return $return_data;
+ }else if($type == 'muscle' || $type == 'muscleval' || $type == 'protein' || $type == 'proteinval' || $type == 'water' || $type == 'sfr' || $type == 'visceral'){//'muscleval'同一标准
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
}else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
+ return false;
}
- return $return_data;
- }else if($type == 'protein'){//'proteinval'同一标准
- if(
- ($gender_val==1 && $data<16) ||
- ($gender_val==2 && $data<14)){
- $return_data[] = '不足';
- $return_data[] = $this->merged_data[$type]['list']['不足'];
- }else if(
- ($gender_val==1 && $data>=16 && $data<18) ||
- ($gender_val==2 && $data>=14 && $data<16)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $data>18) ||
- ($gender_val==2 && $data>16)){
- $return_data[] = '优';
- $return_data[] = $this->merged_data[$type]['list']['优'];
- }else{
- $return_data['蛋白量'][1] = '异常';
- $return_data['蛋白率'][1] = '异常';
- $return_data[] = '异常';
- $return_data[] = '#000000';
- }
- return $return_data;
- }else if($type == 'water'){
- if(
- ($gender_val==1 && $data<55) ||
- ($gender_val==2 && $data<45)){
- $return_data[] = '不足';
- $return_data[] = $this->merged_data[$type]['list']['不足'];
- }else if(
- ($gender_val==1 && $data>=55 && $data<65) ||
- ($gender_val==2 && $data>=45 && $data<60)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $data>65) ||
- ($gender_val==2 && $data>60)){
- $return_data[] = '优';
- $return_data[] = $this->merged_data[$type]['list']['优'];
- }else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
- }
- return $return_data;
- }else if($type == 'sfr'){
- if(
- ($gender_val==1 && $data<7) ||
- ($gender_val==2 && $data<11)){
- $return_data[] = '不足';
- $return_data[] = $this->merged_data[$type]['list']['不足'];
- }else if(
- ($gender_val==1 && $data>=7 && $data<15) ||
- ($gender_val==2 && $data>=11 && $data<17)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $data>=15) ||
- ($gender_val==2 && $data>=17)){
- $return_data[] = '偏高';
- $return_data[] = $this->merged_data[$type]['list']['偏高'];
- }else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
- }
- return $return_data;
- }else if($type == 'visceral'){
- if($data<9){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if($data>=9 && $data<14){
- $return_data[] = '警惕';
- $return_data[] = $this->merged_data[$type]['list']['警惕'];
- }else if($data>=14){
- $return_data[] = '危险';
- $return_data[] = $this->merged_data[$type]['list']['危险'];
- }else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
- }
- return $return_data;
}else if($type == 'bone'){
- if(
- ($gender_val==1 && $user['weight']<60 && $data<2.4) ||
- ($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data<2.8) ||
- ($gender_val==1 && $user['weight']>=75 && $data<3.1) ||
- ($gender_val==2 && $user['weight']<45 && $data<1.7) ||
- ($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data<2.1) ||
- ($gender_val==2 && $user['weight']>=60 && $data<2.4)){
- $return_data[] = '不足';
- $return_data[] = $this->merged_data[$type]['list']['不足'];
- }else if(
- ($gender_val==1 && $user['weight']<60 && $data>=2.4 && $data<=2.6) ||
- ($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data>=2.8 && $data<=3) ||
- ($gender_val==1 && $user['weight']>=75 && $data>=3.1 && $data<=3.3) ||
- ($gender_val==2 && $user['weight']<45 && $data>=1.7 && $data<=1.9) ||
- ($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data>=2.1 && $data<=2.3) ||
- ($gender_val==2 && $user['weight']>=60 && $data>=2.4 && $data<=2.6)){
- $return_data[] = '标准';
- $return_data[] = $this->merged_data[$type]['list']['标准'];
- }else if(
- ($gender_val==1 && $user['weight']<60 && $data>2.6) ||
- ($gender_val==1 && $user['weight']>=60 && $user['weight']<75 && $data>3) ||
- ($gender_val==1 && $user['weight']>=75 && $data<3.3) ||
- ($gender_val==2 && $user['weight']<45 && $data>1.9) ||
- ($gender_val==2 && $user['weight']>=45 && $user['weight']<60 && $data>2.3) ||
- ($gender_val==2 && $user['weight']>=60 && $data>2.6)){
- $return_data[] = '优';
- $return_data[] = $this->merged_data[$type]['list']['优'];
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+
+ if($gender_val == '1'){
+ if($user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }else if($user['weight'] >= 60 && $user['weight'] < 75){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60_75'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['75'];
+ }
+ }else{
+ if($user['weight'] < 45){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45'];
+ }else if($user['weight'] >= 45 && $user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45_60'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }
+ }
+
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
}else{
- $return_data[] = '异常';
- $return_data[] = '#000000';
+ return false;
}
- return $return_data;
}else if($type == 'score'){
$linshi_data = $this->merged_data['score'];
foreach ($linshi_data['standard_list'] as $k => $v) {
@@ -2777,7 +3131,8 @@ class Userbody extends Base{
$linshi_data['standard_color'] = '';
$linshi_data['offset'] = 0;
- $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
if($bhw_date){
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
@@ -2982,8 +3337,6 @@ class Userbody extends Base{
$bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
- // dump($month_num);
- // dump($bhw_date);
if($bhw_date){
$linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f1sd'];
$linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f1sd'];
@@ -2991,8 +3344,8 @@ class Userbody extends Base{
$linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
$linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
$linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
-
- foreach ($linshi_data['standard_list'] as $k => $v) {
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
if($data >= $v['min_val'] && $data < $v['max_val']){
// 如果落在区间内
$linshi_data['standard'] = $v['text'];
@@ -3005,13 +3358,6 @@ class Userbody extends Base{
}
$linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
-
- }else{
- $linshi_data['standard_list'] = [];
- // $return_data[] = '异常';
- // $return_data[] = '#000000';
- // return $linshi_data;
- }
return $linshi_data;
}else{
return false;
@@ -3082,7 +3428,8 @@ class Userbody extends Base{
$linshi_data['standard_color'] = '';
$linshi_data['offset'] = 0;
- $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
if($bhw_date){
$linshi_data['value'] = $bhw_date[0]['median'];
return $linshi_data;
@@ -3176,13 +3523,15 @@ class Userbody extends Base{
}
}
else if($type == 'body_type' || $type == 'body_level' || $type == 'body_age'){
+
if($data){
$linshi_data = $this->merged_data[$type];
- $linshi_data['value'] = $data;
+ $linshi_data['value'] = $type == 'body_age'?(float)$data:$data;
$linshi_data['standard'] = '';
$linshi_data['standard_color'] = '';
$linshi_data['offset'] = 0;
-
+ // dump($linshi_data);
+ // dump($data);
return $linshi_data;
}else{
return false;
diff --git a/application/NewReedaw/view/app/index/privacy_policy.html b/application/NewReedaw/view/app/index/privacy_policy.html
new file mode 100644
index 0000000..5ac2259
--- /dev/null
+++ b/application/NewReedaw/view/app/index/privacy_policy.html
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 隐私协议
+
+
+
+
+
+
+
+
Reedaw隐私协议
+
+
一、前言
+
感谢您选择使用我们的Reedaw体重饮食可视化管理APP(以下简称“本应用”)。我们深知您的个人信息安全至关重要,在您使用本应用后我们郑重承诺,将严格遵守相关法律法规,采取合理有效的措施保护您的个人隐私。本隐私协议旨在明确我们在采集、使用、存储、共享及保护您的个人信息的责任、义务。请您在使用本应用前,仔细阅读并理解本协议内容,一旦您开始使用本应用,即视为您同意我们使用您的个人信息,接受本协议的全部条款。
+
二、信息收集
+
1.必要信息:为了提供基本服务,我们可能会采集您的基本信息,包括但不限于邮箱、姓名(可选择匿名使用)等。这些信息将用于验证您的身份、保障账号安全及提供个性化服务。
+
2.健康数据:在使用本应用进行身体数据健康评估时,我们会采集您的饮食、身高、体重等健康数据。这些数据将用于生成评估报告,并尽量提供相应的健康建议。
+
3.设备信息:为了优化服务体验,我们可能会采集您的设备型号、操作系统版本、IP地址等必要的技术信息。这些信息将帮助我们了解用户的使用环境,以便进行技术调试和服务改进。
+
三、信息使用
+
1.服务提供:我们将根据您提供的信息,为您提供饮食数据评估服务,并生成相应的评估报告。
+
2.个性化推荐:基于您的饮食数据和使用习惯,我们可能会向您推荐适合的饮食管理方案。
+
3.数据分析:我们会对收集到的数据进行匿名化处理,用于统计分析,以改进我们的产品和服务。这些统计数据将不包含任何可以识别您个人身份的信息。
+
四、信息共享与披露
+
1.内部共享:我们可能会将您的信息共享给公司内部负责处理您个人信息的部门或人员,以确保为您提供更好的服务。
+
2.第三方合作:在必要且合法的情况下,我们可能会与第三方服务提供商(如云服务提供商、数据分析公司等)共享您的个人信息,以便他们为我们提供技术支持或数据分析服务。我们将与这些第三方签订严格的保密协议,并要求他们遵守相关法律法规和本协议的规定。
+
3.法律要求:在法律法规要求或政府部门、司法机关要求的情况下,我们可能会依法披露您的个人信息。
+
4.其他4.其他对您的服务性应用。
+
五、信息安全
+
1.技术保障:我们将采取合理的技术手段和管理措施,确保您的个人信息在采集、存储、使用、共享等过程中的安全。
+
2.数据加密:对于敏感信息,我们将采用加密技术进行处理,防止数据在传输和存储过程中被非法访问或泄露。
+
3.访问控制:我们将对访问个人信息的员工进行严格的权限管理,确保只有授权人员才能访问相关信息。
+
六、用户权利
+
1.知情权:您有权了解我们采集、使用、共享及保护您个人信息的详细情况。
+
2.选择权:您有权选择是否向我们提供个人信息的具体内容,以及选择是否接受我们的个性化推荐服务。
+
3.更正权:如果您发现我们采集的个人信息有误,您有权要求我们及时更正。
+
4.屏蔽权:在符合法律法规要求的情况下,您有权要求我们屏蔽您的个人信息全部内容。
+
七、协议变更
+
我们有权根据法律法规的变化或业务发展的需要,对本隐私协议进行修订。修订后的协议将通过本应用内通知或其他适当方式告知您。请您定期查阅本隐私协议,以便及时了解我们的最新政策。
+
八、争议解决
+
如因本协议产生任何争议,双方应首先通过友好协商解决;协商不成的,任何一方均有权向本应用运营方所在地的法院提起诉讼。
+
九、生效与终止
+
本协议自您同意并接受之日起生效,并持续有效至您注销账号或本应用终止服务时止。
+
+
+
+
+
diff --git a/application/NewReedaw2/controller/app/Base.php b/application/NewReedaw2/controller/app/Base.php
index 4d491a6..d8a8309 100644
--- a/application/NewReedaw2/controller/app/Base.php
+++ b/application/NewReedaw2/controller/app/Base.php
@@ -1,6 +1,6 @@
'app_user_data',
'4'=>'pc_vitalcapacity_standard',
'5'=>'admin_estimate',
- '6'=>'app_account_number'
+ '6'=>'app_account_number',
+ 'search_history'=>'app_user_search_history',
+ 'foodlist4'=>'app_z_national_standard_food_type_4',
+ 'user'=>'app_user_data'
];
public $test_token = ['57bd45e3a963b372ea2d873e4bd8d1f8','e0966788d02cc93290d9d674921d9715'];
@@ -80,15 +83,8 @@ class Base extends Controller{
return false;//跟数据库比对过,存在无效数值
}
}
- public function validate_user_identity($data) {
- $validate_user = Db::table($this->base_use_db_name['3'])->where(['id'=>$data])->count();
- if($validate_user<=0){
- return false;
- }else{
- return true;
- }
- }
- // 判断字符串是手机还是邮箱
+
+ // 判断字符串是手机还是邮箱(有用)
public function is_tel_email($str) {
// 手机号码的正则表达式(中国大陆格式)(下面正则实际判断的是是否为11位数字)
$mobilePattern = '/^\d{11}$/';
@@ -106,7 +102,7 @@ class Base extends Controller{
return false;
}
- // 计算年龄
+ // 计算年龄(有用)
public function calculate_age($data = '1991-04-20'){
$today = time(); // 获取当前时间的 Unix 时间戳
$birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳
@@ -121,7 +117,7 @@ class Base extends Controller{
return false;
}
}
- // 秒转化格式,00:00:00
+ // 秒转化格式,00:00:00(有用)
public function handle_hour_branch_second($data = '2000'){
$data = abs($data);
$hours = intval($data / 3600);
@@ -134,7 +130,7 @@ class Base extends Controller{
];
}
- // 判断token是否过期
+ // 判断token是否过期(有用)
public function token_time_validate($token){
// 591b70e0d80b5fa6d77e6e1384453ab9
if(is_string($token)){
@@ -189,7 +185,7 @@ class Base extends Controller{
}
}
- // 计算天数
+ // 计算天数(有用)
public function daysSince($pastDate,$now = false)
{
// 创建一个表示过去日期的 DateTime 对象
@@ -206,7 +202,7 @@ class Base extends Controller{
return $interval->format('%a');
}
- // 计算月龄
+ // 计算月龄(有用)
public function calculateAgeInMonthsWithPrecision($birthDateStr) {
// 获取当前日期
$now = new \DateTime();
@@ -224,28 +220,32 @@ class Base extends Controller{
$ageInMonthsPrecise = intval($ageInMonths + $partialMonth);
return $ageInMonthsPrecise;
}
- // 曲线页面-底部统计动作
- public function base_target_initial_cumulative_weight($data = []){
- // 第一种:用户详情(所有数据都有)
- // 第二种:手动记录(只有最新体重)
- // 第三种:修改原始体重(只有原始体重)
- // $result_data['target_weight'] 目标体重
- // $result_data['initial_weight'] 最初体重
- // $result_data['weight'] 最近一次测量重量
- // $result_data['initial_date'] 初始体重日期
- if(count($data) > 0){
- $result_data['target_weight'] = $data['target_weight'];
- $result_data['initial_weight'] = $data['initial_weight'];
- $result_data['cumulative_weight'] = bcsub($data['weight'],$data['initial_weight'],2);
- $result_data['cumulative_day'] = $data['initial_date'] == 0?0:$this->daysSince($data['initial_date']);
- }else{
- $result_data['target_weight'] = 0;
- $result_data['initial_weight'] = 0;
- $result_data['cumulative_weight'] = 0;
- $result_data['cumulative_day'] = 0;
- }
- return $result_data;
- }
+
+
+ // // 曲线页面-底部统计动作
+ // public function base_target_initial_cumulative_weight($data = []){
+ // // 第一种:用户详情(所有数据都有)
+ // // 第二种:手动记录(只有最新体重)
+ // // 第三种:修改原始体重(只有原始体重)
+ // // $result_data['target_weight'] 目标体重
+ // // $result_data['initial_weight'] 最初体重
+ // // $result_data['weight'] 最近一次测量重量
+ // // $result_data['initial_date'] 初始体重日期
+ // if(count($data) > 0){
+ // $result_data['target_weight'] = $data['target_weight'];
+ // $result_data['initial_weight'] = $data['initial_weight'];
+ // $result_data['cumulative_weight'] = bcsub($data['weight'],$data['initial_weight'],2);
+ // $result_data['cumulative_day'] = $data['initial_date'] == 0?0:$this->daysSince($data['initial_date']);
+ // }else{
+ // $result_data['target_weight'] = 0;
+ // $result_data['initial_weight'] = 0;
+ // $result_data['cumulative_weight'] = 0;
+ // $result_data['cumulative_day'] = 0;
+ // }
+ // return $result_data;
+ // }
+
+
// 判断一个参数是否为数字且大于等于0
public function isPositiveNumber($value) {
@@ -285,38 +285,39 @@ class Base extends Controller{
if(!$grade){
return [];
}
- if($grade['grade'] == 'nothing'){
- // 计算年龄判断是属于哪个年级
- $user_age = $this->calculate_age($grade['birthday']);
- if($user_age <= 7){
- $grade['grade'] = 'grade_s_1';
- }else if($user_age == 8){
- $grade['grade'] = 'grade_s_2';
- }else if($user_age == 9){
- $grade['grade'] = 'grade_s_3';
- }else if($user_age == 10){
- $grade['grade'] = 'grade_s_4';
- }else if($user_age == 11){
- $grade['grade'] = 'grade_s_5';
- }else if($user_age == 12){
- $grade['grade'] = 'grade_s_6';
- }else if($user_age == 13){
- $grade['grade'] = 'grade_m_1';
- }else if($user_age == 14){
- $grade['grade'] = 'grade_m_2';
- }else if($user_age == 15){
- $grade['grade'] = 'grade_m_3';
- }else if($user_age == 16){
- $grade['grade'] = 'grade_h_1';
- }else if($user_age == 17){
- $grade['grade'] = 'grade_h_2';
- }else if($user_age == 18){
- $grade['grade'] = 'grade_h_3';
- }else if($user_age == 19 || $user_age == 20){
- $grade['grade'] = 'grade_u_12';
- }else if($user_age >= 21){
- $grade['grade'] = 'grade_u_34';
- }
+ // if($grade['grade'] == 'nothing'){
+ // // 计算年龄判断是属于哪个年级
+
+ // }
+ $user_age = $this->calculate_age($grade['birthday']);
+ if($user_age <= 7){
+ $grade['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $grade['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $grade['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $grade['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $grade['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $grade['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $grade['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $grade['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $grade['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $grade['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $grade['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $grade['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $grade['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $grade['grade'] = 'grade_u_34';
}
$sql_min = "WITH RankedGrades AS (
SELECT
@@ -593,11 +594,48 @@ class Base extends Controller{
case 'intnum':
// 整数验证 - 必须是整型或纯整数字符串
// 使用 filter_var 同时验证整型和整数字符串
- return filter_var($data, FILTER_VALIDATE_INT) !== false;
+ // 必须是 >0 的整数或字符串整数
+ $filtered = filter_var($data, FILTER_VALIDATE_INT);
+ return $filtered !== false && $filtered > 0;
+
+ case 'intnum_0':
+ // 整数验证 - 必须是整型或纯整数字符串
+ // 使用 filter_var 同时验证整型和整数字符串
+ // 必须是 >0 的整数或字符串整数
+ $filtered = filter_var($data, FILTER_VALIDATE_INT);
+ return $filtered !== false;
+
+ case 'arr_intnum':
+ // 一维整数数组验证 - 必须是非空数组,且所有元素都是整数
+ // 1. 先检查是否是数组
+ if (!is_array($data)) {
+ return false;
+ }
+
+ // 2. 检查数组是否为空
+ if (empty($data)) {
+ return false;
+ }
+
+ // 3. 检查是否是一维数组
+ foreach ($data as $item) {
+ if (is_array($item)) {
+ return false; // 包含多维数组,不是一维数组
+ }
+ }
+
+ // 4. 验证所有元素都是整数
+ foreach ($data as $item) {
+ $filtered = filter_var($item, FILTER_VALIDATE_INT);
+ if ($filtered === false) {
+ return false; // 不是整数
+ }
+ }
+ return true;
case 'datetime':
// 日期时间验证 - 保持原有逻辑不变
- $formats = ['Y-m-d', 'Y-m-d H:i:s'];
+ $formats = ['Y', 'Y-m', 'Y-m-d', 'Y-m-d H:i:s'];
foreach ($formats as $format) {
$dateTime = \DateTime::createFromFormat($format, $data);
if ($dateTime && $dateTime->format($format) === $data) {
@@ -612,7 +650,7 @@ class Base extends Controller{
}
- // 处理身高体重的单位,转换它们为cm和kg。
+ // 处理身高体重的单位,转换它们为cm和kg。(有用)
public function convertHeightAndWeight($height, $weight) {
// 加 bcadd(,,20)
// 减 bcsub(,,20)
@@ -629,6 +667,9 @@ class Base extends Controller{
];
$weightConversion = [
'kg' => 1,
+ '公斤' => 1,
+ 'g' => 0.001,
+ '克' => 0.001,
'斤' => 0.5, // 1斤 = 0.5kg
'st:lb' => function($value) {
list($st, $lb) = explode(':', $value);
@@ -670,7 +711,7 @@ class Base extends Controller{
// 处理 weight
- if (preg_match('/([\d.:]+)(kg|斤|st:lb|lb)/', $weight, $matches)) {
+ if (preg_match('/([\d.:]+)(kg|公斤|g|克|斤|st:lb|lb)/', $weight, $matches)) {
$weightValue = $matches[1];
$weightUnit = $matches[2];
if($weightUnit == 'st:lb'){
@@ -706,35 +747,376 @@ class Base extends Controller{
];
}
-
-
+ ##########################################################以下是厨房秤的内容##########################################################
+ ##########################################################以下是厨房秤的内容##########################################################
+ ##########################################################以下是厨房秤的内容##########################################################
- public function ceshiyong($aa = 4,$gd = 0.2){
+ // 计算常规卡路里
+ public function count_user_nutrition_all($data){
+ // 计算基础代谢率(BMR)
+ if($data['gender'] == 1){
+ // 男性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) + 5
+ $bmr = bcmul(10,$data['weight'],20);
+ $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ $bmr = bcadd($bmr,5,2);
+ }else if($data['gender'] == 2){
+ // 女性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) - 161
+ $bmr = bcmul(10,$data['weight'],20);
+ $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20);
+ $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20);
+ $bmr = bcsub($bmr,161,2);
+ }else{
+ return $this->msg(10003,'性别未知');
+ }
- phpinfo();
- die;
- $token = 'cd3f27cf4c4002170ea7bceeb723ac91';
-
- $data = Db::table('pc_bmistand2')->select();
- for ($i=0; $i < count($data); $i++) {
- foreach ($data[$i] as $key => $value) {
- $data[$i][$key] = str_replace(' ', '',$data[$i][$key]);
-
+ // 每日总能量消耗(TDEE)
+ // 久坐(很少或没有运动):BMR × 1.2
+ // 轻度活动(每周1-3天轻度运动):BMR × 1.375
+ // 中度活动(每周3-5天中度运动):BMR × 1.55
+ // 高度活动(每周6-7天高强度运动):BMR × 1.725
+ // 极高活动(体力劳动或每天高强度训练):BMR × 1.9
+ if(array_key_exists('activity_level',$data)){
+ if($data['activity_level'] != null){
+ $tdee = bcmul($bmr,$data['activity_level'],2);
+ }else{
+ $tdee = bcmul($bmr,1.55,2);
}
- Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([
- 'month'=>$data[$i]['month'],
- 'sex'=>$data[$i]['sex'],
- // 'f3sd'=>$data[$i]['f3sd'],
- // 'f2sd'=>$data[$i]['f2sd'],
- 'f1sd'=>$data[$i]['f1sd'],
- 'median'=>$data[$i]['median'],
- 'z1sd'=>$data[$i]['z1sd'],
- 'z2sd'=>$data[$i]['z2sd'],
- // 'z3sd'=>$data[$i]['z3sd'],
+ }else{
+ $tdee = bcmul($bmr,1.55,2);
+ }
+
+
+ // 碳水化合物:通常占总热量的45-65%
+ // 蛋白质:通常占总热量的10-35%
+ // 脂肪:通常占总热量的20-35%
+ // 孩子&成年人:碳水化合物50%,蛋白质20%,脂肪30%。
+ // 老人:碳水化合物50%,蛋白质25%,脂肪25%。
+ // 建议每日摄入量计算:
+ // 1.碳水化合物(克): (TDEE × 碳水化合物比例) / 4
+ // 2.蛋白质(克):(TDEE × 蛋白质比例) / 4
+ // 3.脂肪(克): (TDEE × 脂肪比例) / 9
+
+ $carbohydrate_p = 0.5;
+ $carbohydrate = bcdiv(bcmul($tdee,0.5,20),4,2);
+ if($data['age_num'] < 65){
+ $protein_p = 0.2;
+ $fat_p = 0.3;
+ $protein = bcdiv(bcmul($tdee,0.2,20),4,2);
+ $fat = bcdiv(bcmul($tdee,0.3,20),9,2);
+ }else{
+ $protein_p = 0.25;
+ $fat_p = 0.25;
+ $protein = bcdiv(bcmul($tdee,0.25,20),4,2);
+ $fat =bcdiv(bcmul($tdee,0.25,20),9,2);
+ }
+ return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr,'carbohydrate_p'=>$carbohydrate_p,'protein_p'=>$protein_p,'fat_p'=>$fat_p];
+ }
+
+ // 计算营养物质
+ public function calculate_nutrients($data){
+ // dump($data);
+ $food_id_arr = [];
+ for ($i=0; $i < count($data); $i++) {
+ $food_id_arr[] = $data[$i]['food_id'];
+ }
+
+ $cfc = Db::connect('cfc_db');
+
+ // dump($data);
+ // dump(implode(",",$food_id_arr));
+ $nutrients_list = $cfc->table($this->base_use_db_name['foodlist4'])
+ ->where("father_id in (".implode(",",$food_id_arr).")")
+ // ->field()
+ ->select();
+
+ $nutrients_arr = ['VitaminA','VitaminB1','VitaminB2','VitaminB6','VitaminB12','VitaminD','VitaminK','Niacin','VitaminC','VitaminE','FolicAcid','Biotin','PantothenicAcid','TotalCholine','Ca','Phosphorus','Kalium','Mg','Na','Fe','Zn','Se','Cu','Mn','Iodine'];
+ // dump($nutrients_list);
+ // die;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ for ($i=0; $i < count($data); $i++) {
+ $zong_all = bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20);
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '卡路里',
+ 'unit' => 'kcal',
+ 'color' => '',
+ 'value' => $data[$i]['kcal_val'],
+ 'proportion' => 0,
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '蛋白质',
+ 'unit' => 'g',
+ 'color' => '#5180D8',
+ 'value' => $data[$i]['protein_val'],
+ 'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['protein_val'],$zong_all,2),100,0),
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '脂肪',
+ 'unit' => 'g',
+ 'color' => '#ED7886',
+ 'value' => $data[$i]['fat_val'],
+ 'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['fat_val'],$zong_all,2),100,0),
+ ];
+ $data[$i]['nutrients_four'][] = [
+ 'name' => '碳水化合物',
+ 'unit' => 'g',
+ 'color' => '#FFB169',
+ 'value' => $data[$i]['carbohydrate_val'],
+ 'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['carbohydrate_val'],$zong_all,2),100,0),
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Calorie',
+ 'name_ch' => '卡路里',
+ 'unit' => 'kcal',
+ 'value' => $data[$i]['kcal_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Protein',
+ 'name_ch' => '蛋白质',
+ 'unit' => 'g',
+ 'value' => $data[$i]['protein_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Fat',
+ 'name_ch' => '脂肪',
+ 'unit' => 'g',
+ 'value' => $data[$i]['fat_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ $data[$i]['nutrients_list'][] = [
+ 'name' => 'Carbohydrate',
+ 'name_ch' => '碳水化合物',
+ 'unit' => 'g',
+ 'value' => $data[$i]['carbohydrate_val'],
+ 'type' => 1,
+ 'type_name' => '能量及宏量营养素',
+ 'color' => '#C4FFE0',
+ ];
+ foreach ($nutrients_list as $key => $value) {
+ if($value['father_id'] == $data[$i]['food_id']){
+ if(in_array($value['name'],$nutrients_arr)){
+ $data[$i]['nutrients_list'][] = [
+ 'name' => $value['name'],
+ 'name_ch' => $value['name_ch'],
+ 'unit' => $value['unit'],
+ 'value' => bcmul($value['value'],bcdiv($data[$i]['weight'],100,20),2),
+ 'type' => $value['type'],
+ 'type_name' => $value['type'] == 1?'能量及宏量营养素':($value['type'] == 2?'维生素':($value['type'] == 3?'矿物质':'')),
+ 'color' => $value['type'] == 1?'#C4FFE0':($value['type'] == 2?'#FFEFB7':($value['type'] == 3?'#7DA8E0':'')),
+ ];
+ }
+
+ }
+ }
+ }
+ return $data;
+ }
+
+
+ public function add_search_history_action($data){
+ // 添加一条搜索记录start
+ // $data['id']是账号id
+ // $cfc = Db::connect('cfc_db');
+ $insert_search_log = Db::table($this->base_use_db_name['search_history'])->where(['user_id'=>$data['id'],'keyword'=>$data['search_data'],'type'=>$data['type']])->field('id,search_count')->find();
+ if($insert_search_log){
+ Db::table($this->base_use_db_name['search_history'])->where(['id'=>$insert_search_log['id']])->update([
+ 'search_count'=>$insert_search_log['search_count']+1,
+ 'last_searched_at'=>date('Y-m-d H:i:s'),
+ ]);
+ }else{
+ Db::table($this->base_use_db_name['search_history'])->insert([
+ 'user_id'=>$data['id'],
+ 'keyword'=>$data['search_data'],
+ 'type'=>$data['type'],
]);
}
- die;
+ // 添加一条搜索记录end
+ }
+
+ /**
+ * 将重量转换为克(g)
+ * @param string $weight 重量值
+ * @param string $unit 单位 (g, oz, lb, lb:oz)
+ * @return float 转换后的克重
+ */
+ public function convertWeightToGrams($weight = 100, $unit = 'oz') {
+
+
+
+ // 定义精确的转换常量
+ $G_PER_OZ = '28.349523125';
+ $G_PER_LB = '453.59237';
+
+ $unit = strtolower($unit);
+ $result = 0;
+
+ switch ($unit) {
+ case 'g':
+ case '克':
+ case 'ml':
+ case '毫升':
+ // 已经是克,直接返回
+ $result = $weight;
+ break;
+
+ case 'oz':
+ case '盎司':
+ // 盎司转克
+ $result = bcmul($weight,$G_PER_OZ,2);
+ break;
+
+ case 'lb':
+ case '磅':
+ // 磅转克
+ $result = bcmul($weight,$G_PER_LB,2);
+ break;
+
+ case 'lb:oz':
+ case '磅:盎司':
+ // 磅:盎司复合单位处理
+ if (strpos($weight, ':') !== false) {
+ $temporary_data = explode(':', $weight);
+ $result = bcadd(bcmul($temporary_data[0],$G_PER_LB,20),bcmul($temporary_data[1],$G_PER_OZ,20),20);
+ } else {
+ // 如果格式不正确,可以抛出异常或返回0
+ $result = '0';
+ }
+ break;
+
+ default:
+ $result = '0';
+ }
+
+ // 保留两位小数并返回(目前不做截取,全额返回)
+ return $result;
+ }
+
+
+
+
+ // 以下是测试时使用
+
+
+ public function ceshiyong_page(){
+
+ }
+ public function ceshiyong(){
+
+ // 老身体数据并入新身体数据
+ $test_data = Db::table('app_card_body_data')->where(['test_type'=>null,'aud_id'=>61])->page('1,100')->select();
+ // $test_data = Db::table('app_card_body_data')->where(['id'=>30883])->page('1,10')->select();
+ // $insert_search_log = Db::table('app_card_body_data_new')->where(['aud_id'=>61])->select();
+ // dump($test_data);
+ // die;
+ $temporary_data = [];
+
+ $data = [];
+ foreach ($test_data as $key => $value) {
+ $data = [];
+ $data = [
+ 'bmi' => (float)$value['bmi_val'],
+ 'bmilevel' => '',
+ 'bm' => explode(',',$value['bone'])[0],
+ 'rom' => explode(',',$value['muscle'])[0],
+ 'vwc' => explode(',',$value['water'])[0],
+ 'bfr' => explode(',',$value['fat_r'])[0],
+ 'sfr' => explode(',',$value['sfr'])[0],
+ 'pp' => explode(',',$value['protein'])[0],
+ 'uvi' => explode(',',$value['visceral'])[0],
+ 'bmr' => explode(',',$value['kcal'])[0],
+ 'bodyage' => (float)$value['body_age'],
+ 'weight' => (float)$value['weight_val'],
+ 'height' => (float)$value['height_val'],
+ 'age' => $value['age'],
+ 'adc' => 550,
+ 'sex' => 0,
+ 'romval' => explode(',',$value['muscleval'])[0],
+ 'ppval' => explode(',',$value['proteinval'])[0],
+ 'bfrval' => explode(',',$value['fat_w'])[0],
+ 'lbm' => 0,
+ 'fatlevel' => 0,
+ 'fatlevelname' => $value['body_level'],
+ 'body' => $value['body_type'],
+ 'cmi' => $value['score'],
+ 'standardlist' => null
+ ];
+ $temporary_data[] = [
+ 'id'=>$value['id'],
+ 'create_time'=>$value['create_time'],
+ 'acd_id'=>$value['acd_id'],
+ 'aud_id'=>$value['aud_id'],
+ 'record_time'=>$value['record_time'],
+ 'age'=>$value['age'],
+ 'is_del'=>$value['is_del'],
+ 'record_type'=>$value['record_type'],
+ 'height'=>(float)$value['height_val'],
+ 'weight'=>(float)$value['weight_val'],
+ 'bmi'=>(float)$value['bmi_val'],
+ 'score'=>$value['score'],
+ 'fat_r'=> explode(',',$value['fat_r'])[0],
+ 'fat_w'=> explode(',',$value['fat_w'])[0],
+ 'muscle'=> explode(',',$value['muscle'])[0],
+ 'muscleval'=> explode(',',$value['muscleval'])[0],
+ 'water'=>explode(',',$value['water'])[0],
+ 'protein'=>explode(',',$value['protein'])[0],
+ 'proteinval'=>explode(',',$value['proteinval'])[0],
+ 'bone'=>explode(',',$value['bone'])[0],
+ 'kcal'=>explode(',',$value['kcal'])[0],
+ 'visceral'=>explode(',',$value['visceral'])[0],
+ 'sfr'=>explode(',',$value['sfr'])[0],
+ 'body_level'=>$value['body_level'],
+ 'body_type'=>$value['body_type'],
+ 'body_age'=>(float)$value['body_age'],
+ 'heart_rate'=>$value['heart_rate'],
+ 'head_circumference'=>$value['head_circumference'],
+ '8_electrode_data'=>null,
+ '4_electrode_data'=>json_encode($data),
+ 'head_circumference_val'=>$value['head_circumference']?json_decode($value['head_circumference'],true)['value']:null,
+ ];
+ }
+
+ foreach ($temporary_data as $key => $value) {
+
+ $id = $value['id'];
+ $xh_data = $value;
+ unset($xh_data['id']);
+ // dump($xh_data);
+ // 启动事务
+ Db::startTrans();
+ try{
+ Db::table('app_card_body_data_new')->insert($xh_data);
+ Db::table('app_card_body_data')->where(['id'=>$id])->update(['test_type'=>'1']);
+ // 提交事务
+ Db::commit();
+ dump('OK');
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ dump($id);
+ // 记录异常信息
+ dump('事务回滚原因:' . $e->getMessage());
+ // dump('异常文件:' . $e->getFile());
+ // dump('异常行号:' . $e->getLine());
+ // dump('SQL错误代码:' . $e->getCode());
+ // dump('########################################################################################################');
+ // break;
+ }
+
+ }
+ // dump($temporary_data);
+ // die;
// $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']);
}
diff --git a/application/NewReedaw2/controller/app/Body.php b/application/NewReedaw2/controller/app/Body.php
index eb4f3e1..444174c 100644
--- a/application/NewReedaw2/controller/app/Body.php
+++ b/application/NewReedaw2/controller/app/Body.php
@@ -1,13 +1,10 @@
[]
];
protected $age_limit = 16;
+ protected $pagesize = 15;
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 $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'=>'%',];
protected $standard_color = [
@@ -85,7 +83,7 @@ class Body extends Base{
public function body_report(){
// phpinfo();
// die;
- // try {
+ try {
$data = input('post.');
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
return $this->msg(10001);
@@ -97,20 +95,243 @@ class Body extends Base{
return $this->msg(10005,'aud_id type error');
}
return $this->body_report_action_detailed($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);
- // }
+ } 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 manual_record(){
+ try {
+
+ $data = input('post.');
+ 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);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ if(strlen($data['time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['time'] = $this->addCurrentTimeToDateString($data['time']);
+ }
+ // $data['acd_id'] = '2';
+ return $this->set_user_body_data($data,'by_hand_means');
+ } 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 device_record(){
+ try {
+ // 你的业务逻辑
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['adc'],'num')){
+ return $this->msg(10005,'adc type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ // 检测设备传过来的info信息
+ if(array_key_exists('info', $data)){
+ if (!is_array($data['info'])) {
+ return $this->msg(10005,'info参数格式错误');
+ }else{
+ $info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
+ foreach ($data['info'] as $key => $value) {
+ if (!in_array($key, $info_data_arr)) {
+ return $this->msg(10005,'info参数格式错误-2');
+ }
+ }
+ }
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ $data['time'] = date('Y-m-d H:i:s');
+ return $this->set_user_body_data($data,'by_device');
+ } 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 record_list_page(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'page');
+ } 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 record_list_group(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->record_list_page_or_group_action($data,'group');
+ } 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 detailed_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->get_all_detaile_data_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 删除历史数据
+ public function del_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $user_data = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
################################################################action################################################################
################################################################action################################################################
@@ -223,8 +444,10 @@ class Body extends Base{
}
// 暂时存储头围数据
$head_circumference = $body_last_data[0]['head_circumference']?json_decode($body_last_data[0]['head_circumference'],true):false;
+
unset($body_last_data[0]['head_circumference']);
// 处理返回数据
+
$result_end = $this->processing_return_data_new($body_last_data[0]);
$cardparts = new Cardparts;
@@ -233,7 +456,9 @@ class Body extends Base{
$result_end['score'] = $result_end['score'];
$result_end['body_type'] = $result_end['body_type'];
+
$result_end = $cardparts->conversion_interval($result_end);
+ // return $this->msg($result_end);
$result_end['cplist'] = $this->grow_up_recommendation([
'birthday'=>$body_last_data[0]['birthday'],
'body'=>[
@@ -242,6 +467,7 @@ class Body extends Base{
'bmi'=>$body_last_data[0]['bmi']
],
]);
+ // return $this->msg($result_end);
// // 加入曲线板块底部的减肥计划数据start
// $result_end['target_current'] = $this->base_target_initial_cumulative_weight([
@@ -307,6 +533,9 @@ class Body extends Base{
// 这段业务处理可以删除,是做的临时的,假的start
$biaozhun_val = $this->body_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']);
+ //
+ // dump($biaozhun_val);
+ // die;
// dump($biaozhun_val);
// $biaozhun_val_weight = 50;
// $biaozhun_val_height = 170;
@@ -344,7 +573,318 @@ class Body extends Base{
// dump($result_end);
}
+ // 用户身体数据卡片记录
+ public function set_user_body_data($data,$type){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 判断头围数据是否存在是否合理
+ if(array_key_exists('head_data', $data)){
+ if(!$this->verify_data_is_ok($data['head_data'],'num')){
+ return $this->msg(10005);
+ }
+ $data['head_circumference'] = $data['head_data'];
+ }else{
+ $data['head_circumference'] = 0;
+ }
+
+ // 查询用户信息
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
+
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 如果最初体重设置为null
+ if($user_data['initial_date'] == null){
+ Db::table($this->body_db_name['juese'])->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'],
+ ]);
+ }
+ // 设置身高、体重、年龄、性别、阶段称谓、头围、生日、阻抗
+ $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['head_circumference'] = $data['head_circumference'];
+ $result_data['birthday'] = $user_data['birthday'];
+ if(array_key_exists('adc', $data)){
+ if($data['adc'] > 0){
+ $result_data['adc'] = $data['adc'];
+ $type = "by_device_adc";
+ }else{
+ $result_data['adc'] = 550;
+ $type = "by_device";
+ }
+ }
+ $calculate_body_formula = new Calculatebody();
+
+ // 计算身体数据
+ $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data);
+
+ if($get_body_value === false){
+ return $this->msg(10005);
+ }
+
+ // 如果年纪小于三岁,处理头围数据star
+ $standardlist = [];
+ if($result_data['age'] < 3){
+ if(array_key_exists('standardlist',$get_body_value)){
+ $standardlist = $get_body_value['standardlist'];
+ foreach ($standardlist as $key => $value) {
+ if($value['name'] == 'head' && count($value['list'] ) > 0){
+ $standardlist = $value;
+ }
+ }
+ $standardlist['list2'] = [];
+ foreach ($standardlist['list'] as $key => $value) {
+ array_push($standardlist['list2'],[
+ 'min_val'=>$value['minvalue'],
+ 'max_val'=>$value['maxvalue'],
+ 'text'=>$value['text'],
+ 'color'=>$value['color']
+ ]);
+ }
+ unset($standardlist['list']);
+ unset($get_body_value['standardlist']);
+ }
+ }else{
+ if(array_key_exists('standardlist',$get_body_value)){
+ unset($get_body_value['standardlist']);
+ }
+ }
+ // 如果年纪小于三岁,处理头围数据end
+ $get_body_value['gender'] = $user_data['gender'];
+ $get_body_value['birthday'] = $user_data['birthday'];
+ // 添加身高、体重、bmi、头围(如果有)的标尺标准
+ $get_body_value = $this->hwb_standard($get_body_value);
+
+ $enumeration_data = [
+ 'fat_r'=>'脂肪率',
+ 'muscle'=>'肌肉率',
+ 'kcal'=>'基础代谢',
+ 'visceral'=>'内脏指数',
+ 'sfr'=>'皮下脂肪',
+ 'water'=>'水分',
+ 'bone'=>'骨重',
+ 'protein'=>'蛋白率',
+ 'bodyage'=>'身体年龄'
+ ];
+
+ // return $this->msg($get_body_value);
+ // 根据秤传过来的数据,去处理要存的结果
+ if(array_key_exists('info', $data)){
+
+
+ foreach ($data['info'] as $key => $value) {
+ if($key == 'bmi'){
+ if($value > 0){
+ $get_body_value['BMI'] = $value;
+ $get_body_value['BMI2'] = explode(',',$get_body_value['BMI2']);
+ $get_body_value['BMI2'][0] = $value;
+ $get_body_value['BMI2'] = implode(',',$get_body_value['BMI2']);
+ }
+ }else if($key == 'bodyage'){
+ $get_body_value[$enumeration_data[$key]] = $value;
+ }else if($key == 'fatlevlval'){
+ continue;
+ }else{
+ if($value > 0){
+ $get_body_value[$enumeration_data[$key]][0] = $value;
+ }
+ }
+ }
+ }
+
+ $set_data = [
+ 'acd_id'=>2,
+ 'aud_id'=>$data['aud_id'],
+ 'record_time'=>array_key_exists('time', $data)?$data['time']:date('Y-m-d H:i:s'),
+ '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['身高2'],
+ 'height_val'=>$get_body_value['身高'],
+ 'weight'=>$get_body_value['体重2'],
+ 'weight_val'=>$get_body_value['体重'],
+ 'bmi'=>$get_body_value['BMI2'],
+ 'bmi_val'=>$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['身体类型'],
+ 'body_age'=>$get_body_value['身体年龄'],
+ 'record_type' => $type,
+ 'head_circumference' => $result_data['age'] < 3?json_encode($standardlist):"",
+ ];
+ if(strlen($set_data['record_time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']);
+ }
+
+ // 启动事务
+ Db::startTrans();
+ try{
+ $set_user_data = Db::table($this->body_db_name['body_data'])->insert($set_data);
+ $update_arr = [
+ 'height'=>$get_body_value['身高'],
+ 'weight'=>$get_body_value['体重']
+ ];
+ if($data['head_circumference']>0){
+ $update_arr['head_data'] = $data['head_circumference'];
+ }
+ $update_user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
+ // 提交事务
+ Db::commit();
+ return $this->msg([
+ 'acd_id'=>2,
+ 'height'=>$get_body_value['身高'].',CM',
+ 'weight'=>$get_body_value['体重'].',公斤',
+ 'bmi'=>$get_body_value['BMI'],
+ 'target_current'=>$target_current,
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+ }
+ public function record_list_page_or_group_action($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->body_db_name['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) {
+ 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->body_db_name['body_data'])->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->body_db_name['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'=>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_all_detaile_data_action($data){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 设置排除在外的数据类型start
+ $exclude_data_arr = ['height','weight','age','bmi'];
+ // 设置排除在外的数据类型end
+ $result = Db::table($this->body_db_name['body_data'])->where(['id'=>$data['id']])->find();
+ $for_data_arr = ['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'=>['体型','']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ // 身体数据处理,如果没有阻抗,则只显示四项$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{
+ if(array_key_exists($key,$result)){
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ }
+
+ }
+ }
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ //
+ // 添加头围详细start
+ 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 processing_return_data_new($data){
$result_end_data = [];
$month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
@@ -655,9 +1195,86 @@ class Body extends Base{
}
return $return_data;
}
- // public function body_report_action_detailed($data){
- // }
+ // 添加身高体重bmi的标准
+ public function hwb_standard($data){
+ $linshi_data = [];
+ $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']);
+ $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($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->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($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->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($this->body_db_name['bmi'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select();
+ 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'];
+ }
+ }
+ }
+ foreach ($linshi_data as $key => $value) {
+ foreach ($value as $k => $v) {
+ if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){
+ // 如果落在区间内
+ $data[$key.'2'] = $data[$key].','.$v['text'].','.$v['color'];
+ break;
+ }
+ }
+ // 如果$key.'2'没有被设置
+ if(!array_key_exists($key.'2', $data)){
+ 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'];
+ }
+ }
+ }
+ // die;
+ }else{
+ $data['身高2'] = $data['身高'].',无,无';
+ $data['体重2'] = $data['体重'].',无,无';
+ $data['BMI2'] = $data['BMI'].',无,无';
+ }
+ return $data;
+ }
+
+
diff --git a/application/NewReedaw2/controller/app/Business.php b/application/NewReedaw2/controller/app/Business.php
new file mode 100644
index 0000000..d8ab8f5
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Business.php
@@ -0,0 +1,36 @@
+fetch();
+ }
+
+ public function business_cooperation_action(){
+ $data = input();
+ $result = Db::table('admin_business_cooperation_log')->insert([
+ 'name'=>$data['name'],
+ 'tel'=>$data['phone'],
+ 'company'=>$data['company'],
+ 'intention_data'=>implode(',',$data['selectedValues']),
+ 'notes_data'=>$data['remark'],
+ 'create_time'=>date('Y-m-d H:i:s'),
+ ]);
+ if($result){
+ $this->send_email_api_error(["19759414@qq.com"],['title'=>'商户合作','from_user_name'=>'reedaw商务','content'=>'有一封商户合作']);
+ // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'商户合作','from_user_name'=>'reedaw商务','content'=>'有一封商户合作']);
+
+ return json(['code'=>0,'msg'=>'提交成功']);
+ }else{
+ return json(['code'=>10001,'msg'=>'网络错误']);
+ // return json(['code'=>10001,'msg'=>'网络错误,请直接联系商务合作电话/微信:13590959084']);
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Calculatebody.php b/application/NewReedaw2/controller/app/Calculatebody.php
new file mode 100644
index 0000000..dda1ea1
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Calculatebody.php
@@ -0,0 +1,638 @@
+52.5,'height'=>165,'age'=>30,'gender'=>1]){
+ $data['gender'] = $data['gender'] == 0 ? 1 : $data['gender'];
+
+ $data['adc'] = array_key_exists('adc', $data)?$data['adc']:$this->default_adc;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 青测自己写的计算start
+ // $result = $this->calculate_body_data($data['height'],$data['weight'],$data['age'],$data['gender'],$data['adc']);
+ // // $result['fat_w'] = $result['fat_r'] / 100 * $data['weight'];
+ // $result['fat_w'] = bcmul(bcdiv($result['fat_r'],'100',20),$data['weight'],2);
+ // // $result['proteinval'] = $result['protein'] / 100 * $data['weight'];
+ // $result['proteinval'] = bcmul(bcdiv($result['protein'],'100',20),$data['weight'],2);
+ // //肌肉量=体重-脂肪量-骨量
+ // // $result['muscleval'] = $result['weight'] - $result['fat_w'] - $result['bone'];
+ // $result['muscleval'] = bcsub(bcsub($result['weight'],$result['fat_w'],20),$result['bone'],2);
+ // // $result['muscle'] = $result['muscleval'] / $data['weight'] * 100.0;
+ // $result['muscle'] = bcmul(bcdiv($result['muscleval'],$data['weight'],20),'100.0',2);
+ // // 水份=肌肉量-蛋白量
+ // // $result['water'] = $result['muscleval'] - $result['proteinval'];
+ // $result['water'] = bcsub($result['muscleval'],$result['proteinval'],2);
+ // // $result['lbm'] = (1 - $result['fat_r'] / 100) * $data['weight'];
+ // $result['lbm'] = bcmul(bcsub('1',bcdiv($result['fat_r'],'100',20),20),$data['weight'],2);
+ // 青测自己写的计算end
+
+ // 使用接口调用之前的进行计算start
+ $url = 'https://klcz.pcxbc.com/open-api/calc/healthcalc/bodyfat3';
+ if($data['age'] < '3'){
+ $temporary_parameter = [
+ 'weight'=>$data['weight'],
+ 'height'=>$data['height'],
+ 'age'=>round($data['age']),//四舍五入取整
+ 'adc'=>round($data['adc']),//四舍五入取整
+ 'gender'=>$data['gender'],
+ 'head'=>$data['head_circumference'],
+ 'hasStandardList'=>true,
+ 'birthDay'=>$data['birthday'],
+ ];
+ }else{
+ $temporary_parameter = [
+ 'weight'=>$data['weight'],
+ 'height'=>$data['height'],
+ 'age'=>round($data['age']),//四舍五入取整
+ 'adc'=>round($data['adc']),//四舍五入取整
+ 'gender'=>$data['gender'],
+ ];
+ }
+ $request_result = $this->postRequest($url,$temporary_parameter);
+ if($request_result['code'] != 0){
+ return false;
+ }
+
+ $result['weight'] = $request_result['data']['weight'];
+ $result['height'] = $request_result['data']['height'];
+ $result['bmi'] = $request_result['data']['bmi'];
+ $result['age'] = $request_result['data']['age'];
+ $result['cmi'] = $request_result['data']['cmi'];
+ $result['fat_w'] = $request_result['data']['bfrval'];
+ $result['fat_r'] = $request_result['data']['bfr'];
+ $result['muscleval'] = $request_result['data']['romval'];
+ $result['muscle'] = $request_result['data']['rom'];
+ $result['water'] = $request_result['data']['vwc'];
+ $result['proteinval'] = $request_result['data']['ppval'];
+ $result['protein'] = $request_result['data']['pp'];
+ $result['bone'] = $request_result['data']['bm'];
+ $result['kcal'] = $request_result['data']['bmr'];
+ $result['visceral'] = $request_result['data']['uvi'];
+ $result['sfr'] = $request_result['data']['sfr'];
+ $result['standard_level'] = $request_result['data']['fatlevelname'];
+ $result['bodyage'] = $request_result['data']['bodyage'];
+ $result['lbm'] = $request_result['data']['lbm'];
+ $result['body'] = $request_result['data']['body'];
+ // 使用接口调用之前的进行计算end
+
+ $return_data['standardlist'] = $request_result['data']['standardlist'];
+ $return_data['体重'] = $data['weight'];
+ $return_data['身高'] = $data['height'];
+ $return_data['BMI'] = $result['bmi'];
+ $return_data['age'] = $result['age'];
+
+ // 身体得分修改start
+ // if($result['bmi']<21.6){
+ // $return_data['身体得分'] = bcmul(bcdiv($result['bmi'],'21.6',20),'100',0);
+ // }else{
+ // $return_data['身体得分'] = bcmul(bcdiv('21.6',$result['bmi'],20),'100',0);
+ // }
+ $return_data['身体得分'] = $result['cmi'];
+ // 身体得分修改end
+
+ $return_data['脂肪量'][0] = $result['fat_w'];
+ $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['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['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['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] = '高';
+ }else{
+ $return_data['脂肪率'][1] = '异常';
+ $return_data['脂肪量'][1] = '异常';
+ }
+
+ $return_data['肌肉量'][0] = $result['muscleval'];
+ $return_data['肌肉率'][0] = $result['muscle'];
+ if(
+ ($data['gender']==1 && $result['muscle']<40) ||
+ ($data['gender']==2 && $result['muscle']<30)){
+ $return_data['肌肉量'][1] = '不足';
+ $return_data['肌肉率'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['muscle']>=40 && $result['muscle']<60) ||
+ ($data['gender']==2 && $result['muscle']>=30 && $result['muscle']<50)){
+ $return_data['肌肉量'][1] = '标准';
+ $return_data['肌肉率'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['muscle']>=60) ||
+ ($data['gender']==2 && $result['muscle']>=50)){
+ $return_data['肌肉量'][1] = '优';
+ $return_data['肌肉率'][1] = '优';
+ }else{
+ $return_data['肌肉量'][1] = '异常';
+ $return_data['肌肉率'][1] = '异常';
+ }
+
+ $return_data['水分'][0] = $result['water'];
+ if(
+ ($data['gender']==1 && $result['water']<55) ||
+ ($data['gender']==2 && $result['water']<45)){
+ $return_data['水分'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['water']>=55 && $result['water']<65) ||
+ ($data['gender']==2 && $result['water']>=45 && $result['water']<60)){
+ $return_data['水分'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['water']>65) ||
+ ($data['gender']==2 && $result['water']>60)){
+ $return_data['水分'][1] = '优';
+ }else{
+ $return_data['水分'][1] = '异常';
+ }
+
+ $return_data['蛋白量'][0] = $result['proteinval'];
+ $return_data['蛋白率'][0] = $result['protein'];
+ if(
+ ($data['gender']==1 && $result['protein']<16) ||
+ ($data['gender']==2 && $result['protein']<14)){
+ $return_data['蛋白量'][1] = '不足';
+ $return_data['蛋白率'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['protein']>=16 && $result['protein']<18) ||
+ ($data['gender']==2 && $result['protein']>=14 && $result['protein']<16)){
+ $return_data['蛋白量'][1] = '标准';
+ $return_data['蛋白率'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['protein']>18) ||
+ ($data['gender']==2 && $result['protein']>16)){
+ $return_data['蛋白量'][1] = '优';
+ $return_data['蛋白率'][1] = '优';
+ }else{
+ $return_data['蛋白量'][1] = '异常';
+ $return_data['蛋白率'][1] = '异常';
+ }
+
+ $return_data['骨重'][0] = $result['bone'];
+ if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']<2.4) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']<2.8) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.1) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']<1.7) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']<2.1) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']<2.4)){
+ $return_data['骨重'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']>=2.4 && $result['bone']<=2.6) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>=2.8 && $result['bone']<=3) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']>=3.1 && $result['bone']<=3.3) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']>=1.7 && $result['bone']<=1.9) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>=2.1 && $result['bone']<=2.3) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']>=2.4 && $result['bone']<=2.6)){
+ $return_data['骨重'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $data['weight']<60 && $result['bone']>2.6) ||
+ ($data['gender']==1 && $data['weight']>=60 && $data['weight']<75 && $result['bone']>3) ||
+ ($data['gender']==1 && $data['weight']>=75 && $result['bone']<3.3) ||
+ ($data['gender']==2 && $data['weight']<45 && $result['bone']>1.9) ||
+ ($data['gender']==2 && $data['weight']>=45 && $data['weight']<60 && $result['bone']>2.3) ||
+ ($data['gender']==2 && $data['weight']>=60 && $result['bone']>2.6)){
+ $return_data['骨重'][1] = '优';
+ }else{
+ $return_data['骨重'][1] = '异常';
+ }
+
+ $return_data['基础代谢'][0] = $result['kcal'];
+ if(
+ ($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)>$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)>$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)>$result['kcal'])){
+ $return_data['基础代谢'][1] = '偏低';
+ }else if(
+ ($data['gender']==1 && $data['age']>0 && $data['age']<3 && (60.9*$data['weight']-54)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=3 && $data['age']<10 && (22.7*$data['weight']+495)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=10 && $data['age']<18 && (17.5*$data['weight']+651)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=18 && $data['age']<30 && (15.3*$data['weight']+679)<=$result['kcal']) ||
+ ($data['gender']==1 && $data['age']>=30 && (11.6*$data['weight']+879)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>0 && $data['age']<3 && (61*$data['weight']-51)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=3 && $data['age']<10 && (22.5*$data['weight']+499)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=10 && $data['age']<18 && (12.2*$data['weight']+746)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=18 && $data['age']<30 && (14.7*$data['weight']+496)<=$result['kcal']) ||
+ ($data['gender']==2 && $data['age']>=30 && (8.7*$data['weight']+820)<=$result['kcal'])){
+ $return_data['基础代谢'][1] = '优';
+ }else{
+ $return_data['基础代谢'][1] = '异常';
+ }
+
+ $return_data['内脏指数'][0] = $result['visceral'];
+ if($result['visceral']<9){
+ $return_data['内脏指数'][1] = '标准';
+ }else if($result['visceral']>=9 && $result['visceral']<14){
+ $return_data['内脏指数'][1] = '警惕';
+ }else if($result['visceral']>=14){
+ $return_data['内脏指数'][1] = '危险';
+ }else{
+ $return_data['内脏指数'][1] = '异常';
+ }
+
+ $return_data['皮下脂肪'][0] = $result['sfr'];
+ if(
+ ($data['gender']==1 && $result['sfr']<7) ||
+ ($data['gender']==2 && $result['sfr']<11)){
+ $return_data['皮下脂肪'][1] = '不足';
+ }else if(
+ ($data['gender']==1 && $result['sfr']>=7 && $result['sfr']<15) ||
+ ($data['gender']==2 && $result['sfr']>=11 && $result['sfr']<17)){
+ $return_data['皮下脂肪'][1] = '标准';
+ }else if(
+ ($data['gender']==1 && $result['sfr']>=15) ||
+ ($data['gender']==2 && $result['sfr']>=17)){
+ $return_data['皮下脂肪'][1] = '偏高';
+ }else{
+ $return_data['皮下脂肪'][1] = '异常';
+ }
+ // 脂肪率:偏低 标准 偏高 高
+ // 肌肉率:不足 标准 优
+
+ // 肥胖等级修改start
+ // // if($data['age']>=16){
+ // if($result['standard_level']<-0.2){
+ // $return_data['肥胖等级'] = '体重不足';
+ // }else if($result['standard_level']>=-0.2 && $result['standard_level']<-0.1){
+ // $return_data['肥胖等级'] = '偏瘦';
+ // }else if($result['standard_level']>=-0.1 && $result['standard_level']<=0.1){
+ // $return_data['肥胖等级'] = '标准';
+ // }else if($result['standard_level']>0.1 && $result['standard_level']<=0.2){
+ // $return_data['肥胖等级'] = '偏重';
+ // }else if($result['standard_level']>0.2){
+ // $return_data['肥胖等级'] = '超重';
+ // }else{
+ // $return_data['肥胖等级'] = '暂无数据';
+ // }
+ // // }else{
+ // // $return_data['肥胖等级'] = '儿童';
+ // // }
+ $return_data['肥胖等级'] = $result['standard_level'];
+ // 肥胖等级修改end
+
+
+ // 身体类型修改start
+ // // if($data['age']>=16){
+ // if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '隐形肥胖';
+ // }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '偏胖';
+ // }else if(($return_data['脂肪率'][1] == '高' || $return_data['脂肪率'][1] == '偏高') && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '结实型偏胖';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '缺乏肌肉型';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '标准型';
+ // }else if($return_data['脂肪率'][1] == '标准' && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '标准肌肉型';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '不足'){
+ // $return_data['身体类型'] = '偏瘦';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '标准'){
+ // $return_data['身体类型'] = '偏瘦肌肉型';
+ // }else if($return_data['脂肪率'][1] == '偏低' && $return_data['肌肉率'][1] == '优'){
+ // $return_data['身体类型'] = '健美肌肉型';
+ // }else{
+ // $return_data['身体类型'] = '暂无数据';
+ // }
+ // // }else{
+ // // $return_data['身体类型'] = '儿童';
+ // // }
+ $return_data['身体类型'] = $result['body'];
+ // 身体类型修改end
+
+ $return_data['身体年龄'] = $result['bodyage'];
+
+ // $result_end['fat_r'] = $result['fat_r'];
+ // $result_end['muscle'] = $result['muscle'];
+ // $result_end['water'] = $result['water'];
+ // $result_end['bone'] = $result['bone'];
+ // $result_end['kcal'] = $result['kcal'];
+ // $result_end['fat_w'] = $result['fat_w'];
+ // $result_end['visceral'] = $result['visceral'];
+ // $result_end['protein'] = $result['protein'];
+ // $result_end['bodyage'] = $result['bodyage'];
+ // $result_end['bmi'] = $result['bmi'];
+ // // $result_end['cmi'] = $result['cmi'];
+ // $result_end['sfr'] = $result['sfr'];
+ // // $result_end['sfrval'] = $result['sfrval'];
+ // $result_end['skeletalmuscle'] = $result['skeletalmuscle'];
+ // $result_end['muscleval'] = $result['muscleval'];
+ // $result_end['proteinval'] = $result['proteinval'];
+ // $result_end['lbm'] = $result['lbm'];
+ // $result_end['weight'] = $result['weight'];
+ // $result_end['height'] = $result['height'];
+ return $return_data;
+ }
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ // 计算身体数据,BMI、脂肪率、脂肪量、肌肉率、肌肉量....
+ public function calculate_body_data($height,$weight,$age,$gender,$impedance){
+
+ $result_data = [];
+ $mheight = bcdiv($height, '100', 20); // 假设我们保留20位小数
+ $gender = $gender == 0 ? 1 : $gender;
+
+ if (($weight <= 0) || ($weight > 220) || ($height <= 0) || ($height > 270) || ($age <= 0) || ($age > 120) || ($impedance <= 0) || ($impedance > 1000) || !in_array($gender, [1, 2])) {
+ if ($weight != 0 && $height != 0) {
+ // 计算BMI
+ $bmi = bcdiv($weight, bcmul($mheight, $mheight,20), 2);
+ $result_data['bmi'] = $bmi;
+ $result_data['bone'] = 0;
+ $result_data['muscle'] = 0;
+ $result_data['water'] = 0;
+ $result_data['fat_r'] = 0;
+ $result_data['sfr'] = 0;
+ $result_data['skeletalmuscle'] = 0;
+ $result_data['protein'] = 0;
+ $result_data['visceral'] = 0;
+ $result_data['kcal'] = 0;
+ $result_data['bodyage'] = 0;
+ $result_data['weight'] = $weight;
+ $result_data['height'] = $height;
+ $result_data['age'] = $age;
+ $result_data['adc'] = $impedance;
+ $result_data['gender'] = $gender;
+ $result_data['standard_level'] = 0.0;
+ return $result_data;
+ }
+ }
+ $num = intval(bcmul(bcdiv($weight,bcmul($mheight,$mheight,20),20),'10',20))/10;
+ $num2 = 0.0;
+ $num3 = 0.0;
+ $num4 = 0.0;
+ $num5 = 0.0;
+ $num6 = 0.0;
+ $num7 = 0.0;
+ $num8 = 0.0;
+ $num9 = 0.0;
+ $num10 = 0.0;
+ $num11 = 0.0;
+ // 根据男女计算脂肪率、脂肪量、肌肉率、肌肉量等等....
+ $standard_weight = 0.0;
+ $standard_level = 0.0;
+ if ($gender == 1){
+ // $num2 = 0.015 * $weight + (2.0 - 0.00055 * $impedance) * $height / 100 - 1.15;
+ $num2 = bcsub(bcadd(bcmul('0.015',$weight,20),bcdiv(bcmul(bcsub('2.0',bcmul('0.00055',$impedance,20),20),$height,20),'100.0',20),20),'1.15',2);
+ // $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 15.4;
+ $num3 = bcsub(bcsub(bcsub(bcsub(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20)),$height,20),'100.0',20),20),bcmul($impedance,'0.08'),20),bcmul($age,'0.04'),20),'15.4',2);
+ // $num4 = 1000000.0/($num*(2.688*$impedance-78.28))-(10058/$impedance)-0.22*$age+52.6;
+ $num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.688',$impedance,20),'78.28',20),20),20),bcdiv('10058',$impedance,20),20),bcmul('0.22',$age,20),20),'52.6',20);
+ // $num5 = -930000.0 / $num / (1.966 * $impedance - 58.46) + (13176 / $impedance) - 0.06 * $age + 40.0;
+ $num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-930000.0',$num,20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('13176',$impedance,0),20),bcmul('0.06',$age,20),20),'40.0',20);
+ // $num6 = 0.898 * $num5;
+ $num6 = bcmul('0.898',$num5,1);
+ // $num7 = 0.895 * $num4;
+ $num7 = bcmul('0.895',$num4,20);
+ // $num8 = 0.8 * (100.0 - $num5 - $num4 - $num2 / $weight);
+ $num8 = bcmul('0.8',bcsub(bcsub(bcsub('100.0',$num5,20),$num4,20),bcdiv($num2,$weight,20),20),2);
+ // $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
+ $num9 = bcadd(bcadd(bcadd(bcsub(bcmul('0.304',$weight,20),bcdiv(bcmul('25.58',$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
+ // $num10 = (9.0 + 0.0015 * $impedance) * $weight + (1350.0 - 0.88 * $impedance) * $height / 100.0 + (188 / $age) + 0.748 * $impedance - 1053.0;
+ $num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd('9.0',bcmul('0.0015',$impedance,20),20),$weight,20),bcdiv(bcmul(bcsub('1350.0',bcmul('0.88',$impedance,20),20),$height,20),'100.0',20),20),bcdiv('188',$age,20),20),bcmul('0.748',$impedance,20),20),'1053.0',0);
+ // $num11 = $age * (1.0 + 0.012 * ($num - 1.0)) - 21.0 + (30 - $age) * 0.35 + ($impedance - 450) * 0.02 + 11.0;
+ $num11 = bcadd(bcadd(bcadd(bcsub(bcmul($age,bcadd('1.0',bcmul('0.012',bcsub($num,'1.0',20),20),20),20),'21.0',20),bcmul(bcsub('30',$age,20),'0.35',20),20),bcmul(bcsub($impedance,'450',20),'0.02',20),20),'11.0',0);
+
+ // $standard_weight = ($height-80)*0.7;
+ $standard_weight = bcmul(bcsub($height,'80',20),'0.7',20);
+
+ }else{
+ // $num2 = 2.2E-05 * $impedance * $weight + (4.99 - 0.00284 * $impedance) * $height / 100.0 + 0.0012 * $impedance - 4.45;
+ $num2 = bcsub(bcadd(bcadd(bcmul(bcmul('0.000022',$impedance,20),$weight,20),bcdiv(bcmul(bcsub('4.99',bcmul('0.00284',$impedance,20),20),$height,20),'100.0',20),20),bcmul('0.0012',$impedance,20),20),'4.45',2);
+ // $num3 = (0.0 - (0.00115 * $impedance + 0.01)) * $weight + (49.64 - 0.031 * $impedance) * $height / 100.0 + $impedance * 0.08 + $age * 0.04 + 6.0;
+ $num3 = bcadd(bcadd(bcadd(bcadd(bcmul(bcsub('0.0',bcadd(bcmul('0.00115',$impedance,20),'0.01',20),20),$weight,20),bcdiv(bcmul(bcsub('49.64',bcmul('0.031',$impedance,20),20),$height,20),'100.0',20),20),bcmul($impedance,'0.08',20),20),bcmul($age,'0.04',20),20),'6.0',2);
+ // $num4 = 1000000.0 / ($num * (2.467 * $impedance - 75.37)) - (14215 / $impedance) - 0.034 * $age + 43.2;
+ $num4 = bcadd(bcsub(bcsub(bcdiv('1000000.0',bcmul($num,bcsub(bcmul('2.467',$impedance,20),'75.37',20),20),20),bcdiv('14215',$impedance,20),20),bcmul('0.034',$age,20),20),'43.2',20);
+ // $num5 = -3030000.0 / ($num + 20.0) / (1.966 * $impedance - 58.46) + (28176 / $impedance) - 0.06 * $age + 51.0;
+ $num5 = bcadd(bcsub(bcadd(bcdiv(bcdiv('-3030000.0',bcadd($num,'20.0',20),20),bcsub(bcmul('1.966',$impedance,20),'58.46',20),20),bcdiv('28176',$impedance,20),20),bcmul('0.06',$age,20),20),'51.0',20);
+ // $num6 = 0.876 * $num5 + 1.66;
+ $num6 = bcadd(bcmul('0.876',$num5,20),'1.66',1);
+ // $num7 = 0.857 * $num4 - 0.36;
+ $num7 = bcsub(bcmul('0.857',$num4,20),'0.36',20);
+ // $num8 = 0.75 * (100.0 - $num5 - $num4 - $num2 / $weight);
+ $num8 = bcmul('0.75',bcsub('100.0',bcsub($num5,bcsub($num4,bcdiv($num2,$weight,20),20),20),20),2);
+ // $num9 = 0.304 * $weight - 25.58 * $height / 100.0 + 0.131 * $age + 0.005 * $impedance + 22.0;
+ $num9 = bcadd(bcadd(bcadd(bcsub(bcmul(0.304,$weight,20),bcdiv(bcmul(25.58,$height,20),'100.0',20),20),bcmul('0.131',$age,20),20),bcmul('0.005',$impedance,20),20),'22.0',0);
+ // $num10 = (0.00307 * $impedance + 1.5) * $weight + (1459.0 - 0.989 * $impedance) * $height / 100.0 + $age * 0.9 + 0.923 * $impedance - 950.0;
+ $num10 = bcsub(bcadd(bcadd(bcadd(bcmul(bcadd(bcmul('0.00307',$impedance,20),'1.5',20),$weight,20),bcdiv(bcmul(bcsub('1459.0',bcmul('0.989',$impedance,20),20),$height,20),'100.0',20),20),bcmul($age,'0.9',20),20),bcmul('0.923',$impedance,20),20),'950.0',0);
+ // $num11 = $age * (0.95 + 0.02 * ($num - 21.2)) + ($impedance - 500) * 0.02;
+ $num11 = bcadd(bcmul($age,bcadd(0.95,bcmul('0.02',bcsub($num,'21.2',20),20),20),20),bcmul(bcsub($impedance,'500',20),'0.02',20),0);
+
+ // $standard_weight = ($height-80)*0.7;
+ $standard_weight = bcmul(bcsub($height,'80',20),'0.6',20);
+ }
+
+ $result_data['bmi'] = $num;
+ // $num2 = (($num2 > $weight * 0.15) ? ($weight * 0.15) : $num2);
+ if(bccomp($num2, bcmul($weight,'0.15',20), 20) === 1){
+ $num2 = bcmul($weight,'0.15',2);
+ }
+ // $result_data['bone'] = ($num2 < $weight * 0.02) ? ($weight * 0.02) : $num2;
+ if(bccomp($num2, bcmul($weight,'0.02',20), 20) === -1){
+ $result_data['bone'] = bcmul($weight,'0.02',2);
+ }else{
+ $result_data['bone'] = $num2;
+ }
+ // $num3 = (($num3 > 75.0) ? 75.0 : $num3);
+ if(bccomp($num3, '75.0', 20) === 1){
+ $num3 = '75.0';
+ }
+ // $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3;
+ if(bccomp($num3, '15.0', 20) === -1){
+ $result_data['muscle'] = '15.00';
+ }else{
+ $result_data['muscle'] = $num3;
+ }
+ // $num4 = (($num4 > 70.0) ? 70.0 : $num4);
+ if(bccomp($num4, '70.0', 20) === 1){
+ $num4 = '70.0';
+ }
+ // $result_data['water'] = ($num4 < 20.0) ? 20.0 : $num4;
+ if(bccomp($num4, '20.0', 20) === -1){
+ $result_data['water'] = '20.00';
+ }else{
+ $result_data['water'] = $num4;
+ }
+ // $num5 = (($num5 > 50.0) ? 50.0 : $num5);
+ if(bccomp($num5, '50.0', 20) === 1){
+ $num5 = '50.0';
+ }
+ // $result_data['fat_r'] = ($num5 < 5.0) ? 5.0 : $num5;
+
+ if(bccomp($num5, '5.0', 20) === -1){
+ $result_data['fat_r'] = '5.00';
+ }else{
+ // $result_data['fat_r'] = $num5;
+ $result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3);
+ }
+ // $result_data['sfr'] = $num6 <= 0 ? "0" : $num6;
+ if(bccomp($num6, '0.0', 20) === -1){
+ $result_data['sfr'] = '0.00';
+ }else{
+ $result_data['sfr'] = $num6;
+ }
+ // $result_data['skeletalmuscle'] = $num7;
+ $result_data['skeletalmuscle'] = substr($num7, 0, strpos($num7, ".") + 3);
+ // $num8 = (($num8 > 50.0) ? 50.0 : $num8);
+ if(bccomp($num8, '50.0', 20) === 1){
+ $num8 = '50.00';
+ }
+ // $result_data['protein'] = ($num8 < 10.0) ? 10.0 : $num8;
+ if(bccomp($num8, '10.0', 20) === -1){
+ $result_data['protein'] = '10.00';
+ }else{
+ $result_data['protein'] = $num8;
+ }
+ // $num9 = (($num9 > 20.0) ? 20.0 : $num9);
+ if(bccomp($num9, '20.0', 20) === 1){
+ $num9 = '20.0';
+ }
+ // $result_data['visceral'] = ($num9 < 1.0) ? 1.0 : $num9;
+ if(bccomp($num9, '1.0', 20) === -1){
+ $result_data['visceral'] = '1.0';
+ }else{
+ $result_data['visceral'] = $num9;
+ }
+ // $result_data['kcal'] = $num10 <= 0 ? "0" : $num10;
+ if(bccomp($num10, '0', 20) !== 1){
+ $result_data['kcal'] = '0';
+ }else{
+ $result_data['kcal'] = $num10;
+ }
+
+ // $standard_level = ($weight-$standard_weight)/$standard_weight;
+ $standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2);
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ if ($age < 18){
+ $num11 = $age;
+ }else{
+ // $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11);
+ if(bccomp($num11, $age + 10, 20) === 1){
+ $num11 = $age + 10;
+ }
+ // $num11 = (($num11 < ($age - 10)) ? (($age - 10)) : $num11);
+ if(bccomp($num11, $age - 10, 20) === -1){
+ $num11 = $age - 10;
+ }
+ }
+
+ $result_data['bodyage'] = $num11;
+ $result_data['weight'] = $weight;
+ $result_data['height'] = $height;
+ $result_data['age'] = $age;
+ $result_data['adc'] = $impedance;
+ $result_data['gender'] = $gender;
+ $result_data['standard_level'] = $standard_level;
+ return $result_data;
+ }
+ // 计算脂肪率
+ function calculate_fat_r(){
+ }
+ // 计算脂肪量
+ function calculate_zhifangliang(){
+
+ }
+ // 计算肌肉率
+ function calculate_jiroulv(){
+
+ }
+ // 计算肌肉量
+ function calculate_jirouliang(){
+
+ }
+ // 计算水分
+ function calculate_shuifen(){
+
+ }
+ // 计算蛋白量
+ function calculate_danbailiang(){
+
+ }
+ // 计算骨重
+ function calculate_guzhong(){
+
+ }
+ // 计算蛋白率
+ function calculate_danbailv(){
+
+ }
+ // 计算基础代谢
+ function calculate_jichudaixie(){
+
+ }
+ // 计算内脏指数
+ function calculate_neizangzhishu(){
+
+ }
+ // 计算皮下脂肪
+ function calculate_pixiazhifang(){
+
+ }
+ // 计算肥胖等级
+ function calculate_feipangdengji(){
+
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Card.php b/application/NewReedaw2/controller/app/Card.php
new file mode 100644
index 0000000..0012c53
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Card.php
@@ -0,0 +1,1678 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'card'=>'app_card_data',
+ 'skip'=>'app_card_skip_data',
+ 'vitalcapacity'=>'app_card_vitalcapacity_data',
+ 'zhongzhao'=>'app_sportstesting_data',
+ 'body_data_new'=>'app_card_body_data_new',
+ 'vitalcapacity_biaozhun'=>'pc_vitalcapacity_standard',
+ 'card_bz'=>'app_card_data_sub_item',
+ ];
+
+ protected $vitalcapacity_color = ['无效'=>'#FF5656','不及格'=>'#FF5656','及格'=>'#FFAB00','良好'=>'#5AD06D','优秀'=>'#6492F6','牛逼'=>'#3967D6'];
+ protected $curve_data_format_skip = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']];
+ protected $curve_data_format_vitalcapacity = ['one_val'=>['第一次','容积/ml','#009DFF'],'two_val'=>['第二次','容积/ml','#009DFF'],'three_val'=>['第三次','容积/ml','#009DFF'],'average_val'=>['平均','容积/ml','#009DFF']];
+ protected $card_standard_arr_data = [
+ 'id'=>'',
+ 'name'=>'',
+ 'content'=>'',
+ 'page_url_report'=>'',
+ 'is_sub_item'=>'',
+ 'background_color'=>'',
+ 'background_pic'=>'',
+ 'key_word'=>'',
+ 'data'=>[],
+ ];
+ protected $pagesize = 15;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 卡片列表信息
+ public function card_list_all(){
+ $data = input('post.');
+ try {
+ // 你的业务逻辑
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->card_list_all_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 保存用户所选的卡片列表
+ public function save_card_list(){
+ $data = input('post.');
+ try {
+ // 你的业务逻辑
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('card_list', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+
+ return $this->save_card_list_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 角色卡片列表信息
+ public function user_card_list(){
+ $data = input('post.');
+ try {
+ // 你的业务逻辑
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->user_card_list_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // BMI测评
+ public function bmi_evaluation(){
+ $cbe_data = input('post.');
+ try {
+
+ if(!is_array($cbe_data)){
+ return $this->msg(10005);
+ }
+ if(!array_key_exists('height', $cbe_data) || !array_key_exists('weight', $cbe_data) || !array_key_exists('birthday', $cbe_data) || !array_key_exists('sex', $cbe_data)){
+ return $this->msg(10001);
+ }
+ unset($cbe_data['token']);
+ if(!$this->verify_data_is_ok($cbe_data['birthday'],'datetime')){
+ return $this->msg(10005,'birthday type error');
+ }
+ if(!$this->verify_data_is_ok($cbe_data['height'],'num')){
+ return $this->msg(10005,'height type error');
+ }
+ if(!$this->verify_data_is_ok($cbe_data['weight'],'num')){
+ return $this->msg(10005,'weight type error');
+ }
+ if(!$this->verify_data_is_ok($cbe_data['sex'],'intnum')){
+ return $this->msg(10005,'sex type error');
+ }
+
+ // 直接开始业务,请求外部接口start
+ $url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
+ $temporary_parameter = [
+ 'height'=>$cbe_data['height'],
+ 'weight'=>$cbe_data['weight'],
+ 'birthday'=>$cbe_data['birthday'],
+ 'sex'=>$cbe_data['sex'],
+ ];
+ $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
+ // 直接开始业务,请求外部接口end
+
+ // 处理进度点
+ $request_result =$this->bmi_evaluation_action($request_result);
+ return $request_result;
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($cbe_data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 身高预测
+ public function genetic_height(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005,'birthday type error');
+ }
+ if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
+ return $this->msg(10005,'dadHeight type error');
+ }
+ if(!$this->verify_data_is_ok($data['momHeight'],'num')){
+ return $this->msg(10005,'momHeight type error');
+ }
+ if(!$this->verify_data_is_ok($data['sex'],'intnum')){
+ return $this->msg(10005,'sex type error');
+ }
+
+ // 直接开始业务,请求外部接口start
+ $url = 'https://ybapi.pcxbc.com/api/child/predictheight';
+ $temporary_parameter = [
+ 'dadHeight'=>$data['dadHeight'],
+ 'momHeight'=>$data['momHeight'],
+ 'birthday'=>$data['birthday'],
+ 'sex'=>$data['sex'],
+ ];
+ $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
+ return json($request_result);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 获取手动记录内容
+ public function obtain_manual_record_content(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ type类型:
+ // 数字输入框:number
+ // 文本输入框:text
+ // 日期下拉框:date Y-m-d
+ // 时间下拉框:multiSelector His或者is
+ // 带小数点的数字键盘:digit
+ $card_data = [
+ [
+ 'id'=>6,
+ 'name'=>'跳绳',
+ 'key_word'=>'skip',
+ 'list'=>[
+ ['name'=>'日期','key_word'=>'r_time','type'=>'date','unit'=>'','value'=>''],
+ ['name'=>'时长','key_word'=>'time_m_s','type'=>'multiSelector','unit'=>'','value'=>''],
+ ['name'=>'数量','key_word'=>'num','type'=>'number','unit'=>'个','value'=>''],
+ ]
+ ],
+ [
+ 'id'=>8,
+ 'name'=>'肺活训练',
+ 'key_word'=>'vitalcapacity',
+ 'list'=>[
+ ['name'=>'日期','key_word'=>'r_time','type'=>'date','unit'=>'','value'=>''],
+ ['name'=>'第一次','key_word'=>'one','type'=>'number','unit'=>'ml','value'=>''],
+ ['name'=>'第二次','key_word'=>'two','type'=>'number','unit'=>'ml','value'=>''],
+ ['name'=>'第三次','key_word'=>'three','type'=>'number','unit'=>'ml','value'=>''],
+ ]
+ ]
+ ];
+ // if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ // return $this->msg(10005);
+ // }
+ // $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,gender')->find();
+ // if(!$user_data){
+ // return $this->msg(10004);
+ // }
+ // $card_data_c = Db::table($this->card_db_name['card_bz'])
+ // ->where(['is_del'=>0])
+ // ->field('id,name,type,unit,unit2,suit_gender,acd_id')
+ // ->select();
+ // $card_data_c2 = [];
+ // foreach ($card_data_c as $key => $value) {
+ // $temporary_arr = [];
+ // $temporary_arr['id'] = $value['acd_id'];
+ // $temporary_arr['height'] = false;
+ // $temporary_arr['weight'] = false;
+ // $temporary_arr['number'] = false;
+ // $temporary_arr['time'] = false;
+ // $temporary_arr['list'] = [];
+ // $card_data_c2[$value['acd_id']] = $temporary_arr;
+ // }
+ // foreach ($card_data_c as $key => $value) {
+ // if(in_array($user_data['gender'], explode(",", $value['suit_gender']))){
+ // $temporary_arr = [];
+ // $temporary_arr['id'] = $value['id'];
+ // $temporary_arr['name'] = $value['name'];
+ // $temporary_arr['number'] = $value['unit2'] == '时长'?false:true;
+ // $temporary_arr['type'] = $value['type'];
+ // $temporary_arr['time'] = $value['unit2'] == '时长'?true:false;
+ // $temporary_arr['describe'] = $value['unit2'];
+ // $temporary_arr['unit'] = $value['unit'] == "分/秒"?'': $value['unit'];
+ // array_push($card_data_c2[$value['acd_id']]['list'],$temporary_arr);
+ // }else{
+ // continue;
+ // }
+
+ // }
+ // $card_data = [
+ // ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]],
+ // ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]],
+ // ];
+ // foreach ($card_data_c2 as $key => $value) {
+ // array_push($card_data,$value);
+ // }
+ // 成功
+ return $this->msg($card_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 manual_record(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data) || !array_key_exists('data', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if (!is_array($data['data'])) {
+ return $this->msg(10005,'data type error');
+ }
+
+
+
+ if($data['type'] == 'skip'){//跳绳
+ return $this->manual_record_skip_action($data);
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->manual_record_vitalcapacity_action($data);
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+
+ } 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 curve_chart(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+
+ if($data['type'] == 'skip'){//跳绳
+ return $this->curve_chart_skip_action($data);
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->curve_chart_vitalcapacity_action($data);
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+
+ } 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 record_list_group(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('type', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+
+ if($data['type'] == 'skip'){//跳绳
+ return $this->record_list_group_skip_action($data,'group');
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->record_list_group_vitalcapacity_action($data,'group');
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+
+
+ } 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 data_compare(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['before_id'],'intnum')){
+ return $this->msg(10005,'before_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['after_id'],'intnum')){
+ return $this->msg(10005,'after_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+
+ if($data['type'] == 'skip'){//跳绳
+ return $this->data_compare_skip_action($data);
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->data_compare_vitalcapacity_action($data);
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+
+
+ } 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 record_list_page(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('type', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+
+ if($data['type'] == 'skip'){//跳绳
+ return $this->record_list_group_skip_action($data,'page');
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->record_list_group_vitalcapacity_action($data,'page');
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+
+ } 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 detailed_record(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('id', $data) || !array_key_exists('type', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+
+ if($data['type'] == 'vitalcapacity'){//肺活
+ return $this->detailed_record_vitalcapacity_action($data);
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+ } 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_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('id', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $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'],'str')){
+ return $this->msg(10005,'type type error');
+ }
+ unset($data['token']);
+
+
+ if($data['type'] == 'skip'){//跳绳
+ $user_data = Db::table($this->card_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }else if($data['type'] == 'vitalcapacity'){//肺活
+ $user_data = Db::table($this->card_db_name['vitalcapacity'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }else{
+ return $this->msg(10005,'type data error');
+ }
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+
+
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+
+ public function card_list_all_action($data){
+
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ // 获取卡片信息
+ $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->select();
+ // $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(10)->select();
+ // dump($card_data);
+ // die;
+ // 根据用户处理卡片信息
+ $return_data_title = [
+ ['name'=>'对比','icon'=>'','page_jump'=>""],
+ ['name'=>'曲线','icon'=>'','page_jump'=>""],
+ ['name'=>'添加','icon'=>'','page_jump'=>""],
+ ['name'=>'历史','icon'=>'','page_jump'=>""]
+ ];
+ $return_data = [
+ 'title'=>[],
+ 'chosen_fixed'=>[
+ ['id'=>'20','name'=>'中招估分','key_word'=>"zz_score",'background_color'=>'','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/report.png','page_jump'=>'/pageTwo/score/score'],
+ ['id'=>'21','name'=>'BMI测评','key_word'=>"bmi",'background_color'=>'','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/bmi.png','page_jump'=>'/pageTwo/bmi/bmi'],
+ ['id'=>'22','name'=>'遗传身高','key_word'=>"heredity",'background_color'=>'','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png','page_jump'=>'/pageTwo/inheritHeighet/inheritHeighet'],
+ ],
+ 'chosen_yes'=>[],
+ 'chosen_no'=>[],
+ ];
+ if($user_data['card_order'] != ''){
+ // 如果有设置过
+ $user_data['card_order'] = explode(',',$user_data['card_order']);
+ }else{
+ $user_data['card_order'] = [];
+ }
+ // dump($user_data['card_order']);
+ // die;
+ // 对照处理用户的卡片信息
+ foreach ($user_data['card_order'] as $key => $value) {
+ foreach ($card_data as $k => $v) {
+ if(in_array($v['id'],$user_data['card_order']) && $v['id'] == $value){
+ if($v['id'] == 20 || $v['id'] == 21 || $v['id'] == 22){
+ continue;
+ }else{
+ $return_data['chosen_yes'][] = $v;
+ unset($card_data[$k]);
+ }
+
+ }
+ }
+ }
+ foreach ($card_data as $key => $value) {
+ $return_data['chosen_no'][] = $value;
+ }
+ // 剔除不必要的数据
+ foreach ($return_data as $key => $value) {
+ if($key == 'chosen_yes' || $key == 'chosen_no'){
+ foreach ($value as $k => $v) {
+ $return_data[$key][$k]['icon'] = $return_data[$key][$k]['background_pic'];
+ unset($return_data[$key][$k]['background_pic']);
+ $return_data[$key][$k]['page_jump'] = $return_data[$key][$k]['page_url_report'];
+ unset($return_data[$key][$k]['page_url_report']);
+ unset($return_data[$key][$k]['content']);
+ unset($return_data[$key][$k]['is_sub_item']);
+ unset($return_data[$key][$k]['ROW_NUMBER']);
+ }
+ }
+ }
+ foreach ($return_data['chosen_yes'] as $key => $value) {
+ if(in_array($value['id'],[6,8])){
+ $return_data['title'] = $return_data_title;
+ break;
+ }
+ }
+
+ return $this->msg($return_data);
+ }
+ public function save_card_list_action($data){
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+
+ if($data['card_list']){
+ if(!$this->verify_data_is_ok(explode(',',$data['card_list']),'arr_intnum')){
+ return $this->msg(10005,'card_list type error');
+ }
+ // 查一下卡片数据
+ $card_data = Db::table($this->card_db_name['card'])->where("id in (".$data['card_list'].")")->field('id')->select();
+ if(count(explode(',',$data['card_list'])) == count($card_data)){
+ $result = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->update([
+ 'card_order' => $data['card_list']
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }else{
+ return $this->msg(10003,'卡片数据错误');
+ }
+ }else{
+ $result = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->update(['card_order' => ""]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+ }
+ public function user_card_list_action($data){
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ if($user_data['card_order'] == '' || $user_data['card_order'] == '2'){
+ // == 2是为了兼容老数据
+ return $this->msg([]);
+ }
+
+ $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
+
+ // 处理卡片映射
+ $card_data_map = [];
+ foreach ($card_data as $key => $value) {
+ $card_data_map[$value['key_word']] = $value;
+ }
+
+ // 开始处理列表数据
+ $user_card_list = explode(',',$user_data['card_order']);
+ $return_data = [];
+
+ // dump($card_data_map);
+ // die;
+
+ foreach ($user_card_list as $key => $value) {
+ // dump('本次card_id:'.$value);
+ $temporary_data = $this->little_tool_one($card_data_map,$data['aud_id'],$value);
+
+ // dump('最终结果如下');
+ // dump($temporary_data);
+ if(count($temporary_data) > 0){
+ $return_data[] = $temporary_data;
+ }
+ }
+
+ return $this->msg($return_data);
+
+ }
+ public function bmi_evaluation_action($data){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){
+ return $this->msg(99999,'网络异常,请稍后重试1');
+ }
+ if($data['code'] != 0){
+ return $this->msg(99999,'网络异常,请稍后重试2');
+ }
+ if(!is_array($data['data'])){
+ return $this->msg(99999,'网络异常,请稍后重试3');
+ }
+ if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){
+ return $this->msg(99999,'网络异常,请稍后重试4');
+ }
+ if(!is_array($data['data']['bmilevellist'])){
+ return $this->msg(99999,'网络异常,请稍后重试5');
+ }
+ $num = 0;
+ $subsection_val = 0;
+ $temporary_subsection_val = null;
+ foreach ($data['data']['bmilevellist'] as $key => $value) {
+ if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){
+ return $this->msg(99999,'网络异常,请稍后重试6');
+ }
+ // 判断是否可以进行比较,规则是否正确
+ if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){
+ if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){
+ // 在落点内
+ $subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差
+ $temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差
+ $temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比
+ $subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比
+ $temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比
+ $temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1);
+ }else{
+ $num = $num + 1;
+ }
+ }
+ }
+
+ if($temporary_subsection_val === null){
+ if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){
+ $temporary_subsection_val = 100;
+ }else{
+ return $this->msg(99999,'网络异常,请稍后重试7');
+ }
+ }
+ $data['data']['offset'] = $temporary_subsection_val;
+ $data = $data['data'];
+ // 处理key名称一致start
+ foreach ($data['bmilevellist'] as $key => $value) {
+ $data['bmilevellist'][$key]['max_val'] = $value['maxvalue'];
+ $data['bmilevellist'][$key]['min_val'] = $value['minvalue'];
+ unset($data['bmilevellist'][$key]['minvalue']);
+ unset($data['bmilevellist'][$key]['maxvalue']);
+ }
+ // 处理key名称一致end
+ return $this->msg($data);
+ }
+
+
+ // 跳绳手动记录
+ public function manual_record_skip_action($data){
+
+ // ['name'=>'日期','key_word'=>'r_time','type'=>'date','unit'=>'','value'=>''],
+ // ['name'=>'时长','key_word'=>'time_m_s','type'=>'multiSelector','unit'=>'','value'=>''],
+ // ['name'=>'数量','key_word'=>'num','type'=>'number','unit'=>'个','value'=>''],
+
+ $temporary_data = [];
+ foreach ($data['data'] as $key => $value) {
+ $temporary_data[$value['key_word']] = $value['value'];
+ }
+ if(!array_key_exists('num', $temporary_data) || !array_key_exists('r_time', $temporary_data) || !array_key_exists('time_m_s', $temporary_data)){
+ return $this->msg(10001);
+ }
+ $temporary_data['time_m_s'] = explode(':',$temporary_data['time_m_s']);
+ $data['time_m'] = (int)$temporary_data['time_m_s'][0];
+ $data['time_s'] = (int)$temporary_data['time_m_s'][1];
+ $data['num'] = (int)$temporary_data['num'];
+ $data['r_time'] = $temporary_data['r_time'];
+ if(!$this->verify_data_is_ok($data['num'],'intnum') || !$this->verify_data_is_ok($data['time_m'],'intnum_0') || !$this->verify_data_is_ok($data['time_s'],'intnum_0')){
+ return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
+ }
+ if($data['num'] <= 0){
+ return $this->msg(10005,'跳绳数不能小于等于0');
+ }
+ if(abs($data['time_m']) >= 60){
+ return $this->msg(10005,'分钟值不能大于60');
+ }
+ if(abs($data['time_s']) >= 60){
+ return $this->msg(10005,'秒钟值不能大于60');
+ }
+ if(strlen($data['r_time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['r_time'] = $this->addCurrentTimeToDateString($data['r_time']);
+ }
+
+
+
+ // 分秒转换为秒
+ $data['time'] = abs($data['time_m'])*60+abs($data['time_s']);
+ $user_msg_content = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->count();
+ if($user_msg_content<=0){
+ return $this->msg(10004);
+ }
+ if(!array_key_exists('kcal', $data)){
+ $last_data_body = Db::table($this->card_db_name['body_data_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight,record_time')->find();
+ if(!$last_data_body){
+ $last_data_body = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,weight')->find();
+ if(!$last_data_body){
+ return $this->msg(10004);
+ }
+ }
+ $kcal_data = $this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight']);
+ }else{
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($data['time'],60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($data['num'],$minutes,2);
+ $kcal_data['totalCalories'] = $data['kcal'];
+ $kcal_data['averageAchievement'] = $jumpsPerMinute;
+ $kcal_data['caloriesPerMinute'] = bcdiv($kcal_data['totalCalories'],$minutes,2);
+ }
+
+
+ $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'=>$kcal_data['totalCalories'],
+ 'average_num'=>$kcal_data['averageAchievement'],
+ 'average_kcal'=>$kcal_data['caloriesPerMinute'],
+ 'aud_id'=>$data['aud_id'],
+ 'record_time'=>array_key_exists('r_time', $data)?$data['r_time']:date('Y-m-d H:i:s'),
+ 'jump_type'=>$data['type']
+ ];
+ if(strlen($data_set['record_time']) <= 12){
+ $data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']);
+ }
+ $last_data_body = Db::table($this->card_db_name['skip'])->insert($data_set);
+ $result = [
+ 'today_jump_num'=>0,
+ 'today_jump_time'=>0,
+ 'today_jump_kcal'=>0,
+ ];
+ $all_data = Db::table($this->card_db_name['skip'])->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'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
+ }
+ $result['last_jump_num'] = $data['num'];
+ $result['last_jump_time'] = $data['time'];
+ $result['last_jump_kcal'] = $data_set['jump_kcal'];
+ // $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
+ $result['last_record_time'] = $data_set['record_time'];
+ $time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
+ $result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ $time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
+ $result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ return $this->msg($result);
+ }
+ // 肺活量手动记录
+ public function manual_record_vitalcapacity_action($data){
+
+ $temporary_data = [];
+ foreach ($data['data'] as $key => $value) {
+ $temporary_data[$value['key_word']] = $value['value'];
+ }
+ if(!array_key_exists('one', $temporary_data) || !array_key_exists('two', $temporary_data) || !array_key_exists('three', $temporary_data) || !array_key_exists('r_time', $temporary_data)){
+ return $this->msg(10001);
+ }
+
+ $data['one'] = $temporary_data['one'];
+ $data['two'] = $temporary_data['two'];
+ $data['three'] = $temporary_data['three'];
+ $data['r_time'] = $temporary_data['r_time'];
+ if(!$this->verify_data_is_ok($data['one'],'intnum')){
+ return $this->msg(10005,'one type error');
+ }
+ if(!$this->verify_data_is_ok($data['two'],'intnum')){
+ return $this->msg(10005,'two type error');
+ }
+ if(!$this->verify_data_is_ok($data['three'],'intnum')){
+ return $this->msg(10005,'three type error');
+ }
+ if(strlen($data['r_time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['r_time'] = $this->addCurrentTimeToDateString($data['r_time']);
+ }
+
+
+
+
+ $temporary_arr['aud_id'] = $data['aud_id'];
+ $temporary_arr['record_time'] = $data['r_time'];
+ $temporary_arr['one'] = $data['one'];
+ $temporary_arr['two'] = $data['two'];
+ $temporary_arr['three'] = $data['three'];
+ $temporary_arr['average'] = bcdiv(bcadd(bcadd($data['one'],$data['two'],2),$data['three'],2),3,2);
+ $temporary_arr['create_time'] = date('Y-m-d H:i:s');
+ $temporary_arr['one_val'] = $data['one'];
+ $temporary_arr['two_val'] = $data['two'];
+ $temporary_arr['three_val'] = $data['three'];
+ $temporary_arr['average_val'] = $temporary_arr['average'];
+ $temporary_arr['flow_val'] = '0.00';//流速
+ $temporary_arr['record_type'] = 'by_hand_means';
+ // die;
+ // 处理记录时间
+
+ $user_msg = Db::name($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find();
+
+ if($user_msg){
+ // // 根据性别&年级&年龄查规则
+ // if($user_msg['grade'] == 'nothing' || $user_msg['grade'] == ''){
+
+ // }
+ // 计算年龄判断是属于哪个年级
+ $user_age = $this->calculate_age($user_msg['birthday']);
+ // dump($user_age);
+ if($user_age <= 7){
+ $user_msg['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $user_msg['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $user_msg['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $user_msg['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $user_msg['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $user_msg['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $user_msg['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $user_msg['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $user_msg['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $user_msg['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $user_msg['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $user_msg['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $user_msg['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $user_msg['grade'] = 'grade_u_34';
+ }
+ $sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val'];
+ // dump($user_age);
+ // dump($user_msg);
+
+ $user_achievement = Db::name($this->card_db_name['vitalcapacity_biaozhun'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->cache(86400)->select();
+
+ if(count($user_achievement)<=0){
+ $user_achievement[0] = ['level'=>'无效','score'=>'0'];
+ }
+
+ $temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->vitalcapacity_color[$user_achievement[0]['level']];
+ $temporary_arr['score_val'] = $user_achievement[0]['score'];
+
+ }else{
+ return $this->msg(10004,'未找到有效数据');
+ }
+ // dump($data);
+ $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+
+
+ $temporary_arr['standard_data'] = json_encode($standard_data);
+ $result = Db::table($this->card_db_name['vitalcapacity'])->insert($temporary_arr);
+
+ if($result){
+ $time = $result[0]['record_time'];
+ $time = strtotime($time);
+ $time = date('Y年m月d日 H:i:s', $time);
+ return $this->msg([
+ 'average'=>$temporary_arr['average'].'ml',
+ 'level'=>$user_achievement[0]['level'],
+ 'time'=>$time,
+ 'flow_val'=>$temporary_arr['flow_val'],
+ 'list'=>$standard_data,
+ 'offset'=>$this->vitalcapacity_standard_interval($temporary_arr['average'],$standard_data)
+ ]);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+ // 跳绳曲线
+ public function curve_chart_skip_action($data){
+ $audid = $data['aud_id'];
+ $timeData = explode('-', $data['time']);
+ // 根据$timeData的长度构建不同的查询条件
+ $map = ['aud_id' => $audid,'is_del'=>0];
+ switch (count($timeData)) {
+ case 3: // 年月日
+ $map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
+ break;
+ case 2: // 年月
+ $map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
+ break;
+ case 1: // 年
+ $map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
+ break;
+ default:
+ return $this->msg(10005); // 无效的时间数据格式
+ }
+
+ // 使用查询构造器进行查询
+ $result = Db::name($this->card_db_name['skip'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
+ $return_data = [];
+ if(count($timeData) == 3){
+ $key_condition = 'hour';
+ }else if(count($timeData) == 2){
+ $key_condition = 'day';
+ }else if(count($timeData) == 1){
+ $key_condition = 'month';
+ }
+ foreach ($this->curve_data_format_skip as $key => $value) {
+ $temporary_arr['title'] = $value[0].'('.$value[1].')';
+ $temporary_arr['key'] = $key;
+ $temporary_arr['line']['categories'] = [];
+ $temporary_arr['line']['series'][0]['color'] = $value[2];
+ $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
+ $temporary_arr['line']['series'][0]['data'] = [];
+ foreach ($result as $k => $v) {
+ if($key_condition == 'hour'){
+ // 每一次的记录都添加进去
+ array_push($temporary_arr['line']['categories'],$result[$k]['hour'].':'.$result[$k]['minute']);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }else if($key_condition == 'day'){
+ // 根据天分组
+ if(in_array($result[$k]['month'].'/'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'/'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
+ $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'/'.$result[$k][$key_condition]);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+
+ }else{
+ // 根据年分组
+ if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
+ $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }
+ }
+ array_push($return_data,$temporary_arr);
+ }
+ foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) {
+ $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2);
+ }
+ return $this->msg($return_data);
+ }
+ // 肺活曲线
+ public function curve_chart_vitalcapacity_action($data){
+ $audid = $data['aud_id'];
+ $timeData = explode('-', $data['time']);
+
+ // 根据$timeData的长度构建不同的查询条件
+ $map = ['aud_id' => $audid];
+ switch (count($timeData)) {
+ case 3: // 年月日
+ $map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
+ break;
+ case 2: // 年月
+ $map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
+ break;
+ case 1: // 年
+ $map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
+ break;
+ default:
+ return $this->msg(10005); // 无效的时间数据格式
+ }
+ // 使用查询构造器进行查询
+ $result = Db::name($this->card_db_name['vitalcapacity'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select();
+ $return_data = [];
+ if(count($timeData) == 3){
+ $key_condition = 'hour';
+ }else if(count($timeData) == 2){
+ $key_condition = 'day';
+ }else if(count($timeData) == 1){
+ $key_condition = 'month';
+ }
+ foreach ($this->curve_data_format_vitalcapacity as $key => $value) {
+ $temporary_arr['title'] = $value[0].'('.$value[1].')';
+ $temporary_arr['key'] = $key;
+ $temporary_arr['line']['categories'] = [];
+ $temporary_arr['line']['series'][0]['color'] = $value[2];
+ $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
+ $temporary_arr['line']['series'][0]['data'] = [];
+ foreach ($result as $k => $v) {
+ if($key_condition == 'hour'){
+ if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){
+
+ $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }else if($key_condition == 'day'){
+ if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'-'.$result[$k][$key_condition]);
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }else{
+ if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
+ $num = array_search($result[$k]['month'].'月', $temporary_arr['line']['categories']);
+ // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2);
+ $temporary_arr['line']['series'][0]['data'][$num] = $temporary_arr['line']['series'][0]['data'][$num] >= $result[$k][$key]?$temporary_arr['line']['series'][0]['data'][$num]:$result[$k][$key];
+ }else{
+ array_push($temporary_arr['line']['categories'],$result[$k]['month'].'月');
+ array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
+ }
+ }
+ }
+ array_push($return_data,$temporary_arr);
+ }
+ return $this->msg($return_data);
+ }
+
+ // 跳绳历史
+ public function record_list_group_skip_action($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->card_db_name['skip']."
+ 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->card_db_name['skip'])->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->card_db_name['skip'])->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'],
+ 'is_have_details'=>'no'
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }
+ // 肺活历史
+ public function record_list_group_vitalcapacity_action($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->card_db_name['vitalcapacity']."
+ 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->card_db_name['vitalcapacity'])->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->card_db_name['vitalcapacity'])->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'],
+ 'is_have_details'=>'yes'
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }
+ // 数据对比
+ public function data_compare_skip_action($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->card_db_name['skip']." as acsd
+ left join ".$this->card_db_name['juese']." 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'] = [];
+
+ $request_result = ['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']];
+ 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'=>$request_result[$key][0],
+ 'unit'=>$request_result[$key][1],
+ 'name'=>$key,
+ ],
+ 'secondresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$key=='jump_time'?implode(':',$this->handle_hour_branch_second($after_arr)):$after_arr,
+ 'title'=>$request_result[$key][0],
+ 'unit'=>$request_result[$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 data_compare_vitalcapacity_action($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->card_db_name['vitalcapacity']." as acsd
+ left join ".$this->card_db_name['juese']." 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'] = [];
+ $request_result = ['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']];
+ 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'=>$request_result[$key][0],
+ 'unit'=>$request_result[$key][1],
+ 'name'=>$key,
+ ],
+ 'secondresult'=>[
+ 'color'=>'',
+ 'level'=>'',
+ 'value'=>$after_arr,
+ 'title'=>$request_result[$key][0],
+ 'unit'=>$request_result[$key][1],
+ 'name'=>$key,
+ ],
+ 'diffval'=>bcsub($after_arr,$before_arr,2)
+ ];
+ array_push($return_data['list'], $temporary_arr);
+
+ }
+
+ }
+ return $this->msg($return_data);
+ }
+
+ // 历史详情(肺活)
+ public function detailed_record_vitalcapacity_action($data){
+
+ $result = $result = Db::table($this->card_db_name['vitalcapacity'])->where(['id'=>$data['id'],'is_del'=>0])->find();
+ $for_data_arr = ['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ $temporary_arr['value'] = explode(',',$result[$key])[0];
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ return $this->msg($result_data);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+
+
+
+
+
+
+ ################################################################小工具################################################################
+ ################################################################小工具################################################################
+
+ public function little_tool_one($data,$aud_id,$type){
+ $result = $this->card_standard_arr_data;
+ if($type == 6){
+ if(!array_key_exists('skip',$data)){
+ // 如果系统已经停用了跳绳
+ return [];
+ }
+ $temporary_data = $data['skip'];
+ $all_data = Db::table($this->card_db_name['skip'])->where(['aud_id'=>$aud_id,'is_del'=>0])->order('id desc')->field('id,jump_kcal as val_data')->find();
+ $result['data']['unit'] = 'kcal';
+ }else if($type == 8){
+ if(!array_key_exists('vitalcapacity',$data)){
+ // 如果系统已经停用了肺活
+ return [];
+ }
+ $temporary_data = $data['skip'];
+ $all_data = Db::table($this->card_db_name['vitalcapacity'])->where(['aud_id'=>$aud_id,'is_del'=>0])->order('id desc')->field('id,score_val as val_data')->find();
+ $result['data']['unit'] = '分';
+ }else if($type == 20){
+ if(!array_key_exists('zz_score',$data)){
+ // 如果系统已经停用了中招估分
+ return [];
+ }
+ $temporary_data = $data['skip'];
+ $all_data = Db::table($this->card_db_name['zhongzhao'])->where(['aud_id'=>$aud_id,'is_del'=>0])->order('id desc')->field('id,score as val_data')->find();
+ $result['data']['unit'] = '分';
+ }else if($type == 21 || $type == 22 || $type == 25 || $type == 26){
+ if(!array_key_exists('bmi',$data) || !array_key_exists('heredity',$data) || !array_key_exists('fat_loss',$data) || !array_key_exists('target',$data)){
+ // 如果系统已经停用了BMI测评、遗传身高、减脂对比、曲线/目标、
+ return [];
+ }
+
+ $map = ['21'=>'bmi','22'=>'heredity','25'=>'fat_loss','26'=>'target'];
+ $temporary_data = $data[$map[$type]];
+ $all_data = ['val_data'=>''];
+ $result['data']['unit'] = '';
+
+ }else{
+ return [];
+ }
+
+
+ if($all_data){
+ $result['id'] = $temporary_data['id'];
+ $result['name'] = $temporary_data['name'];
+ $result['content'] = $temporary_data['content'];
+ $result['page_url_report'] = $temporary_data['page_url_report'];
+ $result['is_sub_item'] = $temporary_data['is_sub_item'];
+ $result['background_color'] = $temporary_data['background_color'];
+ $result['background_pic'] = $temporary_data['background_pic'];
+ $result['key_word'] = $temporary_data['key_word'];
+
+ $result['data']['value'] = $all_data['val_data'];
+ return $result;
+ }else{
+ return [];
+ }
+ }
+
+ // 跳绳卡路里计算
+ public function skip_kcal_calculate($num=143, $time=222, $weight=70) {
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($time,60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($num,$minutes,2);
+ // 根据跳绳次数确定MET值
+ // $met = 11.8;
+ 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 [
+ 'averageAchievement' => $jumpsPerMinute,
+ 'caloriesPerMinute' => $caloriesPerMinute,
+ 'totalCalories' => $totalCalories
+ ];
+ }
+ // 肺活量判断区间
+ public function vitalcapacity_standard_interval($val,$data){
+ // 缓存一周
+ $result = '';
+ if(!$data || count($data) <= 0){
+ return $result;
+ }
+ $temporary_qj = $data;
+ $max = 0;
+ $min = 0;
+ $num = 0;
+ foreach ($temporary_qj as $key => $value) {
+ if($val >= $value['min_val'] && $val <= $value['max_val']){
+ $max = $value['max_val'];
+ $min = $value['min_val'];
+ $num = $key;
+ break;
+ }
+ }
+
+ $num = count($temporary_qj)-1-$num;
+
+ if($max == 0){
+ if($val >= $temporary_qj[0]['max_val']){
+ $result = 100;
+ }
+ }else{
+ $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
+ $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
+ }
+ return $result;
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Cardparts.php b/application/NewReedaw2/controller/app/Cardparts.php
index b062caf..22a3871 100644
--- a/application/NewReedaw2/controller/app/Cardparts.php
+++ b/application/NewReedaw2/controller/app/Cardparts.php
@@ -1,6 +1,6 @@
$value) {
-
+ // dump($value['list']);
+ // dump($value['value']);
+ // dump($value['standard']);
if(count($value['list']) > 0){
- $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard'])[0];
+ $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard']);
}
}
// 如果是没有阻抗的测试,那么就不要底部的其他数据了
@@ -223,9 +225,10 @@ class Cardparts extends Base{
$temporary_arr['bottom_list'] = [];
return $temporary_arr;
}
+
+
+
// 处理底部list
-
-
foreach ($temporary_arr['bottom_list'] as $key => $value) {
// dump($value);
// 脂肪率&
@@ -360,7 +363,41 @@ class Cardparts extends Base{
// 计算落点百分比(区间字典,值,值描述)
- public function calculate_landing_point($data,$val,$t_val){
+ public function calculate_landing_point($data = [],$val = '0',$t_val = ''){
+// $data = [
+// [
+// 'min_val' => '0',
+// 'max_val' => '32.5',
+// 'text' => '低',
+// 'color' => '#F8595D'
+// ],
+// [
+// 'min_val' => '32.5',
+// 'max_val' => '36.2',
+// 'text' => '偏低',
+// 'color' => '#FFAF04'
+// ],
+// [
+// 'min_val' => '36.2',
+// 'max_val' => '48.7',
+// 'text' => '标准',
+// 'color' => '#59D168'
+// ],
+// [
+// 'min_val' => '48.7',
+// 'max_val' => '57.7',
+// 'text' => '偏高',
+// 'color' => '#FFAF04'
+// ],
+// [
+// 'min_val' => '57.7',
+// 'max_val' => '69.7',
+// 'text' => '高',
+// 'color' => '#F8595D'
+// ]
+// ];
+// $val = "41.80";
+// dump($data);
// 根据字典确认有几个区间
$num = count($data);
if($num <= 0){
diff --git a/application/NewReedaw2/controller/app/Countfood.php b/application/NewReedaw2/controller/app/Countfood.php
new file mode 100644
index 0000000..8bb8b39
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Countfood.php
@@ -0,0 +1,89 @@
+'app_account_number',
+ ];
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 卡片列表信息
+ public function card_list_msg(){
+ try {
+ // 你的业务逻辑
+ $data = input('post.');
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->card_list_msg_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+ public function card_list_msg_action($data){
+ // 检查角色
+ $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find();
+ if(!$user_data){
+ return $this->msg(10003,'未核实到角色信息');
+ }
+ // 获取卡片信息
+ $card_data = Db::table($this->card_db_name['card'])->where(['is_del'=>0])->field('id,name,content,page_url_report,is_sub_item,background_color,background_pic,key_word')->cache(86400)->select();
+ // 根据用户处理卡片信息
+ $return_data = [
+ 'chosen_yes'=>[],
+ 'chosen_no'=>[],
+ ];
+ if($user_data['card_order'] != ''){
+ $user_data['card_order'] = explode(',',$user_data['card_order']);
+ }else{
+ $user_data['card_order'] = [];
+ }
+ for ($i=0; $i < count($card_data); $i++) {
+ if(!in_array($card_data[$i]['id'],$user_data['card_order'])){
+ $return_data['chosen_no'][] = $card_data[$i];
+ }else{
+ $key = array_search($card_data[$i]['id'], $user_data['card_order']);
+ $return_data['chosen_yes'][$key] = $card_data[$i];
+ }
+ }
+ ksort($return_data['chosen_yes']);
+ return $this->msg($return_data);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Guessyoulike.php b/application/NewReedaw2/controller/app/Guessyoulike.php
new file mode 100644
index 0000000..06db44b
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Guessyoulike.php
@@ -0,0 +1,436 @@
+ 'app_user_cookbook', //食谱表
+ 'cookbook_label' => 'app_user_cookbook_label', //食谱标签表
+ 'cookbook_food_relation' => 'app_user_cookbook_food_relation', //食谱跟食材关系表
+ 'foodlist2' => 'app_z_national_standard_food_type_2', //食材标签表2
+ 'foodlist3' => 'app_z_national_standard_food_type_3', //食材表
+ 'kcal_log' => 'app_user_kcal_log', //用户饮食记录表记录用户吃了什么食材
+ 'search_history' => 'app_user_search_history', //用户搜索记录表,记录用户搜索过什么内容
+ 'tag_preference' => 'app_user_tag_preference', //用户标签偏好表
+ 'recommend_cache' => 'app_recommend_cache' //智能推荐缓存表
+ ];
+
+ protected $config = [
+ 'tag_limit' => 2,
+ 'item_limit' => 12,
+ 'cache_time' => 3600
+ ];
+
+ /**
+ * 猜你喜欢主接口
+ */
+ public function getGuessYouLike($user_id = 1, $type = 'food', $limit = null) {
+ try {
+ $cfc = Db::connect('cfc_db');
+ // dump(1);
+ // 设置限制数量
+ $tag_limit = $limit ? intval($limit) : $this->config['tag_limit'];
+ $item_limit = $this->config['item_limit'];
+
+ // 检查缓存
+ // $cache_key = $user_id . ':' . $type;
+ // $cache_result = $this->getCache($cfc, $cache_key);
+ // // die;
+ // if ($cache_result !== null) {
+ // return $cache_result;
+ // }
+
+ // 判断用户是否有历史数据
+ $has_history = $this->checkUserHistory($cfc, $user_id);
+
+ if (!$has_history) {
+ // 新用户,返回最火信息(仅一个标签)
+ $result = $this->getPopularRecommendations($cfc, $type, 1, $item_limit);
+ } else {
+ // 老用户,根据类型返回个性化推荐
+
+ if ($type === 'cookbook') {
+ $result = $this->getCookbookRecommendations($cfc, $user_id, $tag_limit, $item_limit);
+
+ } else {
+ $result = $this->getFoodRecommendations($cfc, $user_id, $tag_limit, $item_limit);
+ }
+ }
+
+ // 确保返回格式正确
+ if (!is_array($result)) {
+ $result = [];
+ }
+
+ // 更新缓存
+ // $this->updateCache($cfc, $cache_key, $user_id, $type, $result);
+
+ return $result;
+
+ } catch (\Exception $e) {
+ // 记录错误日志
+ \think\Log::error('猜你喜欢功能错误: ' . $e->getMessage());
+ return [];
+ }
+ }
+
+ /**
+ * 检查用户是否有历史数据
+ */
+ private function checkUserHistory($db, $user_id) {
+ try {
+ // 检查饮食记录
+ // $kcal_result = $db->query("
+ $kcal_result = Db::query("
+ SELECT COUNT(*) as count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ ", [$user_id]);
+ $kcal_count = $kcal_result[0]['count'] ?? 0;
+
+ // 检查搜索记录
+ // $search_result = $db->query("
+ $search_result = Db::query("
+ SELECT COUNT(*) as count
+ FROM {$this->kitchenscale_db_msg['search_history']}
+ WHERE user_id = ? AND is_del = 0
+ ", [$user_id]);
+ $search_count = $search_result[0]['count'] ?? 0;
+
+ return ($kcal_count > 0 || $search_count > 0);
+ } catch (\Exception $e) {
+ return false;
+ }
+ }
+
+ /**
+ * 获取缓存数据
+ */
+ private function getCache($db, $cache_key) {
+ try {
+ // $cache_result = $db->query("
+ $cache_result = Db::query("
+ SELECT id, cache_key, user_id, keyword, recommend_data, hit_count, last_hit, is_del, create_time
+ FROM {$this->kitchenscale_db_msg['recommend_cache']}
+ WHERE cache_key = ? AND is_del = 0
+ ", [$cache_key]);
+
+ if (!empty($cache_result)) {
+ $cache = $cache_result[0];
+ $last_hit_timestamp = strtotime($cache['last_hit']);
+
+ if (time() - $last_hit_timestamp < $this->config['cache_time']) {
+ // 更新命中次数和时间
+ // $db->execute("
+ Db::execute("
+ UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
+ SET hit_count = hit_count + 1, last_hit = GETDATE()
+ WHERE id = ?
+ ", [$cache['id']]);
+
+ $data = json_decode($cache['recommend_data'], true);
+ return is_array($data) ? $data : null;
+ }
+ }
+ } catch (\Exception $e) {
+ // 忽略缓存错误,继续执行
+ }
+
+ return null;
+ }
+
+ /**
+ * 更新缓存
+ */
+ private function updateCache($db, $cache_key, $user_id, $keyword, $data) {
+ try {
+ $current_time = date('Y-m-d H:i:s');
+ $recommend_data = json_encode($data, JSON_UNESCAPED_UNICODE);
+
+ // 检查是否存在缓存
+ // $existing_result = $db->query("
+ $existing_result = Db::query("
+ SELECT id FROM {$this->kitchenscale_db_msg['recommend_cache']}
+ WHERE cache_key = ? AND is_del = 0
+ ", [$cache_key]);
+
+ if (!empty($existing_result)) {
+ // 更新现有缓存
+ // $db->execute("
+ Db::execute("
+ UPDATE {$this->kitchenscale_db_msg['recommend_cache']}
+ SET user_id = ?, keyword = ?, recommend_data = ?, hit_count = 1,
+ last_hit = ?, create_time = ?
+ WHERE cache_key = ? AND is_del = 0
+ ", [$user_id, $keyword, $recommend_data, $current_time, $current_time, $cache_key]);
+ } else {
+ // 插入新缓存
+ // $db->execute("
+ Db::execute("
+ INSERT INTO {$this->kitchenscale_db_msg['recommend_cache']}
+ (cache_key, user_id, keyword, recommend_data, hit_count, last_hit, create_time, is_del)
+ VALUES (?, ?, ?, ?, 1, ?, ?, 0)
+ ", [$cache_key, $user_id, $keyword, $recommend_data, $current_time, $current_time]);
+ }
+ } catch (\Exception $e) {
+ // 忽略缓存更新错误
+ }
+ }
+
+ /**
+ * 获取热门推荐(新用户)
+ */
+ private function getPopularRecommendations($db, $type, $tag_limit, $item_limit) {
+ // dump($type);
+ if ($type === 'cookbook') {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ } else {
+ // dump(111);
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ }
+
+ /**
+ * 获取热门食谱(新用户)
+ */
+ private function getPopularCookbooks($db, $tag_limit, $item_limit) {
+ try {
+ // 简化查询,避免复杂关联导致的错误
+ $popular_cookbooks = $db->query("
+ SELECT TOP {$item_limit}
+ id,
+ title as name
+ FROM {$this->kitchenscale_db_msg['cookbook']}
+ WHERE is_del = 0
+ ORDER BY likes_num DESC, read_it DESC, create_time DESC
+ ");
+ // dump('sp');
+ // dump($popular_cookbooks);
+ $result = [];
+ $label_data = [];
+
+ foreach ($popular_cookbooks as $cookbook) {
+ $label_data[] = [
+ 'name' => $cookbook['name'] ?? '未知食谱',
+ 'id' => $cookbook['id'] ?? 0,
+ 'type' => 'cookbook'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result['最火食谱搜索'] = $label_data;
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return [];
+ }
+ }
+
+ /**
+ * 获取热门食材(新用户)
+ */
+ private function getPopularFoods($db, $tag_limit, $item_limit) {
+ try {
+ // dump(2222);
+ // // 简化查询,避免复杂关联导致的错误
+ // $popular_foods = $db->query("
+ $popular_foods = Db::query("
+ SELECT TOP {$item_limit}
+ id,
+ keyword as name,
+ COUNT(*) as num
+ FROM {$this->kitchenscale_db_msg['search_history']}
+ WHERE is_del = 0 AND type = 'food'
+ GROUP BY id, keyword
+ ORDER BY num DESC
+ ");
+ // dump('sc');
+ // dump($popular_foods);
+
+ $popular_foods_2 = [];
+ if(count($popular_foods) < $item_limit){
+ $num = $item_limit - count($popular_foods);
+ $popular_foods_2 = $db->query("
+ SELECT TOP {$num}
+ id,
+ food_name as name
+ FROM {$this->kitchenscale_db_msg['foodlist3']}
+ WHERE is_del = 0
+ ORDER BY is_popular DESC, food_name ASC
+ ");
+ }
+
+ foreach ($popular_foods_2 as $key => $value) {
+ $popular_foods[] = $value;
+ }
+
+
+ $result = [];
+ $label_data = [];
+
+ foreach ($popular_foods as $food) {
+ $label_data[] = [
+ 'name' => $food['name'] ?? '未知食材',
+ 'id' => $food['id'] ?? 0,
+ 'type' => 'food'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result['最火食材搜索'] = $label_data;
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return [];
+ }
+ }
+
+ /**
+ * 获取个性化食谱推荐(老用户)
+ */
+ private function getCookbookRecommendations($db, $user_id, $tag_limit, $item_limit) {
+ // dump($user_id);
+ try {
+ // 获取用户最常吃的食材
+ // $user_top_foods = $db->query("
+ $user_top_foods = Db::query("
+ SELECT TOP 10 food_id, COUNT(*) as eat_count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ GROUP BY food_id
+ ORDER BY eat_count DESC
+ ", [$user_id]);
+
+ // dump($user_top_foods);
+
+ if (empty($user_top_foods)) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+
+ $food_ids = array_column($user_top_foods, 'food_id');
+ if (empty($food_ids)) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+ $food_ids_str = implode(',', $food_ids);
+ // dump($food_ids_str);
+ // 获取包含这些食材的食谱标签
+ $preferred_labels = $db->query("
+ SELECT TOP {$tag_limit} lbl.id, lbl.name, COUNT(DISTINCT cb.id) as match_count
+ FROM {$this->kitchenscale_db_msg['cookbook_label']} lbl
+ INNER JOIN {$this->kitchenscale_db_msg['cookbook']} cb ON lbl.id = cb.cook_label AND cb.is_del = 0
+ INNER JOIN {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr ON cb.id = cfr.cookbook_id
+ WHERE lbl.is_del = 0 AND cfr.food_id IN ({$food_ids_str})
+ GROUP BY lbl.id, lbl.name
+ ORDER BY match_count DESC
+ ");
+ // dump($preferred_labels);
+ $result = [];
+ foreach ($preferred_labels as $label) {
+ // 使用子查询避免GROUP BY复杂性问题
+ $cookbooks = $db->query("
+ SELECT TOP {$item_limit} cb.id, cb.title as name
+ FROM {$this->kitchenscale_db_msg['cookbook']} cb
+ WHERE cb.id IN (
+ SELECT DISTINCT cfr.cookbook_id
+ FROM {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr
+ WHERE cfr.food_id IN ({$food_ids_str})
+ )
+ AND cb.cook_label = ?
+ AND cb.is_del = 0
+ ORDER BY cb.likes_num DESC, cb.read_it DESC
+ ", [$label['id']]);
+
+ $label_data = [];
+ foreach ($cookbooks as $cookbook) {
+ $label_data[] = [
+ 'name' => $cookbook['name'] ?? '未知食谱',
+ 'id' => $cookbook['id'] ?? 0,
+ 'type' => 'cookbook'
+ ];
+ }
+
+ if (!empty($label_data)) {
+ $result[$label['name'] ?? '未知标签'] = $label_data;
+ }
+ }
+ // dump($result);
+ if(count($result)<=0){
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+ return $result;
+ } catch (\Exception $e) {
+ return $this->getPopularCookbooks($db, $tag_limit, $item_limit);
+ }
+ }
+
+ /**
+ * 获取个性化食材推荐(老用户)
+ */
+ private function getFoodRecommendations($db, $user_id, $tag_limit, $item_limit) {
+ try {
+ // 获取用户最常吃的食材
+ // $user_top_foods = $db->query("
+ $user_top_foods = Db::query("
+ SELECT TOP 10 food_id, COUNT(*) as eat_count
+ FROM {$this->kitchenscale_db_msg['kcal_log']}
+ WHERE aud_id = ? AND is_del = 0
+ GROUP BY food_id
+ ORDER BY eat_count DESC
+ ", [$user_id]);
+
+ if (empty($user_top_foods)) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+
+ $food_ids = array_column($user_top_foods, 'food_id');
+ if (empty($food_ids)) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ $food_ids_str = implode(',', $food_ids);
+
+ // 获取用户偏好食材的分类
+ $preferred_categories = $db->query("
+ SELECT TOP {$tag_limit} f2.id, f2.name, COUNT(DISTINCT f3.id) as food_count
+ FROM {$this->kitchenscale_db_msg['foodlist2']} f2
+ INNER JOIN {$this->kitchenscale_db_msg['foodlist3']} f3 ON f2.id = f3.two_id
+ WHERE f3.id IN ({$food_ids_str}) AND f2.is_del = 0 AND f3.is_del = 0
+ GROUP BY f2.id, f2.name
+ ORDER BY food_count DESC
+ ");
+
+ $result = [];
+ foreach ($preferred_categories as $category) {
+ // 获取该分类下的其他食材
+ $foods = $db->query("
+ SELECT TOP {$item_limit} id, food_name as name
+ FROM {$this->kitchenscale_db_msg['foodlist3']}
+ WHERE two_id = ? AND is_del = 0 AND id NOT IN ({$food_ids_str})
+ ORDER BY is_popular DESC, food_name ASC
+ ", [$category['id']]);
+
+ $category_data = [];
+ foreach ($foods as $food) {
+ $category_data[] = [
+ 'name' => $food['name'] ?? '未知食材',
+ 'id' => $food['id'] ?? 0,
+ 'type' => 'food'
+ ];
+ }
+
+ if (!empty($category_data)) {
+ $result[$category['name'] ?? '未知分类'] = $category_data;
+ }
+ }
+
+ return $result;
+ } catch (\Exception $e) {
+ return $this->getPopularFoods($db, $tag_limit, $item_limit);
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Gufen.php b/application/NewReedaw2/controller/app/Gufen.php
new file mode 100644
index 0000000..010520d
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Gufen.php
@@ -0,0 +1,93 @@
+'app_account_number',
+ 'guize'=>'admin_estimate',
+
+ ];
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 获取单个类型列表
+ public function get_single_data($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){
+ $return_data = $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['address'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ $return_data = $this->sportstesting_get_type_list_action($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);
+ }
+
+ }
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+ public function sportstesting_get_type_list_action($data){
+
+ $parameter_data = explode(',',$data['address']);
+ $gender = $data['gender'];
+ // 精准查询地市规则start
+ // if(count($parameter_data) == 1){
+ // $db_condition = "province = '".$parameter_data[0]."'";
+ // }else if(count($parameter_data) == 2){
+ // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
+ // }else if(count($parameter_data) == 3){
+ // $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
+ // }else{
+ // return $this->msg(10005);
+ // }
+ // 精准查询地市规则end
+ // 全省地市一个规则start
+ $db_condition = "province = '".$parameter_data[0]."'";
+ // 全省地市一个规则end
+ $data = Db::table($this->card_db_name['guize'])->where($db_condition)->find();
+ $data = json_decode($data['content'],true);
+ $result = $this->handle_default_rule_list_content($data,$gender);
+ return $this->msg($result);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Index.php b/application/NewReedaw2/controller/app/Index.php
index 68adcb9..816b3ab 100644
--- a/application/NewReedaw2/controller/app/Index.php
+++ b/application/NewReedaw2/controller/app/Index.php
@@ -1,13 +1,15 @@
'app_account_number',
'juese'=>'app_user_data',
'body_data'=>'app_card_body_data',
-
+ 'banben'=>'app_version_log',
+ 'shangwuhezuo'=>'admin_business_cooperation',
+ 'diqu'=>'admin_estimate',
+ 'banner'=>'admin_notice_banner',
+ 'skip'=>'app_card_skip_data',
+ 'vitalcapacity'=>'app_card_vitalcapacity_data',
+ 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
+ ];
+ 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 $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶'];
+ protected $grade_list = [
+ ['id'=>'nothing','name'=>'无'],
+ ['id'=>'grade_s_1','name'=>'小学一年级'],
+ ['id'=>'grade_s_2','name'=>'小学二年级'],
+ ['id'=>'grade_s_3','name'=>'小学三年级'],
+ ['id'=>'grade_s_4','name'=>'小学四年级'],
+ ['id'=>'grade_s_5','name'=>'小学五年级'],
+ ['id'=>'grade_s_6','name'=>'小学六年级'],
+ ['id'=>'grade_m_1','name'=>'初中一年级'],
+ ['id'=>'grade_m_2','name'=>'初中二年级'],
+ ['id'=>'grade_m_3','name'=>'初中三年级'],
+ ['id'=>'grade_h_1','name'=>'高中一年级'],
+ ['id'=>'grade_h_2','name'=>'高中二年级'],
+ ['id'=>'grade_h_3','name'=>'高中三年级'],
+ ['id'=>'grade_u_12','name'=>'大学一、二年级'],
+ ['id'=>'grade_u_34','name'=>'大学三、四年级']
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
@@ -27,148 +58,96 @@ class Index extends Base{
################################################################接口################################################################
################################################################接口################################################################
+ // 检测版本及判断是否登录失效
+ public function login_invalid_version(){
+
+ $data = input('post.');
+ try {
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+
+ $result = Db::table($this->index_db_name['banben'])->order('is_del,id desc')->find();
+ if($result){
+ $version = $result['version_num_original'];
+ $url = $result['download_url'];
+ }else{
+ $version = '';
+ $url = '';
+ }
+ if($data['token'] == ''){
+ return $this->msg(-2,'未登录',['version'=>$version,'url'=>$url,]);
+ // return $this->msg(-2,'未登录',['version'=>$version,'url'=>$url,'language'=>'zh-Hans','language_arr'=>$this->process_Language()]);
+ }
+ $user_token_state = $this->token_time_validate($data['token']);
+
+ if($user_token_state['state'] === false){
+ return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,]);
+ // return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]);
+ }else{
+ return $this->msg(['version'=>$version,'url'=>$url,]);
+ // return $this->msg(['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]);
+ }
+ } 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'] .= "方法: " . __METHOD__ . "\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 config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
- try {
- // 你的业务逻辑
- if(count(input('post.')) > 0){
- $data = input('post.');
- }
- if(!array_key_exists('token', $data)){
- return $this->msg(10001);
- }
- if(!$this->verify_data_is_ok($data['token'],'str')){
- return $this->msg(10005);
- }
- return $this->config_action($data);
- } catch (\Exception $e) {
- // 捕获异常
- $logContent["flie"] = $e->getFile();
- $logContent["line"] = $e->getLine();
- $logContent['all_content'] = "异常信息:\n";
- $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
- $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
- $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
- $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
- $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
- $this->record_api_log($data, $logContent, null);
- return $this->msg(99999);
- }
- }
- // 遗传身高
- public function genetic_height(){
- try {
- $data = input('post.');
- if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
- return $this->msg(10001);
- }
- unset($data['token']);
- if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['dadHeight'],'num')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['momHeight'],'num')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['sex'],'intnum')){
- return $this->msg(10005);
- }
-
- // 直接开始业务,请求外部接口start
- $url = 'https://ybapi.pcxbc.com/api/child/predictheight';
- $temporary_parameter = [
- 'dadHeight'=>$data['dadHeight'],
- 'momHeight'=>$data['momHeight'],
- 'birthday'=>$data['birthday'],
- 'sex'=>$data['sex'],
- ];
- $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
- // 直接开始业务,请求外部接口end
- return json($request_result);
- } catch (\Exception $e) {
- // 捕获异常
- $logContent["flie"] = $e->getFile();
- $logContent["line"] = $e->getLine();
- $logContent['all_content'] = "异常信息:\n";
- $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
- $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
- $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
- $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
- $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
- $this->record_api_log($data, $logContent, null);
- return $this->msg(99999);
- }
- }
- // BMI测评
- public function bmi_evaluation(){
- try {
- $data = input('post.');
- if(!array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){
- return $this->msg(10001);
- }
- unset($data['token']);
- if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['height'],'num')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['weight'],'num')){
- return $this->msg(10005);
- }
- if(!$this->verify_data_is_ok($data['sex'],'intnum')){
- return $this->msg(10005);
- }
-
- // 直接开始业务,请求外部接口start
- $url = 'http://ybdevice.pcxbc.com/api/result/calcbmi';
- $temporary_parameter = [
- 'height'=>$data['height'],
- 'weight'=>$data['weight'],
- 'birthday'=>$data['birthday'],
- 'sex'=>$data['sex'],
- ];
- $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com'));
- // 直接开始业务,请求外部接口end
-
- // 处理进度点
- $return_result =$this->bmi_evaluation_action($request_result);
- return $return_result;
- } catch (\Exception $e) {
- // 捕获异常
- $logContent["flie"] = $e->getFile();
- $logContent["line"] = $e->getLine();
- $logContent['all_content'] = "异常信息:\n";
- $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
- $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
- $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
- $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
- $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
- $this->record_api_log($data, $logContent, null);
- return $this->msg(99999);
- }
- }
- // 获取首页角色信息
- public function get_user_data_information(){
- try {
- $data = input('post.');
- if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
- return $this->msg(10001);
+ public function config(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
- if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
- return $this->msg(10005,'aud_id type error');
+ return $this->config_action($data);
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: config" . "\n";
+ // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ // $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ // $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // $this->record_api_log($data, $logContent, null);
+ // return $this->msg(99999);
+ // }
+ }
+
+ // 获取角色信息
+ public function get_user_list(){
+ $data = input('post.');
+ try {
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
}
- return $this->get_user_data_information_action($data);
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ return $this->get_user_list_action($data);
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "函数: get_user_list" . "\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
@@ -179,6 +158,64 @@ class Index extends Base{
}
}
+
+ // 隐私协议手机网页端
+ public function privacy_policy(){
+ return $this->fetch();
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+ // // 数据对比(包含身体、跳绳、肺活量)
+ // public function all_data_contrast($data = ['before_id'=>'171','after_id'=>'174','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){
+ // try {
+ // $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']);
+ // 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);
+ // }
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ // $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ // $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ // $this->record_api_log($data, $logContent, null);
+ // return $this->msg(99999);
+ // }
+
+ // }
+
+
################################################################action################################################################
################################################################action################################################################
@@ -193,6 +230,7 @@ class Index extends Base{
'《WHO 5~19岁身高/体重判定标准》',
],
'bmi_evaluation'=>[
+ "BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。",
'*数据参考:',
'《WHO 5~19岁身高/体重判定标准》'
],
@@ -206,93 +244,534 @@ class Index extends Base{
'此测量数据仅供参考,不可替代医学专业测试!'
]
],
- 'king_kong_region'=>[
- ['title'=>'增量对比','icon'=>'','jump'=>''],
- ['title'=>'中招估分','icon'=>'','jump'=>''],
- ['title'=>'遗传身高','icon'=>'','jump'=>''],
- ['title'=>'BMI测评','icon'=>'','jump'=>''],
+ // 'king_kong_region'=>[
+ // ['title'=>'减值对比','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/contrast.png','jump'=>'/pageTwo/compk/contrast'],
+ // ['title'=>'中招估分','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/report.png','jump'=>'/pageTwo/score/report'],
+ // ['title'=>'遗传身高','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/inheritHeighet.png','jump'=>'/pageTwo/home/inheritHeighet'],
+ // ['title'=>'BMI测评','icon'=>'https://tc.pcxbc.com/new_reedaw/icon/bmi.png','jump'=>'/pageTwo/home/bmi'],
+ // ],
+ 'business_cooperation_url'=>[],
+ 'area_list'=>[],
+ 'identity_list'=>[],
+ 'grade_list'=>[],
+ 'banner'=>[],
+ 'activity_level'=>[
+ ['name'=>'久坐(很少或没有运动)','val'=>'1.2'],
+ ['name'=>'轻度活动(每周1-3天轻度运动)','val'=>'1.375'],
+ ['name'=>'中度活动(每周3-5天中度运动)','val'=>'1.55'],
+ ['name'=>'高度活动(每周6-7天高强度运动)','val'=>'1.725'],
+ ['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'],
+ ],
+ 'meal_list'=>[
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png','name'=>'早餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png','name'=>'午餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png','name'=>'晚餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3_bg.jpg'],
+ ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png','name'=>'加餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4_bg.jpg'],
+ ],
+ 'default_count_foot'=>[
+ 'date' => '',
+ 'remaining_kcal' => 0,
+ 'details' => [
+ 'carbohydrate' => [
+ 'name' => '碳水',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png',
+ 'color' => '#ED7886',
+ 'val' => 0,
+ 'unit' => 'g',
+ 'proportion' => '0.00',
+ 'rank_list' => [
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank1.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank2.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank3.png', 'name' => '', 'pic_url' => '', 'weight' => '']
+ ]
+ ],
+ 'protein' => [
+ 'name' => '蛋白质',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png',
+ 'color' => '#FFB169',
+ 'val' => 0,
+ 'unit' => 'g',
+ 'proportion' => '0.00',
+ 'rank_list' => [
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank1.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank2.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank3.png', 'name' => '', 'pic_url' => '', 'weight' => '']
+ ]
+ ],
+ 'fat' => [
+ 'name' => '脂肪',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png',
+ 'color' => '#3CB383',
+ 'val' => 0,
+ 'unit' => 'g',
+ 'proportion' => '0.00',
+ 'rank_list' => [
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank1.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank2.png', 'name' => '', 'pic_url' => '', 'weight' => ''],
+ ['icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank3.png', 'name' => '', 'pic_url' => '', 'weight' => '']
+ ]
+ ]
+ ],
+ 'trace_elements_all_day' => [
+ ['name' => 'VitaminA', 'name_ch' => '维生素A', 'unit' => 'μg RAE', 'value' => 0],
+ ['name' => 'VitaminB1', 'name_ch' => '硫胺素', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'VitaminB2', 'name_ch' => '核黄素', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'VitaminB6', 'name_ch' => '维生素B6', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'VitaminB12', 'name_ch' => '维生素B12', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'VitaminD', 'name_ch' => '维生素D', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'VitaminK', 'name_ch' => '维生素K', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'Niacin', 'name_ch' => '烟酸', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'VitaminC', 'name_ch' => '维生素C', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'VitaminE', 'name_ch' => '维生素E', 'unit' => 'mg α-TE', 'value' => 0],
+ ['name' => 'FolicAcid', 'name_ch' => '叶酸', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'Biotin', 'name_ch' => '生物素', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'PantothenicAcid', 'name_ch' => '泛酸', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'TotalCholine', 'name_ch' => '总胆碱', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Ca', 'name_ch' => '钙', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Phosphorus', 'name_ch' => '磷', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Kalium', 'name_ch' => '钾', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Mg', 'name_ch' => '镁', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Na', 'name_ch' => '钠', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Fe', 'name_ch' => '铁', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Zn', 'name_ch' => '锌', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Se', 'name_ch' => '硒', 'unit' => 'μg', 'value' => 0],
+ ['name' => 'Cu', 'name_ch' => '铜', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Mn', 'name_ch' => '锰', 'unit' => 'mg', 'value' => 0],
+ ['name' => 'Iodine', 'name_ch' => '碘', 'unit' => 'μg', 'value' => 0]
+ ],
+ 'list' => [
+ [
+ 'name' => '早餐',
+ 'val' => 0,
+ 'unit' => 'kcal',
+ 'color' => '#0992B4',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
+ 'icon_home' => '/static/1.png',
+ 'bgimg_home' => '/static/2.png',
+ 'kcal_proportion' => 0,
+ 'nutrients_four' => [
+ ['name' => '卡路里', 'unit' => 'kcal', 'color' => '', 'value' => 0, 'proportion' => 0],
+ ['name' => '碳水化合物', 'unit' => 'g', 'color' => '#FFB169', 'value' => 0, 'proportion' => 0],
+ ['name' => '蛋白质', 'unit' => 'g', 'color' => '#5180D8', 'value' => 0, 'proportion' => 0],
+ ['name' => '脂肪', 'unit' => 'g', 'color' => '#ED7886', 'value' => 0, 'proportion' => 0]
+ ],
+ 'list' => []
+ ],
+ [
+ 'name' => '午餐',
+ 'val' => 0,
+ 'unit' => 'kcal',
+ 'color' => '#4F9211',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
+ 'icon_home' => '/static/3.png',
+ 'bgimg_home' => '/static/4.png',
+ 'kcal_proportion' => 0,
+ 'nutrients_four' => [
+ ['name' => '卡路里', 'unit' => 'kcal', 'color' => '', 'value' => 0, 'proportion' => 0],
+ ['name' => '蛋白质', 'unit' => 'g', 'color' => '#5180D8', 'value' => 0, 'proportion' => 0],
+ ['name' => '脂肪', 'unit' => 'g', 'color' => '#ED7886', 'value' => 0, 'proportion' => 0],
+ ['name' => '碳水化合物', 'unit' => 'g', 'color' => '#FFB169', 'value' => 0, 'proportion' => 0]
+ ],
+ 'list' => []
+ ],
+ [
+ 'name' => '晚餐',
+ 'val' => 0,
+ 'unit' => 'kcal',
+ 'color' => '#B354B0',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
+ 'icon_home' => '/static/5.png',
+ 'bgimg_home' => '/static/6.png',
+ 'kcal_proportion' => 0,
+ 'nutrients_four' => [
+ ['name' => '卡路里', 'unit' => 'kcal', 'color' => '', 'value' => 0, 'proportion' => 0],
+ ['name' => '蛋白质', 'unit' => 'g', 'color' => '#5180D8', 'value' => 0, 'proportion' => 0],
+ ['name' => '脂肪', 'unit' => 'g', 'color' => '#ED7886', 'value' => 0, 'proportion' => 0],
+ ['name' => '碳水化合物', 'unit' => 'g', 'color' => '#FFB169', 'value' => 0, 'proportion' => 0]
+ ],
+ 'list' => []
+ ],
+ [
+ 'name' => '加餐',
+ 'val' => 0,
+ 'unit' => 'kcal',
+ 'color' => '#C08433',
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
+ 'icon_home' => '/static/7.png',
+ 'bgimg_home' => '/static/8.png',
+ 'kcal_proportion' => 0,
+ 'nutrients_four' => [
+ ['name' => '卡路里', 'unit' => 'kcal', 'color' => '', 'value' => 0, 'proportion' => 0],
+ ['name' => '蛋白质', 'unit' => 'g', 'color' => '#5180D8', 'value' => 0, 'proportion' => 0],
+ ['name' => '脂肪', 'unit' => 'g', 'color' => '#ED7886', 'value' => 0, 'proportion' => 0],
+ ['name' => '碳水化合物', 'unit' => 'g', 'color' => '#FFB169', 'value' => 0, 'proportion' => 0]
+ ],
+ 'list' => []
+ ]
+ ],
+ 'nutrients_four' => [
+ ['name' => '卡路里', 'unit' => 'kcal', 'suggestion' => '0', 'today_intake' => 0, 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png', 'color' => '#5180D8', 'proportion' => '0.00', 'proportion_fp' => 0],
+ ['name' => '碳水', 'unit' => 'g', 'suggestion' => '0', 'today_intake' => 0, 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png', 'color' => '#ED7886', 'proportion' => '0.00', 'proportion_fp' => '0'],
+ ['name' => '蛋白质', 'unit' => 'g', 'suggestion' => '0', 'today_intake' => 0, 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png', 'color' => '#FFB169', 'proportion' => '0.00', 'proportion_fp' => '0'],
+ ['name' => '脂肪', 'unit' => 'g', 'suggestion' => '0', 'today_intake' => 0, 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png', 'color' => '#3CB383', 'proportion' => '0.00', 'proportion_fp' => '0']
+ ]
],
- 'role_list'=>[
- ]
];
- $role = new Role;
- $return_data['role_list'] = $role->role_list_action(['token'=>$data['token'],'type'=>2])->getData()['data'];
+ // $food_count = ;
+
+ // 处理厨房秤config
+ // $cf_index = new Cfindex;
+ // $cf_confog = $cf_index->get_default_config_action($data)->getData()['data'];
+
+
+
+
+
+ $return_data['business_cooperation_url'] = Db::table($this->index_db_name['shangwuhezuo'])->where(['is_del'=>0])->field('title,data_url as url')->select();
+
+ $address_data = Db::table($this->index_db_name['diqu'])->where(['type' => '2'])->cache(86400)->field('id,content,city,area')->find();
+ $return_data['area_list'] = json_decode($address_data['content'],true);
+ $return_data['identity_list'] = [];
+ foreach ($this->identity_list as $key => $value) {
+ array_push($return_data['identity_list'],['id'=>$key,'name'=>$value]);
+ }
+ $return_data['grade_list'] = $this->grade_list;
+
+ $return_data['banner'] = Db::table($this->index_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(3600)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
+
+ for ($i=0; $i < count($return_data['banner']); $i++) {
+ if($return_data['banner'][$i]['type'] != 1){
+ $return_data['banner'][$i]['parameter_data'] = '';
+ }
+ unset($return_data['banner'][$i]['sort_num']);
+ unset($return_data['banner'][$i]['ROW_NUMBER']);
+ }
+
+
+ // 添加菜谱类型start
+ $cfc = Db::connect('cfc_db');
+ $cookbook_label = $cfc->table($this->index_db_name['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
+ $return_data['cookbook_label'] = $cookbook_label;
+ // 添加菜谱类型end
+
+ // $return_data['cfc'] = $cf_confog;
return $this->msg($return_data);
}
- public function bmi_evaluation_action($data){
- // 加 bcadd(,,20)
- // 减 bcsub(,,20)
- // 乘 bcmul(,,20)
- // 除 bcdiv(,,20)
- if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){
- return $this->msg(99999,'网络异常,请稍后重试1');
- }
- if($data['code'] != 0){
- return $this->msg(99999,'网络异常,请稍后重试2');
- }
- if(!is_array($data['data'])){
- return $this->msg(99999,'网络异常,请稍后重试3');
- }
- if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){
- return $this->msg(99999,'网络异常,请稍后重试4');
- }
- if(!is_array($data['data']['bmilevellist'])){
- return $this->msg(99999,'网络异常,请稍后重试5');
- }
- $num = 0;
- $subsection_val = 0;
- $temporary_subsection_val = null;
- foreach ($data['data']['bmilevellist'] as $key => $value) {
- if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){
- return $this->msg(99999,'网络异常,请稍后重试6');
- }
- // 判断是否可以进行比较,规则是否正确
- if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){
- if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){
- // 在落点内
- $subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差
- $temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差
- $temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比
- $subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比
- $temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比
- $temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1);
- }else{
- $num = $num + 1;
- }
- }
- }
-
- if($temporary_subsection_val === null){
- if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){
- $temporary_subsection_val = 100;
- }else{
- return $this->msg(99999,'网络异常,请稍后重试7');
- }
- }
- $data['data']['offset'] = $temporary_subsection_val;
- $data = $data['data'];
- // 处理key名称一致start
- foreach ($data['bmilevellist'] as $key => $value) {
- $data['bmilevellist'][$key]['max_val'] = $value['maxvalue'];
- $data['bmilevellist'][$key]['min_val'] = $value['minvalue'];
- unset($data['bmilevellist'][$key]['minvalue']);
- unset($data['bmilevellist'][$key]['maxvalue']);
- }
- // 处理key名称一致end
- return $this->msg($data);
- }
- public function get_user_data_information_action($data){
- $return_result = [
- 'body_data'=>[],
- 'kcal_data'=>[],
- 'card_data'=>[]
- ];
- $aud_data = Db::table($this->index_db_name['juese'])->where(['id'=>$data['aud_id']])->find();
- $body_data = Db::table($this->index_db_name['body_data'])->where(['id'=>$data['aud_id']])->find();
-
-
+ public function get_user_list_action($data){
+
+ $account_data = Db::table($this->index_db_name['zhanghao'])->where(['token' => $data['token'],'is_del' => 0])->field('token,id,default_user_id')->find();
+ if(!$account_data){
+ return $this->msg(10003);
+ }
+
+ $user_list = Db::table($this->index_db_name['juese'])->where(['aan_id' => $account_data['id'],'is_del' => 0])->field('id,id as aud_id,activity_level,nickname,birthday,gender,card_order,head_pic,grade,weight,height,identity_name,identity_id')->select();
+
+ foreach ($user_list as $key => $value) {
+ $user_list[$key]['age'] = $this->calculate_age($value['birthday']);
+ }
+ $result_data = ['default_user_id'=>$account_data['default_user_id'],'user_list'=>$user_list];
+ return $this->msg($result_data);
}
+
+
+
+
+
+
+
+ // // 数据对比(身体)
+ // 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->index_db_name['body_data']." as acbd
+ // left join ".$this->index_db_name['juese']." 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),
+ // ]);
+ // }
+ // }
+ // // 添加头围数据(如果需要的话)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->index_db_name['skip']." as acsd
+ // left join ".$this->index_db_name['juese']." 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->index_db_name['vitalcapacity']." as acsd
+ // left join ".$this->index_db_name['juese']." 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);
+ // }
+
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+
+
+
}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Kitchenscale.php b/application/NewReedaw2/controller/app/Kitchenscale.php
new file mode 100644
index 0000000..9511527
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Kitchenscale.php
@@ -0,0 +1,2903 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'eat_log'=>'app_user_kcal_log',//
+ 'tiaoma'=>'app_commodity_barcode',//
+ 'search_history'=>'app_user_search_history',//搜索历史表
+ 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
+ 'foodlist3'=>'app_z_national_standard_food_type_3',//食材
+ 'foodlist4'=>'app_z_national_standard_food_type_4',//食材营养物质
+ 'collect_list'=>'app_user_collect_list',//点赞表
+ 'cookbook'=>'app_user_cookbook',//菜谱表
+ 'uploadimg'=>'app_user_upload_img',//图片素材表
+ 'nutrition'=>'app_user_cookbook_nutrition',//能量
+ 'vitamin'=>'app_user_cookbook_vitamin',//维生素
+ 'mineral'=>'app_user_cookbook_mineral',//矿物质
+ ];
+
+ // protected $skip_use_db_name = [
+ // '1'=>'app_card_skip_data',
+ // '2'=>'app_user_data',
+ // '3'=>'app_card_body_data',
+ // ];
+ protected $page_num = 10;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ ################################################################首页
+ // // 根据用户获取他的饮食信息(首页)
+ // public function user_diet_content(){
+ // $data = input('post.');
+ // try {
+ // if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ // return $this->msg(10001);
+ // }
+ // if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ // return $this->msg(10005,'aud_id type error');
+ // }
+ // if(!$this->verify_data_is_ok($data['token'],'str')){
+ // return $this->msg(10005,'r_time type error');
+ // }
+ // return $this->user_diet_content_action($data);
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ // $logContent['all_content'] .= "接口: user_diet_content\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 update_user_msg(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'nickname is miss');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'gender is miss');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'birthday is miss');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'height is miss');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'weight is miss');
+ }
+ if(!array_key_exists('activity_level', $data)){
+ return $this->msg(10001,'weight is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type is error');
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005,'gender type is error');
+ }
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005,'birthday type is error');
+ }
+ if(!$this->verify_data_is_ok($data['height'],'num')){
+ return $this->msg(10005,'height type is error');
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005,'weight type is error');
+ }
+ if(!$this->verify_data_is_ok($data['activity_level'],'num')){
+ return $this->msg(10005,'activity_level type is error');
+ }
+ return $this->update_user_msg_action($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'] .= "接口: update_user_msg\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 search_default_msg(){
+ try {
+ $data = input('post.');
+ $return_data = $this->search_default_msg_action($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'] .= "接口: search_default_msg\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_food_list(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ $return_data = $this->get_food_list_action($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'] .= "接口: get_food_list\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 搜索菜谱列表
+ public function search_column(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('search_data', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['search_data'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->search_column_action($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'] .= "接口: (search_column)\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);
+ // }
+ }
+ // 查询食谱的详情(OK)
+ public function cookbook_details(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->cookbook_details_action($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'] .= "接口: (cookbook_details)\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 点赞收藏菜谱(OK)
+ public function cookbook_like(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('cookbook_id', $data)){
+ return $this->msg(10001,'cookbook_id is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
+ return $this->msg(10005,'cookbook_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->cookbook_like_action($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'] .= "接口: (cookbook_like)\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 搜索历史删除
+ public function del_search_history(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!array_key_exists('del_arr', $data)){
+ return $this->msg(10001,'del_arr is miss');
+ }
+ if(!$this->verify_data_is_ok($data['del_arr'],'str')){
+ return $this->msg(10005,'del_arr type is error');
+ }
+ $data['del_arr'] = strval($data['del_arr']);
+ $data['del_arr'] = trim($data['del_arr']);
+ // 判断是否是 "all"(不区分大小写)
+ if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
+ return $this->msg(10005,'del_arr type is error');
+ }
+
+ $return_data = $this->del_search_history_action($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'] .= "接口: (del_search_history)\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+ ################################################################记食器
+ // 获取记食器板块内容
+ public function get_countfoot_content(){
+ $data = input('post.');
+ // 尝试捕获异常
+ try {
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('time', $data)){
+ return $this->msg(10001,'time is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type is error');
+ }
+ return $this->get_countfoot_content_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "接口: get_countfoot_content\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 添加每日摄入记录
+ public function add_intake_food(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('food_list', $data)){
+ return $this->msg(10001,'food_list is miss');
+ }
+ if(!array_key_exists('time', $data)){
+ return $this->msg(10001,'food_list is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type is error');
+ }
+ $return_data = $this->add_intake_food_action($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'] .= "接口: add_intake_food\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 获取记食器饮食记录
+ public function get_log_list(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+
+ $return_data = $this->get_log_list_action($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'] .= "接口: get_log_list\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 设置角色营养比例
+ public function set_nutrition_proportion(){
+ // 尝试捕获异常
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!array_key_exists('set_kcal', $data)){
+ return $this->msg(10001,'set_kcal is miss');
+ }
+ if(!$this->verify_data_is_ok($data['set_kcal'],'num')){
+ return $this->msg(10005,'set_kcal type is error');
+ }
+ if(!array_key_exists('carbohydrate_v', $data)){
+ return $this->msg(10001,'carbohydrate_v is miss');
+ }
+ if(!$this->verify_data_is_ok($data['carbohydrate_v'],'num')){
+ return $this->msg(10005,'carbohydrate_v type is error');
+ }
+ if(!array_key_exists('carbohydrate_p', $data)){
+ return $this->msg(10001,'carbohydrate_p is miss');
+ }
+ if(!$this->verify_data_is_ok($data['carbohydrate_p'],'num')){
+ return $this->msg(10005,'carbohydrate_p type is error');
+ }
+
+ if(!array_key_exists('protein_v', $data)){
+ return $this->msg(10001,'protein_v is miss');
+ }
+ if(!$this->verify_data_is_ok($data['protein_v'],'num')){
+ return $this->msg(10005,'protein_v type is error');
+ }
+ if(!array_key_exists('protein_p', $data)){
+ return $this->msg(10001,'protein_p is miss');
+ }
+ if(!$this->verify_data_is_ok($data['protein_p'],'num')){
+ return $this->msg(10005,'protein_p type is error');
+ }
+
+ if(!array_key_exists('fat_v', $data)){
+ return $this->msg(10001,'fat_v is miss');
+ }
+ if(!$this->verify_data_is_ok($data['fat_v'],'num')){
+ return $this->msg(10005,'fat_v type is error');
+ }
+ if(!array_key_exists('fat_p', $data)){
+ return $this->msg(10001,'fat_p is miss');
+ }
+ if(!$this->verify_data_is_ok($data['fat_p'],'num')){
+ return $this->msg(10005,'fat_p type is error');
+ }
+
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'num')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->set_nutrition_proportion_action($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'] .= "接口: (set_nutrition_proportion)\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 删除一条指定的饮食记录
+ public function del_user_eat_log(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!array_key_exists('eat_log_id', $data)){
+ return $this->msg(10001,'eat_log_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ if(!$this->verify_data_is_ok($data['eat_log_id'],'num')){
+ return $this->msg(10005,'eat_log_id type is error');
+ }
+
+ $return_data = $this->del_user_eat_log_action($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'] .= "接口: (del_user_eat_log)\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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 删除某一天的的饮食记录
+ public function del_user_eat_list_log(){
+ // 尝试捕获异常
+ try {
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('time', $data)){
+ return $this->msg(10001,'time is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+
+ $return_data = $this->del_user_eat_list_log_action($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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 计食器板块-设置内容
+ public function set_up_content(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+
+ $return_data = $this->set_up_content_action($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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+ // 本次添加食材的营养统计
+ public function current_food_statistics(){
+ // 尝试捕获异常
+ $data = input('post.');
+ try {
+ if(!array_key_exists('log_id', $data)){
+ return $this->msg(10001,'log_id is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+
+ if(is_array($data['log_id'])){
+ foreach ($data['log_id'] as $key => $value) {
+ if(!$this->verify_data_is_ok($value,'intnum')){
+ return $this->msg(10005,'log_id type is error');
+ }
+ }
+ }else{
+ return $this->msg(10005,'log_id type is error');
+ }
+
+ $return_data = $this->current_food_statistics_action($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 json(['status' => 'error', 'message' => '系统错误']);
+ }
+ }
+
+ ################################################################我的
+ // 获取用户收藏点赞列表(OK)
+ public function get_user_collect_list(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is miss');
+ }
+ if(!array_key_exists('page', $data)){
+ return $this->msg(10001,'page is miss');
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001,'aud_id is miss');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type is error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type is error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type is error');
+ }
+ $return_data = $this->get_user_collect_list_action($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'] .= "接口: (get_default_config)\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+ // public function user_diet_content_action($data){
+ // // 获取账号下信息以及用户信息
+ // $zhanghao_data = Db::table($this->kitchenscale_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic,tel,email')->find();
+
+ // if(!$zhanghao_data){
+ // return $this->msg(10004);
+ // }
+ // // 获取账号下信息以及用户信息start
+ // $user_all_data['aud_id'] = '';
+ // $user_all_data['token'] = $zhanghao_data['token'];
+ // $user_all_data['nickname'] = '';
+ // $user_all_data['head_pic'] = $zhanghao_data['head_pic'];
+ // $user_all_data['gender'] = '';
+ // $user_all_data['age'] = '';
+ // $user_all_data['height'] = '';
+ // $user_all_data['weight'] = '';
+ // $user_all_data['set_kcal'] = '';
+ // $user_all_data['is_use_set_kcal'] = '';
+ // $user_all_data['tel'] = $zhanghao_data['tel'];
+ // $user_all_data['email'] = $zhanghao_data['email'];
+
+ // $user_account = Db::table($this->kitchenscale_db_name['juese'])
+ // ->where(["id"=>$data['aud_id']])
+ // ->field('id as aud_id,nickname,head_pic,gender,height,weight,set_kcal,is_use_set_kcal,birthday,activity_level')
+ // ->find();
+
+ // if($user_account){
+ // if($user_account['set_kcal'] == '.00'){
+ // $user_account['set_kcal'] = 0;
+ // }
+ // $user_all_data['aud_id'] = $user_account['aud_id'];
+ // $user_all_data['nickname'] = $user_account['nickname'];
+ // $user_all_data['gender'] = $user_account['gender'];
+ // $user_all_data['age'] = $this->calculate_age($user_account['birthday']);
+ // $user_all_data['height'] = $user_account['height'];
+ // $user_all_data['weight'] = $user_account['weight'];
+ // $user_all_data['set_kcal'] = $user_account['set_kcal'];
+ // $user_all_data['is_use_set_kcal'] = $user_account['is_use_set_kcal'];
+ // $user_all_data['birthday'] = $user_account['birthday'];
+ // $user_all_data['activity_level'] = $user_account['activity_level'];
+ // if($user_all_data['gender'] == 2){
+ // if($user_all_data['age'] <= 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman1.png";
+ // }else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman2.png";
+ // }else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman3.png";
+ // }else if($user_all_data['age'] >= 60){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman4.png";
+ // }
+ // }else{
+ // if($user_all_data['age'] <= 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
+ // }else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man2.png";
+ // }else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man3.png";
+ // }else if($user_all_data['age'] >= 60){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man4.png";
+ // }
+ // }
+
+ // $user_all_data['food_count'] = $this->get_countfoot_content_action(['token'=>$data['token'],'aud_id'=>$user_all_data['aud_id'],'time'=>date('Y-m-d')]);
+ // $user_all_data['food_count'] = ($user_all_data['food_count']->getData())['data'];
+ // // dump($user_all_data['food_count']);
+ // }else{
+ // $user_account['set_kcal'] = 0;
+ // $user_all_data['aud_id'] = null;
+ // $user_all_data['gender'] = 0;
+ // $user_all_data['age'] = false;
+ // $user_all_data['height'] = null;
+ // $user_all_data['weight'] = null;
+ // $user_all_data['set_kcal'] = 0;
+ // $user_all_data['is_use_set_kcal'] = 0;
+ // $user_all_data['birthday'] = null;
+ // $user_all_data['activity_level'] = null;
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
+
+ // $user_all_data['food_count'] = $this->get_countfoot_content_action(['token'=>$data['token'],'aud_id'=>$user_all_data['aud_id'],'time'=>date('Y-m-d')]);
+ // $user_all_data['food_count'] = ($user_all_data['food_count']->getData())['data'];
+ // }
+ // return $this->msg($user_all_data);
+ // }
+
+ public function get_countfoot_content_action($data){
+ $cfc = Db::connect('cfc_db');
+ $return_data = [
+ 'date'=>$data['time'], //时间
+ 'suggestion'=>[ //建议
+ 'kcal'=>0, //建议摄入卡路里量
+ 'carbohydrate'=>0, //建议摄入碳水量
+ 'protein'=>0, //建议摄入蛋白质量
+ 'fat'=>0, //建议摄入脂肪量
+ ],
+ 'today_intake'=>[ //今日已摄入
+ 'kcal'=>0, //今日已摄入卡路里量
+ 'carbohydrate'=>0, //今日已摄入碳水量
+ 'protein'=>0, //今日已摄入蛋白质量
+ 'fat'=>0, //今日已摄入脂肪量
+ ],
+ 'remaining_kcal'=>0, //剩下可摄入卡路里量
+ 'details'=>[ //当天营养元素能量占比
+ 'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ 'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]],
+ ],
+ 'trace_elements_all_day' => [
+ [
+ 'name' => 'VitaminA',
+ 'name_ch' => '维生素A',
+ 'unit' => 'μg RAE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB1',
+ 'name_ch' => '硫胺素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB2',
+ 'name_ch' => '核黄素',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB6',
+ 'name_ch' => '维生素B6',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminB12',
+ 'name_ch' => '维生素B12',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminD',
+ 'name_ch' => '维生素D',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminK',
+ 'name_ch' => '维生素K',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Niacin',
+ 'name_ch' => '烟酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminC',
+ 'name_ch' => '维生素C',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'VitaminE',
+ 'name_ch' => '维生素E',
+ 'unit' => 'mg α-TE',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'FolicAcid',
+ 'name_ch' => '叶酸',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Biotin',
+ 'name_ch' => '生物素',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'PantothenicAcid',
+ 'name_ch' => '泛酸',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'TotalCholine',
+ 'name_ch' => '总胆碱',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Ca',
+ 'name_ch' => '钙',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Phosphorus',
+ 'name_ch' => '磷',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Kalium',
+ 'name_ch' => '钾',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mg',
+ 'name_ch' => '镁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Na',
+ 'name_ch' => '钠',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Fe',
+ 'name_ch' => '铁',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Zn',
+ 'name_ch' => '锌',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Se',
+ 'name_ch' => '硒',
+ 'unit' => 'μg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Cu',
+ 'name_ch' => '铜',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Mn',
+ 'name_ch' => '锰',
+ 'unit' => 'mg',
+ 'value' => 0
+ ],
+ [
+ 'name' => 'Iodine',
+ 'name_ch' => '碘',
+ 'unit' => 'μg',
+ 'value' => 0
+ ]
+ ],
+ 'list'=>[
+ [
+ 'name'=>'早餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#0992B4',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
+ 'icon_home'=>'/static/1.png',
+ 'bgimg_home'=>'/static/2.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'午餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#4F9211',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
+ 'icon_home'=>'/static/3.png',
+ 'bgimg_home'=>'/static/4.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'晚餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#B354B0',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
+ 'icon_home'=>'/static/5.png',
+ 'bgimg_home'=>'/static/6.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ [
+ 'name'=>'加餐',
+ 'val'=>0,
+ 'unit'=>'kcal',
+ 'color'=>'#C08433',
+ 'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
+ 'icon_home'=>'/static/7.png',
+ 'bgimg_home'=>'/static/8.png',
+ 'kcal_proportion'=>0,
+ "nutrients_four"=> [
+ [
+ 'name'=>'卡路里',
+ 'unit'=>'kcal',
+ 'color'=>'',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'unit'=>'g',
+ 'color'=>'#5180D8',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'脂肪',
+ 'unit'=>'g',
+ 'color'=>'#ED7886',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ [
+ 'name'=>'碳水化合物',
+ 'unit'=>'g',
+ 'color'=>'#FFB169',
+ 'value'=>0,
+ 'proportion'=>0,
+ ],
+ ],
+ 'list'=>[],
+ ],
+ ],
+ ];
+
+ // if(!$data['aud_id']){//内部调用
+ // return $this->msg($return_data);
+ // }
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,is_use_set_kcal,set_kcal,birthday,set_carbohydrate_v,set_carbohydrate_p,set_protein_v,set_protein_p,set_fat_v,set_fat_p,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal'];
+ $nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate'];
+ $nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein'];
+ $nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat'];
+
+
+ $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?$user_data['set_carbohydrate_p']:bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?$user_data['set_protein_p']:bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?$user_data['set_fat_p']:bcmul($nutrition_data['fat_p'],100,2);
+ }else{
+ $nutrition_data['carbohydrate_p'] = bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = bcmul($nutrition_data['fat_p'],100,2);
+ }
+
+ $return_data['suggestion']['kcal'] = $nutrition_data['kcal'];
+ $return_data['suggestion']['carbohydrate'] = $nutrition_data['carbohydrate'];
+ $return_data['suggestion']['protein'] = $nutrition_data['protein'];
+ $return_data['suggestion']['fat'] = $nutrition_data['fat'];
+ $return_data['remaining_kcal'] = $nutrition_data['kcal'];
+
+
+ // 查询用户今日摄入食物
+ // $food_content = Db::table($this->kitchenscale_db_name['eat_log'])
+ // ->alias('a')
+ // ->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
+ // ->where("a.is_del = 0 AND a.aud_id = " . $data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)")
+ // ->field('a.meals_type,a.food_name,a.weight,a.unit,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id,a.type')
+ // ->select();
+ // \'https://tc.pcxbc.com\' pic_url
+ $food_content = Db::table($this->kitchenscale_db_name['eat_log'])
+ // ->alias('a')
+ // ->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
+ ->where("is_del = 0 AND aud_id = " . $data['aud_id'] . " AND CAST(create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)")
+ ->field('meals_type,food_name,weight,unit,kcal_val,carbohydrate_val,protein_val,fat_val,id,food_id,type')
+ ->select();
+
+ // 处理食材图片
+ $food_id = [];
+ foreach ($food_content as $key => $value) {
+ $food_id[] = $value['food_id'];
+ }
+ if(count($food_id) > 0){
+ $food_ys_pic_url = $cfc->table('app_z_national_standard_food_type_3')
+ ->where("id in (".implode(',',$food_id).")")
+ ->field('id,\'https://tc.pcxbc.com\' + pic_url as pic_url')
+ ->select();
+
+ foreach ($food_content as $key => $value) {
+ foreach ($food_ys_pic_url as $k => $v) {
+ if($value['food_id'] == $v['id']){
+ $food_content[$key]['pic_url'] = $v['pic_url'];
+ }
+ }
+ }
+ }else{
+ foreach ($food_content as $key => $value) {
+ $food_content[$key]['pic_url'] = '';
+ }
+ }
+
+
+ $food_product = [];
+ if(count($food_content) > 0){ //计算营养物质
+ // 提取出来商品食物的id并处理图片
+ foreach ($food_content as $key => $value) {
+ if($value['type'] == 2){
+ $food_product[] = $value['food_id'];
+ }
+ }
+ if(count($food_product) > 0){
+ $food_product_pic_url = Db::table($this->kitchenscale_db_name['tiaoma'])
+ ->where("id in (".implode(',',$food_product).")")
+ ->field('id,pic_sp,name')
+ ->select();
+
+ foreach ($food_content as $key => $value) {
+ foreach ($food_product_pic_url as $k => $v) {
+ if($value['type'] == 2){
+ if($v['id'] == $value['food_id']){
+ $food_content[$key]['pic_url'] = $v['pic_sp'];
+ }
+ }
+ }
+ }
+ }
+
+ // dump($food_content);
+ // die;
+ $food_content = $this->calculate_nutrients($food_content);
+ // return $this->msg($food_content);
+ foreach ($food_content as $key => $value) {
+ // dump($value['nutrients_four']);
+ $return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
+ $return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
+ $return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
+ $return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
+ // 处理各餐
+ if($value['meals_type'] == '早餐'){
+ $return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
+ $return_data['list'][0]['nutrients_four'][0]['value'] = bcadd($return_data['list'][0]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][0]['nutrients_four'][1]['value'] = bcadd($return_data['list'][0]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][0]['nutrients_four'][2]['value'] = bcadd($return_data['list'][0]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][0]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].' '.$value['unit'],
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '午餐'){
+ $return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2);
+ $return_data['list'][1]['nutrients_four'][0]['value'] = bcadd($return_data['list'][1]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][1]['nutrients_four'][1]['value'] = bcadd($return_data['list'][1]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][1]['nutrients_four'][2]['value'] = bcadd($return_data['list'][1]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][1]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].' '.$value['unit'],
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else if($value['meals_type'] == '晚餐'){
+ $return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2);
+ $return_data['list'][2]['nutrients_four'][0]['value'] = bcadd($return_data['list'][2]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][2]['nutrients_four'][1]['value'] = bcadd($return_data['list'][2]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][2]['nutrients_four'][2]['value'] = bcadd($return_data['list'][2]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][2]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].' '.$value['unit'],
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }else{
+ $return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
+ $return_data['list'][3]['nutrients_four'][0]['value'] = bcadd($return_data['list'][3]['nutrients_four'][0]['value'],$value['kcal_val'],2);
+ $return_data['list'][3]['nutrients_four'][1]['value'] = bcadd($return_data['list'][3]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
+ $return_data['list'][3]['nutrients_four'][2]['value'] = bcadd($return_data['list'][3]['nutrients_four'][2]['value'],$value['protein_val'],2);
+ $return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
+ array_push($return_data['list'][3]['list'],[
+ 'name'=>$value['food_name'],
+ 'weight'=>$value['weight'].' '.$value['unit'],
+ 'id'=>$value['id'],
+ 'pic_url'=>$value['pic_url'],
+ 'val'=>$value['kcal_val'],
+ 'nutrients_four' => $value['nutrients_four'],
+ 'nutrients_list' => $value['nutrients_list']
+ ]);
+ }
+ }
+ // dump($return_data['list']);
+ // die;
+ $return_data['list'] = array_values($return_data['list']);
+ // 处理剩下可吃
+ $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
+
+
+
+ // 处理各餐卡路里占比
+ $return_data = $this->calculate_kcal_proportion($return_data);
+ // 计算营养物质能量占比
+ $return_data = $this->calculate_energy_proportion($return_data);
+ // 排序营养元素食物排行榜
+ $return_data = $this->energy_food_rank($return_data);
+ // 微量元素处理全天
+ $return_data = $this->calculate_trace_elements($return_data);
+ // 处理单餐营养占比
+ // return $this->msg($return_data);
+ foreach ($return_data['list'] as $key => $value) {
+ $all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
+ foreach ($value['nutrients_four'] as $k => $v) {
+ if($k != 0){
+ if($all_yy_data_0 == 0){
+ $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
+ }else{
+ $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':bcmul(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2),100,2);
+ }
+ // if($value['name'] == '晚餐'){
+ // // dump($return_data['list'][$key]['nutrients_four'][$k]['proportion']);
+ // }
+ // dump($return_data['list'][$key]['nutrients_four'][$k]['proportion']);
+ }
+ }
+ }
+ // return $this->msg($return_data);
+ }
+
+
+
+ $nameMap = [
+ 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'],
+ 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'],
+ 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'],
+ 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'],
+ ];
+ $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20);
+ foreach ($return_data['suggestion'] as $key => $value) {
+ $return_data['nutrients_four'][] = [
+ 'name'=>$nameMap[$key][0],
+ 'unit'=>$nameMap[$key][1],
+ 'suggestion'=>$value,
+ 'today_intake'=>$return_data['today_intake'][$key],
+ 'icon'=>$nameMap[$key][2],
+ 'color'=>$nameMap[$key][3],
+ 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':bcmul(bcdiv($return_data['today_intake'][$key],$value,2),100,2),
+ // 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
+ 'proportion_fp'=>$key == 'kcal'?0:$nutrition_data[$key.'_p'],
+
+ ];
+ }
+ // dump($user_data);
+ unset($return_data['suggestion']);
+ unset($return_data['today_intake']);
+
+
+
+
+
+ // return $return_data;
+ return $this->msg($return_data);
+
+ }
+
+ public function update_user_msg_action($data){
+ if($data['gender'] == 0){
+ return $this->msg(10005,'性别信息错误');
+ }
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->kitchenscale_db_name['zhanghao'])->where(['token'=>$data['token']])->count();
+ if($user_data<=0){
+ return $this->msg(10005,'账号信息错误');
+ }
+
+ // $cfc = Db::connect('cfc_db');
+
+ $is_user_true = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->count();
+
+ $user_msg['nickname'] = $data['nickname'];
+ $user_msg['head_pic'] = $data['gender'] == 1?'https://tc.pcxbc.com/tsf/1.png':'https://tc.pcxbc.com/tsf/2.png';
+ $user_msg['gender'] = $data['gender'];
+ $user_msg['birthday'] = $data['birthday'];
+ $user_msg['height'] = $data['height'];
+ $user_msg['weight'] = $data['weight'];
+ $user_msg['activity_level'] = $data['activity_level'];
+
+ if($is_user_true>0){
+ $user_msg['last_update_time'] = date('Y-m-d H:i:s');
+ $result = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(['id'=>$data['aud_id']])
+ ->update($user_msg);
+ }else{
+ return $this->msg(10005,'角色信息错误');
+ }
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+ public function search_default_msg_action($data){
+ $return_data = [
+ 'search_history'=>['cookbook'=>[],'food'=>[]],
+ 'search_guess'=>[],
+ ];
+
+ // 如果有角色信息
+ if(array_key_exists('aud_id', $data)){
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ // 获取账号下信息以及用户信息 start
+ $user = Db::table($this->kitchenscale_db_name['juese'])->where(["id"=>$data['aud_id']])->field('id,nickname')->find();
+
+ if($user){
+ // 处理搜索历史 start
+ $search_history_cookbook = Db::table($this->kitchenscale_db_name['search_history'])
+ ->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'cookbook'])
+ ->field('id,keyword,last_searched_at,type')
+ ->order('last_searched_at desc')
+ ->limit(10)
+ ->select();
+ $search_history_food = Db::table($this->kitchenscale_db_name['search_history'])
+ ->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'food'])
+ ->field('id,keyword,last_searched_at,type')
+ ->order('last_searched_at desc')
+ ->limit(10)
+ ->select();
+ // 去重
+ foreach ($search_history_cookbook as $key => $value) {
+ unset($search_history_cookbook[$key]['type']);
+ unset($search_history_cookbook[$key]['ROW_NUMBER']);
+ }
+ foreach ($search_history_food as $key => $value) {
+ unset($search_history_food[$key]['type']);
+ unset($search_history_food[$key]['ROW_NUMBER']);
+ }
+
+ $return_data['search_history']['cookbook'] = $search_history_cookbook;
+ $return_data['search_history']['food'] = $search_history_food;
+ // 处理搜索历史 end
+ }
+ }
+
+ // 处理猜你喜欢信息start
+ // 使用三元运算符判断$user是否存在
+ $user_id = isset($user) ? $user['id'] : 9999999;
+ $cnxh = new Guessyoulike;
+ $cookbook_data = $cnxh->getGuessYouLike($user_id,'cookbook');
+
+ // dump($cookbook_data);
+ // die;
+ $food_data = $cnxh->getGuessYouLike($user_id,'food');
+
+ // dump($return_data['search_history']);
+ // dump($cookbook_data);
+ // dump($food_data);
+ // die;
+ foreach ($cookbook_data as $key => $value) {
+ $return_data['search_guess']['cookbook'][] = ['title'=>$key,'list'=>$value];
+ }
+ foreach ($food_data as $key => $value) {
+ $return_data['search_guess']['food_data'][] = ['title'=>$key,'list'=>$value];
+ }
+ // 处理猜你喜欢信息end
+
+
+ // // 添加菜谱label start
+ // $cfc = Db::connect('cfc_db');
+ // $cookbook_label = $cfc->table($this->kitchenscale_db_name['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
+ // $return_data['cookbook_label'] = $cookbook_label;
+ // // 添加菜谱label end
+
+ return $this->msg($return_data);
+ }
+
+ public function get_food_list_action($data){
+
+ if(!array_key_exists('page',$data)){
+ $data['page'] = 1;
+ }else{
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ $data['page'] = 1;
+ }
+ }
+
+ $cp_page_num = 15;
+ $cfc = Db::connect('cfc_db');
+
+ $search_sql_str = "is_del = 0";
+ if(!array_key_exists('search_data', $data)){
+ $data['search_data'] = "";
+ $ss = "";
+ }else{
+ if($data['search_data'] === ""){
+ $data['search_data'] = "";
+ $ss = "";
+ }else{
+ $ss = $data['search_data'];
+ $data['search_data'] = " AND food_name LIKE '%".str_replace('[', '[[]', $ss)."%'";
+
+ }
+ }
+ $search_sql_str = $search_sql_str.$data['search_data'];
+
+ // 计算总数
+ $count_sql = "SELECT COUNT(*) as total FROM {$this->kitchenscale_db_name['foodlist3']} WHERE {$search_sql_str}";
+ $count_result = $cfc->query($count_sql);
+ $content_num = $count_result[0]['total'] ?? 0;
+ $page_total = ceil($content_num/$cp_page_num);
+
+ // 计算分页偏移量
+ $page = max(1, intval($data['page']));
+ $offset = ($page - 1) * $cp_page_num;
+
+ // SQL Server分页查询 - 使用OFFSET FETCH语法(SQL Server 2012及以上版本)
+ $sql = "SELECT id, record_id, food_name as name, pic_url, Calorie_val as kcal, weight_unit as unit
+ FROM {$this->kitchenscale_db_name['foodlist3']}
+ WHERE {$search_sql_str}
+ ORDER BY id
+ OFFSET {$offset} ROWS
+ FETCH NEXT {$cp_page_num} ROWS ONLY";
+
+ // dump($count_sql);
+
+ $collect_list = $cfc->query($sql);
+
+
+ if(count($collect_list) > 0){
+ $nutrients_list_id = [];
+ $nutrients_list_temporary = [];
+ foreach ($collect_list as $key => $value) {
+ $collect_list[$key]['pic_url'] = "https://tc.pcxbc.com/kitchenscale_all".$collect_list[$key]['pic_url'];
+ array_push($nutrients_list_id,$collect_list[$key]['record_id']);
+ $nutrients_list_temporary[$collect_list[$key]['record_id']] = [];
+ if (!is_numeric($collect_list[$key]['kcal'])) {
+ $collect_list[$key]['kcal'] = 0;
+ }
+ }
+
+ // 处理营养物质
+ $nutrients_list_data = $cfc->table($this->kitchenscale_db_name['foodlist4'])
+ ->where("father_id in (". implode(',',$nutrients_list_id) .")")
+ ->field("father_id,name,name_ch,unit,value,type")
+ ->select();
+ // dump($nutrients_list_id);
+ // die;
+ for ($i=0; $i < count($nutrients_list_data); $i++) {
+ if(!is_numeric($nutrients_list_data[$i]['value']) || $nutrients_list_data[$i]['value'] == 0){
+ array_push($nutrients_list_temporary[$nutrients_list_data[$i]['father_id']],[
+ 'name'=>$nutrients_list_data[$i]['name'],
+ 'name_ch'=>$nutrients_list_data[$i]['name_ch'],
+ 'unit'=>$nutrients_list_data[$i]['unit'],
+ 'value'=>0,
+ 'type'=>$nutrients_list_data[$i]['type'],
+ 'type_name'=>$nutrients_list_data[$i]['type'] == 1?'能量及宏量营养素':($nutrients_list_data[$i]['type'] == 2?'维生素':'矿物质'),
+ 'color'=>$nutrients_list_data[$i]['type'] == 1?'#C4FFE0':($nutrients_list_data[$i]['type'] == 2?'#FFEFB7':'#7DA8E0')
+ ]);
+ }else{
+ array_push($nutrients_list_temporary[$nutrients_list_data[$i]['father_id']],[
+ 'name'=>$nutrients_list_data[$i]['name'],
+ 'name_ch'=>$nutrients_list_data[$i]['name_ch'],
+ 'unit'=>$nutrients_list_data[$i]['unit'],
+ 'value'=>$nutrients_list_data[$i]['value'],
+ 'type'=>$nutrients_list_data[$i]['type'],
+ 'type_name'=>$nutrients_list_data[$i]['type'] == 1?'能量及宏量营养素':($nutrients_list_data[$i]['type'] == 2?'维生素':'矿物质'),
+ 'color'=>$nutrients_list_data[$i]['type'] == 1?'#C4FFE0':($nutrients_list_data[$i]['type'] == 2?'#FFEFB7':'#7DA8E0')
+ ]);
+ }
+ }
+
+ // dump($nutrients_list_temporary);
+ // die;
+ for ($i=0; $i < count($collect_list); $i++) {
+ $collect_list[$i]['nutrients_four'] = [];
+ $collect_list[$i]['nutrients_list'] = [];
+ $temporary_calculate = 0;
+ if(array_key_exists($collect_list[$i]['record_id'],$nutrients_list_temporary)){
+ $collect_list[$i]['nutrients_list'] = $nutrients_list_temporary[$collect_list[$i]['record_id']];
+ // 处理四大营养物质
+ foreach ($nutrients_list_temporary[$collect_list[$i]['record_id']] as $key => $value) {
+ // dump($value);
+ if($value['type'] == 1){
+ array_push($collect_list[$i]['nutrients_four'],[
+ 'name'=>$value['name'] == 'Carbohydrate'?'碳水':$value['name_ch'],
+ 'unit'=>$value['unit'],
+ 'color'=>$value['name'] == 'Carbohydrate'?'#FFB169':($value['name'] == 'Fat'?'#ED7886':($value['name'] == 'Protein'?'#5180D8':'')),
+ 'value'=>!is_numeric($value['value'])?0:$value['value'],
+ ]);
+ // 如果不为卡路里
+ if($value['name'] != 'Calorie'){
+ $temporary_calculate = $temporary_calculate+$value['value'];
+ }
+ }
+ }
+ // dump($collect_list);
+ // 处理详情当中的环数据占比
+ foreach ($collect_list[$i]['nutrients_four'] as $k => $v) {
+ if($v['name'] != '卡路里'){
+ $collect_list[$i]['nutrients_four'][$k]['proportion'] = bcmul(bcdiv($v['value'],$temporary_calculate,2),100,0);
+ }else{
+ $collect_list[$i]['nutrients_four'][$k]['proportion'] = 0;
+ }
+ }
+ }
+ }
+
+ }
+
+
+ // 记录搜索历史
+ if(array_key_exists('aud_id',$data) && $data['aud_id'] != '' && $ss != ''){
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,aan_id')->find();
+ if($user_data){
+ $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$ss,'type'=>'food']);
+ }
+ }
+
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$collect_list
+ ]);
+ }
+
+ public function search_column_action($data){
+
+ // $cookbook = new Cookbook();
+ $cfc = Db::connect('cfc_db');
+ $page_now = array_key_exists('page',$data)?$data['page']:1;
+ $page_total = $page_now;
+ $page_num = 20;
+ // 获取菜谱信息
+ $content_num = $cfc->table($this->kitchenscale_db_name['cookbook'])
+ ->where("is_del = 0 AND (title LIKE '%".$data['search_data']."%' OR describe_data LIKE '%".$data['search_data']."%')")
+ ->count();
+ $page_total = ceil($content_num/$page_num);
+
+ $content_list = $cfc->table($this->kitchenscale_db_name['cookbook'])
+ ->alias('cookbook')
+ ->join($this->kitchenscale_db_name['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
+ ->where("cookbook.is_del = 0 AND (cookbook.title LIKE '%".$data['search_data']."%' OR cookbook.describe_data LIKE '%".$data['search_data']."%')")
+ ->field("cookbook.id,cookbook.title,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num,uploadimg.pic_url as cover")
+ ->page("$page_now,$page_num")
+ ->select();
+
+
+ if(count($content_list)<=0){
+ return $this->msg([]);
+ }
+ if(array_key_exists('aud_id',$data)){
+ if($data['aud_id'] != ''){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic')->find();
+ if($user_data){
+ // 获取用户收藏列表
+ $my_collect_list = Db::table($this->kitchenscale_db_name['collect_list'])
+ ->where(['aud_id'=>$data['aud_id']])
+ ->column('cookbook_id');
+ // dump();
+ // 处理菜谱收藏信息
+ foreach ($content_list as $key => $value) {
+ if(array_key_exists($value['id'],$my_collect_list)){
+ $content_list[$key]['is_me_like_it'] = 'yes';
+ }else{
+ $content_list[$key]['is_me_like_it'] = 'no';
+ }
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ if($data['search_data'] != ''){
+ $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$data['search_data'],'type'=>'cookbook']);
+ }
+
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+ }else{
+ foreach ($content_list as $key => $value) {
+ $content_list[$key]['is_me_like_it'] = 'no';
+ if($value['cover'] == null){
+ $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+ unset($content_list[$key]['ROW_NUMBER']);
+ }
+ }
+
+
+ return $this->msg([
+ 'page_now'=>$page_now,
+ 'page_total'=>$page_total,
+ 'content_list'=>$content_list
+ ]);
+ }
+
+ public function cookbook_details_action($data){
+
+ $cfc = Db::connect('cfc_db');
+ $img_arr = [];
+ // 查询菜谱详情
+ $cookbook_data = $cfc->table($this->kitchenscale_db_name['cookbook'])->where(['id'=>$data['cookbook_id']])->find();
+ if(!$cookbook_data){
+ return $this->msg(10004,'菜谱不存在');
+ }
+ $cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true);
+ $cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true);
+ // $cookbook_data['food_type'] = explode(',',$cookbook_data['food_type']);
+ $cookbook_data_step_data_count = count($cookbook_data['step_data']);
+ // 设置需要的图片id
+ array_push($img_arr, $cookbook_data['cover']);
+
+ foreach ($cookbook_data['step_data'] as $key => $value) {
+ if(count($value['pic_list']) > 0){
+ foreach ($value['pic_list'] as $k => $v) {
+ if(!in_array($v, $img_arr)){
+ array_push($img_arr, $v);
+ }
+ }
+ }
+ }
+ // dump($cookbook_data);
+ // die;
+ $img_arr = implode(',',$img_arr);
+ // 查找需要的图片
+ $img_arr_data = $cfc->table($this->kitchenscale_db_name['uploadimg'])->where("id in ($img_arr) AND is_del = 0")->field('id,pic_name,pic_url')->select();
+ $cookbook_img_data = [];
+ // 处理菜谱图片
+ foreach ($img_arr_data as $key => $value) {
+ $cookbook_img_data[$value['id']] = $value['pic_url'];
+ }
+
+ // 设置菜谱图片
+ foreach ($cookbook_data['step_data'] as $key => $value) {
+ $cookbook_data['step_data'][$key]['step_num'] = "步骤".($key+1).'/'.$cookbook_data_step_data_count;
+ $cookbook_data['step_data'][$key]['pic_url_list'] = [];
+ foreach ($value['pic_list'] as $k => $v) {
+ if(array_key_exists($v, $cookbook_img_data)){
+ array_push($cookbook_data['step_data'][$key]['pic_url_list'],$cookbook_img_data[$v]);
+ }else{
+ array_push($cookbook_data['step_data'][$key]['pic_url_list'],'https://tc.pcxbc.com/kitchenscale_all/diule.jpg');
+ }
+ }
+ }
+
+ // $cookbook_data['cover_id'] = $cookbook_data['cover'];
+ if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){
+ $cookbook_data['cover_pic_url'] = $cookbook_img_data[$cookbook_data['cover']];
+
+ }else{
+ $cookbook_data['cover_pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
+ }
+
+
+ if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){
+ if($data['aud_id'] != ''){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'角色信息错误');
+ }
+ $collect_data = Db::table($this->kitchenscale_db_name['collect_list'])
+ ->where([
+ 'aud_id'=>$data['aud_id'],
+ 'cookbook_id'=>$data['cookbook_id'],
+ ])
+ ->find();
+ if($collect_data){
+ if($collect_data['is_del'] == 0){
+ // 如果有结果并且没被删过
+ $cookbook_data['collect_status'] = 'yes';
+ }else{
+ // 如果有结果被删过
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ // 如果没结果
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ $cookbook_data['collect_status'] = 'no';
+ }
+ }else{
+ $cookbook_data['collect_status'] = 'no';
+ }
+
+
+ $nutrition = $cfc->table($this->kitchenscale_db_name['nutrition'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+ $vitamin = $cfc->table($this->kitchenscale_db_name['vitamin'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+ $mineral = $cfc->table($this->kitchenscale_db_name['mineral'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select();
+
+
+ $cookbook_data['tags'] = [];
+
+ array_push($cookbook_data['tags'],[
+ 'title'=>'所需食材',
+ 'desc'=>'重量',
+ 'list'=>$cookbook_data['food_data'],
+ ]);
+ if(count($nutrition)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'能量',
+ 'desc'=>'含量',
+ 'list'=>$nutrition,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+
+ if(count($vitamin)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'维生素',
+ 'desc'=>'含量',
+ 'list'=>$vitamin,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+
+ if(count($mineral)>0){
+ array_push($cookbook_data['tags'],[
+ 'title'=>'矿物质',
+ 'desc'=>'含量',
+ 'list'=>$mineral,
+ ]);
+ }else{
+ array_push($cookbook_data['tags'],[
+ 'title'=>'',
+ 'desc'=>'',
+ 'list'=>[],
+ ]);
+ }
+
+ // 处理营养物质 end
+
+ $cookbook_data['token'] = $cookbook_data['create_user_token'];
+ $cookbook_data['description'] = $cookbook_data['describe_data'];
+ // $cookbook_data['food_list'] = $cookbook_data['food_data'];
+ $cookbook_data['step_list'] = $cookbook_data['step_data'];
+ unset($cookbook_data['create_user_token']);
+ unset($cookbook_data['describe_data']);
+ unset($cookbook_data['food_data']);
+ unset($cookbook_data['step_data']);
+ unset($cookbook_data['create_time']);
+ unset($cookbook_data['food_type']);
+ unset($cookbook_data['ROW_NUMBER']);
+ unset($cookbook_data['is_del']);
+ return $this->msg($cookbook_data);
+ }
+
+ public function cookbook_like_action($data){
+
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic')->find();
+ if(!$user_data){
+ return $this->msg(20001,'角色信息错误');
+ }
+
+
+ $cfc = Db::connect('cfc_db');
+ $cookbook_data = $cfc->table($this->kitchenscale_db_name['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token,likes_num')->find();
+ if(!$cookbook_data){
+ return $this->msg(10004,'未找到菜谱');
+ }
+
+ $like_data = Db::table($this->kitchenscale_db_name['collect_list'])->where(['aud_id'=>$data['aud_id'],'cookbook_id'=>$data['cookbook_id']])->find();
+
+ $like_data_state = 0;
+ if($like_data){
+ if($like_data['is_del'] == 0){
+ // 如果当前是关注状态
+ $like_data_state = 1;
+ }else{
+ $like_data_state = 0;
+ }
+ // 启动事务
+ Db::startTrans();
+ try{
+ Db::table($this->kitchenscale_db_name['collect_list'])
+ ->where(['id'=>$like_data['id']])
+ ->update(['is_del'=>$like_data_state]);
+ if($like_data_state == 0){
+ $cfc->table($this->kitchenscale_db_name['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num');
+ }else{
+ $cfc->table($this->kitchenscale_db_name['cookbook'])->where(['id'=>$data['cookbook_id']])->setDec('likes_num');
+ }
+ // 提交事务
+ Db::commit();
+ if($like_data_state==0){
+ $likes_num = $cookbook_data['likes_num']+1;
+ }else{
+ $likes_num = $cookbook_data['likes_num']-1;
+ if($likes_num <= 0){
+ $likes_num = 0;
+ }
+ }
+ return $this->msg([
+ 'collect_status'=>$like_data_state==0?'yes':'no',
+ 'likes_num'=>$likes_num
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002,'操作失败.');
+ }
+ }else{
+ // 启动事务
+ Db::startTrans();
+ try{
+ Db::table($this->kitchenscale_db_name['collect_list'])
+ ->insert([
+ 'aud_id'=>$data['aud_id'],
+ 'cookbook_id'=>$data['cookbook_id'],
+ 'create_time'=>date('Y-m-d H:i:s')
+ ]);
+ $cfc->table($this->kitchenscale_db_name['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num');
+ // 提交事务
+ Db::commit();
+ return $this->msg([
+ 'collect_status'=>"yes",
+ 'likes_num'=>$cookbook_data['likes_num']+1
+ ]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002,'操作失败');
+ }
+ }
+ }
+
+ public function add_intake_food_action($data){
+
+ $cfc = Db::connect('cfc_db');
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,birthday,is_use_set_kcal,set_kcal')
+ ->find();
+ // dump($user_data);
+ if(!$user_data){
+ return $this->msg(10003);
+ }else{
+ if(!$user_data['weight'] || !$user_data['height']){
+ return $this->msg(10008);
+ }
+ }
+
+ if(count($data['food_list']) <= 0){
+ return $this->msg(10001,'未选择食材');
+ }
+ // 统计食物的id
+ $food_id_arr = [];
+ $food_id_arr_product = [];
+
+ foreach ($data['food_list'] as $key => $value) {
+ if(!array_key_exists('id', $value)){
+ return $this->msg(10001,'id is miss');
+ }
+ if(!array_key_exists('unit', $value)){
+ return $this->msg(10001,'unit is miss');
+ }
+ if(!array_key_exists('weight', $value)){
+ return $this->msg(10001,'weight is miss');
+ }
+ if(!array_key_exists('meals_type', $value)){
+ return $this->msg(10001,'meals_type is miss');
+ }
+ if(!$this->verify_data_is_ok($value['id'],'intnum')){
+ return $this->msg(10005,'id type is error');
+ }
+
+ if(!in_array($value['meals_type'],['早餐','午餐','晚餐','加餐'])){
+ return $this->msg(10005,'meals_type type is error');
+ }
+
+ foreach ($data['food_list'][$key] as $k => $v) {
+ if(!in_array($k,['id','weight','meals_type','unit'])){
+ unset($data['food_list'][$key][$k]);
+ }
+ }
+ // 如果不是普通食材
+ if(array_key_exists('food_type',$value)){
+ array_push($food_id_arr_product,$value['id']);
+ }else{
+ array_push($food_id_arr,$value['id']);
+ }
+
+ $data['food_list'][$key]['weight_g'] = $this->convertWeightToGrams($value['weight'],$value['unit']);
+ }
+
+ if(count($food_id_arr)>0){
+ $food_content = $cfc->table($this->kitchenscale_db_name['foodlist3'])
+ ->where("id in (".implode(',',$food_id_arr).")")
+ ->field('id,food_name as name,Calorie_val as kcal,Carbohydrate_val as carbohydrate,Protein_val as protein,Fat_val as fat')
+ ->select();
+
+ if(count($food_content) <= 0){
+ return $this->msg(10004,'未找到对应食材');
+ }
+ // 整理食物信息
+ $food_content_arr = [];
+ foreach ($food_content as $key => $value) {
+ $food_content_arr[$value['id']] = $value;
+ }
+ // $create_time = date('Y-m-d H:i:s');
+ foreach ($data['food_list'] as $key => $value) {
+ //获取每100g食物的比例
+ $proportion_num = bcdiv($value['weight_g'],100,20);
+ if(array_key_exists($value['id'], $food_content_arr)){
+ $data['food_list'][$key]['kcal_val'] = bcmul($food_content_arr[$value['id']]['kcal'],$proportion_num,1);
+ $data['food_list'][$key]['carbohydrate_val'] = bcmul($food_content_arr[$value['id']]['carbohydrate'],$proportion_num,1);
+ $data['food_list'][$key]['protein_val'] = bcmul($food_content_arr[$value['id']]['protein'],$proportion_num,1);
+ $data['food_list'][$key]['fat_val'] = bcmul($food_content_arr[$value['id']]['fat'],$proportion_num,1);
+ $data['food_list'][$key]['food_name'] = $food_content_arr[$value['id']]['name'];
+ $data['food_list'][$key]['aud_id'] = $data['aud_id'];
+ $data['food_list'][$key]['meals_type'] = $value['meals_type'];
+ $data['food_list'][$key]['create_time'] = $data['time'].date(' H:i:s');
+ $data['food_list'][$key]['food_id'] = $value['id'];
+ $data['food_list'][$key]['type'] = 1;
+ unset($data['food_list'][$key]['id']);
+ unset($data['food_list'][$key]['weight_g']);
+
+ }else{
+ unset($data['food_list'][$key]);
+ }
+ }
+ }
+ if(count($food_id_arr_product)>0){
+ $food_content_product = $cfc->table($this->kitchenscale_db_name['tiaoma'])
+ ->where("id in (".implode(',',$food_id_arr_product).")")
+ ->field('id,name,Calorie as kcal,Carbohydrate as carbohydrate,Protein as protein,Fat as fat')
+ ->select();
+
+ if(count($food_content_product) <= 0){
+ return $this->msg(10004,'未找到对应食材');
+ }
+ // 整理食物信息
+ $food_content_arr_product = [];
+ foreach ($food_content_product as $key => $value) {
+ $food_content_arr_product[$value['id']] = $value;
+ }
+ // $create_time = date('Y-m-d H:i:s');
+ foreach ($data['food_list'] as $key => $value) {
+ //获取每100g食物的比例
+ $proportion_num = bcdiv($value['weight_g'],100,2);
+ if(array_key_exists($value['id'], $food_content_arr_product)){
+ $data['food_list'][$key]['kcal_val'] = bcmul($food_content_arr_product[$value['id']]['kcal'],$proportion_num,2);
+ $data['food_list'][$key]['carbohydrate_val'] = bcmul($food_content_arr_product[$value['id']]['carbohydrate'],$proportion_num,2);
+ $data['food_list'][$key]['protein_val'] = bcmul($food_content_arr_product[$value['id']]['protein'],$proportion_num,2);
+ $data['food_list'][$key]['fat_val'] = bcmul($food_content_arr_product[$value['id']]['fat'],$proportion_num,2);
+ $data['food_list'][$key]['food_name'] = $food_content_arr_product[$value['id']]['name'];
+ $data['food_list'][$key]['aud_id'] = $data['aud_id'];
+ $data['food_list'][$key]['meals_type'] = $value['meals_type'];
+ $data['food_list'][$key]['create_time'] = $data['time'].date(' H:i:s');
+ $data['food_list'][$key]['food_id'] = $value['id'];
+ $data['food_list'][$key]['type'] = 2;
+ unset($data['food_list'][$key]['id']);
+ unset($data['food_list'][$key]['weight_g']);
+
+ }else{
+ unset($data['food_list'][$key]);
+ }
+ }
+ }
+
+ Db::startTrans();
+ try{
+ if(count($data['food_list']) > 1){
+ $result = Db::table($this->kitchenscale_db_name['eat_log'])->insertAll($data['food_list']);//新增所有
+ if ($result !== count($data['food_list'])) {
+ Db::rollback();
+ return $this->msg(10002,'添加数据错误');
+ } else {
+ Db::commit();
+ return $this->msg([]);
+ }
+ }else{
+ $result = Db::table($this->kitchenscale_db_name['eat_log'])->insertGetId($data['food_list'][0]);//新增1个
+ Db::commit();
+ return $this->msg(['id'=>$result]);
+ }
+
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+ }
+
+ public function get_log_list_action($data){
+ // $cfc = Db::connect('cfc_db');
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,birthday,is_use_set_kcal,set_kcal,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 计算年龄
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+ // 计算推荐营养
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'];
+ }
+
+
+ $content_num = Db::query("SELECT COUNT(DISTINCT CONVERT(varchar, create_time, 23)) as total
+ FROM ".$this->kitchenscale_db_name['eat_log']."
+ WHERE aud_id = ".$data['aud_id']." and is_del = 0");
+ $page_total = ceil($content_num[0]['total']/$this->page_num);
+
+ $food_content = Db::table($this->kitchenscale_db_name['eat_log'])
+ ->where(['aud_id'=>$data['aud_id'],'is_del'=>0])
+ ->group('CONVERT(varchar, create_time, 23)')
+ ->page($data['page'],$this->page_num)
+ ->order('create_time DESC')
+ ->field("CONVERT(varchar, create_time, 23) as create_time, SUM(kcal_val) as kcal_val")
+ ->select();
+
+ $return_data = [];
+ foreach ($food_content as $key => $value) {
+ if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 0.9){
+ $bz['text'] = '不达标';
+ $bz['color'] = '#F0AD4E';
+ }else if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 1.1){
+ $bz['text'] = '达标';
+ $bz['color'] = '#4CD964';
+ }else{
+ $bz['text'] = '超标';
+ $bz['color'] = '#FF0000';
+ }
+ array_push($return_data,['time'=>$value['create_time'],'title'=>'摄入卡路里','val'=>$value['kcal_val'],'unit'=>'kcal','describe'=>$bz['text'],'color'=>$bz['color']]);
+ }
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$return_data
+ ]);
+ }
+
+ public function set_nutrition_proportion_action($data){
+ // $cfc = Db::connect('cfc_db');
+ $result = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(['id'=>$data['aud_id']])
+ ->update([
+ 'is_use_set_kcal'=>1,
+ 'set_kcal'=>$data['set_kcal'],
+ 'set_carbohydrate_v'=>$data['carbohydrate_v'],
+ 'set_carbohydrate_p'=>$data['carbohydrate_p'],
+ 'set_protein_v'=>$data['protein_v'],
+ 'set_protein_p'=>$data['protein_p'],
+ 'set_fat_v'=>$data['fat_v'],
+ 'set_fat_p'=>$data['fat_p'],
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+ public function del_user_eat_log_action($data){
+ // $cfc = Db::connect('cfc_db');
+
+ $user_data = Db::table($this->kitchenscale_db_name['eat_log'])->where(['aud_id'=>$data['aud_id'],'id'=>$data['eat_log_id']])->find();
+
+ if($user_data){
+ $eat_log_data = Db::table($this->kitchenscale_db_name['eat_log'])
+ ->where(["id"=>$data['eat_log_id']])
+ ->update(['is_del'=>1]);
+ if($eat_log_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }else{
+ return $this->msg(10004);
+ }
+
+
+ }
+
+ public function del_search_history_action($data){
+
+ // $cfc = Db::connect('cfc_db');
+ $user = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,aan_id')->find();
+ if(!$user){
+ return $this->msg(20001,'账号信息错误');
+ }
+ if($data['del_arr'] == 'all'){
+ $result = Db::table($this->kitchenscale_db_name['search_history'])
+ ->where(['user_id'=>$user['id']])
+ ->update(['is_del'=>1]);
+ }else{
+ $result = Db::table($this->kitchenscale_db_name['search_history'])
+ ->where("user_id = ".$user['id']." AND id IN (".$data['del_arr'].")")
+ ->update(['is_del'=>1]);
+ }
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+ public function del_user_eat_list_log_action($data){
+ // $cfc = Db::connect('cfc_db');
+
+ $user_data = Db::table($this->kitchenscale_db_name['eat_log'])
+ ->where("aud_id = ".$data['aud_id']." AND LEFT(create_time,10) = '".$data['time']."'")
+ ->select();
+ // dump($user_data);
+ if(!$user_data){
+ return $this->msg(10003);
+ }else{
+ $result = Db::table($this->kitchenscale_db_name['eat_log'])
+ ->where("aud_id = ".$data['aud_id']." AND LEFT(create_time,10) = '".$data['time']."'")
+ ->update(['is_del'=>1]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ }
+
+ public function get_user_collect_list_action($data){
+ // 获取账号下信息以及用户信息
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,aan_id')->find();
+ if(!$user_data){
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>0,
+ 'content_list'=>[],
+ ]);
+ }
+
+
+ $cookbook_like_count = Db::table($this->kitchenscale_db_name['collect_list'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->count();
+
+ if($cookbook_like_count <= 0){
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>0,
+ 'content_list'=>[],
+ ]);
+ }
+ $cookbook_like_data = Db::table($this->kitchenscale_db_name['collect_list'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->page($data['page'],$this->page_num)->field('id,aud_id,cookbook_id')->select();
+
+
+
+ $page_total = ceil($cookbook_like_count/$this->page_num);
+
+ $cookbook_id = [];
+ foreach ($cookbook_like_data as $key => $value) {
+ $cookbook_id[] = $value['cookbook_id'];
+ }
+
+ $cfc = Db::connect('cfc_db');
+
+ $collect_list = $cfc->table($this->kitchenscale_db_name['cookbook'])
+ ->alias('a')
+ ->join($this->kitchenscale_db_name['uploadimg'].' c','a.cover = c.id','LEFT')
+ ->where("a.id IN (".implode(',',$cookbook_id).") AND a.is_del = 0")
+ ->field("a.id,a.title,a.cover as cover_id,c.pic_url as cover_url,a.likes_num,a.create_user_token,a.create_user_head_pic,a.create_user_nickname")
+ ->page($data['page'],$this->page_num)
+ ->select();
+
+
+ foreach ($collect_list as $key => $value) {
+ $collect_list[$key]['is_me_like_it'] = 'yes';
+
+ }
+
+ return $this->msg([
+ 'page_now'=>$data['page'],
+ 'page_total'=>$page_total,
+ 'content_list'=>$collect_list
+ ]);
+
+ }
+
+ public function set_up_content_action($data){
+ // $cfc = Db::connect('cfc_db');
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,is_use_set_kcal,set_kcal,birthday,set_carbohydrate_v,set_carbohydrate_p,set_protein_v,set_protein_p,set_fat_v,set_fat_p,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 计算年龄
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+ // 计算推荐营养
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal'];
+ $nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate'];
+ $nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein'];
+ $nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat'];
+
+
+ // $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?bcdiv($user_data['set_carbohydrate_p'],100,2):$nutrition_data['carbohydrate_p'];
+ // $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?bcdiv($user_data['set_protein_p'],100,2):$nutrition_data['protein_p'];
+ // $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?bcdiv($user_data['set_fat_p'],100,2):$nutrition_data['fat_p'];
+ $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?$user_data['set_carbohydrate_p']:bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?$user_data['set_protein_p']:bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?$user_data['set_fat_p']:bcmul($nutrition_data['fat_p'],100,2);
+ }else{
+ $nutrition_data['carbohydrate_p'] = bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = bcmul($nutrition_data['fat_p'],100,2);
+ }
+ $nutrition_describe = [
+ [
+ // '对于一个孩子(2-18岁)(没有特殊健康问题),身体处于快速生长发育阶段,需要充足的营养支持,尤其是蛋白质和健康脂肪。通常建议的三大营养素比例为:',
+ // '1、碳水化合物:45%-65% 的总热量',
+ // '提供能量,支持孩子的日常活动和生长发育。',
+ // '优先选择复合碳水化合物(如全谷物、蔬菜、水果),避免精制糖和高糖零食。',
+ // '2、蛋白质:10%-30% 的总热量',
+ // '支持肌肉、骨骼和器官的发育。',
+ // '建议摄入优质蛋白质来源,如瘦肉、鱼类、鸡蛋、豆类和乳制品。',
+ // '蛋白质需求较高,尤其是青春期孩子。',
+ // '3、脂肪:25%-35% 的总热量',
+ // '提供能量,并支持大脑发育(尤其是Omega-3脂肪酸)。',
+ // '优先选择健康脂肪,如鱼类、坚果、种子、橄榄油和牛油果。',
+ // '避免反式脂肪和过多的饱和脂肪。',
+ // '注意事项',
+ // '如果你有特定的健康目标(如增高,减重),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ '孩子(2-18岁)处于快速生长发育期,需充足营养,尤其蛋白质和健康脂肪。建议比例:',
+ '1、碳水化合物:45%-65%总热量',
+ '提供能量,优选全谷物、蔬果等复合碳水,避免高糖零食。',
+ '2、蛋白质:10%-30%总热量',
+ '支持肌肉、骨骼发育,推荐鱼、蛋、瘦肉、豆类等优质蛋白。',
+ '3、脂肪:25%-35%总热量',
+ '供能并促进大脑发育,选择坚果、鱼类、橄榄油等健康脂肪。',
+ '注意事项:若有增高、减重等目标,可咨询专业人士调整。'
+ ],
+ [
+ // '对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:',
+ // '1、碳水化合物:45%-65% 的总热量',
+ // '主要功能是提供能量',
+ // '建议选择复合碳水化合物(如全谷物、蔬菜、豆类),而不是精制糖。',
+ // '对于普通人,碳水化合物占总热量的 50%-55% 是一个常见的推荐值。',
+ // '2、蛋白质:10%-35% 的总热量',
+ // '用于维持肌肉、修复组织和支持免疫功能。',
+ // '普通人每日蛋白质摄入量建议为 0.8-1.2克/公斤体重。',
+ // '对于活动量较大或健身人群,蛋白质比例可以提高到 20%-30%。',
+ // '3、脂肪:20%-35% 的总热量',
+ // '提供能量、支持细胞功能并帮助吸收脂溶性维生素。',
+ // '建议以 不饱和脂肪(如橄榄油、坚果、鱼类)为主,减少饱和脂肪和反式脂肪的摄入。',
+ // '脂肪占总热量的 20%-30% 是常见的推荐值。',
+ // '以上是根据世界卫生组织(WHO)和其他健康机构的建议制定的。具体比例可以根据个人的活动水平、健康状况和目标进行微调。',
+ // '注意事项',
+ // '活动水平:活动量大的人可能需要更多的碳水化合物来提供能量,而健身人群可能需要更多的蛋白质。',
+ // '健康状况:例如,糖尿病患者可能需要控制碳水化合物比例,而心血管疾病患者可能需要减少脂肪摄入。',
+ // '个体差异:每个人的代谢和需求不同,建议根据个人情况调整。',
+ // '如果你有特定的健康目标(如减脂、增肌或控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ '正常成年人(无特殊健康问题)建议营养比例:',
+ '1、碳水化合物:45%-65%总热量',
+ '主要供能,推荐全谷物、豆类等复合碳水。',
+ '2、蛋白质:10%-35%总热量',
+ '维持肌肉与免疫功能,日常建议0.8-1.2克/公斤体重。',
+ '3、脂肪:20%-35%总热量',
+ '支持细胞功能,以不饱和脂肪为主,减少饱和脂肪。',
+ '注意事项:根据活动量、健康状况微调,特殊目标需个性化建议。'
+ ],
+ [
+ // '对于一个老人(65岁以上)(没有特殊健康问题),身体的代谢率下降,肌肉量减少,可能面临营养不良或慢性病风险,因此需要调整营养比例。通常建议的三大营养素比例为:',
+ // '1、碳水化合物:45%-65% 的总热量',
+ // '提供能量,但应选择低血糖指数(GI)的食物,如全谷物、蔬菜和豆类,以控制血糖水平。',
+ // '避免精制糖和高糖食物,尤其是糖尿病患者。',
+ // '帮助维持肌肉质量,预防肌肉流失(少肌症)。',
+ // '建议摄入优质蛋白质,如鱼类、瘦肉、鸡蛋、豆类和乳制品。',
+ // '蛋白质需求较高,尤其是活动量较大的老人。',
+ // '3、脂肪:20%-35% 的总热量',
+ // '提供能量,并支持细胞功能和脂溶性维生素的吸收。',
+ // '优先选择不饱和脂肪,如橄榄油、坚果、种子和鱼类。',
+ // '减少饱和脂肪和反式脂肪的摄入,以降低心血管疾病风险。',
+ // '注意事项',
+ // '如果你有特定的健康目标(控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
+ '老人(65岁以上)代谢减缓,需关注肌肉维持与慢性病预防。建议比例:',
+ '1、碳水化合物:45%-65%总热量',
+ '选择低GI食物如全谷物、蔬菜,控制血糖。',
+ '2、蛋白质:10%-30%总热量',
+ '预防肌肉流失,优选鱼、蛋、豆类等易消化蛋白。',
+ '3、脂肪:20%-35%总热量',
+ '支持营养吸收,以橄榄油、鱼类等健康脂肪为主。',
+ '注意事项:慢性病患者需结合医生建议调整饮食。'
+ ]
+ ];
+ $return_data = [
+ 'kcal'=>[
+ 'title'=>"建议摄入卡路里",
+ 'suggestion_kcal_val'=>$nutrition_data['kcal'],
+ 'suggestion_kcal_unit'=>"千卡",
+ 'suggestion_kcal_range_val'=>"建议您在:".bcmul($nutrition_data['bmr'],1.2,2)."~".bcmul($nutrition_data['bmr'],1.9,2)."千卡范围内调整,修改时请以医生建议为准!",
+ 'describe'=>[
+ '基础代谢率(BMR):是指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率。',
+ '每日总能量消耗(TDEE):',
+ 'TDEE是BMR乘以活动系数,活动系数根据日常活动水平确定',
+ '久坐(很少或没有运动):BMR × 1.2',
+ '轻度活动(每周1-3天轻度运动):BMR × 1.375',
+ '中度活动(每周3-5天中度运动):BMR × 1.55',
+ '高度活动(每周6-7天高强度运动):BMR × 1.725',
+ '极高活动(体力劳动或每天高强度训练):BMR × 1.9',
+ '您的BMR为'.$nutrition_data['bmr'].',建议根据您的日常生活水平,调整合适的TDEE',
+ ],
+ ],
+ 'nutrition'=>[
+ 'title'=>"建议三大营养比例",
+ 'list'=>[
+ [
+ 'name'=>'碳水化合物',
+ 'key_v'=>'carbohydrate',
+ 'icon'=>'icon-tanshuihuahewu',
+ 'proportion'=>$nutrition_data['carbohydrate_p'],
+ 'val'=>$nutrition_data['carbohydrate'],
+ 'unit'=>'克'
+ ],
+ [
+ 'name'=>'蛋白质',
+ 'key_v'=>'protein',
+ 'icon'=>'icon-Sm-danbaizhi',
+ 'proportion'=>$nutrition_data['protein_p'],
+ 'val'=>$nutrition_data['protein'],
+ 'unit'=>'克'
+ ],
+ [
+ 'name'=>'脂肪',
+ 'key_v'=>'fat',
+ 'icon'=>'icon-w_fat_normal',
+ 'proportion'=>$nutrition_data['fat_p'],
+ 'val'=>$nutrition_data['fat'],
+ 'unit'=>'克'
+ ]
+ ],
+ 'describe'=>[]
+ ]
+ ];
+ if($user_data['age_num'] >= 2 && $user_data['age_num'] <= 18){
+ $return_data['nutrition']['describe'] = $nutrition_describe[0];
+ }else if($user_data['age_num'] > 18 && $user_data['age_num'] < 65){
+ $return_data['nutrition']['describe'] = $nutrition_describe[1];
+ }else if($user_data['age_num'] >= 65){
+ $return_data['nutrition']['describe'] = $nutrition_describe[2];
+ }else{
+
+ }
+ return $this->msg($return_data);
+
+ }
+
+ public function current_food_statistics_action($data){
+ $id_arr = implode("','",$data['log_id']);
+
+ $cfc = Db::connect('cfc_db');
+ $user_data = Db::table($this->kitchenscale_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ ->field('weight,height,gender,is_use_set_kcal,set_kcal,birthday,set_carbohydrate_v,set_carbohydrate_p,set_protein_v,set_protein_p,set_fat_v,set_fat_p,activity_level')
+ ->find();
+
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ $user_data['age_num'] = $this->calculate_age($user_data['birthday']);
+ $nutrition_data = $this->count_user_nutrition_all($user_data);
+ if($user_data['is_use_set_kcal'] == 1){
+ $nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal'];
+ $nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate'];
+ $nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein'];
+ $nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat'];
+
+
+ $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?$user_data['set_carbohydrate_p']:bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?$user_data['set_protein_p']:bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?$user_data['set_fat_p']:bcmul($nutrition_data['fat_p'],100,2);
+ }else{
+ $nutrition_data['carbohydrate_p'] = bcmul($nutrition_data['carbohydrate_p'],100,2);
+ $nutrition_data['protein_p'] = bcmul($nutrition_data['protein_p'],100,2);
+ $nutrition_data['fat_p'] = bcmul($nutrition_data['fat_p'],100,2);
+ }
+ $return_data = [ //时间
+ 'suggestion'=>[ //建议
+ 'kcal'=>$nutrition_data['kcal'], //建议摄入卡路里量
+ 'carbohydrate'=>$nutrition_data['carbohydrate'], //建议摄入碳水量
+ 'protein'=>$nutrition_data['protein'], //建议摄入蛋白质量
+ 'fat'=>$nutrition_data['fat'], //建议摄入脂肪量
+ ],
+ 'today_intake'=>[ //今日已摄入
+ 'kcal'=>0, //今日已摄入卡路里量
+ 'carbohydrate'=>0, //今日已摄入碳水量
+ 'protein'=>0, //今日已摄入蛋白质量
+ 'fat'=>0, //今日已摄入脂肪量
+ ],
+ 'remaining_kcal'=>$nutrition_data['kcal'], //剩下可摄入卡路里量
+
+ ];
+
+ $eat_food_data = Db::table($this->kitchenscale_db_name['eat_log'])->where("id in ('".$id_arr."')")->select();
+ // dump($eat_food_data);
+ // die;
+ if(count($eat_food_data) > 0){ //计算营养物质
+ // return $this->msg($food_content);
+ foreach ($eat_food_data as $key => $value) {
+ // dump($value['nutrients_four']);
+ $return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
+ $return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
+ $return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
+ $return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
+ // 处理各餐
+
+ }
+ // 处理剩下可吃
+ $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
+ }
+
+
+ $nameMap = [
+ 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'],
+ 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'],
+ 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'],
+ 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'],
+ ];
+
+ $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20);
+ foreach ($return_data['suggestion'] as $key => $value) {
+ $return_data['nutrients_four'][] = [
+ 'name'=>$nameMap[$key][0],
+ 'unit'=>$nameMap[$key][1],
+ 'suggestion'=>$value,
+ 'today_intake'=>$return_data['today_intake'][$key],
+ 'icon'=>$nameMap[$key][2],
+ 'color'=>$nameMap[$key][3],
+ 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':bcmul(bcdiv($return_data['today_intake'][$key],$value,2),100,2),
+ // 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
+ 'proportion_fp'=>$key == 'kcal'?0:$nutrition_data[$key.'_p'],
+
+ ];
+ }
+ // dump($user_data);
+ unset($return_data['suggestion']);
+ unset($return_data['today_intake']);
+ return $this->msg($return_data);
+ }
+
+
+
+
+ ################################################################工具################################################################
+ ################################################################工具################################################################
+ // 计算每日每餐kcal占比
+ public function calculate_kcal_proportion($data){
+
+ $all_kcal = $data['today_intake']['kcal'];
+ $arr_kcal = [];
+ foreach ($data['list'] as $key => $value) {
+ $arr_kcal[] = $value['val'];
+ }
+ // 计算占比
+ $percentages = [];
+ if (bccomp($all_kcal, "0", 20) > 0) {
+ $sum = "0";
+ // 计算前n-1个元素的占比
+ for ($i = 0; $i < count($arr_kcal) - 1; $i++) {
+ $percentage = bcmul(bcdiv($arr_kcal[$i], $all_kcal, 20), "100", 20);
+ $percentage = bcdiv($percentage, "1", 2); // 保留两位小数
+ $percentages[] = $percentage;
+ $sum = bcadd($sum, $percentage, 2);
+ }
+
+ // 最后一个元素用100%减去前面总和,确保100%
+ if($arr_kcal[count($arr_kcal)-1] != 0){
+ $lastPercentage = bcsub("100.00", $sum, 2);
+ }else{
+ $lastPercentage = '0.00';
+ }
+ $percentages[] = $lastPercentage;
+ } else {
+ // 如果总热量为0,所有占比都为0
+ $percentages = array_fill(0, count($arr_kcal), "0.00");
+ }
+
+ // 将占比结果添加回原数据
+ foreach ($data['list'] as $key => &$value) {
+ $value['kcal_proportion'] = $percentages[$key];
+ }
+ return $data;
+ }
+ // 计算营养物质能量占比
+ public function calculate_energy_proportion($data){
+ // 获取今日摄入数据
+ $today_intake = $data['today_intake'];
+ // dump($today_intake);
+ // 总热量摄入
+ $total_kcal = $today_intake['kcal'];
+
+ // 各营养素摄入量(克)
+ $carb_intake = $today_intake['carbohydrate']; // 碳水
+ $protein_intake = $today_intake['protein']; // 蛋白质
+ $fat_intake = $today_intake['fat']; // 脂肪
+
+ // 供能系数
+ $carb_energy_coef = "4"; // 碳水:4 kcal/g
+ $protein_energy_coef = "4"; // 蛋白质:4 kcal/g
+ $fat_energy_coef = "9"; // 脂肪:9 kcal/g
+
+ // 计算各营养素的能量贡献(kcal)
+ $carb_energy = bcmul($carb_intake, $carb_energy_coef, 20);
+ $protein_energy = bcmul($protein_intake, $protein_energy_coef, 20);
+ $fat_energy = bcmul($fat_intake, $fat_energy_coef, 20);
+
+ // 计算各营养素的能量占比(%)
+ if (bccomp($total_kcal, "0", 20) > 0) {
+ // 碳水能量占比
+ $carb_proportion = bcmul(bcdiv($carb_energy, $total_kcal, 20), "100", 20);
+ $carb_proportion = bcdiv($carb_proportion, "1", 2); // 保留两位小数
+
+ // 蛋白质能量占比
+ $protein_proportion = bcmul(bcdiv($protein_energy, $total_kcal, 20), "100", 20);
+ $protein_proportion = bcdiv($protein_proportion, "1", 2);
+
+ // 脂肪能量占比
+ $fat_proportion = bcmul(bcdiv($fat_energy, $total_kcal, 20), "100", 20);
+ $fat_proportion = bcdiv($fat_proportion, "1", 2);
+ } else {
+ $carb_proportion = $protein_proportion = $fat_proportion = "0.00";
+ }
+
+ // 填充details数据
+ $data['details']['carbohydrate']['val'] = $carb_intake;
+ $data['details']['carbohydrate']['proportion'] = $carb_proportion;
+
+ $data['details']['protein']['val'] = $protein_intake;
+ $data['details']['protein']['proportion'] = $protein_proportion;
+
+ $data['details']['fat']['val'] = $fat_intake;
+ $data['details']['fat']['proportion'] = $fat_proportion;
+
+ return $data;
+ }
+ // 排序营养元素食物排行榜
+ public function energy_food_rank($data){
+ // 获取所有食物数据
+ $allFoods = [];
+
+ // 遍历每餐数据,收集所有食物信息
+ foreach ($data['list'] as $meal) {
+ if (!empty($meal['list'])) {
+ foreach ($meal['list'] as $food) {
+ // 获取食物的营养素数据
+ $nutrients_four = $food['nutrients_four'];
+ $nutrientValues = [];
+
+ // 将营养素数据转换为键值对,便于查询
+ foreach ($nutrients_four as $nutrient) {
+ $nutrientValues[$nutrient['name']] = $nutrient['value'];
+ }
+
+ $allFoods[] = [
+ 'name' => $food['name'],
+ 'pic_url' => $food['pic_url'],
+ 'weight' => $food['weight'],
+ 'carbohydrate' => isset($nutrientValues['碳水化合物']) ? $nutrientValues['碳水化合物'] : '0',
+ 'protein' => isset($nutrientValues['蛋白质']) ? $nutrientValues['蛋白质'] : '0',
+ 'fat' => isset($nutrientValues['脂肪']) ? $nutrientValues['脂肪'] : '0'
+ ];
+ }
+ }
+ }
+
+ // 如果没有食物数据,直接返回
+ if (empty($allFoods)) {
+ return $data;
+ }
+
+ // 对每种营养素进行排序并取前三
+ $nutrientTypes = [
+ 'carbohydrate' => '碳水化合物',
+ 'protein' => '蛋白质',
+ 'fat' => '脂肪'
+ ];
+
+ foreach ($nutrientTypes as $nutrientKey => $nutrientName) {
+ // 使用BC函数进行精确比较排序
+ usort($allFoods, function($a, $b) use ($nutrientKey) {
+ $valueA = $a[$nutrientKey];
+ $valueB = $b[$nutrientKey];
+
+ // 使用bccomp进行比较
+ $comparison = bccomp($valueA, $valueB, 20);
+
+ if ($comparison == 0) {
+ return 0;
+ }
+ // 返回-1表示a应该在b前面(降序排序)
+ return ($comparison > 0) ? -1 : 1;
+ });
+
+ // 取前三名
+ $topThree = array_slice($allFoods, 0, 3);
+
+ // 填充rank_list
+ $rankList = [];
+ foreach ($topThree as $index => $food) {
+ $rankList[] = [
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank'.($index+1).'.png',
+ 'name' => $food['name'],
+ 'pic_url' => $food['pic_url'],
+ 'weight' => bcdiv($food[$nutrientKey], '1', 2) // 使用BC函数保留两位小数
+ ];
+ }
+
+ // 如果不足三个,用空数据补全
+ $currentCount = count($rankList);
+ for ($i = $currentCount; $i < 3; $i++) {
+ $rankList[] = [
+ 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank' . ($i + 1) . '.png',
+ 'name' => '',
+ 'pic_url' => '',
+ 'weight' => ''
+ ];
+ }
+
+ // 更新到details中对应的营养素
+ $data['details'][$nutrientKey]['rank_list'] = $rankList;
+ }
+
+ return $data;
+ }
+ // 微量元素处理全天
+ public function calculate_trace_elements($data){
+ $traceElements = [];
+
+ // 遍历所有餐次数据
+ foreach ($data['list'] as $meal) {
+ if (!empty($meal['list'])) {
+ foreach ($meal['list'] as $food) {
+ if (!empty($food['nutrients_list'])) {
+ foreach ($food['nutrients_list'] as $nutrient) {
+ // 只处理维生素(type=2)和矿物质(type=3)
+ if (in_array($nutrient['type'], [2, 3])) {
+ $name = $nutrient['name'];
+ $value = $nutrient['value'];
+
+ // 初始化微量元素数据
+ if (!isset($traceElements[$name])) {
+ $traceElements[$name] = [
+ 'name' => $nutrient['name'],
+ 'name_ch' => isset($nutrient['name_ch']) ? $nutrient['name_ch'] : $nutrient['name'],
+ 'unit' => $nutrient['unit'],
+ 'value' => '0'
+ ];
+ }
+
+ // 使用BC数学函数精确累加
+ $traceElements[$name]['value'] = bcadd(
+ $traceElements[$name]['value'],
+ $value,
+ 20
+ );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // 处理结果,保留两位小数
+ $formattedElements = [];
+ foreach ($traceElements as $element) {
+ // 使用BC函数格式化值为两位小数
+ $formattedValue = bcdiv($element['value'], '1', 2);
+
+ // 如果值为0,跳过(可选,根据需求决定是否显示0值)
+ if (bccomp($formattedValue, '0', 2) > 0) {
+ $formattedElements[] = [
+ 'name' => $element['name'],
+ 'name_ch' => $element['name_ch'],
+ 'unit' => $element['unit'],
+ 'value' => $formattedValue
+ ];
+ }
+ }
+
+
+ // 按中文名称排序
+ usort($formattedElements, function($a, $b) {
+ return strcmp($a['name_ch'], $b['name_ch']);
+ });
+
+ $data['trace_elements_all_day'] = $formattedElements;
+
+ return $data;
+
+
+
+ }
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Language.php b/application/NewReedaw2/controller/app/Language.php
new file mode 100644
index 0000000..141bcac
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Language.php
@@ -0,0 +1,211 @@
+ 'English',
+ 'zh-Hans' => 'Chinese',
+ 'es' => 'Spanish',
+ 'fr' => 'French',
+ 'pt' => 'Portuguese',
+ 'ar' => 'Arabic',
+ 'ru' => 'Russian',
+ 'de' => 'German'
+ ];
+
+ // 语言映射表
+ protected $languageMap = [
+ 'en' => [
+ '操作成功' => 'Success',
+ '体重' => 'Weight',
+ '身高' => 'Height',
+ '消瘦' => 'Slim',
+ '正常' => 'Normal',
+ '偏重' => 'Overweight',
+ '肥胖' => 'Obesity',
+ '反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status",
+ '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors",
+ 'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.",
+ '公斤' => "kg",
+ 'CM' => "cm",
+ '年' => "-",
+ '月' => "-",
+ '日' => "",
+ '身体得分' => "Physical score",
+ '分' => "score",
+ '身体类型' => "body type",
+ '健美肌肉型' => "Bodybuilding muscle type",
+ '低' => "Low",
+ '偏低' => "Slightly low",
+ '标准' => "Standard",
+ '偏高' => "Slightly high",
+ '高' => "High",
+ '矮' => "Short",
+ '偏矮' => "Slightly short",
+ '脂肪率' => "Body Fat Percentage",
+ '体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.",
+ '脂肪量' => "Fat Mass",
+ '人体脂肪的重量' => "Body Fat Weight",
+ '肌肉率' => "Muscle Percentage",
+ '优' => "Excellent",
+ '根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.",
+ '肌肉量' => "Muscle Mass",
+ '不足' => "Insufficient",
+ '肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage",
+ '水分' => "Body Water",
+ '指人体内水分比例。' => "Refers to the proportion of water in the human body.",
+ '蛋白量' => "Protein Mass",
+ '蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage",
+ '骨重' => "Bone Mass",
+ '单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.",
+ '蛋白率' => "Protein Percentage",
+ '人体内蛋白率含量。' => "The proportion of protein in the human body.",
+ '基础代谢' => "Basal Metabolic Rate (BMR)",
+ '指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.",
+ '内脏指数' => "Visceral Fat Index",
+ '警惕' => "Caution",
+ '危险' => "Danger",
+ '内脏脂肪指数' => "Visceral Fat Level",
+ '皮下脂肪' => "Subcutaneous Fat",
+ '皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.",
+ '肥胖等级' => "Obesity Level",
+ '体重不足' => "Underweight",
+ '肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.",
+ '孩子可能存在营养不良:对于处在生长发育期的孩子而言,蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.",
+ '孩子可能存在营养不良:对于处在生长发育期的孩子而言,最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.",
+ '坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.",
+ '3-7岁的孩子:骑两轮车、拍踢球、打篮球、游泳、爬山,每天高强度运动不超过30分钟。' => "Ages 3–7: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.",
+ '该年龄段睡眠时间建议:9-11小时' => "Recommended sleep duration for this age group: 9–11 hours.",
+ '孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'I’m always here for you,' 'I see your progress').",
+ '《中华人民共和国卫生行业标准WS 423-2013》' => "《Chinese Health Industry Standard WS 423-2013》",
+ '《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》",
+ '《中华人民共和国卫生行业标准WS/T1586-2018》' => "《Chinese Health Industry Standard WS/T 1586-2018》",
+ '《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》",
+ '头围' => "Head Circumference",
+ '头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.",
+
+ ],
+ // 可以添加更多语言映射
+ ];
+
+ /**
+ * 处理多国语言翻译
+ *
+ * @param string $language 目标语言代码
+ * @param mixed $data 要翻译的数据(字符串或数组)
+ * @return mixed 翻译后的数据
+ */
+ public function handling_languages_from_multiple_countries($language, $data)
+ {
+
+ // dump($data);
+ // 验证语言是否支持
+ if (!$this->isLanguageSupported($language)) {
+ return $this->msg($data['data']);
+ }
+
+ // 如果是数组,递归处理每个元素
+ if (is_array($data)) {
+ // dump(2);
+ $data = $this->translateArray($language, $data);
+ return $this->msg($data['data']);
+ }
+
+ // 如果是字符串,直接翻译
+ if (is_string($data)) {
+ // dump(3);
+ return $this->translateString($language, $data);
+ }
+
+ // dump($data);
+ // 其他类型直接返回
+ return $this->msg($data['data']);
+ }
+
+ /**
+ * 检查语言是否支持
+ *
+ * @param string $language 语言代码
+ * @return bool
+ */
+ protected function isLanguageSupported($language)
+ {
+ return isset($this->supportedLanguages[$language]);
+ }
+
+ /**
+ * 翻译数组
+ *
+ * @param string $language 目标语言
+ * @param array $array 要翻译的数组
+ * @return array 翻译后的数组
+ */
+ protected function translateArray($language, array $array)
+ {
+ $result = [];
+ foreach ($array as $key => $value) {
+ // 保持键不变,只翻译值
+ $result[$key] = is_array($value)
+ ? $this->translateArray($language, $value)
+ : $this->translateString($language, $value);
+ }
+ return $result;
+ }
+
+ /**
+ * 翻译字符串
+ *
+ * @param string $language 目标语言
+ * @param string $string 要翻译的字符串
+ * @return string 翻译后的字符串
+ */
+ protected function translateString($language, $string)
+ {
+ // dump($string);
+ // 检查是否有该语言的映射表
+ if (!isset($this->languageMap[$language])) {
+ return $string;
+ }
+
+ // 检查是否有对应的翻译
+ return $this->languageMap[$language][$string] ?? $string;
+ }
+
+ /**
+ * 获取支持的语言列表
+ *
+ * @return array
+ */
+ public function getSupportedLanguages()
+ {
+ return $this->supportedLanguages;
+ }
+
+ /**
+ * 添加新的语言翻译
+ *
+ * @param string $language 语言代码
+ * @param array $translations 翻译映射数组
+ * @return bool
+ */
+ public function addTranslations($language, array $translations)
+ {
+ if (!$this->isLanguageSupported($language)) {
+ return false;
+ }
+
+ if (!isset($this->languageMap[$language])) {
+ $this->languageMap[$language] = [];
+ }
+
+ $this->languageMap[$language] = array_merge(
+ $this->languageMap[$language],
+ $translations
+ );
+
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Login.php b/application/NewReedaw2/controller/app/Login.php
index a518d58..847a30b 100644
--- a/application/NewReedaw2/controller/app/Login.php
+++ b/application/NewReedaw2/controller/app/Login.php
@@ -1,12 +1,12 @@
msg(10001);
@@ -57,8 +58,9 @@ class Login extends Base{
}
// 登录
public function login(){
+ $data = input('post.');
try {
- $data = input('post.');
+
if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){
return $this->msg(10001);
}
@@ -90,8 +92,9 @@ class Login extends Base{
}
// 重置密码
public function reset_password(){
+ $data = input('post.');
try {
- $data = input('post.');
+
// 验证数据项是否完整
if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
@@ -128,8 +131,9 @@ class Login extends Base{
}
// 微信手机号快捷登录
public function wechat_quick_login(){
+ $data = input('post.');
try {
- $data = input('post.');
+
if(!array_key_exists('code', $data)){
// return $this->msg(10001,'');
return $this->msg(10001,'code is miss');
@@ -154,14 +158,17 @@ class Login extends Base{
// 调用Wechat服务类处理微信登录逻辑
$wechatService = new Wechat();
$result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']);
+
if($result['code'] == 0){
- $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->fidle('token,id,is_del')->find();
+ $user_data = Db::table($this->login_use_db_name['zhanghao'])->where(['tel'=>$result['data']['phoneNumber']])->field('token,id,is_del')->find();
+ // dump($result);
+ // die;
if($user_data){
if($user_data['is_del'] == 1){
return $this->msg(10002,'该账号已注销');
}
Db::table($this->login_use_db_name['zhanghao'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]);
- $return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
+ return $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]);
}else{
$set_data['password'] = '';
$set_data['tel'] = $result['data']['phoneNumber'];
@@ -356,6 +363,7 @@ class Login extends Base{
return $this->msg(10005);
}
$verify_result[$montage_data] = $data['data'];
+ $verify_result['is_del'] = 0;
// $verify_result['is_del'] = 0;
// 检测校验途径
if($data['validate_type'] == 'code'){
@@ -363,10 +371,10 @@ class Login extends Base{
if($this->check_code($code_name,$data['validate_data']) === true){
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,is_del')->find();
if($result){
- if($result['is_del'] == 1){
- return $this->msg(10002,'该账号已注销');
- }
- Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
+ // if($result['is_del'] == 1){
+ // return $this->msg(10002,'该账号已注销');
+ // }
+ Db::table($this->login_use_db_name['zhanghao'])->where(['id'=>$result['id']])->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]);
}else{
$set_data['password'] = '';
@@ -390,16 +398,16 @@ class Login extends Base{
// $verify_result['password'] = $data['validate_data'];
$result = Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->field('id,token,password,is_del')->find();
if($result){
- if($result['is_del'] == 1){
- return $this->msg(10002,'该账号已注销');
- }
+ // if($result['is_del'] == 1){
+ // return $this->msg(10002,'该账号已注销');
+ // }
if($result['password'] == ''){
$return_data = $this->msg(10002,'该账户未设密码,请用验证码登录');
}
if($data['validate_data'] != $result['password']){
$return_data = $this->msg(10002,'账号或密码错误');
}else{
- Db::table($this->login_use_db_name['zhanghao'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]);
+ Db::table($this->login_use_db_name['zhanghao'])->where(['id'=>$result['id']])->update(['login_time'=>date('Y-m-d H:i:s')]);
$return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功');
}
}else{
diff --git a/application/NewReedaw2/controller/app/Role.php b/application/NewReedaw2/controller/app/Role.php
index 90bf494..ca11f82 100644
--- a/application/NewReedaw2/controller/app/Role.php
+++ b/application/NewReedaw2/controller/app/Role.php
@@ -1,19 +1,19 @@
'app_account_number',
'juese'=>'app_user_data',
- 'quyu_card'=>'admin_estimate'
+ 'quyu_card'=>'admin_estimate',
+ 'cfc_user'=>'app_user_data'
];
protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶'];
protected $grade_list = [
@@ -52,9 +52,9 @@ class Role extends Base{
];
// 阶段性称谓
protected $stage_appellation = [
- ['min'=>'0','max'=>'3','value'=>'婴儿'],
- ['min'=>'3','max'=>'16','value'=>'儿童'],
- ['min'=>'16','max'=>'500','value'=>'成人']
+ ['min'=>'0','max'=>'3','value'=>'婴儿','identification'=>3],
+ ['min'=>'3','max'=>'16','value'=>'儿童','identification'=>2],
+ ['min'=>'16','max'=>'500','value'=>'成人','identification'=>1]
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
@@ -66,17 +66,181 @@ class Role extends Base{
################################################################接口################################################################
################################################################接口################################################################
- // 添加角色
- public function add_member(){
+ // 获取账号下信息
+ public function get_my_account_msg(){
+ $data = input('post.');
try {
- // 你的业务逻辑
- $data = input('post.');
- if(!array_key_exists('token', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
+ if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
- if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
+ if($data['token'] == ''){
+ return $this->msg(-2,'请先登录',[]);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ $return_data = $this->get_my_account_msg_action($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 update_my_account_msg(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){
return $this->msg(10001);
}
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['code'],'intnum')){
+ return $this->msg(10005);
+ }
+
+ return $this->update_my_account_msg_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
+ // 修改密码
+ public function update_my_password(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['password'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['c_password'],'str')){
+ return $this->msg(10005);
+ }
+ $return_data = $this->update_my_password_action($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 set_my_account_msg(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('weight', $data) || !array_key_exists('height', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('activity_level', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['height'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['birthday'],'datetime')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['activity_level'],'num')){
+ return $this->msg(10005);
+ }
+ $return_data = $this->set_my_account_msg_action($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 add_member(){
+ $data = input('post.');
+ try {
+ // 你的业务逻辑
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is loss');
+ }
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'昵称缺失');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'生日缺失');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'性别缺失');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'身高缺失');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'体重缺失');
+ }
+ if(!array_key_exists('activity_level', $data)){
+ return $this->msg(10001,'活动系数缺失');
+ }
+ if(!$this->verify_data_is_ok($data['activity_level'],'num')){
+ return $this->msg(10005,'activity_level type error');
+ }
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
@@ -92,6 +256,9 @@ class Role extends Base{
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type error');
+ }
return $this->add_member_action($data);
} catch (\Exception $e) {
// 捕获异常
@@ -109,14 +276,36 @@ class Role extends Base{
}
// 更新角色
public function update_member(){
+ $data = input('post.');
try {
// 你的业务逻辑
- $data = input('post.');
- if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('nickname', $data) || !array_key_exists('birthday', $data) || !array_key_exists('gender', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('measure_model', $data)){
- return $this->msg(10001);
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001,'token is loss');
}
- if($data['measure_model'] != '1' && $data['measure_model'] != '2'){
- return $this->msg(10001);
+ if(!array_key_exists('nickname', $data)){
+ return $this->msg(10001,'昵称缺失');
+ }
+ if(!array_key_exists('birthday', $data)){
+ return $this->msg(10001,'生日缺失');
+ }
+ if(!array_key_exists('gender', $data)){
+ return $this->msg(10001,'性别缺失');
+ }
+ if(!array_key_exists('height', $data)){
+ return $this->msg(10001,'身高缺失');
+ }
+ if(!array_key_exists('weight', $data)){
+ return $this->msg(10001,'体重缺失');
+ }
+ if(!array_key_exists('activity_level', $data)){
+ return $this->msg(10001,'活动系数缺失');
+ }
+ if(!array_key_exists('id', $data)){
+ return $this->msg(10001,'id is loss');
+ }
+ if(!$this->verify_data_is_ok($data['activity_level'],'num')){
+ return $this->msg(10005,'activity_level type error');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
@@ -136,6 +325,12 @@ class Role extends Base{
if(!$this->verify_data_is_ok($data['weight'],'num')){
return $this->msg(10005,'weight type error');
}
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005,'nickname type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
return $this->update_member_action($data);
} catch (\Exception $e) {
// 捕获异常
@@ -153,9 +348,10 @@ class Role extends Base{
}
// 获取角色列表
public function role_list(){
+ $data = input('post.');
try {
// 你的业务逻辑
- $data = input('post.');
+
if(!array_key_exists('token', $data)){
return $this->msg(10001);
}
@@ -177,9 +373,240 @@ class Role extends Base{
return $this->msg(99999);
}
}
+ // 修改昵称
+ public function update_my_nickname(){
+
+ $data = input('post.');
+ try {
+ if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['nickname'],'str')){
+ return $this->msg(10005);
+ }
+ $return_data = $this->update_my_nickname_action($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_user_data_information(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ return $this->get_user_data_information_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
+ // 删除角色
+ public function del_member(){
+
+ $data = input('post.');
+ try {
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ return $this->del_member_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+
+ }
################################################################action################################################################
################################################################action################################################################
+
+
+ public function get_my_account_msg_action($data){
+ $result = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->find();
+ $cfc = Db::connect('cfc_db');
+ $cfc_user = $cfc->table($this->role_db_name['cfc_user'])
+ ->where(['token'=>$data['token']])
+ ->find(); // 然后获取结果
+
+ //
+ if($result){
+ $return_data = [
+ 'my_tel'=>$result['tel'],
+ 'my_email'=>$result['email'],
+ 'create_time'=>$result['create_time'],
+ 'token'=>$result['token'],
+ 'nickname'=>$result['nickname'],
+ 'head_pic'=>$result['head_pic'],
+ ];
+ if($cfc_user){
+ // dump($result);
+
+ $return_data['weight'] = $cfc_user['weight'];
+ $return_data['height'] = $cfc_user['height'];
+ $return_data['birthday'] = $cfc_user['birthday'];
+ $return_data['gender'] = $cfc_user['gender'];
+ $return_data['activity_level'] = $cfc_user['activity_level'];
+ }else{
+ $return_data['weight'] = 0;
+ $return_data['height'] = 0;
+ $return_data['birthday'] = '';
+ $return_data['gender'] = '';
+ $return_data['activity_level'] = '';
+ }
+ return $this->msg($return_data);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function update_my_account_msg_action($data){
+ $login_action = new Login();
+ $validate_result = $login_action->check_code($data['data'],$data['code']);
+ if($validate_result !== true){
+ return $this->msg(10001,$validate_result);
+ }
+ $montage_data = $this->is_tel_email($data['data']);
+ if($montage_data == false){
+ return $this->msg(10005);
+ }
+ $result = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->update([
+ $montage_data=>$data['data'],
+ 'update_time'=>date('Y-m-d H:i:s')
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function update_my_password_action($data){
+ if($data['password'] != $data['c_password']){
+ return $this->msg(10003,'两次密码不一致');
+ }
+ if($data['password'] == ''){
+ return $this->msg(10003,'密码不能为空');
+ }
+ $result = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->update([
+ 'password'=>$data['password'],
+ 'update_time'=>date('Y-m-d H:i:s')
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function set_my_account_msg_action($data){
+ $cfc = Db::connect('cfc_db');
+ $user = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->find();
+ if($user){
+ $cfc_user = $cfc->table($this->role_db_name['cfc_user'])
+ ->where(['token'=>$data['token']])
+ ->find(); // 然后获取结果
+ if($cfc_user){
+ $cfc_user = $cfc->table($this->role_db_name['cfc_user'])
+ ->where(['token'=>$data['token']])
+ ->update([
+ 'weight'=>$data['weight'],
+ 'height'=>$data['height'],
+ 'birthday'=>$data['birthday'],
+ 'gender'=>$data['gender'],
+ 'activity_level'=>$data['activity_level'],
+ ]);
+ }else{
+ $add_data = [
+ 'token'=>$data['token'],
+ 'nickname'=>$user['nickname'],
+ 'gender'=>$data['gender'],
+ 'height'=>$data['height'],
+ 'weight'=>$data['weight'],
+ 'birthday'=>$data['birthday'],
+ 'activity_level'=>$data['activity_level'],
+ ];
+ $user_age = $this->calculate_age($data['birthday']);
+ if($data['gender'] == 2){
+ if($user_age <= 18){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman1.png";
+ }else if($user_age <= 39 && $user_age > 18){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman2.png";
+ }else if($user_age <= 59 && $user_age > 39){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman3.png";
+ }else if($user_age >= 60){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman4.png";
+ }
+ }else{
+ if($user_age <= 18){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
+ }else if($user_age <= 39 && $user_age > 18){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man2.png";
+ }else if($user_age <= 59 && $user_age > 39){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man3.png";
+ }else if($user_age >= 60){
+ $data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man4.png";
+ }
+ }
+ $cfc_user = $cfc->table($this->role_db_name['cfc_user'])->insert($add_data);
+ }
+ }else{
+ return $this->msg(10003);
+ }
+
+ }
+
+
+
public function add_member_action($data){
$aan_id = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token')->find();
if(!$aan_id){
@@ -195,42 +622,42 @@ class Role extends Base{
$parameter['card_order'] = '';
$parameter['create_time'] = date('Y-m-d H:i:s');
$parameter['last_update_time'] = $parameter['create_time'];
- $parameter['measure_model'] = $data['measure_model'];
+ $parameter['activity_level'] = $data['activity_level'];
$is_nickname_ok = Db::table($this->role_db_name['juese'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
if($is_nickname_ok>0){
return $this->msg(10002,'该角色已存在');
}
- if($parameter['measure_model'] == 1){
- if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
- return $this->msg(10001);
- }
- if(!array_key_exists($data['identity_id'],$this->identity_list)){
- return $this->msg(10005,'身份信息错误');
- }
- if(!array_key_exists($data['grade'],$this->grade_list2)){
- return $this->msg(10005,'年级信息错误');
- }
- $parameter['grade'] = $data['grade'];
- $parameter['identity_id'] = $data['identity_id'];
- $parameter['identity_name'] = $this->identity_list[$data['identity_id']];
- $parameter['address'] = $data['address'];
- $address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
- $parameter['card_order'] = $address_data['recommend_cards'];
- }else{
- $parameter['grade'] = 'nothing';
- $parameter['identity_id'] = 'P0';
- $parameter['identity_name'] = '陌生人';
- $parameter['address'] = '';
- }
- if($parameter['identity_id'] != 'P0'){
- $result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
- if($result>0){
- return $this->msg(10005,'该身份已存在');
- }
- }
- $return_result = Db::table($this->role_db_name['juese'])->insert($parameter);
+ // if($parameter['measure_model'] == 1){
+ // if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
+ // return $this->msg(10001);
+ // }
+ // if(!array_key_exists($data['identity_id'],$this->identity_lis3t)){
+ // return $this->msg(10005,'身份信息错误');
+ // }
+ // if(!array_key_exists($data['grade'],$this->grade_list2)){
+ // return $this->msg(10005,'年级信息错误');
+ // }
+ // $parameter['grade'] = $data['grade'];
+ // $parameter['identity_id'] = $data['identity_id'];
+ // $parameter['identity_name'] = $this->identity_list[$data['identity_id']];
+ // $parameter['address'] = $data['address'];
+ // $address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
+ // $parameter['card_order'] = $address_data['recommend_cards'];
+ // }else{
+ // $parameter['grade'] = 'nothing';
+ // $parameter['identity_id'] = 'P0';
+ // $parameter['identity_name'] = '陌生人';
+ // $parameter['address'] = '';
+ // }
+ // if($parameter['identity_id'] != 'P0'){
+ // $result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count();
+ // if($result>0){
+ // return $this->msg(10005,'该身份已存在');
+ // }
+ // }
+ $return_result = Db::table($this->role_db_name['juese'])->insertGetId($parameter);
if($return_result){
- return $this->msg([]);
+ return $this->msg(['aud_id'=>$return_result]);
}else{
return $this->msg(10002);
}
@@ -248,32 +675,32 @@ class Role extends Base{
$parameter['weight'] = $data['weight'];
$parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png';
$parameter['last_update_time'] = date('Y-m-d H:i:s');
- $parameter['measure_model'] = $data['measure_model'];
- if($parameter['measure_model'] == 1){
- if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
- return $this->msg(10001);
- }
- if(!array_key_exists($data['identity_id'],$this->identity_list)){
- return $this->msg(10005,'身份信息错误');
- }
- if(!array_key_exists($data['grade'],$this->grade_list2)){
- return $this->msg(10005,'年级信息错误');
- }
- $parameter['grade'] = $data['grade'];
- $parameter['identity_id'] = $data['identity_id'];
- $parameter['identity_name'] = $this->identity_list[$data['identity_id']];
- $parameter['address'] = $data['address'];
- if($parameter['identity_id'] != 'P0'){
- $result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id['id'],'is_del'=>0])->count();
- if($result>0){
- return $this->msg(10005,'该身份已存在');
- }
- }
- $address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
- $parameter['card_order'] = $address_data['recommend_cards'];
- }
+ $parameter['activity_level'] = $data['activity_level'];
+ // if($parameter['measure_model'] == 1){
+ // if(!array_key_exists('grade',$data) || !array_key_exists('identity_id',$data) || !array_key_exists('address',$data)){
+ // return $this->msg(10001);
+ // }
+ // if(!array_key_exists($data['identity_id'],$this->identity_list)){
+ // return $this->msg(10005,'身份信息错误');
+ // }
+ // if(!array_key_exists($data['grade'],$this->grade_list2)){
+ // return $this->msg(10005,'年级信息错误');
+ // }
+ // $parameter['grade'] = $data['grade'];
+ // $parameter['identity_id'] = $data['identity_id'];
+ // $parameter['identity_name'] = $this->identity_list[$data['identity_id']];
+ // $parameter['address'] = $data['address'];
+ // if($parameter['identity_id'] != 'P0'){
+ // $result = Db::table($this->role_db_name['juese'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id['id'],'is_del'=>0])->count();
+ // if($result>0){
+ // return $this->msg(10005,'该身份已存在');
+ // }
+ // }
+ // $address_data = Db::table($this->role_db_name['quyu_card'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find();
+ // $parameter['card_order'] = $address_data['recommend_cards'];
+ // }
- $return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update($parameter);
+ $return_result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['id']])->update($parameter);
if($return_result){
return $this->msg([]);
}else{
@@ -312,7 +739,9 @@ class Role extends Base{
// 添加阶段称谓、婴儿、儿童、成人
foreach ($this->stage_appellation as $key => $value) {
if($result[$i]['age'] >= $value['min'] && $result[$i]['age'] < $value['max']){
- $result[$i]['stage'] = $value['value'];
+ // $result[$i]['stage'] = $value['value'];
+ $result[$i]['stage'] = $value['identification'];
+
}
}
}
@@ -320,6 +749,154 @@ class Role extends Base{
}
return $this->msg($temporary_data);
}
+ public function update_my_nickname_action($data){
+ $result = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->update([
+ 'nickname'=>$data['nickname'],
+ 'update_time'=>date('Y-m-d H:i:s')
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
+
+ public function get_user_data_information_action($data){
+
+ // 获取账号下信息以及用户信息
+ $zhanghao_data = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic,tel,email')->find();
+
+
+
+ if(!$zhanghao_data){
+ return $this->msg(10004);
+ }
+ // 获取账号下信息以及用户信息start
+ $user_all_data['aud_id'] = '';
+ $user_all_data['token'] = $zhanghao_data['token'];
+ $user_all_data['nickname'] = '';
+ $user_all_data['head_pic'] = $zhanghao_data['head_pic'];
+ $user_all_data['gender'] = '';
+ $user_all_data['age'] = '';
+ $user_all_data['height'] = '';
+ $user_all_data['weight'] = '';
+ $user_all_data['set_kcal'] = '';
+ $user_all_data['is_use_set_kcal'] = '';
+ $user_all_data['tel'] = $zhanghao_data['tel'];
+ $user_all_data['email'] = $zhanghao_data['email'];
+
+ $user_all_data['aan_id'] = $zhanghao_data['id'];
+ $user_all_data['card_order'] = [];
+ $user_all_data['target_weight'] = 0;
+ $user_all_data['initial_weight'] = 0;
+ $user_all_data['initial_date'] = 0;
+ $user_all_data['address'] = '';
+ $user_all_data['identity_id'] = 'P0';
+ $user_all_data['measure_model'] = 1;
+ $user_all_data['head_data'] = 0;
+ $user_all_data['stage'] = 0;
+
+
+
+
+
+ $user_account = Db::table($this->role_db_name['juese'])
+ ->where(["id"=>$data['aud_id']])
+ // ->field('id as aud_id,nickname,head_pic,gender,height,weight,birthday,set_kcal,is_use_set_kcal,activity_level')
+ ->field('id as aud_id,nickname,head_pic,gender,height,weight,birthday,card_order,target_weight,initial_weight,initial_date,address,identity_id,measure_model,head_data,set_kcal,is_use_set_kcal,activity_level')
+ ->find();
+
+ if($user_account){
+ if($user_account['set_kcal'] == '.00'){
+ $user_account['set_kcal'] = 0;
+ }
+ $user_all_data['id'] = $user_account['aud_id'];
+ $user_all_data['aud_id'] = $user_account['aud_id'];
+ $user_all_data['nickname'] = $user_account['nickname'];
+ $user_all_data['gender'] = $user_account['gender'];
+ $user_all_data['age'] = $this->calculate_age($user_account['birthday']);
+ $user_all_data['height'] = $user_account['height'];
+ $user_all_data['weight'] = $user_account['weight'];
+ $user_all_data['set_kcal'] = $user_account['set_kcal'];
+ $user_all_data['is_use_set_kcal'] = $user_account['is_use_set_kcal'];
+ $user_all_data['birthday'] = $user_account['birthday'];
+ $user_all_data['activity_level'] = $user_account['activity_level'];
+
+ $user_all_data['card_order'] = explode(',',$user_account['card_order']);
+ $user_all_data['target_weight'] = $user_account['target_weight'];
+ $user_all_data['initial_weight'] = $user_account['initial_weight'];
+ $user_all_data['initial_date'] = $user_account['initial_date'];
+ $user_all_data['address'] = $user_account['address'];
+ $user_all_data['identity_id'] = $user_account['identity_id'];
+ $user_all_data['measure_model'] = $user_account['measure_model'];
+ $user_all_data['head_data'] = $user_account['head_data'];
+
+ foreach ($this->stage_appellation as $key => $value) {
+ if($user_all_data['age'] >= $value['min'] && $user_all_data['age'] < $value['max']){
+ // $user_all_data['stage'] = $value['value'];
+ $user_all_data['stage'] = $value['identification'];
+
+ }
+ }
+ // if($user_all_data['gender'] == 2){
+ // if($user_all_data['age'] <= 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman1.png";
+ // }else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman2.png";
+ // }else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman3.png";
+ // }else if($user_all_data['age'] >= 60){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman4.png";
+ // }
+ // }else{
+ // if($user_all_data['age'] <= 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
+ // }else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man2.png";
+ // }else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man3.png";
+ // }else if($user_all_data['age'] >= 60){
+ // $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man4.png";
+ // }
+ // }
+
+ $kitchenscale = NEW Kitchenscale;
+ $user_all_data['food_count'] = $kitchenscale->get_countfoot_content_action(['token'=>$data['token'],'aud_id'=>$user_all_data['aud_id'],'time'=>date('Y-m-d')]);
+ $user_all_data['food_count'] = ($user_all_data['food_count']->getData())['data'];
+ // dump($user_all_data['food_count']);
+ }else{
+ $user_account['set_kcal'] = 0;
+ $user_all_data['aud_id'] = null;
+ $user_all_data['gender'] = 0;
+ $user_all_data['age'] = false;
+ $user_all_data['height'] = null;
+ $user_all_data['weight'] = null;
+ $user_all_data['set_kcal'] = 0;
+ $user_all_data['is_use_set_kcal'] = 0;
+ $user_all_data['birthday'] = null;
+ $user_all_data['activity_level'] = null;
+ $user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
+
+ $user_all_data['food_count'] = [];
+ // $user_all_data['food_count'] = ($user_all_data['food_count']->getData())['data'];
+ }
+ return $this->msg($user_all_data);
+ }
+
+ public function del_member_action($data){
+ // $zh_data = Db::table($this->role_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->field('id,token')->find();
+
+ $result = Db::table($this->role_db_name['juese'])->where(['id'=>$data['aud_id']])->update([
+ 'is_del'=>1
+ ]);
+ if($result){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+
diff --git a/application/NewReedaw2/controller/app/Skip.php b/application/NewReedaw2/controller/app/Skip.php
new file mode 100644
index 0000000..a0143ae
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Skip.php
@@ -0,0 +1,267 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'body'=>'app_card_body_data',
+ 'body_new'=>'app_card_body_data_new',
+ 'skip'=>'app_card_skip_data',
+
+ ];
+ protected $curve_data_format = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']];
+ // protected $skip_use_db_name = [
+ // '1'=>'app_card_skip_data',
+ // '2'=>'app_user_data',
+ // '3'=>'app_card_body_data',
+ // ];
+ protected $pagesize = 15;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+
+ // 设备记录
+ public function device_record(){
+ $data = input('post.');
+ try {
+ // 你的业务逻辑
+ if(count(input('post.')) > 0){
+ $data = input('post.');
+ }
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $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['kcal'],'num')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['type'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){
+ $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
+ }
+ if($data['num'] <= 0){
+ $return_data = $this->msg(10005,'跳绳数不能小于等于0');
+ }
+ if(abs($data['time_s']) >= 60){
+ $return_data = $this->msg(10005,'秒钟值不能大于60');
+ }
+ unset($data['token']);
+
+ return $this->device_record_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 数据报告
+ public function data_report(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005);
+ }
+ unset($data['token']);
+ return $this->data_report_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+ public function device_record_action($data){
+
+ // 分秒转换为秒
+ $data['time'] = abs($data['time_m'])*60+abs($data['time_s']);
+ $user_msg_content = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->count();
+ if($user_msg_content<=0){
+ return $this->msg(10004);
+ }
+ if(!array_key_exists('kcal', $data)){
+ $last_data_body = Db::table($this->skip_db_name['body_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find();
+ if(!$last_data_body){
+ $last_data_body = Db::table($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find();
+ if(!$last_data_body){
+ return $this->msg(10004);
+ }
+ }
+ $kcal_data = $this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight_val']);
+ }else{
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($data['time'],60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($data['num'],$minutes,2);
+ $kcal_data['totalCalories'] = $data['kcal'];
+ $kcal_data['averageAchievement'] = $jumpsPerMinute;
+ $kcal_data['caloriesPerMinute'] = bcdiv($kcal_data['totalCalories'],$minutes,2);
+ }
+
+
+ $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'=>$kcal_data['totalCalories'],
+ 'average_num'=>$kcal_data['averageAchievement'],
+ 'average_kcal'=>$kcal_data['caloriesPerMinute'],
+ 'aud_id'=>$data['aud_id'],
+ 'record_time'=>array_key_exists('r_time', $data)?$data['r_time']:date('Y-m-d H:i:s'),
+ 'jump_type'=>$data['type']
+ ];
+ if(strlen($data_set['record_time']) <= 12){
+ $data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']);
+ }
+ $last_data_body = Db::table($this->skip_db_name['skip'])->insert($data_set);
+ $result = [
+ 'today_jump_num'=>0,
+ 'today_jump_time'=>0,
+ 'today_jump_kcal'=>0,
+ ];
+ $all_data = Db::table($this->skip_db_name['skip'])->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'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
+ }
+ $result['last_jump_num'] = $data['num'];
+ $result['last_jump_time'] = $data['time'];
+ $result['last_jump_kcal'] = $data_set['jump_kcal'];
+ // $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
+ $result['last_record_time'] = $data_set['record_time'];
+ $time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
+ $result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ $time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
+ $result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ return $this->msg($result);
+ }
+
+ public function data_report_action($data){
+ $all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
+ $last_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,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'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
+ }
+ if($last_data){
+ $result['last_jump_num'] = $last_data['jump_num'];
+ $result['last_jump_time'] = $last_data['jump_time'];
+ $result['last_jump_kcal'] = $last_data['jump_kcal'];
+ $result['last_record_time'] = $last_data['record_time'];
+ }else{
+ $result['last_jump_num'] = 0;
+ $result['last_jump_time'] = 0;
+ $result['last_jump_kcal'] = 0;
+ $result['last_record_time'] = '';
+ }
+ $time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
+ $result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ $time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
+ $result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
+ return $this->msg($result);
+ }
+ // public function get_all_detaile_data_action($data){
+
+ // $result = $result = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id'],'is_del'=>0])->find();
+ // $for_data_arr = ['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']];
+ // if($result){
+ // $result_data = [];
+ // foreach ($for_data_arr as $key => $value) {
+ // $temporary_arr['key_name'] = $key;
+ // $temporary_arr['name'] = $value[0];
+ // $temporary_arr['value'] = explode(',',$result[$key])[0];
+ // $temporary_arr['unit'] = $value[1];
+ // array_push($result_data,$temporary_arr);
+ // }
+ // return $this->msg($result_data);
+ // }else{
+ // return $this->msg(10002);
+ // }
+
+ // }
+
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+ // 跳绳卡路里计算
+ public function skip_kcal_calculate($num=143, $time=222, $weight=70) {
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 将时间从秒转换为分钟
+ $minutes = bcdiv($time,60,20);
+ // 计算每分钟的跳绳次数
+ $jumpsPerMinute = bcdiv($num,$minutes,2);
+ // 根据跳绳次数确定MET值
+ // $met = 11.8;
+ 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 [
+ 'averageAchievement' => $jumpsPerMinute,
+ 'caloriesPerMinute' => $caloriesPerMinute,
+ 'totalCalories' => $totalCalories
+ ];
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Smsaliyun.php b/application/NewReedaw2/controller/app/Smsaliyun.php
index 99ea6c9..fbc7f56 100644
--- a/application/NewReedaw2/controller/app/Smsaliyun.php
+++ b/application/NewReedaw2/controller/app/Smsaliyun.php
@@ -1,5 +1,5 @@
'admin_estimate',
+ 'tc_jilu'=>'app_sportstesting_data',
+ 'juese'=>'app_user_data',
+ ];
+ protected $page_num = 10;
+ protected $default_address = '上海';
+ protected $city_data_rule_name = [
+ 'xc'=>'现场类项目',
+ 'xc_1'=>'第一类:素质项目Ⅰ(8分)',
+ 'xc_2'=>'第二类:素质项目Ⅱ(8分)',
+ 'xc_3'=>'第三类:运动能力Ⅰ(8分)',
+ 'xc_4'=>'第四类:运动能力Ⅱ(6分)',
+ 'gc'=>'过程类项目',
+ 'gc_8_m'=>'8年级体质健康统测(10分)',
+ 'gc_8_r'=>'8年级体育与健康知识机考(10分)',
+ ];
+ protected $city_data_rule_is_choice = ['xc_2','xc_3','xc_4'];
+
+ protected $type_all = [
+ '1'=>'整数填数字(例肺活量)',
+ '2'=>'小数(例50米跑)',
+ '3'=>'拖动区间(例坐位体前屈:-15至30之间,需要有小数1位)',
+ '4'=>'分钟秒钟(例1000米跑)',
+ ];
+
+
+ protected $ceshiyongde_data_baocun_canshu = '{
+ "code": 0,
+ "msg": "操作成功",
+ "data": [
+ {
+ "name": "现场考试",
+ "key": "现场考试",
+ "list": [
+ {
+ "name": "第一类项目(3选1)",
+ "key": "第一类项目",
+ "is_choice": "1",
+ "list": [
+ {
+ "name": "1000米跑",
+ "proportion": "1",
+ "value": "4:23",
+ "proportion_value": null,
+ "unit": "分/秒",
+ "type": "4",
+ "describe": null,
+ "total_score": 6,
+ "choice_state": 1
+ },
+ {
+ "name": "200米游泳",
+ "proportion": "1",
+ "value": "6:12",
+ "proportion_value": null,
+ "unit": "分/秒",
+ "type": "4",
+ "describe": null,
+ "total_score": 6,
+ "choice_state": 0
+ },
+ {
+ "name": "4分钟跳绳",
+ "proportion": "1",
+ "value": 340,
+ "proportion_value": null,
+ "unit": "次",
+ "type": "1",
+ "describe": null,
+ "total_score": 6,
+ "choice_state": 0
+ }
+ ]
+ },
+ {
+ "name": "第二类项目(5选1)",
+ "key": "第二类项目",
+ "is_choice": "1",
+ "list": [
+ {
+ "name": "50米跑",
+ "proportion": "1",
+ "value": 8.1,
+ "proportion_value": null,
+ "unit": "秒",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 1
+ },
+ {
+ "name": "立定跳远",
+ "proportion": "1",
+ "value": 2.02,
+ "proportion_value": null,
+ "unit": "米",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "实心球",
+ "proportion": "1",
+ "value": 7.3,
+ "proportion_value": null,
+ "unit": "米",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "引体向上",
+ "proportion": "1",
+ "value": 6,
+ "proportion_value": null,
+ "unit": "次",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "25米游泳",
+ "proportion": "1",
+ "value": 30,
+ "proportion_value": null,
+ "unit": "秒",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ }
+ ]
+ },
+ {
+ "name": "第三类项目(5选1)",
+ "key": "第三类项目",
+ "is_choice": "1",
+ "list": [
+ {
+ "name": "乒乓球",
+ "proportion": "1",
+ "value": 15,
+ "proportion_value": null,
+ "unit": "次",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 1
+ },
+ {
+ "name": "羽毛球",
+ "proportion": "1",
+ "value": 60,
+ "proportion_value": null,
+ "unit": "得分",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "网球",
+ "proportion": "1",
+ "value": 55,
+ "proportion_value": null,
+ "unit": "得分",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "武术",
+ "proportion": "1",
+ "value": "6",
+ "proportion_value": null,
+ "unit": "得分",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "体操",
+ "proportion": "1",
+ "value": "6",
+ "proportion_value": null,
+ "unit": "得分",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ }
+ ]
+ },
+ {
+ "name": "第四类项目(3选1)",
+ "key": "第四类项目",
+ "is_choice": "1",
+ "list": [
+ {
+ "name": "足球运球",
+ "proportion": "1",
+ "value": 15.5,
+ "proportion_value": null,
+ "unit": "秒",
+ "type": "2",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 1
+ },
+ {
+ "name": "篮球",
+ "proportion": "1",
+ "value": 31,
+ "proportion_value": null,
+ "unit": "秒",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ },
+ {
+ "name": "排球",
+ "proportion": "1",
+ "value": 23,
+ "proportion_value": null,
+ "unit": "40秒/次",
+ "type": "1",
+ "describe": null,
+ "total_score": 3,
+ "choice_state": 0
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "日常考核",
+ "key": "日常考核",
+ "list": [
+ {
+ "name": "体育与健身",
+ "key": "体育与健身",
+ "is_choice": "0",
+ "list": [
+ {
+ "name": "7年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "2"
+ },
+ {
+ "name": "8年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "2"
+ },
+ {
+ "name": "9年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "2"
+ }
+ ]
+ },
+ {
+ "name": "体质健康综合评定",
+ "key": "体质健康综合评定",
+ "is_choice": "0",
+ "list": [
+ {
+ "name": "7年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "3"
+ },
+ {
+ "name": "8年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "3"
+ },
+ {
+ "name": "9年级",
+ "proportion": "1",
+ "value": "60",
+ "proportion_value": null,
+ "unit": "分",
+ "type": "1",
+ "describe": "满分100分",
+ "total_score": "3"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }';
+
+ protected $ceshi_data = [
+ [
+ 'name' => '现场考试',
+ 'key' => '现场考试',
+ 'list' => [
+ [
+ 'name' => '第一类:素质项目Ⅰ',
+ 'key' => '第一类:素质项目Ⅰ',
+ 'is_choice' => '0',
+ 'list' => [
+ [
+ 'name' => '1000米',
+ 'proportion' => '1',
+ 'value' => '4:55',
+ 'proportion_value' => null,
+ 'unit' => '分/秒',
+ 'type' => '4',
+ 'describe' => '1000米。考生参加考试时应穿着运动装、运动鞋,鞋底不得有铁钉、胶钉或塑料钉。',
+ 'total_score' => '8'
+ ]
+ ]
+ ],
+ [
+ 'name' => '第二类:素质项目Ⅱ(6选1)',
+ 'key' => '第二类:素质项目Ⅱ',
+ 'is_choice' => '1',
+ 'list' => [
+ [
+ 'name' => '引体向上',
+ 'proportion' => '1',
+ 'value' => '5',
+ 'proportion_value' => null,
+ 'unit' => '个',
+ 'type' => '1',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 1
+ ],
+ [
+ 'name' => '双杠臂屈伸',
+ 'proportion' => '1',
+ 'value' => '5',
+ 'proportion_value' => null,
+ 'unit' => '个',
+ 'type' => '1',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '实心球',
+ 'proportion' => '1',
+ 'value' => '7.0',
+ 'proportion_value' => null,
+ 'unit' => '米',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '1分钟跳绳',
+ 'proportion' => '1',
+ 'value' => '140',
+ 'proportion_value' => null,
+ 'unit' => '次',
+ 'type' => '1',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '原地纵跳摸高',
+ 'proportion' => '1',
+ 'value' => '38',
+ 'proportion_value' => null,
+ 'unit' => '厘米',
+ 'type' => '1',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '立定跳远',
+ 'proportion' => '1',
+ 'value' => '1.85',
+ 'proportion_value' => null,
+ 'unit' => '米',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ]
+ ]
+ ],
+ [
+ 'name' => '第三类:运动能力Ⅰ(5选1)',
+ 'key' => '第三类:运动能力Ⅰ',
+ 'is_choice' => '1',
+ 'list' => [
+ [
+ 'name' => '足球--运球射门',
+ 'proportion' => '1',
+ 'value' => '22.5',
+ 'proportion_value' => null,
+ 'unit' => '秒',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 1
+ ],
+ [
+ 'name' => '篮球--运球投篮',
+ 'proportion' => '1',
+ 'value' => '38.5',
+ 'proportion_value' => null,
+ 'unit' => '秒',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '排球--垫球发球',
+ 'proportion' => '1',
+ 'value' => '8.5',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '乒乓球--左推右攻发球',
+ 'proportion' => '1',
+ 'value' => '32',
+ 'proportion_value' => null,
+ 'unit' => '次数',
+ 'type' => '1',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '羽毛球--正反手挑球发高远',
+ 'proportion' => '1',
+ 'value' => '14.0',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '2',
+ 'describe' => null,
+ 'total_score' => '8',
+ 'choice_state' => 0
+ ]
+ ]
+ ],
+ [
+ 'name' => '第四类:运动能力Ⅱ(5选1)',
+ 'key' => '第四类:运动能力Ⅱ',
+ 'is_choice' => '1',
+ 'list' => [
+ [
+ 'name' => '体操双杠组合Ⅰ',
+ 'proportion' => '1',
+ 'value' => '4',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '1',
+ 'describe' => '体操4个项目的总分均为6分,其中,动作质量5分、动作表现1分。杠端跳上成分腿坐(1 分)—前进一次成分腿坐(1 分)—弹杠举腿进杠(1 分)—支撑后摆转体180 度成分腿坐(1 分)—弹杠进杠前摆下(1 分)。',
+ 'total_score' => '6',
+ 'choice_state' => 1
+ ],
+ [
+ 'name' => '体操技巧组合Ⅰ',
+ 'proportion' => '1',
+ 'value' => '4',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '1',
+ 'describe' => '体操4个项目的总分均为6分,其中,动作质量5分、动作表现1分。鱼跃前滚翻(1分)—交叉转体180 度(1 分)—后滚成肩肘倒立(1分) —前滚成蹲立(1 分)—挺身跳(1 分)。',
+ 'total_score' => '6',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '健身长拳套路',
+ 'proportion' => '1',
+ 'value' => '3.5',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '2',
+ 'describe' => '武术 2 个项目的总分均为6分,其中,动作质量5分、演练水平 1分。起势(0.5分)—开步双劈(0.5分)—按掌前推(0.5分)—搂手勾踢(0.5分)—缠腕斩拳(0.5分)—闪身冲拳(0.5分)—弹踢穿顶(0.5分)—掼拳戳脚(0.5分)—闪身砍推(0.5分)—收势(0.5分)。',
+ 'total_score' => '6',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '健身南拳套路',
+ 'proportion' => '1',
+ 'value' => '3.5',
+ 'proportion_value' => null,
+ 'unit' => '积分',
+ 'type' => '2',
+ 'describe' => '武术 2 个项目的总分均为6分,其中,动作质量5分、演练水平 1分。起势(0.5分)—架桥双砸拳(0.5分)—缠桥切掌(0.5分)—麒麟步双蝶掌(1分)—踩腿撞拳(0.5分)—挡桥冲拳(0.5分)—闪身虎爪(0.5分)—上步抽拳(0.5分)—架桥双砸拳(0.5分)。',
+ 'total_score' => '6',
+ 'choice_state' => 0
+ ],
+ [
+ 'name' => '100米游泳',
+ 'proportion' => '1',
+ 'value' => '3:05',
+ 'proportion_value' => null,
+ 'unit' => '分/秒',
+ 'type' => '4',
+ 'describe' => '参加游泳项目考试时,考生穿着泳装、佩戴泳帽参加考试,泳装款式应符合中学生身份。不得使用任何有利于其速度、浮力、耐力的器材或泳衣,但可戴游泳镜。',
+ 'total_score' => '6',
+ 'choice_state' => 0
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ 'name' => '过程性考核',
+ 'key' => '过程性考核',
+ 'list' => [
+ [
+ 'name' => '8 年级体质健康统测',
+ 'key' => '8 年级体质健康统测',
+ 'is_choice' => '0',
+ 'list' => [
+ [
+ 'name' => 'BMI',
+ 'proportion' => '0.15',
+ 'value' => '25.3',
+ 'proportion_value' => null,
+ 'unit' => '千克/米㎡',
+ 'type' => '2',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '肺活量',
+ 'proportion' => '0.15',
+ 'value' => '2000',
+ 'proportion_value' => null,
+ 'unit' => '毫升',
+ 'type' => '1',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '50米跑',
+ 'proportion' => '0.2',
+ 'value' => '9.9',
+ 'proportion_value' => null,
+ 'unit' => '秒',
+ 'type' => '2',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '坐位体前屈',
+ 'proportion' => '0.1',
+ 'value' => '-1.4',
+ 'proportion_value' => null,
+ 'unit' => '厘米',
+ 'type' => '2',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '立定跳远',
+ 'proportion' => '0.1',
+ 'value' => '170',
+ 'proportion_value' => null,
+ 'unit' => '厘米',
+ 'type' => '1',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '引体向上',
+ 'proportion' => '0.1',
+ 'value' => '5',
+ 'proportion_value' => null,
+ 'unit' => '次',
+ 'type' => '1',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ],
+ [
+ 'name' => '1000米跑',
+ 'proportion' => '0.2',
+ 'value' => '5:05',
+ 'proportion_value' => null,
+ 'unit' => '分/秒',
+ 'type' => '4',
+ 'describe' => '请参考国家学生体质健康标准高中标准',
+ 'total_score' => '10'
+ ]
+ ]
+ ],
+ [
+ 'name' => '8 年级体育与健康知识',
+ 'key' => '8 年级体育与健康知识',
+ 'is_choice' => '0',
+ 'list' => [
+ [
+ 'name' => '机考',
+ 'proportion' => '1',
+ 'value' => '0.0',
+ 'proportion_value' => null,
+ 'unit' => '分数',
+ 'type' => '2',
+ 'describe' => '机考为8年级体育与健康知识,满分10分。',
+ 'total_score' => '10'
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
+
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 获取地区类型列表
+ public function sportstesting_get_region_list(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['parameter_data'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005);
+ }
+ // if(!$this->verify_data_is_ok($data['choice_last_time'],'intnum')){
+ // return $this->msg(10005);
+ // }else{
+ // if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ // return $this->msg(10005);
+ // }
+ // }
+ $return_data = $this->sportstesting_get_region_list_action($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 sportstesting_set_once_data(){
+ $data = input('post.');
+
+ // $data['result_data'] = $this->ceshi_data;
+ try {
+
+
+ // $data['result_data'] = json_decode($this->ceshiyongde_data_baocun_canshu,true)['data'];
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $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['parameter_data'],'str')){
+ return $this->msg(10005);
+ }
+ if(!$this->verify_data_is_ok($data['gender'],'intnum')){
+ return $this->msg(10005);
+ }
+ if(is_array($data['result_data']) && !empty($data['result_data'])){
+ // 是个数组且不为空数组
+ foreach ($data['result_data'] as $key => $value) {
+ foreach ($value['list'] as $k => $v) {
+ if(count($v['list']) <= 0){
+ return $this->msg(10010,$v['name'].'内并未选择内容');
+ }
+ if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){
+ return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项');
+ }
+ foreach ($v['list'] as $c_k => $c_v) {
+ if(count($c_v) <= 0){
+ return $this->msg(10010,$v['name'].'选项内内容异常');
+ }
+ }
+ }
+ }
+ }else{
+ return $this->msg(10006);
+ }
+ // die;
+ unset($data['token']);
+ // dump($data);
+ // die;
+ $return_data = $this->sportstesting_set_once_data_action2($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);
+ }
+
+
+ }
+
+
+
+
+ ################################################################业务################################################################
+
+ ################################################sportstesting_get_region_list
+ public function sportstesting_get_region_list_action($data){
+
+ $parameter_data = explode(',',$data['parameter_data']);
+ $gender = $data['gender'];
+ // 精准查询地市规则start
+ // if(count($parameter_data) == 1){
+ // $db_condition = "province = '".$parameter_data[0]."'";
+ // }else if(count($parameter_data) == 2){
+ // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
+ // }else if(count($parameter_data) == 3){
+ // $db_condition = "province = ".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
+ // }else{
+ // return $this->msg(10005);
+ // }
+ // 精准查询地市规则end
+ // 全省地市一个规则start
+ $db_condition = "province = '".$parameter_data[0]."'";
+ // 全省地市一个规则end
+ $result = false;
+ // if($data['choice_last_time'] == 1){
+
+ // $last_tiame_data = Db::table($this->sportstesting_use_db_name['tc_jilu'])->where(['aud_id'=>$data['aud_id'],'address'=>$data['parameter_data']])->order('id desc')->find();
+ // if($last_tiame_data){
+ // $result = json_decode($last_tiame_data['content'],true);
+ // }else{
+ // $result = false;
+ // }
+ // }
+
+ if($result === false){
+ $rule_data = Db::table($this->sportstesting_use_db_name['tc_biaozhun'])->where($db_condition)->select();
+ if(count($rule_data) > 0){
+ if(count($rule_data) > 1){
+ // 查到不止一条规则
+ return $this->msg(10004,'查询地址不够详细,请重新选择省市地区');
+ }
+ $rule_data = json_decode($rule_data[0]['content'],true);
+ $result = $this->handle_default_rule_list($rule_data,$gender);
+ }else{
+ return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区');
+ }
+ }
+
+ return $this->msg($result);
+ }
+
+ public function sportstesting_set_once_data_action2($data){
+
+ $return_result['total_score'] = 0;
+ $return_result['max_score'] = 0;
+
+ $parameter_data = explode(',',$data['parameter_data']);
+ $gender = $data['gender'];
+ if(count($parameter_data) == 1){
+ // $db_condition = "province = '".$parameter_data[0]."'";
+ $db_condition = "province = '".$parameter_data[0]."'";
+ }else if(count($parameter_data) == 2){
+ // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'";
+ $db_condition = "province = '".$parameter_data[0]."'";
+ }else if(count($parameter_data) == 3){
+ // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'";
+ $db_condition = "province = '".$parameter_data[0]."'";
+ }else{
+ return $this->msg(10005);
+ }
+ // 只根据省查找,全省一个标准
+ $find_data = Db::table($this->sportstesting_use_db_name['tc_biaozhun'])->where($db_condition)->find();
+ // dump($find_data);
+ // die;
+ $find_data = json_decode($find_data['content'],true);
+ $recognition_rule = $find_data[$gender];
+
+ foreach ($data['result_data'] as $key => $value) {
+ // 遍历一级($value['key'] = 现场考试)
+ foreach ($value['list'] as $k2 => $v2) {
+ // 遍历二级级($v2['key'] = 第一类项目
+ foreach ($v2['list'] as $k3 => $v3) {
+ // 遍历二级级($v3['name'] = 1000米跑)
+ $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3);
+ $data['result_data'][$key]['list'][$k2]['list'][$k3] = $temporary_result;
+ // $data['result_data'][$key]['list'][$k2]['list'][$k3]['name'] = $temporary_result['name']."(该项满分:".$temporary_result['total_score'].")";
+ if(array_key_exists('choice_state',$v3) && $v3['choice_state'] == 0){
+ continue;
+ }
+ $return_result['total_score'] = bcadd($return_result['total_score'],$temporary_result['proportion_value'],2);
+ $return_result['max_score'] = bcadd($return_result['max_score'],bcmul($v3['total_score'],$v3['proportion'],2),2);
+ // if(array_key_exists('choice_state',$v3)){
+ // if($v3['choice_state'] == 1){
+
+ // $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3);
+ // $data['result_data'][$key]['list'][$k2]['list'][$k3] = $temporary_result;
+ // // $data['result_data'][$key]['list'][$k2]['list'][$k3]['name'] = $temporary_result['name']."(该项满分:".$temporary_result['total_score'].")";
+ // $return_result['total_score'] = bcadd($return_result['total_score'],$temporary_result['proportion_value'],2);
+ // $return_result['max_score'] = bcadd($return_result['max_score'],bcmul($v3['total_score'],$v3['proportion'],2),2);
+ // }else{
+ // $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3);
+ // $data['result_data'][$key]['list'][$k2]['list'][$k3] = $temporary_result;
+ // // $data['result_data'][$key]['list'][$k2]['list'][$k3]['name'] = $temporary_result['name']."(该项满分:".$temporary_result['total_score'].")";
+ // $return_result['total_score'] = bcadd($return_result['total_score'],$temporary_result['proportion_value'],2);
+ // $return_result['max_score'] = bcadd($return_result['max_score'],bcmul($v3['total_score'],$v3['proportion'],2),2);
+ // }
+ // }else{
+
+ // $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3);
+ // $data['result_data'][$key]['list'][$k2]['list'][$k3] = $temporary_result;
+ // // $data['result_data'][$key]['list'][$k2]['list'][$k3]['name'] = $temporary_result['name']."(该项满分:".$temporary_result['total_score'].")";
+ // $return_result['total_score'] = bcadd($return_result['total_score'],$temporary_result['proportion_value'],2);
+ // $return_result['max_score'] = bcadd($return_result['max_score'],bcmul($v3['total_score'],$v3['proportion'],2),2);
+ // }
+
+ }
+ }
+ }
+
+ $return_result['list'] = $data['result_data'];
+ $user_sportstesting_set = Db::table($this->sportstesting_use_db_name['tc_jilu'])->insert([
+ 'aud_id'=>$data['aud_id'],
+ 'content'=>json_encode($return_result['list']),
+ 'score'=>$return_result['total_score'],
+ 'max_score'=>$return_result['max_score'],
+ 'create_time'=>date('Y-m-d H:i:s'),
+ 'address'=>$data['parameter_data'],
+ ]);
+ // $user_sportstesting_set = true;
+ if($user_sportstesting_set){
+ foreach ($return_result['list'] as $key => $value) {
+ foreach ($value['list'] as $v1k => $v1v) {
+ for( $i=0; $i < count($v1v['list']); $i++ ){
+
+ if(array_key_exists('choice_state',$v1v['list'][$i]) && $v1v['list'][$i]['choice_state'] == 0){
+
+ unset($return_result['list'][$key]['list'][$v1k]['list'][$i]);
+ }
+ }
+ array_unshift($return_result['list'][$key]['list'][$v1k]['list'],[
+ 'name'=>'项目名',
+ 'value'=>'成绩',
+ 'total_score'=>'满分',
+ 'proportion_value'=>'得分',
+ ]);
+ }
+ }
+ return $this->msg($return_result);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+
+
+
+
+
+
+
+
+ // 处理默认规则列表
+ public function handle_default_rule_list($data,$gender){
+ if($gender == 1){
+ $temporary_arr = $data[$gender];
+ }else{
+ $temporary_arr = $data[2];
+ }
+
+ $result = [];
+ foreach ($temporary_arr as $key => $value) {
+
+ $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]);
+
+ foreach ($value as $s_c_k => $s_c_v) {
+ if($s_c_v['choose_num'] == 0){
+ // 如果是必选项
+ $num2 = array_push($result[$num-1]['list'],[
+ 'name'=>$s_c_k,
+ 'key'=>$s_c_k,
+ 'is_choice'=>$s_c_v['choose_num'],
+ 'list'=>[]
+ ]);
+ foreach ($s_c_v['list'] as $x_m_k => $x_m_v) {
+ array_push($result[$num-1]['list'][$num2-1]['list'],[
+ 'name'=>$x_m_k,
+ 'proportion'=>$x_m_v['proportion'],
+ 'value'=>$x_m_v['value'],
+ 'proportion_value'=>null,
+ 'unit'=>$x_m_v['unit_data'],
+ 'type'=>$x_m_v['type'],
+ 'describe'=>$x_m_v['describe'],
+ 'total_score'=>$x_m_v['score'],
+ ]);
+ }
+ }else{
+ // 如果不是必选项
+ $num2 = array_push($result[$num-1]['list'],[
+ 'name'=>$s_c_k."(".count($s_c_v['list'])."选".$s_c_v['choose_num'].")",
+ 'key'=>$s_c_k,
+ 'is_choice'=>$s_c_v['choose_num'],
+ 'list'=>[]
+ ]);
+ $choice_state_num = $s_c_v['choose_num'];
+ foreach ($s_c_v['list'] as $x_m_k => $x_m_v) {
+ array_push($result[$num-1]['list'][$num2-1]['list'],[
+ 'name'=>$x_m_k,
+ 'proportion'=>$x_m_v['proportion'],
+ 'value'=>$x_m_v['value'],
+ 'proportion_value'=>null,
+ 'unit'=>$x_m_v['unit_data'],
+ 'type'=>$x_m_v['type'],
+ 'describe'=>$x_m_v['describe'],
+ 'total_score'=>$x_m_v['score'],
+ 'choice_state'=>$choice_state_num > 0?1:0,
+ ]);
+ $choice_state_num = $choice_state_num-1;
+ }
+ }
+ }
+ }
+ return $result;
+ }
+
+
+ // 取得成绩
+ public function obtaining_grades($rule,$data){
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ if($data['value'] != '' && $data['value'] != null && $data['value'] != '0' && $data['value'] != '0.0' && $data['value'] != '0.0' && $data['value'] != '0:00'){
+ if(count($rule) > 0){
+ foreach ($rule as $key => $value) {
+ if($data['unit'] == '分/秒'){
+ $rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]);
+ $data_result = $this->convertMinutesSecondsToStringSeconds($data['value']);
+ }else{
+ $rule_result = $value[0];
+ $data_result = $data['value'];
+ }
+
+ switch ($value[1]) {
+ case "<=":
+ $result = $data_result <= $rule_result;
+ break;
+ case ">=":
+ $result = $data_result >= $rule_result;
+ break;
+ case "<":
+ $result = $data_result < $rule_result;
+ break;
+ case ">":
+ $result = $data_result > $rule_result;
+ break;
+ case "==":
+ $result = $data_result == $rule_result;
+ break;
+ case "!=":
+ $result = $data_result != $rule_result;
+ break;
+ default:
+ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误
+ throw new Exception("Unsupported comparison operator: " . $value[1]);
+ }
+ if($result == true){
+ // 判断是不是0分
+ if($data_result == 0){
+ $data['score'] = 0;
+ }else{
+ $data['score'] = $value[2];
+ }
+
+ // 计算比例后分值
+ $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2);
+ $data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),2);
+ // 四舍五入一下结果
+ $data['proportion_value'] = $this->roundToString($data['proportion_value'],1);
+ break;
+ }
+ }
+ }else{
+ $data['score'] = $data['value'] <= $data['total_score']?bcmul(bcdiv($data['value'],$data['total_score'],20),100,2):100;
+ // 计算比例后分值
+ $data['proportion_value'] = $data['value'] <= $data['total_score']?$data['value']:$data['total_score'];
+ }
+
+ }else{
+ $data['score'] = 0;
+ // 计算比例后分值
+ $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2);
+ $data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),1);
+ }
+
+ return $data;
+ }
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Userbody.php b/application/NewReedaw2/controller/app/Userbody.php
new file mode 100644
index 0000000..33a1210
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Userbody.php
@@ -0,0 +1,3729 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'body_data'=>'app_card_body_data',
+ 'body_data_new'=>'app_card_body_data_new',
+ 'bmi'=>'pc_bmistand',
+ 'height'=>'pc_heightstand',
+ 'weight'=>'pc_weightstand2',
+ // 'chufang1'=>'pc_childrenprescription',
+ // 'chufang2'=>'pc_childprescriptionbyage',
+ ];
+ protected $age_limit = 16;
+ protected $pagesize = 15;
+ protected $detailed_model_1 = [ //详情里面的数据模板
+ "name"=>"", //名称
+ "value"=>"0", //值
+ "unit"=>"", // 单位
+ "desc"=>'',// 描述
+ "standard"=>"", //标准值
+ "standard_color"=>"#000000", //标准颜色
+ "list"=>[], //标准列表
+ "key_name"=>'', //标准列表
+ "offset"=>0, //标准列表
+ "tip"=>'', //小妙招
+ ];
+ protected $merged_data = [
+ 'score' => [
+ 'name' => '身体得分',
+ 'unit' => '分',
+ "description"=>"",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/score.png",
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'70','text'=>'较差','color'=>'#C2831C'],
+ ['min_val'=>'71','max_val'=>'80','text'=>'一般','color'=>'#F5A623'],
+ ['min_val'=>'81','max_val'=>'90','text'=>'良好','color'=>'#14CBAD'],
+ ['min_val'=>'91','max_val'=>'100','text'=>'很棒','color'=>'#0F9982'],
+ ],
+ 'key_name'=>'score',
+ ],
+ 'height' => [
+ 'name' => '身高',
+ 'unit' => 'cm',
+ "description"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/height.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '矮' => '#FD5759',
+ '偏矮' => '#FAAD01',
+ '标准' => '#5BD068',
+ '偏高' => '#6793F4',
+ '高' => '#3D67D3'
+ ],
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'','text'=>'矮','color'=>'#FD5759'],
+ ['min_val'=>'','max_val'=>'','text'=>'偏矮','color'=>'#FAAD01'],
+ ['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#5BD068'],
+ ['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#6793F4'],
+ ['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#3D67D3'],
+ ],
+ 'key_name'=>'height',
+ ],
+ 'weight' => [
+ 'name' => '体重',
+ 'unit' => 'kg',
+ "description"=>"体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。",
+ "smart_tip_description"=>"保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '低' => '#F8595D',
+ '偏低' => '#FFAF04',
+ '标准' => '#59D168',
+ '偏高' => '#FFAF04',
+ '高' => '#F8595D'
+ ],
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'','text'=>'低','color'=>'#F8595D'],
+ ['min_val'=>'','max_val'=>'','text'=>'偏低','color'=>'#FFAF04'],
+ ['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#59D168'],
+ ['min_val'=>'','max_val'=>'','text'=>'偏高','color'=>'#FFAF04'],
+ ['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#F8595D'],
+ ],
+ 'key_name'=>'weight',
+ ],
+ 'bmi' => [
+ 'name' => 'BMI',
+ 'unit' => '',
+ "description"=>"BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/bmi10.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '消瘦' => '#FDDA6B',
+ '正常' => '#5BD068',
+ '偏重' => '#FAAD01',
+ '肥胖' => '#FD5759'
+ ],
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'18.5','text'=>'消瘦','color'=>'#FDDA6B'],
+ ['min_val'=>'18.5','max_val'=>'24.0','text'=>'正常','color'=>'#5BD068'],
+ ['min_val'=>'24.0','max_val'=>'28.0','text'=>'偏重','color'=>'#FAAD01'],
+ ['min_val'=>'28.0','max_val'=>'100','text'=>'肥胖','color'=>'#FD5759'],
+ ],
+ 'key_name'=>'bmi',
+ ],
+ 'fat_r' => [
+ 'name' => '脂肪率',
+ 'unit' => '%',
+ "description"=>"体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_r.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '偏低' => '#FCDB67',
+ '标准' => '#58D268',
+ '偏高' => '#FCAA00',
+ '高' => '#FD5752'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ '29'=>[
+ ['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
+ ],
+ '30'=>[
+ ['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
+ ],
+ ],
+ '2'=>[
+ '29'=>[
+ ['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
+ ],
+ '30'=>[
+ ['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
+ ]
+ ]
+ ],
+ 'key_name'=>'fat_r',
+ ],
+ 'fat_w' => [
+ 'name' => '脂肪量',
+ 'unit' => 'kg',
+ "description"=>"脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_w.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '偏低' => '#FCDB67',
+ '标准' => '#58D268',
+ '偏高' => '#FCAA00',
+ '高' => '#FD5752'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ '29'=>[
+ ['min_val'=>'0','max_val'=>'10','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'10','max_val'=>'21','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'21','max_val'=>'26','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'26','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
+ ],
+ '30'=>[
+ ['min_val'=>'0','max_val'=>'11','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'11','max_val'=>'22','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'22','max_val'=>'27','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'27','max_val'=>'50','text'=>'高','color'=>'#FA5951'],
+ ],
+ ],
+ '2'=>[
+ '29'=>[
+ ['min_val'=>'0','max_val'=>'20','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'20','max_val'=>'31','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'31','max_val'=>'38','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'38','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
+ ],
+ '30'=>[
+ ['min_val'=>'0','max_val'=>'21','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'21','max_val'=>'32','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'32','max_val'=>'39','text'=>'偏高','color'=>'#FAB000'],
+ ['min_val'=>'39','max_val'=>'80','text'=>'高','color'=>'#FA5951'],
+ ]
+ ]
+ ],
+ 'key_name'=>'fat_w',
+ ],
+ 'muscle' => [
+ 'name' => '肌肉率',
+ 'unit' => '%',
+ "description"=>"肌肉率指人体成分中肌肉占体重的百分比。肌肉率越高,BMR越大,消耗的热量越多,就不容易发胖。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FFDA68',
+ '标准' => '#59CD6F',
+ '优' => '#3C64D4'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ]
+ ],
+ 'key_name'=>'muscle',
+ ],
+ 'muscleval' => [
+ 'name' => '肌肉量',
+ 'unit' => 'kg',
+ "description"=>"肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscleval.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FFDA68',
+ '标准' => '#59CD6F',
+ '优' => '#3C64D4'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'40','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'40','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'30','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'30','max_val'=>'50','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'50','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ]
+ ],
+ 'key_name'=>'muscleval',
+ ],
+ 'water' => [
+ 'name' => '水分',
+ 'unit' => '%',
+ "description"=>"体水分率指人体组织中的水分占总体重的百分比,也称为身体水分含量。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/water.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FED966',
+ '标准' => '#58CF6B',
+ '优' => '#3A68D7'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'55','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'55','max_val'=>'65','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'65','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'45','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'45','max_val'=>'60','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'60','max_val'=>'100','text'=>'优','color'=>'#3C66D2'],
+ ]
+ ],
+ 'key_name'=>'water',
+ ],
+ 'bone' => [
+ 'name' => '骨重',
+ 'unit' => 'kg',
+ "description"=>"身体骨量指人体骨骼所含的骨基质和矿物质的质量。骨量的大小直接影响骨骼健康,对身体的稳定性和功能起着至关重要的作用。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/bone.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FED966',
+ '标准' => '#58CF6F',
+ '优' => '#3A68D7'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ '60'=>[
+ ['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'2.6','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '60_75'=>[
+ ['min_val'=>'0','max_val'=>'2.8','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'2.8','max_val'=>'3','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'3','max_val'=>'6','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '75'=>[
+ ['min_val'=>'0','max_val'=>'3.1','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'3.1','max_val'=>'3.3','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'3.3','max_val'=>'7','text'=>'优','color'=>'#3C66D2'],
+ ],
+ ],
+ '2'=>[
+ '45'=>[
+ ['min_val'=>'0','max_val'=>'1.7','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'1.7','max_val'=>'1.9','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'1.9','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '45_60'=>[
+ ['min_val'=>'0','max_val'=>'2.1','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'2.1','max_val'=>'2.3','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'2.3','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
+ ],
+ '60'=>[
+ ['min_val'=>'0','max_val'=>'2.4','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'2.4','max_val'=>'2.6','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'2.6','max_val'=>'5','text'=>'优','color'=>'#3C66D2'],
+ ],
+ ]
+ ],
+ 'key_name'=>'bone',
+ ],
+ 'protein' => [
+ 'name' => '蛋白率',
+ 'unit' => '%',
+ "description"=>"蛋白质率指人体组织中蛋白质含量占总体重的百分比。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/protein.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FED966',
+ '标准' => '#58CF6F',
+ '优' => '#3A68D7'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
+ ]
+ ],
+ 'key_name'=>'protein',
+ ],
+ 'proteinval' => [
+ 'name' => '蛋白量',
+ 'unit' => 'kg',
+ "description"=>"",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/proteinval.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FED966',
+ '标准' => '#58CF6F',
+ '优' => '#3A68D7'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'16','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'16','max_val'=>'18','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'18','max_val'=>'50','text'=>'优','color'=>'#3C66D2'], //蓝
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'14','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'14','max_val'=>'16','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'16','max_val'=>'50','text'=>'优','color'=>'#3C66D2'],
+ ]
+ ],
+ 'key_name'=>'proteinval',
+ ],
+ 'visceral' => [
+ 'name' => '内脏指数',
+ 'unit' => '',
+ "description"=>"内脏脂肪指围绕脏器的脂肪组织,主要分布于腹腔内,包括肝脏、心脏、肾脏、胰腺等器官周围的脂肪。身体内脏脂肪的增加会导致慢性代谢性疾病的风险增加。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/visceral.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '标准' => '#55CF6C',
+ '警惕' => '#FEAC00',
+ '危险' => '#FB5A52'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
+ ['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'9','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'9','max_val'=>'14','text'=>'警惕','color'=>'#FAB000'],
+ ['min_val'=>'14','max_val'=>'50','text'=>'危险','color'=>'#FA5951'], //红
+ ]
+ ],
+ 'key_name'=>'visceral',
+ ],
+ 'sfr' => [
+ 'name' => '皮下脂肪',
+ 'unit' => '%',
+ "description"=>"皮下脂肪率指身体内皮下脂肪组织占身体总重量的百分比。皮下脂肪适量时对身体有益,但过量会使身体处于肥胖状态,并可能导致多种健康问题。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/sfr.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '不足' => '#FCDB68',
+ '标准' => '#59D16F',
+ '偏高' => '#FEAB03'
+ ],
+ 'standard_list' => [
+ '1'=>[
+ ['min_val'=>'0','max_val'=>'7','text'=>'不足','color'=>'#FCDB67'], //淡黄
+ ['min_val'=>'7','max_val'=>'15','text'=>'标准','color'=>'#59D16D'], //绿
+ ['min_val'=>'15','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'], //橙
+ ],
+ '2'=>[
+ ['min_val'=>'0','max_val'=>'11','text'=>'不足','color'=>'#FCDB67'],
+ ['min_val'=>'11','max_val'=>'17','text'=>'标准','color'=>'#59D16D'],
+ ['min_val'=>'17','max_val'=>'50','text'=>'偏高','color'=>'#FAB000'],
+ ]
+ ],
+ 'key_name'=>'sfr',
+ ],
+ 'body_level' => [
+ 'name' => '肥胖等级',
+ 'unit' => '',
+ "description"=>"肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_level.png",
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name'=>'body_level',
+ ],
+ 'body_type' => [
+ 'name' => '身体类型',
+ 'unit' => '',
+ "description"=>"身体类型是对人体外形的总体描述和评定",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_type.png",
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name'=>'body_type',
+ ],
+ 'body_age' => [
+ 'name' => '身体年龄',
+ 'unit' => '岁',
+ "description"=>"身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_age.png",
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name'=>'body_age',
+ ],
+ 'head_circumference' => [
+ 'name' => '头围',
+ 'unit' => 'cm',
+ "description"=>"",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/head_circumference.png",
+ 'standard_list' => [],
+ 'key_name'=>'head_circumference',
+ ],
+ 'heart_rate' => [
+ 'name' => '心率',
+ 'unit' => '跳/分钟',
+ "description"=>"心率指正常人安静状态下每分钟心跳的次数,可因年龄、性别或其他生理因素产生个体差异。",
+ "smart_tip_description"=>"注意减少压力和焦虑,适度锻炼,保持良好的睡眠质量,避免过度用力或剧烈运动。",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/heart_rate10.png",
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#FCDB67'],
+ ['min_val'=>'','max_val'=>'','text'=>'标准','color'=>'#58D268'],
+ ['min_val'=>'','max_val'=>'9999','text'=>'偏高','color'=>'#FD5752'],
+ ],
+ 'key_name'=>'heart_rate',
+ ],
+ 'ideal_weight' => [
+ 'name' => '理想体重',
+ 'unit' => 'kg',
+ "description"=>"理想体重是反映和衡量一个人健康状况的重要标志之一。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_weight.png",
+ 'standard_list' => [],
+ 'key_name'=>'ideal_weight',
+ ],
+ 'ideal_height' => [
+ 'name' => '理想身高',
+ 'unit' => 'cm',
+ "description"=>"",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_height.png",
+ 'standard_list' => [],
+ 'key_name'=>'ideal_height',
+ ],
+ 'ideal_bmi' => [
+ 'name' => '理想BMI',
+ 'unit' => '',
+ "description"=>"",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png",
+ 'standard_list' => [],
+ 'key_name'=>'ideal_bmi',
+ ],
+ 'kcal' => [
+ 'name' => 'BMR',
+ 'unit' => 'kcal',
+ "description"=>"BMR是基础代谢率(BasalMetabolicRate)的缩写,指人体在安静状态下,维持基本生命活动所需的最低能量消耗率。",
+ "smart_tip_description"=>"",
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png",
+ 'list' => [
+ '异常' => '#ff0004',
+ '偏低' => '#FF5656',
+ '优' => '#3A68D4'
+ ],
+ 'standard_list' => [
+ ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'],
+ ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#3C66D2'],
+ ],
+ 'key_name'=>'kcal',
+ ],
+ ];
+ protected $heart_rate = [
+ [
+ 'age' => ['min' => '0', 'max' => '1'],
+ '1' => ['min' => '70', 'max' => '190'],
+ '2' => ['min' => '70', 'max' => '190']
+ ],
+ [
+ 'age' => ['min' => '1', 'max' => '12'],
+ '1' => ['min' => '80', 'max' => '160'],
+ '2' => ['min' => '80', 'max' => '160']
+ ],
+ [
+ 'age' => ['min' => '12', 'max' => '36'],
+ '1' => ['min' => '80', 'max' => '130'],
+ '2' => ['min' => '80', 'max' => '130']
+ ],
+ [
+ 'age' => ['min' => '36', 'max' => '60'],
+ '1' => ['min' => '80', 'max' => '120'],
+ '2' => ['min' => '80', 'max' => '120']
+ ],
+ [
+ 'age' => ['min' => '60', 'max' => '120'],
+ '1' => ['min' => '70', 'max' => '110'],
+ '2' => ['min' => '70', 'max' => '110']
+ ],
+ [
+ 'age' => ['min' => '120', 'max' => '204'],
+ '1' => ['min' => '60', 'max' => '100'],
+ '2' => ['min' => '60', 'max' => '100']
+ ],
+ [
+ 'age' => ['min' => '204', 'max' => '480'],
+ '1' => ['min' => '60', 'max' => '100'],
+ '2' => ['min' => '60', 'max' => '100']
+ ],
+ [
+ 'age' => ['min' => '480', 'max' => '720'],
+ '1' => ['min' => '60', 'max' => '100'],
+ '2' => ['min' => '60', 'max' => '100']
+ ],
+ [
+ 'age' => ['min' => '720', 'max' => '9999'], // 61岁+,9999作为最大值占位
+ '1' => ['min' => '60', 'max' => '100'],
+ '2' => ['min' => '60', 'max' => '100']
+ ]
+ ];
+
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ // 手动记录
+ public function manual_record(){
+ $data = input('post.');
+ try {
+ 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);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ if(strlen($data['time']) <= 12){
+ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式
+ $data['time'] = $this->addCurrentTimeToDateString($data['time']);
+ }
+ return $this->set_user_body_data($data,'by_hand_means');
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "函数: manual_record" . "\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 device_record(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['adc'],'num')){
+ return $this->msg(10005,'adc type error');
+ }
+ $temporary_data = $this->convertHeightAndWeight($data['height'],$data['weight']);
+ // dump($temporary_data);
+ if($temporary_data['height_in_cm'] == false){
+ return $this->msg(10005,'身高单位错误');
+ }
+ if($temporary_data['weight_in_kg'] == false){
+ return $this->msg(10005,'体重单位错误');
+ }
+ // 检测设备传过来的info信息
+ if(array_key_exists('info', $data)){
+ if (!is_array($data['info'])) {
+ return $this->msg(10005,'info参数格式错误');
+ }else{
+ $info_data_arr =['bodyage','fat_r','muscle','kcal','visceral','sfr','water','bone','fatlevlval','protein','bmi'];
+ foreach ($data['info'] as $key => $value) {
+ if (!in_array($key, $info_data_arr)) {
+ return $this->msg(10005,'info参数格式错误-2');
+ }
+ }
+ }
+ }
+ $data['height'] = $temporary_data['height_in_cm'];
+ $data['weight'] = $temporary_data['weight_in_kg'];
+ $data['time'] = date('Y-m-d H:i:s');
+ // dump($data);
+ // die;
+ return $this->set_user_body_data($data,'by_device');
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: device_record" . "\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 body_report_brief(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->body_report_brief_action($data);
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: body_report_brief" . "\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 body_report_detailed(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->body_report_detailed_action($data);
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: body_report_detailed" . "\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 body_report_depth(){
+ $data = input('post.');
+ // try {
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->body_report_depth_action($data);
+ // } catch (\Exception $e) {
+ // // 捕获异常
+ // $logContent["flie"] = $e->getFile();
+ // $logContent["line"] = $e->getLine();
+ // $logContent['all_content'] = "异常信息:\n";
+ // $logContent['all_content'] .= "函数: body_report_detailed" . "\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 set_target_weight(){
+ $data = input('post.');
+ try {
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005,'weight type error');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+
+ $data['time'] = date('Y-m-d H:i:s');
+ return $this->set_target_weight_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "函数: set_target_weight" . "\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 set_initial_weight(){
+ $data = input('post.');
+ try {
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['weight'],'num')){
+ return $this->msg(10005,'weight type error');
+ }
+ if(!$this->verify_data_is_ok($data['time'],'datetime')){
+ return $this->msg(10005,'time type error');
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ return $this->set_initial_weight_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "函数: set_initial_weight" . "\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 history_list_page(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['page'],'intnum')){
+ return $this->msg(10005,'page type error');
+ }
+ return $this->history_list_page_action($data,'page');
+ } 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 history_detailed(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->history_detailed_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 历史记录删除
+ public function history_del(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['id'],'intnum')){
+ return $this->msg(10005,'id type error');
+ }
+ return $this->history_del_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+ // 曲线详情
+ public function curve_detailed(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
+ return $this->msg(10001);
+ }
+ if(!$this->verify_data_is_ok($data['token'],'str')){
+ return $this->msg(10005,'token type error');
+ }
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
+ return $this->msg(10005,'s_time type error');
+ }
+ if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
+ return $this->msg(10005,'e_time type error');
+ }
+ return $this->curve_detailed_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+
+ // 用户身体数据卡片记录
+ public function set_user_body_data($data,$type){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+
+ $db_data = [];
+ $db_data['create_time'] = date('Y-m-d H:i:s');
+ $db_data['aud_id'] = $data['aud_id'];
+ $db_data['record_time'] = $data['time'];
+ $db_data['height'] = $data['height'];
+ $db_data['weight'] = $data['weight'];
+
+ $db_data['create_time'] = date('Y-m-d H:i:s');
+ // 查询用户信息
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('birthday,gender,target_weight,initial_weight,initial_date')->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+ // 如果最初体重设置为null
+ if($user_data['initial_date'] == null){
+ Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
+ }
+ $db_data['age'] = $this->calculate_age($user_data['birthday']);
+
+ // 设置发送数据:身高、体重、年龄、性别、头围、生日、阻抗
+ $send_data['height'] = $data['height'];
+ $send_data['weight'] = $data['weight'];
+ $send_data['age'] = $db_data['age'];
+ $send_data['gender'] = $user_data['gender'];
+ $send_data['birthDay'] = $user_data['birthday'];
+
+
+ // 1、手动记录还是设备记录
+ if($type == 'by_hand_means'){
+ $db_data['record_type'] = 'by_hand_means';
+ // 判断头围数据是否存在是否合理
+ if(array_key_exists('head_data', $data)){
+ if(!$this->verify_data_is_ok($data['head_data'],'num')){
+ return $this->msg(10005);
+ }
+ $db_data['head_circumference'] = $data['head_data'];
+ $send_data['head'] = $data['head_data'];
+ }else{
+ $send_data['head'] = $data['head_data'];
+ }
+
+ $send_data['adc'] = 550;
+ // 发送请求获取照良那边的身体数据
+ $get_body_value = $this->send_body_data($send_data,'4_electrode');
+ if($get_body_value === false){
+ return $this->msg(10002);
+ }
+
+ // 开始设置数据
+ $db_data['bmi'] = $get_body_value['bmi'];
+ $db_data['score'] = $get_body_value['cmi'];
+ $db_data['fat_r'] = $get_body_value['bfr'];
+ $db_data['fat_w'] = $get_body_value['bfrval'];
+ $db_data['muscle'] = $get_body_value['rom'];
+ $db_data['muscleval'] = $get_body_value['romval'];
+ $db_data['water'] = $get_body_value['vwc'];
+ $db_data['protein'] = $get_body_value['pp'];
+ $db_data['proteinval'] = $get_body_value['ppval'];
+ $db_data['bone'] = $get_body_value['bm'];
+ $db_data['kcal'] = $get_body_value['bmr'];
+ $db_data['visceral'] = $get_body_value['uvi'];
+ $db_data['sfr'] = $get_body_value['sfr'];
+ $db_data['body_level'] = $get_body_value['fatlevelname'];//肥胖等级
+ $db_data['body_type'] = $get_body_value['body'];//身体类型
+ $db_data['body_age'] = $get_body_value['bodyage'];
+ // 如果年纪小于三岁,处理头围数据star
+ $standardlist = [];
+
+ if($send_data['age'] < 3){
+ if(array_key_exists('standardlist',$get_body_value)){
+ $standardlist = $get_body_value['standardlist'];
+ foreach ($standardlist as $key => $value) {
+ if($value['name'] == 'head' && count($value['list'] ) > 0){
+ $standardlist = $value;
+ }
+ }
+ $standardlist['list2'] = [];
+ foreach ($standardlist['list'] as $key => $value) {
+ array_push($standardlist['list2'],[
+ 'min_val'=>$value['minvalue'],
+ 'max_val'=>$value['maxvalue'],
+ 'text'=>$value['text'],
+ 'color'=>$value['color']
+ ]);
+ }
+ unset($standardlist['list']);
+ unset($get_body_value['standardlist']);
+ $db_data['head_circumference_val'] = $db_data['head_circumference'];
+ $db_data['head_circumference'] = json_encode($standardlist);
+ }
+ }else{
+ if(array_key_exists('standardlist',$get_body_value)){
+ unset($get_body_value['standardlist']);
+ }
+ $db_data['head_circumference_val'] = null;
+ $db_data['head_circumference'] = null;
+ }
+ // 如果年纪小于三岁,处理头围数据end
+
+ }else{
+ // 如果原始数据存在阻抗
+ if(array_key_exists('adc', $data)){
+ if(!$this->verify_data_is_ok($data['adc'],'num')){
+ return $this->msg(10005);
+ }
+ if($data['adc'] > 0){
+ // 如果阻抗大于0,那就使用传过来的阻抗
+ $send_data['adc'] = $data['adc'];
+ $db_data['record_type'] = 'by_device_adc';
+ }else{
+ $send_data['adc'] = 550;
+ $db_data['record_type'] = 'by_device';
+ }
+ }else{
+ $send_data['adc'] = 550;
+ $db_data['record_type'] = 'by_device';
+ // return $this->msg(10001);
+ }
+ if(array_key_exists('lefthand', $data) && array_key_exists('righthand', $data) && array_key_exists('leftfoot', $data) && array_key_exists('rightfoot', $data)){
+ // 发送请求获取照良那边的身体数据
+ $send_data['lefthand'] = $data['lefthand'];
+ $send_data['righthand'] = $data['righthand'];
+ $send_data['leftfoot'] = $data['leftfoot'];
+ $send_data['rightfoot'] = $data['rightfoot'];
+ $get_body_value = $this->send_body_data($send_data,'8_electrode');
+ // 开始设置数据
+ $db_data['bmi'] = $get_body_value['bmi'];
+ $db_data['score'] = $get_body_value['cmi'];
+ $db_data['fat_r'] = $get_body_value['fat_r'];
+ $db_data['fat_w'] = $get_body_value['fat_w'];
+ $db_data['muscle'] = $get_body_value['muscle'];
+ $db_data['muscleval'] = $get_body_value['muscleval'];
+ $db_data['water'] = $get_body_value['water'];
+ $db_data['protein'] = $get_body_value['protein'];
+ $db_data['proteinval'] = $get_body_value['proteinval'];
+ $db_data['bone'] = $get_body_value['bone'];
+ $db_data['kcal'] = $get_body_value['kcal'];
+ $db_data['visceral'] = $get_body_value['visceral'];
+ $db_data['sfr'] = $get_body_value['sfr'];
+ $db_data['body_level'] = $get_body_value['fatlevel'];//肥胖等级
+ $db_data['body_type'] = $get_body_value['body'];//身体类型
+ $db_data['body_age'] = $get_body_value['bodyage'];
+ $db_data['8_electrode_data'] = json_encode($get_body_value);
+ }else{
+ // 判断头围数据是否存在是否合理
+ if(array_key_exists('head_data', $data)){
+ if(!$this->verify_data_is_ok($data['head_data'],'num')){
+ return $this->msg(10005);
+ }
+ $db_data['head_circumference'] = $data['head_data'];
+ $send_data['head'] = $data['head_data'];
+ }else{
+ $send_data['head'] = 0;
+ }
+
+
+ // 发送请求获取照良那边的身体数据
+ $get_body_value = $this->send_body_data($send_data,'4_electrode');
+ // 开始设置数据
+ $db_data['bmi'] = $get_body_value['bmi'];
+ $db_data['score'] = $get_body_value['cmi'];
+ $db_data['fat_r'] = $get_body_value['bfr'];
+ $db_data['fat_w'] = $get_body_value['bfrval'];
+ $db_data['muscle'] = $get_body_value['rom'];
+ $db_data['muscleval'] = $get_body_value['romval'];
+ $db_data['water'] = $get_body_value['vwc'];
+ $db_data['protein'] = $get_body_value['pp'];
+ $db_data['proteinval'] = $get_body_value['ppval'];
+ $db_data['bone'] = $get_body_value['bm'];
+ $db_data['kcal'] = $get_body_value['bmr'];
+ $db_data['visceral'] = $get_body_value['uvi'];
+ $db_data['sfr'] = $get_body_value['sfr'];
+ $db_data['body_level'] = $get_body_value['fatlevelname'];//肥胖等级
+ $db_data['body_type'] = $get_body_value['body'];//身体类型
+ $db_data['body_age'] = $get_body_value['bodyage'];
+ $db_data['4_electrode_data'] = json_encode($get_body_value);
+
+ // 如果年纪小于三岁,处理头围数据star
+ $standardlist = [];
+
+ if($send_data['age'] < 3 && $send_data['head'] > 0){
+ if(array_key_exists('standardlist',$get_body_value)){
+ $standardlist = $get_body_value['standardlist'];
+ foreach ($standardlist as $key => $value) {
+ if($value['name'] == 'head' && count($value['list'] ) > 0){
+ $standardlist = $value;
+ }
+ }
+ $standardlist['list2'] = [];
+ foreach ($standardlist['list'] as $key => $value) {
+ array_push($standardlist['list2'],[
+ 'min_val'=>$value['minvalue'],
+ 'max_val'=>$value['maxvalue'],
+ 'text'=>$value['text'],
+ 'color'=>$value['color']
+ ]);
+ }
+ unset($standardlist['list']);
+ unset($get_body_value['standardlist']);
+ $db_data['head_circumference_val'] = $db_data['head_circumference'];
+ $db_data['head_circumference'] = json_encode($standardlist);
+ }
+ }else{
+ if(array_key_exists('standardlist',$get_body_value)){
+ unset($get_body_value['standardlist']);
+ }
+ }
+ // 如果年纪小于三岁,处理头围数据end
+
+ }
+ if($get_body_value === false){
+ return $this->msg(10002);
+ }
+ // dump($get_body_value);
+
+
+ // 处理心率start
+ if(array_key_exists('heart_rate', $data)){
+ if(!$this->verify_data_is_ok($data['heart_rate'],'num')){
+ return $this->msg(10005,'心率数据格式错误');
+ }
+ $db_data['heart_rate'] = $data['heart_rate'];
+ }
+ // 处理心率end
+ }
+
+
+ // 启动事务
+ Db::startTrans();
+ try{
+ Db::table($this->body_db_name['body_data_new'])->insert($db_data);
+ $update_arr = [
+ 'height'=>$db_data['height'],
+ 'weight'=>$db_data['weight']
+ ];
+ Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update($update_arr);
+ // 提交事务
+ Db::commit();
+ return $this->msg([]);
+ } catch (\Exception $e) {
+ // 回滚事务
+ Db::rollback();
+ return $this->msg(10002);
+ }
+
+
+
+ }
+ public function body_report_brief_action($data){
+ $result_return = [
+ 'top_list'=>[
+ [
+ "name"=>$this->merged_data['weight']['name'],
+ 'time'=>'',
+ "value"=>"0",
+ "unit"=>$this->merged_data['weight']['unit'],
+ "standard"=>"",
+ "standard_color"=>"#000000",
+ 'target_weight'=>'0',
+ 'target_weight_unit'=>'kg',
+ 'bk_color'=>'#fffae4',
+ 'curve_list'=>[
+ 'title'=>'体重',
+ 'key'=>'weight',
+ 'line'=>['categories'=>[],'series'=>[['color'=>'#f78814','data'=>[]]]],
+ ],
+ 'ideal_weight'=>'',
+ ],
+ [
+ "name"=>$this->merged_data['height']['name'],
+ 'time'=>'',
+ "value"=>"0",
+ "unit"=>$this->merged_data['height']['unit'],
+ "standard"=>"",
+ "standard_color"=>"#000000",
+ 'bk_color'=>'#f6eefd',
+ 'curve_list'=>[
+ 'title'=>'身高',
+ 'key'=>'height',
+ 'line'=>['categories'=>[],'series'=>[['color'=>'#dab8f4','data'=>[]]]],
+ ],
+ 'ideal_height'=>'',
+ ],
+ [
+ "name"=>$this->merged_data['bmi']['name'],
+ 'time'=>'',
+ "value"=>"0",
+ "unit"=>$this->merged_data['bmi']['unit'],
+ "standard"=>"",
+ "standard_color"=>"#000000",
+ 'bk_color'=>'#edf8fe',
+ 'curve_list'=>[
+ 'title'=>'BMI',
+ 'key'=>'bmi',
+ 'line'=>['categories'=>[],'series'=>[['color'=>'#a8def6','data'=>[]]]],
+ ],
+ 'ideal_bmi'=>'',
+ ],
+ ],
+ 'card_list'=>[
+ ],
+ ];
+
+ $user_data = Db::table($this->body_db_name['juese'])
+ ->where(['id'=>$data['aud_id'],'is_del'=>0])
+ ->field('birthday,gender,target_weight,initial_weight,initial_date,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+
+ $body_last_data = Db::table($this->body_db_name['body_data_new'])
+ ->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
+ ->order('record_time desc,id desc')
+ ->find();
+
+
+ // 设置卡片顺序
+ $set_order = [
+ // 'ideal_weight', //体脂率
+ // 'ideal_height', //体脂率
+ // 'ideal_bmi', //体脂率
+ 'fat_r', //体脂率
+ 'fat_w', //脂肪量
+ 'muscle', //肌肉率
+ 'muscleval', //肌肉量
+ 'protein', //蛋白率
+ 'proteinval', //蛋白量
+ 'water', //水分
+ 'sfr', //皮下脂肪
+ 'body_level', //肥胖等级☆
+ 'visceral', //内脏指数
+ 'bone', //骨重
+ 'body_type', //身体类型☆
+ 'score', //身体得分☆
+ 'body_age', //身体年龄☆
+ ];
+ if(!$body_last_data){
+ foreach ($set_order as $key => $value) {
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>'--',
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>$value,
+ ];
+ }
+ return $this->msg($result_return);
+ }
+
+ $body_last_data_3_list = Db::table($this->body_db_name['body_data_new'])
+ ->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
+ ->order('record_time desc,id desc')
+ ->field('id,weight,height,bmi,record_time')
+ ->page('1,5')
+ ->select();
+
+
+
+
+ $record_time = substr($body_last_data['record_time'], 11, 5);
+ // 处理体重
+ $result_return['top_list'][0]['time'] = $record_time;
+ $result_return['top_list'][0]['value'] = floatval($body_last_data['weight']);
+ $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][0]['value'],'weight',$user_data);
+ $result_return['top_list'][0]['standard'] = $temporary_standard_color[1];
+ $result_return['top_list'][0]['standard_color'] = $temporary_standard_color[2];
+ $result_return['top_list'][0]['target_weight'] = $user_data['target_weight'];
+ $result_return['top_list'][0]['key_name'] = 'weight';
+ foreach ($body_last_data_3_list as $key => $value) {
+ $result_return['top_list'][0]['curve_list']['line']['categories'][] = $value['record_time'];
+ $result_return['top_list'][0]['curve_list']['line']['series'][0]['data'][] = floatval($value['weight']);
+ $result_return['top_list'][1]['curve_list']['line']['categories'][] = $value['record_time'];
+ $result_return['top_list'][1]['curve_list']['line']['series'][0]['data'][] = floatval($value['height']);
+ $result_return['top_list'][2]['curve_list']['line']['categories'][] = $value['record_time'];
+ $result_return['top_list'][2]['curve_list']['line']['series'][0]['data'][] = floatval($value['bmi']);
+ }
+ $user_data['weight'] = $result_return['top_list'][0]['value'];
+ // 处理身高
+ $result_return['top_list'][1]['time'] = $record_time;
+ $result_return['top_list'][1]['value'] = floatval($body_last_data['height']);
+ $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][1]['value'],'height',$user_data);
+ $result_return['top_list'][1]['standard'] = $temporary_standard_color[1];
+ $result_return['top_list'][1]['standard_color'] = $temporary_standard_color[2];
+ $result_return['top_list'][1]['key_name'] = 'height';
+
+ // 处理BMI
+ $result_return['top_list'][2]['time'] = $record_time;
+ $result_return['top_list'][2]['value'] = floatval($body_last_data['bmi']);
+ $temporary_standard_color = $this->judgment_standard_color($result_return['top_list'][2]['value'],'bmi',$user_data);
+ $result_return['top_list'][2]['standard'] = $temporary_standard_color[1];
+ $result_return['top_list'][2]['standard_color'] = $temporary_standard_color[2];
+ $result_return['top_list'][2]['key_name'] = 'bmi';
+ // 如果有头围
+ if($body_last_data['head_circumference']){
+ $temporary_head_circumference = json_decode($body_last_data['head_circumference'],true);
+ $body_last_data_head_circumference_list = Db::table($this->body_db_name['body_data_new'])
+ ->where("is_del = 0 AND aud_id = ".$data['aud_id']." AND head_circumference IS NOT NULL")
+ ->order('record_time desc,id desc')
+ ->field('id,head_circumference,record_time')
+ ->page('1,5')
+ ->select();
+ $head_circumference_curve_list = [
+ 'title'=>'头围',
+ 'key'=>'head_circumference',
+ 'line'=>['categories'=>[],'series'=>[['color'=>'#55d87b','data'=>[]]]],
+ ];
+ foreach ($body_last_data_head_circumference_list as $key => $value) {
+ $head_circumference_curve_list['line']['categories'][] = $value['record_time'];
+ $head_circumference_curve_list['line']['series'][0]['data'][] = floatval($value['head_circumference']);
+ }
+ $result_return['top_list'][] = [
+ "name"=>$this->merged_data['head_circumference']['name'],
+ 'time' => $record_time,
+ 'value' => $temporary_head_circumference['value']?$temporary_head_circumference['value']:0,
+ "unit"=>$this->merged_data['head_circumference']['unit'],
+ 'standard' => $temporary_head_circumference['level']?$temporary_head_circumference['level']:0,
+ 'standard_color' => $temporary_head_circumference['color']?$temporary_head_circumference['color']:0,
+ 'bk_color'=>'#ddfaef',
+ 'curve_list' => $head_circumference_curve_list,
+ 'ideal_head_circumference' => '',
+ ];
+ }
+ // 如果有心率
+ if($body_last_data['heart_rate']){
+ $temporary_standard_color = $this->judgment_standard_color(floatval($body_last_data['heart_rate']),'heart_rate',$user_data);
+ $body_last_data_heart_rate_list = Db::table($this->body_db_name['body_data_new'])
+ ->where("is_del = 0 AND aud_id = ".$data['aud_id']." AND heart_rate IS NOT NULL")
+ ->order('record_time desc,id desc')
+ ->field('id,heart_rate,record_time')
+ ->page('1,5')
+ ->select();
+ $heart_rate_curve_list = [
+ 'title'=>'心率',
+ 'key'=>'heart_rate',
+ 'line'=>['categories'=>[],'series'=>[['color'=>'#fb8587','data'=>[]]]],
+ ];
+ foreach ($body_last_data_heart_rate_list as $key => $value) {
+ $heart_rate_curve_list['line']['categories'][] = $value['record_time'];
+ $heart_rate_curve_list['line']['series'][0]['data'][] = floatval($value['heart_rate']);
+ }
+ $result_return['top_list'][] = [
+ "name"=>$this->merged_data['heart_rate']['name'],
+ 'time' => $record_time,
+ 'value' => floatval($body_last_data['heart_rate']),
+ "unit"=>$this->merged_data['heart_rate']['unit'],
+ 'standard' => $temporary_standard_color[1],
+ 'standard_color' => $temporary_standard_color[2],
+ 'key_name' => 'heart_rate',
+ 'bk_color'=>'#fbeeee',
+ 'curve_list' => $heart_rate_curve_list,
+ 'ideal_heart_rate' => $temporary_standard_color[3],
+ ];
+ }
+ // // 设置卡片顺序
+ // $set_order = [
+ // // 'ideal_weight', //体脂率
+ // // 'ideal_height', //体脂率
+ // // 'ideal_bmi', //体脂率
+ // 'fat_r', //体脂率
+ // 'fat_w', //脂肪量
+ // 'muscle', //肌肉率
+ // 'muscleval', //肌肉量
+ // 'protein', //蛋白率
+ // 'proteinval', //蛋白量
+ // 'water', //水分
+ // 'sfr', //皮下脂肪
+ // 'body_level', //肥胖等级☆
+ // 'visceral', //内脏指数
+ // 'bone', //骨重
+ // 'body_type', //身体类型☆
+ // 'score', //身体得分☆
+ // 'body_age', //身体年龄☆
+ // ];
+ // 处理卡片数据
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ foreach ($set_order as $key => $value) {
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>'--',
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>$value,
+ ];
+ }
+ return $this->msg($result_return);
+ }else{
+ $temporary_three = [];
+ foreach ($set_order as $key => $value) {
+
+ if($value == 'body_level' || $value == 'body_type' || $value == 'body_age'){
+ // 如果是特殊数据
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>$value == 'body_age'?floatval($body_last_data[$value]):$body_last_data[$value],
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>$value,
+ ];
+ }else{
+ if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
+ $temporary_standard_color = $this->judgment_standard_color('none',$value,$user_data);
+ // dump($temporary_standard_color);
+ if($temporary_standard_color){
+
+ if($value == 'ideal_weight'){
+ // dump($temporary_standard_color);
+ // die;
+ $result_return['top_list'][0]['ideal_weight'] = $temporary_standard_color;
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>$temporary_standard_color,
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>$value,
+ ];
+ }else if($value == 'ideal_height'){
+ $result_return['top_list'][1]['ideal_height'] = $temporary_standard_color;
+ }else if($value == 'ideal_bmi'){
+ $result_return['top_list'][2]['ideal_bmi'] = $temporary_standard_color;
+ }
+ }
+
+ }else{
+
+ if($value == 'fat_w' || $value == 'muscleval' || $value == 'proteinval'){
+ $temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>floatval($body_last_data[$value]),
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>$temporary_standard_color[0],
+ 'standard_color'=>$temporary_standard_color[1],
+ 'key_name'=>$value,
+ ];
+ }else if($value == 'score'){
+ $temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>floatval($temporary_standard_color[0]),
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>$temporary_standard_color[1],
+ 'standard_color'=>$temporary_standard_color[2],
+ 'key_name'=>$value,
+ ];
+ }else{
+ // dump($value);
+
+ $temporary_standard_color = $this->judgment_standard_color($body_last_data[$value],$value,$user_data);
+ // dump($temporary_standard_color);
+ if($temporary_standard_color){
+
+ $result_return['card_list'][] = [
+ 'name'=>$this->merged_data[$value]['name'],
+ 'icon'=>$this->merged_data[$value]['icon'],
+ 'value'=>floatval($body_last_data[$value]),
+ 'unit'=>$this->merged_data[$value]['unit'],
+ 'standard'=>$temporary_standard_color[0],
+ 'standard_color'=>$temporary_standard_color[1],
+ 'key_name'=>$value,
+ ];
+ }
+ }
+ }
+
+ }
+ }
+ }
+ $result_return['card_list'][] = [
+ 'name'=>'建议卡路里摄入量',
+ 'icon'=>'https://tc.pcxbc.com/new_reedaw/icon/suggestion_kcal.png',
+ 'value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal'],
+ 'unit'=>'kcal',
+ 'standard'=>'',
+ 'standard_color'=>'',
+ 'key_name'=>'suggestion_kcal',
+ ];
+
+ return $this->msg($result_return);
+ }
+ public function body_report_detailed_action($data){
+
+ $result_return = [];
+
+ $user_data = Db::table($this->body_db_name['juese'])
+ ->where(['id'=>$data['aud_id'],'is_del'=>0])
+ ->field('birthday,gender,target_weight,initial_weight,initial_date,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+
+ $body_last_data = Db::table($this->body_db_name['body_data_new'])
+ ->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
+ ->order('record_time desc,id desc')
+ ->find();
+
+ if(!$body_last_data){
+ $result_return = [
+ [
+ 'name' => '体重',
+ 'unit' => 'kg',
+ 'description' => '体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。',
+ 'smart_tip_description' => '保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'weight',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身高',
+ 'unit' => 'cm',
+ 'description' => '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/height.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'height',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => 'BMR',
+ 'unit' => 'kcal',
+ 'description' => 'BMR是基础代谢率(BasalMetabolicRate)的缩写,指人体在安静状态下,维持基本生命活动所需的最低能量消耗率。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/ideal_bmi.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'kcal',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => 'BMI',
+ 'unit' => '',
+ 'description' => 'BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi10.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'bmi',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '脂肪率',
+ 'unit' => '%',
+ 'description' => '体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_r.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'fat_r',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '脂肪量',
+ 'unit' => 'kg',
+ 'description' => '脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_w.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'fat_w',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肌肉率',
+ 'unit' => '%',
+ 'description' => '肌肉率指人体成分中肌肉占体重的百分比。肌肉率越高,BMR越大,消耗的热量越多,就不容易发胖。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscle.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'muscle',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肌肉量',
+ 'unit' => 'kg',
+ 'description' => '肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscleval.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'muscleval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '蛋白率',
+ 'unit' => '%',
+ 'description' => '蛋白质率指人体组织中蛋白质含量占总体重的百分比。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/protein.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'protein',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '蛋白量',
+ 'unit' => 'kg',
+ 'description' => '',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/proteinval.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'proteinval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '水分',
+ 'unit' => '%',
+ 'description' => '体水分率指人体组织中的水分占总体重的百分比,也称为身体水分含量。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/water.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'water',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '皮下脂肪',
+ 'unit' => '%',
+ 'description' => '皮下脂肪率指身体内皮下脂肪组织占身体总重量的百分比。皮下脂肪适量时对身体有益,但过量会使身体处于肥胖状态,并可能导致多种健康问题。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/sfr.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'sfr',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '内脏指数',
+ 'unit' => '',
+ 'description' => '内脏脂肪指围绕脏器的脂肪组织,主要分布于腹腔内,包括肝脏、心脏、肾脏、胰腺等器官周围的脂肪。身体内脏脂肪的增加会导致慢性代谢性疾病的风险增加。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/visceral.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'visceral',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '骨重',
+ 'unit' => 'kg',
+ 'description' => '身体骨量指人体骨骼所含的骨基质和矿物质的质量。骨量的大小直接影响骨骼健康,对身体的稳定性和功能起着至关重要的作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bone.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'bone',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '肥胖等级',
+ 'unit' => '',
+ 'description' => '肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_level.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_level',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身体年龄',
+ 'unit' => '岁',
+ 'description' => '身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_age.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_age',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ [
+ 'name' => '身体得分',
+ 'unit' => '分',
+ 'description' => '',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/score.png',
+ 'standard_list' => [],
+ 'key_name' => 'score',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0,
+ ],
+ ];
+ return $this->msg($result_return);
+ }
+ $user_data['weight'] = $body_last_data['weight'];
+ $set_order = [
+ 'weight', //体重
+ 'height', //身高
+ 'heart_rate', //心率
+ 'head_circumference', //头围
+ 'kcal', //BMR 静态基础代谢
+ 'bmi', //BMI
+ 'fat_r', //体脂率
+ 'fat_w', //脂肪量
+ 'muscle', //肌肉率
+ 'muscleval', //肌肉量
+ 'protein', //蛋白率
+ 'proteinval', //蛋白量
+ 'water', //水分
+ 'sfr', //皮下脂肪
+ // '', //骨骼肌率
+ // '', //骨路肌量
+ 'visceral', //内脏指数
+ // '', //肌肉控制量
+ // '', //脂筋控制量
+ 'ideal_weight', //理想体重
+ 'ideal_height', //理想身高
+ 'ideal_bmi', //理想bmi
+ // '', //去脂体重
+ // '', //控制体量
+ 'bone', //骨重
+ 'body_type', //身体类型☆
+ 'body_level', //肥胖等级☆
+ // '', //健康评价
+ 'body_age', //身体年龄☆
+ 'score', //身体得分☆
+ ];
+
+ foreach ($set_order as $key => $value) {
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ if($value == 'weight' || $value == 'height' || $value == 'bmi' || $value == 'head_circumference'){
+
+ $temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
+ if($temporary_data_list){
+ $result_return[] = $temporary_data_list;
+ }
+ }else{
+
+ if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
+ $temporary_data_list = $this->judgment_standard_color_detailed(null,$value,$user_data);
+ if($temporary_data_list){
+ $temporary_data_list['value'] = '--';
+ if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
+ $temporary_data_list['offset'] = 0;
+ }
+ $result_return[] = $temporary_data_list;
+ }
+ }else if($value == 'body_type'){
+ $temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
+ if($temporary_data_list){
+ $temporary_data_list['l_line_color'] = ['name'=>'体脂率','standard_list'=>[['name'=>'偏低','color'=>'#EAAE29'],['name'=>'标准、偏高','color'=>'#0AD2B0'],['name'=>'过高、超高','color'=>'#F83F29']]];
+ $temporary_data_list['r_line_color'] = ['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#159383']]];
+ $temporary_data_list['box_list'] = ['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'];
+ $temporary_data_list['value'] = '--';
+ if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
+ $temporary_data_list['offset'] = 0;
+ }
+ $result_return[] = $temporary_data_list;
+ }
+ }else{
+ $temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
+ if($temporary_data_list){
+ $temporary_data_list['value'] = '--';
+ if(array_key_exists('offset',$temporary_data_list) && $temporary_data_list['offset']){
+ $temporary_data_list['offset'] = 0;
+ }
+ $result_return[] = $temporary_data_list;
+ }
+ }
+ }
+ }else{
+ if($value == 'ideal_weight' || $value == 'ideal_height' || $value == 'ideal_bmi'){
+ $temporary_data_list = $this->judgment_standard_color_detailed(null,$value,$user_data);
+ if($temporary_data_list){
+ $result_return[] = $temporary_data_list;
+ }
+ }else if($value == 'body_type'){
+ $temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
+ if($temporary_data_list){
+ $temporary_data_list['l_line_color'] = ['name'=>'体脂率','standard_list'=>[['name'=>'偏低','color'=>'#EAAE29'],['name'=>'标准、偏高','color'=>'#0AD2B0'],['name'=>'过高、超高','color'=>'#F83F29']]];
+ $temporary_data_list['r_line_color'] = ['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#159383']]];
+ $temporary_data_list['box_list'] = ['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'];
+ $result_return[] = $temporary_data_list;
+ }
+ }else{
+ $temporary_data_list = $this->judgment_standard_color_detailed($body_last_data[$value],$value,$user_data);
+ if($temporary_data_list){
+ $result_return[] = $temporary_data_list;
+ }
+ }
+ }
+ }
+
+ if($body_last_data['record_type'] != 'by_device_adc'){
+ foreach ($result_return as $key => $value) {
+ if(!in_array($value['name'],['体重','身高','BMI'])){
+ $result_return[$key]['standard'] = '';
+ $result_return[$key]['standard_color'] = '';
+ }
+ }
+ }
+
+
+ $result_return[] = [
+ 'name' => '建议卡路里摄入量',
+ 'unit' => 'kcal',
+ 'description' => '根据BMR配合运动系数,大致估算的每日建议摄入的卡路里量',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/suggestion_kcal.png',
+ 'list' => [],
+ 'standard_list' => [],
+ 'key_name' => 'body_level',
+ 'value' => $this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal'],
+ 'standard' => '',
+ 'standard_color' => '',
+ 'offset' => 0
+ ];
+
+
+ return $this->msg($result_return);
+
+ }
+ public function body_report_depth_action($data){
+
+ $result_return = [];
+
+ $user_data = Db::table($this->body_db_name['juese'])
+ ->where(['id'=>$data['aud_id'],'is_del'=>0])
+ ->field('nickname,head_pic,birthday,gender,target_weight,initial_weight,initial_date,activity_level')
+ ->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+
+ $body_last_data = Db::table($this->body_db_name['body_data_new'])
+ ->where(['is_del'=>0,'aud_id'=>$data['aud_id']])
+ ->order('record_time desc,id desc')
+ ->find();
+
+ if(!$body_last_data){
+ $result_return = array(
+ 'user_data' => array(
+ 'title_name' => '',
+ 'nickname' => $user_data['nickname'],
+ 'head_pic' => $user_data['head_pic'],
+ 'gender' => $user_data['gender'],
+ 'record_time' => '',
+ 'age' => $this->calculate_age($user_data['birthday']),
+ 'height' => 0,
+ 'weight' => 0,
+ 'score' => 0
+ ),
+ 'body_data' => array(
+ 'title_name' => '身体成分分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/body_data.png',
+ 'title' => '体重',
+ 'standard' => '',
+ 'description' => '*总体重=体水分量+蛋白质量+脂肪量+其他',
+ 'list' => array(
+ array(
+ 'color' => '#3E7AF6',
+ 'name' => '体水分量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#FFB119',
+ 'name' => '蛋白质量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#31D4F5',
+ 'name' => '脂肪量',
+ 'scope' => '',
+ 'value' => '--',
+ 'offset' => '0'
+ ),
+ array(
+ 'color' => '#999999',
+ 'name' => '其他',
+ 'scope' => '',
+ 'value' => '',
+ 'offset' => '100'
+ )
+ ),
+ 'value' => 0,
+ 'unit' => 'kg'
+ ),
+ 'muscle_fat' => array(
+ 'title_name' => '肌肉脂肪分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png',
+ 'list' => array(
+ array(
+ 'name' => '体重',
+ 'unit' => 'kg',
+ 'description' => '体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。',
+ 'smart_tip_description' => '保持均衡营养的饮食,摄入足够的碳水化合物、蛋白质、脂肪等。适度进行运动,保持良好的生活习惯。',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'weight',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0
+ ),
+ array(
+ 'name' => '肌肉量',
+ 'unit' => 'kg',
+ 'description' => '肌肉量指人体所有肌肉的含量,包括水分量、骨骼肌、心肌和平滑肌等。肌肉是人体内的主要代谢组织之一,具有维持基础代谢率、提高身体稳定性、促进脂肪分解等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/muscleval.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'muscleval',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ ),
+ array(
+ 'name' => '脂肪量',
+ 'unit' => 'kg',
+ 'description' => '脂肪量指人体含有脂肪的总量。脂肪在身体中起着能量储存、保护内脏器官和维持体温等重要作用。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_w.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'fat_w',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ )
+ )
+ ),
+ 'fat_analysis' => array(
+ 'title_name' => '肥胖分析',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_analysis.png',
+ 'list' => array(
+ array(
+ 'name' => '脂肪率',
+ 'unit' => '%',
+ 'description' => '体脂率指人体中脂肪组织所占的百分比。体脂率是评估一个人身体脂肪含量和肥胖程度的指标。',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/fat_r.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'fat_r',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => '0'
+ ),
+ array(
+ 'name' => 'BMI',
+ 'unit' => '',
+ 'description' => 'BMI是身体质量指数(BodyMasslndex)的缩写,是一种常用的衡量人体肥胖程度的指标',
+ 'smart_tip_description' => '',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/bmi10.png',
+ 'list' => array(),
+ 'standard_list' => array(),
+ 'key_name' => 'bmi',
+ 'value' => '--',
+ 'standard' => '',
+ 'standard_color' => '#FFFFFF',
+ 'offset' => 0
+ )
+ )
+ ),
+ 'weight_controller' => array(
+ 'title_name' => '体重控制',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png',
+ 'list' => array(
+ array(
+ 'name' => '数据',
+ 'value' => '测量值'
+ ),
+ array(
+ 'name' => '标准体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '控制体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => 'BMR',
+ 'value' => '--',
+ )
+ )
+ ),
+ 'other_data' => array(
+ 'title_name' => '其他指标',
+ 'icon' => 'https://tc.pcxbc.com/new_reedaw/icon/other_data.png',
+ 'list' => array(
+ array(
+ 'name' => '项目',
+ 'value' => '测量值'
+ ),
+ array(
+ 'name' => '去脂体重',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '皮下脂肪量',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '身体年龄',
+ 'value' => '--',
+ ),
+ array(
+ 'name' => '内脏脂肪',
+ 'value' => '--',
+ )
+ )
+ )
+ );
+ return $this->msg($result_return);
+ }
+ if($body_last_data['8_electrode_data']){
+ $electrode_data_8 = json_decode($body_last_data['8_electrode_data'],true);
+ }else{
+ $electrode_data_8 = [];
+ }
+
+ $user_data['weight'] = $body_last_data['weight'];
+
+ $temporary_data_list_score = $this->judgment_standard_color_detailed($body_last_data['score'],'score',$user_data);
+
+ // 处理顶部用户信息板块
+ $result_return['user_data'] = [
+ // 'title_key'=>'user_data',
+ 'title_name'=>'',
+ 'nickname'=>$user_data['nickname'],
+ 'head_pic'=>$user_data['head_pic'],
+ 'gender'=>$user_data['gender'],
+ 'record_time'=>$body_last_data['record_time'],
+ 'age'=>$this->calculate_age($user_data['birthday']),
+ 'height'=>(float)$body_last_data['height'],
+ 'weight'=>(float)$body_last_data['weight'],
+ 'score'=>(float)$temporary_data_list_score?$temporary_data_list_score['value']:0,
+ ];
+
+ // 如果有心率处理心率板块
+ if($body_last_data['heart_rate']){
+ $temporary_data_list_heart_rate = $this->judgment_standard_color_detailed($body_last_data['heart_rate'],'heart_rate',$user_data);
+ $result_return['heart_rate'] = [
+ // 'title_key'=>'heart_rate',
+ 'title_name'=>'心脏健康',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/heart_rate.png",
+ 'value'=>"心率 ".$temporary_data_list_heart_rate['value'],
+ 'unit'=>$temporary_data_list_heart_rate['unit'],
+ 'standard'=>$temporary_data_list_heart_rate['standard'],
+ 'standard_color'=>$temporary_data_list_heart_rate['standard_color'],
+ 'standard_list'=>$temporary_data_list_heart_rate['standard_list'],
+ 'offset'=>$temporary_data_list_heart_rate['offset'],
+ ];
+ }
+
+ // 处理身体成分分析板块
+ $temporary_data_list_weight = $this->judgment_standard_color_detailed($body_last_data['weight'],'weight',$user_data);
+ $temporary_data_list_fat_w = $this->judgment_standard_color_detailed($body_last_data['fat_w'],'fat_w',$user_data);
+ $temporary_data_list_proteinval = $this->judgment_standard_color_detailed($body_last_data['proteinval'],'proteinval',$user_data);
+ $temporary_data_list_water = $this->judgment_standard_color_detailed($body_last_data['water'],'water',$user_data);
+ // 设置临时身体成分数据变量
+ $temporary_data_list = [];
+ // 体重获取标准信息以及标准描述
+ if(count($temporary_data_list_weight['standard_list'])){
+ foreach ($temporary_data_list_weight['standard_list'] as $key => $value) {
+ if($value['text'] == $temporary_data_list_weight['standard']){
+ $temporary_body_data['weight']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
+ $temporary_body_data['weight']['standard_str'] = $value['text'];
+ }
+ }
+ }else{
+ $temporary_body_data['weight']['standard_arr'] = '';
+ $temporary_body_data['weight']['standard_str'] = '';
+ }
+ // 脂肪量获取标准信息以及体重占比值
+ if(count($temporary_data_list_fat_w['standard_list'])){
+ foreach ($temporary_data_list_fat_w['standard_list'] as $key => $value) {
+ if($value['text'] == $temporary_data_list_fat_w['standard']){
+ $temporary_body_data['fat_w']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
+ $temporary_body_data['fat_w']['standard_str'] = bcdiv($body_last_data['fat_w'],$body_last_data['weight'],2);
+ }
+ }
+ }else{
+ $temporary_body_data['fat_w']['standard_arr'] = '';
+ $temporary_body_data['fat_w']['standard_str'] = bcdiv($body_last_data['fat_w'],$body_last_data['weight'],2);
+ }
+ // 蛋白量获取标准信息以及体重占比值
+ if(count($temporary_data_list_proteinval['standard_list'])){
+ foreach ($temporary_data_list_proteinval['standard_list'] as $key => $value) {
+ if($value['text'] == $temporary_data_list_proteinval['standard']){
+ $temporary_body_data['proteinval']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
+ $temporary_body_data['proteinval']['standard_str'] = bcdiv($body_last_data['proteinval'],$body_last_data['weight'],2);
+ }
+ }
+ }else{
+ $temporary_body_data['proteinval']['standard_arr'] = '';
+ $temporary_body_data['proteinval']['standard_str'] = bcdiv($body_last_data['proteinval'],$body_last_data['weight'],2);
+ }
+ // 水分获取标准信息以及体重占比值
+ if(count($temporary_data_list_water['standard_list'])){
+ foreach ($temporary_data_list_water['standard_list'] as $key => $value) {
+ if($value['text'] == $temporary_data_list_water['standard']){
+ $temporary_body_data['water']['standard_arr'] = "(".$value['min_val']."~".$value['max_val'].")";
+ $temporary_body_data['water']['standard_str'] = bcdiv($body_last_data['water'],$body_last_data['weight'],2);
+ }
+ }
+ }else{
+ $temporary_body_data['water']['standard_arr'] = '';
+ $temporary_body_data['water']['standard_str'] = bcdiv($body_last_data['water'],$body_last_data['weight'],2);
+ }
+ if($body_last_data['record_type'] != 'by_hand_means'){
+ $result_return['body_data'] = [
+ 'title_name'=>'身体成分分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
+ "title"=>"体重".$temporary_body_data['weight']['standard_arr'],
+ 'standard'=>$temporary_body_data['weight']['standard_str'] == ''?'':$temporary_body_data['weight']['standard_str'],
+ "description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
+ 'list'=>[
+ ['color'=>'#3E7AF6','name'=>'体水分量','scope'=>$temporary_body_data['water']['standard_arr'],'value'=>(float)$body_last_data['water'],'offset'=>$temporary_body_data['water']['standard_str']],
+ ['color'=>'#FFB119','name'=>'蛋白质量','scope'=>$temporary_body_data['proteinval']['standard_arr'],'value'=>(float)$body_last_data['proteinval'],'offset'=>$temporary_body_data['proteinval']['standard_str']],
+ ['color'=>'#31D4F5','name'=>'脂肪量','scope'=>$temporary_body_data['fat_w']['standard_arr'],'value'=>(float)$body_last_data['fat_w'],'offset'=>$temporary_body_data['fat_w']['standard_str']],
+ ['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'','offset'=>bcsub(bcsub(bcsub(100,$temporary_body_data['water']['standard_str'],20),$temporary_body_data['proteinval']['standard_str'],20),$temporary_body_data['fat_w']['standard_str'],2)],
+ ],
+ 'value'=>(float)$body_last_data['weight'],
+ 'unit'=>$temporary_data_list_weight['unit'],
+ ];
+ }else{
+ $result_return['body_data'] = [
+ 'title_name'=>'身体成分分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
+ "title"=>"体重",
+ 'standard'=>'',
+ "description"=>"*总体重=体水分量+蛋白质量+脂肪量+其他",
+ 'list'=>[
+ ['color'=>'#3E7AF6','name'=>'体水分量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#FFB119','name'=>'蛋白质量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#31D4F5','name'=>'脂肪量','scope'=>'(---)','value'=>'--','offset'=>0],
+ ['color'=>'#999999','name'=>'其他','scope'=>"",'value'=>'--','offset'=>100],
+ ],
+ 'value'=>(float)$body_last_data['weight'],
+ 'unit'=>$temporary_data_list_weight['unit'],
+ ];
+ }
+
+
+ // 处理肌肉脂肪分析
+ $temporary_data_list_muscleval = $this->judgment_standard_color_detailed($body_last_data['muscleval'],'muscleval',$user_data);
+ $result_return['muscle_fat'] = [
+ 'title_name'=>'肌肉脂肪分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/muscle_fat.png",
+ 'list'=>[],
+ ];
+ $result_return['muscle_fat']['list'][] = $temporary_data_list_weight;
+ $result_return['muscle_fat']['list'][] = $temporary_data_list_muscleval;
+ $result_return['muscle_fat']['list'][] = $temporary_data_list_fat_w;
+ foreach ($result_return['muscle_fat']['list'] as $key => $value) {
+ $result_return['muscle_fat']['list'][$key]['list'] = $value['standard_list'];
+ }
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ foreach ($result_return['muscle_fat']['list'] as $key => $value) {
+ if($value['name'] != '体重'){
+ $result_return['muscle_fat']['list'][$key]['offset'] = 0;
+ $result_return['muscle_fat']['list'][$key]['standard'] = '';
+ $result_return['muscle_fat']['list'][$key]['value'] = '--';
+ $result_return['muscle_fat']['list'][$key]['standard_color'] = '#FFFFFF';
+
+ }
+ }
+ }
+
+
+ // 处理节段脂肪分析(如果是8电极才有)
+ // return $this->msg($electrode_data_8);
+ if(count($electrode_data_8) > 0){
+ $result_return['segment_fat'] = [
+ // 'title_key'=>'segment_fat',
+ 'title_name'=>'节段脂肪分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat.png",
+ "bg_img"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat".$user_data['gender'].".png",
+ 'list'=>[
+ [
+ 'name'=>'L:',
+ 'value'=>$electrode_data_8['bodyfatkgleftarm'],//左手脂肪量,kg
+ 'unit'=>'kg',
+ 'value2'=>$electrode_data_8['bodyfatrateleftarm'],//左手脂肪率,%
+ 'unit2'=>'%',
+ ],
+ [
+ 'name'=>'R:',
+ 'value'=>$electrode_data_8['bodyfatkgrightarm'],//右手脂肪量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['bodyfatraterightarm'],//右手脂肪率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'B:',
+ 'value'=>$electrode_data_8['bodyfatkgtrunk'],//躯干脂肪量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['bodyfatraterunk'],//躯干脂肪率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'L:',
+ 'value'=>$electrode_data_8['bodyfatkgleftleg'],//左脚脂肪量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['bodyfatrateleftleg'],//左脚脂肪率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'R:',
+ 'value'=>$electrode_data_8['bodyfatkgrightleg'],//右脚脂肪量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['bodyfatraterightleg'],//右脚脂肪率,%
+ 'unit'=>'%',
+ ],
+ ],
+ ];
+
+ // 肌肉平衡
+ $result_return['segment_muscle'] = [
+ // 'title_key'=>'segment_muscle',
+ 'title_name'=>'肌肉平衡',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_muscle.png",
+ "bg_img"=>"https://tc.pcxbc.com/new_reedaw/icon/segment_fat".$user_data['gender'].".png",
+ 'list'=>[
+ [
+ 'name'=>'L:',
+ 'value'=>$electrode_data_8['musclekgleftarm'],//左手肌肉量,kg
+ 'unit'=>'kg',
+ 'value2'=>$electrode_data_8['musclerateleftarm'],//左手肌肉率,%
+ 'unit2'=>'%',
+ ],
+ [
+ 'name'=>'R:',
+ 'value'=>$electrode_data_8['musclekgrightarm'],//右手肌肉量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['muscleraterightarm'],//右手肌肉率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'B:',
+ 'value'=>$electrode_data_8['musclekgtrunk'],//躯干肌肉量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['muscleratetrunk'],//躯干肌肉率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'L:',
+ 'value'=>$electrode_data_8['musclekgleftleg'],//左脚肌肉量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['musclerateleftleg'],//左脚肌肉率,%
+ 'unit'=>'%',
+ ],
+ [
+ 'name'=>'R:',
+ 'value'=>$electrode_data_8['musclekgrightleg'],//右脚肌肉量,kg
+ 'unit'=>'kg',
+ 'value'=>$electrode_data_8['muscleraterightleg'],//右脚肌肉率,%
+ 'unit'=>'%',
+ ],
+ ],
+ ];
+ }
+
+
+
+ //处理肥胖分析
+ $temporary_data_list_fat_r = $this->judgment_standard_color_detailed($body_last_data['fat_r'],'fat_r',$user_data);
+ $temporary_data_list_bmi = $this->judgment_standard_color_detailed($body_last_data['bmi'],'bmi',$user_data);
+ // $temporary_data_list_muscleval = $this->judgment_standard_color_detailed($body_last_data['fat_r'],'fat_r',$user_data);
+ $result_return['fat_analysis'] = [
+ // 'title_key'=>'fat_analysis',
+ 'title_name'=>'肥胖分析',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/fat_analysis.png",
+ // "title"=>$temporary_body_data['weight'][0],
+ 'list'=>[],
+ ];
+ $result_return['fat_analysis']['list'][] = $temporary_data_list_fat_r;
+ $result_return['fat_analysis']['list'][] = $temporary_data_list_bmi;
+ foreach ($result_return['fat_analysis']['list'] as $key => $value) {
+ $result_return['fat_analysis']['list'][$key]['list'] = $value['standard_list'];
+ }
+ if($body_last_data['record_type'] == 'by_hand_means'){
+ foreach ($result_return['fat_analysis']['list'] as $key => $value) {
+ if($value['name'] != 'BMI'){
+ $result_return['fat_analysis']['list'][$key]['offset'] = 0;
+ $result_return['fat_analysis']['list'][$key]['standard'] = '';
+ $result_return['fat_analysis']['list'][$key]['value'] = '--';
+ $result_return['fat_analysis']['list'][$key]['standard_color'] = '#FFFFFF';
+
+ }
+ }
+ }
+
+
+ //体重控制
+ if($body_last_data['age'] <= 18){
+ $month_num = $this->calculateAgeInMonthsWithPrecision($user_data['birthday']);
+ // dump($month_num);
+ $standard_weight = Db::table($this->body_db_name['weight'])
+ ->where("Month <= $month_num AND Sex = ".$user_data['gender'])
+ ->order('Month desc')
+ ->field('id,median,Month')
+ ->find();
+ $user_BMR = $this->calculateBMR_BC($body_last_data['age'],$body_last_data['weight'],$user_data['gender']);
+ $result_return['weight_controller'] = [
+ // 'title_key'=>'weight_controller',
+ 'title_name'=>'体重控制',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png",
+ // "title"=>$temporary_body_data['weight'][0],
+ 'list'=>[
+ ['name'=>'数据','value'=>'测量值'],
+ ['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
+ ['name'=>'控制体重','value'=>bcsub($standard_weight['median'],$body_last_data['weight'],2).'kg'],
+ ['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
+ ['name'=>'建议摄入Kcal','value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal']],
+ ],
+ ];
+ }else{
+ $standard_weight = $this->calculateStandardWeight($user_data['gender'],$body_last_data['age'],$body_last_data['height']);
+ $user_BMR = $this->calculateBMR_BC($body_last_data['age'],$body_last_data['weight'],$user_data['gender']);
+ $result_return['weight_controller'] = [
+ 'title_name'=>'体重控制',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/weight_controller.png",
+ // "title"=>$temporary_body_data['weight'][0],
+ 'list'=>[
+ ['name'=>'数据','value'=>'测量值'],
+ ['name'=>'标准体重','value'=>(float)$standard_weight.'kg'],
+ ['name'=>'控制体重','value'=>bcsub($standard_weight,$body_last_data['weight'],2).'kg'],
+ ['name'=>'BMR','value'=>$user_BMR != false?$user_BMR:'异常'],
+ ['name'=>'建议摄入Kcal','value'=>$this->count_user_nutrition_all(['gender'=>$user_data['gender'],'weight'=>$body_last_data['weight'],'height'=>$body_last_data['height'],'age_num'=>$this->calculate_age($user_data['birthday']),'activity_level'=>$user_data['activity_level']])['kcal']],
+ ],
+ ];
+ }
+
+ //身体类型(这还是假数据,需要根据接口确认正确的box_list以及value)
+ $result_return['body_type'] = [
+ // 'title_key'=>'body_type',
+ 'title_name'=>'身体类型',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/body_data.png",
+ // "title"=>$temporary_body_data['weight'][0],
+ 'l_line_color'=>['name'=>'脂肪率','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'偏高','color'=>'#dc0225']]],
+ 'r_line_color'=>['name'=>'肌肉量','standard_list'=>[['name'=>'偏低','color'=>'#4db4ec'],['name'=>'标准','color'=>'#8bcc4c'],['name'=>'优秀','color'=>'#299744']]],
+ 'box_list'=>['浮肿肥胖型','偏胖肌肉型','肌肉型偏胖','缺乏运动型','标准型','标准肌肉型','偏瘦型','偏瘦肌肉型','肌肉发达型'],
+ 'value'=>$body_last_data['body_type'],
+ ];
+
+ //其他指标
+ $result_return['other_data'] = [
+ // 'title_key'=>'other_data',
+ 'title_name'=>'其他指标',
+ "icon"=>"https://tc.pcxbc.com/new_reedaw/icon/other_data.png",
+ // "title"=>$temporary_body_data['weight'][0],
+ 'list'=>[
+ ['name'=>'项目','value'=>'测量值'],
+ ['name'=>'去脂体重','value'=>$body_last_data['record_type'] != 'by_hand_means'?bcsub($body_last_data['weight'],$body_last_data['fat_w'],2).'kg':'--'],
+ ['name'=>'皮下脂肪量','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['sfr'].'kg':'--'],
+ ['name'=>'身体年龄','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['body_age']:'--'],
+ ['name'=>'内脏脂肪','value'=>$body_last_data['record_type'] != 'by_hand_means'?(float)$body_last_data['visceral']:'--'],
+ ],
+ ];
+
+
+
+
+ return $this->msg($result_return);
+ }
+ public function set_target_weight_action($data){
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['target_weight'=>$data['weight']]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function set_initial_weight_action($data){
+ $data['time'] = $data['time'].' '.date('H:i:s');
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]);
+ if($user_data){
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function history_list_page_action($data,$type){
+ $return_result = [];
+ $result = Db::table($this->body_db_name['body_data_new'])
+ ->where(['aud_id'=>$data['aud_id'],'is_del'=>0])
+ ->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height,weight,bmi")
+ ->order('record_time desc')
+ ->page($data['page'],$this->pagesize)
+ ->select();
+ $return_result['totalrows'] = Db::table($this->body_db_name['body_data_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->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($value['height']),
+ 'v2'=>floatval($value['weight']),
+ 'v3'=>floatval($value['bmi']),
+ 'v1_name'=>'身高',
+ 'v2_name'=>'体重',
+ 'v3_name'=>'BMI',
+ 'record_time'=>$value['b_time'],
+ ]);
+ }
+ return $this->msg($return_result);
+ }
+ public function history_detailed_action($data){
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 设置排除在外的数据类型start
+ $exclude_data_arr = ['height','weight','age','bmi'];
+ // 设置排除在外的数据类型end
+ $result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['id']])->find();
+ $for_data_arr = ['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'=>['体型','']];
+ if($result){
+ $result_data = [];
+ foreach ($for_data_arr as $key => $value) {
+
+ $temporary_arr['key_name'] = $key;
+ $temporary_arr['name'] = $value[0];
+ // 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr
+ if($result['record_type'] != 'by_device_adc'){
+ if(!in_array($key, $exclude_data_arr)){
+ continue;
+ }else{
+ $temporary_arr['value'] = $result[$key];
+ }
+ }else{
+ if($key == 'un_fat_w_weight'){
+ $temporary_arr['value'] = bcsub($result['weight'],$result['fat_w'],2);
+ }else{
+ if(array_key_exists($key,$result)){
+ $temporary_arr['value'] = $result[$key];
+ }
+
+ }
+ }
+ $temporary_arr['unit'] = $value[1];
+ array_push($result_data,$temporary_arr);
+ }
+ //
+ // 添加头围详细start
+ if($result['head_circumference']){
+ 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
+ // 添加心率详细start
+ if($result['heart_rate']){
+ array_unshift($result_data,[
+ 'key_name'=>'heart_rate',
+ 'name'=>'心率',
+ 'value'=>$result['heart_rate'],
+ 'unit'=>'跳/分钟',
+ ]);
+ }
+ // 添加心率详细end
+ return $this->msg($result_data);
+ }else{
+ return $this->msg(10004);
+ }
+
+ }
+ public function history_del_action($data){
+
+ $result = Db::table($this->body_db_name['body_data_new'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
+ if($result){
+ // 添加心率详细end
+ return $this->msg([]);
+ }else{
+ return $this->msg(10002);
+ }
+
+ }
+ public function curve_detailed_action($data){
+
+ $user_data = Db::table($this->body_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,target_weight,initial_weight,initial_date')->find();
+ if(!$user_data){
+ return $this->msg(10003);
+ }
+
+
+
+ $weight_result = null;
+ if($user_data['target_weight'] == null || $user_data['initial_weight'] == null){
+ $user_data['target_weight'] = $user_data['target_weight'] == null?0:$user_data['target_weight'];
+ $user_data['initial_weight'] = $user_data['initial_weight'] == null?0:$user_data['initial_weight'];
+ }else{
+ $weight_result = Db::table($this->body_db_name['body_data_new'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field('id,weight,record_time')->find();
+
+ }
+
+ $return_data['target_weight'] = $user_data['target_weight'];
+ $return_data['initial_weight'] = $user_data['initial_weight'];
+
+ if($weight_result){
+
+ $return_data['calculate_time'] = $this->daysSince($user_data['initial_date']);
+ // dump($weight_result['weight']);
+ // dump($data['initial_weight']);
+ // dump(bcsub($weight_result['weight'],$data['initial_weight'],2));
+
+ $return_data['calculate_val'] = bcsub($weight_result['weight'],$return_data['initial_weight'],2);
+
+ // dump($user_data['initial_date']);
+
+ // die;
+ }else{
+ $return_data['calculate_time'] = 0;
+ $return_data['calculate_val'] = 0;
+ }
+
+ $db_type = [['weight','体重'],['height','身高'],['bmi','BMI'],['heart_rate','心率'],['head_circumference_val','头围']];
+
+ // foreach ($variable as $key => $value) {
+ // # code...
+ // }
+
+ $data['s_time'] = $data['s_time'].' 00:00:00';
+ $data['e_time'] = $data['e_time'].' 23:59:59';
+
+ $cha_data = Db::table($this->body_db_name['body_data_new'])
+ ->where("aud_id = ".$data['aud_id']." AND is_del = 0 AND record_time >= '".$data['s_time']."' AND record_time <= '".$data['e_time']."'")
+ ->order('record_time desc')
+ ->field('id,weight,height,bmi,heart_rate,head_circumference_val,LEFT(record_time,10) as record_time')
+ ->select();
+
+ $temporary_arr = [];
+ $return_data['curve_list'] = [];
+ $bg_color = ['体重'=>'#f78814','身高'=>'#dab8f4','BMI'=>'#a8def6','心率'=>'#fb8587','头围'=>'#55d87b'];
+ foreach ($db_type as $key => $value) {
+ $temporary_arr = [];
+ // $temporary_arr['key'] = $value[0];
+ $temporary_arr['title'] = $value[1];
+ $temporary_arr['line'] = [
+ 'categories' => [],
+ 'series' => [
+ ['color' => $bg_color[$value[1]],'data' => []]
+ // ['color' => '#000000','data' => []]
+ ],
+ ];
+
+ foreach ($cha_data as $k => $v) {
+ if($v[$value[0]]){
+ $temporary_arr['line']['categories'][] = $v['record_time'];
+ $temporary_arr['line']['series'][0]['data'][] = floatval($v[$value[0]]);
+ }
+
+ }
+ $return_data['curve_list'][] = $temporary_arr;
+ }
+
+
+
+
+
+
+ // if($data['type'] == 'heart_rate'){
+ // $where_str = "aud_id = ".$data['aud_id']." AND heart_rate is not null AND is_del = 0";
+ // $field_str = "id,record_time,heart_rate as val_data";
+ // }else if($data['type'] == 'head_circumference'){
+ // $where_str = "aud_id = ".$data['aud_id']." AND head_circumference_val is not null AND is_del = 0";
+ // $field_str = "id,record_time,head_circumference_val as val_data";
+ // }else{
+ // $where_str = "aud_id = ".$data['aud_id']." AND is_del = 0";
+ // $field_str = "id,record_time,".$data['type']." as val_data";
+ // }
+
+
+ // $return_data['curve_list'] = [
+ // 'key' => $data['type'],
+ // 'line' => [
+ // 'categories' => [],
+ // 'series' => [
+ // 'color' => "#000000",
+ // 'data' => [],
+ // ],
+ // ],
+ // ];
+
+ // foreach ($cha_data as $key => $value) {
+ // $return_data['curve_list']['line']['categories'][] = $value['record_time'];
+ // $return_data['curve_list']['line']['series']['data'][] = $value['val_data'];
+ // }
+
+
+ return $this->msg($return_data);
+
+ }
+
+ ################################################################工具################################################################
+ ################################################################工具################################################################
+
+
+
+
+
+ // 处理一般落点
+ public function process_offset_action($val, $list) {
+
+ $count = count($list);
+ if($count <= 0){
+ return 0;
+ }
+ // dump($val);
+ // dump($list);
+ // die;
+ // 边界检查:小于最小值
+ $firstMin = floatval($list[0]['min_val']);
+ if (floatval($val) < $firstMin) {
+ return '0';
+ }
+
+ // 边界检查:大于最大值
+ $lastMax = floatval($list[$count-1]['max_val']);
+ if (floatval($val) > $lastMax) {
+ return '100';
+ }
+
+ // 找到数值所在的区间
+ for ($i = 0; $i < $count; $i++) {
+ $item = $list[$i];
+ $valNum = floatval($val);
+ $minNum = floatval($item['min_val']);
+ $maxNum = floatval($item['max_val']);
+
+ // 如果是第一个区间,包含最小值
+ if ($i == 0 && $valNum <= $maxNum) {
+ $index = $i;
+ break;
+ }
+ // 如果是最后一个区间,包含最大值
+ elseif ($i == $count - 1 && $valNum >= $minNum) {
+ $index = $i;
+ break;
+ }
+ // 中间区间
+ elseif ($valNum >= $minNum && $valNum < $maxNum) {
+ $index = $i;
+ break;
+ }
+ }
+
+ if (!isset($index)) {
+ return '0';
+ }
+
+ // 计算基准值
+ $itemPercent = bcdiv('100', strval($count), 20);
+ $basePercent = bcmul(strval($index), $itemPercent, 20);
+
+ // 计算当前区间内的百分比
+ $item = $list[$index];
+ $minVal = $item['min_val'];
+ $maxVal = $item['max_val'];
+
+ $rangeWidth = bcsub($maxVal, $minVal, 20);
+
+ // 如果范围宽度为0,直接返回基准百分比
+ if (floatval($rangeWidth) == 0) {
+ $result = bcdiv($basePercent, '1', 1);
+ return $result;
+ }
+
+ $offset = bcsub($val, $minVal, 20);
+ $percentInRange = bcdiv($offset, $rangeWidth, 20);
+ $currentPercent = bcmul($percentInRange, $itemPercent, 20);
+
+ // 计算总百分比并格式化
+ $result = bcadd($basePercent, $currentPercent, 1);
+ // $result = bcdiv($totalPercent, '1', 1);
+
+ return $result;
+ }
+ // 发送信息获取身体数据
+ public function send_body_data($data,$type){
+ if($type == '4_electrode'){
+ // 使用接口调用照良那边的 进行计算start
+ $url = 'https://klcz.pcxbc.com/open-api/calc/healthcalc/bodyfat3';
+ if($data['age'] < '3'){
+ $data['hasStandardList'] = true;
+ }else{
+ unset($data['birthDay']);
+ unset($data['head']);
+ }
+ $request_result = $this->postRequest($url,$data);
+ }else{
+ // 使用接口调用照良那边的 进行计算start
+ $url = 'https://ybapi.ybhdmob.com/api/third/body120';
+ $data['body'] = $data['adc'];
+ $data['sex'] = $data['gender'];
+ unset($data['adc']);
+ unset($data['gender']);
+ unset($data['birthDay']);
+ $request_result = $this->postRequest($url,$data);
+ }
+ if($request_result['code'] != 0){
+ return false;
+ }else{
+ return $request_result['data'];
+ }
+
+ }
+ //简要身体数据标准和颜色
+ public function judgment_standard_color($data,$type,$user){
+ $linshi_data = [];
+ $month_num = $this->calculateAgeInMonthsWithPrecision($user['birthday']);
+ $age = $this->calculate_age($user['birthday']);
+ $gender_val = $user['gender'];
+ $return_data = [$data];
+ if($type == 'weight'){
+
+ $linshi_data = $this->merged_data['weight'];
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ }
+ }
+ // dump($return_data);
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ }
+ return $return_data;
+ }else{
+
+ $return_data[] = '';
+ $return_data[] = '';
+ return $return_data;
+ }
+ }else if($type == 'height'){
+ $linshi_data = $this->merged_data['height'];
+ $bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ }
+ }
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ }
+ return $return_data;
+ }else{
+ $return_data[] = '';
+ $return_data[] = '';
+ return $return_data;
+ }
+ }else if($type == 'bmi'){
+ $linshi_data = $this->merged_data['bmi'];
+ $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
+
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ }
+ }
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ }
+ return $return_data;
+ }else if($type == 'heart_rate'){
+ $linshi_data = $this->merged_data['heart_rate'];
+ foreach ($this->heart_rate as $key => $value) {
+ if($month_num > $value['age']['min'] && $month_num <= $value['age']['max']){
+ $linshi_data['standard_list'][0]['max_val'] = $value[$gender_val]['min'];
+ $linshi_data['standard_list'][1]['min_val'] = $value[$gender_val]['min'];
+ $linshi_data['standard_list'][1]['max_val'] = $value[$gender_val]['max'];
+ $linshi_data['standard_list'][2]['min_val'] = $value[$gender_val]['max'];
+ $linshi_data['standard_list'][2]['max_val'] = 300;
+ break;
+ }
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ $return_data[] = bcdiv(bcadd($linshi_data['standard_list'][1]['min_val'],$linshi_data['standard_list'][1]['max_val'],20),2,0);
+ }
+ }
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ $return_data[] = 0;
+ }
+ return $return_data;
+ }else if($type == 'ideal_weight'){
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ return $bhw_date[0]['median'];
+ }else{
+ return false;
+ }
+ }else if($type == 'ideal_height'){
+ $bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ return $bhw_date[0]['median'];
+ }else{
+ return false;
+ }
+ }else if($type == 'ideal_bmi'){
+ $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ return $bhw_date[0]['median'];
+ }else{
+ return false;
+ }
+ }else if($type == 'fat_r' || $type == 'fat_w'){//'fat_w'同一标准
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ if($age < 30){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['29'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['30'];
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
+ }else{
+ return false;
+ }
+ // return $return_data;
+ }else if($type == 'muscle' || $type == 'muscleval' || $type == 'protein' || $type == 'proteinval' || $type == 'water' || $type == 'sfr' || $type == 'visceral'){//'muscleval'同一标准
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
+ }else{
+ return false;
+ }
+ }else if($type == 'bone'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+
+ if($gender_val == '1'){
+ if($user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }else if($user['weight'] >= 60 && $user['weight'] < 75){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60_75'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['75'];
+ }
+ }else{
+ if($user['weight'] < 45){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45'];
+ }else if($user['weight'] >= 45 && $user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45_60'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }
+ }
+
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ return [$linshi_data['standard'],$linshi_data['standard_color']];
+ }else{
+ return false;
+ }
+ }else if($type == 'score'){
+ $linshi_data = $this->merged_data['score'];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $return_data[] = $v['text'];
+ $return_data[] = $v['color'];
+ }
+ }
+ if(count($return_data) <= 1){
+ $return_data[] = '异常';
+ $return_data[] = '#000000';
+ }
+ return $return_data;
+ }else{
+ return false;
+ }
+ }
+ //详细身体数据
+ public function judgment_standard_color_detailed($data,$type,$user){
+ $linshi_data = [];
+ $month_num = $this->calculateAgeInMonthsWithPrecision($user['birthday']);
+ $age = $this->calculate_age($user['birthday']);
+ $gender_val = $user['gender'];
+ $return_data = [$data];
+ if($type == 'weight'){
+ if($data){
+ $linshi_data = $this->merged_data['weight'];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
+
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+
+ }else{
+ $linshi_data['standard_list'] = [];
+ // $return_data[] = '异常';
+ // $return_data[] = '#000000';
+ // return $linshi_data;
+ }
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'height'){
+ if($data){
+ $linshi_data = $this->merged_data['height'];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ $bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f2sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][3]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['min_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][4]['max_val'] = $bhw_date[0]['z3sd'];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+
+ }else{
+ $linshi_data['standard_list'] = [];
+ // $return_data[] = '异常';
+ // $return_data[] = '#000000';
+ // return $return_data;
+ }
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'heart_rate'){
+ if($data){
+ $linshi_data = $this->merged_data['heart_rate'];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ foreach ($this->heart_rate as $key => $value) {
+ if($month_num > $value['age']['min'] && $month_num <= $value['age']['max']){
+ $linshi_data['standard_list'][0]['max_val'] = $value[$gender_val]['min'];
+ $linshi_data['standard_list'][1]['min_val'] = $value[$gender_val]['min'];
+ $linshi_data['standard_list'][1]['max_val'] = $value[$gender_val]['max'];
+ $linshi_data['standard_list'][2]['min_val'] = $value[$gender_val]['max'];
+ $linshi_data['standard_list'][2]['max_val'] = 300;
+ break;
+ }
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'head_circumference'){
+ if($data){
+ $linshi_data = $this->merged_data['head_circumference'];
+ $bhw_date =json_decode($data,true);
+ $linshi_data['standard_list'] = $bhw_date['list2'];
+ $linshi_data['value'] = $bhw_date['value']?$bhw_date['value']:0;
+ $linshi_data['standard'] = $bhw_date['level']?$bhw_date['level']:'';
+ $linshi_data['standard_color'] = $bhw_date['color']?$bhw_date['color']:'#000000';
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+
+ }
+ else if($type == 'kcal'){
+ if($data){
+ $linshi_data = $this->merged_data['kcal'];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ // 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
+ $vv_val = 0;
+ if($age < 3){
+ if($gender_val == '1'){
+ $vv_val = bcsub(bcmul(60.9,$user['weight'],2),54,2);
+ }else{
+ $vv_val = bcsub(bcmul(61.0,$user['weight'],2),51,2);
+ }
+ }else if($age >= 3 && $age < 10){
+ if($gender_val == '1'){
+ $vv_val = bcadd(bcmul(22.7,$user['weight'],2),495,2);
+ }else{
+ $vv_val = bcadd(bcmul(22.5,$user['weight'],2),499,2);
+ }
+ }else if($age >= 10 && $age < 18){
+ if($gender_val == '1'){
+ $vv_val = bcadd(bcmul(17.5,$user['weight'],2),651,2);
+ }else{
+ $vv_val = bcadd(bcmul(12.2,$user['weight'],2),746,2);
+ }
+ }else if($age >= 18 && $age < 30){
+ if($gender_val == '1'){
+ $vv_val = bcadd(bcmul(15.3,$user['weight'],2),679,2);
+ }else{
+ $vv_val = bcadd(bcmul(14.7,$user['weight'],2),496,2);
+ }
+ }else{
+ if($gender_val == '1'){
+ $vv_val = bcadd(bcmul(11.6,$user['weight'],2),879,2);
+ }else{
+ $vv_val = bcadd(bcmul(8.7,$user['weight'],2),820,2);
+ }
+ }
+ // dump($linshi_data['standard_list']);
+ $linshi_data['standard_list'][0]['max_val'] = $vv_val;
+ $linshi_data['standard_list'][1]['min_val'] = $vv_val;
+ // dump($linshi_data['standard_list']);
+ // dump($data);
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'bmi'){
+ if($data){
+ $linshi_data = $this->merged_data['bmi'];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+
+ if($bhw_date){
+ $linshi_data['standard_list'][0]['max_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][1]['min_val'] = $bhw_date[0]['f1sd'];
+ $linshi_data['standard_list'][1]['max_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][2]['min_val'] = $bhw_date[0]['z1sd'];
+ $linshi_data['standard_list'][2]['max_val'] = $bhw_date[0]['z2sd'];
+ $linshi_data['standard_list'][3]['min_val'] = $bhw_date[0]['z2sd'];
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'fat_r' || $type == 'fat_w'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+
+ if($age < 30){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['29'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['30'];
+ }
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'muscle' || $type == 'muscleval' || $type == 'protein' || $type == 'proteinval' || $type == 'water' || $type == 'sfr' || $type == 'visceral'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val];
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'ideal_weight'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->select();
+ // $bhw_date = Db::table($this->body_db_name['weight'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['value'] = $bhw_date[0]['median'];
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'ideal_height'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $bhw_date = Db::table($this->body_db_name['height'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['value'] = $bhw_date[0]['median'];
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'ideal_bmi'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ $bhw_date = Db::table($this->body_db_name['bmi'])->where("Month >= $month_num and Sex = '$gender_val'")->order('Month')->limit(1)->cache(86400)->select();
+ if($bhw_date){
+ $linshi_data['value'] = $bhw_date[0]['median'];
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'bone'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+
+ if($gender_val == '1'){
+ if($user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }else if($user['weight'] >= 60 && $user['weight'] < 75){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60_75'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['75'];
+ }
+ }else{
+ if($user['weight'] < 45){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45'];
+ }else if($user['weight'] >= 45 && $user['weight'] < 60){
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['45_60'];
+ }else{
+ $linshi_data['standard_list'] = $this->merged_data[$type]['standard_list'][$gender_val]['60'];
+ }
+ }
+
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'body_type' || $type == 'body_level' || $type == 'body_age'){
+
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = $type == 'body_age'?(float)$data:$data;
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+ // dump($linshi_data);
+ // dump($data);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else if($type == 'score'){
+ if($data){
+ $linshi_data = $this->merged_data[$type];
+ $linshi_data['value'] = floatval($data);
+ $linshi_data['standard'] = '';
+ $linshi_data['standard_color'] = '';
+ $linshi_data['offset'] = 0;
+
+ foreach ($linshi_data['standard_list'] as $k => $v) {
+ if($data >= $v['min_val'] && $data < $v['max_val']){
+ // 如果落在区间内
+ $linshi_data['standard'] = $v['text'];
+ $linshi_data['standard_color'] = $v['color'];
+ }
+ }
+ if($linshi_data['standard'] == ''){
+ $linshi_data['standard'] = '异常';
+ $linshi_data['standard_color'] = '#000000';
+ }
+ $linshi_data['offset'] = $this->process_offset_action($linshi_data['value'],$linshi_data['standard_list']);
+ return $linshi_data;
+ }else{
+ return false;
+ }
+ }
+ else{
+ return false;
+ }
+ }
+
+ /**
+ * 根据Broca改良公式计算标准体重参考值
+ * @param int $gender 性别: 1=男, 2=女
+ * @param int $age 年龄(周岁)
+ * @param float $height 身高(厘米)
+ * @return string 标准体重(kg),保留2位小数
+ * @throws InvalidArgumentException 当参数无效时抛出异常
+ */
+ public function calculateStandardWeight($gender, $age, $height) {
+ // 1. 参数校验
+ if (!in_array($gender, [1, 2])) {
+ return false;
+ }
+ if ($age <= 0 || $age > 120) {
+ return false;
+ }
+ if ($height < 50 || $height > 250) {
+ return false;
+ }
+
+ // 2. 根据性别和年龄确定系数K
+ if ($age < 30) {
+ $k = ($gender === 1) ? '0.90' : '0.85'; // 1=男, 2=女
+ } elseif ($age <= 50) {
+ $k = ($gender === 1) ? '0.88' : '0.82';
+ } else { // age > 50
+ $k = ($gender === 1) ? '0.86' : '0.80';
+ }
+
+ // 3. 使用BC数学函数计算:标准体重 = (身高 - 100) × K
+ // 身高减去100
+ $heightMinus100 = bcsub((string)$height, '100', 20);
+
+ // 乘以系数K
+ $standardWeight = bcmul($heightMinus100, $k, 2);
+
+ // 4. 格式化为保留2位小数
+ return $standardWeight;
+ }
+
+ /**
+ * 使用BC数学函数的精确版本
+ * @param int $age 年龄(岁),数字类型
+ * @param float $weight 体重(kg),数字类型
+ * @param int $gender 性别: 1=男, 2=女
+ * @return string BMR值(千卡/天),保留2位小数
+ */
+ function calculateBMR_BC($age, $weight, $gender) {
+ // 参数校验
+ if (!is_numeric($age) || $age < 0 || $age > 100) {
+ return false;
+ }
+
+ if (!is_numeric($weight) || $weight <= 0 || $weight > 300) {
+ return false;
+ }
+
+ if (!in_array($gender, [1, 2])) {
+ return false;
+ }
+
+ $isMale = ($gender === 1);
+ $weightStr = (string)$weight;
+ $bmr = '0';
+
+ // WHO/FAO/UNU公式分段计算(使用BC函数)
+ if ($age < 3) {
+ // 0-3岁婴儿
+ if ($isMale) {
+ $temp = bcmul('60.9', $weightStr, 4);
+ $bmr = bcsub($temp, '54', 2);
+ } else {
+ $temp = bcmul('61.0', $weightStr, 4);
+ $bmr = bcsub($temp, '51', 2);
+ }
+ } elseif ($age < 10) {
+ // 3-10岁儿童
+ if ($isMale) {
+ $temp = bcmul('22.7', $weightStr, 4);
+ $bmr = bcadd($temp, '495', 2);
+ } else {
+ $temp = bcmul('22.5', $weightStr, 4);
+ $bmr = bcadd($temp, '499', 2);
+ }
+ } elseif ($age < 18) {
+ // 10-18岁青少年
+ if ($isMale) {
+ $temp = bcmul('17.5', $weightStr, 4);
+ $bmr = bcadd($temp, '651', 2);
+ } else {
+ $temp = bcmul('12.2', $weightStr, 4);
+ $bmr = bcadd($temp, '746', 2);
+ }
+ } elseif ($age < 30) {
+ // 18-30岁成年人
+ if ($isMale) {
+ $temp = bcmul('15.3', $weightStr, 4);
+ $bmr = bcadd($temp, '679', 2);
+ } else {
+ $temp = bcmul('14.7', $weightStr, 4);
+ $bmr = bcadd($temp, '496', 2);
+ }
+ } elseif ($age < 60) {
+ // 30-60岁中年人
+ if ($isMale) {
+ $temp = bcmul('11.6', $weightStr, 4);
+ $bmr = bcadd($temp, '879', 2);
+ } else {
+ $temp = bcmul('8.7', $weightStr, 4);
+ $bmr = bcadd($temp, '820', 2);
+ }
+ } else {
+ // 60岁以上老年人
+ if ($isMale) {
+ $temp = bcmul('13.5', $weightStr, 4);
+ $bmr = bcadd($temp, '487', 2);
+ } else {
+ $temp = bcmul('10.5', $weightStr, 4);
+ $bmr = bcadd($temp, '596', 2);
+ }
+ }
+
+ // 确保BMR不为负值
+ if (bccomp($bmr, '0', 2) < 0) {
+ $bmr = '0.00';
+ }
+
+ return $bmr;
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Vitalcapacity.php b/application/NewReedaw2/controller/app/Vitalcapacity.php
new file mode 100644
index 0000000..8f1ea07
--- /dev/null
+++ b/application/NewReedaw2/controller/app/Vitalcapacity.php
@@ -0,0 +1,286 @@
+'app_account_number',
+ 'juese'=>'app_user_data',
+ 'vitalcapacity'=>'app_card_vitalcapacity_data',
+ 'biaozhun'=>'pc_vitalcapacity_standard',
+
+ ];
+ protected $color = ['无效'=>'#FF5656','不及格'=>'#FF5656','及格'=>'#FFAB00','良好'=>'#5AD06D','优秀'=>'#6492F6','牛逼'=>'#3967D6'];
+ protected $curve_data_format = ['one_val'=>['第一次','容积/ml','#009DFF'],'two_val'=>['第二次','容积/ml','#009DFF'],'three_val'=>['第三次','容积/ml','#009DFF'],'average_val'=>['平均','容积/ml','#009DFF']];
+ protected $pagesize = 15;
+ // 加 bcadd(,,20)
+ // 减 bcsub(,,20)
+ // 乘 bcmul(,,20)
+ // 除 bcdiv(,,20)
+ // 测试token=>'caadd1be045a65f30b92aa805f1de54a'
+
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+ ################################################################接口################################################################
+
+ // 设备记录
+ public function device_record(){
+ try {
+ $data = input('post.');
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('one', $data) || !array_key_exists('two', $data) || !array_key_exists('three', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ if(!$this->verify_data_is_ok($data['one'],'intnum')){
+ return $this->msg(10005,'one type error');
+ }
+ if(!$this->verify_data_is_ok($data['two'],'intnum')){
+ return $this->msg(10005,'two type error');
+ }
+ if(!$this->verify_data_is_ok($data['three'],'intnum')){
+ return $this->msg(10005,'three type error');
+ }
+ $data['time'] = date('Y-m-d H:i:s');
+ return $this->manual_record_action($data,'by_device');
+ } 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 data_report(){
+ $data = input('post.');
+ try {
+
+ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){
+ return $this->msg(10001);
+ }
+ unset($data['token']);
+ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
+ return $this->msg(10005,'aud_id type error');
+ }
+ return $this->data_report_action($data);
+ } catch (\Exception $e) {
+ // 捕获异常
+ $logContent["flie"] = $e->getFile();
+ $logContent["line"] = $e->getLine();
+ $logContent['all_content'] = "异常信息:\n";
+ $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
+ $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
+ $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
+ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
+ $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
+ $this->record_api_log($data, $logContent, null);
+ return $this->msg(99999);
+ }
+ }
+
+
+
+ ################################################################action################################################################
+ ################################################################action################################################################
+ public function manual_record_action($data,$type){
+ $temporary_arr['aud_id'] = $data['aud_id'];
+ $temporary_arr['record_time'] = $data['time'];
+ $temporary_arr['one'] = $data['one'];
+ $temporary_arr['two'] = $data['two'];
+ $temporary_arr['three'] = $data['three'];
+ $temporary_arr['average'] = bcdiv(bcadd(bcadd($data['one'],$data['two'],2),$data['three'],2),3,2);
+ $temporary_arr['create_time'] = date('Y-m-d H:i:s');
+ $temporary_arr['one_val'] = $data['one'];
+ $temporary_arr['two_val'] = $data['two'];
+ $temporary_arr['three_val'] = $data['three'];
+ $temporary_arr['average_val'] = $temporary_arr['average'];
+ $temporary_arr['flow_val'] = array_key_exists('flow', $data)?$data['flow']:'0.00';//流速
+ $temporary_arr['record_type'] = $type;
+ // die;
+ // 处理记录时间
+
+ $user_msg = Db::name($this->vitalcapacity_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find();
+ // die;
+ if($user_msg){
+ // 根据性别&年级&年龄查规则
+ if($user_msg['grade'] == 'nothing'){
+ // 计算年龄判断是属于哪个年级
+ $user_age = $this->calculate_age($user_msg['birthday']);
+ if($user_age <= 7){
+ $user_msg['grade'] = 'grade_s_1';
+ }else if($user_age == 8){
+ $user_msg['grade'] = 'grade_s_2';
+ }else if($user_age == 9){
+ $user_msg['grade'] = 'grade_s_3';
+ }else if($user_age == 10){
+ $user_msg['grade'] = 'grade_s_4';
+ }else if($user_age == 11){
+ $user_msg['grade'] = 'grade_s_5';
+ }else if($user_age == 12){
+ $user_msg['grade'] = 'grade_s_6';
+ }else if($user_age == 13){
+ $user_msg['grade'] = 'grade_m_1';
+ }else if($user_age == 14){
+ $user_msg['grade'] = 'grade_m_2';
+ }else if($user_age == 15){
+ $user_msg['grade'] = 'grade_m_3';
+ }else if($user_age == 16){
+ $user_msg['grade'] = 'grade_h_1';
+ }else if($user_age == 17){
+ $user_msg['grade'] = 'grade_h_2';
+ }else if($user_age == 18){
+ $user_msg['grade'] = 'grade_h_3';
+ }else if($user_age == 19 || $user_age == 20){
+ $user_msg['grade'] = 'grade_u_12';
+ }else if($user_age >= 21){
+ $user_msg['grade'] = 'grade_u_34';
+ }
+ }
+ $sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val'];
+ $user_achievement = Db::name($this->vitalcapacity_db_name['biaozhun'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->cache(86400)->select();
+ if(count($user_achievement)<=0){
+ $user_achievement[0] = ['level'=>'无效','score'=>'0'];
+ }
+ $temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->color[$user_achievement[0]['level']];
+ $temporary_arr['score_val'] = $user_achievement[0]['score'];
+
+ }else{
+ return $this->msg(10004,'未找到有效数据');
+ }
+ $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+ $temporary_arr['standard_data'] = json_encode($standard_data);
+ $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->insert($temporary_arr);
+
+ if($result){
+ $time = $result[0]['record_time'];
+ $time = strtotime($time);
+ $time = date('Y年m月d日 H:i:s', $time);
+ return $this->msg([
+ 'average'=>$temporary_arr['average'].'ml',
+ 'level'=>$user_achievement[0]['level'],
+ 'time'=>$time,
+ 'flow_val'=>$temporary_arr['flow_val'],
+ 'list'=>$standard_data,
+ 'offset'=>$this->vitalcapacity_standard_interval($temporary_arr['average'],$standard_data)
+ ]);
+ }else{
+ return $this->msg(10002);
+ }
+ }
+ public function data_report_action($data){
+ $result = Db::table($this->vitalcapacity_db_name['vitalcapacity'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select();
+
+ if(count($result) <= 0){
+ // return $this->msg(10004);
+ return $this->msg([
+ 'average'=>'',
+ 'level'=>'',
+ 'time'=>'',
+ 'flow_val'=>'',
+ 'list'=>'',
+ 'offset'=>''
+ ]);
+
+ }else{
+
+ $time = $result[0]['record_time'];
+ $time = strtotime($time);
+ $time = date('Y年m月d日 H:i:s', $time);
+ $o_l = explode(',',$result[0]['score']);
+ // $standard_data = $this->get_vitalcapacity_data($data['aud_id']);
+ $standard_data = json_decode($result[0]['standard_data'],true);
+
+ return $this->msg([
+ 'average'=>$result[0]['average'].'ml',
+ 'level'=>$o_l[1],
+ 'time'=>$time,
+ 'flow_val'=>$result[0]['flow_val'] == '.00'?'0.00':$result[0]['flow_val'],
+ 'list'=>$standard_data,
+ 'offset'=>$this->vitalcapacity_standard_interval($result[0]['average'],$standard_data)
+ ]);
+ }
+ }
+
+ ################################################################内部调用################################################################
+ ################################################################内部调用################################################################
+ // 肺活量判断区间
+ public function vitalcapacity_standard_interval($val,$data){
+ // 缓存一周
+ $result = '';
+ if(!$data || count($data) <= 0){
+ return $result;
+ }
+ $temporary_qj = $data;
+ $max = 0;
+ $min = 0;
+ $num = 0;
+ foreach ($temporary_qj as $key => $value) {
+ if($val >= $value['min_val'] && $val <= $value['max_val']){
+ $max = $value['max_val'];
+ $min = $value['min_val'];
+ $num = $key;
+ break;
+ }
+ }
+
+ $num = count($temporary_qj)-1-$num;
+
+ if($max == 0){
+ if($val >= $temporary_qj[0]['max_val']){
+ $result = 100;
+ }
+ }else{
+ $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
+ $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
+ }
+ return $result;
+ }
+ // 肺活量判断区间(根据得分)
+ public function vitalcapacity_standard_interval2($val,$data){
+ // 缓存一周
+ $result = '';
+ if(count($data) <= 0){
+ return $result;
+ }
+ $temporary_qj = $data;
+ $max = 0;
+ $min = 0;
+ $num = 0;
+ foreach ($temporary_qj as $key => $value) {
+ if($val >= $value['min_val'] && $val <= $value['max_val']){
+ $max = $value['max_val'];
+ $min = $value['min_val'];
+ $num = $key;
+ break;
+ }
+ }
+ // 计算每份占比
+ $share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1);
+ // 计算在这一段中占多少
+ $result = bcsub($val,$min,1);
+ $result = bcdiv($result,bcsub($max,$min,1),1);
+ $num = count($temporary_qj)-1-$num;
+ $num = bcmul($num,$share_value,1);
+ $result = bcadd($num,$result,1);
+ // $num = count($temporary_qj)-1-$num;
+ // $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2);
+ // $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2);
+
+ return $result;
+ }
+
+
+}
\ No newline at end of file
diff --git a/application/NewReedaw2/controller/app/Wechat.php b/application/NewReedaw2/controller/app/Wechat.php
index d544794..85bbcc2 100644
--- a/application/NewReedaw2/controller/app/Wechat.php
+++ b/application/NewReedaw2/controller/app/Wechat.php
@@ -1,6 +1,6 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 商务合作
+
+
+
+
+
+
+
+
+
+

+
+
商务合作意向登记表
+
+ 智能设备产品包含身高测量仪、体重体脂秤、宠物秤, 母婴秤,厨房秤,商业秤,身高体重/体脂秤,八电极体脂秤,运动训练设备等;软件包含就智能健康管理系统,智能硬件管理系统等,支持智能设备选购/定制、健康系统对接/定制,行业解决方案等,期待与您合作!
+
+
+
+
+
+
+
+
+
+
提交
+
+
+
+
+
+
\ No newline at end of file
diff --git a/application/NewReedaw2/view/app/index/privacy_policy.html b/application/NewReedaw2/view/app/index/privacy_policy.html
new file mode 100644
index 0000000..5ac2259
--- /dev/null
+++ b/application/NewReedaw2/view/app/index/privacy_policy.html
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 隐私协议
+
+
+
+
+
+
+
+
Reedaw隐私协议
+
+
一、前言
+
感谢您选择使用我们的Reedaw体重饮食可视化管理APP(以下简称“本应用”)。我们深知您的个人信息安全至关重要,在您使用本应用后我们郑重承诺,将严格遵守相关法律法规,采取合理有效的措施保护您的个人隐私。本隐私协议旨在明确我们在采集、使用、存储、共享及保护您的个人信息的责任、义务。请您在使用本应用前,仔细阅读并理解本协议内容,一旦您开始使用本应用,即视为您同意我们使用您的个人信息,接受本协议的全部条款。
+
二、信息收集
+
1.必要信息:为了提供基本服务,我们可能会采集您的基本信息,包括但不限于邮箱、姓名(可选择匿名使用)等。这些信息将用于验证您的身份、保障账号安全及提供个性化服务。
+
2.健康数据:在使用本应用进行身体数据健康评估时,我们会采集您的饮食、身高、体重等健康数据。这些数据将用于生成评估报告,并尽量提供相应的健康建议。
+
3.设备信息:为了优化服务体验,我们可能会采集您的设备型号、操作系统版本、IP地址等必要的技术信息。这些信息将帮助我们了解用户的使用环境,以便进行技术调试和服务改进。
+
三、信息使用
+
1.服务提供:我们将根据您提供的信息,为您提供饮食数据评估服务,并生成相应的评估报告。
+
2.个性化推荐:基于您的饮食数据和使用习惯,我们可能会向您推荐适合的饮食管理方案。
+
3.数据分析:我们会对收集到的数据进行匿名化处理,用于统计分析,以改进我们的产品和服务。这些统计数据将不包含任何可以识别您个人身份的信息。
+
四、信息共享与披露
+
1.内部共享:我们可能会将您的信息共享给公司内部负责处理您个人信息的部门或人员,以确保为您提供更好的服务。
+
2.第三方合作:在必要且合法的情况下,我们可能会与第三方服务提供商(如云服务提供商、数据分析公司等)共享您的个人信息,以便他们为我们提供技术支持或数据分析服务。我们将与这些第三方签订严格的保密协议,并要求他们遵守相关法律法规和本协议的规定。
+
3.法律要求:在法律法规要求或政府部门、司法机关要求的情况下,我们可能会依法披露您的个人信息。
+
4.其他4.其他对您的服务性应用。
+
五、信息安全
+
1.技术保障:我们将采取合理的技术手段和管理措施,确保您的个人信息在采集、存储、使用、共享等过程中的安全。
+
2.数据加密:对于敏感信息,我们将采用加密技术进行处理,防止数据在传输和存储过程中被非法访问或泄露。
+
3.访问控制:我们将对访问个人信息的员工进行严格的权限管理,确保只有授权人员才能访问相关信息。
+
六、用户权利
+
1.知情权:您有权了解我们采集、使用、共享及保护您个人信息的详细情况。
+
2.选择权:您有权选择是否向我们提供个人信息的具体内容,以及选择是否接受我们的个性化推荐服务。
+
3.更正权:如果您发现我们采集的个人信息有误,您有权要求我们及时更正。
+
4.屏蔽权:在符合法律法规要求的情况下,您有权要求我们屏蔽您的个人信息全部内容。
+
七、协议变更
+
我们有权根据法律法规的变化或业务发展的需要,对本隐私协议进行修订。修订后的协议将通过本应用内通知或其他适当方式告知您。请您定期查阅本隐私协议,以便及时了解我们的最新政策。
+
八、争议解决
+
如因本协议产生任何争议,双方应首先通过友好协商解决;协商不成的,任何一方均有权向本应用运营方所在地的法院提起诉讼。
+
九、生效与终止
+
本协议自您同意并接受之日起生效,并持续有效至您注销账号或本应用终止服务时止。
+
+
+
+
+
diff --git a/application/app/view/download/demo2.html b/application/app/view/download/demo2.html
index 20d48a5..b499625 100644
--- a/application/app/view/download/demo2.html
+++ b/application/app/view/download/demo2.html
@@ -15,6 +15,7 @@
下载页面
+