厨房秤部分修改提交
This commit is contained in:
parent
b4711455c0
commit
9d043259a6
|
|
@ -6,7 +6,7 @@ use think\Db;
|
|||
|
||||
class Cookbook extends Base{
|
||||
|
||||
protected $code_time = 50;
|
||||
|
||||
// protected $token_time = 2592000;//30天的秒数
|
||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||
protected $reedaw_db_msg = [
|
||||
|
|
@ -281,7 +281,7 @@ class Cookbook extends Base{
|
|||
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||
// }
|
||||
}
|
||||
// 计算当前食材重量的卡路里
|
||||
// 计算当前食材重量的卡路里(OK)
|
||||
public function food_count_kcal($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_name'=>'鸡肉','food_weight'=>456.37]){
|
||||
// 尝试捕获异常
|
||||
// try {
|
||||
|
|
@ -301,10 +301,10 @@ class Cookbook extends Base{
|
|||
return $this->msg(10005,'token type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['food_name'],'str')){
|
||||
return $this->msg(10005,'cook_label type is error');
|
||||
return $this->msg(10005,'food_name type is error');
|
||||
}
|
||||
if(!$this->verify_data_is_ok($data['food_weight'],'num')){
|
||||
return $this->msg(10005,'cook_label type is error');
|
||||
return $this->msg(10005,'food_weight type is error');
|
||||
}
|
||||
|
||||
$return_data = $this->food_count_kcal_action($data);
|
||||
|
|
@ -324,6 +324,41 @@ class Cookbook extends Base{
|
|||
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||
// }
|
||||
}
|
||||
// 保存每日餐食食物信息
|
||||
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#######################################################################
|
||||
|
|
@ -704,7 +739,37 @@ class Cookbook extends Base{
|
|||
}
|
||||
$weight = bcdiv($data['food_weight'],100,2);
|
||||
$kcal = bcmul($weight,$food_data['kcal'],2);
|
||||
return $this->msg(['kcal'=>$kcal.'kcal']);
|
||||
return $this->msg(['value'=>$kcal,'unit'=>'kcal']);
|
||||
}
|
||||
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($value['kcal'],'datetime')){
|
||||
return $this->msg(10005,'kcal type is error');
|
||||
}
|
||||
}
|
||||
|
||||
$result = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
|
||||
->insert([
|
||||
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue