SchoolPhysicalExamination/application/KitchenScale/controller/app/Countfood.php

985 lines
47 KiB
PHP
Raw Normal View History

2025-01-22 12:31:08 +08:00
<?php
namespace app\KitchenScale\controller\app;
use think\Db;
2025-04-03 18:19:04 +08:00
class Countfood extends Base{
2025-01-22 12:31:08 +08:00
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
2025-04-03 18:19:04 +08:00
protected $page_num = 10;
2025-03-12 18:03:31 +08:00
protected $reedaw_db_msg = [
'zhanghao'=>'app_account_number',//账号表
'juese'=>'app_user_data',//角色表
];
protected $kitchenscale_db_msg = [
'cookbook'=>'app_user_cookbook',//菜谱表
'uploadimg'=>'app_user_upload_img',//素材表
'followlist'=>'app_user_follow_list',//关注列表
'collect_list'=>'app_user_collect_list',//收藏列表
2025-09-03 19:09:13 +08:00
'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3
2025-09-26 16:35:42 +08:00
'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3
2025-04-03 18:19:04 +08:00
'eat_log'=>'app_user_kcal_log',//食材列表3
'user'=>'app_user_data',//banner
2025-01-22 12:31:08 +08:00
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2025-03-17 03:26:23 +08:00
// 添加每日摄入记录
2025-07-23 21:32:05 +08:00
public function add_intake_food($data=['token'=>'3e5876042361c8cb42bd48c46918f737','aud_id'=>6,'meals_type'=>'早餐','food_list'=>[['id'=>2778,'name'=>"啤酒X",'weight'=>'150','unit'=>'g']]]){
2025-03-12 18:03:31 +08:00
// 尝试捕获异常
2025-07-23 21:32:05 +08:00
try {
2025-01-22 12:31:08 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
}
2025-03-12 18:03:31 +08:00
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
2025-03-17 03:26:23 +08:00
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
2025-04-03 18:19:04 +08:00
if(!array_key_exists('meals_type', $data)){
return $this->msg(10001,'meals_type is miss');
}
2025-03-12 18:03:31 +08:00
if(!array_key_exists('food_list', $data)){
return $this->msg(10001,'food_list is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
2025-01-22 12:31:08 +08:00
}
2025-03-17 03:26:23 +08:00
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type is error');
}
$return_data = $this->add_intake_food_action($data);
return $return_data;
2025-07-23 21:32:05 +08:00
} 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' => '系统错误']);
}
2025-03-17 03:26:23 +08:00
}
// 获取记食器板块内容
2025-11-03 18:18:07 +08:00
public function get_countfoot_content(){
2025-03-17 03:26:23 +08:00
// 尝试捕获异常
2025-09-26 16:35:42 +08:00
// try {
2025-03-17 03:26:23 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
if(!array_key_exists('time', $data)){
return $this->msg(10001,'time is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type is error');
}
if(!$this->verify_data_is_ok($data['time'],'datetime')){
return $this->msg(10005,'time type is error');
}
2025-03-12 18:03:31 +08:00
2025-03-17 03:26:23 +08:00
$return_data = $this->get_countfoot_content_action($data);
return $return_data;
2025-09-26 16:35:42 +08:00
// } 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' => '系统错误']);
// }
2025-03-17 03:26:23 +08:00
}
// 获取记食器记录
2025-04-03 18:19:04 +08:00
public function get_log_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'s_time'=>'2025-03-15','e_time'=>'2025-03-16']){
2025-03-17 03:26:23 +08:00
// 尝试捕获异常
2025-07-23 21:32:05 +08:00
try {
2025-03-17 03:26:23 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
2025-04-03 18:19:04 +08:00
if(!array_key_exists('s_time', $data)){
return $this->msg(10001,'s_time is miss');
}
if(!array_key_exists('e_time', $data)){
return $this->msg(10001,'e_time is miss');
2025-03-17 03:26:23 +08:00
}
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');
}
2025-04-03 18:19:04 +08:00
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
return $this->msg(10005,'s_time type is error');
}
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
return $this->msg(10005,'e_time type is error');
2025-03-17 03:26:23 +08:00
}
2025-03-12 18:03:31 +08:00
2025-03-17 03:26:23 +08:00
$return_data = $this->get_log_list_action($data);
2025-01-22 12:31:08 +08:00
return $return_data;
2025-07-23 21:32:05 +08:00
} 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' => '系统错误']);
}
2025-01-22 12:31:08 +08:00
}
2025-04-03 18:19:04 +08:00
// 计食器板块-设置内容
public function set_up_content($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61]){
// 尝试捕获异常
2025-07-23 21:32:05 +08:00
try {
2025-04-03 18:19:04 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type is error');
}
$return_data = $this->set_up_content_action($data);
return $return_data;
2025-07-23 21:32:05 +08:00
} 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' => '系统错误']);
}
2025-04-03 18:19:04 +08:00
}
// 设置用户的卡路里
public function set_user_kcal($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61,'set_kcal'=>2000]){
// 尝试捕获异常
2025-07-23 21:32:05 +08:00
try {
2025-04-03 18:19:04 +08:00
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
if(!array_key_exists('set_kcal', $data)){
return $this->msg(10001,'set_kcal is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type is error');
}
if(!$this->verify_data_is_ok($data['set_kcal'],'num')){
return $this->msg(10005,'set_kcal type is error');
}
$return_data = $this->set_user_kcal_action($data);
return $return_data;
2025-07-23 21:32:05 +08:00
} 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' => '系统错误']);
}
2025-04-03 18:19:04 +08:00
}
2025-09-03 19:09:13 +08:00
public function del_user_eat_log($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>6,'eat_log_id'=>160]){
// 尝试捕获异常
try {
if(count(input('post.')) > 0){
$data = input('post.');
}
if(!array_key_exists('token', $data)){
return $this->msg(10001,'token is miss');
}
if(!array_key_exists('aud_id', $data)){
return $this->msg(10001,'aud_id is miss');
}
if(!array_key_exists('eat_log_id', $data)){
return $this->msg(10001,'eat_log_id is miss');
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type is error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type is error');
}
if(!$this->verify_data_is_ok($data['eat_log_id'],'num')){
return $this->msg(10005,'eat_log_id type is error');
}
$return_data = $this->del_user_eat_log_action($data);
return $return_data;
} catch (\Exception $e) {
// 捕获异常
$logContent["flie"] = $e->getFile();
$logContent["line"] = $e->getLine();
$logContent['all_content'] = "异常信息:\n";
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
$logContent['all_content'] .= "代码: " . $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' => '系统错误']);
}
}
2025-01-22 12:31:08 +08:00
#######################################################################action#######################################################################
2025-03-12 18:03:31 +08:00
#######################################################################action#######################################################################
#######################################################################action#######################################################################
2025-03-17 03:26:23 +08:00
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
2025-03-12 18:03:31 +08:00
2025-03-17 03:26:23 +08:00
public function add_intake_food_action($data){
2025-07-23 21:32:05 +08:00
2025-03-12 18:03:31 +08:00
$cfc = Db::connect('cfc_db');
2025-04-03 18:19:04 +08:00
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
->find();
if(!$user_data){
return $this->msg(10003);
}
2025-07-23 21:32:05 +08:00
2025-03-17 03:26:23 +08:00
// 统计食物的id
$food_id_arr = [];
2025-04-03 18:19:04 +08:00
2025-03-12 18:03:31 +08:00
foreach ($data['food_list'] as $key => $value) {
2025-04-03 18:19:04 +08:00
if(!array_key_exists('id', $value)){
return $this->msg(10001,'id is miss');
2025-03-17 03:26:23 +08:00
}
if(!array_key_exists('weight', $value)){
return $this->msg(10001,'weight is miss');
2025-03-12 18:03:31 +08:00
}
2025-04-03 18:19:04 +08:00
if(!$this->verify_data_is_ok($value['id'],'intnum')){
return $this->msg(10005,'id type is error');
2025-03-12 18:03:31 +08:00
}
if(!$this->verify_data_is_ok($value['weight'],'num')){
return $this->msg(10005,'weight type is error');
}
2025-04-03 18:19:04 +08:00
foreach ($data['food_list'][$key] as $k => $v) {
// dump($k);
if(!in_array($k,['id','weight','unit'])){
unset($data['food_list'][$key][$k]);
}
}
2025-03-17 03:26:23 +08:00
array_push($food_id_arr,$value['id']);
}
2025-07-23 21:32:05 +08:00
2025-03-17 03:26:23 +08:00
$food_content = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
->where("id in (".implode(',',$food_id_arr).")")
2025-09-03 19:09:13 +08:00
->field('id,food_name as name,Calorie_val as kcal,Carbohydrate_val as carbohydrate,Protein_val as protein,Fat_val as fat')
2025-03-17 03:26:23 +08:00
->select();
2025-04-03 18:19:04 +08:00
2025-03-17 03:26:23 +08:00
// 整理食物信息
$food_content_arr = [];
foreach ($food_content as $key => $value) {
$food_content_arr[$value['id']] = $value;
}
$create_time = date('Y-m-d H:i:s');
foreach ($data['food_list'] as $key => $value) {
//获取每100g食物的比例
$proportion_num = bcdiv($value['weight'],100,2);
if(array_key_exists($value['id'], $food_content_arr)){
$data['food_list'][$key]['kcal_val'] = bcmul($food_content_arr[$value['id']]['kcal'],$proportion_num,2);
$data['food_list'][$key]['carbohydrate_val'] = bcmul($food_content_arr[$value['id']]['carbohydrate'],$proportion_num,2);
$data['food_list'][$key]['protein_val'] = bcmul($food_content_arr[$value['id']]['protein'],$proportion_num,2);
$data['food_list'][$key]['fat_val'] = bcmul($food_content_arr[$value['id']]['fat'],$proportion_num,2);
2025-04-03 18:19:04 +08:00
$data['food_list'][$key]['food_name'] = $food_content_arr[$value['id']]['name'];
2025-03-17 03:26:23 +08:00
$data['food_list'][$key]['aud_id'] = $data['aud_id'];
$data['food_list'][$key]['meals_type'] = $data['meals_type'];
$data['food_list'][$key]['create_time'] = $create_time;
2025-04-03 18:19:04 +08:00
$data['food_list'][$key]['food_id'] = $value['id'];
unset($data['food_list'][$key]['id']);
2025-03-17 03:26:23 +08:00
}else{
unset($data['food_list'][$key]);
2025-03-12 18:03:31 +08:00
}
}
2025-04-03 18:19:04 +08:00
// dump($data['food_list']);
// die;
2025-03-17 03:26:23 +08:00
// 数据库数据字段id,aud_id,meals_type,food_id,food_name,weight,kcal_val,carbohydrate_val,protein_val,fat_val,create_time
// 启动事务
2025-07-23 21:32:05 +08:00
2025-03-17 03:26:23 +08:00
Db::startTrans();
try{
2025-04-03 18:19:04 +08:00
$result = $cfc->table($this->kitchenscale_db_msg['eat_log'])->insertAll($data['food_list']);
if ($result !== count($data['food_list'])) {
2025-03-17 03:26:23 +08:00
Db::rollback();
2025-07-23 21:32:05 +08:00
return $this->msg(10002,'添加数据错误');
2025-03-17 03:26:23 +08:00
} else {
Db::commit();
return $this->msg([]);
}
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
return $this->msg(10002);
}
2025-07-23 21:32:05 +08:00
// dump($data);
// dump($food_id_arr);
// dump($food_content);
// die;
2025-03-17 03:26:23 +08:00
}
public function get_countfoot_content_action($data){
$cfc = Db::connect('cfc_db');
2025-04-03 18:19:04 +08:00
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
2025-11-03 18:18:07 +08:00
->field('weight,height,gender,age,birthday,is_use_set_kcal,set_kcal')
2025-03-17 03:26:23 +08:00
->find();
if(!$user_data){
return $this->msg(10003);
}
2025-11-03 18:18:07 +08:00
if($user_data['birthday']){
$user_data['age_num'] = $this->calculate_age($user_data['birthday']);
}else{
$user_data['age_num'] = $user_data['age'];
}
2025-03-17 03:26:23 +08:00
$nutrition_data = $this->count_user_nutrition_all($user_data);
2025-04-03 18:19:04 +08:00
if($user_data['is_use_set_kcal'] == 1){
2025-09-03 19:09:13 +08:00
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
$proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
2025-04-03 18:19:04 +08:00
$nutrition_data['kcal'] = $user_data['set_kcal'];
2025-09-03 19:09:13 +08:00
$nutrition_data['carbohydrate'] = bcmul($nutrition_data['carbohydrate'],$proportion,2);
$nutrition_data['protein'] = bcmul($nutrition_data['protein'],$proportion,2);
$nutrition_data['fat'] = bcmul($nutrition_data['fat'],$proportion,2);
2025-04-03 18:19:04 +08:00
}
2025-03-17 03:26:23 +08:00
// 查询用户今日摄入食物
$food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
2025-09-03 19:09:13 +08:00
->alias('a')
->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
->where("a.is_del = 0 AND a.aud_id = " . $data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)")
2025-09-26 16:35:42 +08:00
->field('a.meals_type,a.food_name,a.weight,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id')
2025-03-17 03:26:23 +08:00
->select();
2025-09-26 16:35:42 +08:00
if(count($food_content) > 0){
$food_content = $this->calculate_nutrients($food_content);
}
2025-03-17 03:26:23 +08:00
$date = date('Y-m-d H:i:s');
$return_data = [
'suggestion'=>[
2025-04-03 18:19:04 +08:00
'kcal'=>$nutrition_data['kcal'],
'carbohydrate'=>$nutrition_data['carbohydrate'],
'protein'=>$nutrition_data['protein'],
'fat'=>$nutrition_data['fat'],
2025-03-17 03:26:23 +08:00
],
'today_intake'=>[
'kcal'=>0,
'carbohydrate'=>0,
'protein'=>0,
'fat'=>0,
],
2025-04-03 18:19:04 +08:00
'remaining_kcal'=>$nutrition_data['kcal'],//剩下可摄入卡路里
2025-03-17 03:26:23 +08:00
'list'=>[
[
'name'=>'早餐',
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
[
'name'=>'午餐',
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
[
'name'=>'晚餐',
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
[
2025-04-03 18:19:04 +08:00
'name'=>'早加餐',
2025-03-17 03:26:23 +08:00
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
[
2025-04-03 18:19:04 +08:00
'name'=>'午加餐',
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
[
'name'=>'晚加餐',
2025-03-17 03:26:23 +08:00
'val'=>0,
'unit'=>'kcal',
'list'=>[],
],
],
'date'=>date('Y-m-d'),
];
if(count($food_content) <= 0){
2025-04-03 18:19:04 +08:00
$return_data['list'] = [];
2025-03-17 03:26:23 +08:00
return $this->msg($return_data);
}
foreach ($food_content as $key => $value) {
2025-04-03 18:19:04 +08:00
$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);
2025-03-17 03:26:23 +08:00
if($value['meals_type'] == '早餐'){
2025-04-03 18:19:04 +08:00
$return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][0]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-03-17 03:26:23 +08:00
}else if($value['meals_type'] == '午餐'){
2025-04-03 18:19:04 +08:00
$return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][1]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-03-17 03:26:23 +08:00
}else if($value['meals_type'] == '晚餐'){
2025-04-03 18:19:04 +08:00
$return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][2]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-04-03 18:19:04 +08:00
}else if($value['meals_type'] == '早加餐'){
$return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][3]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-04-03 18:19:04 +08:00
}else if($value['meals_type'] == '午加餐'){
$return_data['list'][4]['val'] = bcadd($return_data['list'][4]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][4]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-04-03 18:19:04 +08:00
}else if($value['meals_type'] == '晚加餐'){
$return_data['list'][5]['val'] = bcadd($return_data['list'][5]['val'],$value['kcal_val'],2);
2025-09-03 19:09:13 +08:00
array_push($return_data['list'][5]['list'],[
'name'=>$value['food_name'],
'weight'=>$value['weight'].'克',
'id'=>$value['id'],
'pic_url'=>$value['pic_url'],
2025-09-26 16:35:42 +08:00
// 'val'=>$value['kcal_val'].'kcal',
'val'=>$value['kcal_val'],
'nutrients_four' => $value['nutrients_four'],
'nutrients_list' => $value['nutrients_list']
2025-09-03 19:09:13 +08:00
]);
2025-04-03 18:19:04 +08:00
}else{
}
}
foreach ($return_data['list'] as $key => $value) {
if(count($value['list']) <= 0){
unset($return_data['list'][$key]);
2025-03-17 03:26:23 +08:00
}
}
2025-04-03 18:19:04 +08:00
$return_data['list'] = array_values($return_data['list']);
$return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
2025-09-26 16:35:42 +08:00
2025-03-17 03:26:23 +08:00
return $this->msg($return_data);
2025-04-03 18:19:04 +08:00
}
2025-03-17 03:26:23 +08:00
public function get_log_list_action($data){
$cfc = Db::connect('cfc_db');
2025-04-03 18:19:04 +08:00
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
2025-03-17 03:26:23 +08:00
->find();
if(!$user_data){
return $this->msg(10003);
}
2025-04-03 18:19:04 +08:00
// dump($user_data);
2025-03-17 03:26:23 +08:00
// 计算年龄
2025-04-03 18:19:04 +08:00
$user_data['age_num'] = $user_data['age'];
2025-03-17 03:26:23 +08:00
// 计算推荐营养
$nutrition_data = $this->count_user_nutrition_all($user_data);
2025-04-03 18:19:04 +08:00
if($user_data['is_use_set_kcal'] == 1){
$nutrition_data['kcal'] = $user_data['set_kcal'];
}
2025-03-17 03:26:23 +08:00
// 计算取值范围
2025-04-03 18:19:04 +08:00
// $time_arr = $this->calculateDateRange($data['page']);
// $content_num = $cfc->query("SELECT COUNT(DISTINCT CONVERT(varchar, create_time, 23)) as total
// FROM ".$this->kitchenscale_db_msg['eat_log']."
// WHERE aud_id = ".$data['aud_id']."");
// $page_total = ceil($content_num[0]['total']/$this->page_num);
2025-03-17 03:26:23 +08:00
$food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
2025-04-03 18:19:04 +08:00
->field("CONVERT(varchar, create_time, 23) as create_time, SUM(kcal_val) as kcal_val")
->where(['aud_id'=>$data['aud_id'],'create_time'=>['>=',$data['s_time'].' 00:00:00'],'create_time'=>['<=',$data['e_time'].' 23:59:59']])
->group('CONVERT(varchar, create_time, 23)')
// ->page($data['page'],$this->page_num)
->order('create_time DESC')
2025-03-17 03:26:23 +08:00
->select();
2025-04-03 18:19:04 +08:00
// dump($food_content);
// die;
2025-03-17 03:26:23 +08:00
$user_log = [];
foreach ($food_content as $key => $value) {
2025-04-03 18:19:04 +08:00
$time_data = substr($value['create_time'], 0, 10);
if(array_key_exists($time_data, $user_log)){
$user_log[$time_data] += $value['kcal_val'];
2025-03-17 03:26:23 +08:00
}else{
2025-04-03 18:19:04 +08:00
$user_log[$time_data] = $value['kcal_val'];
2025-03-12 18:03:31 +08:00
}
2025-01-22 12:31:08 +08:00
}
2025-03-17 03:26:23 +08:00
$return_data = [];
2025-04-03 18:19:04 +08:00
foreach ($user_log as $key => $value) {
2025-03-17 03:26:23 +08:00
if(bcdiv($value,$nutrition_data['kcal'],2) < 0.9){
$bz['text'] = '不达标';
2025-04-03 18:19:04 +08:00
$bz['color'] = '#F0AD4E';
2025-03-17 03:26:23 +08:00
}else if(bcdiv($value,$nutrition_data['kcal'],2) >= 0.9 && bcdiv($value,$nutrition_data['kcal'],2) < 1.1){
$bz['text'] = '达标';
2025-04-03 18:19:04 +08:00
$bz['color'] = '#4CD964';
2025-03-17 03:26:23 +08:00
}else{
$bz['text'] = '超标';
2025-04-03 18:19:04 +08:00
$bz['color'] = '#FF0000';
2025-03-17 03:26:23 +08:00
}
2025-11-04 05:38:15 +08:00
array_push($return_data,['time'=>$key,'title'=>'摄入卡路里','val'=>$value,'unit'=>'kcal','describe'=>$bz['text'],'color'=>$bz['color']]);
2025-03-17 03:26:23 +08:00
}
2025-04-03 18:19:04 +08:00
// dump($return_data);
return $this->msg([
2025-11-04 05:38:15 +08:00
'page_now'=>$data['page'],
'page_total'=>$page_total,
2025-04-03 18:19:04 +08:00
'content_list'=>$return_data
]);
}
public function set_up_content_action($data){
$cfc = Db::connect('cfc_db');
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
->find();
if(!$user_data){
return $this->msg(10003);
}
// 计算年龄
$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'];
}
$nutrition_describe = [
[
'对于一个孩子2-18岁没有特殊健康问题身体处于快速生长发育阶段需要充足的营养支持尤其是蛋白质和健康脂肪。通常建议的三大营养素比例为',
'1、碳水化合物45%-65% 的总热量',
'提供能量,支持孩子的日常活动和生长发育。',
'优先选择复合碳水化合物(如全谷物、蔬菜、水果),避免精制糖和高糖零食。',
'2、蛋白质10%-30% 的总热量',
'支持肌肉、骨骼和器官的发育。',
'建议摄入优质蛋白质来源,如瘦肉、鱼类、鸡蛋、豆类和乳制品。',
'蛋白质需求较高,尤其是青春期孩子。',
'3、脂肪25%-35% 的总热量',
'提供能量并支持大脑发育尤其是Omega-3脂肪酸。',
'优先选择健康脂肪,如鱼类、坚果、种子、橄榄油和牛油果。',
'避免反式脂肪和过多的饱和脂肪。',
'注意事项',
'如果你有特定的健康目标(如增高,减重),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
],
[
'对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:',
'1、碳水化合物45%-65% 的总热量',
'主要功能是提供能量',
'建议选择复合碳水化合物(如全谷物、蔬菜、豆类),而不是精制糖。',
'对于普通人,碳水化合物占总热量的 50%-55% 是一个常见的推荐值。',
'2、蛋白质10%-35% 的总热量',
'用于维持肌肉、修复组织和支持免疫功能。',
'普通人每日蛋白质摄入量建议为 0.8-1.2克/公斤体重。',
'对于活动量较大或健身人群,蛋白质比例可以提高到 20%-30%。',
'3、脂肪20%-35% 的总热量',
'提供能量、支持细胞功能并帮助吸收脂溶性维生素。',
'建议以 不饱和脂肪(如橄榄油、坚果、鱼类)为主,减少饱和脂肪和反式脂肪的摄入。',
'脂肪占总热量的 20%-30% 是常见的推荐值。',
'以上是根据世界卫生组织WHO和其他健康机构的建议制定的。具体比例可以根据个人的活动水平、健康状况和目标进行微调。',
'注意事项',
'活动水平:活动量大的人可能需要更多的碳水化合物来提供能量,而健身人群可能需要更多的蛋白质。',
'健康状况:例如,糖尿病患者可能需要控制碳水化合物比例,而心血管疾病患者可能需要减少脂肪摄入。',
'个体差异:每个人的代谢和需求不同,建议根据个人情况调整。',
'如果你有特定的健康目标(如减脂、增肌或控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
],
[
'对于一个老人65岁以上没有特殊健康问题身体的代谢率下降肌肉量减少可能面临营养不良或慢性病风险因此需要调整营养比例。通常建议的三大营养素比例为',
'1、碳水化合物45%-65% 的总热量',
'提供能量但应选择低血糖指数GI的食物如全谷物、蔬菜和豆类以控制血糖水平。',
'避免精制糖和高糖食物,尤其是糖尿病患者。',
'帮助维持肌肉质量,预防肌肉流失(少肌症)。',
'建议摄入优质蛋白质,如鱼类、瘦肉、鸡蛋、豆类和乳制品。',
'蛋白质需求较高,尤其是活动量较大的老人。',
'3、脂肪20%-35% 的总热量',
'提供能量,并支持细胞功能和脂溶性维生素的吸收。',
'优先选择不饱和脂肪,如橄榄油、坚果、种子和鱼类。',
'减少饱和脂肪和反式脂肪的摄入,以降低心血管疾病风险。',
'注意事项',
'如果你有特定的健康目标(控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
]
];
$return_data = [
'kcal'=>[
'title'=>"建议摄入卡路里",
'suggestion_kcal_val'=>$nutrition_data['kcal'],
'suggestion_kcal_unit'=>"千卡",
'suggestion_kcal_range_val'=>"建议您在:".bcmul($nutrition_data['bmr'],1.2,2)."~".bcmul($nutrition_data['bmr'],1.9,2)."千卡范围内调整,修改时请以医生建议为准!",
'describe'=>[
'基础代谢率(BMR):是指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率。',
'每日总能量消耗TDEE',
'TDEE是BMR乘以活动系数活动系数根据日常活动水平确定',
'久坐很少或没有运动BMR × 1.2',
'轻度活动每周1-3天轻度运动BMR × 1.375',
'中度活动每周3-5天中度运动BMR × 1.55',
'高度活动每周6-7天高强度运动BMR × 1.725',
'极高活动体力劳动或每天高强度训练BMR × 1.9',
'您的BMR为'.$nutrition_data['bmr'].',建议根据您的日常生活水平调整合适的TDEE',
],
],
'nutrition'=>[
'title'=>"建议三大营养比例",
'list'=>[
[
'name'=>'碳水化合物',
'icon'=>'icon-tanshuihuahewu',
'proportion'=>'50%',
'val'=>$nutrition_data['carbohydrate'],
'unit'=>'克'
],
[
'name'=>'蛋白质',
'icon'=>'icon-Sm-danbaizhi',
'proportion'=>'20%',
'val'=>$nutrition_data['protein'],
'unit'=>'克'
],
[
'name'=>'脂肪',
'icon'=>'icon-w_fat_normal',
'proportion'=>'30%',
'val'=>$nutrition_data['fat'],
'unit'=>'克'
]
],
'describe'=>[]
]
];
if($user_data['age_num'] >= 2 && $user_data['age_num'] <= 18){
$return_data['nutrition']['describe'] = $nutrition_describe[0];
}else if($user_data['age_num'] > 18 && $user_data['age_num'] < 65){
$return_data['nutrition']['describe'] = $nutrition_describe[1];
}else if($user_data['age_num'] >= 65){
$return_data['nutrition']['describe'] = $nutrition_describe[2];
}else{
}
2025-03-17 03:26:23 +08:00
return $this->msg($return_data);
2025-04-03 18:19:04 +08:00
}
public function set_user_kcal_action($data){
$cfc = Db::connect('cfc_db');
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
->field('weight,height,gender,age,is_use_set_kcal,set_kcal')
->find();
if(!$user_data){
return $this->msg(10003);
}
$result = $cfc->table($this->kitchenscale_db_msg['user'])
->where(["id"=>$data['aud_id']])
->update([
'is_use_set_kcal'=>1,
'set_kcal'=>$data['set_kcal']
]);
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
2025-03-17 03:26:23 +08:00
}
2025-09-03 19:09:13 +08:00
public function del_user_eat_log_action($data){
$cfc = Db::connect('cfc_db');
$user_data = $cfc->table($this->kitchenscale_db_msg['eat_log'])
->where(["id"=>$data['eat_log_id']])
->update(['is_del'=>1]);
if($user_data){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
2025-03-17 03:26:23 +08:00
#######################################################################工具#######################################################################
#######################################################################工具#######################################################################
#######################################################################工具#######################################################################
2025-11-03 18:18:07 +08:00
// 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,'性别未知');
// }
2025-03-17 03:26:23 +08:00
2025-11-03 18:18:07 +08:00
// // 每日总能量消耗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);
2025-03-17 03:26:23 +08:00
2025-11-03 18:18:07 +08:00
// // 碳水化合物通常占总热量的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];
// }
2025-03-17 03:26:23 +08:00
public function calculateDateRange($n) {
// 获取当前日期和时间
2025-04-03 18:19:04 +08:00
$today = new \DateTime();
2025-03-17 03:26:23 +08:00
// 计算结束时间:往前推 (10 * (n - 1)) 天,时间设为 23:59:59
2025-04-03 18:19:04 +08:00
$endInterval = new \DateInterval('P' . (10 * ($n - 1)) . 'D');
2025-03-17 03:26:23 +08:00
$endTime = clone $today;
$endTime->sub($endInterval)->setTime(23, 59, 59);
2025-03-12 18:03:31 +08:00
2025-03-17 03:26:23 +08:00
// 计算开始时间:往前推 (10 * n) 天,时间设为 00:00:00
2025-04-03 18:19:04 +08:00
$startInterval = new \DateInterval('P' . (10 * $n) . 'D');
2025-03-17 03:26:23 +08:00
$startTime = clone $today;
$startTime->sub($startInterval)->setTime(0, 0, 0);
2025-03-12 18:03:31 +08:00
2025-03-17 03:26:23 +08:00
return [
's_time' => $startTime->format('Y-m-d H:i:s'),
'e_time' => $endTime->format('Y-m-d H:i:s'),
];
2025-01-22 12:31:08 +08:00
}
2025-09-26 16:35:42 +08:00
// 计算营养物质
public function calculate_nutrients($data){
// dump($data);
$food_id_arr = [];
for ($i=0; $i < count($data); $i++) {
$food_id_arr[] = $data[$i]['food_id'];
}
$cfc = Db::connect('cfc_db');
$nutrients_list = $cfc->table($this->kitchenscale_db_msg['foodlist4'])
->where("father_id in ('".implode("','",$food_id_arr)."')")
// ->field()
->select();
$nutrients_arr = ['VitaminA','VitaminB1','VitaminB2','VitaminB6','VitaminB12','VitaminD','VitaminK','Niacin','VitaminC','VitaminE','FolicAcid','Biotin','PantothenicAcid','TotalCholine','Ca','Phosphorus','Kalium','Mg','Na','Fe','Zn','Se','Cu','Mn','Iodine'];
// dump($nutrients_list);
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
for ($i=0; $i < count($data); $i++) {
$data[$i]['nutrients_four'][] = [
'name' => '卡路里',
'unit' => 'kcal',
'color' => '',
'value' => $data[$i]['kcal_val'],
'proportion' => 0,
];
$data[$i]['nutrients_four'][] = [
'name' => '蛋白质',
'unit' => 'g',
'color' => '#5180D8',
'value' => $data[$i]['protein_val'],
'proportion' => bcmul(bcdiv($data[$i]['protein_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
];
$data[$i]['nutrients_four'][] = [
'name' => '脂肪',
'unit' => 'g',
'color' => '#ED7886',
'value' => $data[$i]['fat_val'],
'proportion' => bcmul(bcdiv($data[$i]['fat_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
];
$data[$i]['nutrients_four'][] = [
'name' => '碳水化合物',
'unit' => 'g',
'color' => '#FFB169',
'value' => $data[$i]['carbohydrate_val'],
'proportion' => bcmul(bcdiv($data[$i]['carbohydrate_val'],bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20),2),100,0),
];
$data[$i]['nutrients_list'][] = [
'name' => 'Calorie',
'name_ch' => '卡路里',
'unit' => 'kcal',
'value' => $data[$i]['kcal_val'],
'type' => 1,
'type_name' => '能量及宏量营养素',
'color' => '#C4FFE0',
];
$data[$i]['nutrients_list'][] = [
'name' => 'Protein',
'name_ch' => '蛋白质',
'unit' => 'g',
'value' => $data[$i]['protein_val'],
'type' => 1,
'type_name' => '能量及宏量营养素',
'color' => '#C4FFE0',
];
$data[$i]['nutrients_list'][] = [
'name' => 'Fat',
'name_ch' => '脂肪',
'unit' => 'g',
'value' => $data[$i]['fat_val'],
'type' => 1,
'type_name' => '能量及宏量营养素',
'color' => '#C4FFE0',
];
$data[$i]['nutrients_list'][] = [
'name' => 'Carbohydrate',
'name_ch' => '碳水化合物',
'unit' => 'g',
'value' => $data[$i]['carbohydrate_val'],
'type' => 1,
'type_name' => '能量及宏量营养素',
'color' => '#C4FFE0',
];
foreach ($nutrients_list as $key => $value) {
if($value['father_id'] == $data[$i]['food_id']){
if(in_array($value['name'],$nutrients_arr)){
$data[$i]['nutrients_list'][] = [
'name' => $value['name'],
'name_ch' => $value['name_ch'],
'unit' => $value['unit'],
'value' => bcmul($value['value'],bcdiv($data[$i]['weight'],100,20),2),
'type' => $value['type'],
'type_name' => $value['type'] == 1?'能量及宏量营养素':($value['type'] == 2?'维生素':($value['type'] == 3?'矿物质':'')),
'color' => $value['type'] == 1?'#C4FFE0':($value['type'] == 2?'#FFEFB7':($value['type'] == 3?'#7DA8E0':'')),
];
}
}
}
}
return $data;
}
2025-01-22 12:31:08 +08:00
2025-09-03 19:09:13 +08:00
2025-01-22 12:31:08 +08:00
}