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

102 lines
4.5 KiB
PHP

<?php
namespace app\KitchenScale\controller\app;
use think\Db;
class Login extends Base{
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
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',//收藏列表
'foodlist3'=>'app_food_type_three',//食材列表3
'user_kcal_log'=>'app_user_kcal_log',//食材列表3
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 保存每日餐食食物信息
public function save_food_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_list'=>[['name'=>'鸡肉','weight'=>456.37,'kcal'=>761.52]]]){
// 尝试捕获异常
// 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('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');
}
$return_data = $this->save_food_list_action($data);
return $return_data;
// } catch (\Exception $e) {
// // 捕获异常
// $logContent["file"] = $e->getFile();
// $logContent["line"] = $e->getLine();
// $logContent['all_content'] = "异常信息:\n";
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// // 记录日志
// // $this->record_api_log($data, $logContent, null);
// return json(['status' => 'error', 'message' => '系统错误']);
// }
}
#######################################################################action#######################################################################
#######################################################################action#######################################################################
#######################################################################action#######################################################################
public function save_food_list_action($data){
$cfc = Db::connect('cfc_db');
foreach ($data['food_list'] as $key => $value) {
if(!array_key_exists('name', $value) || !array_key_exists('weight', $value) || !array_key_exists('kcal', $value)){
return $this->msg(10001,'food_list content lost');
}
if(!$this->verify_data_is_ok($value['name'],'str')){
return $this->msg(10005,'name 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['kcal'],'num')){
return $this->msg(10005,'kcal type is error');
}
}
if(!array_key_exists('eat_time', $data)){
$data['eat_time'] = date('Y-m-d H:i:s');
}else{
if(!$this->verify_data_is_ok($data['eat_time'],'datetime')){
return $this->msg(10005,'eat_time type is error');
}
}
$result = $cfc->table($this->kitchenscale_db_msg['user_kcal_log'])
->insert([
'food_name'=>
]);
}
}