251128提交
|
|
@ -115,6 +115,40 @@ class Base extends Controller{
|
|||
################################################################通用工具################################################################
|
||||
################################################################通用工具################################################################
|
||||
################################################################通用工具################################################################
|
||||
|
||||
// 验证验证码是否有效
|
||||
public function check_code($data = 18530934717 , $code = 123456){
|
||||
// // 默认验证码正确
|
||||
|
||||
if(cache($data) == false){
|
||||
return '验证码过期';
|
||||
}else{
|
||||
if($code != cache($data)){
|
||||
return '验证码错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 判断字符串是手机还是邮箱
|
||||
public function is_tel_email($str) {
|
||||
// 手机号码的正则表达式(中国大陆格式)(下面正则实际判断的是是否为11位数字)
|
||||
$mobilePattern = '/^\d{11}$/';
|
||||
// 电子邮件地址的正则表达式
|
||||
$emailPattern = '/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/';
|
||||
// 判断是否为手机号码
|
||||
if (preg_match($mobilePattern, $str)) {
|
||||
return 'tel';
|
||||
}
|
||||
// 判断是否为电子邮件地址
|
||||
if (preg_match($emailPattern, $str)) {
|
||||
return 'email';
|
||||
}
|
||||
// 如果都不是,返回其他
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 判断token是否过期
|
||||
public function token_time_validate($token){
|
||||
// 591b70e0d80b5fa6d77e6e1384453ab9
|
||||
|
|
@ -250,7 +284,16 @@ class Base extends Controller{
|
|||
// 中度活动(每周3-5天中度运动):BMR × 1.55
|
||||
// 高度活动(每周6-7天高强度运动):BMR × 1.725
|
||||
// 极高活动(体力劳动或每天高强度训练):BMR × 1.9
|
||||
if(array_key_exists('activity_level',$data)){
|
||||
if($data['activity_level'] != null){
|
||||
$tdee = bcmul($bmr,$data['activity_level'],2);
|
||||
}else{
|
||||
$tdee = bcmul($bmr,1.55,2);
|
||||
}
|
||||
}else{
|
||||
$tdee = bcmul($bmr,1.55,2);
|
||||
}
|
||||
|
||||
|
||||
// 碳水化合物:通常占总热量的45-65%
|
||||
// 蛋白质:通常占总热量的10-35%
|
||||
|
|
@ -261,15 +304,73 @@ class Base extends Controller{
|
|||
// 1.碳水化合物(克): (TDEE × 碳水化合物比例) / 4
|
||||
// 2.蛋白质(克):(TDEE × 蛋白质比例) / 4
|
||||
// 3.脂肪(克): (TDEE × 脂肪比例) / 9
|
||||
|
||||
$carbohydrate_p = 0.5;
|
||||
$carbohydrate = bcdiv(bcmul($tdee,0.5,20),4,2);
|
||||
if($data['age_num'] < 65){
|
||||
$protein_p = 0.2;
|
||||
$fat_p = 0.3;
|
||||
$protein = bcdiv(bcmul($tdee,0.2,20),4,2);
|
||||
$fat = bcdiv(bcmul($tdee,0.3,20),9,2);
|
||||
}else{
|
||||
$protein_p = 0.25;
|
||||
$fat_p = 0.25;
|
||||
$protein = bcdiv(bcmul($tdee,0.25,20),4,2);
|
||||
$fat =bcdiv(bcmul($tdee,0.25,20),9,2);
|
||||
}
|
||||
return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr];
|
||||
return ['kcal'=>$tdee,'carbohydrate'=>$carbohydrate,'protein'=>$protein,'fat'=>$fat,'bmr'=>$bmr,'carbohydrate_p'=>$carbohydrate_p,'protein_p'=>$protein_p,'fat_p'=>$fat_p];
|
||||
}
|
||||
/**
|
||||
* 将重量转换为克(g)
|
||||
* @param string $weight 重量值
|
||||
* @param string $unit 单位 (g, oz, lb, lb:oz)
|
||||
* @return float 转换后的克重
|
||||
*/
|
||||
function convertWeightToGrams($weight, $unit) {
|
||||
// 定义精确的转换常量
|
||||
$G_PER_OZ = '28.349523125';
|
||||
$G_PER_LB = '453.59237';
|
||||
|
||||
$unit = strtolower($unit);
|
||||
$result = 0;
|
||||
|
||||
switch ($unit) {
|
||||
// case 'g':
|
||||
case '克':
|
||||
// 已经是克,直接返回
|
||||
$result = $weight;
|
||||
break;
|
||||
|
||||
// case 'oz':
|
||||
case '盎司':
|
||||
// 盎司转克
|
||||
$result = bcmul($weight,$G_PER_OZ,2);
|
||||
break;
|
||||
|
||||
// case 'lb':
|
||||
case '磅':
|
||||
// 磅转克
|
||||
$result = bcmul($weight,$G_PER_LB,2);
|
||||
break;
|
||||
|
||||
// case 'lb:oz':
|
||||
case '磅:盎司':
|
||||
// 磅:盎司复合单位处理
|
||||
if (strpos($weight, ':') !== false) {
|
||||
$temporary_data = explode(':', $weight);
|
||||
$result = bcadd(bcmul($temporary_data[0],$G_PER_LB,20),bcmul($temporary_data[1],$G_PER_OZ,20),2);
|
||||
} else {
|
||||
// 如果格式不正确,可以抛出异常或返回0
|
||||
$result = '0';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$result = '0';
|
||||
}
|
||||
|
||||
// 保留两位小数并返回
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 计算营养物质
|
||||
|
|
@ -293,6 +394,7 @@ class Base extends Controller{
|
|||
// 乘 bcmul(,,20)
|
||||
// 除 bcdiv(,,20)
|
||||
for ($i=0; $i < count($data); $i++) {
|
||||
$zong_all = bcadd($data[$i]['protein_val'],bcadd($data[$i]['fat_val'],$data[$i]['carbohydrate_val'],20),20);
|
||||
$data[$i]['nutrients_four'][] = [
|
||||
'name' => '卡路里',
|
||||
'unit' => 'kcal',
|
||||
|
|
@ -305,21 +407,21 @@ class Base extends Controller{
|
|||
'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),
|
||||
'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['protein_val'],$zong_all,2),100,0),
|
||||
];
|
||||
$data[$i]['nutrients_four'][] = [
|
||||
'name' => '脂肪',
|
||||
'unit' => 'g',
|
||||
'color' => '#ED7886',
|
||||
'value' => $data[$i]['fat_val'],
|
||||
'proportion' => 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),
|
||||
'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['fat_val'],$zong_all,2),100,0),
|
||||
];
|
||||
$data[$i]['nutrients_four'][] = [
|
||||
'name' => '碳水化合物',
|
||||
'unit' => 'g',
|
||||
'color' => '#FFB169',
|
||||
'value' => $data[$i]['carbohydrate_val'],
|
||||
'proportion' => 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),
|
||||
'proportion' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['carbohydrate_val'],$zong_all,2),100,0),
|
||||
];
|
||||
$data[$i]['nutrients_list'][] = [
|
||||
'name' => 'Calorie',
|
||||
|
|
|
|||
|
|
@ -600,6 +600,7 @@ class Cookbook extends Base{
|
|||
'step_data'=>json_encode($data['step_list']),
|
||||
// 'food_type'=>implode(',', $food_type),
|
||||
'cook_label'=>$data['cook_label'],
|
||||
'is_del'=>1,
|
||||
'create_time'=>date('Y-m-d H:i:s')
|
||||
];
|
||||
// dump($insert_data);
|
||||
|
|
|
|||
|
|
@ -48,12 +48,18 @@ class Countfood extends Base{
|
|||
if(!array_key_exists('food_list', $data)){
|
||||
return $this->msg(10001,'food_list is miss');
|
||||
}
|
||||
if(!array_key_exists('time', $data)){
|
||||
return $this->msg(10001,'food_list is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
|
||||
return $this->msg(10005,'aud_id type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['time'],'datetime')){
|
||||
return $this->msg(10005,'time type is error');
|
||||
}
|
||||
$return_data = $this->add_intake_food_action($data);
|
||||
return $return_data;
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -194,49 +200,7 @@ class Countfood extends Base{
|
|||
return json(['status' => 'error', 'message' => '系统错误']);
|
||||
}
|
||||
}
|
||||
// 设置用户的卡路里
|
||||
public function set_user_kcal($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61,'set_kcal'=>2000]){
|
||||
// 尝试捕获异常
|
||||
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('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;
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
// 记录日志
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return json(['status' => 'error', 'message' => '系统错误']);
|
||||
}
|
||||
}
|
||||
public function del_user_eat_log($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>6,'eat_log_id'=>160]){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
|
|
@ -334,7 +298,9 @@ class Countfood extends Base{
|
|||
if(!$user_data){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
|
||||
if(count($data['food_list']) <= 0){
|
||||
return $this->msg(10001,'未选择食材');
|
||||
}
|
||||
// 统计食物的id
|
||||
$food_id_arr = [];
|
||||
|
||||
|
|
@ -351,21 +317,22 @@ class Countfood extends Base{
|
|||
if(!$this->verify_data_is_ok($value['id'],'intnum')){
|
||||
return $this->msg(10005,'id type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($value['weight'],'num')){
|
||||
return $this->msg(10005,'weight type is error');
|
||||
}
|
||||
// if(!$this->verify_data_is_ok($value['weight'],'num')){
|
||||
// return $this->msg(10005,'weight type is error');
|
||||
// }
|
||||
if(!in_array($value['meals_type'],['早餐','午餐','晚餐','加餐'])){
|
||||
return $this->msg(10005,'meals_type type is error');
|
||||
}
|
||||
|
||||
foreach ($data['food_list'][$key] as $k => $v) {
|
||||
if(!in_array($k,['id','weight','meals_type'])){
|
||||
if(!in_array($k,['id','weight','meals_type','unit'])){
|
||||
unset($data['food_list'][$key][$k]);
|
||||
}
|
||||
}
|
||||
array_push($food_id_arr,$value['id']);
|
||||
$data['food_list'][$key]['weight_g'] = $this->convertWeightToGrams($value['weight'],$value['unit']);
|
||||
}
|
||||
|
||||
// return $this->msg($data);
|
||||
$food_content = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
|
||||
->where("id in (".implode(',',$food_id_arr).")")
|
||||
->field('id,food_name as name,Calorie_val as kcal,Carbohydrate_val as carbohydrate,Protein_val as protein,Fat_val as fat')
|
||||
|
|
@ -375,15 +342,17 @@ class Countfood extends Base{
|
|||
return $this->msg(10004,'未找到对应食材');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 整理食物信息
|
||||
$food_content_arr = [];
|
||||
foreach ($food_content as $key => $value) {
|
||||
$food_content_arr[$value['id']] = $value;
|
||||
}
|
||||
$create_time = date('Y-m-d H:i:s');
|
||||
// $create_time = date('Y-m-d H:i:s');
|
||||
foreach ($data['food_list'] as $key => $value) {
|
||||
//获取每100g食物的比例
|
||||
$proportion_num = bcdiv($value['weight'],100,2);
|
||||
$proportion_num = bcdiv($value['weight_g'],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);
|
||||
|
|
@ -392,22 +361,25 @@ class Countfood extends Base{
|
|||
$data['food_list'][$key]['food_name'] = $food_content_arr[$value['id']]['name'];
|
||||
$data['food_list'][$key]['aud_id'] = $data['aud_id'];
|
||||
$data['food_list'][$key]['meals_type'] = $value['meals_type'];
|
||||
$data['food_list'][$key]['create_time'] = $create_time;
|
||||
$data['food_list'][$key]['create_time'] = $data['time'].date(' H:i:s');
|
||||
$data['food_list'][$key]['food_id'] = $value['id'];
|
||||
unset($data['food_list'][$key]['id']);
|
||||
unset($data['food_list'][$key]['weight_g']);
|
||||
|
||||
}else{
|
||||
unset($data['food_list'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// dump($data['food_list']);
|
||||
// die;
|
||||
// 数据库数据字段:id,aud_id,meals_type,food_id,food_name,weight,kcal_val,carbohydrate_val,protein_val,fat_val,create_time
|
||||
// 启动事务
|
||||
|
||||
// return $this->msg($data['food_list']);
|
||||
Db::startTrans();
|
||||
try{
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['eat_log'])->insertAll($data['food_list']);
|
||||
if(count($data['food_list']) > 1){
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['eat_log'])->insertAll($data['food_list']);//新增所有
|
||||
if ($result !== count($data['food_list'])) {
|
||||
Db::rollback();
|
||||
return $this->msg(10002,'添加数据错误');
|
||||
|
|
@ -415,6 +387,12 @@ class Countfood extends Base{
|
|||
Db::commit();
|
||||
return $this->msg([]);
|
||||
}
|
||||
}else{
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['eat_log'])->insertGetId($data['food_list'][0]);//新增1个
|
||||
Db::commit();
|
||||
return $this->msg(['id'=>$result]);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
|
|
@ -431,7 +409,8 @@ class Countfood extends Base{
|
|||
|
||||
$user_data = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->where(["id"=>$data['aud_id']])
|
||||
->field('weight,height,gender,age,birthday,is_use_set_kcal,set_kcal')
|
||||
// ->field('weight,height,gender,age,birthday,is_use_set_kcal,set_kcal')
|
||||
->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);
|
||||
|
|
@ -443,12 +422,24 @@ class Countfood extends Base{
|
|||
}
|
||||
$nutrition_data = $this->count_user_nutrition_all($user_data);
|
||||
if($user_data['is_use_set_kcal'] == 1){
|
||||
$proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
|
||||
$nutrition_data['kcal'] = $user_data['set_kcal'];
|
||||
$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);
|
||||
// $proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
|
||||
// $nutrition_data['kcal'] = $user_data['set_kcal'];
|
||||
// $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);
|
||||
$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 = [
|
||||
'date'=>$data['time'], //时间
|
||||
|
|
@ -795,7 +786,7 @@ class Countfood extends Base{
|
|||
->alias('a')
|
||||
->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
|
||||
->where("a.is_del = 0 AND a.aud_id = " . $data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $data['time'] . "' AS DATE)")
|
||||
->field('a.meals_type,a.food_name,a.weight,a.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')
|
||||
->field('a.meals_type,a.food_name,a.weight,a.unit,a.kcal_val,a.carbohydrate_val,a.protein_val,a.fat_val,a.id,\'https://tc.pcxbc.com\' + b.pic_url as pic_url,a.food_id')
|
||||
->select();
|
||||
|
||||
if(count($food_content) > 0){ //计算营养物质
|
||||
|
|
@ -816,7 +807,7 @@ class Countfood extends Base{
|
|||
$return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][0]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'weight'=>$value['weight'].' '.$value['unit'],
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
|
|
@ -831,7 +822,7 @@ class Countfood extends Base{
|
|||
$return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][1]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'weight'=>$value['weight'].' '.$value['unit'],
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
|
|
@ -846,7 +837,7 @@ class Countfood extends Base{
|
|||
$return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][2]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'weight'=>$value['weight'].' '.$value['unit'],
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
|
|
@ -861,7 +852,7 @@ class Countfood extends Base{
|
|||
$return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][3]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'weight'=>$value['weight'].' '.$value['unit'],
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
|
|
@ -887,6 +878,7 @@ class Countfood extends Base{
|
|||
// 微量元素处理全天
|
||||
$return_data = $this->calculate_trace_elements($return_data);
|
||||
// 处理单餐营养占比
|
||||
// return $this->msg($return_data);
|
||||
foreach ($return_data['list'] as $key => $value) {
|
||||
$all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
|
||||
foreach ($value['nutrients_four'] as $k => $v) {
|
||||
|
|
@ -894,11 +886,16 @@ class Countfood extends Base{
|
|||
if($all_yy_data_0 == 0){
|
||||
$return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
|
||||
}else{
|
||||
$return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2))*100;
|
||||
}
|
||||
$return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':bcmul(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2),100,2);
|
||||
}
|
||||
// if($value['name'] == '晚餐'){
|
||||
// // dump($return_data['list'][$key]['nutrients_four'][$k]['proportion']);
|
||||
// }
|
||||
// dump($return_data['list'][$key]['nutrients_four'][$k]['proportion']);
|
||||
}
|
||||
}
|
||||
}
|
||||
// return $this->msg($return_data);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -918,15 +915,18 @@ class Countfood extends Base{
|
|||
'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':(bcdiv($return_data['today_intake'][$key],$value,2))*100,
|
||||
'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
|
||||
'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_data = $this->calculate_kcal_proportion($return_data);
|
||||
|
||||
|
||||
// return $return_data;
|
||||
return $this->msg($return_data);
|
||||
|
||||
}
|
||||
|
|
@ -934,7 +934,7 @@ class Countfood extends Base{
|
|||
$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')
|
||||
->field('weight,height,gender,age,is_use_set_kcal,set_kcal,activity_level')
|
||||
->find();
|
||||
if(!$user_data){
|
||||
return $this->msg(10003);
|
||||
|
|
@ -981,74 +981,118 @@ class Countfood extends Base{
|
|||
'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')
|
||||
->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'];
|
||||
$nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal'];
|
||||
$nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate'];
|
||||
$nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein'];
|
||||
$nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat'];
|
||||
|
||||
|
||||
// $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?bcdiv($user_data['set_carbohydrate_p'],100,2):$nutrition_data['carbohydrate_p'];
|
||||
// $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?bcdiv($user_data['set_protein_p'],100,2):$nutrition_data['protein_p'];
|
||||
// $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?bcdiv($user_data['set_fat_p'],100,2):$nutrition_data['fat_p'];
|
||||
$nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?$user_data['set_carbohydrate_p']:bcmul($nutrition_data['carbohydrate_p'],100,2);
|
||||
$nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?$user_data['set_protein_p']:bcmul($nutrition_data['protein_p'],100,2);
|
||||
$nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?$user_data['set_fat_p']:bcmul($nutrition_data['fat_p'],100,2);
|
||||
}else{
|
||||
$nutrition_data['carbohydrate_p'] = bcmul($nutrition_data['carbohydrate_p'],100,2);
|
||||
$nutrition_data['protein_p'] = bcmul($nutrition_data['protein_p'],100,2);
|
||||
$nutrition_data['fat_p'] = bcmul($nutrition_data['fat_p'],100,2);
|
||||
}
|
||||
$nutrition_describe = [
|
||||
[
|
||||
'对于一个孩子(2-18岁)(没有特殊健康问题),身体处于快速生长发育阶段,需要充足的营养支持,尤其是蛋白质和健康脂肪。通常建议的三大营养素比例为:',
|
||||
'1、碳水化合物:45%-65% 的总热量',
|
||||
'提供能量,支持孩子的日常活动和生长发育。',
|
||||
'优先选择复合碳水化合物(如全谷物、蔬菜、水果),避免精制糖和高糖零食。',
|
||||
'2、蛋白质:10%-30% 的总热量',
|
||||
'支持肌肉、骨骼和器官的发育。',
|
||||
'建议摄入优质蛋白质来源,如瘦肉、鱼类、鸡蛋、豆类和乳制品。',
|
||||
'蛋白质需求较高,尤其是青春期孩子。',
|
||||
'3、脂肪:25%-35% 的总热量',
|
||||
'提供能量,并支持大脑发育(尤其是Omega-3脂肪酸)。',
|
||||
'优先选择健康脂肪,如鱼类、坚果、种子、橄榄油和牛油果。',
|
||||
'避免反式脂肪和过多的饱和脂肪。',
|
||||
'注意事项',
|
||||
'如果你有特定的健康目标(如增高,减重),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
// '对于一个孩子(2-18岁)(没有特殊健康问题),身体处于快速生长发育阶段,需要充足的营养支持,尤其是蛋白质和健康脂肪。通常建议的三大营养素比例为:',
|
||||
// '1、碳水化合物:45%-65% 的总热量',
|
||||
// '提供能量,支持孩子的日常活动和生长发育。',
|
||||
// '优先选择复合碳水化合物(如全谷物、蔬菜、水果),避免精制糖和高糖零食。',
|
||||
// '2、蛋白质:10%-30% 的总热量',
|
||||
// '支持肌肉、骨骼和器官的发育。',
|
||||
// '建议摄入优质蛋白质来源,如瘦肉、鱼类、鸡蛋、豆类和乳制品。',
|
||||
// '蛋白质需求较高,尤其是青春期孩子。',
|
||||
// '3、脂肪:25%-35% 的总热量',
|
||||
// '提供能量,并支持大脑发育(尤其是Omega-3脂肪酸)。',
|
||||
// '优先选择健康脂肪,如鱼类、坚果、种子、橄榄油和牛油果。',
|
||||
// '避免反式脂肪和过多的饱和脂肪。',
|
||||
// '注意事项',
|
||||
// '如果你有特定的健康目标(如增高,减重),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
'孩子(2-18岁)处于快速生长发育期,需充足营养,尤其蛋白质和健康脂肪。建议比例:',
|
||||
'1、碳水化合物:45%-65%总热量',
|
||||
'提供能量,优选全谷物、蔬果等复合碳水,避免高糖零食。',
|
||||
'2、蛋白质:10%-30%总热量',
|
||||
'支持肌肉、骨骼发育,推荐鱼、蛋、瘦肉、豆类等优质蛋白。',
|
||||
'3、脂肪:25%-35%总热量',
|
||||
'供能并促进大脑发育,选择坚果、鱼类、橄榄油等健康脂肪。',
|
||||
'注意事项:若有增高、减重等目标,可咨询专业人士调整。'
|
||||
],
|
||||
[
|
||||
'对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:',
|
||||
'1、碳水化合物:45%-65% 的总热量',
|
||||
'主要功能是提供能量',
|
||||
'建议选择复合碳水化合物(如全谷物、蔬菜、豆类),而不是精制糖。',
|
||||
'对于普通人,碳水化合物占总热量的 50%-55% 是一个常见的推荐值。',
|
||||
'2、蛋白质:10%-35% 的总热量',
|
||||
'用于维持肌肉、修复组织和支持免疫功能。',
|
||||
'普通人每日蛋白质摄入量建议为 0.8-1.2克/公斤体重。',
|
||||
'对于活动量较大或健身人群,蛋白质比例可以提高到 20%-30%。',
|
||||
'3、脂肪:20%-35% 的总热量',
|
||||
'提供能量、支持细胞功能并帮助吸收脂溶性维生素。',
|
||||
'建议以 不饱和脂肪(如橄榄油、坚果、鱼类)为主,减少饱和脂肪和反式脂肪的摄入。',
|
||||
'脂肪占总热量的 20%-30% 是常见的推荐值。',
|
||||
'以上是根据世界卫生组织(WHO)和其他健康机构的建议制定的。具体比例可以根据个人的活动水平、健康状况和目标进行微调。',
|
||||
'注意事项',
|
||||
'活动水平:活动量大的人可能需要更多的碳水化合物来提供能量,而健身人群可能需要更多的蛋白质。',
|
||||
'健康状况:例如,糖尿病患者可能需要控制碳水化合物比例,而心血管疾病患者可能需要减少脂肪摄入。',
|
||||
'个体差异:每个人的代谢和需求不同,建议根据个人情况调整。',
|
||||
'如果你有特定的健康目标(如减脂、增肌或控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
// '对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:',
|
||||
// '1、碳水化合物:45%-65% 的总热量',
|
||||
// '主要功能是提供能量',
|
||||
// '建议选择复合碳水化合物(如全谷物、蔬菜、豆类),而不是精制糖。',
|
||||
// '对于普通人,碳水化合物占总热量的 50%-55% 是一个常见的推荐值。',
|
||||
// '2、蛋白质:10%-35% 的总热量',
|
||||
// '用于维持肌肉、修复组织和支持免疫功能。',
|
||||
// '普通人每日蛋白质摄入量建议为 0.8-1.2克/公斤体重。',
|
||||
// '对于活动量较大或健身人群,蛋白质比例可以提高到 20%-30%。',
|
||||
// '3、脂肪:20%-35% 的总热量',
|
||||
// '提供能量、支持细胞功能并帮助吸收脂溶性维生素。',
|
||||
// '建议以 不饱和脂肪(如橄榄油、坚果、鱼类)为主,减少饱和脂肪和反式脂肪的摄入。',
|
||||
// '脂肪占总热量的 20%-30% 是常见的推荐值。',
|
||||
// '以上是根据世界卫生组织(WHO)和其他健康机构的建议制定的。具体比例可以根据个人的活动水平、健康状况和目标进行微调。',
|
||||
// '注意事项',
|
||||
// '活动水平:活动量大的人可能需要更多的碳水化合物来提供能量,而健身人群可能需要更多的蛋白质。',
|
||||
// '健康状况:例如,糖尿病患者可能需要控制碳水化合物比例,而心血管疾病患者可能需要减少脂肪摄入。',
|
||||
// '个体差异:每个人的代谢和需求不同,建议根据个人情况调整。',
|
||||
// '如果你有特定的健康目标(如减脂、增肌或控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
'正常成年人(无特殊健康问题)建议营养比例:',
|
||||
'1、碳水化合物:45%-65%总热量',
|
||||
'主要供能,推荐全谷物、豆类等复合碳水。',
|
||||
'2、蛋白质:10%-35%总热量',
|
||||
'维持肌肉与免疫功能,日常建议0.8-1.2克/公斤体重。',
|
||||
'3、脂肪:20%-35%总热量',
|
||||
'支持细胞功能,以不饱和脂肪为主,减少饱和脂肪。',
|
||||
'注意事项:根据活动量、健康状况微调,特殊目标需个性化建议。'
|
||||
],
|
||||
[
|
||||
'对于一个老人(65岁以上)(没有特殊健康问题),身体的代谢率下降,肌肉量减少,可能面临营养不良或慢性病风险,因此需要调整营养比例。通常建议的三大营养素比例为:',
|
||||
'1、碳水化合物:45%-65% 的总热量',
|
||||
'提供能量,但应选择低血糖指数(GI)的食物,如全谷物、蔬菜和豆类,以控制血糖水平。',
|
||||
'避免精制糖和高糖食物,尤其是糖尿病患者。',
|
||||
'帮助维持肌肉质量,预防肌肉流失(少肌症)。',
|
||||
'建议摄入优质蛋白质,如鱼类、瘦肉、鸡蛋、豆类和乳制品。',
|
||||
'蛋白质需求较高,尤其是活动量较大的老人。',
|
||||
'3、脂肪:20%-35% 的总热量',
|
||||
'提供能量,并支持细胞功能和脂溶性维生素的吸收。',
|
||||
'优先选择不饱和脂肪,如橄榄油、坚果、种子和鱼类。',
|
||||
'减少饱和脂肪和反式脂肪的摄入,以降低心血管疾病风险。',
|
||||
'注意事项',
|
||||
'如果你有特定的健康目标(控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
// '对于一个老人(65岁以上)(没有特殊健康问题),身体的代谢率下降,肌肉量减少,可能面临营养不良或慢性病风险,因此需要调整营养比例。通常建议的三大营养素比例为:',
|
||||
// '1、碳水化合物:45%-65% 的总热量',
|
||||
// '提供能量,但应选择低血糖指数(GI)的食物,如全谷物、蔬菜和豆类,以控制血糖水平。',
|
||||
// '避免精制糖和高糖食物,尤其是糖尿病患者。',
|
||||
// '帮助维持肌肉质量,预防肌肉流失(少肌症)。',
|
||||
// '建议摄入优质蛋白质,如鱼类、瘦肉、鸡蛋、豆类和乳制品。',
|
||||
// '蛋白质需求较高,尤其是活动量较大的老人。',
|
||||
// '3、脂肪:20%-35% 的总热量',
|
||||
// '提供能量,并支持细胞功能和脂溶性维生素的吸收。',
|
||||
// '优先选择不饱和脂肪,如橄榄油、坚果、种子和鱼类。',
|
||||
// '减少饱和脂肪和反式脂肪的摄入,以降低心血管疾病风险。',
|
||||
// '注意事项',
|
||||
// '如果你有特定的健康目标(控制慢性病),可以进一步调整比例,并咨询营养师或医生以获得个性化建议。',
|
||||
'老人(65岁以上)代谢减缓,需关注肌肉维持与慢性病预防。建议比例:',
|
||||
'1、碳水化合物:45%-65%总热量',
|
||||
'选择低GI食物如全谷物、蔬菜,控制血糖。',
|
||||
'2、蛋白质:10%-30%总热量',
|
||||
'预防肌肉流失,优选鱼、蛋、豆类等易消化蛋白。',
|
||||
'3、脂肪:20%-35%总热量',
|
||||
'支持营养吸收,以橄榄油、鱼类等健康脂肪为主。',
|
||||
'注意事项:慢性病患者需结合医生建议调整饮食。'
|
||||
]
|
||||
];
|
||||
$return_data = [
|
||||
|
|
@ -1075,21 +1119,21 @@ class Countfood extends Base{
|
|||
[
|
||||
'name'=>'碳水化合物',
|
||||
'icon'=>'icon-tanshuihuahewu',
|
||||
'proportion'=>'50%',
|
||||
'proportion'=>$nutrition_data['carbohydrate_p'],
|
||||
'val'=>$nutrition_data['carbohydrate'],
|
||||
'unit'=>'克'
|
||||
],
|
||||
[
|
||||
'name'=>'蛋白质',
|
||||
'icon'=>'icon-Sm-danbaizhi',
|
||||
'proportion'=>'20%',
|
||||
'proportion'=>$nutrition_data['protein_p'],
|
||||
'val'=>$nutrition_data['protein'],
|
||||
'unit'=>'克'
|
||||
],
|
||||
[
|
||||
'name'=>'脂肪',
|
||||
'icon'=>'icon-w_fat_normal',
|
||||
'proportion'=>'30%',
|
||||
'proportion'=>$nutrition_data['fat_p'],
|
||||
'val'=>$nutrition_data['fat'],
|
||||
'unit'=>'克'
|
||||
]
|
||||
|
|
@ -1109,28 +1153,7 @@ class Countfood extends Base{
|
|||
return $this->msg($return_data);
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
public function del_user_eat_log_action($data){
|
||||
$cfc = Db::connect('cfc_db');
|
||||
$user_data = $cfc->table($this->kitchenscale_db_msg['eat_log'])
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use app\KitchenScale2\controller\app\Guessyoulike;// 引入Wechat服务类
|
||||
use app\KitchenScale2\controller\app\Guessyoulike;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
|
|
@ -233,23 +233,6 @@ class Index extends Base{
|
|||
// 新版
|
||||
public function get_default_config_action($data){
|
||||
$return_data = [
|
||||
// 'user_data'=>[],
|
||||
// 'kcal_data'=>[
|
||||
// 'title'=>'今日已摄入热量',
|
||||
// 'time'=>date('Y-m-d H:i:s'),
|
||||
// 'kcal'=>['value'=>0,'unit'=>'kcal','standard'=>'不达标','color'=>'#F0AD4E'],
|
||||
// 'other_elements'=>[
|
||||
// 'carbohydrate'=>['value'=>0,'unit'=>'g'],
|
||||
// 'protein'=>['value'=>0,'unit'=>'g'],
|
||||
// 'fat'=>['value'=>0,'unit'=>'g'],
|
||||
// ],
|
||||
// 'list'=>[
|
||||
// ['title'=>'早餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'午餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'晚餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ['title'=>'加餐(千卡)','icon'=>'','value'=>0,'unit'=>'kcal'],
|
||||
// ],
|
||||
// ],
|
||||
'business_cooperation'=>[],
|
||||
'banner_data'=>[],
|
||||
'search_history'=>['cookbook'=>[],'food'=>[]],
|
||||
|
|
@ -623,8 +606,14 @@ class Index extends Base{
|
|||
'list'=>[],
|
||||
],
|
||||
],
|
||||
]
|
||||
// 'cookbook_label'=>[],
|
||||
],
|
||||
'activity_level'=>[
|
||||
['name'=>'久坐(很少或没有运动)','val'=>'1.2'],
|
||||
['name'=>'轻度活动(每周1-3天轻度运动)','val'=>'1.375'],
|
||||
['name'=>'中度活动(每周3-5天中度运动)','val'=>'1.55'],
|
||||
['name'=>'高度活动(每周6-7天高强度运动)','val'=>'1.725'],
|
||||
['name'=>'极高活动(体力劳动或每天高强度训练)','val'=>'1.9'],
|
||||
],
|
||||
];
|
||||
$cfc = Db::connect('cfc_db');
|
||||
|
||||
|
|
@ -643,13 +632,13 @@ class Index extends Base{
|
|||
->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'cookbook'])
|
||||
->field('id,keyword,last_searched_at,type')
|
||||
->order('last_searched_at desc')
|
||||
->limit(30)
|
||||
->limit(10)
|
||||
->select();
|
||||
$search_history_food = $cfc->table($this->kitchenscale_db_msg['search_history'])
|
||||
->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'food'])
|
||||
->field('id,keyword,last_searched_at,type')
|
||||
->order('last_searched_at desc')
|
||||
->limit(30)
|
||||
->limit(10)
|
||||
->select();
|
||||
// 去重
|
||||
foreach ($search_history_cookbook as $key => $value) {
|
||||
|
|
@ -727,15 +716,16 @@ class Index extends Base{
|
|||
}else{
|
||||
|
||||
}
|
||||
$banner_list = Db::table($this->reedaw_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(43200)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
|
||||
for ($i=0; $i < count($banner_list); $i++) {
|
||||
if($banner_list[$i]['type'] != 1){
|
||||
$banner_list[$i]['parameter_data'] = '';
|
||||
}
|
||||
unset($banner_list[$i]['sort_num']);
|
||||
unset($banner_list[$i]['ROW_NUMBER']);
|
||||
}
|
||||
$return_data['banner_data'] = $banner_list;
|
||||
// 处理banner信息 start
|
||||
// $banner_list = Db::table($this->reedaw_db_name['banner'])->where(['scene_data' => '3','is_del'=>0])->cache(43200)->order('sort_num desc')->field('id,type,pic,jump_url,parameter_data,sort_num')->select();
|
||||
// for ($i=0; $i < count($banner_list); $i++) {
|
||||
// if($banner_list[$i]['type'] != 1){
|
||||
// $banner_list[$i]['parameter_data'] = '';
|
||||
// }
|
||||
// unset($banner_list[$i]['sort_num']);
|
||||
// unset($banner_list[$i]['ROW_NUMBER']);
|
||||
// }
|
||||
// $return_data['banner_data'] = $banner_list;
|
||||
// 处理banner信息 end
|
||||
|
||||
// 处理猜你喜欢信息start
|
||||
|
|
@ -759,8 +749,8 @@ class Index extends Base{
|
|||
|
||||
// 添加菜谱label start
|
||||
|
||||
// $cookbook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
|
||||
// $return_data['cookbook_label'] = $cookbook_label;
|
||||
$cookbook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])->where(["is_del"=>0])->field('id,name')->select();
|
||||
$return_data['cookbook_label'] = $cookbook_label;
|
||||
// 添加菜谱label end
|
||||
|
||||
// 添加每餐背景图start
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace app\KitchenScale2\controller\app;
|
||||
|
||||
use think\Db;
|
||||
use app\KitchenScale2\controller\app\Countfood;
|
||||
|
||||
class Usercenter extends Base{
|
||||
|
||||
|
|
@ -39,11 +40,9 @@ class Usercenter extends Base{
|
|||
################################################################接口################################################################
|
||||
|
||||
// 获取角色信息
|
||||
public function get_user_msg($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||
// try { 、
|
||||
if(count(input('post.')) > 0){
|
||||
public function get_user_msg(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001);
|
||||
}
|
||||
|
|
@ -52,27 +51,25 @@ class Usercenter extends Base{
|
|||
}
|
||||
$return_data = $this->get_user_msg_action($data);
|
||||
return $return_data;
|
||||
// } catch (\Exception $e) {
|
||||
// // 捕获异常
|
||||
// $logContent["flie"] = $e->getFile();
|
||||
// $logContent["line"] = $e->getLine();
|
||||
// $logContent['all_content'] = "异常信息:\n";
|
||||
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
// $logContent['all_content'] .= "接口: (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);
|
||||
// }
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
// 修改用户
|
||||
public function update_user_msg(){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
|
|
@ -91,6 +88,9 @@ class Usercenter extends Base{
|
|||
if(!array_key_exists('weight', $data)){
|
||||
return $this->msg(10001,'weight is miss');
|
||||
}
|
||||
if(!array_key_exists('activity_level', $data)){
|
||||
return $this->msg(10001,'weight is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
|
|
@ -109,6 +109,9 @@ class Usercenter extends Base{
|
|||
if(!$this->verify_data_is_ok($data['weight'],'num')){
|
||||
return $this->msg(10005,'weight type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['activity_level'],'num')){
|
||||
return $this->msg(10005,'activity_level type is error');
|
||||
}
|
||||
$return_data = $this->update_user_msg_action($data);
|
||||
return $return_data;
|
||||
} catch (\Exception $e) {
|
||||
|
|
@ -128,11 +131,9 @@ class Usercenter extends Base{
|
|||
}
|
||||
|
||||
// 获取用户收藏点赞列表(OK)
|
||||
public function get_user_collect_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
|
||||
public function get_user_collect_list(){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
|
|
@ -164,11 +165,9 @@ class Usercenter extends Base{
|
|||
}
|
||||
|
||||
// 我的菜谱
|
||||
public function get_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1,'search_data'=>'']){
|
||||
public function get_my_cookbook(){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
|
|
@ -200,11 +199,9 @@ class Usercenter extends Base{
|
|||
}
|
||||
|
||||
// 菜谱删除
|
||||
public function del_my_cookbook($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'cookbook_id'=>'33']){
|
||||
public function del_my_cookbook(){
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
|
|
@ -245,9 +242,7 @@ class Usercenter extends Base{
|
|||
public function del_search_history(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
if(count(input('post.')) > 0){
|
||||
$data = input('post.');
|
||||
}
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
|
|
@ -290,6 +285,174 @@ class Usercenter extends Base{
|
|||
return $this->fetch();
|
||||
}
|
||||
|
||||
// 设置营养比例
|
||||
public function set_nutrition_proportion(){
|
||||
// 尝试捕获异常
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!array_key_exists('set_kcal', $data)){
|
||||
return $this->msg(10001,'set_kcal is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['set_kcal'],'num')){
|
||||
return $this->msg(10005,'set_kcal type is error');
|
||||
}
|
||||
|
||||
if(!array_key_exists('carbohydrate_v', $data)){
|
||||
return $this->msg(10001,'carbohydrate_v is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['carbohydrate_v'],'num')){
|
||||
return $this->msg(10005,'carbohydrate_v type is error');
|
||||
}
|
||||
if(!array_key_exists('carbohydrate_p', $data)){
|
||||
return $this->msg(10001,'carbohydrate_p is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['carbohydrate_p'],'num')){
|
||||
return $this->msg(10005,'carbohydrate_p type is error');
|
||||
}
|
||||
|
||||
if(!array_key_exists('protein_v', $data)){
|
||||
return $this->msg(10001,'protein_v is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['protein_v'],'num')){
|
||||
return $this->msg(10005,'protein_v type is error');
|
||||
}
|
||||
if(!array_key_exists('protein_p', $data)){
|
||||
return $this->msg(10001,'protein_p is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['protein_p'],'num')){
|
||||
return $this->msg(10005,'protein_p type is error');
|
||||
}
|
||||
|
||||
if(!array_key_exists('fat_v', $data)){
|
||||
return $this->msg(10001,'fat_v is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['fat_v'],'num')){
|
||||
return $this->msg(10005,'fat_v type is error');
|
||||
}
|
||||
if(!array_key_exists('fat_p', $data)){
|
||||
return $this->msg(10001,'fat_p is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['fat_p'],'num')){
|
||||
return $this->msg(10005,'fat_p type is error');
|
||||
}
|
||||
|
||||
// $data['del_arr'] = strval($data['del_arr']);
|
||||
// $data['del_arr'] = trim($data['del_arr']);
|
||||
// 判断是否是 "all"(不区分大小写)
|
||||
// if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) {
|
||||
// return $this->msg(10005,'del_arr type is error');
|
||||
// }
|
||||
|
||||
$return_data = $this->set_nutrition_proportion_action($data);
|
||||
return $return_data;
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
// 记录日志
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return json(['status' => 'error', 'message' => '系统错误']);
|
||||
}
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
public function update_my_password(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('password', $data)){
|
||||
return $this->msg(10001,'password is miss');
|
||||
}
|
||||
if(!array_key_exists('c_password', $data)){
|
||||
return $this->msg(10001,'c_password is miss');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if($data['password'] != $data['c_password']){
|
||||
return $this->msg(10005,'两次密码不一致');
|
||||
}
|
||||
if($data['password'] == ''){
|
||||
return $this->msg(10005,'密码不能为空');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['password'],'str')){
|
||||
return $this->msg(10005,'password type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['c_password'],'str')){
|
||||
return $this->msg(10005,'c_password type is error');
|
||||
}
|
||||
$return_data = $this->update_my_password_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);
|
||||
}
|
||||
}
|
||||
// 绑定手机/邮箱
|
||||
public function update_my_account_msg(){
|
||||
try {
|
||||
$data = input('post.');
|
||||
if(!array_key_exists('token', $data)){
|
||||
return $this->msg(10001,'token is miss');
|
||||
}
|
||||
if(!array_key_exists('data', $data)){
|
||||
return $this->msg(10001,'data is miss');
|
||||
}
|
||||
if(!array_key_exists('code', $data)){
|
||||
return $this->msg(10001,'code 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['data'],'str')){
|
||||
return $this->msg(10005,'data type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['code'],'intnum')){
|
||||
return $this->msg(10005,'code type is error');
|
||||
}
|
||||
$return_data = $this->update_my_account_msg_action($data);
|
||||
return $return_data;
|
||||
} catch (\Exception $e) {
|
||||
// 捕获异常
|
||||
$logContent["flie"] = $e->getFile();
|
||||
$logContent["line"] = $e->getLine();
|
||||
$logContent['all_content'] = "异常信息:\n";
|
||||
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||
$logContent['all_content'] .= "接口: (get_default_config)\n";
|
||||
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||
$this->record_api_log($data, $logContent, null);
|
||||
return $this->msg(99999);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#######################################################################action#######################################################################
|
||||
|
|
@ -319,7 +482,7 @@ class Usercenter extends Base{
|
|||
$cfc = Db::connect('cfc_db');
|
||||
$user_account = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->where(["token"=>$data['token']])
|
||||
->field('id as aud_id,token,nickname,head_pic,gender,age,height,weight,set_kcal,is_use_set_kcal,birthday')
|
||||
->field('id as aud_id,token,nickname,head_pic,gender,age,height,weight,set_kcal,is_use_set_kcal,birthday,activity_level')
|
||||
->find();
|
||||
if($user_account){
|
||||
if($user_account['set_kcal'] == '.00'){
|
||||
|
|
@ -333,7 +496,33 @@ class Usercenter extends Base{
|
|||
$user_all_data['set_kcal'] = $user_account['set_kcal'];
|
||||
$user_all_data['is_use_set_kcal'] = $user_account['is_use_set_kcal'];
|
||||
$user_all_data['birthday'] = $user_account['birthday'];
|
||||
$user_all_data['food_count'] = $this->user_that_day_food_count($user_account);
|
||||
$user_all_data['activity_level'] = $user_account['activity_level'];
|
||||
if($user_all_data['gender'] == 2){
|
||||
if($user_all_data['age'] <= 18){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman1.png";
|
||||
}else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman2.png";
|
||||
}else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman3.png";
|
||||
}else if($user_all_data['age'] >= 60){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/woman4.png";
|
||||
}
|
||||
}else{
|
||||
if($user_all_data['age'] <= 18){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man1.png";
|
||||
}else if($user_all_data['age'] <= 39 && $user_all_data['age'] > 18){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man2.png";
|
||||
}else if($user_all_data['age'] <= 59 && $user_all_data['age'] > 39){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man3.png";
|
||||
}else if($user_all_data['age'] >= 60){
|
||||
$user_all_data['head_pic'] = "https://tc.pcxbc.com/kitchenscale_all/man4.png";
|
||||
}
|
||||
}
|
||||
|
||||
$countfood = new Countfood;
|
||||
$user_all_data['food_count'] = $countfood->get_countfoot_content_action(['token'=>$data['token'],'aud_id'=>$user_all_data['aud_id'],'time'=>date('Y-m-d')]);
|
||||
$user_all_data['food_count'] = ($user_all_data['food_count']->getData())['data'];
|
||||
// dump($user_all_data['food_count']);
|
||||
}else{
|
||||
return $this->msg(10004);
|
||||
}
|
||||
|
|
@ -363,6 +552,7 @@ class Usercenter extends Base{
|
|||
$user_msg['birthday'] = $data['birthday'];
|
||||
$user_msg['height'] = $data['height'];
|
||||
$user_msg['weight'] = $data['weight'];
|
||||
$user_msg['activity_level'] = $data['activity_level'];
|
||||
|
||||
if($is_user_true>0){
|
||||
$user_msg['update_time'] = date('Y-m-d H:i:s');
|
||||
|
|
@ -430,7 +620,6 @@ class Usercenter extends Base{
|
|||
'content_list'=>$collect_list
|
||||
]);
|
||||
}
|
||||
|
||||
public function get_my_cookbook_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
|
|
@ -495,7 +684,6 @@ class Usercenter extends Base{
|
|||
'content_list'=>$content_list
|
||||
]);
|
||||
}
|
||||
|
||||
public function del_my_cookbook_action($data){
|
||||
// 获取账号下信息以及用户信息
|
||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count();
|
||||
|
|
@ -530,8 +718,6 @@ class Usercenter extends Base{
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function del_search_history_action($data){
|
||||
|
||||
// $data['del_arr'] = strval($data['del_arr']);
|
||||
|
|
@ -567,7 +753,6 @@ class Usercenter extends Base{
|
|||
|
||||
// 获取菜谱分类标签end
|
||||
}
|
||||
|
||||
public function business_cooperation_action(){
|
||||
$data = input();
|
||||
|
||||
|
|
@ -587,222 +772,63 @@ class Usercenter extends Base{
|
|||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function user_that_day_food_count($user_data){
|
||||
public function set_nutrition_proportion_action($data){
|
||||
$cfc = Db::connect('cfc_db');
|
||||
if($user_data['birthday']){
|
||||
$user_data['age_num'] = $this->calculate_age($user_data['birthday']);
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['user'])
|
||||
->where(['token'=>$data['token']])
|
||||
->update([
|
||||
'is_use_set_kcal'=>1,
|
||||
'set_kcal'=>$data['set_kcal'],
|
||||
'set_carbohydrate_v'=>$data['carbohydrate_v'],
|
||||
'set_carbohydrate_p'=>$data['carbohydrate_p'],
|
||||
'set_protein_v'=>$data['protein_v'],
|
||||
'set_protein_p'=>$data['protein_p'],
|
||||
'set_fat_v'=>$data['fat_v'],
|
||||
'set_fat_p'=>$data['fat_p'],
|
||||
]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
$user_data['age_num'] = $user_data['age'];
|
||||
return $this->msg(10002);
|
||||
}
|
||||
$nutrition_data = $this->count_user_nutrition_all($user_data);
|
||||
if($user_data['is_use_set_kcal'] == 1){
|
||||
$proportion = bcdiv($user_data['set_kcal'],$nutrition_data['kcal'],20);
|
||||
$nutrition_data['kcal'] = $user_data['set_kcal'];
|
||||
$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);
|
||||
|
||||
}
|
||||
$day_time = date('Y-m-d');
|
||||
$return_data = [
|
||||
'date'=>$day_time, //时间
|
||||
'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'], //剩下可摄入卡路里量
|
||||
'list'=>[
|
||||
[
|
||||
'name'=>'早餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#0992B4',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png',
|
||||
'icon_home'=>'/static/1.png',
|
||||
'bgimg_home'=>'/static/2.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'午餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#4F9211',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png',
|
||||
'icon_home'=>'/static/3.png',
|
||||
'bgimg_home'=>'/static/4.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'晚餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#B354B0',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png',
|
||||
'icon_home'=>'/static/5.png',
|
||||
'bgimg_home'=>'/static/6.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>'加餐',
|
||||
'val'=>0,
|
||||
'unit'=>'kcal',
|
||||
'color'=>'#C08433',
|
||||
'icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png',
|
||||
'icon_home'=>'/static/7.png',
|
||||
'bgimg_home'=>'/static/8.png',
|
||||
'kcal_proportion'=>0,
|
||||
'list'=>[],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// 查询用户今日摄入食物
|
||||
$food_content = $cfc->table($this->kitchenscale_db_msg['eat_log'])
|
||||
->alias('a')
|
||||
->join('app_z_national_standard_food_type_3 b','a.food_id = b.id','LEFT')
|
||||
->where("a.is_del = 0 AND a.aud_id = " . $user_data['aud_id'] . " AND CAST(a.create_time AS DATE) = CAST('" . $day_time . "' AS DATE)")
|
||||
->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')
|
||||
->select();
|
||||
|
||||
if(count($food_content) > 0){ //计算营养物质
|
||||
$food_content = $this->calculate_nutrients($food_content);
|
||||
// return $this->msg($food_content);
|
||||
foreach ($food_content as $key => $value) {
|
||||
// dump($value['nutrients_four']);
|
||||
$return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2);
|
||||
$return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2);
|
||||
$return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2);
|
||||
$return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2);
|
||||
// 处理各餐
|
||||
if($value['meals_type'] == '早餐'){
|
||||
$return_data['list'][0]['val'] = bcadd($return_data['list'][0]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][0]['value'] = bcadd($return_data['list'][0]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][1]['value'] = bcadd($return_data['list'][0]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][2]['value'] = bcadd($return_data['list'][0]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][0]['nutrients_four'][3]['value'] = bcadd($return_data['list'][0]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][0]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
]);
|
||||
}else if($value['meals_type'] == '午餐'){
|
||||
$return_data['list'][1]['val'] = bcadd($return_data['list'][1]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][0]['value'] = bcadd($return_data['list'][1]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][1]['value'] = bcadd($return_data['list'][1]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][2]['value'] = bcadd($return_data['list'][1]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][1]['nutrients_four'][3]['value'] = bcadd($return_data['list'][1]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][1]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
]);
|
||||
}else if($value['meals_type'] == '晚餐'){
|
||||
$return_data['list'][2]['val'] = bcadd($return_data['list'][2]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][0]['value'] = bcadd($return_data['list'][2]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][1]['value'] = bcadd($return_data['list'][2]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][2]['value'] = bcadd($return_data['list'][2]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][2]['nutrients_four'][3]['value'] = bcadd($return_data['list'][2]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][2]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
]);
|
||||
public function update_my_password_action($data){
|
||||
// $cfc = Db::connect('cfc_db');
|
||||
// 检查账号是否存在
|
||||
$find_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->count();
|
||||
if(!$find_data){
|
||||
return $this->msg(10003);
|
||||
}
|
||||
$result = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->update(['password'=>$data['password']]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
$return_data['list'][3]['val'] = bcadd($return_data['list'][3]['val'],$value['kcal_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][0]['value'] = bcadd($return_data['list'][3]['nutrients_four'][0]['value'],$value['kcal_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][1]['value'] = bcadd($return_data['list'][3]['nutrients_four'][1]['value'],$value['carbohydrate_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][2]['value'] = bcadd($return_data['list'][3]['nutrients_four'][2]['value'],$value['protein_val'],2);
|
||||
// $return_data['list'][3]['nutrients_four'][3]['value'] = bcadd($return_data['list'][3]['nutrients_four'][3]['value'],$value['fat_val'],2);
|
||||
array_push($return_data['list'][3]['list'],[
|
||||
'name'=>$value['food_name'],
|
||||
'weight'=>$value['weight'].'克',
|
||||
'id'=>$value['id'],
|
||||
'pic_url'=>$value['pic_url'],
|
||||
'val'=>$value['kcal_val'],
|
||||
// 'nutrients_four' => $value['nutrients_four'],
|
||||
// 'nutrients_list' => $value['nutrients_list']
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
public function update_my_account_msg_action($data){
|
||||
$validate_result = $this->check_code($data['data'],$data['code']);
|
||||
if($validate_result !== true){
|
||||
return $this->msg(10001,$validate_result);
|
||||
}
|
||||
$montage_data = $this->is_tel_email($data['data']);
|
||||
if($montage_data == false){
|
||||
return $this->msg(10005);
|
||||
}
|
||||
$result = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->update([
|
||||
$montage_data=>$data['data'],
|
||||
'update_time'=>date('Y-m-d H:i:s')
|
||||
]);
|
||||
if($result){
|
||||
return $this->msg([]);
|
||||
}else{
|
||||
return $this->msg(10002);
|
||||
}
|
||||
}
|
||||
// dump($return_data['list']);
|
||||
// die;
|
||||
$return_data['list'] = array_values($return_data['list']);
|
||||
// 处理剩下可吃
|
||||
$return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0;
|
||||
|
||||
$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':(bcdiv($return_data['today_intake'][$key],$value,2))*100,
|
||||
'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100,
|
||||
];
|
||||
}
|
||||
unset($return_data['suggestion']);
|
||||
unset($return_data['today_intake']);
|
||||
|
||||
|
||||
// // 处理各餐卡路里占比
|
||||
// $return_data = $this->calculate_kcal_proportion($return_data);
|
||||
// // 计算营养物质能量占比
|
||||
// $return_data = $this->calculate_energy_proportion($return_data);
|
||||
// // 排序营养元素食物排行榜
|
||||
// $return_data = $this->energy_food_rank($return_data);
|
||||
// // 微量元素处理全天
|
||||
// $return_data = $this->calculate_trace_elements($return_data);
|
||||
// 处理单餐营养占比
|
||||
// foreach ($return_data['list'] as $key => $value) {
|
||||
// $all_yy_data_0 = bcadd($value['nutrients_four'][3]['value'],bcadd($value['nutrients_four'][1]['value'],$value['nutrients_four'][2]['value'],20),2);
|
||||
// foreach ($value['nutrients_four'] as $k => $v) {
|
||||
// if($k != 0){
|
||||
// if($all_yy_data_0 == 0){
|
||||
// $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = 0;
|
||||
// }else{
|
||||
// $return_data['list'][$key]['nutrients_four'][$k]['proportion'] = bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2) >= 1?'100':(bcdiv($value['nutrients_four'][$k]['value'],$all_yy_data_0,2))*100;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return $return_data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -452,6 +452,8 @@ Route::any('/open_wechat_content', 'app/Msginformation/open_wechat_content');
|
|||
###########################################################################################################################################
|
||||
################################################################以上是Reedaw################################################################
|
||||
|
||||
|
||||
|
||||
################################################################下面是厨房秤################################################################
|
||||
###########################################################################################################################################
|
||||
|
||||
|
|
@ -541,9 +543,6 @@ Route::any('/kitchenscale2/get_log_list', 'app/kitchenscale2/app.countfood/get_l
|
|||
// 计食器板块-设置内容
|
||||
Route::any('/kitchenscale/set_up_content', 'app/kitchenscale/app.countfood/set_up_content');
|
||||
Route::any('/kitchenscale2/set_up_content', 'app/kitchenscale2/app.countfood/set_up_content');
|
||||
// 设置用户的卡路里
|
||||
Route::any('/kitchenscale/set_user_kcal', 'app/kitchenscale/app.countfood/set_user_kcal');
|
||||
Route::any('/kitchenscale2/set_user_kcal', 'app/kitchenscale2/app.countfood/set_user_kcal');
|
||||
// 删除用户某个饮食记录
|
||||
Route::any('/kitchenscale/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
|
||||
Route::any('/kitchenscale2/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log');
|
||||
|
|
@ -579,6 +578,18 @@ Route::any('/kitchenscale2/business_cooperation', 'app/kitchenscale2/app.usercen
|
|||
// 商务合作提交
|
||||
Route::any('/kitchenscale/business_cooperation_action', 'app/kitchenscale/app.usercenter/business_cooperation_action');
|
||||
Route::any('/kitchenscale2/business_cooperation_action', 'app/kitchenscale2/app.usercenter/business_cooperation_action');
|
||||
// ☆设置用户的卡路里&营养占比
|
||||
Route::any('/kitchenscale/set_user_kcal', 'app/kitchenscale/app.usercenter/set_nutrition_proportion');
|
||||
Route::any('/kitchenscale2/set_user_kcal', 'app/kitchenscale2/app.usercenter/set_nutrition_proportion');
|
||||
// ☆重置密码
|
||||
Route::any('/kitchenscale/update_my_password', 'app/kitchenscale/app.usercenter/update_my_password');
|
||||
Route::any('/kitchenscale2/update_my_password', 'app/kitchenscale2/app.usercenter/update_my_password');
|
||||
// ☆修改个人信息
|
||||
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');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 百度图片识别接口################################################################
|
||||
|
|
|
|||
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.6 KiB |