diff --git a/application/KitchenScale2/controller/app/Base.php b/application/KitchenScale2/controller/app/Base.php index f02fd03..45c6be8 100644 --- a/application/KitchenScale2/controller/app/Base.php +++ b/application/KitchenScale2/controller/app/Base.php @@ -13,7 +13,8 @@ class Base extends Controller{ protected $base_use_db_name = [ '6'=>'app_account_number', 'search_history'=>'app_user_search_history', - 'foodlist4'=>'app_z_national_standard_food_type_4' + 'foodlist4'=>'app_z_national_standard_food_type_4', + 'user'=>'app_user_data' ]; protected $token_time = 30;//30天的秒数 protected $file_size = 5*1024*1024; @@ -152,6 +153,7 @@ class Base extends Controller{ // 判断token是否过期 public function token_time_validate($token){ // 591b70e0d80b5fa6d77e6e1384453ab9 + if(is_string($token)){ $length = strlen($token); if ($length < 10 ) { @@ -162,13 +164,12 @@ class Base extends Controller{ Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log'); return false; } - - $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find(); + $cfc = Db::connect('cfc_db'); + $user_login = $cfc->table($this->base_use_db_name['user'])->where(['token'=>$token])->field('id,login_time')->find(); if(!$user_login){ Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log'); return false; } - // 创建 DateTime 对象来表示指定的日期和时间 $specifiedDateTime = new \DateTime($user_login['login_time']); @@ -192,7 +193,7 @@ class Base extends Controller{ return false; } else { // echo "未超过 {$specifiedDays} 天"; - $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]); + $user_login = $cfc->table($this->base_use_db_name['user'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]); if($user_login){ Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log'); return true; @@ -335,25 +336,25 @@ class Base extends Controller{ $result = 0; switch ($unit) { - // case 'g': + case 'g': case '克': // 已经是克,直接返回 $result = $weight; break; - // case 'oz': + case 'oz': case '盎司': // 盎司转克 $result = bcmul($weight,$G_PER_OZ,2); break; - // case 'lb': + case 'lb': case '磅': // 磅转克 $result = bcmul($weight,$G_PER_LB,2); break; - // case 'lb:oz': + case 'lb:oz': case '磅:盎司': // 磅:盎司复合单位处理 if (strpos($weight, ':') !== false) { diff --git a/application/KitchenScale2/controller/app/Cookbook.php b/application/KitchenScale2/controller/app/Cookbook.php index 954bf48..4860ce3 100644 --- a/application/KitchenScale2/controller/app/Cookbook.php +++ b/application/KitchenScale2/controller/app/Cookbook.php @@ -461,36 +461,36 @@ class Cookbook extends Base{ // } } // 获取所有食谱label - public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ - // 尝试捕获异常 - try { - if(count(input('post.')) > 0){ - $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'); - } + // public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // // 尝试捕获异常 + // try { + // if(count(input('post.')) > 0){ + // $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'); + // } - $return_data = $this->get_cookbook_label_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'] .= "代码: " . $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' => '系统错误']); - } - } + // $return_data = $this->get_cookbook_label_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'] .= "代码: " . $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_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ @@ -1379,32 +1379,32 @@ class Cookbook extends Base{ 'content_list'=>$collect_list ]); } - public function get_cookbook_label_list_action(){ - $cfc = Db::connect('cfc_db'); - // 获取菜谱分类标签start - $cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label']) - ->where("is_del = 0") - ->field('id,name') - ->select(); - $temporary_label = []; - foreach ($cook_label as $key => $value) { - unset($cook_label[$key]['ROW_NUMBER']); - $cook_label[$key]['list'] = []; - $temporary_label[$value['id']] = $key; - } - $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) - ->alias('a') - ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT') - ->where(['a.is_del'=>0]) - ->field('a.id,a.cook_label,a.title,b.pic_url as cover') - ->select(); - foreach ($content_list as $key => $value) { - unset($content_list[$key]['ROW_NUMBER']); - array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]); - } - return $this->msg($cook_label); - // 获取菜谱分类标签end - } + // public function get_cookbook_label_list_action(){ + // $cfc = Db::connect('cfc_db'); + // // 获取菜谱分类标签start + // $cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label']) + // ->where("is_del = 0") + // ->field('id,name') + // ->select(); + // $temporary_label = []; + // foreach ($cook_label as $key => $value) { + // unset($cook_label[$key]['ROW_NUMBER']); + // $cook_label[$key]['list'] = []; + // $temporary_label[$value['id']] = $key; + // } + // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // ->alias('a') + // ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT') + // ->where(['a.is_del'=>0]) + // ->field('a.id,a.cook_label,a.title,b.pic_url as cover') + // ->select(); + // foreach ($content_list as $key => $value) { + // unset($content_list[$key]['ROW_NUMBER']); + // array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]); + // } + // return $this->msg($cook_label); + // // 获取菜谱分类标签end + // } public function get_search_food_page_list_action($data){ $cfc = Db::connect('cfc_db'); diff --git a/application/KitchenScale2/controller/app/Countfood.php b/application/KitchenScale2/controller/app/Countfood.php index 4bf3e70..4ecb9e9 100644 --- a/application/KitchenScale2/controller/app/Countfood.php +++ b/application/KitchenScale2/controller/app/Countfood.php @@ -279,6 +279,43 @@ class Countfood extends Base{ return json(['status' => 'error', 'message' => '系统错误']); } } + // 本次添加食材的营养统计 + public function current_food_statistics(){ + // 尝试捕获异常 + try { + $data = input('post.'); + + if(!array_key_exists('log_id', $data)){ + return $this->msg(10001,'log_id is miss'); + } + + 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' => '系统错误']); + } + } #######################################################################action####################################################################### #######################################################################action####################################################################### #######################################################################action####################################################################### @@ -1118,6 +1155,7 @@ class Countfood extends Base{ 'list'=>[ [ 'name'=>'碳水化合物', + 'key_v'=>'carbohydrate', 'icon'=>'icon-tanshuihuahewu', 'proportion'=>$nutrition_data['carbohydrate_p'], 'val'=>$nutrition_data['carbohydrate'], @@ -1125,6 +1163,7 @@ class Countfood extends Base{ ], [ 'name'=>'蛋白质', + 'key_v'=>'protein', 'icon'=>'icon-Sm-danbaizhi', 'proportion'=>$nutrition_data['protein_p'], 'val'=>$nutrition_data['protein'], @@ -1132,6 +1171,7 @@ class Countfood extends Base{ ], [ 'name'=>'脂肪', + 'key_v'=>'fat', 'icon'=>'icon-w_fat_normal', 'proportion'=>$nutrition_data['fat_p'], 'val'=>$nutrition_data['fat'], @@ -1182,76 +1222,111 @@ class Countfood extends Base{ } } + public function current_food_statistics_action($data){ + $id_arr = implode("','",$data['log_id']); + + $cfc = Db::connect('cfc_db'); + $user_data = $cfc->table($this->kitchenscale_db_msg['user']) + ->where(["token"=>$data['token']]) + ->field('weight,height,gender,age,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); + } + if($user_data['birthday']){ + $user_data['age_num'] = $this->calculate_age($user_data['birthday']); + }else{ + $user_data['age_num'] = $user_data['age']; + } + $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 = $cfc->table($this->kitchenscale_db_msg['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); + } + + + #######################################################################工具####################################################################### #######################################################################工具####################################################################### #######################################################################工具####################################################################### - // 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,'性别未知'); - // } - - // // 每日总能量消耗(TDEE) - // // 久坐(很少或没有运动):BMR × 1.2 - // // 轻度活动(每周1-3天轻度运动):BMR × 1.375 - // // 中度活动(每周3-5天中度运动):BMR × 1.55 - // // 高度活动(每周6-7天高强度运动):BMR × 1.725 - // // 极高活动(体力劳动或每天高强度训练):BMR × 1.9 - // $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 = bcdiv(bcmul($tdee,0.5,20),4,2); - // if($data['age_num'] < 65){ - // $protein = bcdiv(bcmul($tdee,0.2,20),4,2); - // $fat = bcdiv(bcmul($tdee,0.3,20),9,2); - // }else{ - // $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]; - // } - // public function calculateDateRange($n) { - // // 获取当前日期和时间 - // $today = new \DateTime(); - // // dump($today); - // // 计算结束时间:往前推 (10 * (n - 1)) 天,时间设为 23:59:59 - // $endInterval = new \DateInterval('P' . (10 * ($n - 1)) . 'D'); - // $endTime = clone $today; - // $endTime->sub($endInterval)->setTime(23, 59, 59); - - // // 计算开始时间:往前推 (10 * n) 天,时间设为 00:00:00 - // $startInterval = new \DateInterval('P' . (10 * $n) . 'D'); - // $startTime = clone $today; - // $startTime->sub($startInterval)->setTime(0, 0, 0); - - // return [ - // 's_time' => $startTime->format('Y-m-d H:i:s'), - // 'e_time' => $endTime->format('Y-m-d H:i:s'), - // ]; - // } // 计算每日每餐kcal占比 public function calculate_kcal_proportion($data){ diff --git a/application/KitchenScale2/controller/app/Index.php b/application/KitchenScale2/controller/app/Index.php index 567ec26..4f2276d 100644 --- a/application/KitchenScale2/controller/app/Index.php +++ b/application/KitchenScale2/controller/app/Index.php @@ -4,6 +4,7 @@ namespace app\KitchenScale2\controller\app; use think\Db; use app\KitchenScale2\controller\app\Guessyoulike; +use app\KitchenScale2\controller\app\Language; class Index extends Base{ @@ -36,6 +37,28 @@ class Index extends Base{ 'banner'=>'admin_notice_banner',//菜谱表 ]; + protected $language_country = [ + 'zh' => ['中文','zh'], // 中文(简体)★ + 'en' => ['English','en'], // 英语(通用)★ + 'jp' => ['日本語(Japanese)','ja'], // 日语(变化) + 'fra' => ['Français(French)','fr'], // 法语(变化) + 'de' => ['Deutsch(German)','de'], // 德语 + 'kor' => ['한국어(Korean)','ko'], // 韩语(变化) + 'ru' => ['Русский(Russian)','ru'], // 俄语 + 'pt' => ['Português(Portuguese)','pt'], // 葡萄牙 + 'spa' => ["Español(Spanish)",'es'], // 西班牙(变化) + 'ara' => ['Arabic(العربية)','ar'], // 阿拉伯(变化) + ]; + // zh, //中文 + // en, // 英语 + // jp, //日语(变化) + // fra, //法语(变化) + // de, //德语 + // kor, //韩语(变化) + // ru, //俄语 + // pt, //葡萄牙 + // spa, //西班牙(变化) + // ara, //阿拉伯(变化) // 加 bcadd(,,20) @@ -49,15 +72,46 @@ class Index extends Base{ // 检测版本及判断是否登录失效 public function login_invalid_version($data = ['token'=>'']){ try { + // 获取客户端IP + $ip = request()->ip(); + // 调用IP识别方法 + $region = $this->getIpInfo($ip); + // dump($region); + // 解析地区信息 + $regionParts = explode('|', $region); + $country = $regionParts[0] ?? ''; + // 判断国家是否在支持的语言列表中 + $language = ''; + if ($country && $country !== '0') { + $languageMap = [ + '中国' => 'zh', + '美国' => 'en', + '英国' => 'en', + '西班牙' => 'spa', + '法国' => 'fra', + '葡萄牙' => 'pt', + '阿拉伯联合酋长国' => 'ara', + '俄罗斯' => 'ru', + '德国' => 'de' + ]; + $language = $languageMap[$country] ?? ''; + } + // 检查语言是否在支持列表中 + $language_all = new Language(); + $isSupportedLanguage = array_key_exists($language, $language_all->getSupportedLanguages()); + + // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); } - // if(!array_key_exists('token', $data)){ - // return $this->msg(10001); - // } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } $cfc = Db::connect('cfc_db'); + $result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find(); + if($result){ $version = $result['version_num_original']; $url = $result['download_url']; @@ -65,13 +119,20 @@ class Index extends Base{ $version = ''; $url = ''; } + if($data['token'] == ''){ + return $this->msg(-2,'未登录',['version'=>$version,'url'=>$url,'language'=>'en']); + } + // dump($data); + $user_token_state = $this->token_time_validate($data['token']); + // dump($user_token_state); + $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language); + // dump($user_token_state); + // dump($language_data); - if($this->token_time_validate($data['token']) === false){ - $this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]); - return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]); + if($user_token_state['state'] === false){ + return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>$language_data]); }else{ - $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]); - return $this->msg(['version'=>$version,'url'=>$url]); + return $this->msg(['version'=>$version,'url'=>$url,'language'=>$language_data]); } } catch (\Exception $e) { @@ -82,12 +143,26 @@ class Index extends Base{ $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); } } + // 添加IP信息获取方法 + protected function getIpInfo($ip) { + // 默认IP + $ip = $ip ?: request()->ip(); + try { + $ip2region = new \Ip2Region(); + $info = $ip2region->memorySearch($ip); + // 返回国家信息 + return $info['region'] ?: '未知'; + } catch (\Exception $e) { + return '未知'; + } + } // 微信手机号快捷登录 public function wechat_quick_login($data = ['code'=>'asdasdasd','encryptedData'=>'adsadasdasd','iv'=>'asdasdasdasd']){ @@ -614,6 +689,7 @@ class Index extends Base{ ['name'=>'高度活动(每周6-7天高强度运动)','val'=>'1.725'], ['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'], ], + 'language_arr'=>$this->process_Language() ]; $cfc = Db::connect('cfc_db'); @@ -876,5 +952,25 @@ class Index extends Base{ } return $str; } + public function pd_language($user_language,$isSupportedLanguage,$language){ + if(!$user_language){ + if($isSupportedLanguage){ + $result = $language; + }else{ + $result = 'zh'; // 默认语言为中文 + } + }else{ + $result = $user_language; + } + return $result; + } + // 处理返回的语言数组 + public function process_Language(){ + $temporary_arr = []; + foreach ($this->language_country as $key => $value) { + array_push($temporary_arr,['name'=>$value[0],'val'=>$key,'key'=>$value[1]]); + } + return $temporary_arr; + } } \ No newline at end of file diff --git a/application/KitchenScale2/controller/app/Language.php b/application/KitchenScale2/controller/app/Language.php new file mode 100644 index 0000000..0fc01e6 --- /dev/null +++ b/application/KitchenScale2/controller/app/Language.php @@ -0,0 +1,240 @@ + 'English', + 'zh-Hans' => 'Chinese', + 'es' => 'Spanish', + 'fr' => 'French', + 'pt' => 'Portuguese', + 'ar' => 'Arabic', + 'ru' => 'Russian', + 'de' => 'German' + ]; + + // 语言映射表 + protected $languageMap = [ + 'en' => [ + '操作成功' => 'Success', + '关键参数缺失' => 'Required parameter missing', + '操作失败' => 'Operation failed', + '信息核实错误' => 'Information verification error', + '未找到有效数据' => 'No valid data found', + '参数格式错误' => 'Parameter format error', + '参数不能为空' => 'Parameter cannot be empty', + '参数错误' => 'Parameter error', + '自定义信息' => 'Custom message', + '登录失效' => 'Login invalid', + '网络异常,请稍后重试' => 'Network error, please try again later', + '年龄' => 'Age', + '岁' => '', + '无' => 'none', + '体重' => 'Weight', + '身高' => 'Height', + '消瘦' => 'Slim', + '正常' => 'Normal', + '偏重' => 'Overweight', + '肥胖' => 'Obesity', + '反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status", + '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors", + 'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.", + '公斤' => "kg", + 'CM' => "cm", + '年' => "-", + '月' => "-", + '日' => "", + '身体得分' => "Physical score", + '分' => "score", + '身体类型' => "body type", + '健美肌肉型' => "Bodybuilding muscle type", + '低' => "Low", + '偏低' => "Slightly low", + '标准' => "Standard", + '偏高' => "Slightly high", + '高' => "High", + '矮' => "Short", + '偏矮' => "Slightly short", + '脂肪率' => "Body Fat Percentage", + '体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.", + '脂肪量' => "Fat Mass", + '人体脂肪的重量' => "Body Fat Weight", + '肌肉率' => "Muscle Percentage", + '优' => "Excellent", + '根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.", + '肌肉量' => "Muscle Mass", + '不足' => "Insufficient", + '肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage", + '水分' => "Body Water", + '指人体内水分比例。' => "Refers to the proportion of water in the human body.", + '蛋白量' => "Protein Mass", + '蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage", + '骨重' => "Bone Mass", + '单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.", + '蛋白率' => "Protein Percentage", + '人体内蛋白率含量。' => "The proportion of protein in the human body.", + '基础代谢' => "Basal Metabolic Rate (BMR)", + '指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.", + '内脏指数' => "Visceral Fat Index", + '警惕' => "Caution", + '危险' => "Danger", + '内脏脂肪指数' => "Visceral Fat Level", + '皮下脂肪' => "Subcutaneous Fat", + '皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.", + '肥胖等级' => "Obesity Level", + '体重不足' => "Underweight", + '肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.", + '孩子可能存在营养不良:对于处在生长发育期的孩子而言,蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.", + '孩子可能存在营养不良:对于处在生长发育期的孩子而言,最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.", + '坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.", + '3-7岁的孩子:骑两轮车、拍踢球、打篮球、游泳、爬山,每天高强度运动不超过30分钟。' => "Ages 3–7: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.", + '该年龄段睡眠时间建议:9-11小时' => "Recommended sleep duration for this age group: 9–11 hours.", + '孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'I’m always here for you,' 'I see your progress').", + '《中华人民共和国卫生行业标准WS/T 423-2022》' => "《Chinese Health Industry Standard WS 423-2022》", + '《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》", + '《中华人民共和国卫生行业标准WS/T 586-2018》' => "《Chinese Health Industry Standard WS/T 586-2018》", + '《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》", + '头围' => "Head Circumference", + '头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.", + '心率' => "Heart rate", + '过缓' => "Too slow", + '过速' => "Too fast", + '心率变化与心脏疾病密切相关,请随时关注心率变化情况,尤其是运动时期。' => "Heart rate changes are closely related to heart disease, please keep an eye on heart rate changes, especially during exercise.", + '心率图' => "heart rate chart", + '第1次' => "1st", + '第2次' => "2nd", + '第3次' => "3rd", + '第4次' => "4th", + '第5次' => "5th", + '第6次' => "6th", + '第7次' => "7th", + '第8次' => "8th", + '第9次' => "9th", + '第10次' => "10th", + '第11次' => "11th", + '第12次' => "12th", + + ], + // 可以添加更多语言映射 + ]; + /** + * 处理多国语言翻译 + * + * @param string $language 目标语言代码 + * @param mixed $data 要翻译的数据(字符串或数组) + * @return mixed 翻译后的数据 + */ + public function handling_languages_from_multiple_countries($language, $data) + { + + // dump($data); + // 验证语言是否支持 + if (!$this->isLanguageSupported($language)) { + return $this->msg($data['data']); + } + + // 如果是数组,递归处理每个元素 + if (is_array($data)) { + // dump(2); + $data = $this->translateArray($language, $data); + return $this->msg($data['data']); + } + + // 如果是字符串,直接翻译 + if (is_string($data)) { + // dump(3); + return $this->translateString($language, $data); + } + + // dump($data); + // 其他类型直接返回 + return $this->msg($data['data']); + } + + /** + * 检查语言是否支持 + * + * @param string $language 语言代码 + * @return bool + */ + protected function isLanguageSupported($language) + { + return isset($this->supportedLanguages[$language]); + } + + /** + * 翻译数组 + * + * @param string $language 目标语言 + * @param array $array 要翻译的数组 + * @return array 翻译后的数组 + */ + protected function translateArray($language, array $array) + { + $result = []; + foreach ($array as $key => $value) { + // 保持键不变,只翻译值 + $result[$key] = is_array($value) + ? $this->translateArray($language, $value) + : $this->translateString($language, $value); + } + return $result; + } + + /** + * 翻译字符串 + * + * @param string $language 目标语言 + * @param string $string 要翻译的字符串 + * @return string 翻译后的字符串 + */ + protected function translateString($language, $string) + { + // dump($string); + // 检查是否有该语言的映射表 + if (!isset($this->languageMap[$language])) { + return $string; + } + + // 检查是否有对应的翻译 + return $this->languageMap[$language][$string] ?? $string; + } + + /** + * 获取支持的语言列表 + * + * @return array + */ + public function getSupportedLanguages() + { + return $this->supportedLanguages; + } + + /** + * 添加新的语言翻译 + * + * @param string $language 语言代码 + * @param array $translations 翻译映射数组 + * @return bool + */ + public function addTranslations($language, array $translations) + { + if (!$this->isLanguageSupported($language)) { + return false; + } + + if (!isset($this->languageMap[$language])) { + $this->languageMap[$language] = []; + } + + $this->languageMap[$language] = array_merge( + $this->languageMap[$language], + $translations + ); + + return true; + } +} \ No newline at end of file diff --git a/application/KitchenScale2/controller/app/Usercenter.php b/application/KitchenScale2/controller/app/Usercenter.php index d8135a6..cce7243 100644 --- a/application/KitchenScale2/controller/app/Usercenter.php +++ b/application/KitchenScale2/controller/app/Usercenter.php @@ -29,6 +29,18 @@ class Usercenter extends Base{ 'business_cooperation'=>'app_business_cooperation_log',//商务合作 'eat_log'=>'app_user_kcal_log',//食材列表3 ]; + protected $language_country = [ + 'zh' => '中文', // 中文(简体)★ + 'en' => 'English', // 英语(通用)★ + 'jp' => '日本語', // 日语(变化) + 'fra' => 'Français', // 法语(变化) + 'de' => 'Deutsch', // 德语 + 'kor' => '한국어', // 韩语(变化) + 'ru' => 'Русский', // 俄语 + 'pt' => 'Português', // 葡萄牙 + 'spa' => 'Español', // 西班牙(变化) + 'ara' => 'العربية', // 阿拉伯(变化) + ]; // 加 bcadd(,,20) @@ -451,6 +463,40 @@ class Usercenter extends Base{ return $this->msg(99999); } } + + public function update_language(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001,'token is miss'); + } + if(!array_key_exists('language', $data)){ + return $this->msg(10001,'language is miss'); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005,'token type is error'); + } + if(!array_key_exists($data['language'],$this->language_country)){ + return $this->msg(10005,'language type is error'); + } + + $return_data = $this->update_language_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); + } + } @@ -826,6 +872,15 @@ class Usercenter extends Base{ } } + public function update_language_action($data){ + $cfc = Db::connect('cfc_db'); + $result = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->update(['language'=>$data['language']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg([10002]); + } + } diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index 217ac51..459125e 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -576,14 +576,14 @@ class Base extends Controller{ if (is_string($data)) { return true; } else { - $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + // $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); return false; } }else if($type == 'num'){ if (is_numeric($data)) { return true; } else { - $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + // $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); return false; } }else if($type == 'intnum'){ @@ -591,7 +591,7 @@ class Base extends Controller{ if (preg_match($pattern, $data)) { return true; // 匹配成功,返回 true } else { - $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + // $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); return false; // 匹配失败,返回 false } }else if($type == 'datetime'){ @@ -604,7 +604,7 @@ class Base extends Controller{ } } // 如果所有格式都解析失败,则返回 false - $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + // $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); return false; }else if($type == 'other'){ diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index e25d07a..d55c085 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -5,6 +5,7 @@ namespace app\app\controller; use think\Db; use app\app\controller\Calculatebody; use app\app\controller\Cardparts; +use app\app\controller\Xinlv; class Card extends Base{ @@ -97,6 +98,12 @@ class Card extends Base{ if(!array_key_exists('aud_id', $data)){ return $this->msg(10001); } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ return $this->msg(10005); } @@ -537,6 +544,7 @@ class Card extends Base{ acbd.bmi, acbd.body_age, acbd.head_circumference, + acbd.heart_rate, aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date from ".$this->card_use_db_name['1']." as acbd left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id=aud.id @@ -608,6 +616,7 @@ class Card extends Base{ 'cumulative_weight'=>'0', 'cumulative_day'=>'0' ], + 'heart_rate_data'=>[], ]; return $this->msg($result_return); }else{ @@ -752,6 +761,19 @@ class Card extends Base{ } // 这段业务处理可以删除,是做的临时的,假的end + + // 处理返回的心率数据start + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + if($result[0]['heart_rate'] != '' || $result[0]['heart_rate'] != null){ + // dump($result[0]['heart_rate']); + $xinlv_ac = new Xinlv; + $heart_rate_data = $xinlv_ac->heart_rate_details($result[0]['heart_rate']); + array_push($result_end['top_list'],$heart_rate_data); + } + // 处理返回的心率数据start return $this->msg($result_end); } @@ -1168,6 +1190,24 @@ class Card extends Base{ $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']); } + + // 处理心率数据start + if(array_key_exists('heart_rate_data', $data)){ + if(!is_array($data['heart_rate_data'])){ + $set_data['heart_rate'] = ''; + }else{ + foreach ($data['heart_rate_data'] as $key => $value) { + if(!$this->verify_data_is_ok($value,'num')){ + $data['heart_rate_data'][$key] = 0; + } + } + $set_data['heart_rate'] = implode(',',$data['heart_rate_data']); + } + }else{ + $set_data['heart_rate'] = ''; + } + // 处理心率数据end + // 启动事务 Db::startTrans(); try{ diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 3506ee0..ea520de 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -102,7 +102,7 @@ class Index extends Base{ ################################################################个人资料卡################################################################ // 检测版本及判断是否登录失效 - public function login_invalid_version($data = ['token'=>'2d4ea9b3f44b169ddf64b2f3d2725ceb']){ + public function login_invalid_version($data = ['token'=>'']){ try { // 获取客户端IP $ip = request()->ip(); @@ -146,6 +146,10 @@ class Index extends Base{ $version = ''; $url = ''; } + if($data['token'] == ''){ + return $this->msg(-2,'未登录',['version'=>$version,'url'=>$url,'language'=>'zh-Hans','language_arr'=>$this->process_Language()]); + } + $user_token_state = $this->token_time_validate($data['token']); $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language); @@ -421,7 +425,7 @@ class Index extends Base{ // 获取指定用户详细信息 public function get_user_data_information($data = ['aud_id'=>61]){ - // try { + try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); @@ -492,19 +496,19 @@ class Index extends Base{ } $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); return $this->msg($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); - // } + } 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); + } } diff --git a/application/app/controller/Language.php b/application/app/controller/Language.php index 2e607c2..8bf5b76 100644 --- a/application/app/controller/Language.php +++ b/application/app/controller/Language.php @@ -1,20 +1,30 @@ 'English', - 'zh-Hans' => 'Chinese', - 'es' => 'Spanish', - 'fr' => 'French', - 'pt' => 'Portuguese', - 'ar' => 'Arabic', - 'ru' => 'Russian', - 'de' => 'German' + 'zh' => '中文', + // 'es' => 'Spanish', + // 'fr' => 'French', + // 'pt' => 'Portuguese', + // 'ar' => 'Arabic', + // 'ru' => 'Russian', + // 'de' => 'German' ]; + // zh, //中文 + // en, // 英语 + // jp, //日语(变化) + // fra, //法语(变化) + // de, //德语 + // kor, //韩语(变化) + // ru, //俄语 + // pt, //葡萄牙 + // spa, //西班牙(变化) + // ara, //阿拉伯(变化) // 语言映射表 protected $languageMap = [ @@ -99,6 +109,23 @@ class Language extends Base '《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》", '头围' => "Head Circumference", '头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.", + '心率' => "Heart rate", + '过缓' => "Too slow", + '过速' => "Too fast", + '心率变化与心脏疾病密切相关,请随时关注心率变化情况,尤其是运动时期。' => "Heart rate changes are closely related to heart disease, please keep an eye on heart rate changes, especially during exercise.", + '心率图' => "heart rate chart", + '第1次' => "1st", + '第2次' => "2nd", + '第3次' => "3rd", + '第4次' => "4th", + '第5次' => "5th", + '第6次' => "6th", + '第7次' => "7th", + '第8次' => "8th", + '第9次' => "9th", + '第10次' => "10th", + '第11次' => "11th", + '第12次' => "12th", ], // 可以添加更多语言映射 diff --git a/application/app/controller/Msginformation.php b/application/app/controller/Msginformation.php index 13dd7b2..9989805 100644 --- a/application/app/controller/Msginformation.php +++ b/application/app/controller/Msginformation.php @@ -8,7 +8,7 @@ use think\Db; class Msginformation extends Base{ - protected $judge_wechat_release = false; + protected $judge_wechat_release = true; protected $msginformation_use_db_name = [ '1'=>'admin_editor_text_content', @@ -536,9 +536,9 @@ class Msginformation extends Base{ ################################################################小工具################################################################ // 判断微信发版工具 - public function judge_wechat_release(){ + // public function judge_wechat_release(){ - } + // } } \ No newline at end of file diff --git a/application/app/controller/Myinformation.php b/application/app/controller/Myinformation.php index 69c9574..9452b54 100644 --- a/application/app/controller/Myinformation.php +++ b/application/app/controller/Myinformation.php @@ -20,7 +20,7 @@ class Myinformation extends Base{ ################################################################接口################################################################ // 获取账号下信息 - public function get_my_account_msg($data = ['token'=>'e0966788d02cc93290d9d674921d9715']){ + public function get_my_account_msg($data = ['token'=>'']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -29,6 +29,9 @@ class Myinformation extends Base{ 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); } diff --git a/application/app/controller/Xinlv.php b/application/app/controller/Xinlv.php new file mode 100644 index 0000000..cb1ce1e --- /dev/null +++ b/application/app/controller/Xinlv.php @@ -0,0 +1,204 @@ +'app_heart_rate_log', + ]; + + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + public function heart_rate_save_data(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001,'token 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('heart_rate_data', $data)){ + return $this->msg(10001,'heart_rate_data is miss'); + } + if(!array_key_exists('aud_id', $data)){ + return $this->msg(10001,'aud_id is miss'); + } + if(!array_key_exists('adc', $data)){ + return $this->msg(10001,'adc 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($data['height'] == ''){ + $data['height'] = 0; + } + if($data['weight'] == ''){ + $data['weight'] = 0; + } + if(!is_array($data['heart_rate_data'])){ + return $this->msg(10005,'heart_rate_data type is error'); + } + if(!$this->verify_data_is_ok($data['adc'],'num')){ + $data['adc'] = 0; + } + $return_data = $this->heart_rate_save_data_action($data); + // 成功 + // $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + + + #################################################################action############################################################################## + #################################################################action############################################################################## + #################################################################action############################################################################## + + public function heart_rate_save_data_action($data){ + // dump($data); + // die; + foreach ($data['heart_rate_data'] as $key => $value) { + if(!$this->verify_data_is_ok($value,'num')){ + $data['heart_rate_data'][$key] = 0; + } + } + $heart_rate_data = implode(',',$data['heart_rate_data']); + $data['height'] = $this->getNumber($data['height']); + $data['weight'] = $this->getNumber($data['weight']); + // dump($data); + // die; + $result = Db::table($this->db_name['xinlv'])->insert([ + 'token'=>$data['token'], + 'aud_id'=>$data['aud_id'], + 'height'=>$data['height'], + 'weight'=>$data['weight'], + 'heart_rate'=>$heart_rate_data, + 'adc'=>$data['adc'], + 'create_time'=>date('Y-m-d H:i:s') + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + + public function heart_rate_details($data){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + $data_map = [ + ['min_val'=>'0','max_val'=>'60','text'=>'过缓','color'=>'#D0873A'], + ['min_val'=>'60','max_val'=>'100','text'=>'正常','color'=>'#40A980'], + ['min_val'=>'100','max_val'=>'220','text'=>'过速','color'=>'#DF4841'] + ]; + $heart_rate_v = 0; + $data = explode(',',$data); + foreach ($data as $key => $value) { + $heart_rate_v = bcadd($heart_rate_v,$value,20); + } + $heart_rate_v = bcdiv($heart_rate_v,count($data),0); + $result = [ + "name"=>"心率", + "value"=>$heart_rate_v, + "unit"=>"", + "standard"=>"", + "color"=>"", + "list"=>$data_map, + "key_name"=>"heart_rate_data", + "desc"=>"心率变化与心脏疾病密切相关,请随时关注心率变化情况,尤其是运动时期。", + "offset"=>"0", + "standard_val"=>"", + "difference_val"=>"", + ]; + foreach ($data_map as $key => $value) { + if($heart_rate_v > $value['min_val'] && $heart_rate_v <= $value['max_val']){ + $result['standard'] = $value['text']; + $result['color'] = $value['color']; + + // 计算数值与区间最小值差多少 + $offset_min = bcsub($heart_rate_v,$value['min_val'],20); + // 计算出区间是多少 + $offset_max = bcsub($value['max_val'],$value['min_val'],20); + // 算出来在区间占比多少 + $offset = bcdiv($offset_min,$offset_max,20); + if($key = 2){ + $offset = bcmul(0.34,$offset,20); + $offset = bcadd($offset,0.66,2); + }else if($key = 1){ + $offset = bcmul(0.33,$offset,20); + $offset = bcadd($offset,0.33,2); + }else{ + $offset = bcmul(0.33,$offset,20); + } + $result['offset'] = bcmul($offset,100,0); + } + } + + if($heart_rate_v > $data_map[2]['max_val']){ + $result['standard'] = '危险'; + $result['color'] = '#DF4841'; + $result['offset'] = '100'; + } + $result['curve_chart'] = [ + 'title' => '心率图', + 'key' => 'heart_rate_data', + 'line' => [ + 'categories' => [ + + ], + 'series' => [ + [ + 'color'=>'#D0873A', + 'data'=>[], + ] + ], + ], + ]; + foreach ($data as $key => $value) { + $result['curve_chart']['line']['categories'][] = '第'.($key+1).'次'; + $result['curve_chart']['line']['series'][0]['data'][] = $value; + } + return $result; + } + + + #################################################################工具############################################################################## + #################################################################工具############################################################################## + #################################################################工具############################################################################## + + public function getNumber($str) { + // 匹配所有数字(包括小数) + preg_match('/\d+\.?\d*/', (string)$str, $matches); + return isset($matches[0]) ? (float)$matches[0] : 0; + } + + +} \ No newline at end of file diff --git a/application/route.php b/application/route.php index 319fbdb..3c16c4c 100644 --- a/application/route.php +++ b/application/route.php @@ -338,6 +338,13 @@ Route::any('/testedition/vitalcapacity_data_report', 'testapp/vitalcapacity/vita // 曲线 Route::any('/vitalcapacity_curve_chart', 'app/vitalcapacity/vitalcapacity_curve_chart'); Route::any('/testedition/vitalcapacity_curve_chart', 'testapp/vitalcapacity/vitalcapacity_curve_chart'); +// ################################心率接口################################ +// 记录数据 +Route::any('/heart_rate_save_data', 'app/xinlv/heart_rate_save_data'); +// 报告数据(上次数据) +Route::any('/heart_rate_details', 'app/xinlv/heart_rate_details'); +// // 报告数据(上次数据) +// Route::any('/vitalcapacity_data_report', 'app/vitalcapacity/vitalcapacity_data_report'); // ################################估分接口################################ // 获取类型列表 Route::any('/sportstesting_get_type_list', 'app/sportstesting/sportstesting_get_type_list'); @@ -478,7 +485,7 @@ Route::any('/kitchenscale2/pic_upload_action', 'app/kitchenscale2/app.base/pic_u // 首页内容################################################################ // 检测版本及判断是否登录失效 Route::any('/kitchenscale/login_invalid_version', 'app/Kitchenscale/app.Index/login_invalid_version'); -Route::any('/testedition/kitchenscale/login_invalid_version', 'app/kitchenscale/testapp.index/login_invalid_version'); +Route::any('/kitchenscale2/login_invalid_version', 'app/kitchenscale2/app.Index/login_invalid_version'); // 获取配置类信息 Route::any('/kitchenscale/get_default_config', 'app/Kitchenscale/app.Index/get_default_config'); Route::any('/kitchenscale2/get_default_config', 'app/Kitchenscale2/app.Index/get_default_config'); @@ -549,6 +556,10 @@ Route::any('/kitchenscale2/del_user_eat_log', 'app/kitchenscale/app.countfood/de // 删除用户某个饮食记录 // Route::any('/kitchenscale/del_user_eat_list_log', 'app/kitchenscale/app.countfood/del_user_eat_list_log'); Route::any('/kitchenscale2/del_user_eat_list_log', 'app/kitchenscale2/app.countfood/del_user_eat_list_log'); +// 获取指定饮食记录的四大营养分析 +// Route::any('/kitchenscale/current_food_statistics', 'app/kitchenscale/app.countfood/current_food_statistics'); +Route::any('/kitchenscale2/current_food_statistics', 'app/kitchenscale2/app.countfood/current_food_statistics'); + @@ -587,6 +598,8 @@ Route::any('/kitchenscale2/update_my_password', 'app/kitchenscale2/app.usercente // ☆修改个人信息 Route::any('/kitchenscale/update_my_account_msg', 'app/kitchenscale/app.usercenter/update_my_account_msg'); Route::any('/kitchenscale2/update_my_account_msg', 'app/kitchenscale2/app.usercenter/update_my_account_msg'); +// ☆修改语言设置(多语言) +Route::any('/kitchenscale2/update_language', 'app/kitchenscale2/app.usercenter/update_language'); @@ -858,6 +871,34 @@ Route::any('/download_picture_api', 'test/testuse/download_picture_api'); Route::any('/update_cookbook_data_api', 'test/testuse/update_cookbook_data_api'); Route::any('/cun_bendi_pic', 'test/testuse/cun_bendi_pic'); +// 百度翻译 +Route::any('/translateDemo', 'test/baidufanyi/translateDemo'); +Route::any('/baidufanyi/congli_fanyi', 'test/baidufanyi/congli_fanyi'); + + +// 洗数据,国外食材 +Route::any('/xishuju1/wash_step1', 'test/xishuju1/wash_step1'); +Route::any('/xishuju1/xishuju1_qd_page', 'test/xishuju1/xishuju1_qd_page'); +Route::any('/xishuju1/xishuju1_action', 'test/xishuju1/xishuju1_action'); +Route::any('/xishuju1/xishuju2_action', 'test/xishuju1/xishuju2_action'); +Route::any('/xishuju1/xishuju3_action', 'test/xishuju1/xishuju3_action'); +Route::any('/xishuju1/error_action', 'test/xishuju1/error_action'); +Route::any('/xishuju1/look_food_data', 'test/xishuju1/look_food_data'); +Route::any('/xishuju1/next_pass_action', 'test/xishuju1/next_pass_action'); + + +Route::any('/xishuju1/new_step1_action', 'test/xishuju1/new_step1_action'); + + + + + + + + + + + @@ -869,7 +910,7 @@ Route::any('/cun_bendi_pic', 'test/testuse/cun_bendi_pic'); // Route::any('/app_update_file/*', 'app/sportstesting/aaaaaaaaaaaaaaa'); // 处理404错误 z -Route::miss(function(){ - return '404 Not Found(out)'; - // 或者你可以重定向到一个错误页面,或者进行其他处理 -}); +// Route::miss(function(){ +// return '404 Not Found(out)'; +// // 或者你可以重定向到一个错误页面,或者进行其他处理 +// }); diff --git a/application/test/controller/Baidufanyi.php b/application/test/controller/Baidufanyi.php new file mode 100644 index 0000000..a8898ff --- /dev/null +++ b/application/test/controller/Baidufanyi.php @@ -0,0 +1,337 @@ + $q, + 'from' => $from, + 'to' => $to, + ]; + + // 合并可选参数 + $optional_params = ['needIntervene', 'model_type', 'reference', 'tag_handling', 'ignore_tags']; + foreach ($optional_params as $param) { + if (isset($options[$param]) && $options[$param] !== '') { + $data[$param] = $options[$param]; + } + } + + // 发送请求 + $result = $this->httpPost($data); + + // 解析结果 + $result_array = json_decode($result, true); + + if (isset($result_array['error_code'])) { + // 翻译失败 + // Log::error('百度翻译API错误:' . json_encode($result_array, JSON_UNESCAPED_UNICODE)); + return [ + 'success' => false, + 'error_code' => $result_array['error_code'], + 'error_msg' => $result_array['error_msg'] ?? '翻译失败', + 'data' => null + ]; + } else { + // 翻译成功 + return [ + 'success' => true, + 'error_code' => 0, + 'error_msg' => '', + 'data' => $result_array + ]; + } + + } catch (\Exception $e) { + // Log::error('百度翻译异常:' . $e->getMessage()); + return [ + 'success' => false, + 'error_code' => '500', + 'error_msg' => '系统异常:' . $e->getMessage(), + 'data' => null + ]; + } + } + + /** + * 发送HTTP POST请求 + * @param array $data 请求数据 + * @return string + */ + private function httpPost($data) + { + $ch = curl_init(); + $data['appid'] = '20251205002512839'; + // 设置cURL选项 + curl_setopt($ch, CURLOPT_URL, $this->api_url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_UNICODE)); + curl_setopt($ch, CURLOPT_HTTPHEADER, [ + 'Content-Type: application/json', + 'Authorization: Bearer ' . $this->api_key + ]); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 10秒超时 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + + $response = curl_exec($ch); + $error = curl_error($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + curl_close($ch); + + if ($error) { + throw new \Exception('cURL错误:' . $error); + } + + if ($httpCode != 200) { + throw new \Exception('HTTP请求失败,状态码:' . $httpCode); + } + + return $response; + } + + /** + * 使用示例 + */ + public function translateDemo() + { + + // 英语:en,德语:de,日语:jp,韩语:kor,阿拉伯语:ara,葡萄牙:pt,西班牙:spa,俄语:ru,法语:fra + // 示例1:基本翻译 + $result1 = $this->baiduTranslate('Beans, Dry, Dark Red Kidney (0% moisture)', 'en', 'zh'); + // $result1 = $this->baiduTranslate('HUNTS ', 'en', 'zh'); + + dump($result1); + + // // 示例2:带可选参数的翻译 + // $result2 = $this->baiduTranslate('Apples, gala, with skin, raw', 'en', 'zh', [ + // 'model_type' => 'nmt', + // 'reference' => '使用学术风格翻译' + // ]); + // dump($result2); + + // $result3 = $this->baiduTranslate('Tomatoes, diced, canned, HUNTS (CA) - NFY120AB9', 'en', 'zh'); + // dump($result3); + + // 示例3:获取翻译结果 + if ($result1['success']) { + $translated_text = ''; + if (isset($result1['data']['trans_result'][0]['dst'])) { + $translated_text = $result1['data']['trans_result'][0]['dst']; + } + echo "翻译结果:" . $translated_text; + } else { + echo "翻译失败:" . $result1['error_msg']; + } + } + + public function fanyi_action($data,$from,$to) + { + + $result = $this->baiduTranslate($data, $from, $to); + return $result; + } + + + + public function congli_fanyi(){ + $congli = '{ + "tips": { + "msgTitle": "友情提示", + "msgUpgradeFail": "升级失败", + "msgDownloading": "正在下载", + "msgLatestVersion": "已经是最新版本了!", + "msgCancel": "您已取消操作!", + "msgLoginSuccess": "登录成功!", + "msgDelete": "删除成功", + "msgSetSuccess": "设置成功", + "msgBottom": "到底了,看看别的吧", + "msgNoMoreData": "没有更多数据了!", + "msgSetPasswordSuccess": "密码设置成功,进入程序中!", + "msgAddUser": "暂无成员,请先添加", + "verifyNickName": "请输入昵称", + "verifyNotOptional": "未来日期不可选", + "verifyDate": "请选择测量日期", + "verifyBirthday": "请选择出生日期", + "verifyHeight": "请输入身高", + "verifyWeight": "请输入体重", + "verifyGender": "请选择性别", + "verifyBontrast": "请选择数据", + "verifyBodyDate": "请选择正确的时间", + "verifyRecord": "请输入", + "verifyPicker": "请选择", + "verifyAccount": "请输入正确的手机号或邮箱", + "verifyEmail": "请输入邮箱", + "verifyEmailCorrect": "请输入正确的邮箱", + "verifyMobile": "请输入手机号", + "verifyMobileCorrect": "请输入正确的手机号", + "verifyCode": "请输入验证码", + "verifyPassword": "请输入密码", + "verifyPasswordTwo": "请输入确认密码", + "verifyPasswordCorrect": "请确认两次密码填写一致", + "verifyAgreement": "请先确认并勾选协议", + "verifyOutLogin": "是否退出登录?", + "verifyDeleteUser": "是否删除该成员?", + "verifyDeleteHistory": "是否删除当前测量记录?", + "verifyDeleteAccount": "删除成功后,该账号的所有关联信息将被清空且无法找回,是否删除?", + "btnConfirm": "确认", + "btnSubmit": "提交", + "btnSancellation": "取消", + "btnContinue": "继续", + "btnBack": "返回", + "btnDelete": "删除" + }, + "linkBluetooth": { + "ConnectionTimeout": "连接超时,点击重新连接", + "Measuring": "测量中,请将食物放到秤上", + "Weight": "重量", + "RecordWeight": "请输入食物重量", + "Search": "蓝牙搜索中", + "Remeasure": "数据异常,请重新测量!", + "reset": "数据异常,请清零后重新测量!", + "Disconnect": "断开连接", + "remeasure": "重新测量", + "resetBtn": "清零", + "UnitBtn": "单位", + "SaveResult": "保存" + }, + "common": { + "titleHome": "首页", + "titleMenu": "菜谱", + "titleMenuAdd": "添加食谱", + "titleMenuSearch": "搜索菜谱", + "titleCount": "计食", + "titleCountList": "食材库", + "titleCustomKcal": "自定义卡路里", + "titleEveryMeal": "餐食详情", + "titleCountSearch": "食材搜索", + "titleeveryDay": "营养分析", + "titleMe": "我的", + "titleDetail": "详情", + "titleBody": "目标", + "titleHistory": "饮食记录", + "titlePhone": "绑定手机号", + "titleEmail": "绑定邮箱", + "titlePasswordEdit": "修改密码", + "titleSet": "设置", + "titleDate": "日期", + "titleMember": "资料", + "titleManage": "成员管理", + "titleManageAdd": "添加成员", + "titleAboutUs": "关于我们", + "titleSetPassword": "设置密码", + "titlePassword": "密码", + "titleConfirmPassword": "确认密码", + "titleForgotPassword": "忘记密码", + "titleCode": "验证码", + "titleLanguage": "语言设置", + "titleSendCode": "获取验证码", + "titleSendCodeRetry": "S后重发", + "titleLogin": "登录", + "titleRegister": "注册", + "titleToggleLogin": "切换登录", + "titleAccountText": "手机号/邮箱", + "titleAgreementText": "阅读并同意", + "titleAgreementContntText": "隐私协议", + "titleVersionUpdate": "版本更新", + "titleNewVersion": "新版本", + "infoActivityCoefficient": "活动系数", + "infoPersonalProfile": "个人资料", + "infoMyRecipes": "我的菜谱", + "infoMyCollection": "我的收藏", + "infoAvatar": "头像", + "infoNickname": "昵称", + "infoMobile": "手机号", + "infoEmail": "邮箱", + "infoAge": "年龄", + "infoAgeunit": "岁", + "infoGender": "性别", + "infoMan": "男", + "infoWoman": "女", + "infoUnknown": "未知", + "infoBirthday": "出生日期", + "infoHeight": "身高", + "infoWeight": "体重", + "btnEdit": "编辑", + "btnDelete": "删除", + "btnAdd": "添加", + "btnDetail": "查看详情", + "btnDeleteAccount": "删除账号", + "btnLogOut": "退出登录" + }, + "countIntake": "摄入", + "countCalorieIntake": "热量摄入", + "countMealdetails": "餐食详情", + "countAddFood": "添加食物", + "countNutritionalProportion": "营养占比", + "countComponentStatistics": "成分统计", + "countCalorieAnalysis": "卡路里分析", + "countNutrientElementEnergyProportion": "营养元素能量占比", + "countNutritionClassification": "营养分类", + "countNutritionElementRankingList": "营养元素排行榜", + "countFoodTypes": "食物类型" + }'; + $congli_arr = json_decode($congli,true); + // foreach ($congli_arr as $key => $value) { + // if(is_array($value)){ + // foreach ($value as $k => $v) { + // $congli_arr[$key][$k] = $this->baiduTranslate($v, 'zh', 'en'); + // } + // }else{ + // $congli_arr[$key] = $this->baiduTranslate($value, 'zh', 'en'); + // } + + // } + + + + // foreach ($congli_arr as $key => $value) { + // if(!is_array($value)){ + // $congli_arr[$key] = $this->baiduTranslate($value, 'zh', 'en')['data']['trans_result'][0]['dst']; + // } + + foreach ($congli_arr['tips'] as $key => $value) { + $congli_arr['tips'][$key] = $this->baiduTranslate($value, 'zh', 'en')['data']['trans_result'][0]['dst']; + + + + } + return $this->msg(0,'成功',$congli_arr); + } + + + + public function msg($code,$str,$data){ + return json(['code'=>$code,'msg'=>$str,'data'=>$data]); + } +} \ No newline at end of file diff --git a/application/test/controller/Xishuju1.php b/application/test/controller/Xishuju1.php new file mode 100644 index 0000000..85980e5 --- /dev/null +++ b/application/test/controller/Xishuju1.php @@ -0,0 +1,1532 @@ + ['success',[]], + '10001'=>'关键参数缺失', + '10002'=>'操作失败', + '10003'=>'信息核实错误', + '10004'=>'未找到有效数据', + '10005'=>'参数格式错误', + '10006'=>'参数不能为空', + '10007'=>'参数错误', + '10008'=>'', + '10009'=>'', + '10010'=>'自定义信息', + '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', + ]; + + + public function xishuju1_qd_page(){ + // $cfc = Db::connect('cfc_db'); + // $y_result_food = $cfc->table('linshi_usa_data')->group('data_type')->field('data_type,count(*) as num')->select(); + // dump($y_result_food); + // die; + return $this->fetch(); + } + + public function xishuju1_action(){ + $data = input(); + $result = $this->wash_step1_chuli_shicai_name(); + return $result; + + } + public function xishuju2_action(){ + // // 处理lebal + // $cfc = Db::connect('cfc_db'); + // $data = $cfc->table('linshi_usa_label_list')->order('id')->select(); + // $data2 = []; + // foreach ($data as $key => $value) { + // $data2[] = [ + // 'name'=>$value['description'], + // 'one_id'=>999, + // 'create_time'=>date('Y-m-d H:i:s'), + // ]; + // } + + // $data3 = $cfc->table('app_z_national_standard_food_type_2_multilingual')->insertAll($data2); + // dump($data3); + // die; + + $data = input(); + $result = $this->wash_step2_chuli_shicai_name(); + return $result; + + } + public function xishuju3_action(){ + $data = input(); + $result = $this->wash_step3_chuli_shicai_name(); + return $result; + + } + + public function wash_step1_chuli_shicai_name(){ + $cfc = Db::connect('cfc_db'); + $y_result_food = $cfc->table('linshi_usa_data')->where("data_type = 'sub_sample_food' AND status is null")->order('id desc')->field('id,fdc_id,data_type,food_category_id,description')->find(); + + if(!$y_result_food){ + return $this->msg(10004); + } + $y_result_food_id = $y_result_food['id']; + unset($y_result_food['ROW_NUMBER']); + unset($y_result_food['id']); + // unset($y_result_food['publication_date']); + + // unset($y_result_food['status']); + $y_result_food['description2'] = str_replace(' ', '', $y_result_food['description']); + $now_result_food = $cfc->table('linshi_usa_data_copy')->where(['data_type'=>'sub_sample_food','description2'=>$y_result_food['description2']])->find(); + + // dump($y_result_food); + // dump($now_result_food); + // die; + if($now_result_food){ + // 启动事务 + $cfc->startTrans(); + try{ + $cfc->table('linshi_usa_data_copy')->where(['id'=>$now_result_food['id']])->update([ + 'fdc_id'=>$now_result_food['fdc_id'].','.$y_result_food['fdc_id'], + ]); + $cfc->table('linshi_usa_data')->where(['id'=>$y_result_food_id])->update([ + 'status'=>$now_result_food['id'], + ]); + // 提交事务 + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + return $this->msg(10002); + } + }else{ + $cfc->startTrans(); + try{ + $new_id = $cfc->table('linshi_usa_data_copy')->insertGetId($y_result_food); + $cfc->table('linshi_usa_data')->where(['id'=>$y_result_food_id])->update([ + 'status'=>$new_id, + ]); + // 提交事务 + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + return $this->msg(10002); + } + } + } + + public function wash_step2_chuli_shicai_name(){ + // 选出一个食材,并处理它的营养物质,然后分别插入对应的表单 + $nutritionData_map = [ + '1008'=>['name'=>'Calorie','name_ch'=>'卡路里','unit'=>'KCAL','type'=>1], + '1003'=>['name'=>'Protein','name_ch'=>'蛋白质','unit'=>'G','type'=>1], + '1004'=>['name'=>'Fat','name_ch'=>'脂肪','unit'=>'G','type'=>1], + '1005'=>['name'=>'Carbohydrate','name_ch'=>'碳水化合物','unit'=>'G','type'=>1], + '1106'=>['name'=>'VitaminA','name_ch'=>'维生素A','unit'=>'UG','type'=>2], + '1165'=>['name'=>'VitaminB1','name_ch'=>'硫胺素','unit'=>'MG','type'=>2], + '1166'=>['name'=>'VitaminB2','name_ch'=>'核黄素','unit'=>'MG','type'=>2], + '1175'=>['name'=>'VitaminB6','name_ch'=>'维生素B6','unit'=>'MG','type'=>2], + '1178'=>['name'=>'VitaminB12','name_ch'=>'维生素B12','unit'=>'UG','type'=>2], + '1114'=>['name'=>'VitaminD','name_ch'=>'维生素D','unit'=>'UG','type'=>2], + '1185'=>['name'=>'VitaminK','name_ch'=>'维生素K','unit'=>'UG','type'=>2], + '1167'=>['name'=>'Niacin','name_ch'=>'烟酸','unit'=>'MG','type'=>2], + '1169'=>['name'=>'Niacin','name_ch'=>'烟酸','unit'=>'MG','type'=>2], + '1162'=>['name'=>'VitaminC','name_ch'=>'维生素C','unit'=>'MG','type'=>2], + '1109'=>['name'=>'VitaminE','name_ch'=>'维生素E','unit'=>'MG','type'=>2], + '1186'=>['name'=>'FolicAcid','name_ch'=>'叶酸','unit'=>'UG','type'=>2], + '1176'=>['name'=>'Biotin','name_ch'=>'生物素','unit'=>'UG','type'=>2], + '1170'=>['name'=>'PantothenicAcid','name_ch'=>'泛酸','unit'=>'MG','type'=>2], + '1180'=>['name'=>'TotalCholine','name_ch'=>'总胆碱','unit'=>'MG','type'=>2], + '1087'=>['name'=>'Ca','name_ch'=>'钙','unit'=>'MG','type'=>3], + '1091'=>['name'=>'Phosphorus','name_ch'=>'磷','unit'=>'MG','type'=>3], + '1092'=>['name'=>'Kalium','name_ch'=>'钾','unit'=>'MG','type'=>3], + '1090'=>['name'=>'Mg','name_ch'=>'镁','unit'=>'MG','type'=>3], + '1093'=>['name'=>'Na','name_ch'=>'钠','unit'=>'MG','type'=>3], + '1089'=>['name'=>'Fe','name_ch'=>'铁','unit'=>'MG','type'=>3], + '1095'=>['name'=>'Zn','name_ch'=>'锌','unit'=>'MG','type'=>3], + '1103'=>['name'=>'Se','name_ch'=>'硒','unit'=>'UG','type'=>3], + '1098'=>['name'=>'Cu','name_ch'=>'铜','unit'=>'MG','type'=>3], + '1101'=>['name'=>'Mn','name_ch'=>'锰','unit'=>'MG','type'=>3], + '1100'=>['name'=>'Iodine','name_ch'=>'碘','unit'=>'UG','type'=>3], + ]; + $nutritionData = [ + "Calorie" => [], + "Protein" => [], + "Fat" => [], + "Carbohydrate" => [], + "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" => [] + ]; + // 处理食物表数据 + $cfc = Db::connect('cfc_db'); + // 获取一条数据 + $shiwu_name = $cfc->table('linshi_usa_data_copy')->where("status is null")->order('id')->find(); + // dump($shiwu_name); + // dump(explode(',',$shiwu_name['fdc_id'])); + // die; + if(!$shiwu_name){ + return $this->msg(10004); + } + // 开始处理 + $end_shiwu_data = []; + $end_shiwu_data['record_id'] = 251213; + $end_shiwu_data['Calorie_name'] = '卡路里'; + $end_shiwu_data['Calorie_unit'] = 'kcal'; + $end_shiwu_data['Calorie_val'] = ''; + $end_shiwu_data['Protein_name'] = '蛋白质'; + $end_shiwu_data['Protein_unit'] = 'g'; + $end_shiwu_data['Protein_val'] = ''; + $end_shiwu_data['Fat_name'] = '脂肪'; + $end_shiwu_data['Fat_unit'] = 'g'; + $end_shiwu_data['Fat_val'] = ''; + $end_shiwu_data['Carbohydrate_name'] = '碳水化合物'; + $end_shiwu_data['Carbohydrate_unit'] = 'g'; + $end_shiwu_data['Carbohydrate_val'] = ''; + $end_shiwu_data['two_id'] = $shiwu_name['food_category_id']; + $end_shiwu_data['data_type'] = $shiwu_name['data_type']; + $end_shiwu_data['food_name_en'] = $shiwu_name['description']; + + // 处理营养成分表 + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 获取一条数据 + $yingyang_list = $cfc->table('linshi_usa_yingyang_guanlian')->where("fdc_id in (".$shiwu_name['fdc_id'].")")->select(); + // dump(count($yingyang_list)); + // die; + if(count($yingyang_list)<=0){ + return $this->msg(11006,'error',['id'=>$shiwu_name['id']]); + } + // 开始处理 + // 处理有值的营养成分 + foreach ($yingyang_list as $key => $value) { + if(array_key_exists($value['nutrient_id'],$nutritionData_map)){ + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['father_id'] = ''; + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['name'] = $nutritionData_map[$value['nutrient_id']]['name']; + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['name_ch'] = $nutritionData_map[$value['nutrient_id']]['name_ch']; + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['unit'] = $nutritionData_map[$value['nutrient_id']]['unit']; + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['value'][] = $value['amount']; + $nutritionData[$nutritionData_map[$value['nutrient_id']]['name']]['type'] = $nutritionData_map[$value['nutrient_id']]['type']; + } + } + // 处理无值的营养成分 + foreach ($nutritionData as $key => $value) { + if(count($value)<=0){ + foreach ($nutritionData_map as $k => $v) { + if($v['name'] == $key){ + $nutritionData[$key]['father_id'] = ''; + $nutritionData[$key]['name'] = $v['name']; + $nutritionData[$key]['name_ch'] = $v['name_ch']; + $nutritionData[$key]['unit'] = $v['unit']; + $nutritionData[$key]['value'] = []; + $nutritionData[$key]['type'] = $v['type']; + } + } + } + } + // 处理营养成分的具体值&食材中的四大营养物质 + foreach ($nutritionData as $key => $value) { + + // 营养成分的具体值 + $nutritionData_tmp = 0; + if(count($value['value'])<=0){ + if($key == 'Calorie' || $key == 'Protein' || $key == 'Fat' || $key == 'Carbohydrate'){ + return $this->msg(10006,'error',['id'=>$shiwu_name['id']]); + } + $nutritionData[$key]['value'] = '/'; + }else{ + foreach ($value['value'] as $k => $v) { + $nutritionData_tmp = bcadd($nutritionData_tmp,$v,20); + } + $nutritionData[$key]['value'] = bcdiv($nutritionData_tmp,count($value),20); + $nutritionData[$key]['value'] = $this->processPrecisionNumberBC($nutritionData[$key]['value']); + } + // 食材中的四大营养物质 + if($key == 'Calorie'){ + $end_shiwu_data['Calorie_unit'] = $value['unit']; + $end_shiwu_data['Calorie_val'] = $nutritionData[$key]['value']; + }else if($key == 'Protein'){ + $end_shiwu_data['Protein_unit'] = $value['unit']; + $end_shiwu_data['Protein_val'] = $nutritionData[$key]['value']; + + }else if($key == 'Fat'){ + $end_shiwu_data['Fat_unit'] = $value['unit']; + $end_shiwu_data['Fat_val'] = $nutritionData[$key]['value']; + + }else if($key == 'Carbohydrate'){ + $end_shiwu_data['Carbohydrate_unit'] = $value['unit']; + $end_shiwu_data['Carbohydrate_val'] = $nutritionData[$key]['value']; + } + + } + $end_nutritionData = []; + foreach ($nutritionData as $key => $value) { + $end_nutritionData[] = $value; + } + + $cfc->startTrans(); + try{ + $new_id = $cfc->table('app_z_national_standard_food_type_3_multilingual')->insertGetId($end_shiwu_data); + foreach ($end_nutritionData as $key => $value) { + $end_nutritionData[$key]['father_id'] = $new_id; + } + $cfc->table('app_z_national_standard_food_type_4_multilingual')->insertAll($end_nutritionData); + $cfc->table('linshi_usa_data_copy')->where(['id'=>$shiwu_name['id']])->update([ + 'status'=>'success-'.$new_id, + ]); + // 提交事务 + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + return $this->msg(10002,'error',['id'=>$shiwu_name['id']]); + } + + } + + public function wash_step3_chuli_shicai_name(){ + + // 处理食物表数据 + $cfc = Db::connect('cfc_db'); + // 获取一条数据 + $shicai_data = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where("food_name is null")->order('id')->find(); + // dump($shicai_data); + $baidufanyi = new Baidufanyi; + $result = $baidufanyi->fanyi_action($shicai_data['food_name_en'], 'en', 'zh'); + // dump($result); + // dump($result['data']['trans_result'][0]['dst']); + // die; + // $fanyi_result = ''; + if($result['success'] == true){ + $fanyi_result = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where(['id'=>$shicai_data['id']])->update(['food_name'=>$result['data']['trans_result'][0]['dst']]); + if($fanyi_result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + }else{ + return $this->msg(12002); + } + + } + + + + + + public function error_action(){ + $data = input(); + $code_arr = [ + '10002' => 'DB_error', + '10006' => 'all_null', + '11006' => 'food_nutrition_null2', + '12002' => 'fanyi_error', + ]; + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('linshi_usa_data_copy')->where(['id'=>$data['id']])->update([ + 'status'=>$code_arr[$data['code']] + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002,$data); + } + } + + // 查看数据 + public function look_food_data(){ + // 根据您提供的营养成分表创建的数组 + $nutritionArray = [ + 'Energy (Atwater General Factors)' => ['中文意思' => '能量(阿特沃特通用系数)', '状态' => '新!'], + 'Energy (Atwater Specific Factors)' => ['中文意思' => '能量(阿特沃特定系数)', '状态' => '新!'], + 'Solids' => ['中文意思' => '固形物', '状态' => '新!'], + 'Nitrogen' => ['中文意思' => '氮', '状态' => '新!'], + 'Protein' => ['中文意思' => '蛋白质', '状态' => '默认'], + 'Total lipid (fat)' => ['中文意思' => '总脂肪', '状态' => '默认'], + 'Carbohydrate, by difference' => ['中文意思' => '碳水化合物(差值法)', '状态' => '默认'], + 'Fiber, crude (DO NOT USE - Archived)' => ['中文意思' => '粗纤维(已归档-请勿使用)', '状态' => '新!'], + 'Ash' => ['中文意思' => '灰分', '状态' => '新!'], + 'Energy' => ['中文意思' => '能量', '状态' => '默认'], + 'Starch' => ['中文意思' => '淀粉', '状态' => '新!'], + 'Sucrose' => ['中文意思' => '蔗糖', '状态' => '新!'], + 'Glucose' => ['中文意思' => '葡萄糖', '状态' => '新!'], + 'Fructose' => ['中文意思' => '果糖', '状态' => '新!'], + 'Lactose' => ['中文意思' => '乳糖', '状态' => '新!'], + 'Maltose' => ['中文意思' => '麦芽糖', '状态' => '新!'], + 'Amylose' => ['中文意思' => '直链淀粉', '状态' => '新!'], + 'Amylopectin' => ['中文意思' => '支链淀粉', '状态' => '新!'], + 'Pectin' => ['中文意思' => '果胶', '状态' => '新!'], + 'Alcohol, ethyl' => ['中文意思' => '乙醇', '状态' => '新!'], + 'Pentosan' => ['中文意思' => '戊聚糖', '状态' => '新!'], + 'Pentoses' => ['中文意思' => '戊糖', '状态' => '新!'], + 'Hemicellulose' => ['中文意思' => '半纤维素', '状态' => '新!'], + 'Cellulose' => ['中文意思' => '纤维素', '状态' => '新!'], + 'pH' => ['中文意思' => '酸碱度', '状态' => '新!'], + 'Specific Gravity' => ['中文意思' => '比重', '状态' => '新!'], + 'Organic acids' => ['中文意思' => '有机酸', '状态' => '新!'], + 'Acetic acid' => ['中文意思' => '乙酸', '状态' => '新!'], + 'Aconitic acid' => ['中文意思' => '乌头酸', '状态' => '新!'], + 'Benzoic acid' => ['中文意思' => '苯甲酸', '状态' => '新!'], + 'Chelidonic acid' => ['中文意思' => '白屈菜酸', '状态' => '新!'], + 'Chlorogenic acid' => ['中文意思' => '绿原酸', '状态' => '新!'], + 'Cinnamic acid' => ['中文意思' => '肉桂酸', '状态' => '新!'], + 'Citric acid' => ['中文意思' => '柠檬酸', '状态' => '新!'], + 'Fumaric acid' => ['中文意思' => '富马酸', '状态' => '新!'], + 'Galacturonic acid' => ['中文意思' => '半乳糖醛酸', '状态' => '新!'], + 'Gallic acid' => ['中文意思' => '没食子酸', '状态' => '新!'], + 'Glycolic acid' => ['中文意思' => '乙醇酸', '状态' => '新!'], + 'Isocitric acid' => ['中文意思' => '异柠檬酸', '状态' => '新!'], + 'Lactic acid' => ['中文意思' => '乳酸', '状态' => '新!'], + 'Malic acid' => ['中文意思' => '苹果酸', '状态' => '新!'], + 'Oxaloacetic acid' => ['中文意思' => '草酰乙酸', '状态' => '新!'], + 'Oxalic acid' => ['中文意思' => '草酸', '状态' => '新!'], + 'Phytic acid' => ['中文意思' => '植酸', '状态' => '新!'], + 'Pyruvic acid' => ['中文意思' => '丙酮酸', '状态' => '新!'], + 'Quinic acid' => ['中文意思' => '奎宁酸', '状态' => '新!'], + 'Salicylic acid' => ['中文意思' => '水杨酸', '状态' => '新!'], + 'Succinic acid' => ['中文意思' => '琥珀酸', '状态' => '新!'], + 'Tartaric acid' => ['中文意思' => '酒石酸', '状态' => '新!'], + 'Ursolic acid' => ['中文意思' => '熊果酸', '状态' => '新!'], + 'Solids, non-fat' => ['中文意思' => '非脂固形物', '状态' => '新!'], + 'Carbohydrate, by summation' => ['中文意思' => '碳水化合物(加和法)', '状态' => '新!'], + 'Water' => ['中文意思' => '水分', '状态' => '新!'], + 'Adjusted Nitrogen' => ['中文意思' => '调整氮', '状态' => '新!'], + 'Adjusted Protein' => ['中文意思' => '调整蛋白质', '状态' => '新!'], + 'Piperine' => ['中文意思' => '胡椒碱', '状态' => '新!'], + 'Mannitol' => ['中文意思' => '甘露醇', '状态' => '新!'], + 'Sorbitol' => ['中文意思' => '山梨糖醇', '状态' => '新!'], + 'Caffeine' => ['中文意思' => '咖啡因', '状态' => '新!'], + 'Theobromine' => ['中文意思' => '可可碱', '状态' => '新!'], + 'Nitrates' => ['中文意思' => '硝酸盐', '状态' => '新!'], + 'Nitrites' => ['中文意思' => '亚硝酸盐', '状态' => '新!'], + 'Nitrosamine,total' => ['中文意思' => '总亚硝胺', '状态' => '新!'], + 'Energy' => ['中文意思' => '能量(千焦)', '状态' => '默认'], + 'Sugars, Total' => ['中文意思' => '总糖', '状态' => '新!'], + 'Solids, soluble' => ['中文意思' => '可溶性固形物', '状态' => '新!'], + 'Glycogen' => ['中文意思' => '糖原', '状态' => '新!'], + 'Fiber, neutral detergent (DO NOT USE - Archived)' => ['中文意思' => '中性洗涤纤维(已归档-请勿使用)', '状态' => '新!'], + 'Reducing sugars' => ['中文意思' => '还原糖', '状态' => '新!'], + 'Beta-glucans' => ['中文意思' => 'β-葡聚糖', '状态' => '新!'], + 'Oligosaccharides' => ['中文意思' => '低聚糖', '状态' => '新!'], + 'Nonstarch polysaccharides' => ['中文意思' => '非淀粉多糖', '状态' => '新!'], + 'Resistant starch' => ['中文意思' => '抗性淀粉', '状态' => '新!'], + 'Carbohydrate, other' => ['中文意思' => '其他碳水化合物', '状态' => '新!'], + 'Arabinose' => ['中文意思' => '阿拉伯糖', '状态' => '新!'], + 'Xylose' => ['中文意思' => '木糖', '状态' => '新!'], + 'Galactose' => ['中文意思' => '半乳糖', '状态' => '新!'], + 'Raffinose' => ['中文意思' => '棉子糖', '状态' => '新!'], + 'Stachyose' => ['中文意思' => '水苏糖', '状态' => '新!'], + 'Xylitol' => ['中文意思' => '木糖醇', '状态' => '新!'], + 'Fiber, total dietary' => ['中文意思' => '总膳食纤维', '状态' => '新!'], + 'Lignin' => ['中文意思' => '木质素', '状态' => '新!'], + 'Ribose' => ['中文意思' => '核糖', '状态' => '新!'], + 'Fiber, soluble' => ['中文意思' => '可溶性纤维', '状态' => '新!'], + 'Theophylline' => ['中文意思' => '茶碱', '状态' => '新!'], + 'Fiber, insoluble' => ['中文意思' => '不溶性纤维', '状态' => '新!'], + 'Total fat (NLEA)' => ['中文意思' => '总脂肪(NLEA)', '状态' => '新!'], + 'Total sugar alcohols' => ['中文意思' => '总糖醇', '状态' => '新!'], + 'Calcium, Ca' => ['中文意思' => '钙', '状态' => '默认'], + 'Chlorine, Cl' => ['中文意思' => '氯', '状态' => '新!'], + 'Iron, Fe' => ['中文意思' => '铁', '状态' => '默认'], + 'Magnesium, Mg' => ['中文意思' => '镁', '状态' => '默认'], + 'Phosphorus, P' => ['中文意思' => '磷', '状态' => '默认'], + 'Potassium, K' => ['中文意思' => '钾', '状态' => '默认'], + 'Sodium, Na' => ['中文意思' => '钠', '状态' => '默认'], + 'Sulfur, S' => ['中文意思' => '硫', '状态' => '新!'], + 'Zinc, Zn' => ['中文意思' => '锌', '状态' => '默认'], + 'Chromium, Cr' => ['中文意思' => '铬', '状态' => '新!'], + 'Cobalt, Co' => ['中文意思' => '钴', '状态' => '新!'], + 'Copper, Cu' => ['中文意思' => '铜', '状态' => '默认'], + 'Fluoride, F' => ['中文意思' => '氟化物', '状态' => '新!'], + 'Iodine, I' => ['中文意思' => '碘', '状态' => '默认'], + 'Manganese, Mn' => ['中文意思' => '锰', '状态' => '默认'], + 'Molybdenum, Mo' => ['中文意思' => '钼', '状态' => '新!'], + 'Selenium, Se' => ['中文意思' => '硒', '状态' => '默认'], + 'Vitamin A, IU' => ['中文意思' => '维生素A(国际单位)', '状态' => '新!'], + 'Retinol' => ['中文意思' => '视黄醇', '状态' => '新!'], + 'Vitamin A, RAE' => ['中文意思' => '维生素A(视黄醇活性当量)', '状态' => '默认'], + 'Carotene, beta' => ['中文意思' => 'β-胡萝卜素', '状态' => '新!'], + 'Carotene, alpha' => ['中文意思' => 'α-胡萝卜素', '状态' => '新!'], + 'Vitamin E (alpha-tocopherol)' => ['中文意思' => '维生素E(α-生育酚)', '状态' => '默认'], + 'Vitamin D (D2 + D3), International Units' => ['中文意思' => '维生素D(D2+D3,国际单位)', '状态' => '新!'], + 'Vitamin D2 (ergocalciferol)' => ['中文意思' => '维生素D2(麦角钙化醇)', '状态' => '新!'], + 'Vitamin D3 (cholecalciferol)' => ['中文意思' => '维生素D3(胆钙化醇)', '状态' => '新!'], + '25-hydroxycholecalciferol' => ['中文意思' => '25-羟基胆钙化醇', '状态' => '新!'], + 'Vitamin D (D2 + D3)' => ['中文意思' => '维生素D(D2+D3)', '状态' => '默认'], + '25-hydroxyergocalciferol' => ['中文意思' => '25-羟基麦角钙化醇', '状态' => '新!'], + 'Phytoene' => ['中文意思' => '八氢番茄红素', '状态' => '新!'], + 'Phytofluene' => ['中文意思' => '六氢番茄红素', '状态' => '新!'], + 'Carotene, gamma' => ['中文意思' => 'γ-胡萝卜素', '状态' => '新!'], + 'Zeaxanthin' => ['中文意思' => '玉米黄质', '状态' => '新!'], + 'Cryptoxanthin, beta' => ['中文意思' => 'β-隐黄质', '状态' => '新!'], + 'Lutein' => ['中文意思' => '叶黄素', '状态' => '新!'], + 'Lycopene' => ['中文意思' => '番茄红素', '状态' => '新!'], + 'Lutein + zeaxanthin' => ['中文意思' => '叶黄素+玉米黄质', '状态' => '新!'], + 'Vitamin E (label entry primarily)' => ['中文意思' => '维生素E(标签主要条目)', '状态' => '新!'], + 'Tocopherol, beta' => ['中文意思' => 'β-生育酚', '状态' => '新!'], + 'Tocopherol, gamma' => ['中文意思' => 'γ-生育酚', '状态' => '新!'], + 'Tocopherol, delta' => ['中文意思' => 'δ-生育酚', '状态' => '新!'], + 'Tocotrienol, alpha' => ['中文意思' => 'α-生育三烯酚', '状态' => '新!'], + 'Tocotrienol, beta' => ['中文意思' => 'β-生育三烯酚', '状态' => '新!'], + 'Tocotrienol, gamma' => ['中文意思' => 'γ-生育三烯酚', '状态' => '新!'], + 'Tocotrienol, delta' => ['中文意思' => 'δ-生育三烯酚', '状态' => '新!'], + 'Aluminum, Al' => ['中文意思' => '铝', '状态' => '新!'], + 'Antimony, Sb' => ['中文意思' => '锑', '状态' => '新!'], + 'Arsenic, As' => ['中文意思' => '砷', '状态' => '新!'], + 'Barium, Ba' => ['中文意思' => '钡', '状态' => '新!'], + 'Beryllium, Be' => ['中文意思' => '铍', '状态' => '新!'], + 'Boron, B' => ['中文意思' => '硼', '状态' => '新!'], + 'Bromine, Br' => ['中文意思' => '溴', '状态' => '新!'], + 'Cadmium, Cd' => ['中文意思' => '镉', '状态' => '新!'], + 'Gold, Au' => ['中文意思' => '金', '状态' => '新!'], + 'Iron, heme' => ['中文意思' => '血红素铁', '状态' => '新!'], + 'Iron, non-heme' => ['中文意思' => '非血红素铁', '状态' => '新!'], + 'Lead, Pb' => ['中文意思' => '铅', '状态' => '新!'], + 'Lithium, Li' => ['中文意思' => '锂', '状态' => '新!'], + 'Mercury, Hg' => ['中文意思' => '汞', '状态' => '新!'], + 'Nickel, Ni' => ['中文意思' => '镍', '状态' => '新!'], + 'Rubidium, Rb' => ['中文意思' => '铷', '状态' => '新!'], + 'Fluoride - DO NOT USE; use 313' => ['中文意思' => '氟化物(请勿使用,使用313)', '状态' => '新!'], + 'Salt, NaCl' => ['中文意思' => '食盐(氯化钠)', '状态' => '新!'], + 'Silicon, Si' => ['中文意思' => '硅', '状态' => '新!'], + 'Silver, Ag' => ['中文意思' => '银', '状态' => '新!'], + 'Strontium, Sr' => ['中文意思' => '锶', '状态' => '新!'], + 'Tin, Sn' => ['中文意思' => '锡', '状态' => '新!'], + 'Titanium, Ti' => ['中文意思' => '钛', '状态' => '新!'], + 'Vanadium, V' => ['中文意思' => '钒', '状态' => '新!'], + 'Vitamin A, RE' => ['中文意思' => '维生素A(视黄醇当量)', '状态' => '新!'], + 'Carotene' => ['中文意思' => '胡萝卜素', '状态' => '新!'], + 'Vitamin E' => ['中文意思' => '维生素E(α-生育酚当量)', '状态' => '新!'], + 'cis-beta-Carotene' => ['中文意思' => '顺式-β-胡萝卜素', '状态' => '新!'], + 'cis-Lycopene' => ['中文意思' => '顺式-番茄红素', '状态' => '新!'], + 'cis-Lutein/Zeaxanthin' => ['中文意思' => '顺式-叶黄素/玉米黄质', '状态' => '新!'], + 'Vitamin C, total ascorbic acid' => ['中文意思' => '总抗坏血酸(维生素C)', '状态' => '默认'], + 'Vitamin C, reduced ascorbic acid' => ['中文意思' => '还原型抗坏血酸', '状态' => '新!'], + 'Vitamin C, dehydro ascorbic acid' => ['中文意思' => '脱氢抗坏血酸', '状态' => '新!'], + 'Thiamin' => ['中文意思' => '硫胺素(维生素B1)', '状态' => '默认'], + 'Riboflavin' => ['中文意思' => '核黄素(维生素B2)', '状态' => '默认'], + 'Niacin' => ['中文意思' => '烟酸(维生素B3)', '状态' => '默认'], + 'Niacin from tryptophan, determined' => ['中文意思' => '由色氨酸转化的烟酸(测定值)', '状态' => '新!'], + 'Niacin equivalent N406 +N407' => ['中文意思' => '烟酸当量(N406+N407)', '状态' => '默认'], + 'Pantothenic acid' => ['中文意思' => '泛酸(维生素B5)', '状态' => '默认'], + 'Vitamin B-6, pyridoxine, alcohol form' => ['中文意思' => '维生素B6(吡哆醇,醇型)', '状态' => '新!'], + 'Vitamin B-6, pyridoxal, aldehyde form' => ['中文意思' => '维生素B6(吡哆醛,醛型)', '状态' => '新!'], + 'Vitamin B-6, pyridoxamine, amine form' => ['中文意思' => '维生素B6(吡哆胺,胺型)', '状态' => '新!'], + 'Vitamin B-6, N411 + N412 +N413' => ['中文意思' => '维生素B6(N411+N412+N413)', '状态' => '新!'], + 'Vitamin B-6' => ['中文意思' => '维生素B6', '状态' => '默认'], + 'Biotin' => ['中文意思' => '生物素(维生素B7)', '状态' => '默认'], + 'Folate, total' => ['中文意思' => '总叶酸', '状态' => '新!'], + 'Vitamin B-12' => ['中文意思' => '维生素B12', '状态' => '默认'], + 'Folate, free' => ['中文意思' => '游离叶酸', '状态' => '新!'], + 'Choline, total' => ['中文意思' => '总胆碱', '状态' => '默认'], + 'Inositol' => ['中文意思' => '肌醇', '状态' => '新!'], + 'Inositol phosphate' => ['中文意思' => '肌醇磷酸', '状态' => '新!'], + 'Vitamin K (Menaquinone-4)' => ['中文意思' => '维生素K(甲基萘醌-4)', '状态' => '新!'], + 'Vitamin K (Dihydrophylloquinone)' => ['中文意思' => '维生素K(二氢叶绿醌)', '状态' => '新!'], + 'Vitamin K (phylloquinone)' => ['中文意思' => '维生素K(叶绿醌)', '状态' => '默认'], + 'Folic acid' => ['中文意思' => '叶酸(合成)', '状态' => '默认'], + 'Folate, food' => ['中文意思' => '食物叶酸', '状态' => '新!'], + '5-methyl tetrahydrofolate (5-MTHF)' => ['中文意思' => '5-甲基四氢叶酸(5-MTHF)', '状态' => '新!'], + 'Folate, not 5-MTHF' => ['中文意思' => '非5-MTHF叶酸', '状态' => '新!'], + 'Folate, DFE' => ['中文意思' => '叶酸(膳食叶酸当量)', '状态' => '新!'], + '10-Formyl folic acid (10HCOFA)' => ['中文意思' => '10-甲酰叶酸(10HCOFA)', '状态' => '新!'], + '5-Formyltetrahydrofolic acid (5-HCOH4' => ['中文意思' => '5-甲酰四氢叶酸(5-HCOH4)', '状态' => '新!'], + 'Tetrahydrofolic acid (THF)' => ['中文意思' => '四氢叶酸(THF)', '状态' => '新!'], + 'Choline, free' => ['中文意思' => '游离胆碱', '状态' => '新!'], + 'Choline, from phosphocholine' => ['中文意思' => '来自磷酸胆碱的胆碱', '状态' => '新!'], + 'Choline, from phosphotidyl choline' => ['中文意思' => '来自磷脂酰胆碱的胆碱', '状态' => '新!'], + 'Choline, from glycerophosphocholine' => ['中文意思' => '来自甘油磷酸胆碱的胆碱', '状态' => '新!'], + 'Betaine' => ['中文意思' => '甜菜碱', '状态' => '新!'], + 'Choline, from sphingomyelin' => ['中文意思' => '来自鞘磷脂的胆碱', '状态' => '新!'], + 'p-Hydroxy benzoic acid' => ['中文意思' => '对羟基苯甲酸', '状态' => '新!'], + 'Caffeic acid' => ['中文意思' => '咖啡酸', '状态' => '新!'], + 'p-Coumaric acid' => ['中文意思' => '对香豆酸', '状态' => '新!'], + 'Ellagic acid' => ['中文意思' => '鞣花酸', '状态' => '新!'], + 'Ferrulic acid' => ['中文意思' => '阿魏酸', '状态' => '新!'], + 'Gentisic acid' => ['中文意思' => '龙胆酸', '状态' => '新!'], + 'Tyrosol' => ['中文意思' => '酪醇', '状态' => '新!'], + 'Vanillic acid' => ['中文意思' => '香草酸', '状态' => '新!'], + 'Phenolic acids, total' => ['中文意思' => '总酚酸', '状态' => '新!'], + 'Polyphenols, total' => ['中文意思' => '总多酚', '状态' => '新!'], + 'Tryptophan' => ['中文意思' => '色氨酸', '状态' => '新!'], + 'Threonine' => ['中文意思' => '苏氨酸', '状态' => '新!'], + 'Isoleucine' => ['中文意思' => '异亮氨酸', '状态' => '新!'], + 'Leucine' => ['中文意思' => '亮氨酸', '状态' => '新!'], + 'Lysine' => ['中文意思' => '赖氨酸', '状态' => '新!'], + 'Methionine' => ['中文意思' => '蛋氨酸', '状态' => '新!'], + 'Cystine' => ['中文意思' => '胱氨酸', '状态' => '新!'], + 'Phenylalanine' => ['中文意思' => '苯丙氨酸', '状态' => '新!'], + 'Tyrosine' => ['中文意思' => '酪氨酸', '状态' => '新!'], + 'Valine' => ['中文意思' => '缬氨酸', '状态' => '新!'], + 'Arginine' => ['中文意思' => '精氨酸', '状态' => '新!'], + 'Histidine' => ['中文意思' => '组氨酸', '状态' => '新!'], + 'Alanine' => ['中文意思' => '丙氨酸', '状态' => '新!'], + 'Aspartic acid' => ['中文意思' => '天冬氨酸', '状态' => '新!'], + 'Glutamic acid' => ['中文意思' => '谷氨酸', '状态' => '新!'], + 'Glycine' => ['中文意思' => '甘氨酸', '状态' => '新!'], + 'Proline' => ['中文意思' => '脯氨酸', '状态' => '新!'], + 'Serine' => ['中文意思' => '丝氨酸', '状态' => '新!'], + 'Hydroxyproline' => ['中文意思' => '羟脯氨酸', '状态' => '新!'], + 'Cysteine and methionine(sulfer containig AA)' => ['中文意思' => '含硫氨基酸(半胱氨酸+蛋氨酸)', '状态' => '新!'], + 'Phenylalanine and tyrosine (aromatic AA)' => ['中文意思' => '芳香族氨基酸(苯丙氨酸+酪氨酸)', '状态' => '新!'], + 'Asparagine' => ['中文意思' => '天冬酰胺', '状态' => '新!'], + 'Cysteine' => ['中文意思' => '半胱氨酸', '状态' => '新!'], + 'Glutamine' => ['中文意思' => '谷氨酰胺', '状态' => '新!'], + 'Taurine' => ['中文意思' => '牛磺酸', '状态' => '新!'], + 'Sugars, added' => ['中文意思' => '添加糖', '状态' => '新!'], + 'Sugars, intrinsic' => ['中文意思' => '内源糖', '状态' => '新!'], + 'Calcium, added' => ['中文意思' => '添加钙', '状态' => '新!'], + 'Iron, added' => ['中文意思' => '添加铁', '状态' => '新!'], + 'Calcium, intrinsic' => ['中文意思' => '内源钙', '状态' => '新!'], + 'Iron, intrinsic' => ['中文意思' => '内源铁', '状态' => '新!'], + 'Vitamin C, added' => ['中文意思' => '添加维生素C', '状态' => '新!'], + 'Vitamin E, added' => ['中文意思' => '添加维生素E', '状态' => '新!'], + 'Thiamin, added' => ['中文意思' => '添加硫胺素', '状态' => '新!'], + 'Riboflavin, added' => ['中文意思' => '添加核黄素', '状态' => '新!'], + 'Niacin, added' => ['中文意思' => '添加烟酸', '状态' => '新!'], + 'Vitamin B-12, added' => ['中文意思' => '添加维生素B12', '状态' => '新!'], + 'Vitamin C, intrinsic' => ['中文意思' => '内源维生素C', '状态' => '新!'], + 'Vitamin E, intrinsic' => ['中文意思' => '内源维生素E', '状态' => '新!'], + 'Thiamin, intrinsic' => ['中文意思' => '内源硫胺素', '状态' => '新!'], + 'Riboflavin, intrinsic' => ['中文意思' => '内源核黄素', '状态' => '新!'], + 'Niacin, intrinsic' => ['中文意思' => '内源烟酸', '状态' => '新!'], + 'Vitamin B-12, intrinsic' => ['中文意思' => '内源维生素B12', '状态' => '新!'], + 'Cholesterol' => ['中文意思' => '胆固醇', '状态' => '新!'], + 'Glycerides' => ['中文意思' => '甘油酯', '状态' => '新!'], + 'Phospholipids' => ['中文意思' => '磷脂', '状态' => '新!'], + 'Glycolipids' => ['中文意思' => '糖脂', '状态' => '新!'], + 'Fatty acids, total trans' => ['中文意思' => '总反式脂肪酸', '状态' => '新!'], + 'Fatty acids, total saturated' => ['中文意思' => '总饱和脂肪酸', '状态' => '新!'], + 'SFA 4:0' => ['中文意思' => '饱和脂肪酸4:0(丁酸)', '状态' => '新!'], + 'SFA 6:0' => ['中文意思' => '饱和脂肪酸6:0(己酸)', '状态' => '新!'], + 'SFA 8:0' => ['中文意思' => '饱和脂肪酸8:0(辛酸)', '状态' => '新!'], + 'SFA 10:0' => ['中文意思' => '饱和脂肪酸10:0(癸酸)', '状态' => '新!'], + 'SFA 12:0' => ['中文意思' => '饱和脂肪酸12:0(月桂酸)', '状态' => '新!'], + 'SFA 14:0' => ['中文意思' => '饱和脂肪酸14:0(肉豆蔻酸)', '状态' => '新!'], + 'SFA 16:0' => ['中文意思' => '饱和脂肪酸16:0(棕榈酸)', '状态' => '新!'], + 'SFA 18:0' => ['中文意思' => '饱和脂肪酸18:0(硬脂酸)', '状态' => '新!'], + 'SFA 20:0' => ['中文意思' => '饱和脂肪酸20:0(花生酸)', '状态' => '新!'], + 'MUFA 18:1' => ['中文意思' => '单不饱和脂肪酸18:1(油酸)', '状态' => '新!'], + 'PUFA 18:2' => ['中文意思' => '多不饱和脂肪酸18:2(亚油酸)', '状态' => '新!'], + 'PUFA 18:3' => ['中文意思' => '多不饱和脂肪酸18:3(亚麻酸)', '状态' => '新!'], + 'PUFA 20:4' => ['中文意思' => '多不饱和脂肪酸20:4(花生四烯酸)', '状态' => '新!'], + 'PUFA 22:6 n-3 (DHA)' => ['中文意思' => '多不饱和脂肪酸22:6 n-3(DHA)', '状态' => '新!'], + 'SFA 22:0' => ['中文意思' => '饱和脂肪酸22:0(山萮酸)', '状态' => '新!'], + 'MUFA 14:1' => ['中文意思' => '单不饱和脂肪酸14:1(肉豆蔻油酸)', '状态' => '新!'], + 'MUFA 16:1' => ['中文意思' => '单不饱和脂肪酸16:1(棕榈油酸)', '状态' => '新!'], + 'PUFA 18:4' => ['中文意思' => '多不饱和脂肪酸18:4(十八碳四烯酸)', '状态' => '新!'], + 'MUFA 20:1' => ['中文意思' => '单不饱和脂肪酸20:1(二十碳一烯酸)', '状态' => '新!'], + 'PUFA 20:5 n-3 (EPA)' => ['中文意思' => '多不饱和脂肪酸20:5 n-3(EPA)', '状态' => '新!'], + 'MUFA 22:1' => ['中文意思' => '单不饱和脂肪酸22:1(芥酸)', '状态' => '新!'], + 'PUFA 22:5 n-3 (DPA)' => ['中文意思' => '多不饱和脂肪酸22:5 n-3(DPA)', '状态' => '新!'], + 'TFA 14:1 t' => ['中文意思' => '反式脂肪酸14:1 t', '状态' => '新!'], + 'Phytosterols' => ['中文意思' => '植物固醇', '状态' => '新!'], + 'Ergosterol' => ['中文意思' => '麦角固醇', '状态' => '新!'], + 'Stigmasterol' => ['中文意思' => '豆甾醇', '状态' => '新!'], + 'Campesterol' => ['中文意思' => '菜油甾醇', '状态' => '新!'], + 'Brassicasterol' => ['中文意思' => '菜籽甾醇', '状态' => '新!'], + 'Beta-sitosterol' => ['中文意思' => 'β-谷甾醇', '状态' => '新!'], + 'Campestanol' => ['中文意思' => '菜油甾烷醇', '状态' => '新!'], + 'Unsaponifiable matter (lipids)' => ['中文意思' => '不皂化物(脂质)', '状态' => '新!'], + 'Fatty acids, other than 607-615, 617-621, 624-632, 652-654, 686-689)' => ['中文意思' => '其他脂肪酸(除指定范围)', '状态' => '新!'], + 'Fatty acids, total monounsaturated' => ['中文意思' => '总单不饱和脂肪酸', '状态' => '新!'], + 'Fatty acids, total polyunsaturated' => ['中文意思' => '总多不饱和脂肪酸', '状态' => '新!'], + 'Beta-sitostanol' => ['中文意思' => 'β-谷甾烷醇', '状态' => '新!'], + 'Delta-7-avenasterol' => ['中文意思' => 'Δ7-燕麦甾醇', '状态' => '新!'], + 'Delta-5-avenasterol' => ['中文意思' => 'Δ5-燕麦甾醇', '状态' => '新!'], + 'Alpha-spinasterol' => ['中文意思' => 'α-菠菜甾醇', '状态' => '新!'], + 'Phytosterols, other' => ['中文意思' => '其他植物固醇', '状态' => '新!'], + 'SFA 15:0' => ['中文意思' => '饱和脂肪酸15:0(十五酸)', '状态' => '新!'], + 'SFA 17:0' => ['中文意思' => '饱和脂肪酸17:0(十七酸)', '状态' => '新!'], + 'SFA 24:0' => ['中文意思' => '饱和脂肪酸24:0(木焦油酸)', '状态' => '新!'], + 'Wax Esters(Total Wax)' => ['中文意思' => '蜡酯(总蜡)', '状态' => '新!'], + 'TFA 16:1 t' => ['中文意思' => '反式脂肪酸16:1 t', '状态' => '新!'], + 'TFA 18:1 t' => ['中文意思' => '反式脂肪酸18:1 t', '状态' => '新!'], + 'TFA 22:1 t' => ['中文意思' => '反式脂肪酸22:1 t', '状态' => '新!'], + 'TFA 18:2 t not further defined' => ['中文意思' => '反式脂肪酸18:2 t(未进一步定义)', '状态' => '新!'], + 'PUFA 18:2 i' => ['中文意思' => '多不饱和脂肪酸18:2 i(异构体)', '状态' => '新!'], + 'PUFA 18:2 t,c' => ['中文意思' => '多不饱和脂肪酸18:2 t,c', '状态' => '新!'], + 'PUFA 18:2 c,t' => ['中文意思' => '多不饱和脂肪酸18:2 c,t', '状态' => '新!'], + 'TFA 18:2 t,t' => ['中文意思' => '反式脂肪酸18:2 t,t', '状态' => '新!'], + 'PUFA 18:2 CLAs' => ['中文意思' => '多不饱和脂肪酸18:2(共轭亚油酸)', '状态' => '新!'], + 'MUFA 24:1 c' => ['中文意思' => '单不饱和脂肪酸24:1 c(神经酸)', '状态' => '新!'], + 'PUFA 20:2 n-6 c,c' => ['中文意思' => '多不饱和脂肪酸20:2 n-6 c,c', '状态' => '新!'], + 'MUFA 16:1 c' => ['中文意思' => '单不饱和脂肪酸16:1 c(顺式棕榈油酸)', '状态' => '新!'], + 'MUFA 18:1 c' => ['中文意思' => '单不饱和脂肪酸18:1 c(顺式油酸)', '状态' => '新!'], + 'PUFA 18:2 n-6 c,c' => ['中文意思' => '多不饱和脂肪酸18:2 n-6 c,c(亚油酸)', '状态' => '新!'], + 'MUFA 22:1 c' => ['中文意思' => '单不饱和脂肪酸22:1 c(顺式芥酸)', '状态' => '新!'], + 'Fatty acids, saturated, other' => ['中文意思' => '其他饱和脂肪酸', '状态' => '新!'], + 'Fatty acids, monounsat., other' => ['中文意思' => '其他单不饱和脂肪酸', '状态' => '新!'], + 'Fatty acids, polyunsat., other' => ['中文意思' => '其他多不饱和脂肪酸', '状态' => '新!'], + 'PUFA 18:3 n-6 c,c,c' => ['中文意思' => '多不饱和脂肪酸18:3 n-6 c,c,c(γ-亚麻酸)', '状态' => '新!'], + 'SFA 19:0' => ['中文意思' => '饱和脂肪酸19:0(十九酸)', '状态' => '新!'], + 'MUFA 17:1' => ['中文意思' => '单不饱和脂肪酸17:1(十七碳一烯酸)', '状态' => '新!'], + 'PUFA 16:2' => ['中文意思' => '多不饱和脂肪酸16:2(十六碳二烯酸)', '状态' => '新!'], + 'PUFA 20:3' => ['中文意思' => '多不饱和脂肪酸20:3(二十碳三烯酸)', '状态' => '新!'], + 'Fatty acids, total sat., NLEA' => ['中文意思' => '总饱和脂肪酸(NLEA)', '状态' => '新!'], + 'Fatty acids, total monounsat., NLEA' => ['中文意思' => '总单不饱和脂肪酸(NLEA)', '状态' => '新!'], + 'Fatty acids, total polyunsat., NLEA' => ['中文意思' => '总多不饱和脂肪酸(NLEA)', '状态' => '新!'], + 'Fatty acids, total trans-monoenoic' => ['中文意思' => '总反式单烯酸', '状态' => '新!'], + 'Fatty acids, total trans-dienoic' => ['中文意思' => '总反式二烯酸', '状态' => '新!'], + 'Fatty acids, total trans-polyenoic' => ['中文意思' => '总反式多烯酸', '状态' => '新!'], + 'SFA 13:0' => ['中文意思' => '饱和脂肪酸13:0(十三酸)', '状态' => '新!'], + 'MUFA 15:1' => ['中文意思' => '单不饱和脂肪酸15:1(十五碳一烯酸)', '状态' => '新!'], + 'PUFA 22:2' => ['中文意思' => '多不饱和脂肪酸22:2(二十二碳二烯酸)', '状态' => '新!'], + 'SFA 11:0' => ['中文意思' => '饱和脂肪酸11:0(十一酸)', '状态' => '新!'], + 'ORAC, Hydrophyllic' => ['中文意思' => '亲水性氧自由基吸收能力', '状态' => '新!'], + 'ORAC, Lipophillic' => ['中文意思' => '亲脂性氧自由基吸收能力', '状态' => '新!'], + 'ORAC, Total' => ['中文意思' => '总氧自由基吸收能力', '状态' => '新!'], + 'Total Phenolics' => ['中文意思' => '总酚类化合物', '状态' => '新!'], + 'Daidzein' => ['中文意思' => '大豆苷元', '状态' => '新!'], + 'Genistein' => ['中文意思' => '染料木素', '状态' => '新!'], + 'Glycitein' => ['中文意思' => '黄豆黄素', '状态' => '新!'], + 'Isoflavones' => ['中文意思' => '异黄酮', '状态' => '新!'], + 'Biochanin A' => ['中文意思' => '鹰嘴豆素A', '状态' => '新!'], + 'Formononetin' => ['中文意思' => '芒柄花素', '状态' => '新!'], + 'Coumestrol' => ['中文意思' => '香豆雌酚', '状态' => '新!'], + 'Flavonoids, total' => ['中文意思' => '总黄酮', '状态' => '新!'], + 'Anthocyanidins' => ['中文意思' => '花青素', '状态' => '新!'], + 'Cyanidin' => ['中文意思' => '矢车菊素', '状态' => '新!'], + 'Proanthocyanidin (dimer-A linkage)' => ['中文意思' => '原花青素(A型二聚体)', '状态' => '新!'], + 'Proanthocyanidin monomers' => ['中文意思' => '原花青素单体', '状态' => '新!'], + 'Proanthocyanidin dimers' => ['中文意思' => '原花青素二聚体', '状态' => '新!'], + 'Proanthocyanidin trimers' => ['中文意思' => '原花青素三聚体', '状态' => '新!'], + 'Proanthocyanidin 4-6mers' => ['中文意思' => '原花青素4-6聚体', '状态' => '新!'], + 'Proanthocyanidin 7-10mers' => ['中文意思' => '原花青素7-10聚体', '状态' => '新!'], + 'Proanthocyanidin polymers (>10mers)' => ['中文意思' => '原花青素聚合物(>10聚体)', '状态' => '新!'], + 'Delphinidin' => ['中文意思' => '飞燕草素', '状态' => '新!'], + 'Malvidin' => ['中文意思' => '锦葵色素', '状态' => '新!'], + 'Pelargonidin' => ['中文意思' => '天竺葵素', '状态' => '新!'], + 'Peonidin' => ['中文意思' => '芍药素', '状态' => '新!'], + 'Petunidin' => ['中文意思' => '矮牵牛素', '状态' => '新!'], + 'Flavans, total' => ['中文意思' => '总黄烷', '状态' => '新!'], + 'Catechins, total' => ['中文意思' => '总儿茶素', '状态' => '新!'], + 'Catechin' => ['中文意思' => '儿茶素', '状态' => '新!'], + 'Epigallocatechin' => ['中文意思' => '表没食子儿茶素', '状态' => '新!'], + 'Epicatechin' => ['中文意思' => '表儿茶素', '状态' => '新!'], + 'Epicatechin-3-gallate' => ['中文意思' => '表儿茶素-3-没食子酸酯', '状态' => '新!'], + 'Epigallocatechin-3-gallate' => ['中文意思' => '表没食子儿茶素-3-没食子酸酯', '状态' => '新!'], + 'Procyanidins, total' => ['中文意思' => '总原花青素', '状态' => '新!'], + 'Theaflavins' => ['中文意思' => '茶黄素', '状态' => '新!'], + 'Thearubigins' => ['中文意思' => '茶红素', '状态' => '新!'], + 'Flavanones, total' => ['中文意思' => '总黄烷酮', '状态' => '新!'], + 'Eriodictyol' => ['中文意思' => '圣草酚', '状态' => '新!'], + 'Hesperetin' => ['中文意思' => '橙皮素', '状态' => '新!'], + 'Isosakuranetin' => ['中文意思' => '异樱花素', '状态' => '新!'], + 'Liquiritigenin' => ['中文意思' => '甘草素', '状态' => '新!'], + 'Naringenin' => ['中文意思' => '柚皮素', '状态' => '新!'], + 'Flavones, total' => ['中文意思' => '总黄酮', '状态' => '新!'], + 'Apigenin' => ['中文意思' => '芹菜素', '状态' => '新!'], + 'Chrysoeriol' => ['中文意思' => '金圣草黄素', '状态' => '新!'], + 'Diosmetin' => ['中文意思' => '香叶木素', '状态' => '新!'], + 'Luteolin' => ['中文意思' => '木犀草素', '状态' => '新!'], + 'Nobiletin' => ['中文意思' => '川陈皮素', '状态' => '新!'], + 'Sinensetin' => ['中文意思' => '甜橙黄酮', '状态' => '新!'], + 'Tangeretin' => ['中文意思' => '橘皮素', '状态' => '新!'], + 'Flavonols, total' => ['中文意思' => '总黄酮醇', '状态' => '新!'], + 'Isorhamnetin' => ['中文意思' => '异鼠李素', '状态' => '新!'], + 'Kaempferol' => ['中文意思' => '山奈酚', '状态' => '新!'], + 'Limocitrin' => ['中文意思' => '柠檬黄酮', '状态' => '新!'], + 'Myricetin' => ['中文意思' => '杨梅素', '状态' => '新!'], + 'Quercetin' => ['中文意思' => '槲皮素', '状态' => '新!'], + 'Theogallin' => ['中文意思' => '茶没食子素', '状态' => '新!'], + "Theaflavin -3,3' -digallate" => ['中文意思' => "茶黄素-3,3'-双没食子酸酯", '状态' => '新!'], + "Theaflavin -3' -gallate" => ['中文意思' => "茶黄素-3'-没食子酸酯", '状态' => '新!'], + 'Theaflavin -3 -gallate' => ['中文意思' => '茶黄素-3-没食子酸酯', '状态' => '新!'], + '(+) -Gallo catechin' => ['中文意思' => '(+)-没食子儿茶素', '状态' => '新!'], + '(+)-Catechin 3-gallate' => ['中文意思' => '(+)-儿茶素-3-没食子酸酯', '状态' => '新!'], + '(+)-Gallocatechin 3-gallate' => ['中文意思' => '(+)-没食子儿茶素-3-没食子酸酯', '状态' => '新!'], + 'Mannose' => ['中文意思' => '甘露糖', '状态' => '新!'], + 'Triose' => ['中文意思' => '丙糖', '状态' => '新!'], + 'Tetrose' => ['中文意思' => '丁糖', '状态' => '新!'], + 'Other Saccharides' => ['中文意思' => '其他糖类', '状态' => '新!'], + 'Inulin' => ['中文意思' => '菊粉', '状态' => '新!'], + 'PUFA 18:3 n-3 c,c,c (ALA)' => ['中文意思' => '多不饱和脂肪酸18:3 n-3 c,c,c(α-亚麻酸)', '状态' => '新!'], + 'PUFA 20:3 n-3' => ['中文意思' => '多不饱和脂肪酸20:3 n-3', '状态' => '新!'], + 'PUFA 20:3 n-6' => ['中文意思' => '多不饱和脂肪酸20:3 n-6', '状态' => '新!'], + 'PUFA 20:4 n-3' => ['中文意思' => '多不饱和脂肪酸20:4 n-3', '状态' => '新!'], + 'PUFA 20:4 n-6' => ['中文意思' => '多不饱和脂肪酸20:4 n-6(花生四烯酸)', '状态' => '新!'], + 'PUFA 18:3i' => ['中文意思' => '多不饱和脂肪酸18:3i(异构体)', '状态' => '新!'], + 'PUFA 21:5' => ['中文意思' => '多不饱和脂肪酸21:5(二十一碳五烯酸)', '状态' => '新!'], + 'PUFA 22:4' => ['中文意思' => '多不饱和脂肪酸22:4(二十二碳四烯酸)', '状态' => '新!'], + 'MUFA 18:1-11 t (18:1t n-7)' => ['中文意思' => '单不饱和脂肪酸18:1-11 t(反式十八碳一烯酸n-7)', '状态' => '新!'], + 'MUFA 18:1-11 c (18:1c n-7)' => ['中文意思' => '单不饱和脂肪酸18:1-11 c(顺式十八碳一烯酸n-7)', '状态' => '新!'], + 'PUFA 20:3 n-9' => ['中文意思' => '多不饱和脂肪酸20:3 n-9', '状态' => '新!'], + 'Total Sugars' => ['中文意思' => '总糖', '状态' => '新!'], + 'SFA 5:0' => ['中文意思' => '饱和脂肪酸5:0(戊酸)', '状态' => '新!'], + 'SFA 7:0' => ['中文意思' => '饱和脂肪酸7:0(庚酸)', '状态' => '新!'], + 'SFA 9:0' => ['中文意思' => '饱和脂肪酸9:0(壬酸)', '状态' => '新!'], + 'SFA 21:0' => ['中文意思' => '饱和脂肪酸21:0(二十一酸)', '状态' => '新!'], + 'SFA 23:0' => ['中文意思' => '饱和脂肪酸23:0(二十三酸)', '状态' => '新!'], + 'MUFA 12:1' => ['中文意思' => '单不饱和脂肪酸12:1(十二碳一烯酸)', '状态' => '新!'], + 'MUFA 14:1 c' => ['中文意思' => '单不饱和脂肪酸14:1 c(顺式肉豆蔻油酸)', '状态' => '新!'], + 'MUFA 17:1 c' => ['中文意思' => '单不饱和脂肪酸17:1 c(顺式十七碳一烯酸)', '状态' => '新!'], + 'TFA 17:1 t' => ['中文意思' => '反式脂肪酸17:1 t(反式十七碳一烯酸)', '状态' => '新!'], + 'MUFA 20:1 c' => ['中文意思' => '单不饱和脂肪酸20:1 c(顺式二十碳一烯酸)', '状态' => '新!'], + 'TFA 20:1 t' => ['中文意思' => '反式脂肪酸20:1 t(反式二十碳一烯酸)', '状态' => '新!'], + 'MUFA 22:1 n-9' => ['中文意思' => '单不饱和脂肪酸22:1 n-9(芥酸n-9)', '状态' => '新!'], + 'MUFA 22:1 n-11' => ['中文意思' => '单不饱和脂肪酸22:1 n-11(芥酸n-11)', '状态' => '新!'], + 'PUFA 18:2 c' => ['中文意思' => '多不饱和脂肪酸18:2 c(顺式)', '状态' => '新!'], + 'TFA 18:2 t' => ['中文意思' => '反式脂肪酸18:2 t', '状态' => '新!'], + 'PUFA 18:3 c' => ['中文意思' => '多不饱和脂肪酸18:3 c(顺式)', '状态' => '新!'], + 'TFA 18:3 t' => ['中文意思' => '反式脂肪酸18:3 t', '状态' => '新!'], + 'PUFA 20:3 c' => ['中文意思' => '多不饱和脂肪酸20:3 c(顺式)', '状态' => '新!'], + 'PUFA 22:3' => ['中文意思' => '多不饱和脂肪酸22:3(二十二碳三烯酸)', '状态' => '新!'], + 'PUFA 20:4c' => ['中文意思' => '多不饱和脂肪酸20:4 c(顺式花生四烯酸)', '状态' => '新!'], + 'PUFA 20:5c' => ['中文意思' => '多不饱和脂肪酸20:5 c(顺式EPA)', '状态' => '新!'], + 'PUFA 22:5 c' => ['中文意思' => '多不饱和脂肪酸22:5 c(顺式DPA)', '状态' => '新!'], + 'PUFA 22:6 c' => ['中文意思' => '多不饱和脂肪酸22:6 c(顺式DHA)', '状态' => '新!'], + 'PUFA 20:2 c' => ['中文意思' => '多不饱和脂肪酸20:2 c(顺式)', '状态' => '新!'], + 'Proximate' => ['中文意思' => '近似成分', '状态' => '新!'], + 'trans-beta-Carotene' => ['中文意思' => '反式-β-胡萝卜素', '状态' => '新!'], + 'trans-Lycopene' => ['中文意思' => '反式-番茄红素', '状态' => '新!'], + 'Cryptoxanthin, alpha' => ['中文意思' => 'α-隐黄质', '状态' => '新!'], + 'Total dietary fiber (AOAC 2011.25)' => ['中文意思' => '总膳食纤维(AOAC 2011.25方法)', '状态' => '新!'], + 'Insoluble dietary fiber (IDF)' => ['中文意思' => '不溶性膳食纤维', '状态' => '新!'], + 'Soluble dietary fiber (SDFP+SDFS)' => ['中文意思' => '可溶性膳食纤维(SDFP+SDFS)', '状态' => '新!'], + 'Soluble dietary fiber (SDFP)' => ['中文意思' => '可溶性膳食纤维(SDFP)', '状态' => '新!'], + 'Soluble dietary fiber (SDFS)' => ['中文意思' => '可溶性膳食纤维(SDFS)', '状态' => '新!'], + 'High Molecular Weight Dietary Fiber (HMWDF)' => ['中文意思' => '高分子量膳食纤维', '状态' => '新!'], + 'Carbohydrates' => ['中文意思' => '碳水化合物', '状态' => '新!'], + 'Other carotenoids' => ['中文意思' => '其他类胡萝卜素', '状态' => '新!'], + 'Tocopherols and tocotrienols' => ['中文意思' => '生育酚和生育三烯酚', '状态' => '新!'], + 'Amino acids' => ['中文意思' => '氨基酸', '状态' => '新!'], + 'Minerals' => ['中文意思' => '矿物质', '状态' => '新!'], + 'Lipids' => ['中文意思' => '脂质', '状态' => '新!'], + 'Proximates' => ['中文意思' => '近似成分', '状态' => '新!'], + 'Vitamins and Other Components' => ['中文意思' => '维生素及其他成分', '状态' => '新!'], + 'Total Tocopherols' => ['中文意思' => '总生育酚', '状态' => '新!'], + 'Total Tocotrienols' => ['中文意思' => '总生育三烯酚', '状态' => '新!'], + 'Stigmastadiene' => ['中文意思' => '豆甾二烯', '状态' => '新!'], + 'Delta-7-Stigmastenol' => ['中文意思' => 'Δ7-豆甾烯醇', '状态' => '新!'], + 'Daidzin' => ['中文意思' => '大豆苷', '状态' => '新!'], + 'Genistin' => ['中文意思' => '染料木苷', '状态' => '新!'], + 'Glycitin' => ['中文意思' => '黄豆黄苷', '状态' => '新!'], + 'Ergothioneine' => ['中文意思' => '麦角硫因', '状态' => '新!'], + 'Beta-glucan' => ['中文意思' => 'β-葡聚糖', '状态' => '新!'], + 'Vitamin D4' => ['中文意思' => '维生素D4', '状态' => '新!'], + 'Ergosta-7-enol' => ['中文意思' => '麦角甾-7-烯醇', '状态' => '新!'], + 'Ergosta-7,22-dienol' => ['中文意思' => '麦角甾-7,22-二烯醇', '状态' => '新!'], + 'Ergosta-5,7-dienol' => ['中文意思' => '麦角甾-5,7-二烯醇', '状态' => '新!'], + 'Verbascose' => ['中文意思' => '毛蕊花糖', '状态' => '新!'], + 'Oligosaccharides' => ['中文意思' => '低聚糖', '状态' => '新!'], + 'Low Molecular Weight Dietary Fiber (LMWDF)' => ['中文意思' => '低分子量膳食纤维', '状态' => '新!'], + 'Vitamin E' => ['中文意思' => '维生素E', '状态' => '新!'], + 'Vitamin A' => ['中文意思' => '维生素A', '状态' => '新!'], + 'Glutathione' => ['中文意思' => '谷胱甘肽', '状态' => '新!'], + ]; + $cfc = Db::connect('cfc_db'); + $result = []; + $shiwu_data= $cfc->table('linshi_usa_data_copy')->where(['id'=>126])->order('id')->find(); + + + // dump($shiwu_data); + // dump(explode(',',$shiwu_data['fdc_id'])); + // die; + $result['shiwu_data'] = $shiwu_data; + $yingyang_list = $cfc->table('linshi_usa_yingyang_guanlian') + ->alias('a') + ->join('linshi_usa_yingyang_list w','a.nutrient_id = w.yuanshi_id','LEFT') + ->where("fdc_id in (".$shiwu_data['fdc_id'].")") + ->field('a.*,w.name') + ->select(); + + // ->count(); + // dump($yingyang_list); + // die; + $yingyang_data = []; + foreach ($yingyang_list as $key => $value) { + if(array_key_exists($value['name'],$yingyang_data)){ + $yingyang_data[$value['name']]['value'][] = $value['amount']; + }else{ + $yingyang_data[$value['name']]['en'] = $value['name']; + $yingyang_data[$value['name']]['ch'] = $nutritionArray[$value['name']]['中文意思']; + $yingyang_data[$value['name']]['status'] = $nutritionArray[$value['name']]['状态']; + $yingyang_data[$value['name']]['value'] = [$value['amount']]; + } + } + $yingyang_data2 = ['default_num'=>0,'default'=>[],'new_num'=>0,'new'=>[]]; + foreach ($yingyang_data as $key => $value) { + if($value['status'] == '默认'){ + $yingyang_data2['default'][] = $value; + }else{ + $yingyang_data2['new'][] = $value; + } + } + $yingyang_data2['default_num'] = count($yingyang_data2['default']); + $yingyang_data2['new_num'] = count($yingyang_data2['new']); + $result['yingyang'] = $yingyang_data2; + return $this->msg($result); + + + } + + + public function next_pass_action(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + if($data['id'] == 0){ + $result = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where("status is null")->order('id')->find(); + return $this->msg($result); + } + + $cfc->startTrans(); + try{ + $cfc->table('app_z_national_standard_food_type_3_multilingual')->where(['id'=>$data['id']])->update([ + 'status'=>$data['type'] + ]); + $result = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where("status is null")->order('id')->find(); + // 提交事务 + $cfc->commit(); + return $this->msg($result); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + return $this->msg(10002); + } + } + public function pass_action(){ + $data = input(); + } + + + + + ###########################################################################使用API进行处理的########################################################################### + ###########################################################################使用API进行处理的########################################################################### + ###########################################################################使用API进行处理的########################################################################### + + public function new_step1_action(){ + $data = input(); + $page_size = 3; + // $curl_result = $this->queryUSDAFoodsRaw('Foundation',['pageSize'=>3,'pageNumber'=>1]); + $curl_result = $this->queryUSDAFoodsRaw('Foundation',['pageSize'=>$page_size,'pageNumber'=>$data['page']]); + if($curl_result === false){ + return $this->msg(99999); + } + // return $this->msg($curl_result); + // 定义营养成分映射关系 + $nutrientMapping = [ + 'Calorie' => ['Energy (Atwater General Factors)', 'Energy (Atwater Specific Factors)', 'Energy'], + 'Protein' => ['Protein'], + 'Fat' => ['Total lipid (fat)', 'Total fat (NLEA)'], + 'Carbohydrate' => ['Carbohydrate, by difference', 'Carbohydrate, by summation', 'Carbohydrates'], + 'VitaminA' => ['Vitamin A, IU', 'Vitamin A, RAE', 'Vitamin A, RE', 'Vitamin A', 'Retinol', 'Vitamin A, RAE'], + 'VitaminB1' => ['Thiamin', 'Thiamin, added', 'Thiamin, intrinsic'], + 'VitaminB2' => ['Riboflavin', 'Riboflavin, added', 'Riboflavin, intrinsic'], + 'VitaminB6' => ['Vitamin B-6', 'Vitamin B-6, pyridoxine, alcohol form', 'Vitamin B-6, pyridoxal, aldehyde form', 'Vitamin B-6, pyridoxamine, amine form', 'Vitamin B-6, N411 + N412 +N413'], + 'VitaminB12' => ['Vitamin B-12', 'Vitamin B-12, added', 'Vitamin B-12, intrinsic'], + 'VitaminD' => ['Vitamin D (D2 + D3)', 'Vitamin D (D2 + D3), International Units', 'Vitamin D2 (ergocalciferol)', 'Vitamin D3 (cholecalciferol)', '25-hydroxycholecalciferol', '25-hydroxyergocalciferol', 'Vitamin D4'], + 'VitaminK' => ['Vitamin K (phylloquinone)', 'Vitamin K (Menaquinone-4)', 'Vitamin K (Dihydrophylloquinone)', 'Vitamin K'], + 'Niacin' => ['Niacin', 'Niacin equivalent N406 +N407', 'Niacin from tryptophan, determined', 'Niacin, added', 'Niacin, intrinsic'], + 'VitaminC' => ['Vitamin C, total ascorbic acid', 'Vitamin C, reduced ascorbic acid', 'Vitamin C, dehydro ascorbic acid', 'Vitamin C, added', 'Vitamin C, intrinsic', 'Vitamin C'], + 'VitaminE' => ['Vitamin E (alpha-tocopherol)', 'Vitamin E (label entry primarily)', 'Tocopherol, beta', 'Tocopherol, gamma', 'Tocopherol, delta', 'Vitamin E, added', 'Vitamin E, intrinsic', 'Vitamin E'], + 'FolicAcid' => ['Folic acid', 'Folate, total', 'Folate, free', 'Folate, food', 'Folate, DFE', '5-methyl tetrahydrofolate (5-MTHF)', 'Folate, not 5-MTHF', '10-Formyl folic acid (10HCOFA)', '5-Formyltetrahydrofolic acid (5-HCOH4', 'Tetrahydrofolic acid (THF)'], + 'Biotin' => ['Biotin'], + 'PantothenicAcid' => ['Pantothenic acid'], + 'TotalCholine' => ['Choline, total', 'Choline, free', 'Choline, from phosphocholine', 'Choline, from phosphotidyl choline', 'Choline, from glycerophosphocholine', 'Choline, from sphingomyelin'], + 'Ca' => ['Calcium, Ca', 'Calcium, added', 'Calcium, intrinsic'], + 'Phosphorus' => ['Phosphorus, P'], + 'Kalium' => ['Potassium, K'], + 'Mg' => ['Magnesium, Mg'], + 'Na' => ['Sodium, Na'], + 'Fe' => ['Iron, Fe', 'Iron, heme', 'Iron, non-heme', 'Iron, added', 'Iron, intrinsic'], + 'Zn' => ['Zinc, Zn'], + 'Se' => ['Selenium, Se'], + 'Cu' => ['Copper, Cu'], + 'Mn' => ['Manganese, Mn'], + 'Iodine' => ['Iodine, I'] + ]; + $v_k = [ + // === 维生素 (2) === + 'Vitamin A, IU' => 2, + 'Vitamin A, RAE' => 2, + 'Vitamin A, RE' => 2, + 'Vitamin A' => 2, + 'Retinol' => 2, + + 'Vitamin B-6' => 2, + 'Vitamin B-6, pyridoxine, alcohol form' => 2, + 'Vitamin B-6, pyridoxal, aldehyde form' => 2, + 'Vitamin B-6, pyridoxamine, amine form' => 2, + 'Vitamin B-6, N411 + N412 +N413' => 2, + + 'Vitamin B-12' => 2, + 'Vitamin B-12, added' => 2, + 'Vitamin B-12, intrinsic' => 2, + + 'Vitamin C, total ascorbic acid' => 2, + 'Vitamin C, reduced ascorbic acid' => 2, + 'Vitamin C, dehydro ascorbic acid' => 2, + 'Vitamin C, added' => 2, + 'Vitamin C, intrinsic' => 2, + 'Vitamin C' => 2, + + 'Vitamin D (D2 + D3)' => 2, + 'Vitamin D (D2 + D3), International Units' => 2, + 'Vitamin D2 (ergocalciferol)' => 2, + 'Vitamin D3 (cholecalciferol)' => 2, + '25-hydroxycholecalciferol' => 2, + '25-hydroxyergocalciferol' => 2, + 'Vitamin D4' => 2, + + 'Vitamin E (alpha-tocopherol)' => 2, + 'Vitamin E (label entry primarily)' => 2, + 'Tocopherol, beta' => 2, + 'Tocopherol, gamma' => 2, + 'Tocopherol, delta' => 2, + 'Vitamin E, added' => 2, + 'Vitamin E, intrinsic' => 2, + 'Vitamin E' => 2, + + 'Vitamin K (phylloquinone)' => 2, + 'Vitamin K (Menaquinone-4)' => 2, + 'Vitamin K (Dihydrophylloquinone)' => 2, + 'Vitamin K' => 2, + + 'Thiamin' => 2, + 'Thiamin, added' => 2, + 'Thiamin, intrinsic' => 2, + + 'Riboflavin' => 2, + 'Riboflavin, added' => 2, + 'Riboflavin, intrinsic' => 2, + + 'Niacin' => 2, + 'Niacin equivalent N406 +N407' => 2, + 'Niacin from tryptophan, determined' => 2, + 'Niacin, added' => 2, + 'Niacin, intrinsic' => 2, + + 'Folic acid' => 2, + 'Folate, total' => 2, + 'Folate, free' => 2, + 'Folate, food' => 2, + 'Folate, DFE' => 2, + '5-methyl tetrahydrofolate (5-MTHF)' => 2, + 'Folate, not 5-MTHF' => 2, + '10-Formyl folic acid (10HCOFA)' => 2, + '5-Formyltetrahydrofolic acid (5-HCOH4' => 2, + 'Tetrahydrofolic acid (THF)' => 2, + + 'Biotin' => 2, + 'Pantothenic acid' => 2, + + 'Choline, total' => 2, + 'Choline, free' => 2, + 'Choline, from phosphocholine' => 2, + 'Choline, from phosphotidyl choline' => 2, + 'Choline, from glycerophosphocholine' => 2, + 'Choline, from sphingomyelin' => 2, + + // === 矿物质 (3) === + 'Calcium, Ca' => 3, + 'Calcium, added' => 3, + 'Calcium, intrinsic' => 3, + + 'Phosphorus, P' => 3, + + 'Potassium, K' => 3, + + 'Magnesium, Mg' => 3, + + 'Sodium, Na' => 3, + + 'Iron, Fe' => 3, + 'Iron, heme' => 3, + 'Iron, non-heme' => 3, + 'Iron, added' => 3, + 'Iron, intrinsic' => 3, + + 'Zinc, Zn' => 3, + + 'Selenium, Se' => 3, + + 'Copper, Cu' => 3, + + 'Manganese, Mn' => 3, + + 'Iodine, I' => 3, + + // 其他矿物质 + 'Chlorine, Cl' => 3, + 'Sulfur, S' => 3, + 'Chromium, Cr' => 3, + 'Cobalt, Co' => 3, + 'Fluoride, F' => 3, + 'Molybdenum, Mo' => 3, + 'Aluminum, Al' => 3, + 'Antimony, Sb' => 3, + 'Arsenic, As' => 3, + 'Barium, Ba' => 3, + 'Beryllium, Be' => 3, + 'Boron, B' => 3, + 'Bromine, Br' => 3, + 'Cadmium, Cd' => 3, + 'Gold, Au' => 3, + 'Lead, Pb' => 3, + 'Lithium, Li' => 3, + 'Mercury, Hg' => 3, + 'Nickel, Ni' => 3, + 'Rubidium, Rb' => 3, + 'Silicon, Si' => 3, + 'Silver, Ag' => 3, + 'Strontium, Sr' => 3, + 'Tin, Sn' => 3, + 'Titanium, Ti' => 3, + 'Vanadium, V' => 3 + ]; + $food_data = []; + $nutrients_data = []; + $nutrients_data2 = []; + $temporary_data1 = []; + $temporary_data2 = []; + // 如果有数据,不是最后一页 + if(count($curl_result['foods'])){ + $temporary_data1 = []; + $temporary_data2 = [ + 'Calorie' => [], + 'Protein' => [], + 'Fat' => [], + 'Carbohydrate' => [], + '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' => [] + ]; + + foreach ($curl_result['foods'] as $key => $value) { + // 处理食材数据 + $temporary_data1['record_id'] = $value['fdcId']; + $temporary_data1['food_name'] = ''; + $temporary_data1['Calorie_name'] = '卡路里'; + $temporary_data1['Calorie_unit'] = 'kcal'; + $temporary_data1['Calorie_val'] = '/'; + $temporary_data1['Protein_name'] = '蛋白质'; + $temporary_data1['Protein_unit'] = 'g'; + $temporary_data1['Protein_val'] = '/'; + $temporary_data1['Fat_name'] = '脂肪'; + $temporary_data1['Fat_unit'] = 'g'; + $temporary_data1['Fat_val'] = '/'; + $temporary_data1['Carbohydrate_name'] = '碳水化合物'; + $temporary_data1['Carbohydrate_unit'] = 'g'; + $temporary_data1['Carbohydrate_val'] = '/'; + $temporary_data1['two_id'] = $value['foodCategory']; + $temporary_data1['weight_unit'] = 'g'; + $temporary_data1['data_type'] = $value['dataType']; + $temporary_data1['food_name_en'] = $value['description']; + $food_data[] = $temporary_data1; + + // 处理营养成分数据 + // 使用映射表处理数据 + foreach ($value['foodNutrients'] as $k => $v) { + if(!array_key_exists('value',$v)){ + continue; + }else{ + $nutrientName = $v['nutrientName']; + foreach ($nutrientMapping as $category => $names) { + if (in_array($nutrientName, $names)) { + $temporary_data2[$category][$nutrientName] = [$v['value'], $v['unitName']]; + break; // 找到匹配后跳出内层循环 + } + } + } + } + $nutrients_data[$value['fdcId']] = $temporary_data2; + } + + // 重新处理数据,最终数据 + $temporary_data3 = []; + foreach ($food_data as $key => $value) { + $temporary_data3 = []; + foreach ($nutrients_data[$value['record_id']] as $k => $v) { + if($k == 'Calorie'){ + if(count($v) > 0){ + if(array_key_exists('Energy (Atwater General Factors)',$v)){ + $food_data[$key]['Calorie_val'] = $v['Energy (Atwater General Factors)'][0]; + $food_data[$key]['Calorie_unit'] = $v['Energy (Atwater General Factors)'][1]; + }else if(array_key_exists('Energy (Atwater Specific Factors)',$v)){ + $food_data[$key]['Calorie_val'] = $v['Energy (Atwater Specific Factors)'][0]; + $food_data[$key]['Calorie_unit'] = $v['Energy (Atwater Specific Factors)'][1]; + }else if(array_key_exists('Energy',$v)){ + $food_data[$key]['Calorie_val'] = $v['Energy'][0]; + $food_data[$key]['Calorie_unit'] = $v['Energy'][1]; + } + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>$food_data[$key]['Calorie_val'], + 'unit'=>$food_data[$key]['Calorie_unit'], + 'type'=>1, + ]; + // $temporary_data3['name'] = $k; + // $temporary_data3['value'] = $food_data[$key]['Calorie_val']; + // $temporary_data3['unit'] = $food_data[$key]['Calorie_unit']; + // $temporary_data3['type'] = 1; + }else{ + $food_data[$key]['Calorie_val'] = 0; + $food_data[$key]['Calorie_unit'] = 'KCAL'; + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>0, + 'unit'=>'KCAL', + 'type'=>1, + ]; + } + }else if($k == 'Protein'){ + if(count($v) > 0){ + $food_data[$key]['Protein_val'] = $v['Protein'][0]; + $food_data[$key]['Protein_unit'] = $v['Protein'][1]; + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>$v['Protein'][0], + 'unit'=>$v['Protein'][1], + 'type'=>1, + ]; + }else{ + $food_data[$key]['Protein_val'] = 0; + $food_data[$key]['Protein_unit'] = 'G'; + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>0, + 'unit'=>'G', + 'type'=>1, + ]; + } + }else if($k == 'Fat'){ + if(count($v) > 0){ + if(array_key_exists('Total lipid (fat)',$v)){ + $food_data[$key]['Fat_val'] = $v['Total lipid (fat)'][0]; + $food_data[$key]['Fat_unit'] = $v['Total lipid (fat)'][1]; + }else if(array_key_exists('Total fat (NLEA)',$v)){ + $food_data[$key]['Fat_val'] = $v['Total fat (NLEA)'][0]; + $food_data[$key]['Fat_unit'] = $v['Total fat (NLEA)'][1]; + } + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>$food_data[$key]['Fat_val'], + 'unit'=>$food_data[$key]['Fat_unit'], + 'type'=>1, + ]; + }else{ + $food_data[$key]['Fat_val'] = 0; + $food_data[$key]['Fat_unit'] = 'G'; + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>0, + 'unit'=>'G', + 'type'=>1, + ]; + } + }else if($k == 'Carbohydrate'){ + if(count($v) > 0){ + if(array_key_exists('Carbohydrate, by difference',$v)){ + $food_data[$key]['Carbohydrate_val'] = $v['Carbohydrate, by difference'][0]; + $food_data[$key]['Carbohydrate_unit'] = $v['Carbohydrate, by difference'][1]; + }else if(array_key_exists('Carbohydrate, by summation',$v)){ + $food_data[$key]['Carbohydrate_val'] = $v['Carbohydrate, by summation'][0]; + $food_data[$key]['Carbohydrate_unit'] = $v['Carbohydrate, by summation'][1]; + }else if(array_key_exists('Carbohydrates',$v)){ + $food_data[$key]['Carbohydrate_val'] = $v['Carbohydrates'][0]; + $food_data[$key]['Carbohydrate_unit'] = $v['Carbohydrates'][1]; + } + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>$food_data[$key]['Carbohydrate_val'], + 'unit'=>$food_data[$key]['Carbohydrate_unit'], + 'type'=>1, + ]; + }else{ + $food_data[$key]['Carbohydrate_val'] = 0; + $food_data[$key]['Carbohydrate_unit'] = 'G'; + $temporary_data3[] = [ + 'name'=>$k, + 'value'=>0, + 'unit'=>'G', + 'type'=>1, + ]; + } + }else{ + if(count($v) > 0){ + foreach ($v as $kk => $vv) { + if($vv[0] != 0){ + $temporary_data3[] = [ + 'name'=>$kk, + 'value'=>$vv[0], + 'unit'=>$vv[1], + 'type'=>array_key_exists($kk,$v_k)?$v_k[$kk]:0, + ]; + } + } + } + } + } + $nutrients_data2[$value['record_id']] = $temporary_data3; + } + + // return $this->msg(['food'=>$food_data,'yingyang'=>$nutrients_data2]); + + + // 开始插入数据库 + $cfc = Db::connect('cfc_db'); + + $linshi_chalou = false; + $chongfu_chalou = 0; + $chongfu_chalou_arr = []; + $success_num = []; + + // 过滤重复数据 + foreach ($food_data as $key => $value) { + $congfu_num = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1') + ->where(['food_name_en' => $value['food_name_en']]) + ->find(); + + if ($congfu_num) { + unset($food_data[$key]); + $chongfu_chalou++; + } + } + + + // 如果没有需要插入的数据,直接返回 + if (empty($food_data)) { + return $this->msg([ + 'now_page' => $data['page'], + 'total_num' => $page_size, + 'fail_num' => 0, + 'chongfu_num' => $chongfu_chalou, + 'success_num' => 0, + ]); + } + // 启动事务 + $cfc->startTrans(); + try{ + + foreach ($food_data as $key => $value) { + $new_id = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->insertGetId($value); + foreach ($nutrients_data2[$value['record_id']] as $k => $v) { + $nutrients_data2[$value['record_id']][$k]['father_id'] = $new_id; + } + $cfc->table('app_z_national_standard_food_type_4_multilingual_copy1')->insertAll($nutrients_data2[$value['record_id']]); + $success_num[] = $value['food_name_en']; + } + // 提交事务 + $cfc->commit(); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + $error_message = $e->getMessage(); + $linshi_chalou = true; + } + + if($linshi_chalou == true){ + foreach ($food_data as $key => $value) { + $chongfu_chalou_arr[] = ['name'=>$value['food_name_en']]; + } + $cfc->table('linshi_z_chalou')->insertAll($chongfu_chalou_arr); + } + + + return $this->msg([ + 'now_page' => $data['page'], + 'total_num' => $page_size, + 'fail_num' => count($chongfu_chalou_arr), + 'chongfu_num' => $chongfu_chalou, + 'success_num' => count($success_num), + ]); + }else{ + return $this->msg(10006); + } + + + } + + + /** + * 查询美国农业部食品数据库 + * 支持按数据类型查询食材及其营养成分 + * + * @param string $dataType 数据类型:'Foundation', 'SR Legacy', 'Survey (FNDDS)', 'Branded' + * @param array $params 查询参数 + * - query: 搜索关键词(可选) + * - pageSize: 每页数量,默认10 + * - pageNumber: 页码,默认1 + * - includeNutrients: 是否包含营养成分,默认true + * - nutrientIds: 指定营养成分ID数组(可选) + * - sortBy: 排序字段,默认'relevance' + * - sortOrder: 排序顺序,默认'desc' + * @return array 返回API数据 + */ + public function queryUSDAFoodsRaw($dataType, $params = []) { + $apiKey = '4HgkqLdr0tXrufKZpgA5TB2KTcDmFuzrfFl9t0YW'; + $url = "https://api.nal.usda.gov/fdc/v1/foods/search?api_key={$apiKey}"; + + $requestBody = [ + 'dataType' => [$dataType], + 'pageSize' => $params['pageSize'] ?? 10, + 'pageNumber' => $params['pageNumber'] ?? 1 + ]; + + if (!empty($params['query'])) { + $requestBody['query'] = $params['query']; + } + + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => json_encode($requestBody), + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_SSL_VERIFYHOST => false + ]); + + $response = curl_exec($ch); + curl_close($ch); + + return $response ? json_decode($response, true) : false; + } + + ################################################################################################################### + ################################################################################################################### + ################################################################################################################### + + + public function msg($data,$str='',$result = []){ + if(is_array($data)){ + if($str != ''){ + return json(['code'=>0,'msg'=>$str,'data'=>$data]); + }else{ + return json(['code'=>0,'msg'=>'操作成功','data'=>$data]); + } + }else{ + if($str != ''){ + return json(['code'=>$data,'msg'=>$str,'data'=>$result]); + } + return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]); + } + } + // 使用纯BC函数的版本(最精确) + public function processPrecisionNumberBC($numberStr) { + // 1. 去除数字末尾的0 + $processed = rtrim($numberStr, '0'); + + if ($processed === '' || $processed === '.') { + return '0'; + } + + $processed = rtrim($processed, '.'); + + // 2. 判断小数点后的位数 + $dotPosition = strpos($processed, '.'); + + if ($dotPosition === false) { + return $processed; + } + + $decimalLength = strlen($processed) - $dotPosition - 1; + + // 3. 如果小数点长度不超过5位,直接返回 + if ($decimalLength <= 5) { + return $processed; + } + + // 4. 使用BC函数处理 + $decimalPart = substr($processed, $dotPosition + 1); + + // 找到第一个非零字符的位置 + $firstNonZeroPos = -1; + for ($i = 0; $i < strlen($decimalPart); $i++) { + if ($decimalPart[$i] !== '0') { + $firstNonZeroPos = $i; + break; + } + } + + if ($firstNonZeroPos === -1) { + return $processed; + } + + // 计算需要保留的小数位数 + $keepDecimalPlaces = $firstNonZeroPos + 1; + + // 使用BC函数进行截断 + $number = $processed; + $multiplier = bcpow('10', $keepDecimalPlaces); + + // 方法:乘以倍数,取整数部分(截断),再除以倍数 + $scaled = bcmul($number, $multiplier, 20); + + // 取整数部分(直接截断小数部分) + $integerPart = bcdiv($scaled, '1', 0); + + // 得到截断后的结果 + $result = bcdiv($integerPart, $multiplier, $keepDecimalPlaces); + + // 去除末尾0 + $result = rtrim($result, '0'); + if (substr($result, -1) === '.') { + $result = rtrim($result, '.'); + } + + return $result === '' ? '0' : $result; + } +} \ No newline at end of file diff --git a/application/test/view/xishuju1/xishuju1_qd_page.html b/application/test/view/xishuju1/xishuju1_qd_page.html new file mode 100644 index 0000000..1e3425d --- /dev/null +++ b/application/test/view/xishuju1/xishuju1_qd_page.html @@ -0,0 +1,263 @@ + + +
+ + +