脚本2025 12 19
This commit is contained in:
parent
0c86dbe0c6
commit
110c0b39cf
|
|
@ -13,7 +13,8 @@ class Base extends Controller{
|
||||||
protected $base_use_db_name = [
|
protected $base_use_db_name = [
|
||||||
'6'=>'app_account_number',
|
'6'=>'app_account_number',
|
||||||
'search_history'=>'app_user_search_history',
|
'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 $token_time = 30;//30天的秒数
|
||||||
protected $file_size = 5*1024*1024;
|
protected $file_size = 5*1024*1024;
|
||||||
|
|
@ -152,6 +153,7 @@ class Base extends Controller{
|
||||||
// 判断token是否过期
|
// 判断token是否过期
|
||||||
public function token_time_validate($token){
|
public function token_time_validate($token){
|
||||||
// 591b70e0d80b5fa6d77e6e1384453ab9
|
// 591b70e0d80b5fa6d77e6e1384453ab9
|
||||||
|
|
||||||
if(is_string($token)){
|
if(is_string($token)){
|
||||||
$length = strlen($token);
|
$length = strlen($token);
|
||||||
if ($length < 10 ) {
|
if ($length < 10 ) {
|
||||||
|
|
@ -162,13 +164,12 @@ class Base extends Controller{
|
||||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log');
|
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$cfc = Db::connect('cfc_db');
|
||||||
$user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find();
|
$user_login = $cfc->table($this->base_use_db_name['user'])->where(['token'=>$token])->field('id,login_time')->find();
|
||||||
if(!$user_login){
|
if(!$user_login){
|
||||||
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log');
|
Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建 DateTime 对象来表示指定的日期和时间
|
// 创建 DateTime 对象来表示指定的日期和时间
|
||||||
$specifiedDateTime = new \DateTime($user_login['login_time']);
|
$specifiedDateTime = new \DateTime($user_login['login_time']);
|
||||||
|
|
||||||
|
|
@ -192,7 +193,7 @@ class Base extends Controller{
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
// echo "未超过 {$specifiedDays} 天";
|
// 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){
|
if($user_login){
|
||||||
Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log');
|
Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log');
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -335,25 +336,25 @@ class Base extends Controller{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
|
|
||||||
switch ($unit) {
|
switch ($unit) {
|
||||||
// case 'g':
|
case 'g':
|
||||||
case '克':
|
case '克':
|
||||||
// 已经是克,直接返回
|
// 已经是克,直接返回
|
||||||
$result = $weight;
|
$result = $weight;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'oz':
|
case 'oz':
|
||||||
case '盎司':
|
case '盎司':
|
||||||
// 盎司转克
|
// 盎司转克
|
||||||
$result = bcmul($weight,$G_PER_OZ,2);
|
$result = bcmul($weight,$G_PER_OZ,2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'lb':
|
case 'lb':
|
||||||
case '磅':
|
case '磅':
|
||||||
// 磅转克
|
// 磅转克
|
||||||
$result = bcmul($weight,$G_PER_LB,2);
|
$result = bcmul($weight,$G_PER_LB,2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// case 'lb:oz':
|
case 'lb:oz':
|
||||||
case '磅:盎司':
|
case '磅:盎司':
|
||||||
// 磅:盎司复合单位处理
|
// 磅:盎司复合单位处理
|
||||||
if (strpos($weight, ':') !== false) {
|
if (strpos($weight, ':') !== false) {
|
||||||
|
|
|
||||||
|
|
@ -461,36 +461,36 @@ class Cookbook extends Base{
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// 获取所有食谱label
|
// 获取所有食谱label
|
||||||
public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
// public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
// 尝试捕获异常
|
// // 尝试捕获异常
|
||||||
try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
// if(count(input('post.')) > 0){
|
||||||
$data = input('post.');
|
// $data = input('post.');
|
||||||
}
|
// }
|
||||||
if(!array_key_exists('token', $data)){
|
// if(!array_key_exists('token', $data)){
|
||||||
return $this->msg(10001,'token is miss');
|
// return $this->msg(10001,'token is miss');
|
||||||
}
|
// }
|
||||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
// if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||||
return $this->msg(10005,'token type is error');
|
// return $this->msg(10005,'token type is error');
|
||||||
}
|
// }
|
||||||
|
|
||||||
$return_data = $this->get_cookbook_label_list_action($data);
|
// $return_data = $this->get_cookbook_label_list_action($data);
|
||||||
return $return_data;
|
// return $return_data;
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
// 捕获异常
|
// // 捕获异常
|
||||||
$logContent["flie"] = $e->getFile();
|
// $logContent["flie"] = $e->getFile();
|
||||||
$logContent["line"] = $e->getLine();
|
// $logContent["line"] = $e->getLine();
|
||||||
$logContent['all_content'] = "异常信息:\n";
|
// $logContent['all_content'] = "异常信息:\n";
|
||||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||||
// 记录日志
|
// // 记录日志
|
||||||
$this->record_api_log($data, $logContent, null);
|
// $this->record_api_log($data, $logContent, null);
|
||||||
return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 获取查询页页面导航食材列表
|
// 获取查询页页面导航食材列表
|
||||||
public function get_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
public function get_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
|
|
@ -1379,32 +1379,32 @@ class Cookbook extends Base{
|
||||||
'content_list'=>$collect_list
|
'content_list'=>$collect_list
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
public function get_cookbook_label_list_action(){
|
// public function get_cookbook_label_list_action(){
|
||||||
$cfc = Db::connect('cfc_db');
|
// $cfc = Db::connect('cfc_db');
|
||||||
// 获取菜谱分类标签start
|
// // 获取菜谱分类标签start
|
||||||
$cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])
|
// $cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])
|
||||||
->where("is_del = 0")
|
// ->where("is_del = 0")
|
||||||
->field('id,name')
|
// ->field('id,name')
|
||||||
->select();
|
// ->select();
|
||||||
$temporary_label = [];
|
// $temporary_label = [];
|
||||||
foreach ($cook_label as $key => $value) {
|
// foreach ($cook_label as $key => $value) {
|
||||||
unset($cook_label[$key]['ROW_NUMBER']);
|
// unset($cook_label[$key]['ROW_NUMBER']);
|
||||||
$cook_label[$key]['list'] = [];
|
// $cook_label[$key]['list'] = [];
|
||||||
$temporary_label[$value['id']] = $key;
|
// $temporary_label[$value['id']] = $key;
|
||||||
}
|
// }
|
||||||
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
// $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||||
->alias('a')
|
// ->alias('a')
|
||||||
->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT')
|
// ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT')
|
||||||
->where(['a.is_del'=>0])
|
// ->where(['a.is_del'=>0])
|
||||||
->field('a.id,a.cook_label,a.title,b.pic_url as cover')
|
// ->field('a.id,a.cook_label,a.title,b.pic_url as cover')
|
||||||
->select();
|
// ->select();
|
||||||
foreach ($content_list as $key => $value) {
|
// foreach ($content_list as $key => $value) {
|
||||||
unset($content_list[$key]['ROW_NUMBER']);
|
// unset($content_list[$key]['ROW_NUMBER']);
|
||||||
array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]);
|
// array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]);
|
||||||
}
|
// }
|
||||||
return $this->msg($cook_label);
|
// return $this->msg($cook_label);
|
||||||
// 获取菜谱分类标签end
|
// // 获取菜谱分类标签end
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function get_search_food_page_list_action($data){
|
public function get_search_food_page_list_action($data){
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
|
||||||
|
|
@ -279,6 +279,43 @@ class Countfood extends Base{
|
||||||
return json(['status' => 'error', 'message' => '系统错误']);
|
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#######################################################################
|
#######################################################################action#######################################################################
|
||||||
#######################################################################action#######################################################################
|
#######################################################################action#######################################################################
|
||||||
|
|
@ -1118,6 +1155,7 @@ class Countfood extends Base{
|
||||||
'list'=>[
|
'list'=>[
|
||||||
[
|
[
|
||||||
'name'=>'碳水化合物',
|
'name'=>'碳水化合物',
|
||||||
|
'key_v'=>'carbohydrate',
|
||||||
'icon'=>'icon-tanshuihuahewu',
|
'icon'=>'icon-tanshuihuahewu',
|
||||||
'proportion'=>$nutrition_data['carbohydrate_p'],
|
'proportion'=>$nutrition_data['carbohydrate_p'],
|
||||||
'val'=>$nutrition_data['carbohydrate'],
|
'val'=>$nutrition_data['carbohydrate'],
|
||||||
|
|
@ -1125,6 +1163,7 @@ class Countfood extends Base{
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name'=>'蛋白质',
|
'name'=>'蛋白质',
|
||||||
|
'key_v'=>'protein',
|
||||||
'icon'=>'icon-Sm-danbaizhi',
|
'icon'=>'icon-Sm-danbaizhi',
|
||||||
'proportion'=>$nutrition_data['protein_p'],
|
'proportion'=>$nutrition_data['protein_p'],
|
||||||
'val'=>$nutrition_data['protein'],
|
'val'=>$nutrition_data['protein'],
|
||||||
|
|
@ -1132,6 +1171,7 @@ class Countfood extends Base{
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name'=>'脂肪',
|
'name'=>'脂肪',
|
||||||
|
'key_v'=>'fat',
|
||||||
'icon'=>'icon-w_fat_normal',
|
'icon'=>'icon-w_fat_normal',
|
||||||
'proportion'=>$nutrition_data['fat_p'],
|
'proportion'=>$nutrition_data['fat_p'],
|
||||||
'val'=>$nutrition_data['fat'],
|
'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占比
|
// 计算每日每餐kcal占比
|
||||||
public function calculate_kcal_proportion($data){
|
public function calculate_kcal_proportion($data){
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace app\KitchenScale2\controller\app;
|
||||||
|
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use app\KitchenScale2\controller\app\Guessyoulike;
|
use app\KitchenScale2\controller\app\Guessyoulike;
|
||||||
|
use app\KitchenScale2\controller\app\Language;
|
||||||
|
|
||||||
class Index extends Base{
|
class Index extends Base{
|
||||||
|
|
||||||
|
|
@ -36,6 +37,28 @@ class Index extends Base{
|
||||||
'banner'=>'admin_notice_banner',//菜谱表
|
'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)
|
// 加 bcadd(,,20)
|
||||||
|
|
@ -49,15 +72,46 @@ class Index extends Base{
|
||||||
// 检测版本及判断是否登录失效
|
// 检测版本及判断是否登录失效
|
||||||
public function login_invalid_version($data = ['token'=>'']){
|
public function login_invalid_version($data = ['token'=>'']){
|
||||||
try {
|
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){
|
if(count(input('post.')) > 0){
|
||||||
$data = input('post.');
|
$data = input('post.');
|
||||||
}
|
}
|
||||||
// if(!array_key_exists('token', $data)){
|
if(!array_key_exists('token', $data)){
|
||||||
// return $this->msg(10001);
|
return $this->msg(10001);
|
||||||
// }
|
}
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
||||||
$result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find();
|
$result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find();
|
||||||
|
|
||||||
if($result){
|
if($result){
|
||||||
$version = $result['version_num_original'];
|
$version = $result['version_num_original'];
|
||||||
$url = $result['download_url'];
|
$url = $result['download_url'];
|
||||||
|
|
@ -65,13 +119,20 @@ class Index extends Base{
|
||||||
$version = '';
|
$version = '';
|
||||||
$url = '';
|
$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){
|
if($user_token_state['state'] === false){
|
||||||
$this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]);
|
return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>$language_data]);
|
||||||
return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]);
|
|
||||||
}else{
|
}else{
|
||||||
$this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]);
|
return $this->msg(['version'=>$version,'url'=>$url,'language'=>$language_data]);
|
||||||
return $this->msg(['version'=>$version,'url'=>$url]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
@ -82,12 +143,26 @@ class Index extends Base{
|
||||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||||
|
$logContent['all_content'] .= "方法: " . __METHOD__ . "\n";
|
||||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||||
$this->record_api_log($data, $logContent, null);
|
$this->record_api_log($data, $logContent, null);
|
||||||
return $this->msg(99999);
|
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']){
|
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'=>'高度活动(每周6-7天高强度运动)','val'=>'1.725'],
|
||||||
['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'],
|
['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'],
|
||||||
],
|
],
|
||||||
|
'language_arr'=>$this->process_Language()
|
||||||
];
|
];
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
||||||
|
|
@ -876,5 +952,25 @@ class Index extends Base{
|
||||||
}
|
}
|
||||||
return $str;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,240 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\KitchenScale2\controller\app;
|
||||||
|
|
||||||
|
class Language extends Base
|
||||||
|
{
|
||||||
|
// 支持的语言列表
|
||||||
|
protected $supportedLanguages = [
|
||||||
|
'en' => '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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,6 +29,18 @@ class Usercenter extends Base{
|
||||||
'business_cooperation'=>'app_business_cooperation_log',//商务合作
|
'business_cooperation'=>'app_business_cooperation_log',//商务合作
|
||||||
'eat_log'=>'app_user_kcal_log',//食材列表3
|
'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)
|
// 加 bcadd(,,20)
|
||||||
|
|
@ -452,6 +464,40 @@ class Usercenter extends Base{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -576,14 +576,14 @@ class Base extends Controller{
|
||||||
if (is_string($data)) {
|
if (is_string($data)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
|
// $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else if($type == 'num'){
|
}else if($type == 'num'){
|
||||||
if (is_numeric($data)) {
|
if (is_numeric($data)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
|
// $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}else if($type == 'intnum'){
|
}else if($type == 'intnum'){
|
||||||
|
|
@ -591,7 +591,7 @@ class Base extends Controller{
|
||||||
if (preg_match($pattern, $data)) {
|
if (preg_match($pattern, $data)) {
|
||||||
return true; // 匹配成功,返回 true
|
return true; // 匹配成功,返回 true
|
||||||
} else {
|
} else {
|
||||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
|
// $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]);
|
||||||
return false; // 匹配失败,返回 false
|
return false; // 匹配失败,返回 false
|
||||||
}
|
}
|
||||||
}else if($type == 'datetime'){
|
}else if($type == 'datetime'){
|
||||||
|
|
@ -604,7 +604,7 @@ class Base extends Controller{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果所有格式都解析失败,则返回 false
|
// 如果所有格式都解析失败,则返回 false
|
||||||
$this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
|
// $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]);
|
||||||
return false;
|
return false;
|
||||||
}else if($type == 'other'){
|
}else if($type == 'other'){
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace app\app\controller;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use app\app\controller\Calculatebody;
|
use app\app\controller\Calculatebody;
|
||||||
use app\app\controller\Cardparts;
|
use app\app\controller\Cardparts;
|
||||||
|
use app\app\controller\Xinlv;
|
||||||
|
|
||||||
class Card extends Base{
|
class Card extends Base{
|
||||||
|
|
||||||
|
|
@ -97,6 +98,12 @@ class Card extends Base{
|
||||||
if(!array_key_exists('aud_id', $data)){
|
if(!array_key_exists('aud_id', $data)){
|
||||||
return $this->msg(10001);
|
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')){
|
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||||
return $this->msg(10005);
|
return $this->msg(10005);
|
||||||
}
|
}
|
||||||
|
|
@ -537,6 +544,7 @@ class Card extends Base{
|
||||||
acbd.bmi,
|
acbd.bmi,
|
||||||
acbd.body_age,
|
acbd.body_age,
|
||||||
acbd.head_circumference,
|
acbd.head_circumference,
|
||||||
|
acbd.heart_rate,
|
||||||
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date
|
||||||
from ".$this->card_use_db_name['1']." as acbd
|
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
|
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_weight'=>'0',
|
||||||
'cumulative_day'=>'0'
|
'cumulative_day'=>'0'
|
||||||
],
|
],
|
||||||
|
'heart_rate_data'=>[],
|
||||||
];
|
];
|
||||||
return $this->msg($result_return);
|
return $this->msg($result_return);
|
||||||
}else{
|
}else{
|
||||||
|
|
@ -753,6 +762,19 @@ class Card extends Base{
|
||||||
}
|
}
|
||||||
// 这段业务处理可以删除,是做的临时的,假的end
|
// 这段业务处理可以删除,是做的临时的,假的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);
|
return $this->msg($result_end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1168,6 +1190,24 @@ class Card extends Base{
|
||||||
$set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']);
|
$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();
|
Db::startTrans();
|
||||||
try{
|
try{
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ class Index extends Base{
|
||||||
################################################################个人资料卡################################################################
|
################################################################个人资料卡################################################################
|
||||||
|
|
||||||
// 检测版本及判断是否登录失效
|
// 检测版本及判断是否登录失效
|
||||||
public function login_invalid_version($data = ['token'=>'2d4ea9b3f44b169ddf64b2f3d2725ceb']){
|
public function login_invalid_version($data = ['token'=>'']){
|
||||||
try {
|
try {
|
||||||
// 获取客户端IP
|
// 获取客户端IP
|
||||||
$ip = request()->ip();
|
$ip = request()->ip();
|
||||||
|
|
@ -146,6 +146,10 @@ class Index extends Base{
|
||||||
$version = '';
|
$version = '';
|
||||||
$url = '';
|
$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']);
|
$user_token_state = $this->token_time_validate($data['token']);
|
||||||
$language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language);
|
$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]){
|
public function get_user_data_information($data = ['aud_id'=>61]){
|
||||||
// try {
|
try {
|
||||||
// 你的业务逻辑
|
// 你的业务逻辑
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
$data = input('post.');
|
$data = input('post.');
|
||||||
|
|
@ -492,19 +496,19 @@ class Index extends Base{
|
||||||
}
|
}
|
||||||
$this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]);
|
$this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]);
|
||||||
return $this->msg($result);
|
return $this->msg($result);
|
||||||
// } catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// // 捕获异常
|
// 捕获异常
|
||||||
// $logContent["flie"] = $e->getFile();
|
$logContent["flie"] = $e->getFile();
|
||||||
// $logContent["line"] = $e->getLine();
|
$logContent["line"] = $e->getLine();
|
||||||
// $logContent['all_content'] = "异常信息:\n";
|
$logContent['all_content'] = "异常信息:\n";
|
||||||
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||||
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||||
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||||
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||||
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||||
// $this->record_api_log($data, $logContent, null);
|
$this->record_api_log($data, $logContent, null);
|
||||||
// return $this->msg(99999);
|
return $this->msg(99999);
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,30 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\app\controller;
|
namespace app\KitchenScale2\controller\app;
|
||||||
|
|
||||||
class Language extends Base
|
class Language extends Base
|
||||||
{
|
{
|
||||||
// 支持的语言列表
|
// 支持的语言列表
|
||||||
protected $supportedLanguages = [
|
protected $supportedLanguages = [
|
||||||
'en' => 'English',
|
'en' => 'English',
|
||||||
'zh-Hans' => 'Chinese',
|
'zh' => '中文',
|
||||||
'es' => 'Spanish',
|
// 'es' => 'Spanish',
|
||||||
'fr' => 'French',
|
// 'fr' => 'French',
|
||||||
'pt' => 'Portuguese',
|
// 'pt' => 'Portuguese',
|
||||||
'ar' => 'Arabic',
|
// 'ar' => 'Arabic',
|
||||||
'ru' => 'Russian',
|
// 'ru' => 'Russian',
|
||||||
'de' => 'German'
|
// 'de' => 'German'
|
||||||
];
|
];
|
||||||
|
// zh, //中文
|
||||||
|
// en, // 英语
|
||||||
|
// jp, //日语(变化)
|
||||||
|
// fra, //法语(变化)
|
||||||
|
// de, //德语
|
||||||
|
// kor, //韩语(变化)
|
||||||
|
// ru, //俄语
|
||||||
|
// pt, //葡萄牙
|
||||||
|
// spa, //西班牙(变化)
|
||||||
|
// ara, //阿拉伯(变化)
|
||||||
|
|
||||||
// 语言映射表
|
// 语言映射表
|
||||||
protected $languageMap = [
|
protected $languageMap = [
|
||||||
|
|
@ -99,6 +109,23 @@ class Language extends Base
|
||||||
'《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》",
|
'《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》",
|
||||||
'头围' => "Head Circumference",
|
'头围' => "Head Circumference",
|
||||||
'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.",
|
'头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "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",
|
||||||
|
|
||||||
],
|
],
|
||||||
// 可以添加更多语言映射
|
// 可以添加更多语言映射
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ use think\Db;
|
||||||
class Msginformation extends Base{
|
class Msginformation extends Base{
|
||||||
|
|
||||||
|
|
||||||
protected $judge_wechat_release = false;
|
protected $judge_wechat_release = true;
|
||||||
|
|
||||||
protected $msginformation_use_db_name = [
|
protected $msginformation_use_db_name = [
|
||||||
'1'=>'admin_editor_text_content',
|
'1'=>'admin_editor_text_content',
|
||||||
|
|
@ -536,9 +536,9 @@ class Msginformation extends Base{
|
||||||
################################################################小工具################################################################
|
################################################################小工具################################################################
|
||||||
|
|
||||||
// 判断微信发版工具
|
// 判断微信发版工具
|
||||||
public function judge_wechat_release(){
|
// public function judge_wechat_release(){
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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 {
|
try {
|
||||||
// 你的业务逻辑
|
// 你的业务逻辑
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -29,6 +29,9 @@ class Myinformation extends Base{
|
||||||
if(!array_key_exists('token', $data)){
|
if(!array_key_exists('token', $data)){
|
||||||
return $this->msg(10001);
|
return $this->msg(10001);
|
||||||
}
|
}
|
||||||
|
if($data['token'] == ''){
|
||||||
|
return $this->msg(-2,'特殊状态',[]);
|
||||||
|
}
|
||||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||||
return $this->msg(10005);
|
return $this->msg(10005);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,204 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\app\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
|
||||||
|
|
||||||
|
class Xinlv extends Base{
|
||||||
|
protected $db_name = [
|
||||||
|
'xinlv'=>'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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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('/vitalcapacity_curve_chart', 'app/vitalcapacity/vitalcapacity_curve_chart');
|
||||||
Route::any('/testedition/vitalcapacity_curve_chart', 'testapp/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');
|
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('/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('/kitchenscale/get_default_config', 'app/Kitchenscale/app.Index/get_default_config');
|
||||||
Route::any('/kitchenscale2/get_default_config', 'app/Kitchenscale2/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('/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('/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('/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_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('/update_cookbook_data_api', 'test/testuse/update_cookbook_data_api');
|
||||||
Route::any('/cun_bendi_pic', 'test/testuse/cun_bendi_pic');
|
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');
|
// Route::any('/app_update_file/*', 'app/sportstesting/aaaaaaaaaaaaaaa');
|
||||||
// 处理404错误 z
|
// 处理404错误 z
|
||||||
Route::miss(function(){
|
// Route::miss(function(){
|
||||||
return '404 Not Found(out)';
|
// return '404 Not Found(out)';
|
||||||
// 或者你可以重定向到一个错误页面,或者进行其他处理
|
// // 或者你可以重定向到一个错误页面,或者进行其他处理
|
||||||
});
|
// });
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,337 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\test\controller;
|
||||||
|
|
||||||
|
use think\Controller;
|
||||||
|
use think\facade\Log;
|
||||||
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
|
class Baidufanyi extends Controller
|
||||||
|
{
|
||||||
|
// API Key - 按你说的放在控制器属性中
|
||||||
|
protected $api_key = 'hMo4_d4p9d29a9802e5gscdf0';
|
||||||
|
|
||||||
|
// 百度翻译API地址
|
||||||
|
protected $api_url = 'https://fanyi-api.baidu.com/ait/api/aiTextTranslate';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 百度翻译函数
|
||||||
|
* @param string $q 待翻译文本
|
||||||
|
* @param string $from 源语言(默认中文)
|
||||||
|
* @param string $to 目标语言(默认英文)
|
||||||
|
* @param array $options 可选参数
|
||||||
|
* - needIntervene: 是否使用自定义术语干预
|
||||||
|
* - model_type: 翻译模型 'llm'或'nmt'
|
||||||
|
* - reference: 自定义翻译指令
|
||||||
|
* - tag_handling: 标签保持功能
|
||||||
|
* - ignore_tags: 自定义标签
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function baiduTranslate($q, $from = 'zh', $to = 'en', $options = [])
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// 构建请求数据
|
||||||
|
$data = [
|
||||||
|
'q' => $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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,263 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>洗数据1</title>
|
||||||
|
<script src="/x_admin/js/jq.js"></script>
|
||||||
|
<style>
|
||||||
|
*{
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
body{
|
||||||
|
padding: 10px 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cook{
|
||||||
|
width:90vw;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
.start_action{
|
||||||
|
width: 50px;
|
||||||
|
height: 30px;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 30px;
|
||||||
|
border: 1px solid red;
|
||||||
|
padding: 1px;
|
||||||
|
box-shadow: 1px 1px 1px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.title{
|
||||||
|
font-size: 50px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.centent{
|
||||||
|
font-size: 50px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.red{
|
||||||
|
color: red;
|
||||||
|
font-size: 30px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.green{
|
||||||
|
color: green;
|
||||||
|
font-size: 30px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="start_action" onclick="start_action2()">开始</div>
|
||||||
|
<div class="title">描述:</div>
|
||||||
|
<div class="centent"></div><br/><br/>
|
||||||
|
<div>~~~~~~~~~~~~~~~~~~~~~~分割线~~~~~~~~~~~~~~~~~~~~</div>
|
||||||
|
<div>ID:<span id='id_data' class="">0</span></div>
|
||||||
|
<div>名称:<span id='name' class="">0</span></div>
|
||||||
|
<div>卡路里:<span class="Calorie">0</span></div>
|
||||||
|
<div>蛋白质:<span class="Protein">0</span></div>
|
||||||
|
<div>脂肪:<span class="Fat">0</span></div>
|
||||||
|
<div>碳水:<span class="Carbohydrate">0</span></div>
|
||||||
|
<div class="start_action" onclick="next()">下一个</div>
|
||||||
|
<div class="start_action" onclick="pass()">pass</div>
|
||||||
|
<!-- <div>累积成功<span class="ok">0</span>项</div>
|
||||||
|
<div>查找菜谱失败<span class="no1">0</span>项</div>
|
||||||
|
<div>修改数据失败<span class="no2">0</span>项</div>
|
||||||
|
<div class="cook"><span style="width:89vw;">成功原始菜谱id:</span><br/></div> -->
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var page = 1;
|
||||||
|
var content = 0;
|
||||||
|
var content2 = 0;
|
||||||
|
var content3 = 0;
|
||||||
|
var str = '';
|
||||||
|
var error_num = 0;
|
||||||
|
var success_num = 0,chongfu_num = 0,fail_num = 0,total_num = 0;
|
||||||
|
// 处理图片表跟食谱表的数据统一
|
||||||
|
function start_action(){
|
||||||
|
$.ajax({
|
||||||
|
// url:"xishuju1_action", //请求的url地址
|
||||||
|
// url:"xishuju2_action", //请求的url地址
|
||||||
|
url:"xishuju3_action", //请求的url地址
|
||||||
|
dataType:"json", //返回格式为json
|
||||||
|
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
|
data:{"page":page}, //参数值
|
||||||
|
type:"POST", //请求方式
|
||||||
|
success:function(req){
|
||||||
|
//请求成功时处理
|
||||||
|
// console.log(req.msg)
|
||||||
|
if(req.code == 0){
|
||||||
|
content = content + 1
|
||||||
|
str = "<p>处理成功:"+content+"项</p>"
|
||||||
|
+ "<p>处理失败:"+content2+"项</p>"
|
||||||
|
$('.centent').html(str)
|
||||||
|
setTimeout(() => {
|
||||||
|
start_action()
|
||||||
|
}, 100);
|
||||||
|
}else if(req.code == 10004){
|
||||||
|
str = "<p>处理成功:"+content+"项</p>"
|
||||||
|
+ "<p>处理失败:"+content2+"项</p>"
|
||||||
|
+ "<p>处理完毕</p>"
|
||||||
|
$('.centent').html(str)
|
||||||
|
}else{
|
||||||
|
content2 = content2 + 1
|
||||||
|
str = "<p>处理成功:"+content+"项</p>"
|
||||||
|
+ "<p>处理失败:"+content2+"项</p>"
|
||||||
|
$('.centent').html(str)
|
||||||
|
setTimeout(() => {
|
||||||
|
error_action(req.data.id,req.code)
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
//请求出错处理
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
function error_action(id,code){
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:"error_action", //请求的url地址
|
||||||
|
dataType:"json", //返回格式为json
|
||||||
|
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
|
data:{"id":id,"code":code}, //参数值
|
||||||
|
type:"POST", //请求方式
|
||||||
|
success:function(req){
|
||||||
|
//请求成功时处理
|
||||||
|
// console.log(req.msg)
|
||||||
|
if(req.code == 0){
|
||||||
|
setTimeout(() => {
|
||||||
|
start_action()
|
||||||
|
}, 100);
|
||||||
|
}else if(req.code == 10002){
|
||||||
|
if(error_num >= 5){
|
||||||
|
error_num = 0
|
||||||
|
setTimeout(() => {
|
||||||
|
start_action()
|
||||||
|
}, 100);
|
||||||
|
}else{
|
||||||
|
error_num = error_num + 1
|
||||||
|
setTimeout(() => {
|
||||||
|
error_action(id,code)
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
//请求出错处理
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function start_action2(){
|
||||||
|
$.ajax({
|
||||||
|
url:"new_step1_action", //请求的url地址
|
||||||
|
dataType:"json", //返回格式为json
|
||||||
|
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
|
data:{"page":page}, //参数值
|
||||||
|
type:"POST", //请求方式
|
||||||
|
success:function(req){
|
||||||
|
//请求成功时处理
|
||||||
|
|
||||||
|
if(req.code == 0){
|
||||||
|
success_num = success_num+req.data.success_num
|
||||||
|
fail_num = fail_num+req.data.fail_num
|
||||||
|
chongfu_num = chongfu_num+req.data.chongfu_num
|
||||||
|
total_num = total_num+req.data.total_num
|
||||||
|
// console.log(success_num)
|
||||||
|
// console.log(chongfu_num)
|
||||||
|
// console.log(fail_num)
|
||||||
|
// console.log(total_num)
|
||||||
|
str = "<p>处理成功:"+(success_num)+"项</p>"
|
||||||
|
+ "<p>处理失败:"+(fail_num)+"项</p>"
|
||||||
|
+ "<p>处理重复:"+(chongfu_num)+"项</p>"
|
||||||
|
+ "<p>总计处理:"+(total_num)+"项</p>"
|
||||||
|
$('.centent').html(str)
|
||||||
|
page = page+1
|
||||||
|
setTimeout(() => {
|
||||||
|
start_action2()
|
||||||
|
}, 100);
|
||||||
|
}else if(req.code == 10006){
|
||||||
|
$('.centent').append('<p>处理完成!</p>');
|
||||||
|
// $('.centent').html(str)
|
||||||
|
// setTimeout(() => {
|
||||||
|
// error_action(req.data.id,req.code)
|
||||||
|
// }, 100);
|
||||||
|
}else{
|
||||||
|
setTimeout(() => {
|
||||||
|
start_action2()
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
//请求出错处理
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// document.addEventListener('keydown', function(event) {
|
||||||
|
// // 按下左箭头键 ←
|
||||||
|
// if (event.key === 'ArrowLeft') {
|
||||||
|
// pass(); // 触发pass函数
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // 按下右箭头键 →
|
||||||
|
// if (event.key === 'ArrowRight') {
|
||||||
|
// next(); // 触发next函数
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// function next(){
|
||||||
|
// next_pass_qq($('span#id_data').html(),'next')
|
||||||
|
// }
|
||||||
|
// function pass(){
|
||||||
|
// next_pass_qq($('span#id_data').html(),'pass')
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function next_pass_qq(id,type){
|
||||||
|
// $.ajax({
|
||||||
|
// url:"next_pass_action", //请求的url地址
|
||||||
|
// dataType:"json", //返回格式为json
|
||||||
|
// async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
|
// data:{"id":id,'type':type}, //参数值
|
||||||
|
// type:"POST", //请求方式
|
||||||
|
// success:function(req){
|
||||||
|
// //请求成功时处理
|
||||||
|
// // console.log(req.msg)
|
||||||
|
// if(req.code == 0){
|
||||||
|
// $('span#id_data').html(req.data.id)
|
||||||
|
// $('span#name').html(req.data.food_name)
|
||||||
|
// $('span.Calorie').html(req.data.Calorie_val)
|
||||||
|
// $('span.Protein').html(req.data.Protein_val)
|
||||||
|
// $('span.Fat').html(req.data.Fat_val)
|
||||||
|
// $('span.Carbohydrate').html(req.data.Carbohydrate_val)
|
||||||
|
// if(req.data.Calorie_val == '/' || req.data.Protein_val == '/' || req.data.Fat_val == '/' || req.data.Carbohydrate_val == '/'){
|
||||||
|
// $('span#name').removeClass()
|
||||||
|
// $('span#name').addClass('red')
|
||||||
|
// }else{
|
||||||
|
// $('span#name').removeClass()
|
||||||
|
// $('span#name').addClass('green')
|
||||||
|
// }
|
||||||
|
// }else{
|
||||||
|
// alert('出错')
|
||||||
|
// // error_num = error_num + 1
|
||||||
|
// // setTimeout(() => {
|
||||||
|
// // error_action(id,code)
|
||||||
|
// // }, 100);
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// error:function(){
|
||||||
|
// //请求出错处理
|
||||||
|
// }});
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
3cbca840689f9b4f691de817908a0a27
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Loading…
Reference in New Issue