diff --git a/application/KitchenScale2/controller/app/Countfood.php b/application/KitchenScale2/controller/app/Countfood.php index a72c0e9..351dd13 100644 --- a/application/KitchenScale2/controller/app/Countfood.php +++ b/application/KitchenScale2/controller/app/Countfood.php @@ -1246,10 +1246,8 @@ class Countfood extends Base{ } } - // dump($food_content); - // die; $food_content = $this->calculate_nutrients($food_content); - return $this->msg($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); diff --git a/application/KitchenScale2/controller/app/Index.php b/application/KitchenScale2/controller/app/Index.php index 4f2276d..ad76162 100644 --- a/application/KitchenScale2/controller/app/Index.php +++ b/application/KitchenScale2/controller/app/Index.php @@ -689,7 +689,7 @@ class Index extends Base{ ['name'=>'高度活动(每周6-7天高强度运动)','val'=>'1.725'], ['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'], ], - 'language_arr'=>$this->process_Language() + // 'language_arr'=>$this->process_Language() ]; $cfc = Db::connect('cfc_db'); @@ -838,9 +838,6 @@ class Index extends Base{ ]; // 添加每餐背景图start - - - return $this->msg($return_data); } diff --git a/application/KitchenScale3/controller/app/Login.php b/application/KitchenScale3/controller/app/Login.php index abeb30a..5d8b47a 100644 --- a/application/KitchenScale3/controller/app/Login.php +++ b/application/KitchenScale3/controller/app/Login.php @@ -8,7 +8,7 @@ use PHPMailer\PHPMailer\PHPMailer; class Login extends Base{ - protected $code_time = 300; + protected $code_time = 55; // protected $token_time = 2592000;//30天的秒数 protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png'; protected $login_use_db_name = [ @@ -57,18 +57,19 @@ class Login extends Base{ if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) { return $this->msg(10005,'data type is error'); }else{ - if(!strlen($data['data']) > 20){ - return $this->msg(10005,'data too long'); + if(strlen($data['data']) > 50){ + return $this->msg(10005,'email too long'); } } + if(!$this->verify_data_is_ok($data['password'],'str')){ return $this->msg(10005,'password type is error'); }else{ - if(!strlen($data['password']) > 20){ + if(!strlen($data['password']) > 50){ return $this->msg(10005,'password too long'); }else{ if($data['password'] != $data['confirm_password']){ - return $this->msg(10005,'请确认密码'); + return $this->msg(10005,'The two passwords entered do not match.'); } } } @@ -82,7 +83,7 @@ class Login extends Base{ $inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token')->find(); if($inspect_repeat){ - return $this->msg(10002,'注册失败,账号已存在'); + return $this->msg(10002,'Registration failed. Account already exists.'); } @@ -90,7 +91,7 @@ class Login extends Base{ // 检查验证码 $code_result = $this->check_code($data['data'],$data['code']); if($code_result !== true){ - return $this->msg(10002,'验证码错误或失效'); + return $this->msg(10002,'Verification code is incorrect or invalid.'); } // 验证完之后 @@ -148,8 +149,8 @@ class Login extends Base{ if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) { return $this->msg(10005,'data type is error'); }else{ - if(!strlen($data['data']) > 30){ - return $this->msg(10005,'data too long'); + if(strlen($data['data']) > 50){ + return $this->msg(10005,'email too long'); } } if(!array_key_exists($data['language'],$this->language_country)){ @@ -167,14 +168,14 @@ class Login extends Base{ // 检查验证码 $code_result = $this->check_code($data['data'],$data['validate_data']); if($code_result !== true){ - return $this->msg(20001,'验证码错误或失效'); + return $this->msg(20001,'Verification code is incorrect or invalid.'); } $code_name = $data['data']; if($this->check_code($code_name,$data['validate_data']) === true){ // 查询账号是否已经注册 - $inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data']])->field('id,token,language')->find(); + $inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token,language')->find(); if($inspect_repeat){ $cfc->table($this->login_use_db_name['account'])->where(['token'=>$inspect_repeat['token']])->update(['login_time'=>date('Y-m-d H:i:s'),'language'=>$data['language']]); return $this->msg(['token'=>$inspect_repeat['token'],'aan_id'=>$inspect_repeat['id'],'language'=>$this->language_country[$data['language']][1]]); @@ -192,22 +193,22 @@ class Login extends Base{ if($result_add){ return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result_add,'language'=>$this->language_country[$data['language']][1]]); }else{ - return $this->msg(10002,'登录失败,请稍后重试'); + return $this->msg(10002,'Login failed. Please try again later.'); } } }else{ - return $this->msg(10002,'登录失败,验证码错误或失效'); + return $this->msg(10002,'Login failed. Verification code is incorrect or expired.'); } }else if($data['validate_type'] == 'password'){ if(!$this->verify_data_is_ok($data['validate_data'],'str')){ return $this->msg(10005,'validate_data type is error'); }else{ - if(!strlen($data['validate_data']) > 20){ - return $this->msg(10005,'validate_data too long'); + if(strlen($data['validate_data']) > 50){ + return $this->msg(10005,'password too long'); } } // 查询账号是否已经注册 - $inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'password'=>$data['validate_data']])->field('id,token,language')->find(); + $inspect_repeat = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'password'=>$data['validate_data'],'is_del'=>0])->field('id,token,language')->find(); if($inspect_repeat){ @@ -215,7 +216,7 @@ class Login extends Base{ return $this->msg(['token'=>$inspect_repeat['token'],'aan_id'=>$inspect_repeat['id'],'language'=>$this->language_country[$inspect_repeat['language']][1]]); }else{ - return $this->msg(10003,'账号未注册,请先注册'); + return $this->msg(10003,'Account not registered. Please sign up first.'); $set_data['password'] = $data['validate_data']; $set_data['account'] = $data['data']; $set_data['head_pic'] = $this->default_head_pic; @@ -228,7 +229,7 @@ class Login extends Base{ if($result_add){ return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result_add,'language'=>$this->language_country[$data['language']][1]]); }else{ - return $this->msg(10002,'登录失败,请稍后重试'); + return $this->msg(10002,'Login failed. Please try again later.'); } } }else{ @@ -253,7 +254,7 @@ class Login extends Base{ } // 退出登录操作 public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // try { + try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); @@ -274,41 +275,40 @@ class Login extends Base{ // 成功 $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'] .= "方法: " . __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); - // } + } 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 reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ + public function reset_password(){ + $data = input('post.'); try { // 你的业务逻辑 // 验证是否前段发送过来的数据 - if(count(input('post.')) > 0){ - $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)){ + if(!array_key_exists('token', $data) || !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); } // 验证数据值是否合规 if($data['password'] != $data['c_password']){ - return $this->msg(10003,'两次密码不一致'); + return $this->msg(10003,'The two passwords entered do not match.'); } if($data['password'] == ''){ - return $this->msg(10003,'密码不能为空'); + return $this->msg(10003,'Password cannot be empty.'); } if(!$this->verify_data_is_ok($data['password'],'str')){ return $this->msg(10005); @@ -321,25 +321,40 @@ class Login extends Base{ if($code_result !== true){ return $this->msg(10003,$code_result); } - $t_y = $this->is_tel_email($data['data']); - if($t_y === false){ - return $this->msg(10003,'账号格式错误'); + + if (!preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/', $data['data'])) { + return $this->msg(10005,'data type is error'); + }else{ + if(strlen($data['data']) > 50){ + return $this->msg(10005,'email too long'); + } } + + + // $t_y = $this->is_tel_email($data['data']); + // if($t_y === false){ + // return $this->msg(10003,'账号格式错误'); + // } + + $cfc = Db::connect('cfc_db'); + // 检查账号是否存在 - $find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); + $find_data = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data'],'is_del'=>0])->field('id,token')->find(); if(!$find_data){ return $this->msg(10003); } - $result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); + + $result = $cfc->table($this->login_use_db_name['account'])->where(['account'=>$data['data']])->update(['password'=>$data['password']]); + if($result){ - $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); + return $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); }else{ - $return_data = $this->msg(10002); + return $this->msg(10002); } // 成功 - $this->record_api_log($data, null, $return_data); - return $return_data; + // $this->record_api_log($data, null, $return_data); + // return $return_data; } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -360,25 +375,43 @@ class Login extends Base{ // 删除账号 - public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function delete_account(){ + $data = input('post.'); try { // 你的业务逻辑 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - $return_data = $this->msg(10001); - } - $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']); - if($result){ - $return_data = $this->msg([]); - }else{ - $return_data = $this->msg(10002); - } - // 成功 - $this->record_api_log($data, null, $return_data); - return $return_data; + if(!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'],'num')){ + return $this->msg(10005); + } + + + $cfc = Db::connect('cfc_db'); + + $account_data = $cfc->table($this->login_use_db_name['account'])->where(['token'=>$data['token']])->field('id,token,account')->find(); + + // dump($account_data); + // die; + // 检查验证码 + $code_result = $this->check_code($account_data['account'],$data['code']); + + + if($code_result !== true){ + return $this->msg(10003,$code_result); + } + + $result = $cfc->table($this->login_use_db_name['account'])->where(['token'=>$data['token']])->update(['is_del'=>1]); + + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -419,7 +452,7 @@ class Login extends Base{ } if(cache($data['data'].'_cfc_multilingual')){ - return $this->msg(10002,'60秒仅可发送一次验证码'); + return $this->msg(10002,'You can only send a verification code once every 60 seconds.'); } $num = mt_rand(100000,999999); @@ -429,7 +462,7 @@ class Login extends Base{ cache($data['data'].'_cfc_multilingual', $num, $this->code_time); return $this->msg([]); }else{ - return $this->msg(10010,'验证码发送失败'); + return $this->msg(10010,'Failed to send verification code.'); } } diff --git a/application/NewReedaw/controller/app/Base.php b/application/NewReedaw/controller/app/Base.php index b192f9f..6a1b028 100644 --- a/application/NewReedaw/controller/app/Base.php +++ b/application/NewReedaw/controller/app/Base.php @@ -16,7 +16,10 @@ class Base extends Controller{ '3'=>'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']; @@ -88,7 +91,7 @@ class Base extends Controller{ return true; } } - // 判断字符串是手机还是邮箱 + // 判断字符串是手机还是邮箱(有用) public function is_tel_email($str) { // 手机号码的正则表达式(中国大陆格式)(下面正则实际判断的是是否为11位数字) $mobilePattern = '/^\d{11}$/'; @@ -106,7 +109,7 @@ class Base extends Controller{ return false; } - // 计算年龄 + // 计算年龄(有用) public function calculate_age($data = '1991-04-20'){ $today = time(); // 获取当前时间的 Unix 时间戳 $birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳 @@ -206,7 +209,7 @@ class Base extends Controller{ return $interval->format('%a'); } - // 计算月龄 + // 计算月龄(有用) public function calculateAgeInMonthsWithPrecision($birthDateStr) { // 获取当前日期 $now = new \DateTime(); @@ -224,28 +227,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) { @@ -596,6 +603,34 @@ class Base extends Controller{ // 必须是 >0 的整数或字符串整数 $filtered = filter_var($data, FILTER_VALIDATE_INT); return $filtered !== false && $filtered > 0; + + 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': // 日期时间验证 - 保持原有逻辑不变 @@ -614,7 +649,7 @@ class Base extends Controller{ } - // 处理身高体重的单位,转换它们为cm和kg。 + // 处理身高体重的单位,转换它们为cm和kg。(有用) public function convertHeightAndWeight($height, $weight) { // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -708,37 +743,291 @@ 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; - // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']); + // 添加一条搜索记录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 '克': + // 已经是克,直接返回 + $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($aa = 4,$gd = 0.2){ + + // 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]); + + // } + // 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']); + // } } \ No newline at end of file diff --git a/application/NewReedaw/controller/app/Body.php b/application/NewReedaw/controller/app/Body.php new file mode 100644 index 0000000..2a57d6d --- /dev/null +++ b/application/NewReedaw/controller/app/Body.php @@ -0,0 +1,1284 @@ +'app_account_number', + 'juese'=>'app_user_data', + 'body_data'=>'app_card_body_data', + 'bmi'=>'pc_bmistand', + 'heigh'=>'pc_heightstand', + 'weigh'=>'pc_weightstand', + 'chufang1'=>'pc_childrenprescription', + 'chufang2'=>'pc_childprescriptionbyage', + ]; + protected $result_end_data_mould = [ + 'name'=>'', + 'value'=>'', + 'unit'=>'', + 'standard'=>'', + 'color'=>'', + 'list'=>[] + ]; + 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 = [ + 'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'], + 'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'], + 'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'], + 'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'], + 'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'], + 'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'], + 'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'], + ]; + protected $bhw_list = [ + 'bmi'=>[ + ['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'], + ['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#59D06A'], + ['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FDAA02'], + ['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FB5755'], + ], + 'height'=>[ + ['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'], + ], + 'weight'=>[ + ['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'], + ] + ]; + protected $card_body_level = [ + 'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]], + 'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]], + 'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]], + ]; + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 测试token=>'caadd1be045a65f30b92aa805f1de54a' + + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + // 获取角色报告 + public function body_report(){ + // phpinfo(); + // die; + 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->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); + } + } + // 手动记录 + 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################################################################ + public function body_report_action_detailed($data){ + $result_return = [ + "score_name"=>"", + "score_value"=>"", + "score_unit"=>"", + "body_type_name"=>"", + "body_type_value"=>"", + "body_type_unit"=>"", + "record_time"=>"", + 'top_list'=>[ + [ + "name"=>"体重", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"weight", + "desc"=>"反映和衡量一个人健康状况的重要标志之一", + "offset"=>"0", + "standard_val"=>"", + "difference_val"=>"", + ], + [ + "name"=>"身高", + "value"=>"0", + "unit"=>"CM", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"height", + "desc"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大", + "offset"=>"0", + "standard_val"=>"", + "difference_val"=>"", + ], + [ + "name"=>"BMI", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"bmi", + "desc"=>"BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。", + "offset"=>"0", + "standard_val"=>"", + "difference_val"=>"", + ], + ], + 'bottom_list' => [], + 'cplist'=>[ + 'nutritionlist'=>[], + 'sportlist'=>[], + 'sleeplist'=>[], + 'moodlist'=>[], + ], + 'target_current'=>[ + 'target_weight'=>'0', + 'initial_weight'=>'0', + 'cumulative_weight'=>'0', + 'cumulative_day'=>'0' + ], + ]; + $body_last_data = Db::query(" + select + Top 1 + acbd.id, + acbd.acd_id, + acbd.record_type, + acbd.create_time, + acbd.last_update_time, + acbd.score, + 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.body_level, + acbd.aud_id, + acbd.record_time, + acbd.body_type, + acbd.age, + acbd.is_del, + acbd.height, + acbd.height_val, + acbd.weight, + acbd.weight_val, + acbd.bmi, + acbd.body_age, + acbd.head_circumference, + aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date + from ".$this->body_db_name['body_data']." as acbd + left join ".$this->body_db_name['juese']." as aud on acbd.aud_id=aud.id + where acbd.is_del=0 and acbd.aud_id='".$data['aud_id']."' + order by acbd.record_time desc + "); + // return $this->msg($body_last_data); + if(count($body_last_data) <= 0){ + return $this->msg($result_return); + } + // 暂时存储头围数据 + $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; + $result_end['gender'] = $body_last_data[0]['gender']; + $result_end['record_time'] = $body_last_data[0]['record_time']; + + $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'=>[ + 'height'=>$body_last_data[0]['height'], + 'weight'=>$body_last_data[0]['weight'], + 'bmi'=>$body_last_data[0]['bmi'] + ], + ]); + // return $this->msg($result_end); + + // // 加入曲线板块底部的减肥计划数据start + // $result_end['target_current'] = $this->base_target_initial_cumulative_weight([ + // 'weight'=>$body_last_data[0]['weight']>0?$body_last_data[0]['weight']:0, + // 'target_weight'=>$body_last_data[0]['target_weight']>0?$body_last_data[0]['target_weight']:0, + // 'initial_weight'=>$body_last_data[0]['initial_weight']>0?$body_last_data[0]['initial_weight']:0, + // 'initial_date'=>$body_last_data[0]['initial_date']!=null?$body_last_data[0]['initial_date']:0, + // ]); + // // dump($result_end); + // if(count($result_end['top_list'][2]['list']) <= 0){ + // // 这是16岁以上人群 + // $data = [ + // 'height'=>$body_last_data[0]['height_val'], + // 'weight'=>$body_last_data[0]['weight_val'], + // 'birthday'=>$body_last_data[0]['birthday'], + // 'sex'=>$body_last_data[0]['gender'] + // ]; + + // $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true); + // $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData(); + + // if($temporary_arr_bmi_list['code'] == 0){ + // $result_end['top_list'][2]['standard'] = $temporary_arr_bmi_list['data']['bmilevel']; + // $result_end['top_list'][2]['color'] = $temporary_arr_bmi_list['data']['bmilevelcolor']; + // $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist']; + // $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset']; + // } + // // dump($result_end); + // // die; + // } + + // 添加头围数据(如果有的话)start + if($head_circumference !== false && $this->calculate_age($body_last_data[0]['birthday']) < 3){ + + if($head_circumference['level'] == '异常' || $head_circumference['value'] == 0){ + $offset = 0; + }else{ + $offset = $cardparts->calculate_landing_point($head_circumference['list2'],$head_circumference['value'],$head_circumference['level']); + } + $touwei_array = [ + 'name'=>'头围', + 'value'=>$head_circumference['value'], + 'unit'=>'CM', + 'standard'=>$head_circumference['level'], + 'color'=>'', + 'list'=>$head_circumference['list2'], + 'key_name'=>'head_circumference', + 'desc'=>'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关', + 'offset'=>$offset + ]; + $touwei_data = $this->touwei_temporary_use($body_last_data[0]['birthday'],$body_last_data[0]['gender']); + if(count($touwei_data)){ + $touwei_array['standard_val'] = $touwei_data['middle']; + $touwei_array['difference_val'] = bcsub($touwei_array['value'],$touwei_data['middle'],2); + }else{ + $touwei_array['standard_val'] = ''; + $touwei_array['difference_val'] = ''; + } + array_push($result_end['top_list'],$touwei_array); + + } + // 添加头围数据(如果有的话)end + // 这段业务处理可以删除,是做的临时的,假的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; + // $biaozhun_val_bmi = 22; + foreach ($result_end['top_list'] as $key => $value) { + if($value['key_name'] == 'weight'){ + if($biaozhun_val['weight'] == ''){ + $result_end['top_list'][$key]['standard_val'] = ''; + $result_end['top_list'][$key]['difference_val'] = ''; + }else{ + $result_end['top_list'][$key]['standard_val'] = $biaozhun_val['weight']; + $result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['weight'],2); + } + }else if($value['key_name'] == 'height'){ + if($biaozhun_val['height'] == ''){ + $result_end['top_list'][$key]['standard_val'] = ''; + $result_end['top_list'][$key]['difference_val'] = ''; + }else{ + $result_end['top_list'][$key]['standard_val'] = $biaozhun_val['height']; + $result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['height'],2); + } + }else if($value['key_name'] == 'bmi'){ + if($biaozhun_val['bmi'] == ''){ + $result_end['top_list'][$key]['standard_val'] = ''; + $result_end['top_list'][$key]['difference_val'] = ''; + }else{ + $result_end['top_list'][$key]['standard_val'] = $biaozhun_val['bmi']; + $result_end['top_list'][$key]['difference_val'] = bcsub($value['value'],$biaozhun_val['bmi'],2); + } + } + + } + // 这段业务处理可以删除,是做的临时的,假的end + return $this->msg($result_end); + // 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']); + $gender_val = $data['gender']; + foreach ($data as $key => $value) { + if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){ + // 设置单个数据格式 + $result_end_data[$key] = $this->result_end_data_mould; + // 该项名 + if(array_key_exists($key, $this->unit_name)){ + $result_end_data[$key]['name'] = $this->unit_name[$key]; + } + // 该项单位 + if(array_key_exists($key, $this->unit_symbol)){ + $result_end_data[$key]['unit'] = $this->unit_symbol[$key]; + } + + $result_end_data[$key]['value'] = explode(',',$value)[0]; + + if(strpos($value, ',')){ + $result_end_data[$key]['standard'] = explode(',',$value)[1]; + } + if(array_key_exists($key, $this->standard_color)){ + if($result_end_data[$key]['standard'] != '异常' && $result_end_data[$key]['standard'] != ''){ + $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; + } + } + // 如果小于16岁(儿童) + if($data['age'] < $this->age_limit){ + if(array_key_exists($key, $this->bhw_list)){ + $result_end_data[$key]['list'] = $this->bhw_list[$key]; + if($key == '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){ + $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z2sd']; + $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd']; + } + }else if($key == 'height'){ + $bhw_date = Db::table($this->body_db_name['heigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + if($bhw_date){ + $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; + $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; + $result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd']; + $result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd']; + $result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd']; + } + }else if($key == 'weight'){ + $bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + if($bhw_date){ + $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; + $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; + $result_end_data[$key]['list'][1]['max_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][2]['min_val'] = $bhw_date[0]['f1sd']; + $result_end_data[$key]['list'][2]['max_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z1sd']; + $result_end_data[$key]['list'][3]['max_val'] = $bhw_date[0]['z2sd']; + $result_end_data[$key]['list'][4]['min_val'] = $bhw_date[0]['z2sd']; + $result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd']; + } + } + } + } + } + } + return $result_end_data; + } + public function grow_up_recommendation($data){ + // card_body_level + // die; + // $result = [ + // ['name'=>'营养','key'=>'nutrition','content'=>''], + // ['name'=>'睡眠','key'=>'sleep','content'=>''], + // ['name'=>'运动','key'=>'motion','content'=>''], + // ['name'=>'情绪','key'=>'emotion','content'=>''] + // ]; + $result = [ + 'nutritionlist'=>[],//营养 + 'sportlist'=>[],//运动 + 'sleeplist'=>[],//睡眠 + 'moodlist'=>[],//情绪 + ]; + + $temporary_arr = []; + foreach ($data['body'] as $key => $value) { + if(explode(',',$value)[1] == '无'){ + $result = [ + 'nutritionlist'=>[],//营养 + 'sportlist'=>[],//运动 + 'sleeplist'=>[],//睡眠 + 'moodlist'=>[],//情绪 + ]; + return $result; + } + $temporary_arr[$key] = $this->card_body_level[$key]['list'][explode(',',$value)[1]]; + } + $min_value = min($temporary_arr); + $min_key = array_search($min_value,$temporary_arr); + $type_num = $this->card_body_level[$min_key]['value']; + $temporary_arr2 = Db::table($this->body_db_name['chufang1'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find(); + // dump($temporary_arr2); + array_push($result['nutritionlist'],$temporary_arr2['Nutrition']); + array_push($result['sportlist'],$temporary_arr2['Sport']); + // $result['nutritionlist'] = $temporary_arr2['Nutrition']; + // $result['sportlist'] = $temporary_arr2['Sport']; + + $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); + $temporary_arr2 = Db::table($this->body_db_name['chufang2'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select(); + $default_sleep = ''; + $default_emotion = ''; + foreach ($temporary_arr2 as $key => $value) { + if($value['MinAge'] == -1 && $value['Type'] == 2){ + $default_sleep = $value['Content']; + } + if($value['MinAge'] == -1 && $value['Type'] == 3){ + $default_emotion = $value['Content']; + } + if($month_num>=$value['MinAge'] && $month_num<=$value['MaxAge']){ + if($value['Type'] == 1){ + array_push($result['sportlist'],$value['Content']); + // $result['sportlist'] = $result['sportlist'].$value['Content']; + }else if($value['Type'] == 2){ + array_push($result['sleeplist'],$value['Content']); + // $result['sleeplist'] = $result['sleeplist'].$value['Content']; + }else if($value['Type'] == 3){ + array_push($result['moodlist'],$value['Content']); + // $result['moodlist'] = $result['moodlist'].$value['Content']; + } + } + } + + $result['sleeplist'] = count($result['sleeplist']) <= 0?array_push($result['sportlist'],$default_sleep):$result['sleeplist']; + $result['moodlist'] = count($result['moodlist']) <= 0?array_push($result['moodlist'],$default_sleep):$result['moodlist']; + + return $result; + } + public function touwei_temporary_use($age,$gender){ + $return_data = [ + + ]; + if(!in_array($gender,['1','2'])){ + return $return_data; + } + + $age_m = $this->calculateAgeInMonthsWithPrecision($age); + + if($age_m <= 36){ + // $touwei_date = Db::table('ws_touwei')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->fetchSql(true)->select(); + $touwei_date = Db::query("select * from ws_touwei where age <= $age_m and gender = '$gender' order by age desc"); + $return_data = $touwei_date[0]; + } + return $return_data; + } + public function body_temporary_use($age,$gender){ + $return_data = [ + 'height'=>'', + 'weight'=>'', + 'bmi'=>'', + ]; + if(!in_array($gender,['1','2'])){ + return $return_data; + } + $age_m = $this->calculateAgeInMonthsWithPrecision($age); + if($age_m < 228){//月龄小于19岁 + // dump($age_m); + // $height_date = Db::table('ws_height')->where("age <= $age_m and gender = '$gender'")->order('age desc')->limit(1)->field('middle')->select(); + $height_date = Db::query("select * from ws_height where age <= $age_m and gender = '$gender' order by age desc"); + // $weight_date = Db::table('ws_weight')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select(); + $weight_date = Db::query("select * from ws_weight where age <= $age_m and gender = '$gender' order by age desc"); + // $bmi_date = Db::table('ws_bmi')->where("age <= $month_num and Sex = '$gender'")->order('age desc')->limit(1)->field('middle')->select(); + $bmi_date = Db::query("select * from ws_bmi where age <= $age_m and gender = '$gender' order by age desc"); + $return_data = array( + 'height' => $height_date[0]['middle'], + 'weight' => $weight_date[0]['middle'], + 'bmi' => $bmi_date[0]['middle'], + ); + }else{ + $bmi_data = [ + '1' => [ // 男性 + [ + 'age' => ['min' => 216, 'max' => 299], // 18-24岁(216-299月龄) + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.5', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '20.5', 'max_val' => '23.9', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '24.0', 'max_val' => '27.9', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '28.0', 'max_val' => '31.9', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '32.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 300, 'max' => 419], // 25-34岁(300-419月龄) + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.5', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '21.0', 'max_val' => '24.4', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '24.5', 'max_val' => '28.4', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '28.5', 'max_val' => '32.4', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '32.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 420, 'max' => 539], // 35-44岁(420-539月龄) + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.5', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '21.5', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '25.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 540, 'max' => 719], // 45-59岁(540-719月龄) + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.5', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '22.0', 'max_val' => '25.5', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '25.6', 'max_val' => '29.5', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '29.6', 'max_val' => '33.5', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '33.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 720, 'max' => '99999'], // ≥60岁(720+月龄) + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.5', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.5', 'max_val' => '22.4', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '22.5', 'max_val' => '26.0', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '26.1', 'max_val' => '29.0', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '29.1', 'max_val' => '33.0', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '33.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ] + ], + '2' => [ // 女性 + [ + 'age' => ['min' => 216, 'max' => 299], // 18-24岁 + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.0', 'max_val' => '19.9', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '20.0', 'max_val' => '22.9', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '23.0', 'max_val' => '26.9', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '27.0', 'max_val' => '30.9', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '31.0', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 300, 'max' => 419], // 25-34岁 + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.0', 'max_val' => '20.4', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '20.5', 'max_val' => '23.4', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '23.5', 'max_val' => '27.4', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '27.5', 'max_val' => '31.4', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '31.5', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 420, 'max' => 539], // 35-44岁 + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.0', 'max_val' => '20.9', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '21.0', 'max_val' => '24.0', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '24.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 540, 'max' => 719], // 45-59岁 + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.0', 'max_val' => '21.4', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '21.5', 'max_val' => '24.5', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '24.6', 'max_val' => '28.5', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '28.6', 'max_val' => '32.5', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '32.6', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ], + [ + 'age' => ['min' => 720, 'max' => 99999], // ≥60岁 + 'list'=>[ + ['min_val' => '0', 'max_val' => '18.0', 'text' => '低体重', 'color' => '#8BC8FB'], + ['min_val' => '18.0', 'max_val' => '21.9', 'text' => '偏瘦', 'color' => '#B4E3FD'], + ['min_val' => '22.0', 'max_val' => '25.0', 'text' => '正常', 'color' => '#6CD86F'], + ['min_val' => '25.1', 'max_val' => '28.0', 'text' => '超重', 'color' => '#FFD166'], + ['min_val' => '28.1', 'max_val' => '32.0', 'text' => '肥胖', 'color' => '#FF9A5A'], + ['min_val' => '32.1', 'max_val' => '99999', 'text' => '重度肥胖', 'color' => '#FF6B6B'] + ] + ] + ] + ]; + + foreach ($bmi_data[$gender] as $group) { + if ($age_m >= $group['age']['min'] && $age_m <= $group['age']['max']) { + $return_data['bmi'] = bcdiv(bcadd($group['list'][2]['min_val'],$group['list'][2]['max_val'],20),2,1); + } + } + + } + return $return_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; + } + + + + + + + + +} \ No newline at end of file diff --git a/application/NewReedaw/controller/app/Card.php b/application/NewReedaw/controller/app/Card.php index a954c3d..97f5529 100644 --- a/application/NewReedaw/controller/app/Card.php +++ b/application/NewReedaw/controller/app/Card.php @@ -3,14 +3,31 @@ namespace app\NewReedaw\controller\app; use think\Db; -use think\Cache; + class Card extends Base{ protected $card_db_name = [ 'zhanghao'=>'app_account_number', 'juese'=>'app_user_data', - 'card'=>'app_card_data' + 'card'=>'app_card_data', + 'skip'=>'app_card_skip_data', + 'vitalcapacity'=>'app_card_vitalcapacity_data', + 'zhongzhao'=>'app_sportstesting_data', + + + ]; + + protected $card_standard_arr_data = [ + 'id'=>'', + 'name'=>'', + 'content'=>'', + 'page_url_report'=>'', + 'is_sub_item'=>'', + 'background_color'=>'', + 'background_pic'=>'', + 'key_word'=>'', + 'data'=>[], ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -23,10 +40,10 @@ class Card extends Base{ ################################################################接口################################################################ // 卡片列表信息 - public function card_list_msg(){ + public function card_list_all(){ + $data = input('post.'); try { // 你的业务逻辑 - $data = input('post.'); if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){ return $this->msg(10001); } @@ -36,7 +53,7 @@ class Card extends Base{ 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); + return $this->card_list_all_action($data); } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -51,12 +68,12 @@ class Card extends Base{ return $this->msg(99999); } } - // 卡片列表信息 - public function card_user_order(){ + // 保存用户所选的卡片列表 + public function save_card_list(){ + $data = input('post.'); try { // 你的业务逻辑 - $data = input('post.'); - if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('card_data', $data)){ + 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')){ @@ -65,7 +82,10 @@ class Card extends Base{ if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ return $this->msg(10005,'aud_id type error'); } - return $this->card_user_order_action($data); + if(!$this->verify_data_is_ok(explode(',',$data['card_list']),'arr_intnum')){ + return $this->msg(10005,'aud_id type error'); + } + return $this->save_card_list_action($data); } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -80,11 +100,142 @@ class Card extends Base{ 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); + } + } + + ################################################################action################################################################ ################################################################action################################################################ - public function card_list_msg_action($data){ + + 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){ @@ -98,46 +249,223 @@ class Card extends Base{ '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]; + // 对照处理用户的卡片信息 + 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){ + $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) { + foreach ($value as $k => $v) { + unset($return_data[$key][$k]['content']); + unset($return_data[$key][$k]['page_url_report']); + unset($return_data[$key][$k]['is_sub_item']); + unset($return_data[$key][$k]['background_color']); + unset($return_data[$key][$k]['background_pic']); + unset($return_data[$key][$k]['ROW_NUMBER']); } } - ksort($return_data['chosen_yes']); return $this->msg($return_data); } - public function card_user_order_action($data){ - - if($data['card_data'] != ''){ - $data['card_data2'] = explode(',',$data['card_data']); - }else{ - $data['card_data2'] = []; - } - - foreach ($data['card_data2'] as $key => $value) { - if(!$this->verify_data_is_ok($value,'intnum')){ - return $this->msg(10005,'卡片id错误'); - } - } - $user_data = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id'],'is_del'=>0])->count(); - if($user_data <= 0){ + 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,'未核实到角色信息'); } - $result = Db::table($this->card_db_name['juese'])->where(['id'=>$data['aud_id']])->update(['card_order' => $data['card_data']]); - if($result){ - return $this->msg([]); + $card_data = Db::table($this->card_db_name['card'])->where("id in (".$data['card_list'].")")->field('id')->cache(86400)->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(10002); + return $this->msg(10003,'卡片数据错误'); + } + } + 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 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 []; + } + } + diff --git a/application/NewReedaw/controller/app/Guessyoulike.php b/application/NewReedaw/controller/app/Guessyoulike.php new file mode 100644 index 0000000..adb7d03 --- /dev/null +++ b/application/NewReedaw/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/NewReedaw/controller/app/Index.php b/application/NewReedaw/controller/app/Index.php index 354cb8c..5727558 100644 --- a/application/NewReedaw/controller/app/Index.php +++ b/application/NewReedaw/controller/app/Index.php @@ -8,7 +8,8 @@ use think\Db; // use think\Log; // use PHPMailer\PHPMailer\PHPMailer; // use app\NewReedaw\controller\app\Role; -use app\app\controller\Language; +// use app\app\controller\Language; +use app\KitchenScale2\controller\app\Index as Cfindex;//厨房秤的config class Index extends Base{ @@ -22,6 +23,7 @@ class Index extends Base{ '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'=>['体型','']], @@ -56,10 +58,33 @@ class Index extends Base{ ################################################################接口################################################################ ################################################################接口################################################################ + // 检测版本及判断是否登录失效 + public function login_invalid_version(){ + + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(-1,'已过期'); + + }else{ + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $user_token_state = $this->token_time_validate($data['token']); + // $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language); + if($user_token_state['state'] === false){ + return $this->msg(-1,'已过期'); + // return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url]]; + }else{ + $zh = Db::table($this->index_db_name['zhanghao'])->where(['token' => $data['token']])->cache(86400)->field('id,token,nickname')->find(); + return $this->msg($zh); + // return [['code'=>0,'description'=>'未过期'],['version'=>$version,'url'=>$url]]; + } + } + } // 配置信息 public function config(){ $data = input('post.'); - try { + // try { if(!array_key_exists('token', $data)){ return $this->msg(10001,'token is miss'); } @@ -67,20 +92,20 @@ class Index extends Base{ return $this->msg(10005,'token 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); - } + // } 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); + // } } // 获取角色信息 @@ -115,107 +140,9 @@ class Index extends Base{ - // // 身高预测 - // public function genetic_height(){ - // try { - // $data = input('post.'); - // if(!is_array($data)){ - // return $this->msg(10005); - // } - // 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,'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); - // } - // } - // // BMI测评 - // public function bmi_evaluation(){ - // try { - // $cbe_data = input('post.'); - // 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 all_data_contrast($data = ['before_id'=>'171','after_id'=>'174','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ @@ -285,25 +212,188 @@ class Index extends Base{ '此测量数据仅供参考,不可替代医学专业测试!' ] ], - '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'], - ], - 'version_msg'=>[], - 'login_status'=>[], + // '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'] + ] + ], ]; - - $temporary = $this->login_invalid_version($data); - $return_data['version_msg'] = $temporary[1]; - $return_data['login_status'] = $temporary[0]; + // $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(); @@ -324,6 +414,20 @@ class Index extends Base{ 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 + + // foreach ($cf_confog as $key => $value) { + // // dump($key); + // $return_data[$key] = $value; + // } + + // $return_data['cfc'] = $cf_confog; return $this->msg($return_data); } @@ -345,68 +449,7 @@ class Index extends Base{ - // 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_body_data_contrast($data){ // $data2 = [$data['before_id'],$data['after_id']]; @@ -696,58 +739,7 @@ class Index extends Base{ ################################################################内部调用################################################################ ################################################################内部调用################################################################ - // 检测版本及判断是否登录失效 - public function login_invalid_version($data){ - // 获取客户端IP - $ip = request()->ip(); - // 调用IP识别方法 - $region = $this->getIpInfo($ip); - // 解析地区信息 - $regionParts = explode('|', $region); - $country = $regionParts[0] ?? ''; - // 判断国家是否在支持的语言列表中 - $language = ''; - if ($country && $country !== '0') { - $languageMap = [ - '中国' => 'zh-Hans', - '美国' => 'en', - '英国' => 'en', - '西班牙' => 'es', - '法国' => 'fr', - '葡萄牙' => 'pt', - '阿拉伯联合酋长国' => 'ar', - '俄罗斯' => 'ru', - '德国' => 'de' - ]; - $language = $languageMap[$country] ?? ''; - } - // 检查语言是否在支持列表中 - $language_all = new Language(); - $isSupportedLanguage = array_key_exists($language, $language_all->getSupportedLanguages()); - - $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(!array_key_exists('token', $data)){ - return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>'zh-Hans','language_arr'=>$this->process_Language()]]; - }else{ - if(!$this->verify_data_is_ok($data['token'],'str')){ - return $this->msg(10005); - } - $user_token_state = $this->token_time_validate($data['token']); - $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language); - if($user_token_state['state'] === false){ - return [['code'=>-1,'description'=>'已过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]]; - }else{ - return [['code'=>0,'description'=>'未过期'],['version'=>$version,'url'=>$url,'language'=>$language_data,'language_arr'=>$this->process_Language()]]; - } - } - } + // 添加IP信息获取方法 protected function getIpInfo($ip) { // 默认IP diff --git a/application/NewReedaw/controller/app/Kitchenscale.php b/application/NewReedaw/controller/app/Kitchenscale.php new file mode 100644 index 0000000..ea123c0 --- /dev/null +++ b/application/NewReedaw/controller/app/Kitchenscale.php @@ -0,0 +1,2901 @@ +'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(){ + // 尝试捕获异常 + 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('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('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/NewReedaw/controller/app/Login.php b/application/NewReedaw/controller/app/Login.php index a518d58..3772812 100644 --- a/application/NewReedaw/controller/app/Login.php +++ b/application/NewReedaw/controller/app/Login.php @@ -22,8 +22,9 @@ class Login extends Base{ // 注册 public function register(){ + $data = input('post.'); try { - $data = input('post.'); + // 验证数据项是否完整 if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ return $this->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); @@ -356,6 +359,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 +367,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 +394,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/NewReedaw/controller/app/Role.php b/application/NewReedaw/controller/app/Role.php index 2548d7c..5e34b4b 100644 --- a/application/NewReedaw/controller/app/Role.php +++ b/application/NewReedaw/controller/app/Role.php @@ -2,18 +2,18 @@ namespace app\NewReedaw\controller\app; -use think\Controller; use think\Db; -use think\Cache; -use think\Log; -use PHPMailer\PHPMailer\PHPMailer; +use app\NewReedaw\controller\app\Login; +use app\NewReedaw\controller\app\Kitchenscale; + class Role extends Base{ protected $role_db_name = [ 'zhanghao'=>'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 = [ @@ -66,11 +66,158 @@ class Role extends Base{ ################################################################接口################################################################ ################################################################接口################################################################ + // 获取账号下信息 + public function get_my_account_msg(){ + $data = input('post.'); + try { + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + 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 { // 你的业务逻辑 - $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)){ return $this->msg(10001); } @@ -109,9 +256,10 @@ class Role extends Base{ } // 更新角色 public function update_member(){ + $data = input('post.'); try { // 你的业务逻辑 - $data = input('post.'); + 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('measure_model', $data)){ return $this->msg(10001); } @@ -153,9 +301,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 +326,211 @@ 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); + // } + + } + ################################################################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){ @@ -320,6 +671,137 @@ 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['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']; + } + } + // 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); + } diff --git a/application/NewReedaw/controller/app/Skip.php b/application/NewReedaw/controller/app/Skip.php index 90d39c2..8d2be0b 100644 --- a/application/NewReedaw/controller/app/Skip.php +++ b/application/NewReedaw/controller/app/Skip.php @@ -33,10 +33,10 @@ class Skip extends Base{ // 手动记录 public function manual_record(){ + $data = input('post.'); try { - $data = input('post.'); if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - $return_data = $this->msg(10001); + return $this->msg(10001); } if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ return $this->msg(10005,'aud_id type error'); @@ -78,10 +78,10 @@ class Skip extends Base{ } // 设备记录 public function device_record(){ + $data = input('post.'); try { - $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); + return $this->msg(10001); } if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ return $this->msg(10005); @@ -93,23 +93,19 @@ class Skip extends Base{ 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,'跳绳数量或者分钟、秒钟值必须为整数'); + return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); } if($data['num'] <= 0){ - $return_data = $this->msg(10005,'跳绳数不能小于等于0'); + return $this->msg(10005,'跳绳数不能小于等于0'); } if(abs($data['time_s']) >= 60){ - $return_data = $this->msg(10005,'秒钟值不能大于60'); + return $this->msg(10005,'秒钟值不能大于60'); } unset($data['token']); if($this->validate_user_identity($data['aud_id']) === false){ - $return_data = $this->msg(10003); + return $this->msg(10003); } - $return_data = $this->manual_record_action($data); - - // 成功 - $this->record_api_log($data, null, $return_data); - return $return_data; + return $this->manual_record_action($data); } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -126,8 +122,9 @@ class Skip extends Base{ } // 数据报告 public function data_report(){ + $data = input('post.'); try { - $data = input('post.'); + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } @@ -152,8 +149,9 @@ class Skip extends Base{ } // 曲线 public function curve_chart(){ + $data = input('post.'); try { - $data = input('post.'); + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } @@ -179,8 +177,9 @@ class Skip extends Base{ } // 获取历史列表(分页) public function record_list_page(){ + $data = input('post.'); 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); } @@ -210,8 +209,9 @@ class Skip extends Base{ } // 获取历史列表(分组) public function record_list_group(){ + $data = input('post.'); 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); } @@ -244,8 +244,9 @@ class Skip extends Base{ } // 历史记录(详细) public function detailed_record(){ + $data = input('post.'); try { - $data = input('post.'); + if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ return $this->msg(10001); } @@ -272,21 +273,58 @@ class Skip extends Base{ } // 删除历史数据 public function del_record(){ + $data = input('post.'); 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->skip_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($user_data){ - return $this->msg([]); - }else{ - return $this->msg(10002); + // unset($data['token']); + // 核实账号 + $zh_data = Db::table($this->skip_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->field('id,token')->find(); + if(!$zh_data){ + return $this->msg(10003); } + // dump($zh_data); + // 核实角色 + $js_data = Db::table($this->skip_db_name['juese'])->where(['aan_id'=>$zh_data['id'],'is_del'=>0])->field('id')->select(); + if(!$js_data){ + return $this->msg(10003); + } + + // dump($js_data); + $skip_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->field('id,aud_id')->find(); + + if(!$skip_data){ + return $this->msg(10004); + } + + // dump($skip_data); + $pd = false; + + foreach ($js_data as $key => $value) { + if($value['id'] == $skip_data['aud_id']){ + $pd = true; + } + } + + if($pd == true){ + $user_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + }else{ + return $this->msg(10002,'请勿操作他人数据'); + } + + + + } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); diff --git a/application/NewReedaw/controller/app/Userbody.php b/application/NewReedaw/controller/app/Userbody.php index af6bb82..388a67f 100644 --- a/application/NewReedaw/controller/app/Userbody.php +++ b/application/NewReedaw/controller/app/Userbody.php @@ -20,165 +20,421 @@ class Userbody extends Base{ ]; 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' => '分', - 'list' => [] + "description"=>"身体得分指综合评估身体健康状况的指标。", + 'list' => [ + '偏低' => '#C2831C', + '标准' => '#F5A623', + '偏高' => '#14CBAD', + '高' => '#0F9982' + ], + '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'], + ] ], 'height' => [ 'name' => '身高', 'unit' => 'cm', - 'list' => [] + "description"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大", + 'list' => [ + '矮'=>'#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'], + ] ], 'weight' => [ 'name' => '体重', 'unit' => 'kg', - 'list' => [] + "description"=>"体重指人体的重量,通常用斤、公斤或磅作为单位来衡量。体重是人体健康的重要指标,但需要结合身高、体型和体脂率等因素来综合评估。", + 'list' => [ + '低'=>'#FD5759', + '偏低'=>'#FAAD01', + '标准'=>'#5BD068', + '偏高'=>'#FAAD01', + '高'=>'#FD5759', + ], + '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'=>'#FAAD01'], + ['min_val'=>'','max_val'=>'','text'=>'高','color'=>'#FD5759'], + ] ], 'bmi' => [ 'name' => 'BMI', 'unit' => '', - 'list' => [] + "description"=>"BMI是身体质量指数(BodyMassIndex)的缩写,是一种常用的衡量人体肥胖程度的指标", + 'list' => [ + '消瘦'=>'#FDDA6B', + '正常'=>'#5BD068', + '偏重'=>'#FAAD01', + '肥胖'=>'#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'], + ] ], 'fat_r' => [ 'name' => '脂肪率', 'unit' => '%', + "description"=>"", 'list' => [ '偏低' => '#FCDB67', '标准' => '#58D268', '偏高' => '#FCAA00', '高' => '#FD5752' + ], + 'standard_list' => [ + 'man'=>[ + '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'], + ], + ], + 'woman'=>[ + '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'], + ] + ] ] ], 'fat_w' => [ 'name' => '脂肪量', 'unit' => 'kg', + "description"=>"", 'list' => [ '偏低' => '#FCDB67', '标准' => '#58D268', '偏高' => '#FCAA00', '高' => '#FD5752' + ], + 'standard_list' => [ + 'man'=>[ + '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'], + ], + ], + 'woman'=>[ + '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'], + ] + ] ] ], 'muscle' => [ 'name' => '肌肉率', 'unit' => '%', + "description"=>"", 'list' => [ '不足' => '#FFDA68', '标准' => '#59CD6F', '优' => '#3C64D4' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], + ], + 'woman'=>[ + ['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'], + ] ] ], 'muscleval' => [ 'name' => '肌肉量', 'unit' => 'kg', + "description"=>"", 'list' => [ '不足' => '#FFDA68', '标准' => '#59CD6F', '优' => '#3C64D4' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], + ], + 'woman'=>[ + ['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'], + ] ] ], 'water' => [ 'name' => '水分', 'unit' => 'kg', + "description"=>"", 'list' => [ '不足' => '#FED966', '标准' => '#58CF6B', '优' => '#3A68D7' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], + ], + 'woman'=>[ + ['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'], + ] ] ], 'bone' => [ 'name' => '骨重', 'unit' => 'kg', + "description"=>"", 'list' => [ '不足' => '#FED966', '标准' => '#58CF6F', '优' => '#3A68D7' + ], + 'standard_list' => [ + 'man'=>[ + '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'], + ], + ], + 'woman'=>[ + '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'], + ], + ] ] ], 'protein' => [ 'name' => '蛋白率', 'unit' => '%', + "description"=>"", 'list' => [ '不足' => '#FED966', '标准' => '#58CF6F', '优' => '#3A68D7' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], //蓝 + ], + 'woman'=>[ + ['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'], + ] ] ], 'proteinval' => [ 'name' => '蛋白量', 'unit' => 'kg', + "description"=>"", 'list' => [ '不足' => '#FED966', '标准' => '#58CF6F', '优' => '#3A68D7' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], //蓝 + ], + 'woman'=>[ + ['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'], + ] ] ], 'kcal' => [ 'name' => '基础代谢', 'unit' => 'kcal', + "description"=>"", 'list' => [ '偏低' => '#FF5656', '优' => '#3A68D4' + ], + 'standard_list' => [ + ['min_val'=>'0','max_val'=>'','text'=>'偏低','color'=>'#ff5656'], + ['min_val'=>'','max_val'=>'9999','text'=>'优','color'=>'#3C66D2'], ] ], 'visceral' => [ 'name' => '内脏指数', 'unit' => '', + "description"=>"", 'list' => [ '标准' => '#55CF6C', '警惕' => '#FEAC00', '危险' => '#FB5A52' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], //红 + ], + 'woman'=>[ + ['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'], //红 + ] ] ], 'sfr' => [ 'name' => '皮下脂肪', 'unit' => '%', + "description"=>"", 'list' => [ '不足' => '#FCDB68', '标准' => '#59D16F', '偏高' => '#FEAB03' + ], + 'standard_list' => [ + 'man'=>[ + ['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'], //橙 + ], + 'woman'=>[ + ['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'], + ] ] ], 'body_level' => [ 'name' => '肥胖等级', 'unit' => '', - 'list' => [] + "description"=>"肥胖等级指根据个体BMI来评估一个人是否超重或肥胖的指标。", + 'list' => [], + 'standard_list' => [] ], 'body_type' => [ 'name' => '身体类型', 'unit' => '', - 'list' => [] + "description"=>"身体类型是对人体外形的总体描述和评定", + 'list' => [], + 'standard_list' => [] ], 'body_age' => [ 'name' => '身体年龄', 'unit' => '岁', - 'list' => [] + "description"=>"身体年龄指衡量身体健康状况的指标,它反映了一个人的生理状态相对于实际年龄的健康程度。相关模型主要与BMI有关。", + 'list' => [], + 'standard_list' => [] ] ]; - protected $bhw_list = [ - 'bmi'=>[ - ['min_val'=>'0','max_val'=>'','text'=>'消瘦','color'=>'#FDDA6B'], - ['min_val'=>'','max_val'=>'','text'=>'正常','color'=>'#59D06A'], - ['min_val'=>'','max_val'=>'','text'=>'偏重','color'=>'#FDAA02'], - ['min_val'=>'','max_val'=>'50','text'=>'肥胖','color'=>'#FB5755'], - ], - 'height'=>[ - ['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'], - ], - 'weight'=>[ - ['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'], - ] + protected $standard_color = [ + 'fat_r'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'], + 'fat_w'=>['偏低'=>'#FCDB67','标准'=>'#58D268','偏高'=>'#FCAA00','高'=>'#FD5752'], + 'muscle'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'], + 'muscleval'=>['不足'=>'#FFDA68','标准'=>'#59CD6F','优'=>'#3C64D4'], + 'water'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], + 'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'], + 'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'], + 'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'], ]; protected $card_body_level = [ 'height'=>['value'=>1,'list'=>['矮'=>2,'偏矮'=>3,'标准'=>4,'偏高'=>5,'高'=>5]], @@ -213,6 +469,7 @@ class Userbody extends Base{ $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"; @@ -241,6 +498,139 @@ class Userbody extends Base{ $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 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']); + 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'] .= "函数: 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 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"; @@ -257,32 +647,37 @@ class Userbody extends Base{ ################################################################action################################################################ public function body_report_brief_action($data){ $result_return = [ - 'weight'=>[ - "name"=>"体重", - 'time'=>'', - "value"=>"0", - "unit"=>"kg", - "standard"=>"", - "standard_color"=>"#77E46C", - 'target_weight'=>'0', - 'target_weight_unit'=>'kg' - ], - 'height'=>[ - "name"=>"身高", - 'time'=>'', - "value"=>"0", - "unit"=>"cm", - "standard"=>"", - "standard_color"=>"#FEA63D", - ], - 'bmi'=>[ - "name"=>"BMI", - 'time'=>'', - "value"=>"0", - "unit"=>"", - "standard"=>"", - "standard_color"=>"#FF8072", + 'top_list'=>[ + [ + "name"=>"体重", + 'time'=>'', + "value"=>"0", + "unit"=>"kg", + "standard"=>"", + "standard_color"=>"#77E46C", + 'target_weight'=>'0', + 'target_weight_unit'=>'kg' + ], + [ + "name"=>"身高", + 'time'=>'', + "value"=>"0", + "unit"=>"cm", + "standard"=>"", + "standard_color"=>"#FEA63D", + ], + [ + "name"=>"BMI", + 'time'=>'', + "value"=>"0", + "unit"=>"", + "standard"=>"", + "standard_color"=>"#FF8072", + ], ], + // 'weight'=> + // 'height'=> + // 'bmi'=> 'card_list'=>[ ], @@ -337,25 +732,32 @@ class Userbody extends Base{ $record_time = substr($body_last_data[0]['record_time'], 11, 5); // 处理体重 $temporary_weight = explode(',',$body_last_data[0]['weight']); - $result_return['weight']['time'] = $record_time; - $result_return['weight']['value'] = $temporary_weight[0]; - $result_return['weight']['standard'] = $temporary_weight[1] == '无'?'':$temporary_weight[1]; - $result_return['weight']['standard_color'] = $temporary_weight[2] == '无'?'':$temporary_weight[2]; - $result_return['weight']['target_weight'] = $body_last_data[0]['target_weight']; + $result_return['top_list'][0]['time'] = $record_time; + $result_return['top_list'][0]['value'] = $temporary_weight[0]; + $result_return['top_list'][0]['standard'] = $temporary_weight[1] == '无'?'':$temporary_weight[1]; + $result_return['top_list'][0]['standard_color'] = $temporary_weight[2] == '无'?'':$temporary_weight[2]; + $result_return['top_list'][0]['target_weight'] = $body_last_data[0]['target_weight']; + $result_return['top_list'][0]['key_name'] = 'weight'; // 处理身高 $temporary_height = explode(',',$body_last_data[0]['height']); - $result_return['height']['time'] = $record_time; - $result_return['height']['value'] = $temporary_height[0]; - $result_return['height']['standard'] = $temporary_height[1] == '无'?'':$temporary_height[1]; - $result_return['height']['standard_color'] = $temporary_height[2] == '无'?'':$temporary_height[2]; + $result_return['top_list'][1]['time'] = $record_time; + $result_return['top_list'][1]['value'] = $temporary_height[0]; + $result_return['top_list'][1]['standard'] = $temporary_height[1] == '无'?'':$temporary_height[1]; + $result_return['top_list'][1]['standard_color'] = $temporary_height[2] == '无'?'':$temporary_height[2]; + $result_return['top_list'][1]['key_name'] = 'height'; // 处理BMI $temporary_bmi = explode(',',$body_last_data[0]['bmi']); - $result_return['bmi']['time'] = $record_time; - $result_return['bmi']['value'] = $temporary_bmi[0]; - $result_return['bmi']['standard'] = $temporary_bmi[1] == '无'?'':$temporary_bmi[1]; - $result_return['bmi']['standard_color'] = $temporary_bmi[2] == '无'?'':$temporary_bmi[2]; + $result_return['top_list'][2]['time'] = $record_time; + $result_return['top_list'][2]['value'] = $temporary_bmi[0]; + $result_return['top_list'][2]['standard'] = $temporary_bmi[1] == '无'?'':$temporary_bmi[1]; + $result_return['top_list'][2]['standard_color'] = $temporary_bmi[2] == '无'?'':$temporary_bmi[2]; + $result_return['top_list'][2]['key_name'] = 'bmi'; + + // 如果有心率 + + // 如果有头围 // 处理卡片数据 if($body_last_data[0]['record_type'] == 'by_hand_means'){ @@ -388,6 +790,7 @@ class Userbody extends Base{ 'unit'=>$this->merged_data[$value]['unit'], 'standard'=>'', 'standard_color'=>'', + 'key_name'=>$value, ]; }else{ // 分割数据 @@ -405,6 +808,7 @@ class Userbody extends Base{ 'unit'=>$this->merged_data[$value]['unit'], 'standard'=>$temporary_data_1[1], 'standard_color'=>$standard_color, + 'key_name'=>$value, ]; } } @@ -413,37 +817,8 @@ class Userbody extends Base{ return $this->msg($result_return); } public function body_report_detailed_action($data){ - $result_return = [ - 'weight'=>[ - "name"=>"体重", - 'time'=>'', - "value"=>"0", - "unit"=>"kg", - "standard"=>"", - "standard_color"=>"#77E46C", - 'target_weight'=>'0', - 'target_weight_unit'=>'kg' - ], - 'height'=>[ - "name"=>"身高", - 'time'=>'', - "value"=>"0", - "unit"=>"cm", - "standard"=>"", - "standard_color"=>"#FEA63D", - ], - 'bmi'=>[ - "name"=>"BMI", - 'time'=>'', - "value"=>"0", - "unit"=>"", - "standard"=>"", - "standard_color"=>"#FF8072", - ], - 'card_list'=>[ - - ], - ]; + $result_return = []; + $body_last_data = Db::query(" select Top 1 @@ -486,12 +861,14 @@ class Userbody extends Base{ if(count($body_last_data) <= 0){ return $this->msg($result_return); } + // return $this->msg($body_last_data); // 设置卡片顺序 $set_order = [ 'weight', //体重 - '', //心率 - '', //BMR 静态基础代谢 - 'BMI', //BMI + 'height', //身高 + // '', //心率 + // 'bmr', //BMR 静态基础代谢 + 'bmi', //BMI 'fat_r', //体脂率 'fat_w', //脂肪量 'muscle', //肌肉率 @@ -506,10 +883,299 @@ class Userbody extends Base{ 'body_level', //肥胖等级☆ 'body_age', //身体年龄☆ 'score', //身体得分☆ - ]; + $temporary_model = []; + foreach ($set_order as $key => $value) { + $temporary_model = []; + + if($value == 'body_type' || $value == 'body_level'){ + $temporary_model = $this->detailed_model_1; + $temporary_model['name'] = $this->merged_data[$value]['name']; + $temporary_model['value'] = ''; + $temporary_model['unit'] = ''; + $temporary_model['desc'] = $this->merged_data[$value]['description']; + $temporary_model['standard'] = $body_last_data[0][$value]; + $temporary_model['key_name'] = $value; + $result_return[] = $temporary_model; + }else if($value == 'weight' || $value == 'height' || $value == 'bmi'){ + $temporary_data_array = explode(',',$body_last_data[0][$value]); + $temporary_model = $this->detailed_model_1; + $temporary_model['name'] = $this->merged_data[$value]['name']; + $temporary_model['value'] = $temporary_data_array[0]; + $temporary_model['unit'] = $this->merged_data[$value]['unit']; + $temporary_model['desc'] = $this->merged_data[$value]['description']; + $temporary_model['standard'] = $temporary_data_array[1]; + $temporary_model['standard_color'] = $temporary_data_array[1] == '无'?'':$this->merged_data[$value]['list'][$temporary_data_array[1]]; + $temporary_model['list'] = $this->process_hwb_standard_action($body_last_data[0]['birthday'],$value,$body_last_data[0]['age'],$body_last_data[0]['gender']); + $temporary_model['key_name'] = $value; + $temporary_model['offset'] = $this->process_offset_action($temporary_data_array[0],$temporary_model['list']); + $result_return[] = $temporary_model; + }else if($value == 'score' || $value == 'body_age'){ + $temporary_model = $this->detailed_model_1; + $temporary_model['name'] = $this->merged_data[$value]['name']; + $temporary_model['value'] = $body_last_data[0][$value]; + $temporary_model['unit'] = $this->merged_data[$value]['unit']; + $temporary_model['desc'] = $this->merged_data[$value]['description']; + $temporary_model['key_name'] = $value; + $temporary_model['list'] = $this->process_other_standard_action($body_last_data[0],$value); + $temporary_model['offset'] = $this->process_offset_action($temporary_model['value'],$temporary_model['list']); + $temporary_model['standard'] = $this->process_special_offset_action($temporary_model['value'],$temporary_model['list'])['standard']; + $temporary_model['standard_color'] = $this->process_special_offset_action($temporary_model['value'],$temporary_model['list'])['standard_color']; + $result_return[] = $temporary_model; + }else{ + if($body_last_data[0]['record_type'] == 'by_device_adc'){ + $temporary_data_array = explode(',',$body_last_data[0][$value]); + $temporary_model = $this->detailed_model_1; + $temporary_model['name'] = $this->merged_data[$value]['name']; + $temporary_model['value'] = $temporary_data_array[0]; + $temporary_model['unit'] = $this->merged_data[$value]['unit']; + $temporary_model['desc'] = $this->merged_data[$value]['description']; + + $temporary_model['standard'] = array_key_exists(1,$temporary_data_array)?$temporary_data_array[1]:''; + // dump($temporary_model['standard']); + if($temporary_model['standard'] == ''){ + $temporary_model['standard_color'] = "#000000"; + }else if($temporary_model['standard'] == '异常'){ + $temporary_model['standard_color'] = "#FD5759"; + }else{ + $temporary_model['standard_color'] = $this->merged_data[$value]['list'][$temporary_data_array[1]]; + } + $temporary_model['list'] = $temporary_model['standard'] == ''?[]:$this->process_other_standard_action($body_last_data[0],$value); + // dump($value); + // dump($temporary_model['list']); + $temporary_model['key_name'] = $value; + $temporary_model['offset'] = $temporary_model['standard'] == ''?0:$this->process_offset_action($temporary_data_array[0],$temporary_model['list']); + if($temporary_model['standard'] == '异常'){ + $temporary_model = $this->handling_exceptions($temporary_model); + } + $result_return[] = $temporary_model; + }else{ + continue; + } + } + } + + return $this->msg($result_return); + } + // 用户身体数据卡片记录 + 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){ + // 如果阻抗大于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(10002); + } + + // 如果年纪小于三岁,处理头围数据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'=>'身体年龄' + ]; + + + // 根据秤传过来的数据,去处理要存的结果 + 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([]); + // 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 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); + } + } + @@ -518,8 +1184,367 @@ class Userbody extends Base{ ################################################################工具################################################################ ################################################################工具################################################################ - public function body_report_brief​_action_tool1($data){ + // 处理身高体重BMI的标准 + public function process_hwb_standard_action($birthday,$key_name,$age,$gender_val){ + $month_num = $this->calculateAgeInMonthsWithPrecision($birthday); + if($age < $this->age_limit){ + $result_data = $this->merged_data[$key_name]['standard_list']; + if($key_name == '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){ + $result_data[0]['max_val'] = $bhw_date[0]['f1sd']; + $result_data[0]['max_val'] = $bhw_date[0]['f1sd']; + $result_data[1]['min_val'] = $bhw_date[0]['f1sd']; + $result_data[1]['max_val'] = $bhw_date[0]['z1sd']; + $result_data[2]['min_val'] = $bhw_date[0]['z1sd']; + $result_data[2]['max_val'] = $bhw_date[0]['z2sd']; + $result_data[3]['min_val'] = $bhw_date[0]['z2sd']; + } + }else if($key_name == '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){ + $result_data[0]['max_val'] = $bhw_date[0]['f2sd']; + $result_data[1]['min_val'] = $bhw_date[0]['f2sd']; + $result_data[1]['max_val'] = $bhw_date[0]['f1sd']; + $result_data[2]['min_val'] = $bhw_date[0]['f1sd']; + $result_data[2]['max_val'] = $bhw_date[0]['z1sd']; + $result_data[3]['min_val'] = $bhw_date[0]['z1sd']; + $result_data[3]['max_val'] = $bhw_date[0]['z2sd']; + $result_data[4]['min_val'] = $bhw_date[0]['z2sd']; + $result_data[4]['max_val'] = $bhw_date[0]['z3sd']; + } + }else if($key_name == 'weight'){ + $bhw_date = Db::table($this->body_db_name['weigh'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + // dump($bhw_date); + if($bhw_date){ + $result_data[0]['max_val'] = $bhw_date[0]['f2sd']; + $result_data[1]['min_val'] = $bhw_date[0]['f2sd']; + $result_data[1]['max_val'] = $bhw_date[0]['f1sd']; + $result_data[2]['min_val'] = $bhw_date[0]['f1sd']; + $result_data[2]['max_val'] = $bhw_date[0]['z1sd']; + $result_data[3]['min_val'] = $bhw_date[0]['z1sd']; + $result_data[3]['max_val'] = $bhw_date[0]['z2sd']; + $result_data[4]['min_val'] = $bhw_date[0]['z2sd']; + $result_data[4]['max_val'] = $bhw_date[0]['z3sd']; + } + } + }else{ + $result_data = []; + } + return $result_data; + } + + // 处理其他的标注列表 + public function process_other_standard_action($data,$key_name){ + if($key_name == 'body_age'){ + $result_data = [ + ['min_val'=>'0','max_val'=>$data['age'],'text'=>'年轻','color'=>'#14CBAD'], //淡黄 + ['min_val'=>$data['age'],'max_val'=>bcadd(bcsub($data['age'],0,2),$data['age'],2),'text'=>'偏大','color'=>'#F53F31'], //绿 + ]; + }else if($key_name == 'score'){ + $result_data = $this->merged_data['score']['standard_list']; + }else{ + $gender_val = $data['gender'] == 2?'woman':'man'; + if($key_name == 'fat_r'){ + if($data['age'] < 30){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['29']; + }else{ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['30']; + } + }else if($key_name == 'fat_w'){ + if($data['age'] < 30){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['29']; + }else{ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['30']; + } + $result_data = $this->calculate_new_standard($result_data,$data['weight_val'],$key_name,$data['age'],$gender_val); + }else if($key_name == 'muscle' || $key_name == 'protein' || $key_name == 'water' || $key_name == 'sfr' || $key_name == 'visceral'){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]; + }else if($key_name == 'muscleval' || $key_name == 'proteinval'){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]; + $result_data = $this->calculate_new_standard($result_data,$data['weight_val'],$key_name,$data['age'],$gender_val); + }else if($key_name == 'bone'){ + if($gender_val == 'man'){ + if($data['weight_val'] < 60){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60']; + }else if($data['weight_val'] >= 60 && $data['weight_val'] < 75){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60_75']; + }else{ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['75']; + } + }else{ + if($data['weight_val'] < 45){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['45']; + }else if($data['weight_val'] >= 45 && $data['weight_val'] < 60){ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['45_60']; + }else{ + $result_data = $this->merged_data[$key_name]['standard_list'][$gender_val]['60']; + } + } + } + } + return $result_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 process_special_offset_action($val, $list) { + $return_data['standard'] = ''; + $return_data['standard_color'] = '#000000'; + if($val<$list[0]['min_val']){ + $return_data['standard'] = $list[0]['text']; + $return_data['standard_color'] = $list[0]['color']; + return $return_data; + } + + if($val>$list[count($list)-1]['max_val']){ + $return_data['standard'] = $list[count($list)-1]['text']; + $return_data['standard_color'] = $list[count($list)-1]['color']; + return $return_data; + } + foreach ($list as $key => $value) { + if($val >= $value['min_val'] && $val <= $value['max_val']){ + $return_data['standard'] = $value['text']; + $return_data['standard_color'] = $value['color']; + break; + } + } + return $return_data; + } + + // 计算新标准 + public function calculate_new_standard($data,$w,$k,$age=0,$gender='man'){ + $temporary_arr = []; + if($k != 'kcal'){ + foreach ($data as $key => $value) { + array_push($temporary_arr,[ + 'min_val'=>bcmul($w,bcdiv($value['min_val'],100,2),2), + 'max_val'=>bcmul($w,bcdiv($value['max_val'],100,2),2), + 'text'=>$value['text'], + 'color'=>$value['color'] + ]); + } + }else{ + // 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 == 'man'){ + $vv_val = bcsub(bcmul(60.9,$w,2),54,2); + }else{ + $vv_val = bcsub(bcmul(61.0,$w,2),51,2); + } + }else if($age >= 3 && $age < 10){ + if($gender == 'man'){ + $vv_val = bcadd(bcmul(22.7,$w,2),495,2); + }else{ + $vv_val = bcadd(bcmul(22.5,$w,2),499,2); + } + }else if($age >= 10 && $age < 18){ + if($gender == 'man'){ + $vv_val = bcadd(bcmul(17.5,$w,2),651,2); + }else{ + $vv_val = bcadd(bcmul(12.2,$w,2),746,2); + } + }else if($age >= 18 && $age < 30){ + if($gender == 'man'){ + $vv_val = bcadd(bcmul(15.3,$w,2),679,2); + }else{ + $vv_val = bcadd(bcmul(14.7,$w,2),496,2); + } + }else{ + if($gender == 'man'){ + $vv_val = bcadd(bcmul(11.6,$w,2),879,2); + }else{ + $vv_val = bcadd(bcmul(8.7,$w,2),820,2); + } + } + $data[0]['max_val'] = $vv_val; + $data[1]['min_val'] = $vv_val; + $temporary_arr = $data; + } + return $temporary_arr; + } + + // + 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->merged_data['height']['standard_list']; + $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->merged_data['weight']['standard_list']; + $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->merged_data['bmi']['standard_list']; + $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; + } + + // 处理异常 + public function handling_exceptions($data){ + for ($i=0; $i < count($data['list']); $i++) { + if($data['value']>=$data['list'][$i]['min_val'] && $data['value']<$data['list'][$i]['max_val']){ + $data['standard'] = $data['list'][$i]['text']; + $data['color'] = $data['list'][$i]['color']; + break; + } + } + if($data['standard'] == '异常'){ + if($data['value'] <= $data['list'][0]['min_val']){ + $data['standard'] = $data['list'][0]['text']; + $data['color'] = $data['list'][0]['color']; + }else if($data['value'] >= $data['list'][count($data['list'])-1]['max_val']){ + $data['standard'] = $data['list'][count($data['list'])-1]['text']; + $data['color'] = $data['list'][count($data['list'])-1]['color']; + } + } + return $data; } diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index d55c085..2a9cc74 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -635,6 +635,8 @@ class Card extends Base{ $result_end['score'] = $result_end['score']; $result_end['body_type'] = $result_end['body_type']; $result_end = $cardparts->conversion_interval($result_end); + // dump($result_end); + // die; $result_end['cplist'] = $this->grow_up_recommendation([ 'birthday'=>$result[0]['birthday'], 'body'=>[ @@ -668,6 +670,7 @@ class Card extends Base{ 'initial_date'=>$result[0]['initial_date']!=null?$result[0]['initial_date']:0, ]); // dump($result_end); + // dump($result_end); if(count($result_end['top_list'][2]['list']) <= 0){ // 这是16岁以上人群 $data = [ @@ -679,6 +682,7 @@ class Card extends Base{ $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true); // dump($temporary_arr_bmi_list); + // die; $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData(); // dump($temporary_arr_bmi_list); // die; @@ -688,10 +692,10 @@ class Card extends Base{ $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist']; $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset']; } - // dump($result_end); - // die; + } - + // dump($result_end); + // die; // 加入曲线板块底部的减肥计划数据end // 添加头围数据(如果有的话)start if($head_circumference !== false && $this->calculate_age($result[0]['birthday']) < 3){ diff --git a/application/app/controller/Cardparts.php b/application/app/controller/Cardparts.php index 5d42583..3d22d14 100644 --- a/application/app/controller/Cardparts.php +++ b/application/app/controller/Cardparts.php @@ -215,7 +215,15 @@ class Cardparts extends Base{ foreach ($temporary_arr['top_list'] as $key => $value) { if(count($value['list']) > 0){ - $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard'])[0]; + // dump($value['list']); + // dump($value['value']); + // dump($value['standard']); + + // dump($value['name']); + // dump($value['value']); + // dump($this->calculate_landing_point($value['list'],$value['value'],$value['standard'])); + $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($value['list'],$value['value'],$value['standard']); + // dump() } } // 如果是没有阻抗的测试,那么就不要底部的其他数据了 @@ -379,6 +387,9 @@ class Cardparts extends Base{ } } if(count($temporary_data) <= 0){ + if($val >= $data[count($data)-1]['max_val']){ + return 100; + } return 0; } // 加 bcadd(,,20) diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index ea520de..8eb2a06 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -451,10 +451,15 @@ class Index extends Base{ } } + // 从这里开始进入体脂还是体测的判断 $result['card_order'] = $result['card_order'] == ""?[]:explode(',',$result['card_order']); if($result['measure_model'] == 1){// 这里是体测 + // dump($result); + // die; $calculation_results = $this->get_user_card_data_list($result,$result['id']); + // dump($calculation_results); + // die; $result['card_data_list'] = $calculation_results[0]; $result['card_order'] = $calculation_results[1]; // dump($result); @@ -466,6 +471,7 @@ class Index extends Base{ $this->record_api_log($data, null, ['code'=>10001,'msg'=>'measure_model数据不是1或者2',[]]); return $this->msg(10004); } + // // 获取设备信息进入卡片 start // $likePattern = '%' . $result['aan_id'] . '%'; // $result_device = Db::table($this->index_use_db_name['4']) @@ -494,7 +500,7 @@ class Index extends Base{ if($result['head_data'] == null){ $result['head_data'] = 0; } - $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); + // $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); return $this->msg($result); } catch (\Exception $e) { // 捕获异常 @@ -740,7 +746,7 @@ class Index extends Base{ } } } - // dump($data); + $data['card_order'] = array_values($data['card_order']); // 获取卡片背景图,及背景色信息及其他信息 $card_all_data = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select(); @@ -748,6 +754,7 @@ class Index extends Base{ foreach ($card_all_data as $key => $value) { $card_all_data_result[$value['id']] = $value; } + // 获取卡片路径及卡片数组处理end // // 添加目标体重于当前体重差数据 // if(array_key_exists('2', $db_arr)){ @@ -766,31 +773,39 @@ class Index extends Base{ // ]); // } + if(count($db_arr) <= 0){ // 没有数据,传递一个空的卡片 + + // dump($data['card_order']); + // dump($card_all_data_result); foreach ($data['card_order'] as $key => $value) { - $temporary_arr = []; - $temporary_arr['id'] = ''; - $temporary_arr['acd_id'] = $value; - $temporary_arr['record_time'] = ''; - $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; - $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; - $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; - $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; - $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; - $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; - $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; - $temporary_arr['inside_data'] = []; - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - 'name'=>'最近一次', - 'value'=>"--", - 'unit'=>'', - 'standard'=>'*分', - 'color'=>'' - ]); - array_push($result,$temporary_arr); + if(array_key_exists($value,$card_all_data_result)){ + $temporary_arr = []; + $temporary_arr['id'] = ''; + $temporary_arr['acd_id'] = $value; + $temporary_arr['record_time'] = ''; + $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; + $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; + $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; + $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; + $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; + $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; + $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; + $temporary_arr['inside_data'] = []; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', + 'color'=>'' + ]); + array_push($result,$temporary_arr); + } } + + // die; }else{ foreach ($data['card_order'] as $key => $value) { $temporary_arr = []; diff --git a/application/app/controller/Language.php b/application/app/controller/Language.php index 8bf5b76..0114975 100644 --- a/application/app/controller/Language.php +++ b/application/app/controller/Language.php @@ -1,30 +1,20 @@ 'English', - 'zh' => '中文', - // 'es' => 'Spanish', - // 'fr' => 'French', - // 'pt' => 'Portuguese', - // 'ar' => 'Arabic', - // 'ru' => 'Russian', - // 'de' => 'German' + 'zh-Hans' => 'Chinese', + 'es' => 'Spanish', + 'fr' => 'French', + 'pt' => 'Portuguese', + 'ar' => 'Arabic', + 'ru' => 'Russian', + 'de' => 'German' ]; - // zh, //中文 - // en, // 英语 - // jp, //日语(变化) - // fra, //法语(变化) - // de, //德语 - // kor, //韩语(变化) - // ru, //俄语 - // pt, //葡萄牙 - // spa, //西班牙(变化) - // ara, //阿拉伯(变化) // 语言映射表 protected $languageMap = [ diff --git a/application/route.php b/application/route.php index 6e70780..157c2d9 100644 --- a/application/route.php +++ b/application/route.php @@ -660,7 +660,10 @@ Route::any('/kitchenscale3/register_action', 'app/kitchenscale3/app.login/regist Route::any('/kitchenscale3/login_action', 'app/kitchenscale3/app.login/login_action'); // 退出登录 Route::any('/kitchenscale3/user_quit_account', 'app/kitchenscale3/app.login/user_quit_account'); - +// 修改密码 +Route::any('/kitchenscale3/reset_password', 'app/kitchenscale3/app.login/reset_password'); +// 删除账户 +Route::any('/kitchenscale3/delete_account', 'app/kitchenscale3/app.login/delete_account'); // 首页内容################################################################ @@ -837,11 +840,19 @@ Route::any('/de/admin/device/device_all', 'app/DeviceEnter/admin.device/device_a // 检测是否已录入设备 Route::any('/de/check_device_msg', 'app/DeviceEnter/Appinterface/check_device_msg'); + + + + + ################################################################下面是新版reedaw(体侧+厨房秤)################################################################ ############################################################################################################################################################# ################################################################接口(API)################################################################ ################################################################登录注册部分(OK) +// 检测版本及判断是否登录失效 +Route::any('/reedaw/login_invalid_version', 'app/NewReedaw/app.index/login_invalid_version'); + // 注册账号 Route::any('/reedaw/register', 'app/NewReedaw/app.login/register'); // 登录账号 @@ -863,15 +874,127 @@ Route::any('/reedaw/config', 'app/NewReedaw/app.index/config'); // 获取角色列表 Route::any('/reedaw/get_user_list', 'app/NewReedaw/app.index/get_user_list'); - ################################################################首页(身体数据) // 角色报告(简要) Route::any('/reedaw/body_report_brief', 'app/NewReedaw/app.Userbody/body_report_brief'); // 角色报告(详细) Route::any('/reedaw/body_report_detailed', 'app/NewReedaw/app.Userbody/body_report_detailed'); +// 手动记录 +Route::any('/reedaw/manual_record', 'app/NewReedaw/app.Userbody/manual_record'); +// 设备记录 +Route::any('/reedaw/device_record', 'app/NewReedaw/app.Userbody/device_record'); +// 修改目标体重 +Route::any('/reedaw/set_target_weight', 'app/NewReedaw/app.Userbody/set_target_weight'); + +################################################################首页(饮食数据) +// 根据用户获取他的饮食信息 +// Route::any('/reedaw/user_diet_content', 'app/NewReedaw/app.Kitchenscale/user_diet_content'); +// 获取记食器板块内容 +Route::any('/reedaw/get_countfoot_content', 'app/NewReedaw/app.Kitchenscale/get_countfoot_content'); +// 修改角色信息 +Route::any('/reedaw/update_user_msg', 'app/NewReedaw/app.Kitchenscale/update_user_msg'); +// 搜索页面的默认信息数据 +Route::any('/reedaw/search_default_msg', 'app/NewReedaw/app.Kitchenscale/search_default_msg'); +// 搜索食材列表 +Route::any('/reedaw/get_food_list', 'app/NewReedaw/app.Kitchenscale/get_food_list'); +// 搜索食材列表 +Route::any('/reedaw/search_column', 'app/NewReedaw/app.Kitchenscale/search_column'); +// 查询食谱的详情 +Route::any('/reedaw/cookbook_details', 'app/NewReedaw/app.Kitchenscale/cookbook_details'); +// 点赞收藏菜谱 +Route::any('/reedaw/cookbook_like', 'app/NewReedaw/app.Kitchenscale/cookbook_like'); +// 点赞收藏菜谱 +Route::any('/reedaw/add_intake_food', 'app/NewReedaw/app.Kitchenscale/add_intake_food'); +// 获取记食器饮食记录 +Route::any('/reedaw/get_log_list', 'app/NewReedaw/app.Kitchenscale/get_log_list'); +// 设置角色营养比例 +Route::any('/reedaw/set_user_kcal', 'app/NewReedaw/app.Kitchenscale/set_nutrition_proportion'); +// 删除一条指定的饮食记录 +Route::any('/reedaw/del_user_eat_log', 'app/NewReedaw/app.Kitchenscale/del_user_eat_log'); +// 搜索历史删除 +Route::any('/reedaw/del_search_history', 'app/NewReedaw/app.Kitchenscale/del_search_history'); +// 设置角色营养比例 +Route::any('/reedaw/del_user_eat_list_log', 'app/NewReedaw/app.Kitchenscale/del_user_eat_list_log'); +// 我的收藏 +Route::any('/reedaw/get_user_collect_list', 'app/NewReedaw/app.Kitchenscale/get_user_collect_list'); +// 设置营养占比页面数据 +Route::any('/reedaw/set_up_content', 'app/NewReedaw/app.Kitchenscale/set_up_content'); +// 本次添加食材的营养统计 +Route::any('/reedaw/current_food_statistics', 'app/NewReedaw/app.Kitchenscale/current_food_statistics'); + + + + + + + + + + + + + + + + +// 使用国内轻厨记的 +################################################################首页(健康工具) +// 卡片列表 +Route::any('/reedaw/card_list_all', 'app/NewReedaw/app.Card/card_list_all'); +// 保存用户所选的卡片列表 +Route::any('/reedaw/save_card_list', 'app/NewReedaw/app.Card/save_card_list'); +// 角色卡片列表信息 +Route::any('/reedaw/user_card_list', 'app/NewReedaw/app.Card/user_card_list'); +// // BMI评测 +Route::any('/reedaw/bmi_evaluation', 'app/NewReedaw/app.Card/bmi_evaluation'); +// // 遗传身高 +Route::any('/reedaw/genetic_height', 'app/NewReedaw/app.Card/genetic_height'); +// ###############################跳绳部分 +// 手动记录 +Route::any('/reedaw/skip/manual_record', 'app/NewReedaw/app.skip/manual_record'); +// 设备记录 +Route::any('/reedaw/skip/device_record', 'app/NewReedaw/app.skip/device_record'); +// 上一次数据 +Route::any('/reedaw/skip/data_report', 'app/NewReedaw/app.skip/data_report'); +// 曲线 +Route::any('/reedaw/skip/curve_chart', 'app/NewReedaw/app.skip/curve_chart'); +// 历史记录(分页) +Route::any('/reedaw/skip/record_list_page', 'app/NewReedaw/app.skip/record_list_page'); +// 历史记录(分组) +Route::any('/reedaw/skip/record_list_group', 'app/NewReedaw/app.skip/record_list_group'); +// 历史记录(详细) +Route::any('/reedaw/skip/detailed_record', 'app/NewReedaw/app.skip/detailed_record'); +// 删除历史记录 +Route::any('/reedaw/skip/del_record', 'app/NewReedaw/app.skip/del_record'); + + + + +################################################################我的 +// 创建角色 +Route::any('/reedaw/add_member', 'app/NewReedaw/app.role/add_member'); +// 更新角色 +Route::any('/reedaw/update_member', 'app/NewReedaw/app.role/update_member'); +// 获取指定角色详细信息(含厨房秤的当日信息) +Route::any('/reedaw/get_user_data_information', 'app/NewReedaw/app.role/get_user_data_information'); +// 修改账号昵称 +Route::any('/reedaw/update_my_nickname', 'app/NewReedaw/app.role/update_my_nickname'); +// 获取账号信息 +Route::any('/reedaw/get_my_account_msg', 'app/NewReedaw/app.role/get_my_account_msg'); +// 邮箱/手机绑定 +Route::any('/reedaw/update_my_account_msg', 'app/NewReedaw/app.role/update_my_account_msg'); +// 修改密码 +Route::any('/reedaw/update_my_password', 'app/NewReedaw/app.role/update_my_password'); +// 修改账号信息 +Route::any('/reedaw/set_my_account_msg', 'app/NewReedaw/app.role/set_my_account_msg'); + + +// https://tc.pcxbc.comreedaw/pdate_my_nickname + + + -// 角色报告(详细) @@ -888,10 +1011,8 @@ Route::any('/reedaw/body_report_detailed', 'app/NewReedaw/app.Userbody/body_repo // Route::any('/reedaw/all_data_contrast', 'app/NewReedaw/app.index/all_data_contrast'); // ################################################################金刚区部分 -// // 遗传身高 -// Route::any('/reedaw/genetic_height', 'app/NewReedaw/app.index/genetic_height'); -// // BMI评测 -// Route::any('/reedaw/bmi_evaluation', 'app/NewReedaw/app.index/bmi_evaluation'); + + @@ -903,10 +1024,8 @@ Route::any('/reedaw/body_report_detailed', 'app/NewReedaw/app.Userbody/body_repo // ################################################################角色部分 -// // 创建角色 -// Route::any('/reedaw/add_member', 'app/NewReedaw/app.role/add_member'); -// // 更新角色 -// Route::any('/reedaw/update_member', 'app/NewReedaw/app.role/update_member'); + + // // 获取角色列表 // Route::any('/reedaw/role_list', 'app/NewReedaw/app.role/role_list'); // ################################################################卡片部分 @@ -946,23 +1065,7 @@ Route::any('/reedaw/body_report_detailed', 'app/NewReedaw/app.Userbody/body_repo // Route::any('/reedaw/vitalcapacity/detailed_record', 'app/NewReedaw/app.vitalcapacity/detailed_record'); // // 历史记录(详细) // Route::any('/reedaw/vitalcapacity/del_record', 'app/NewReedaw/app.vitalcapacity/del_record'); -// ################################################################跳绳部分 -// // 手动记录 -// Route::any('/reedaw/skip/manual_record', 'app/NewReedaw/app.skip/manual_record'); -// // 设备记录 -// Route::any('/reedaw/skip/device_record', 'app/NewReedaw/app.skip/device_record'); -// // 上一次数据 -// Route::any('/reedaw/skip/data_report', 'app/NewReedaw/app.skip/data_report'); -// // 曲线 -// Route::any('/reedaw/skip/curve_chart', 'app/NewReedaw/app.skip/curve_chart'); -// // 历史记录(分页) -// Route::any('/reedaw/skip/record_list_page', 'app/NewReedaw/app.skip/record_list_page'); -// // 历史记录(分组) -// Route::any('/reedaw/skip/record_list_group', 'app/NewReedaw/app.skip/record_list_group'); -// // 历史记录(详细) -// Route::any('/reedaw/skip/detailed_record', 'app/NewReedaw/app.skip/detailed_record'); -// // 历史记录(详细) -// Route::any('/reedaw/skip/del_record', 'app/NewReedaw/app.skip/del_record'); + // ################################################################跳绳部分 // // 获取单个地区数据 // Route::any('/reedaw/gf/get_single_data', 'app/NewReedaw/app.gufen/get_single_data');