From d9d7396557d597e846318b30cc86e2fe873c92f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0?= Date: Mon, 22 Dec 2025 01:16:09 +0800 Subject: [PATCH 1/2] 251222 --- application/route.php | 5 + application/test/controller/Xishuju1.php | 116 +++++++++++++++++- .../test/view/xishuju1/xishuju1_qd_page.html | 53 +++++--- 3 files changed, 152 insertions(+), 22 deletions(-) diff --git a/application/route.php b/application/route.php index 3c16c4c..e88e51d 100644 --- a/application/route.php +++ b/application/route.php @@ -888,6 +888,11 @@ Route::any('/xishuju1/next_pass_action', 'test/xishuju1/next_pass_action'); Route::any('/xishuju1/new_step1_action', 'test/xishuju1/new_step1_action'); +Route::any('/xishuju1/new_step2_action', 'test/xishuju1/new_step2_action'); +Route::any('/xishuju1/new_step3_action', 'test/xishuju1/new_step3_action'); + +Route::any('/xishuju1/ceshiyong', 'test/xishuju1/ceshiyong'); + diff --git a/application/test/controller/Xishuju1.php b/application/test/controller/Xishuju1.php index 85980e5..d68e73a 100644 --- a/application/test/controller/Xishuju1.php +++ b/application/test/controller/Xishuju1.php @@ -326,8 +326,12 @@ class Xishuju1 extends Controller{ // 处理食物表数据 $cfc = Db::connect('cfc_db'); // 获取一条数据 - $shicai_data = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where("food_name is null")->order('id')->find(); + $shicai_data = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where("food_name = ''")->order('id')->find(); + if(!$shicai_data){ + return $this->msg(10004,'没了'); + } // dump($shicai_data); + // die; $baidufanyi = new Baidufanyi; $result = $baidufanyi->fanyi_action($shicai_data['food_name_en'], 'en', 'zh'); // dump($result); @@ -335,14 +339,14 @@ class Xishuju1 extends Controller{ // die; // $fanyi_result = ''; if($result['success'] == true){ - $fanyi_result = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where(['id'=>$shicai_data['id']])->update(['food_name'=>$result['data']['trans_result'][0]['dst']]); + $fanyi_result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$shicai_data['id']])->update(['food_name'=>$result['data']['trans_result'][0]['dst']]); if($fanyi_result){ return $this->msg([]); }else{ return $this->msg(10002); } }else{ - return $this->msg(12002); + return $this->msg(10002,'翻译失败'); } } @@ -1397,6 +1401,108 @@ class Xishuju1 extends Controller{ } + public function new_step2_action(){ + $foodCategories = [ + 'Dairy and Egg Products' => 1, + 'Spices and Herbs' => 2, + 'Baby Foods' => 3, + 'Fats and Oils' => 4, + 'Poultry Products' => 5, + 'Soups, Sauces, and Gravies' => 6, + 'Sausages and Luncheon Meats' => 7, + 'Breakfast Cereals' => 8, + 'Fruits and Fruit Juices' => 9, + 'Pork Products' => 10, + 'Vegetables and Vegetable Products' => 11, + 'Nut and Seed Products' => 12, + 'Beef Products' => 13, + 'Beverages' => 14, + 'Finfish and Shellfish Products' => 15, + 'Legumes and Legume Products' => 16, + 'Lamb, Veal, and Game Products' => 17, + 'Baked Products' => 18, + 'Sweets' => 19, + 'Cereal Grains and Pasta' => 20, + 'Fast Foods' => 21, + 'Meals, Entrees, and Side Dishes' => 22, + 'Snacks' => 23, + 'American Indian/Alaska Native Foods' => 24, + 'Restaurant Foods' => 25, + 'Branded Food Products Database' => 26, + 'Quality Control Materials' => 27, + 'Alcoholic Beverages' => 28 + ]; + $cfc = Db::connect('cfc_db'); + $congfu_num = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1') + ->where("status is null") + ->order('id') + ->find(); + if(!$congfu_num){ + return $this->msg(11006,'没了'); + } + if(array_key_exists($congfu_num['two_id'],$foodCategories)){ + $result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['two_id'=>$foodCategories[$congfu_num['two_id']],'status'=>'ok']); + }else{ + $result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['two_id'=>$foodCategories[$congfu_num['two_id']],'status'=>'nothing']); + } + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + public function new_step3_action(){ + $foodCategories = [ + 'Dairy and Egg Products' => 1, + 'Spices and Herbs' => 2, + 'Baby Foods' => 3, + 'Fats and Oils' => 4, + 'Poultry Products' => 5, + 'Soups, Sauces, and Gravies' => 6, + 'Sausages and Luncheon Meats' => 7, + 'Breakfast Cereals' => 8, + 'Fruits and Fruit Juices' => 9, + 'Pork Products' => 10, + 'Vegetables and Vegetable Products' => 11, + 'Nut and Seed Products' => 12, + 'Beef Products' => 13, + 'Beverages' => 14, + 'Finfish and Shellfish Products' => 15, + 'Legumes and Legume Products' => 16, + 'Lamb, Veal, and Game Products' => 17, + 'Baked Products' => 18, + 'Sweets' => 19, + 'Cereal Grains and Pasta' => 20, + 'Fast Foods' => 21, + 'Meals, Entrees, and Side Dishes' => 22, + 'Snacks' => 23, + 'American Indian/Alaska Native Foods' => 24, + 'Restaurant Foods' => 25, + 'Branded Food Products Database' => 26, + 'Quality Control Materials' => 27, + 'Alcoholic Beverages' => 28 + ]; + $cfc = Db::connect('cfc_db'); + $congfu_num = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1') + ->where("Calorie_unit = 'kJ'") + ->order('id') + ->find(); + if(!$congfu_num){ + return $this->msg(11006,'没了'); + } + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + $kcal_val = bcdiv($congfu_num['Calorie_val'],4.184,2); + $result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['Calorie_unit'=>'KCAL','Calorie_val'=>$kcal_val]); + + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } /** @@ -1448,7 +1554,9 @@ class Xishuju1 extends Controller{ ################################################################################################################### ################################################################################################################### ################################################################################################################### - + public function ceshiyong(){ + + } public function msg($data,$str='',$result = []){ if(is_array($data)){ diff --git a/application/test/view/xishuju1/xishuju1_qd_page.html b/application/test/view/xishuju1/xishuju1_qd_page.html index 1e3425d..6b2c756 100644 --- a/application/test/view/xishuju1/xishuju1_qd_page.html +++ b/application/test/view/xishuju1/xishuju1_qd_page.html @@ -112,7 +112,8 @@ + "

处理失败:"+content2+"项

" $('.centent').html(str) setTimeout(() => { - error_action(req.data.id,req.code) + // error_action(req.data.id,req.code) + start_action() }, 100); } }, @@ -158,39 +159,55 @@ function start_action2(){ $.ajax({ - url:"new_step1_action", //请求的url地址 + // url:"new_step1_action", //请求的url地址 + // url:"new_step2_action", //请求的url地址 + url:"new_step3_action", //请求的url地址 dataType:"json", //返回格式为json async:true,//请求是否异步,默认为异步,这也是ajax重要特性 data:{"page":page}, //参数值 type:"POST", //请求方式 success:function(req){ //请求成功时处理 - + // if(req.code == 0){ + // success_num = success_num+req.data.success_num + // fail_num = fail_num+req.data.fail_num + // chongfu_num = chongfu_num+req.data.chongfu_num + // total_num = total_num+req.data.total_num + // str = "

处理成功:"+(success_num)+"项

" + // + "

处理失败:"+(fail_num)+"项

" + // + "

处理重复:"+(chongfu_num)+"项

" + // + "

总计处理:"+(total_num)+"项

" + // $('.centent').html(str) + // page = page+1 + // setTimeout(() => { + // start_action2() + // }, 100); + // }else if(req.code == 10006){ + // $('.centent').append('

处理完成!

'); + // }else{ + // setTimeout(() => { + // start_action2() + // }, 100); + // } if(req.code == 0){ - success_num = success_num+req.data.success_num - fail_num = fail_num+req.data.fail_num - chongfu_num = chongfu_num+req.data.chongfu_num - total_num = total_num+req.data.total_num - // console.log(success_num) - // console.log(chongfu_num) - // console.log(fail_num) - // console.log(total_num) + success_num = success_num+1 + total_num = total_num+1 str = "

处理成功:"+(success_num)+"项

" + "

处理失败:"+(fail_num)+"项

" - + "

处理重复:"+(chongfu_num)+"项

" + "

总计处理:"+(total_num)+"项

" $('.centent').html(str) - page = page+1 setTimeout(() => { start_action2() }, 100); - }else if(req.code == 10006){ + }else if(req.code == 11006){ $('.centent').append('

处理完成!

'); - // $('.centent').html(str) - // setTimeout(() => { - // error_action(req.data.id,req.code) - // }, 100); }else{ + total_num = total_num+1 + fail_num = fail_num+1 + str = "

处理成功:"+(success_num)+"项

" + + "

处理失败:"+(fail_num)+"项

" + + "

总计处理:"+(total_num)+"项

" + $('.centent').html(str) setTimeout(() => { start_action2() }, 100); From 1b986d17b5c341179747610cf6c72b58e7672548 Mon Sep 17 00:00:00 2001 From: tiansf Date: Mon, 22 Dec 2025 03:58:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=B7=E5=A4=96=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KitchenScale3/controller/admin/Base.php | 172 ++ .../controller/admin/Cookbook.php | 178 ++ .../KitchenScale3/controller/admin/Index.php | 30 + .../KitchenScale3/controller/admin/Login.php | 40 + .../KitchenScale3/controller/app/Base.php | 548 ++++++ .../KitchenScale3/controller/app/Cookbook.php | 1284 ++++++++++++++ .../controller/app/Countfood.php | 1576 +++++++++++++++++ .../controller/app/Guessyoulike.php | 418 +++++ .../KitchenScale3/controller/app/Index.php | 898 ++++++++++ .../KitchenScale3/controller/app/Language.php | 240 +++ .../KitchenScale3/controller/app/Login.php | 705 ++++++++ .../KitchenScale3/controller/app/Product.php | 75 + .../controller/app/Usercenter.php | 892 ++++++++++ .../KitchenScale3/controller/app/Wechat.php | 121 ++ .../view/admin/base/pic_index.html | 209 +++ .../view/admin/cookbook/add_cookbook.html | 420 +++++ .../view/admin/cookbook/card_edit.html | 232 +++ .../view/admin/cookbook/index.html | 288 +++ .../KitchenScale3/view/admin/index/index.html | 230 +++ .../view/admin/index/welcome.html | 219 +++ .../KitchenScale3/view/admin/login/login.html | 77 + .../app/usercenter/business_cooperation.html | 398 +++++ application/route.php | 94 +- 23 files changed, 9342 insertions(+), 2 deletions(-) create mode 100644 application/KitchenScale3/controller/admin/Base.php create mode 100644 application/KitchenScale3/controller/admin/Cookbook.php create mode 100644 application/KitchenScale3/controller/admin/Index.php create mode 100644 application/KitchenScale3/controller/admin/Login.php create mode 100644 application/KitchenScale3/controller/app/Base.php create mode 100644 application/KitchenScale3/controller/app/Cookbook.php create mode 100644 application/KitchenScale3/controller/app/Countfood.php create mode 100644 application/KitchenScale3/controller/app/Guessyoulike.php create mode 100644 application/KitchenScale3/controller/app/Index.php create mode 100644 application/KitchenScale3/controller/app/Language.php create mode 100644 application/KitchenScale3/controller/app/Login.php create mode 100644 application/KitchenScale3/controller/app/Product.php create mode 100644 application/KitchenScale3/controller/app/Usercenter.php create mode 100644 application/KitchenScale3/controller/app/Wechat.php create mode 100644 application/KitchenScale3/view/admin/base/pic_index.html create mode 100644 application/KitchenScale3/view/admin/cookbook/add_cookbook.html create mode 100644 application/KitchenScale3/view/admin/cookbook/card_edit.html create mode 100644 application/KitchenScale3/view/admin/cookbook/index.html create mode 100644 application/KitchenScale3/view/admin/index/index.html create mode 100644 application/KitchenScale3/view/admin/index/welcome.html create mode 100644 application/KitchenScale3/view/admin/login/login.html create mode 100644 application/KitchenScale3/view/app/usercenter/business_cooperation.html diff --git a/application/KitchenScale3/controller/admin/Base.php b/application/KitchenScale3/controller/admin/Base.php new file mode 100644 index 0000000..38be76b --- /dev/null +++ b/application/KitchenScale3/controller/admin/Base.php @@ -0,0 +1,172 @@ +'test_app_data_log', + ]; + protected $return_data_all = [ + '10001'=>'关键参数缺失', + '10002'=>'操作失败', + '10003'=>'信息核实错误', + '10004'=>'未找到有效数据', + '10005'=>'参数格式错误', + '10006'=>'参数不能为空', + '10007'=>'参数错误', + '10008'=>'', + '10009'=>'', + '10010'=>'自定义信息', + '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', + ]; + protected $file_max = 1024*1024*2;//xxxMB + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + + + // 验证 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + // 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致 + if ($dateTime && $dateTime->format($format) === $data) { + return true; + } + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + } + + ####################################################图片选择上传start############################################################## + public function pic_index($page = 1) { + $data = input(); + $pd = true; + if(array_key_exists('page',$data)){ + $page = $data['page']; + $pd = false; + } + $cfc = Db::connect('cfc_db'); + $num = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->count(); + $result = $cfc->table('app_user_upload_img')->where(['special_record_str'=>'admin'])->order('id desc')->page($page,20)->field('id,pic_url')->select(); + if(!$pd){ + $return_result['num'] = $num; + $return_result['result'] = $result; + return $this->msg(0,'success',$return_result); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + } + public function pic_upload_action(){ + + $save_data = []; + $error_data = []; + // 获取表单上传文件 + $files = request()->file('image'); + foreach($files as $file){ + $name = $file->getInfo()['name']; + // 使用 pathinfo() 函数获取文件名的扩展名 + $pathinfo = pathinfo($name); + $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较 + $file_name = $pathinfo['filename']; + // 判断扩展名是否不是 .png 或 .gif + if ($extension !== 'png' && $extension !== 'gif') { + // 修改文件名,将扩展名改为 .jpg + $new_filename = date('YmdHis').$file_name . '.jpg'; + } else { + $new_filename = date('YmdHis').$name; + } + $info = $file->validate(['size'=>$this->file_max,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload',$new_filename); + if($info){ + array_push($save_data,[ + 'user_token'=>'caadd1be045a65f30b92aa805f1de54a', + 'pic_name'=>$new_filename, + 'pic_url'=>'https://tc.pcxbc.com/kitchenscale_all/user_upload/'.$new_filename, + 'create_time'=>date('Y-m-d H:i:s'), + 'special_record_str'=>'admin', + 'operate_log'=>1 + ]); + }else{ + array_push($error_data,[ + 'pic_name'=>$name, + 'error_msg'=>$file->getError(), + ]); + } + } + $cfc = Db::connect('cfc_db'); + $pic_result = $cfc->table('app_user_upload_img')->insertAll ($save_data); + if($pic_result){ + return $this->msg(['success'=>count($save_data),'error_data'=>$error_data]); + }else{ + for ($i=0; $i < count($save_data); $i++) { + unlink(ROOT_PATH . 'public' . DS . 'kitchenscale_all' . DS . 'user_upload' . DS . $new_filename); + } + return $this->msg(10002,'图片数据保存失败'); + } + } + + ####################################################图片选择上传end############################################################## + + + public function msg($data,$str='',$result = []){ + if(is_array($data)){ + if($str != ''){ + return json(['code'=>0,'msg'=>$str,'data'=>$data]); + }else{ + return json(['code'=>0,'msg'=>'操作成功','data'=>$data]); + } + }else{ + if($str != ''){ + return json(['code'=>$data,'msg'=>$str,'data'=>$result]); + } + return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]); + } + } + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/admin/Cookbook.php b/application/KitchenScale3/controller/admin/Cookbook.php new file mode 100644 index 0000000..48589cd --- /dev/null +++ b/application/KitchenScale3/controller/admin/Cookbook.php @@ -0,0 +1,178 @@ +=',$data['s_time']]; + // } + // if($data['e_time']){ + // $parameter['create_time'] = ['<=',$data['e_time']]; + // } + } + $where = '1=1'; + $cfc = Db::connect('cfc_db'); + $num = $cfc->table('app_user_cookbook')->where($parameter)->count(); + $sql = " + SELECT + a.id, + a.title, + a.create_user_nickname, + a.likes_num, + a.read_it, + a.is_del, + a.create_time, + b.pic_url + FROM + app_user_cookbook a + LEFT JOIN + app_user_upload_img b ON a.cover = b.id + WHERE + $where + ORDER BY + a.id DESC + OFFSET (".($page - 1)." * ".$this->page_num.") ROWS + FETCH NEXT ".$this->page_num." ROWS ONLY; + "; + $result = $cfc->query($sql); + + if(!$pd){ + $return_data['num'] = $num; + $return_data['data'] = $result; + return $this->msg($return_data); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + + } + + public function add_cookbook(){ + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_user_cookbook_label')->where(['is_del'=>0])->select(); + $this->assign([ + 'result' => $result, + ]); + return $this->fetch(); + } + + public function add_cookbook_action(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + // dump($data); + // 处理食谱数据 + $id_list = []; + $food_cookbook_relationship = []; + foreach ($data['foodList'] as $key => $value) { + if(!in_array($value['id'],$id_list)){ + array_push($id_list,$value['id']); + array_push($food_cookbook_relationship,[ + 'cookbook_id' => '', + 'food_id' => $value['id'] + ]); + } + } + $kcal_data = $cfc->table('app_z_national_standard_food_type_3')->where("id in (".implode(',',$id_list).")")->field('id,Calorie_val')->select(); + for ($i=0; $i < count($kcal_data); $i++) { + $id_list[$kcal_data[$i]['id']] = $kcal_data[$i]['Calorie_val']; + } + foreach ($data['foodList'] as $key => $value) { + $data['foodList'][$key]['kcal'] = bcmul(bcdiv($value['weight'],100,20),$id_list[$value['id']],2); + $data['foodList'][$key]['unit'] = 'g'; + } + + // 设置食谱信息 + $cookbook_data = [ + 'title'=>$data['title'], + 'cover'=>$data['cover'], + 'create_user_token'=>'caadd1be045a65f30b92aa805f1de54a', + 'create_user_head_pic'=>'https://tc.pcxbc.com/tsf/head_pic.png', + 'create_user_nickname'=>'clown', + 'describe_data'=>$data['description'], + 'food_data'=>json_encode($data['foodList']), + 'step_data'=>json_encode($data['stepList']), + 'create_time'=>date('Y-m-d H:i:s'), + 'original_cookbook_id'=>'admin', + 'cook_label'=>$data['cook_label'], + 'is_del'=>1, + + ]; + + $cfc->startTrans(); + try { + + $cookbook_id = $cfc->table('app_user_cookbook')->insertGetId($cookbook_data); + for ($i=0; $i < count($food_cookbook_relationship); $i++) { + $food_cookbook_relationship[$i]['cookbook_id'] = $cookbook_id; + } + $cfc->table('app_user_cookbook_food_relation')->insertAll($food_cookbook_relationship); + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + $cfc->rollback(); + return $this->msg(10002,'数据保存失败,'.$e->getMessage()); + } + + } + + public function stop_and_run(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_user_cookbook')->where(['id'=>$data['id']])->update(['is_del'=>$data['status']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + + + + public function find_food_list(){ + $data = input(); + $cfc = Db::connect('cfc_db'); + $result = $cfc->table('app_z_national_standard_food_type_3')->where("food_name like '%". $data['search_data'] ."%'")->field('id,food_name,Calorie_val')->select(); + return $this->msg(0,'success',$result); + } + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/admin/Index.php b/application/KitchenScale3/controller/admin/Index.php new file mode 100644 index 0000000..f06f5e1 --- /dev/null +++ b/application/KitchenScale3/controller/admin/Index.php @@ -0,0 +1,30 @@ +assign('domain',$a); + return $this->fetch(); + } + + public function welcome(){ + // $this->assign('domain',$a); + return $this->fetch(); + } + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/admin/Login.php b/application/KitchenScale3/controller/admin/Login.php new file mode 100644 index 0000000..2f0eddf --- /dev/null +++ b/application/KitchenScale3/controller/admin/Login.php @@ -0,0 +1,40 @@ +fetch(); + + } + // 检测登录信息是否超时 + public function login_action(){ + $data = input(); + // 验证数据项是否完整 + if(!array_key_exists('username', $data) || !array_key_exists('password', $data)){ + return $this->msg(10001); + } + $cfc = Db::connect('cfc_db'); + $account = $cfc->table('admin_user_account_number')->where(['account_num'=>$data['username'],'password'=>$data['password']])->count(); + if($account>0){ + return $this->msg([]); + }else{ + return $this->msg(10003); + } + } + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Base.php b/application/KitchenScale3/controller/app/Base.php new file mode 100644 index 0000000..dd18ab9 --- /dev/null +++ b/application/KitchenScale3/controller/app/Base.php @@ -0,0 +1,548 @@ +'app_user_search_history_multilingual', + 'foodlist4'=>'app_z_national_standard_food_type_4_multilingual', + 'user'=>'app_user_data_multilingual' + ]; + protected $token_time = 30;//30天的秒数 + protected $file_size = 5*1024*1024; + protected $return_data_all = [ + '10001'=>'关键参数缺失', + '10002'=>'操作失败', + '10003'=>'信息核实错误', + '10004'=>'未找到有效数据', + '10005'=>'参数格式错误', + '10006'=>'参数不能为空', + '10007'=>'参数错误', + '10008'=>'', + '10009'=>'', + '10010'=>'自定义信息', + '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', + ]; + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口监控################################################################ + ################################################################接口监控################################################################ + ################################################################接口监控################################################################ + // 接口记录 + public function record_api_log($params, $error = null, $response = null){ + // dump($params); + // dump($error); + // die; + $logContent = "接口请求参数:" . json_encode($params, JSON_UNESCAPED_UNICODE) . PHP_EOL; + if ($error) { + $logContent .= "错误信息:" . $error['all_content'] . PHP_EOL; + if(!cache($error['flie']."_".$error['line'])){ + cache($error['flie']."_".$error['line'],"API错误",3600); + $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'厨房秤(海外)(后台)','content'=>$logContent]); + } + } + if ($response) { + $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL; + } + // 使用ThinkPHP的日志记录方法 + Log::record($logContent, 'api_log'); + } + + + + /* 接口说明(发邮件) + * $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......] + * $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123'] + * $annex(附件路径信息) 字符串 + */ + public function send_email_api_error($address,$content,$annex=''){ + // $ad = '460834639@qq.com'; + $ad1 = '295155911@qq.com'; + $mail = new PHPMailer(); //实例化 + $mail->IsSMTP(); // 启用SMTP + $mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子 + $mail->Port = 465; //邮件发送端口 + $mail->SMTPAuth = true; //启用SMTP认证 + $mail->SMTPSecure = 'ssl'; + $mail->CharSet = "UTF-8"; //字符集 + $mail->Encoding = "base64"; //编码方式 + $mail->Username = "tsf3920322@126.com"; //你的邮箱 + $mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码) + $mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱) + + // $mail->Subject = "微盟测试邮件"; //邮件标题 + $mail->Subject = $content['title']; //邮件标题 + + // $mail->FromName = "微盟体测中心"; //发件人姓名 + $mail->FromName = $content['from_user_name']; //发件人姓名 + + + for ($i=0; $i < count($address); $i++) { + $mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称) + } + + if($annex != ''){ + // $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg'; + $mail->AddAttachment($annex,''); // 添加附件,并指定名称 + } + + $mail->IsHTML(true); //支持html格式内容 + + $neirong = $content['content']; + + $mail->Body = $neirong; //邮件主体内容 + //发送 + if (!$mail->Send()) { + + return ['code' => 10003,'msg'=>$mail->ErrorInfo]; + // return $mail->ErrorInfo; + } else { + return ['code' => 0]; + // return 'success'; + } + } + + ################################################################通用工具################################################################ + ################################################################通用工具################################################################ + ################################################################通用工具################################################################ + + // 验证验证码是否有效 + 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 + + if(is_string($token)){ + $length = strlen($token); + if ($length < 10 ) { + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,字符串长度小于10', 'token_log'); + return false; + } + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log'); + return false; + } + $cfc = Db::connect('cfc_db'); + $user_login = $cfc->table($this->base_use_db_name['user'])->where(['token'=>$token])->field('id,login_time')->find(); + if(!$user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log'); + return false; + } + // 创建 DateTime 对象来表示指定的日期和时间 + $specifiedDateTime = new \DateTime($user_login['login_time']); + + // 获取当前时间的 DateTime 对象 + $currentDateTime = new \DateTime(); + + // 计算两个日期之间的差异(以秒为单位) + $interval = $currentDateTime->diff($specifiedDateTime); + + // 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等) + $daysDifference = $interval->days; + + // 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式: + // $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s'); + // $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整 + + // 判断差异是否超过指定的天数 + if ($daysDifference > $this->token_time) { + // echo "超过 {$specifiedDays} 天"; + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log'); + return false; + } else { + // echo "未超过 {$specifiedDays} 天"; + $user_login = $cfc->table($this->base_use_db_name['user'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]); + if($user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log'); + return true; + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log'); + return true; + } + + } + } + // 验证数据类型 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + // dump($data); + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + // 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致 + if ($dateTime && $dateTime->format($format) === $data) { + return true; + } + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + } + // 计算年龄 + public function calculate_age($data = '1991-04-20'){ + $today = time(); // 获取当前时间的 Unix 时间戳 + $birthDate = strtotime($data); // 将出生日期字符串转换为 Unix 时间戳 + if ($birthDate !== false) { + $age = date('Y', $today) - date('Y', $birthDate); + // 如果当前年份的月份和日期小于出生年份的月份和日期,那么年龄减一 + if (date('m-d', $today) < date('m-d', $birthDate)) { + $age--; + } + return $age; + } else { + return false; + } + } + // 计算常规卡路里 + public function count_user_nutrition_all($data){ + // 计算基础代谢率(BMR) + if($data['gender'] == 1){ + // 男性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) + 5 + $bmr = bcmul(10,$data['weight'],20); + $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20); + $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20); + $bmr = bcadd($bmr,5,2); + }else if($data['gender'] == 2){ + // 女性:BMR = 10 × 体重(kg) + 6.25 × 身高(cm) - 5 × 年龄(岁) - 161 + $bmr = bcmul(10,$data['weight'],20); + $bmr = bcadd($bmr,bcmul(6.25,$data['height'],20),20); + $bmr = bcsub($bmr,bcmul(5,$data['age_num'],20),20); + $bmr = bcsub($bmr,161,2); + }else{ + return $this->msg(10003,'性别未知'); + } + + // 每日总能量消耗(TDEE) + // 久坐(很少或没有运动):BMR × 1.2 + // 轻度活动(每周1-3天轻度运动):BMR × 1.375 + // 中度活动(每周3-5天中度运动):BMR × 1.55 + // 高度活动(每周6-7天高强度运动):BMR × 1.725 + // 极高活动(体力劳动或每天高强度训练):BMR × 1.9 + 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% + // 脂肪:通常占总热量的20-35% + // 孩子&成年人:碳水化合物50%,蛋白质20%,脂肪30%。 + // 老人:碳水化合物50%,蛋白质25%,脂肪25%。 + // 建议每日摄入量计算: + // 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,'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; + } + + // 计算营养物质 + 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->base_use_db_name['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++) { + $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', + 'color' => '', + 'value' => $data[$i]['kcal_val'], + 'proportion' => 0, + ]; + $data[$i]['nutrients_four'][] = [ + 'name' => '蛋白质', + 'unit' => 'g', + 'color' => '#5180D8', + 'value' => $data[$i]['protein_val'], + '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' => $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' => $zong_all == 0?0:bcmul(bcdiv($data[$i]['carbohydrate_val'],$zong_all,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; + } + + + + public function add_search_history_action($data){ + // 添加一条搜索记录start + $cfc = Db::connect('cfc_db'); + $insert_search_log = $cfc->table($this->base_use_db_name['search_history'])->where(['user_id'=>$data['id'],'keyword'=>$data['search_data'],'type'=>$data['type']])->field('id,search_count')->find(); + if($insert_search_log){ + $cfc->table($this->base_use_db_name['search_history'])->where(['id'=>$insert_search_log['id']])->update([ + 'search_count'=>$insert_search_log['search_count']+1, + 'last_searched_at'=>date('Y-m-d H:i:s'), + ]); + }else{ + $cfc->table($this->base_use_db_name['search_history'])->insert([ + 'user_id'=>$data['id'], + 'keyword'=>$data['search_data'], + 'type'=>$data['type'], + ]); + } + // 添加一条搜索记录end + } + ####################################################图片选择上传start############################################################## + ####################################################图片选择上传start############################################################## + ####################################################图片选择上传start############################################################## + + + ####################################################图片选择上传end############################################################## + ####################################################图片选择上传end############################################################## + ####################################################图片选择上传end############################################################## + + + ########################################################其他工具######################################################## + ########################################################其他工具######################################################## + ########################################################其他工具######################################################## + public function msg($data,$str='',$result = []){ + if(is_array($data)){ + if($str != ''){ + return json(['code'=>0,'msg'=>$str,'data'=>$data]); + }else{ + return json(['code'=>0,'msg'=>'操作成功','data'=>$data]); + } + }else{ + if($str != ''){ + return json(['code'=>$data,'msg'=>$str,'data'=>$result]); + } + return json(['code'=>$data,'msg'=>$this->return_data_all[$data],'data'=>$result]); + } + } + + public function generateRandomString($length = 10) { + $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; + $charactersLength = strlen($characters); + $randomString = ''; + for ($i = 0; $i < $length; $i++) { + $randomString .= $characters[rand(0, $charactersLength - 1)]; + } + return $randomString; + } + + + public function ceshi(){ + echo 'hello'; + } + + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Cookbook.php b/application/KitchenScale3/controller/app/Cookbook.php new file mode 100644 index 0000000..e15dcb9 --- /dev/null +++ b/application/KitchenScale3/controller/app/Cookbook.php @@ -0,0 +1,1284 @@ +'app_account_number',//账号表 + // 'juese'=>'app_user_data',//角色表 + ]; + protected $kitchenscale_db_msg = [ + // 'cookbook'=>'app_user_cookbook',//菜谱表 + // 'cookbook_food_relation'=>'app_user_cookbook_food_relation',//菜谱表 + // 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表 + // 'uploadimg'=>'app_user_upload_img',//素材表 + // 'followlist'=>'app_user_follow_list',//关注列表 + // 'collect_list'=>'app_user_collect_list',//收藏列表 + 'foodlist1'=>'app_z_national_standard_food_type_1_multilingual',//食材列表3 + 'foodlist2'=>'app_z_national_standard_food_type_2_multilingual',//食材列表3 + 'foodlist3'=>'app_z_national_standard_food_type_3_multilingual',//食材列表3 + 'foodlist4'=>'app_z_national_standard_food_type_4_multilingual',//食材列表3 + // 'nutrition'=>'app_user_cookbook_nutrition',//能量 + // 'vitamin'=>'app_user_cookbook_vitamin',//维生素 + // 'mineral'=>'app_user_cookbook_mineral',//矿物质 + 'user'=>'app_user_data_multilingual',//用户表 + ]; + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 根据菜谱标签查询列表(首页用)(OK) + // public function find_by_cook_label($data=['token'=>'','cook_label'=>4,'page'=>'1']){ + // // 尝试捕获异常 + // try { + // if(count(input('post.')) > 0){ + // $data = input('post.'); + // } + + // if(!array_key_exists('cook_label', $data)){ + // return $this->msg(10001,'cook_label is miss'); + // } + // // if(!array_key_exists('page', $data)){ + // // return $this->msg(10001,'page is miss'); + // // } + + // if(!$this->verify_data_is_ok($data['cook_label'],'intnum')){ + // return $this->msg(10005,'cook_label type is error'); + // } + // // if(!$this->verify_data_is_ok($data['page'],'intnum')){ + // // return $this->msg(10005,'page type is error'); + // // } + // $return_data = $this->find_by_cook_label_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' => '系统错误']); + // } + // } + // 根据食材详细查找列表(OK) + // public function find_by_food($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_name'=>"2724,2670",'page'=>'1']){ + // // 尝试捕获异常 + // 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_name', $data)){ + // return $this->msg(10001,'food_name is miss'); + // } + // // if(!array_key_exists('page', $data)){ + // // return $this->msg(10001,'page 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['food_name'],'str')){ + // return $this->msg(10005,'tofood_nameken type is error'); + // } + // // if(!$this->verify_data_is_ok($data['page'],'intnum')){ + // // return $this->msg(10005,'page type is error'); + // // } + // $return_data = $this->find_by_food_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' => '系统错误']); + // } + // } + // 查询食谱的详情(OK) + // public function cookbook_details($data=['token'=>'','cookbook_id'=>'3594']){ + // // 尝试捕获异常 + // try { + // if(count(input('post.')) > 0){ + // $data = input('post.'); + // } + // if(!array_key_exists('cookbook_id', $data)){ + // return $this->msg(10001,'cookbook_id is miss'); + // } + // if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){ + // return $this->msg(10005,'cookbook_id type is error'); + // } + // $return_data = $this->cookbook_details_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' => '系统错误']); + // } + // } + // 关注行为(OK) + // public function cookbook_follow($data=['token'=>'caadd1be045a65f3','being_followed'=>'caadd1be045a65f30b92aa805f1de54a']){ + // // 尝试捕获异常 + // 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('being_followed', $data)){ + // return $this->msg(10001,'cookbook_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['being_followed'],'str')){ + // return $this->msg(10005,'cookbook_id type is error'); + // } + // $return_data = $this->cookbook_follow_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' => '系统错误']); + // } + // } + // 点赞收藏菜谱(OK) + // public function cookbook_like($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12']){ + // // 尝试捕获异常 + // 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('cookbook_id', $data)){ + // return $this->msg(10001,'cookbook_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['cookbook_id'],'intnum')){ + // return $this->msg(10005,'cookbook_id type is error'); + // } + // $return_data = $this->cookbook_like_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' => '系统错误']); + // } + // } + // 计算当前食材重量的卡路里(OK) + // public function food_count_kcal($data=['food_name'=>'鸡肉','food_weight'=>456.37]){ + // // 尝试捕获异常 + // try { + // if(count(input('post.')) > 0){ + // $data = input('post.'); + // } + // if(!array_key_exists('food_name', $data)){ + // return $this->msg(10001,'food_name is miss'); + // } + // if(!array_key_exists('food_weight', $data)){ + // return $this->msg(10001,'food_weight is miss'); + // } + // if(!$this->verify_data_is_ok($data['food_name'],'str')){ + // return $this->msg(10005,'food_name type is error'); + // } + // if(!$this->verify_data_is_ok($data['food_weight'],'num')){ + // return $this->msg(10005,'food_weight type is error'); + // } + + // $return_data = $this->food_count_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' => '系统错误']); + // } + // } + // 食材列表查询接口(OK) + public function find_food($data=['food_name'=>'鸡肉']){ + // 尝试捕获异常 + try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('food_name', $data)){ + return $this->msg(10001,'food_name is miss'); + } + if(!$this->verify_data_is_ok($data['food_name'],'str')){ + return $this->msg(10005,'food_name type is error'); + } + + $return_data = $this->find_food_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 get_food_list(){ + // 尝试捕获异常 + // try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // if(!array_key_exists('food_level2_id', $data)){ + // return $this->msg(10001,'food_level2_id is miss'); + // } + // if(!array_key_exists('page', $data)){ + // return $this->msg(10001,'page is miss'); + // } + // if(!$this->verify_data_is_ok($data['food_level2_id'],'intnum')){ + // return $this->msg(10005,'food_level2_id type is error'); + // } + // if(!$this->verify_data_is_ok($data['page'],'intnum')){ + // return $this->msg(10005,'page type is error'); + // } + + $return_data = $this->get_food_list_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' => '系统错误']); + // } + } + // 获取所有食谱label + // public function get_cookbook_label_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // // 尝试捕获异常 + // try { + // if(count(input('post.')) > 0){ + // $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'); + // } + + // $return_data = $this->get_cookbook_label_list_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 get_search_food_page_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // 尝试捕获异常 + try { + if(count(input('post.')) > 0){ + $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'); + } + + $return_data = $this->get_search_food_page_list_action($data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + // 记录日志 + $this->record_api_log($data, $logContent, null); + return json(['status' => 'error', 'message' => '系统错误']); + } + } + + + + + + #######################################################################action####################################################################### + #######################################################################action####################################################################### + #######################################################################action####################################################################### + + + + // public function find_by_cook_label_action($data){ + + // $page_now = array_key_exists('page',$data)?$data['page']:1; + // $page_total = $page_now; + // $page_num = 20; + // $cook_label = $data['cook_label']; + + // $cfc = Db::connect('cfc_db'); + // $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // ->where(['cook_label'=>$cook_label,'is_del'=>0]) + // ->count(); + + // $page_total = ceil($content_num/$page_num); + // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // ->alias('a') + // ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT') + // ->where(['a.cook_label'=>$cook_label,'a.is_del'=>0]) + // ->field('a.id,a.title,b.pic_url as cover,a.create_user_head_pic,a.create_user_nickname,a.likes_num') + // // ->order('id DESC') + // ->page("$page_now,$page_num") + // ->select(); + + // if(array_key_exists('token',$data)){ + // if($data['token'] != ''){ + // // 获取账号下信息以及用户信息 + // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + // if(!$user_data){ + // return $this->msg(20001,'账号信息错误'); + // } + // // 获取用户收藏列表 + // $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list']) + // ->where(['token'=>$data['token'],'is_del'=>0]) + // ->column('cookbook_id'); + // // dump($my_collect_list); + // // 处理菜谱收藏信息 + // foreach ($content_list as $key => $value) { + // // if(in_array($value['id'],$my_collect_list)){ + // if(array_key_exists($value['id'],$my_collect_list)){ + // $content_list[$key]['is_me_like_it'] = 'yes'; + // }else{ + // $content_list[$key]['is_me_like_it'] = 'no'; + // } + // if($value['cover'] == null){ + // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + // unset($content_list[$key]['ROW_NUMBER']); + // } + // }else{ + // foreach ($content_list as $key => $value) { + // $content_list[$key]['is_me_like_it'] = 'no'; + // if($value['cover'] == null){ + // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + // unset($content_list[$key]['ROW_NUMBER']); + // } + // } + // }else{ + // foreach ($content_list as $key => $value) { + // $content_list[$key]['is_me_like_it'] = 'no'; + // if($value['cover'] == null){ + // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + // unset($content_list[$key]['ROW_NUMBER']); + // } + // } + // // dump($content_list); + // // die; + // return $this->msg([ + // 'page_now'=>$page_now, + // 'page_total'=>$page_total, + // 'content_list'=>$content_list + // ]); + // } + // public function find_by_food_action($data){ + + + // // 获取账号下信息以及用户信息 + // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + // if(!$user_data){ + // return $this->msg(20001,'账号信息错误'); + // } + + // $page_now = array_key_exists('page',$data)?$data['page']:1; + // $page_total = $page_now; + // $page_num = 20; + // $food_name = $data['food_name']; + + // $cfc = Db::connect('cfc_db'); + + // // $food_name = implode(',',$food_name); + // // dump($food_name); + // // die; + + // $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation']) + // ->where("food_id in ($food_name)") + // ->group('cookbook_id') + // ->field('count(distinct cookbook_id) as count') // 显式指定列名 + // ->select(); // 然后获取结果 + // // dump($content_num); + // $page_total = ceil(count($content_num)/$page_num); + + // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook_food_relation']) + // ->alias('a') + // ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT') + // ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT') + // ->where("a.food_id in ($food_name)") + // ->field('b.id,b.title,c.pic_url as cover,b.create_user_head_pic,b.create_user_nickname,b.likes_num') + // ->group('b.id,b.title,c.pic_url,b.create_user_head_pic,b.create_user_nickname,b.likes_num') + // ->page("$page_now,$page_num") + // ->select(); + + // // dump($food_name); + // // dump($content_num); + // // dump($page_total); + // // dump($content_list); + // // die; + + // // $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // // ->where("food_type like '%$food_name%'") + // // ->count(); + // // $page_total = ceil($content_num/$page_num); + + // // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // // ->alias('cookbook') + // // ->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT') + // // ->where("cookbook.food_type like '%$food_name%'") + // // ->field('cookbook.id,cookbook.title,uploadimg.pic_url as cover,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num') + // // ->page("$page_now,$page_num") + // // ->select(); + + // // 获取用户收藏列表 + // $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list']) + // ->where(['token'=>$data['token']]) + // ->column('cookbook_id'); + // // dump($my_collect_list); + // // 处理菜谱收藏信息 + // foreach ($content_list as $key => $value) { + // // if(in_array($value['id'],$my_collect_list)){ + // if(array_key_exists($value['id'],$my_collect_list)){ + // $content_list[$key]['is_me_like_it'] = 'yes'; + // }else{ + // $content_list[$key]['is_me_like_it'] = 'no'; + // } + // if($value['cover'] == null){ + // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + // unset($content_list[$key]['ROW_NUMBER']); + // } + + // return $this->msg([ + // 'page_now'=>$page_now, + // 'page_total'=>$page_total, + // 'content_list'=>$content_list + // ]); + // } + // public function cookbook_details_action($data){ + + // $cfc = Db::connect('cfc_db'); + // $img_arr = []; + // // 查询菜谱详情 + // $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->find(); + // if(!$cookbook_data){ + // return $this->msg(10004,'菜谱不存在'); + // } + // $cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true); + // $cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true); + // // $cookbook_data['food_type'] = explode(',',$cookbook_data['food_type']); + // $cookbook_data_step_data_count = count($cookbook_data['step_data']); + // // 设置需要的图片id + // array_push($img_arr, $cookbook_data['cover']); + + // foreach ($cookbook_data['step_data'] as $key => $value) { + // if(count($value['pic_list']) > 0){ + // foreach ($value['pic_list'] as $k => $v) { + // if(!in_array($v, $img_arr)){ + // array_push($img_arr, $v); + // } + // } + // } + // } + // // dump($cookbook_data); + // // die; + // $img_arr = implode(',',$img_arr); + // // 查找需要的图片 + // $img_arr_data = $cfc->table($this->kitchenscale_db_msg['uploadimg'])->where("id in ($img_arr) AND is_del = 0")->field('id,pic_name,pic_url')->select(); + // $cookbook_img_data = []; + // // 处理菜谱图片 + // foreach ($img_arr_data as $key => $value) { + // $cookbook_img_data[$value['id']] = $value['pic_url']; + // } + + // // 设置菜谱图片 + // foreach ($cookbook_data['step_data'] as $key => $value) { + // $cookbook_data['step_data'][$key]['step_num'] = "步骤".($key+1).'/'.$cookbook_data_step_data_count; + // $cookbook_data['step_data'][$key]['pic_url_list'] = []; + // foreach ($value['pic_list'] as $k => $v) { + // if(array_key_exists($v, $cookbook_img_data)){ + // array_push($cookbook_data['step_data'][$key]['pic_url_list'],$cookbook_img_data[$v]); + // }else{ + // array_push($cookbook_data['step_data'][$key]['pic_url_list'],'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'); + // } + // } + // } + + // // $cookbook_data['cover_id'] = $cookbook_data['cover']; + // if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){ + // $cookbook_data['cover_pic_url'] = $cookbook_img_data[$cookbook_data['cover']]; + + // }else{ + // $cookbook_data['cover_pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + + + // if(array_key_exists($cookbook_data['cover'], $cookbook_img_data)){ + // if($data['token'] != ''){ + // // 获取账号下信息以及用户信息 + // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + // if(!$user_data){ + // return $this->msg(20001,'账号信息错误'); + // } + // $collect_data = $cfc->table($this->kitchenscale_db_msg['collect_list']) + // ->where([ + // 'token'=>$data['token'], + // 'cookbook_id'=>$data['cookbook_id'], + // ]) + // ->find(); + // if($collect_data){ + // if($collect_data['is_del'] == 0){ + // // 如果有结果并且没被删过 + // $cookbook_data['collect_status'] = 'yes'; + // }else{ + // // 如果有结果被删过 + // $cookbook_data['collect_status'] = 'no'; + // } + // }else{ + // // 如果没结果 + // $cookbook_data['collect_status'] = 'no'; + // } + // }else{ + // $cookbook_data['collect_status'] = 'no'; + // } + // }else{ + // $cookbook_data['collect_status'] = 'no'; + // } + + // // 处理营养物质 + // $nutrition = $cfc->table($this->kitchenscale_db_msg['nutrition'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select(); + // $vitamin = $cfc->table($this->kitchenscale_db_msg['vitamin'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select(); + // $mineral = $cfc->table($this->kitchenscale_db_msg['mineral'])->where(['cookbook_id'=>$data['cookbook_id']])->field('name_en,name_ch as name,unit,value as weight,nrv')->select(); + + + // $cookbook_data['tags'] = []; + + // array_push($cookbook_data['tags'],[ + // 'title'=>'所需食材', + // 'desc'=>'重量', + // 'list'=>$cookbook_data['food_data'], + // ]); + // if(count($nutrition)>0){ + // array_push($cookbook_data['tags'],[ + // 'title'=>'能量', + // 'desc'=>'含量', + // 'list'=>$nutrition, + // ]); + // }else{ + // array_push($cookbook_data['tags'],[ + // 'title'=>'', + // 'desc'=>'', + // 'list'=>[], + // ]); + // } + // if(count($vitamin)>0){ + // array_push($cookbook_data['tags'],[ + // 'title'=>'维生素', + // 'desc'=>'含量', + // 'list'=>$vitamin, + // ]); + // }else{ + // array_push($cookbook_data['tags'],[ + // 'title'=>'', + // 'desc'=>'', + // 'list'=>[], + // ]); + // } + // if(count($mineral)>0){ + // array_push($cookbook_data['tags'],[ + // 'title'=>'矿物质', + // 'desc'=>'含量', + // 'list'=>$mineral, + // ]); + // }else{ + // array_push($cookbook_data['tags'],[ + // 'title'=>'', + // 'desc'=>'', + // 'list'=>[], + // ]); + // } + + // $cookbook_data['token'] = $cookbook_data['create_user_token']; + // $cookbook_data['description'] = $cookbook_data['describe_data']; + // // $cookbook_data['food_list'] = $cookbook_data['food_data']; + // $cookbook_data['step_list'] = $cookbook_data['step_data']; + // unset($cookbook_data['create_user_token']); + // unset($cookbook_data['describe_data']); + // unset($cookbook_data['food_data']); + // unset($cookbook_data['step_data']); + // unset($cookbook_data['create_time']); + // unset($cookbook_data['food_type']); + // unset($cookbook_data['ROW_NUMBER']); + // unset($cookbook_data['is_del']); + // return $this->msg($cookbook_data); + // } + + // public function cookbook_follow_action($data){ + // // 获取账号下信息以及用户信息 + // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + // if(!$user_data){ + // return $this->msg(20001,'账号信息错误'); + // } + // // dump($data); + // $cfc = Db::connect('cfc_db'); + // // $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find(); + // // if(!$cookbook_data){ + // // return $this->msg(10002,'未找到菜谱'); + // // } + // if($data['token'] == $data['being_followed']){ + // // 如果查询跟作者一致 + // return $this->msg(10003,'不能关注自己'); + // } + // $follow_data = $cfc->table($this->kitchenscale_db_msg['followlist']) + // ->where([ + // 'follow_user_token'=>$data['token'], + // 'being_follow_user_token'=>$data['being_followed'], + // ]) + // ->find(); + // $follow_data_state = 0; + // if($follow_data){ + // if($follow_data['is_del'] == 0){ + // // 如果当前是关注状态 + // $follow_data_state = 1; + // }else{ + // $follow_data_state = 0; + // } + // $follow_result= $cfc->table($this->kitchenscale_db_msg['followlist']) + // ->where(['id'=>$follow_data['id']]) + // ->update(['is_del'=>$follow_data_state]); + // }else{ + // $follow_result = $cfc->table($this->kitchenscale_db_msg['followlist']) + // ->insert([ + // 'follow_user_token'=>$data['token'], + // 'being_follow_user_token'=>$data['being_followed'], + // 'create_time'=>date('Y-m-d H:i:s') + // ]); + // } + // if($follow_result){ + // return $this->msg([]); + // }else{ + // return $this->msg(10002,'操作失败'); + // } + // } + // public function cookbook_like_action($data){ + + // // 获取账号下信息以及用户信息 + // $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + // if(!$user_data){ + // return $this->msg(20001,'账号信息错误'); + // } + + + // $cfc = Db::connect('cfc_db'); + // $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token,likes_num')->find(); + // if(!$cookbook_data){ + // return $this->msg(10004,'未找到菜谱'); + // } + // // return $this->msg(10002,'是这里'); + // // if($data['token'] == $cookbook_data['create_user_token']){ + // // // 如果查询跟作者一致 + // // return $this->msg(10002,'不能收藏自己'); + // // } + // $like_data = $cfc->table($this->kitchenscale_db_msg['collect_list'])->where(['token'=>$data['token'],'cookbook_id'=>$data['cookbook_id']])->find(); + + // $like_data_state = 0; + // if($like_data){ + // if($like_data['is_del'] == 0){ + // // 如果当前是关注状态 + // $like_data_state = 1; + // }else{ + // $like_data_state = 0; + // } + // // 启动事务 + // Db::startTrans(); + // try{ + // $cfc->table($this->kitchenscale_db_msg['collect_list']) + // ->where(['id'=>$like_data['id']]) + // ->update(['is_del'=>$like_data_state]); + // if($like_data_state == 0){ + // $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num'); + // }else{ + // $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setDec('likes_num'); + // } + // // 提交事务 + // Db::commit(); + // if($like_data_state==0){ + // $likes_num = $cookbook_data['likes_num']+1; + // }else{ + // $likes_num = $cookbook_data['likes_num']-1; + // if($likes_num <= 0){ + // $likes_num = 0; + // } + // } + // return $this->msg([ + // 'collect_status'=>$like_data_state==0?'yes':'no', + // 'likes_num'=>$likes_num + // ]); + // } catch (\Exception $e) { + // // 回滚事务 + // Db::rollback(); + // return $this->msg(10002,'操作失败.'); + // } + // }else{ + // // 启动事务 + // Db::startTrans(); + // try{ + // $cfc->table($this->kitchenscale_db_msg['collect_list']) + // ->insert([ + // 'token'=>$data['token'], + // 'cookbook_id'=>$data['cookbook_id'], + // 'create_time'=>date('Y-m-d H:i:s') + // ]); + // $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('likes_num'); + // // 提交事务 + // Db::commit(); + // return $this->msg([ + // 'collect_status'=>"yes", + // 'likes_num'=>$cookbook_data['likes_num']+1 + // ]); + // } catch (\Exception $e) { + // // 回滚事务 + // Db::rollback(); + // return $this->msg(10002,'操作失败'); + // } + // } + // } + public function food_count_kcal_action($data){ + $cfc = Db::connect('cfc_db'); + $food_data = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where(['name'=>$data['food_name']])->field("kcal")->find(); + if(!$food_data){ + return $this->msg(10004,'未登记的食材'); + } + $weight = bcdiv($data['food_weight'],100,2); + $kcal = bcmul($weight,$food_data['kcal'],2); + return $this->msg(['value'=>$kcal,'unit'=>'kcal']); + } + + + + + + + + + + + + + + public function find_food_action($data){ + $cfc = Db::connect('cfc_db'); + $food_data = $cfc->query("select f3.id,f3.food_name as name,f3.pic_url,f3.Calorie_val as kcal,f3.weight_unit as unit,f2.id as up_one_level_id,f1.id as up_two_level_id + from ".$this->kitchenscale_db_msg['foodlist3']." as f3 + LEFT JOIN ".$this->kitchenscale_db_msg['foodlist2']." as f2 + on f3.two_id = f2.id + LEFT JOIN ".$this->kitchenscale_db_msg['foodlist1']." as f1 + on f2.one_id = f1.id + where f3.is_del=0 AND f3.food_name like '%".$data['food_name']."%' + "); + + if(count($food_data)>0){ + for ($i=0; $i < count($food_data); $i++) { + if($food_data[$i]['pic_url'] != ''){ + $food_data[$i]['pic_url'] = 'https://tc.pcxbc.com/kitchenscale_all'.$food_data[$i]['pic_url']; + } + } + return $this->msg($food_data); + }else{ + return $this->msg(10004,'未找到该食材'); + } + } + + + public function get_food_list_action($data){ + + if(!array_key_exists('page',$data)){ + $data['page'] = 1; + }else{ + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + $data['page'] = 1; + } + } + + // $cp_page_num = 15; + // $cfc = Db::connect('cfc_db'); + // $search_sql_str = "is_del = 0"; + // if(!array_key_exists('search_data', $data)){ + // $data['search_data'] = ""; + // $ss = ""; + // }else{ + // if($data['search_data'] === ""){ + // $data['search_data'] = ""; + // $ss = ""; + // }else{ + // $ss = $data['search_data']; + // $data['search_data'] = " AND food_name LIKE '%".str_replace('[', '[[]', $ss)."%'"; + + // } + // } + // $search_sql_str = $search_sql_str.$data['search_data']; + + // $content_num = $cfc->table($this->kitchenscale_db_msg['foodlist3']) + // ->where($search_sql_str) + // ->count(); + // $page_total = ceil($content_num/$cp_page_num); + + // $collect_list = $cfc->table($this->kitchenscale_db_msg['foodlist3']) + // ->where($search_sql_str) + // ->field('id,record_id,food_name as name,pic_url,Calorie_val as kcal,weight_unit as unit') + // ->page($data['page'],$cp_page_num) + // ->select(); + $cp_page_num = 15; + $cfc = Db::connect('cfc_db'); + $search_sql_str = "is_del = 0"; + if(!array_key_exists('search_data', $data)){ + $data['search_data'] = ""; + $ss = ""; + }else{ + if($data['search_data'] === ""){ + $data['search_data'] = ""; + $ss = ""; + }else{ + $ss = $data['search_data']; + $data['search_data'] = " AND food_name LIKE '%".str_replace('[', '[[]', $ss)."%'"; + + } + } + $search_sql_str = $search_sql_str.$data['search_data']; + + // 计算总数 + $count_sql = "SELECT COUNT(*) as total FROM {$this->kitchenscale_db_msg['foodlist3']} WHERE {$search_sql_str}"; + $count_result = $cfc->query($count_sql); + $content_num = $count_result[0]['total'] ?? 0; + $page_total = ceil($content_num/$cp_page_num); + + // 计算分页偏移量 + $page = max(1, intval($data['page'])); + $offset = ($page - 1) * $cp_page_num; + + // SQL Server分页查询 - 使用OFFSET FETCH语法(SQL Server 2012及以上版本) + $sql = "SELECT id, record_id, food_name as name, pic_url, Calorie_val as kcal, weight_unit as unit + FROM {$this->kitchenscale_db_msg['foodlist3']} + WHERE {$search_sql_str} + ORDER BY id + OFFSET {$offset} ROWS + FETCH NEXT {$cp_page_num} ROWS ONLY"; + + // dump($count_sql); + + $collect_list = $cfc->query($sql); + + + if(count($collect_list) > 0){ + $nutrients_list_id = []; + $nutrients_list_temporary = []; + foreach ($collect_list as $key => $value) { + $collect_list[$key]['pic_url'] = "https://tc.pcxbc.com/kitchenscale_all".$collect_list[$key]['pic_url']; + array_push($nutrients_list_id,$collect_list[$key]['record_id']); + $nutrients_list_temporary[$collect_list[$key]['record_id']] = []; + if (!is_numeric($collect_list[$key]['kcal'])) { + $collect_list[$key]['kcal'] = 0; + } + } + + // 处理营养物质 + $nutrients_list_data = $cfc->table($this->kitchenscale_db_msg['foodlist4']) + ->where("father_id in (". implode(',',$nutrients_list_id) .")") + ->field("father_id,name,name_ch,unit,value,type") + ->select(); + + for ($i=0; $i < count($nutrients_list_data); $i++) { + if(!is_numeric($nutrients_list_data[$i]['value']) || $nutrients_list_data[$i]['value'] == 0){ + continue; + }else{ + array_push($nutrients_list_temporary[$nutrients_list_data[$i]['father_id']],[ + 'name'=>$nutrients_list_data[$i]['name'], + 'name_ch'=>$nutrients_list_data[$i]['name_ch'], + 'unit'=>$nutrients_list_data[$i]['unit'], + 'value'=>$nutrients_list_data[$i]['value'], + 'type'=>$nutrients_list_data[$i]['type'], + 'type_name'=>$nutrients_list_data[$i]['type'] == 1?'能量及宏量营养素':($nutrients_list_data[$i]['type'] == 2?'维生素':'矿物质'), + 'color'=>$nutrients_list_data[$i]['type'] == 1?'#C4FFE0':($nutrients_list_data[$i]['type'] == 2?'#FFEFB7':'#7DA8E0') + ]); + } + } + + for ($i=0; $i < count($collect_list); $i++) { + $collect_list[$i]['nutrients_four'] = []; + $collect_list[$i]['nutrients_list'] = []; + $temporary_calculate = 0; + if(array_key_exists($collect_list[$i]['record_id'],$nutrients_list_temporary)){ + $collect_list[$i]['nutrients_list'] = $nutrients_list_temporary[$collect_list[$i]['record_id']]; + foreach ($nutrients_list_temporary[$collect_list[$i]['record_id']] as $key => $value) { + if($value['type'] == 1){ + array_push($collect_list[$i]['nutrients_four'],[ + 'name'=>$value['name'] == 'Carbohydrate'?'碳水':$value['name_ch'], + 'unit'=>$value['unit'], + 'color'=>$value['name'] == 'Carbohydrate'?'#FFB169':($value['name'] == 'Fat'?'#ED7886':($value['name'] == 'Protein'?'#5180D8':'')), + 'value'=>!is_numeric($value['value'])?0:$value['value'], + ]); + // 如果不为卡路里 + if($value['name'] != 'Calorie'){ + $temporary_calculate = $temporary_calculate+$value['value']; + } + } + } + // 处理详情当中的环数据占比 + foreach ($collect_list[$i]['nutrients_four'] as $k => $v) { + if($v['name'] != '卡路里'){ + $collect_list[$i]['nutrients_four'][$k]['proportion'] = bcmul(bcdiv($v['value'],$temporary_calculate,2),100,0); + }else{ + $collect_list[$i]['nutrients_four'][$k]['proportion'] = 0; + } + } + } + } + } + + + // 记录搜索历史 + if(array_key_exists('token',$data) && $data['token'] != '' && $ss != ''){ + $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find(); + if($user_data){ + $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$ss,'type'=>'food']); + } + } + + return $this->msg([ + 'page_now'=>$data['page'], + 'page_total'=>$page_total, + 'content_list'=>$collect_list + ]); + } + // public function get_cookbook_label_list_action(){ + // $cfc = Db::connect('cfc_db'); + // // 获取菜谱分类标签start + // $cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label']) + // ->where("is_del = 0") + // ->field('id,name') + // ->select(); + // $temporary_label = []; + // foreach ($cook_label as $key => $value) { + // unset($cook_label[$key]['ROW_NUMBER']); + // $cook_label[$key]['list'] = []; + // $temporary_label[$value['id']] = $key; + // } + // $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + // ->alias('a') + // ->join($this->kitchenscale_db_msg['uploadimg'].' b','a.cover = b.id','LEFT') + // ->where(['a.is_del'=>0]) + // ->field('a.id,a.cook_label,a.title,b.pic_url as cover') + // ->select(); + // foreach ($content_list as $key => $value) { + // unset($content_list[$key]['ROW_NUMBER']); + // array_push($cook_label[$temporary_label[$value['cook_label']]]['list'],$content_list[$key]); + // } + // return $this->msg($cook_label); + // // 获取菜谱分类标签end + // } + + public function get_search_food_page_list_action($data){ + $cfc = Db::connect('cfc_db'); + // 获取菜谱分类标签start + // 蔬菜类id:4 6 7 + // 肉类id:10 11 14 + $data_list = $cfc->table($this->kitchenscale_db_msg['foodlist3']) + ->where('two_id in (4,6,7,10,11,14) and is_popular = 1') + ->field('id,food_name,two_id') + ->select(); + $result = [ + 'food'=>[ + 'title'=>'流行食材', + 'list'=>[ + [ + 'title'=>'蔬菜', + 'list'=>[] + ], + [ + 'title'=>'肉类', + 'list'=>[] + ], + ] + ], + 'log'=>[], + ]; + foreach ($data_list as $key => $value) { + if($value['two_id'] == 4 || $value['two_id'] == 6 || $value['two_id'] == 7){ + array_push($result['food']['list'][0]['list'],['id'=>$value['id'],'name'=>$value['food_name']]); + }else if($value['two_id'] == 10 || $value['two_id'] == 11 || $value['two_id'] == 14){ + array_push($result['food']['list'][1]['list'],['id'=>$value['id'],'name'=>$value['food_name']]); + } + } + + return $this->msg($result); + // 获取菜谱分类标签end + } + + + + + + + + + + #######################################################################小工具####################################################################### + #######################################################################小工具####################################################################### + #######################################################################小工具####################################################################### + + // 处理食材的卡路里 + public function count_calorie($data,$step){ + + $foot_name = array_column($data, 'id'); + $foot_name = array_unique($foot_name); + $cfc = Db::connect('cfc_db'); + $foot_kcal = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("id in ('".implode("','", $foot_name)."')")->field("id,food_name as name,Calorie_val as kcal")->select(); + $foot_kcal2 = []; + foreach ($foot_kcal as $key => $value) { + $foot_kcal2[$value['name']] = [$value['id'],$value['kcal']]; + } + // dump($data); + // dump($foot_kcal2); + // die; + foreach ($data as $key => $value) { + if(array_key_exists($value['name'], $foot_kcal2)){ + $data[$key]['id'] = $foot_kcal2[$value['name']][0]; + $data[$key]['kcal'] = $foot_kcal2[$value['name']][1]; + }else{ + $data[$key]['kcal'] = '0'; + $data[$key]['id'] = 0; + } + $data[$key]['unit'] = 'g'; + } + + + return $data; + } + + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 计算卡路里 + public function count_calorie_action($weight,$kcal){ + $weight = bcdiv($weight,100,2); + return bcmul($weight,$kcal,2); + } + + + + public function chuli_shuju(){ + $cfc = Db::connect('cfc_db'); + // $foot_kcal = $cfc->table('app_user_cookbook')->field("food_data,id")->select(); + // $foot_name = []; + // // dump($foot_kcal); + // foreach ($foot_kcal as $key => $value) { + // unset($foot_kcal[$key]['ROW_NUMBER']); + // $foot_kcal[$key]['food_data'] = json_decode($foot_kcal[$key]['food_data'],true); + // foreach ($foot_kcal[$key]['food_data'] as $k => $v) { + // $linshi_data = $v; + // // dump($linshi_data); + // $foot_kcal[$key]['food_data'][$k] = []; + // $foot_kcal[$key]['food_data'][$k]['name'] = $linshi_data['name']; + // $foot_kcal[$key]['food_data'][$k]['weight'] = $linshi_data['weight']; + // $foot_kcal[$key]['food_data'][$k]['unit'] = 'g'; + // $foot_kcal[$key]['food_data'][$k]['kcal'] = rtrim($linshi_data['kcal'], "kcal"); + // if(!in_array($linshi_data['name'], $foot_name)){ + // array_push($foot_name,$linshi_data['name']); + // } + // } + // // $foot_kcal[$key]['food_data'] = $foot_kcal[$key]['food_data'][0]; + + // // $foot_kcal[$key]['food_data'] = json_encode($foot_kcal[$key]['food_data']); + // } + + // $shicai = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("name in ('".implode("','", $foot_name)."')")->field("id,name,kcal")->select(); + // $shicai2 = []; + // foreach ($shicai as $key => $value) { + // $shicai2[$value['name']] = [$value['id'],$value['kcal']]; + // } + // // dump($shicai2); + // foreach ($foot_kcal as $key => $value) { + // foreach ($foot_kcal[$key]['food_data'] as $k => $v) { + // $foot_kcal[$key]['food_data'][$k]['kcal'] = $shicai2[$v['name']][1]; + // $foot_kcal[$key]['food_data'][$k]['id'] = $shicai2[$v['name']][0]; + // } + // // $foot_kcal[$key]['food_data'] = $foot_kcal[$key]['food_data'][0]; + + // $foot_kcal[$key]['food_data'] = json_encode($foot_kcal[$key]['food_data']); + // } + + // // dump($foot_kcal); + // // die; + // foreach ($foot_kcal as $key => $value) { + // $cfc->table('app_user_cookbook')->where(['id'=>$value['id']])->update(['food_data'=>$value['food_data']]); + // } + // dump($foot_kcal); + // die; + + + $sql = "SELECT father_id,count(*) as num FROM app_z_national_standard_food_type_4 GROUP BY father_id ORDER BY num DESC"; + + $result = $cfc->query($sql); + $aa = []; + foreach ($result as $key => $value) { + if($value['num'] >= 30){ + $aa[] = $value['father_id']; + } + } + $bb = implode("','",$aa); + + $sql2 = "SELECT id,father_id FROM app_z_national_standard_food_type_4 WHERE father_id IN ('".$bb."')"; + $result2 = $cfc->query($sql2); + + $cc = []; + foreach ($result2 as $key => $value) { + if (array_key_exists($value['father_id'], $cc)) { + // 基本用法 + if (!in_array($value['id'], $cc[$value['father_id']])) { + $cc[$value['father_id']][] = $value['id']; + } + } else { + $cc[$value['father_id']] = [$value['id']]; + } + } + + $toDeleteStructured = []; + + foreach ($cc as $key => $value) { + // 每个数组有58个元素,后29个是需要删除的 + $deletePart = array_slice($value, 29, 29); + $toDeleteStructured[$key] = $deletePart; + // $toDeleteStructured[$key] = count($deletePart); + } + + foreach ($toDeleteStructured as $key => $value) { + $zz = implode("','",$value); + + $result3 = $cfc->table('app_z_national_standard_food_type_4') + ->where("id in ('".$zz."')") + ->update(['is_del'=>1]); + dump($key); + dump($result3); + // $sql3 = "UPDATE app_z_national_standard_food_type_4 SET is_del = 1 WHERE id IN (".$zz.")"; + // $result3 = $cfc->query($sql3); + } + + // foreach ($toDeleteStructured as $key => $value) { + + // foreach ($value as $k => $v) { + // $dd[] = $v; + // } + // } + // $zz = implode(",",$dd); + // $sql3 = "UPDATE app_z_national_standard_food_type_4 SET is_del = 1 WHERE id IN (".$zz.")"; + // $result3 = $cfc->query($sql3); + // dump($result3); + // dump($toDeleteStructured); + } + + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Countfood.php b/application/KitchenScale3/controller/app/Countfood.php new file mode 100644 index 0000000..ecb264a --- /dev/null +++ b/application/KitchenScale3/controller/app/Countfood.php @@ -0,0 +1,1576 @@ +'app_z_national_standard_food_type_3_multilingual',//食材列表3 + 'foodlist4'=>'app_z_national_standard_food_type_4_multilingual',//食材列表3 + 'eat_log'=>'app_user_kcal_log_multilingual',//食材列表3 + 'user'=>'app_user_data_multilingual',//banner + ]; + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 添加每日摄入记录 + public function add_intake_food($data=['token'=>'3e5876042361c8cb42bd48c46918f737','aud_id'=>6,'meals_type'=>'早餐','food_list'=>[['id'=>2778,'name'=>"啤酒(X)",'weight'=>'150','unit'=>'g']]]){ + // 尝试捕获异常 + 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('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) { + // 捕获异常 + $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 get_countfoot_content(){ + // 尝试捕获异常 + // 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('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'); + } + + $return_data = $this->get_countfoot_content_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 get_log_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>1,'page'=>1]){ + // 尝试捕获异常 + // 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('page', $data)){ + return $this->msg(10001,'page 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['page'],'intnum')){ + return $this->msg(10005,'page type is error'); + } + + $return_data = $this->get_log_list_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 set_up_content($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','aud_id'=>61]){ + // 尝试捕获异常 + 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(!$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; + } 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 { + 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' => '系统错误']); + } + } + public function del_user_eat_list_log(){ + // 尝试捕获异常 + 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('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['time'],'datetime')){ + return $this->msg(10005,'time type is error'); + } + + $return_data = $this->del_user_eat_list_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' => '系统错误']); + } + } + // 本次添加食材的营养统计 + public function current_food_statistics(){ + // 尝试捕获异常 + try { + $data = input('post.'); + + if(!array_key_exists('log_id', $data)){ + return $this->msg(10001,'log_id is miss'); + } + + if(is_array($data['log_id'])){ + foreach ($data['log_id'] as $key => $value) { + if(!$this->verify_data_is_ok($value,'intnum')){ + return $this->msg(10005,'log_id type is error'); + } + } + }else{ + return $this->msg(10005,'log_id type is error'); + } + + $return_data = $this->current_food_statistics_action($data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + // 记录日志 + $this->record_api_log($data, $logContent, null); + return json(['status' => 'error', 'message' => '系统错误']); + } + } + #######################################################################action####################################################################### + #######################################################################action####################################################################### + #######################################################################action####################################################################### + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + + public function add_intake_food_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); + } + if(count($data['food_list']) <= 0){ + return $this->msg(10001,'未选择食材'); + } + // 统计食物的id + $food_id_arr = []; + + foreach ($data['food_list'] as $key => $value) { + if(!array_key_exists('id', $value)){ + return $this->msg(10001,'id is miss'); + } + if(!array_key_exists('weight', $value)){ + return $this->msg(10001,'weight is miss'); + } + if(!array_key_exists('meals_type', $value)){ + return $this->msg(10001,'meals_type is miss'); + } + 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(!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','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') + ->select(); + + if(count($food_content) <= 0){ + 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'); + foreach ($data['food_list'] as $key => $value) { + //获取每100g食物的比例 + $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); + $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); + $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'] = $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{ + 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,'添加数据错误'); + } else { + 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(); + return $this->msg(10002); + } + + // dump($data); + // dump($food_id_arr); + // dump($food_content); + // die; + } + public function get_countfoot_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,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); + } + 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){ + // $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'], //时间 + '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'], //剩下可摄入卡路里量 + 'details'=>[ //当天营养元素能量占比 + 'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + 'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + 'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + ], + 'trace_elements_all_day' => [ + [ + 'name' => 'VitaminA', + 'name_ch' => '维生素A', + 'unit' => 'μg RAE', + 'value' => 0 + ], + [ + 'name' => 'VitaminB1', + 'name_ch' => '硫胺素', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB2', + 'name_ch' => '核黄素', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB6', + 'name_ch' => '维生素B6', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB12', + 'name_ch' => '维生素B12', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'VitaminD', + 'name_ch' => '维生素D', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'VitaminK', + 'name_ch' => '维生素K', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Niacin', + 'name_ch' => '烟酸', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminC', + 'name_ch' => '维生素C', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminE', + 'name_ch' => '维生素E', + 'unit' => 'mg α-TE', + 'value' => 0 + ], + [ + 'name' => 'FolicAcid', + 'name_ch' => '叶酸', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Biotin', + 'name_ch' => '生物素', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'PantothenicAcid', + 'name_ch' => '泛酸', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'TotalCholine', + 'name_ch' => '总胆碱', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Ca', + 'name_ch' => '钙', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Phosphorus', + 'name_ch' => '磷', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Kalium', + 'name_ch' => '钾', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Mg', + 'name_ch' => '镁', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Na', + 'name_ch' => '钠', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Fe', + 'name_ch' => '铁', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Zn', + 'name_ch' => '锌', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Se', + 'name_ch' => '硒', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Cu', + 'name_ch' => '铜', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Mn', + 'name_ch' => '锰', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Iodine', + 'name_ch' => '碘', + 'unit' => 'μg', + 'value' => 0 + ] + ], + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + '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 = " . $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.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){ //计算营养物质 + $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'].' '.$value['unit'], + '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'].' '.$value['unit'], + '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'].' '.$value['unit'], + 'id'=>$value['id'], + 'pic_url'=>$value['pic_url'], + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] + ]); + }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'].' '.$value['unit'], + 'id'=>$value['id'], + 'pic_url'=>$value['pic_url'], + 'val'=>$value['kcal_val'], + 'nutrients_four' => $value['nutrients_four'], + 'nutrients_list' => $value['nutrients_list'] + ]); + } + } + // 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; + + + + // 处理各餐卡路里占比 + $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); + // 处理单餐营养占比 + // 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) { + 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':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); + } + + + + $nameMap = [ + 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'], + 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'], + 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'], + 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'], + ]; + $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20); + foreach ($return_data['suggestion'] as $key => $value) { + $return_data['nutrients_four'][] = [ + 'name'=>$nameMap[$key][0], + 'unit'=>$nameMap[$key][1], + 'suggestion'=>$value, + 'today_intake'=>$return_data['today_intake'][$key], + 'icon'=>$nameMap[$key][2], + 'color'=>$nameMap[$key][3], + 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':bcmul(bcdiv($return_data['today_intake'][$key],$value,2),100,2), + // 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100, + 'proportion_fp'=>$key == 'kcal'?0:$nutrition_data[$key.'_p'], + + ]; + } + // dump($user_data); + unset($return_data['suggestion']); + unset($return_data['today_intake']); + + + // return $return_data; + return $this->msg($return_data); + + } + public function get_log_list_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,activity_level') + ->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']; + } + + + $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']." and is_del = 0"); + $page_total = ceil($content_num[0]['total']/$this->page_num); + + $food_content = $cfc->table($this->kitchenscale_db_msg['eat_log']) + ->where(['aud_id'=>$data['aud_id'],'is_del'=>0]) + ->group('CONVERT(varchar, create_time, 23)') + ->page($data['page'],$this->page_num) + ->order('create_time DESC') + ->field("CONVERT(varchar, create_time, 23) as create_time, SUM(kcal_val) as kcal_val") + ->select(); + + $return_data = []; + foreach ($food_content as $key => $value) { + if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 0.9){ + $bz['text'] = '不达标'; + $bz['color'] = '#F0AD4E'; + }else if(bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($value['kcal_val'],$nutrition_data['kcal'],2) < 1.1){ + $bz['text'] = '达标'; + $bz['color'] = '#4CD964'; + }else{ + $bz['text'] = '超标'; + $bz['color'] = '#FF0000'; + } + array_push($return_data,['time'=>$value['create_time'],'title'=>'摄入卡路里','val'=>$value['kcal_val'],'unit'=>'kcal','describe'=>$bz['text'],'color'=>$bz['color']]); + } + return $this->msg([ + 'page_now'=>$data['page'], + 'page_total'=>$page_total, + '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,birthday,set_carbohydrate_v,set_carbohydrate_p,set_protein_v,set_protein_p,set_fat_v,set_fat_p,activity_level') + ->find(); + if(!$user_data){ + return $this->msg(10003); + } + // 计算年龄 + if($user_data['birthday']){ + $user_data['age_num'] = $this->calculate_age($user_data['birthday']); + }else{ + $user_data['age_num'] = $user_data['age']; + } + // 计算推荐营养 + $nutrition_data = $this->count_user_nutrition_all($user_data); + if($user_data['is_use_set_kcal'] == 1){ + $nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal']; + $nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate']; + $nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein']; + $nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat']; + + + // $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?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%总热量', + '供能并促进大脑发育,选择坚果、鱼类、橄榄油等健康脂肪。', + '注意事项:若有增高、减重等目标,可咨询专业人士调整。' + ], + [ + // '对于一个正常成年人(没有特殊健康问题或特定健身目标),通常建议的三大营养素比例为:', + // '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食物如全谷物、蔬菜,控制血糖。', + '2、蛋白质:10%-30%总热量', + '预防肌肉流失,优选鱼、蛋、豆类等易消化蛋白。', + '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'=>'碳水化合物', + 'key_v'=>'carbohydrate', + 'icon'=>'icon-tanshuihuahewu', + 'proportion'=>$nutrition_data['carbohydrate_p'], + 'val'=>$nutrition_data['carbohydrate'], + 'unit'=>'克' + ], + [ + 'name'=>'蛋白质', + 'key_v'=>'protein', + 'icon'=>'icon-Sm-danbaizhi', + 'proportion'=>$nutrition_data['protein_p'], + 'val'=>$nutrition_data['protein'], + 'unit'=>'克' + ], + [ + 'name'=>'脂肪', + 'key_v'=>'fat', + 'icon'=>'icon-w_fat_normal', + 'proportion'=>$nutrition_data['fat_p'], + '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{ + + } + return $this->msg($return_data); + + } + + 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); + } + } + public function del_user_eat_list_log_action($data){ + $cfc = Db::connect('cfc_db'); + $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find(); + // dump($user_data); + if(!$user_data){ + return $this->msg(10003); + } + $result = $cfc->table($this->kitchenscale_db_msg['eat_log']) + ->where("aud_id = ".$user_data['id']." AND LEFT(create_time,10) = '" .$data['time']. "'") + ->update(['is_del'=>1]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + public function current_food_statistics_action($data){ + $id_arr = implode("','",$data['log_id']); + + $cfc = Db::connect('cfc_db'); + $user_data = $cfc->table($this->kitchenscale_db_msg['user']) + ->where(["token"=>$data['token']]) + ->field('weight,height,gender,age,is_use_set_kcal,set_kcal,birthday,set_carbohydrate_v,set_carbohydrate_p,set_protein_v,set_protein_p,set_fat_v,set_fat_p,activity_level') + ->find(); + + if(!$user_data){ + return $this->msg(10003); + } + if($user_data['birthday']){ + $user_data['age_num'] = $this->calculate_age($user_data['birthday']); + }else{ + $user_data['age_num'] = $user_data['age']; + } + $nutrition_data = $this->count_user_nutrition_all($user_data); + if($user_data['is_use_set_kcal'] == 1){ + $nutrition_data['kcal'] = $user_data['set_kcal'] != 0?$user_data['set_kcal']:$nutrition_data['kcal']; + $nutrition_data['carbohydrate'] = $user_data['set_carbohydrate_v'] != null?$user_data['set_carbohydrate_v']:$nutrition_data['carbohydrate']; + $nutrition_data['protein'] = $user_data['set_protein_v'] != null?$user_data['set_protein_v']:$nutrition_data['protein']; + $nutrition_data['fat'] = $user_data['set_fat_v'] != null?$user_data['set_fat_v']:$nutrition_data['fat']; + + + $nutrition_data['carbohydrate_p'] = $user_data['set_carbohydrate_p'] != null?$user_data['set_carbohydrate_p']:bcmul($nutrition_data['carbohydrate_p'],100,2); + $nutrition_data['protein_p'] = $user_data['set_protein_p'] != null?$user_data['set_protein_p']:bcmul($nutrition_data['protein_p'],100,2); + $nutrition_data['fat_p'] = $user_data['set_fat_p'] != null?$user_data['set_fat_p']:bcmul($nutrition_data['fat_p'],100,2); + }else{ + $nutrition_data['carbohydrate_p'] = bcmul($nutrition_data['carbohydrate_p'],100,2); + $nutrition_data['protein_p'] = bcmul($nutrition_data['protein_p'],100,2); + $nutrition_data['fat_p'] = bcmul($nutrition_data['fat_p'],100,2); + } + $return_data = [ //时间 + 'suggestion'=>[ //建议 + 'kcal'=>$nutrition_data['kcal'], //建议摄入卡路里量 + 'carbohydrate'=>$nutrition_data['carbohydrate'], //建议摄入碳水量 + 'protein'=>$nutrition_data['protein'], //建议摄入蛋白质量 + 'fat'=>$nutrition_data['fat'], //建议摄入脂肪量 + ], + 'today_intake'=>[ //今日已摄入 + 'kcal'=>0, //今日已摄入卡路里量 + 'carbohydrate'=>0, //今日已摄入碳水量 + 'protein'=>0, //今日已摄入蛋白质量 + 'fat'=>0, //今日已摄入脂肪量 + ], + 'remaining_kcal'=>$nutrition_data['kcal'], //剩下可摄入卡路里量 + + ]; + + $eat_food_data = $cfc->table($this->kitchenscale_db_msg['eat_log'])->where("id in ('".$id_arr."')")->select(); + // dump($eat_food_data); + // die; + if(count($eat_food_data) > 0){ //计算营养物质 + // return $this->msg($food_content); + foreach ($eat_food_data as $key => $value) { + // dump($value['nutrients_four']); + $return_data['today_intake']['kcal'] = bcadd($return_data['today_intake']['kcal'],$value['kcal_val'],2); + $return_data['today_intake']['carbohydrate'] = bcadd($return_data['today_intake']['carbohydrate'],$value['carbohydrate_val'],2); + $return_data['today_intake']['protein'] = bcadd($return_data['today_intake']['protein'],$value['protein_val'],2); + $return_data['today_intake']['fat'] = bcadd($return_data['today_intake']['fat'],$value['fat_val'],2); + // 处理各餐 + + } + // 处理剩下可吃 + $return_data['remaining_kcal'] = bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2)>=0?bcsub($return_data['suggestion']['kcal'],$return_data['today_intake']['kcal'],2):0; + } + + + $nameMap = [ + 'kcal' => ['卡路里','kcal','https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png','#5180D8'], + 'carbohydrate' => ['碳水','g','https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','#ED7886'], + 'protein' => ['蛋白质','g','https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','#FFB169'], + 'fat' => ['脂肪','g','https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','#3CB383'], + ]; + + $all_yy_data = bcadd($return_data['suggestion']['fat'],bcadd($return_data['suggestion']['carbohydrate'],$return_data['suggestion']['protein'],20),20); + foreach ($return_data['suggestion'] as $key => $value) { + $return_data['nutrients_four'][] = [ + 'name'=>$nameMap[$key][0], + 'unit'=>$nameMap[$key][1], + 'suggestion'=>$value, + 'today_intake'=>$return_data['today_intake'][$key], + 'icon'=>$nameMap[$key][2], + 'color'=>$nameMap[$key][3], + 'proportion'=>bcdiv($return_data['today_intake'][$key],$value,2) >= 1?'100':bcmul(bcdiv($return_data['today_intake'][$key],$value,2),100,2), + // 'proportion_fp'=>$key == 'kcal'?0:(bcdiv($return_data['suggestion'][$key],$all_yy_data,2))*100, + 'proportion_fp'=>$key == 'kcal'?0:$nutrition_data[$key.'_p'], + + ]; + } + // dump($user_data); + unset($return_data['suggestion']); + unset($return_data['today_intake']); + return $this->msg($return_data); + } + + + + + + #######################################################################工具####################################################################### + #######################################################################工具####################################################################### + #######################################################################工具####################################################################### + + + // 计算每日每餐kcal占比 + public function calculate_kcal_proportion($data){ + + $all_kcal = $data['today_intake']['kcal']; + $arr_kcal = []; + foreach ($data['list'] as $key => $value) { + $arr_kcal[] = $value['val']; + } + // 计算占比 + $percentages = []; + if (bccomp($all_kcal, "0", 20) > 0) { + $sum = "0"; + // 计算前n-1个元素的占比 + for ($i = 0; $i < count($arr_kcal) - 1; $i++) { + $percentage = bcmul(bcdiv($arr_kcal[$i], $all_kcal, 20), "100", 20); + $percentage = bcdiv($percentage, "1", 2); // 保留两位小数 + $percentages[] = $percentage; + $sum = bcadd($sum, $percentage, 2); + } + + // 最后一个元素用100%减去前面总和,确保100% + if($arr_kcal[count($arr_kcal)-1] != 0){ + $lastPercentage = bcsub("100.00", $sum, 2); + }else{ + $lastPercentage = '0.00'; + } + $percentages[] = $lastPercentage; + } else { + // 如果总热量为0,所有占比都为0 + $percentages = array_fill(0, count($arr_kcal), "0.00"); + } + + // 将占比结果添加回原数据 + foreach ($data['list'] as $key => &$value) { + $value['kcal_proportion'] = $percentages[$key]; + } + return $data; + } + // 计算营养物质能量占比 + public function calculate_energy_proportion($data){ + // 获取今日摄入数据 + $today_intake = $data['today_intake']; + // dump($today_intake); + // 总热量摄入 + $total_kcal = $today_intake['kcal']; + + // 各营养素摄入量(克) + $carb_intake = $today_intake['carbohydrate']; // 碳水 + $protein_intake = $today_intake['protein']; // 蛋白质 + $fat_intake = $today_intake['fat']; // 脂肪 + + // 供能系数 + $carb_energy_coef = "4"; // 碳水:4 kcal/g + $protein_energy_coef = "4"; // 蛋白质:4 kcal/g + $fat_energy_coef = "9"; // 脂肪:9 kcal/g + + // 计算各营养素的能量贡献(kcal) + $carb_energy = bcmul($carb_intake, $carb_energy_coef, 20); + $protein_energy = bcmul($protein_intake, $protein_energy_coef, 20); + $fat_energy = bcmul($fat_intake, $fat_energy_coef, 20); + + // 计算各营养素的能量占比(%) + if (bccomp($total_kcal, "0", 20) > 0) { + // 碳水能量占比 + $carb_proportion = bcmul(bcdiv($carb_energy, $total_kcal, 20), "100", 20); + $carb_proportion = bcdiv($carb_proportion, "1", 2); // 保留两位小数 + + // 蛋白质能量占比 + $protein_proportion = bcmul(bcdiv($protein_energy, $total_kcal, 20), "100", 20); + $protein_proportion = bcdiv($protein_proportion, "1", 2); + + // 脂肪能量占比 + $fat_proportion = bcmul(bcdiv($fat_energy, $total_kcal, 20), "100", 20); + $fat_proportion = bcdiv($fat_proportion, "1", 2); + } else { + $carb_proportion = $protein_proportion = $fat_proportion = "0.00"; + } + + // 填充details数据 + $data['details']['carbohydrate']['val'] = $carb_intake; + $data['details']['carbohydrate']['proportion'] = $carb_proportion; + + $data['details']['protein']['val'] = $protein_intake; + $data['details']['protein']['proportion'] = $protein_proportion; + + $data['details']['fat']['val'] = $fat_intake; + $data['details']['fat']['proportion'] = $fat_proportion; + + return $data; + } + // 排序营养元素食物排行榜 + public function energy_food_rank($data){ + // 获取所有食物数据 + $allFoods = []; + + // 遍历每餐数据,收集所有食物信息 + foreach ($data['list'] as $meal) { + if (!empty($meal['list'])) { + foreach ($meal['list'] as $food) { + // 获取食物的营养素数据 + $nutrients_four = $food['nutrients_four']; + $nutrientValues = []; + + // 将营养素数据转换为键值对,便于查询 + foreach ($nutrients_four as $nutrient) { + $nutrientValues[$nutrient['name']] = $nutrient['value']; + } + + $allFoods[] = [ + 'name' => $food['name'], + 'pic_url' => $food['pic_url'], + 'weight' => $food['weight'], + 'carbohydrate' => isset($nutrientValues['碳水化合物']) ? $nutrientValues['碳水化合物'] : '0', + 'protein' => isset($nutrientValues['蛋白质']) ? $nutrientValues['蛋白质'] : '0', + 'fat' => isset($nutrientValues['脂肪']) ? $nutrientValues['脂肪'] : '0' + ]; + } + } + } + + // 如果没有食物数据,直接返回 + if (empty($allFoods)) { + return $data; + } + + // 对每种营养素进行排序并取前三 + $nutrientTypes = [ + 'carbohydrate' => '碳水化合物', + 'protein' => '蛋白质', + 'fat' => '脂肪' + ]; + + foreach ($nutrientTypes as $nutrientKey => $nutrientName) { + // 使用BC函数进行精确比较排序 + usort($allFoods, function($a, $b) use ($nutrientKey) { + $valueA = $a[$nutrientKey]; + $valueB = $b[$nutrientKey]; + + // 使用bccomp进行比较 + $comparison = bccomp($valueA, $valueB, 20); + + if ($comparison == 0) { + return 0; + } + // 返回-1表示a应该在b前面(降序排序) + return ($comparison > 0) ? -1 : 1; + }); + + // 取前三名 + $topThree = array_slice($allFoods, 0, 3); + + // 填充rank_list + $rankList = []; + foreach ($topThree as $index => $food) { + $rankList[] = [ + 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank'.($index+1).'.png', + 'name' => $food['name'], + 'pic_url' => $food['pic_url'], + 'weight' => bcdiv($food[$nutrientKey], '1', 2) // 使用BC函数保留两位小数 + ]; + } + + // 如果不足三个,用空数据补全 + $currentCount = count($rankList); + for ($i = $currentCount; $i < 3; $i++) { + $rankList[] = [ + 'icon' => 'https://tc.pcxbc.com/kitchenscale_all/rank' . ($i + 1) . '.png', + 'name' => '', + 'pic_url' => '', + 'weight' => '' + ]; + } + + // 更新到details中对应的营养素 + $data['details'][$nutrientKey]['rank_list'] = $rankList; + } + + return $data; + } + + // 微量元素处理全天 + public function calculate_trace_elements($data){ + $traceElements = []; + + // 遍历所有餐次数据 + foreach ($data['list'] as $meal) { + if (!empty($meal['list'])) { + foreach ($meal['list'] as $food) { + if (!empty($food['nutrients_list'])) { + foreach ($food['nutrients_list'] as $nutrient) { + // 只处理维生素(type=2)和矿物质(type=3) + if (in_array($nutrient['type'], [2, 3])) { + $name = $nutrient['name']; + $value = $nutrient['value']; + + // 初始化微量元素数据 + if (!isset($traceElements[$name])) { + $traceElements[$name] = [ + 'name' => $nutrient['name'], + 'name_ch' => isset($nutrient['name_ch']) ? $nutrient['name_ch'] : $nutrient['name'], + 'unit' => $nutrient['unit'], + 'value' => '0' + ]; + } + + // 使用BC数学函数精确累加 + $traceElements[$name]['value'] = bcadd( + $traceElements[$name]['value'], + $value, + 20 + ); + } + } + } + } + } + } + + // 处理结果,保留两位小数 + $formattedElements = []; + foreach ($traceElements as $element) { + // 使用BC函数格式化值为两位小数 + $formattedValue = bcdiv($element['value'], '1', 2); + + // 如果值为0,跳过(可选,根据需求决定是否显示0值) + if (bccomp($formattedValue, '0', 2) > 0) { + $formattedElements[] = [ + 'name' => $element['name'], + 'name_ch' => $element['name_ch'], + 'unit' => $element['unit'], + 'value' => $formattedValue + ]; + } + } + + + // 按中文名称排序 + usort($formattedElements, function($a, $b) { + return strcmp($a['name_ch'], $b['name_ch']); + }); + + $data['trace_elements_all_day'] = $formattedElements; + + return $data; + + + + } + + + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Guessyoulike.php b/application/KitchenScale3/controller/app/Guessyoulike.php new file mode 100644 index 0000000..80c4bd9 --- /dev/null +++ b/application/KitchenScale3/controller/app/Guessyoulike.php @@ -0,0 +1,418 @@ + 'app_user_cookbook', //食谱表 + 'cookbook_label' => 'app_user_cookbook_label', //食谱标签表 + 'cookbook_food_relation' => 'app_user_cookbook_food_relation', //食谱跟食材关系表 + 'foodlist2' => 'app_z_national_standard_food_type_2_multilingual', //食材标签表2 + 'foodlist3' => 'app_z_national_standard_food_type_3_multilingual', //食材表 + 'kcal_log' => 'app_user_kcal_log_multilingual', //用户饮食记录表记录用户吃了什么食材 + 'search_history' => 'app_user_search_history_multilingual', //用户搜索记录表,记录用户搜索过什么内容 + // 'tag_preference' => 'app_user_tag_preference', //用户标签偏好表 + 'recommend_cache' => 'app_recommend_cache_multilingual' //智能推荐缓存表 + ]; + + protected $config = [ + 'tag_limit' => 2, + 'item_limit' => 12, + 'cache_time' => 3600 + ]; + + /** + * 猜你喜欢主接口 + */ + public function getGuessYouLike($user_id = 1, $type = 'food', $limit = null) { + try { + $cfc = Db::connect('cfc_db'); + // dump(1); + // 设置限制数量 + $tag_limit = $limit ? intval($limit) : $this->config['tag_limit']; + $item_limit = $this->config['item_limit']; + + // 检查缓存 + // $cache_key = $user_id . ':' . $type; + // $cache_result = $this->getCache($cfc, $cache_key); + // // die; + // if ($cache_result !== null) { + // return $cache_result; + // } + + // 判断用户是否有历史数据 + $has_history = $this->checkUserHistory($cfc, $user_id); + if (!$has_history) { + // 新用户,返回最火信息(仅一个标签) + $result = $this->getPopularRecommendations($cfc, $type, 1, $item_limit); + } else { + // 老用户,根据类型返回个性化推荐 + if ($type === 'cookbook') { + $result = $this->getCookbookRecommendations($cfc, $user_id, $tag_limit, $item_limit); + + } else { + $result = $this->getFoodRecommendations($cfc, $user_id, $tag_limit, $item_limit); + } + } + + // 确保返回格式正确 + if (!is_array($result)) { + $result = []; + } + + // 更新缓存 + // $this->updateCache($cfc, $cache_key, $user_id, $type, $result); + + return $result; + + } catch (\Exception $e) { + // 记录错误日志 + \think\Log::error('猜你喜欢功能错误: ' . $e->getMessage()); + return []; + } + } + + /** + * 检查用户是否有历史数据 + */ + private function checkUserHistory($db, $user_id) { + try { + // 检查饮食记录 + $kcal_result = $db->query(" + SELECT COUNT(*) as count + FROM {$this->kitchenscale_db_msg['kcal_log']} + WHERE aud_id = ? AND is_del = 0 + ", [$user_id]); + $kcal_count = $kcal_result[0]['count'] ?? 0; + + // 检查搜索记录 + $search_result = $db->query(" + SELECT COUNT(*) as count + FROM {$this->kitchenscale_db_msg['search_history']} + WHERE user_id = ? AND is_del = 0 + ", [$user_id]); + $search_count = $search_result[0]['count'] ?? 0; + + return ($kcal_count > 0 || $search_count > 0); + } catch (\Exception $e) { + return false; + } + } + + /** + * 获取缓存数据 + */ + private function getCache($db, $cache_key) { + try { + $cache_result = $db->query(" + SELECT id, cache_key, user_id, keyword, recommend_data, hit_count, last_hit, is_del, create_time + FROM {$this->kitchenscale_db_msg['recommend_cache']} + WHERE cache_key = ? AND is_del = 0 + ", [$cache_key]); + + if (!empty($cache_result)) { + $cache = $cache_result[0]; + $last_hit_timestamp = strtotime($cache['last_hit']); + + if (time() - $last_hit_timestamp < $this->config['cache_time']) { + // 更新命中次数和时间 + $db->execute(" + UPDATE {$this->kitchenscale_db_msg['recommend_cache']} + SET hit_count = hit_count + 1, last_hit = GETDATE() + WHERE id = ? + ", [$cache['id']]); + + $data = json_decode($cache['recommend_data'], true); + return is_array($data) ? $data : null; + } + } + } catch (\Exception $e) { + // 忽略缓存错误,继续执行 + } + + return null; + } + + /** + * 更新缓存 + */ + private function updateCache($db, $cache_key, $user_id, $keyword, $data) { + try { + $current_time = date('Y-m-d H:i:s'); + $recommend_data = json_encode($data, JSON_UNESCAPED_UNICODE); + + // 检查是否存在缓存 + $existing_result = $db->query(" + SELECT id FROM {$this->kitchenscale_db_msg['recommend_cache']} + WHERE cache_key = ? AND is_del = 0 + ", [$cache_key]); + + if (!empty($existing_result)) { + // 更新现有缓存 + $db->execute(" + UPDATE {$this->kitchenscale_db_msg['recommend_cache']} + SET user_id = ?, keyword = ?, recommend_data = ?, hit_count = 1, + last_hit = ?, create_time = ? + WHERE cache_key = ? AND is_del = 0 + ", [$user_id, $keyword, $recommend_data, $current_time, $current_time, $cache_key]); + } else { + // 插入新缓存 + $db->execute(" + INSERT INTO {$this->kitchenscale_db_msg['recommend_cache']} + (cache_key, user_id, keyword, recommend_data, hit_count, last_hit, create_time, is_del) + VALUES (?, ?, ?, ?, 1, ?, ?, 0) + ", [$cache_key, $user_id, $keyword, $recommend_data, $current_time, $current_time]); + } + } catch (\Exception $e) { + // 忽略缓存更新错误 + } + } + + /** + * 获取热门推荐(新用户) + */ + private function getPopularRecommendations($db, $type, $tag_limit, $item_limit) { + // dump($type); + if ($type === 'cookbook') { + return $this->getPopularCookbooks($db, $tag_limit, $item_limit); + } else { + // dump(111); + return $this->getPopularFoods($db, $tag_limit, $item_limit); + } + } + + /** + * 获取热门食谱(新用户) + */ + private function getPopularCookbooks($db, $tag_limit, $item_limit) { + try { + // 简化查询,避免复杂关联导致的错误 + $popular_cookbooks = $db->query(" + SELECT TOP {$item_limit} + id, + title as name + FROM {$this->kitchenscale_db_msg['cookbook']} + WHERE is_del = 0 + ORDER BY likes_num DESC, read_it DESC, create_time DESC + "); + // dump('sp'); + // dump($popular_cookbooks); + $result = []; + $label_data = []; + + foreach ($popular_cookbooks as $cookbook) { + $label_data[] = [ + 'name' => $cookbook['name'] ?? '未知食谱', + 'id' => $cookbook['id'] ?? 0, + 'type' => 'cookbook' + ]; + } + + if (!empty($label_data)) { + $result['最火食谱搜索'] = $label_data; + } + + return $result; + } catch (\Exception $e) { + return []; + } + } + + /** + * 获取热门食材(新用户) + */ + private function getPopularFoods($db, $tag_limit, $item_limit) { + try { + // dump(2222); + // // 简化查询,避免复杂关联导致的错误 + $popular_foods = $db->query(" + SELECT TOP {$item_limit} + id, + keyword as name, + COUNT(*) as num + FROM {$this->kitchenscale_db_msg['search_history']} + WHERE is_del = 0 AND type = 'food' + GROUP BY id, keyword + ORDER BY num DESC + "); + // dump('sc'); + // dump($popular_foods); + + $popular_foods_2 = []; + if(count($popular_foods) < $item_limit){ + $num = $item_limit - count($popular_foods); + $popular_foods_2 = $db->query(" + SELECT TOP {$num} + id, + food_name as name + FROM {$this->kitchenscale_db_msg['foodlist3']} + WHERE is_del = 0 + ORDER BY is_popular DESC, food_name ASC + "); + } + + foreach ($popular_foods_2 as $key => $value) { + $popular_foods[] = $value; + } + + + $result = []; + $label_data = []; + + foreach ($popular_foods as $food) { + $label_data[] = [ + 'name' => $food['name'] ?? '未知食材', + 'id' => $food['id'] ?? 0, + 'type' => 'food' + ]; + } + + if (!empty($label_data)) { + $result['最火食材搜索'] = $label_data; + } + + return $result; + } catch (\Exception $e) { + return []; + } + } + + /** + * 获取个性化食谱推荐(老用户) + */ + private function getCookbookRecommendations($db, $user_id, $tag_limit, $item_limit) { + try { + // 获取用户最常吃的食材 + $user_top_foods = $db->query(" + SELECT TOP 10 food_id, COUNT(*) as eat_count + FROM {$this->kitchenscale_db_msg['kcal_log']} + WHERE aud_id = ? AND is_del = 0 + GROUP BY food_id + ORDER BY eat_count DESC + ", [$user_id]); + + if (empty($user_top_foods)) { + return $this->getPopularCookbooks($db, $tag_limit, $item_limit); + } + + $food_ids = array_column($user_top_foods, 'food_id'); + if (empty($food_ids)) { + return $this->getPopularCookbooks($db, $tag_limit, $item_limit); + } + $food_ids_str = implode(',', $food_ids); + + // 获取包含这些食材的食谱标签 + $preferred_labels = $db->query(" + SELECT TOP {$tag_limit} lbl.id, lbl.name, COUNT(DISTINCT cb.id) as match_count + FROM {$this->kitchenscale_db_msg['cookbook_label']} lbl + INNER JOIN {$this->kitchenscale_db_msg['cookbook']} cb ON lbl.id = cb.cook_label AND cb.is_del = 0 + INNER JOIN {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr ON cb.id = cfr.cookbook_id + WHERE lbl.is_del = 0 AND cfr.food_id IN ({$food_ids_str}) + GROUP BY lbl.id, lbl.name + ORDER BY match_count DESC + "); + + $result = []; + foreach ($preferred_labels as $label) { + // 使用子查询避免GROUP BY复杂性问题 + $cookbooks = $db->query(" + SELECT TOP {$item_limit} cb.id, cb.title as name + FROM {$this->kitchenscale_db_msg['cookbook']} cb + WHERE cb.id IN ( + SELECT DISTINCT cfr.cookbook_id + FROM {$this->kitchenscale_db_msg['cookbook_food_relation']} cfr + WHERE cfr.food_id IN ({$food_ids_str}) + ) + AND cb.cook_label = ? + AND cb.is_del = 0 + ORDER BY cb.likes_num DESC, cb.read_it DESC + ", [$label['id']]); + + $label_data = []; + foreach ($cookbooks as $cookbook) { + $label_data[] = [ + 'name' => $cookbook['name'] ?? '未知食谱', + 'id' => $cookbook['id'] ?? 0, + 'type' => 'cookbook' + ]; + } + + if (!empty($label_data)) { + $result[$label['name'] ?? '未知标签'] = $label_data; + } + } + + return $result; + } catch (\Exception $e) { + return $this->getPopularCookbooks($db, $tag_limit, $item_limit); + } + } + + /** + * 获取个性化食材推荐(老用户) + */ + private function getFoodRecommendations($db, $user_id, $tag_limit, $item_limit) { + try { + // 获取用户最常吃的食材 + $user_top_foods = $db->query(" + SELECT TOP 10 food_id, COUNT(*) as eat_count + FROM {$this->kitchenscale_db_msg['kcal_log']} + WHERE aud_id = ? AND is_del = 0 + GROUP BY food_id + ORDER BY eat_count DESC + ", [$user_id]); + + if (empty($user_top_foods)) { + return $this->getPopularFoods($db, $tag_limit, $item_limit); + } + + $food_ids = array_column($user_top_foods, 'food_id'); + if (empty($food_ids)) { + return $this->getPopularFoods($db, $tag_limit, $item_limit); + } + $food_ids_str = implode(',', $food_ids); + + // 获取用户偏好食材的分类 + $preferred_categories = $db->query(" + SELECT TOP {$tag_limit} f2.id, f2.name, COUNT(DISTINCT f3.id) as food_count + FROM {$this->kitchenscale_db_msg['foodlist2']} f2 + INNER JOIN {$this->kitchenscale_db_msg['foodlist3']} f3 ON f2.id = f3.two_id + WHERE f3.id IN ({$food_ids_str}) AND f2.is_del = 0 AND f3.is_del = 0 + GROUP BY f2.id, f2.name + ORDER BY food_count DESC + "); + + $result = []; + foreach ($preferred_categories as $category) { + // 获取该分类下的其他食材 + $foods = $db->query(" + SELECT TOP {$item_limit} id, food_name as name + FROM {$this->kitchenscale_db_msg['foodlist3']} + WHERE two_id = ? AND is_del = 0 AND id NOT IN ({$food_ids_str}) + ORDER BY is_popular DESC, food_name ASC + ", [$category['id']]); + + $category_data = []; + foreach ($foods as $food) { + $category_data[] = [ + 'name' => $food['name'] ?? '未知食材', + 'id' => $food['id'] ?? 0, + 'type' => 'food' + ]; + } + + if (!empty($category_data)) { + $result[$category['name'] ?? '未知分类'] = $category_data; + } + } + + return $result; + } catch (\Exception $e) { + return $this->getPopularFoods($db, $tag_limit, $item_limit); + } + } +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Index.php b/application/KitchenScale3/controller/app/Index.php new file mode 100644 index 0000000..9391bdd --- /dev/null +++ b/application/KitchenScale3/controller/app/Index.php @@ -0,0 +1,898 @@ +'app_account_number',//账号表 + // 'juese'=>'app_user_data',//角色表 + // ]; + protected $kitchenscale_db_msg = [ + 'cookbook'=>'app_user_cookbook',//菜谱表 + 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表 + 'uploadimg'=>'app_user_upload_img',//图片素材表 + 'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1 + 'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2 + 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3 + 'foodlist4'=>'app_z_national_standard_food_type_4',//食材列表3 + 'collect_list'=>'app_user_collect_list',//点赞表 + 'banner'=>'app_banner_data',//banner + 'version'=>'app_version_log',//版本表 + 'user'=>'app_user_data',//用户表 + 'kcal_log'=>'app_user_kcal_log',//饮食记录表 + 'search_history'=>'app_user_search_history',//搜索历史表 + 'business_cooperation'=>'app_business_cooperation',//搜索历史表 + + ]; + + protected $reedaw_db_name = [ + 'banner'=>'admin_notice_banner',//菜谱表 + + ]; + protected $language_country = [ + 'zh' => ['中文','zh'], // 中文(简体)★ + 'en' => ['English','en'], // 英语(通用)★ + 'jp' => ['日本語(Japanese)','ja'], // 日语(变化) + 'fra' => ['Français(French)','fr'], // 法语(变化) + 'de' => ['Deutsch(German)','de'], // 德语 + 'kor' => ['한국어(Korean)','ko'], // 韩语(变化) + 'ru' => ['Русский(Russian)','ru'], // 俄语 + 'pt' => ['Português(Portuguese)','pt'], // 葡萄牙 + 'spa' => ["Español(Spanish)",'es'], // 西班牙(变化) + 'ara' => ['Arabic(العربية)','ar'], // 阿拉伯(变化) + ]; + // zh, //中文 + // en, // 英语 + // jp, //日语(变化) + // fra, //法语(变化) + // de, //德语 + // kor, //韩语(变化) + // ru, //俄语 + // pt, //葡萄牙 + // spa, //西班牙(变化) + // ara, //阿拉伯(变化) + + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 检测版本及判断是否登录失效 + public function login_invalid_version($data = ['token'=>'']){ + try { + // 获取客户端IP + $ip = request()->ip(); + // 调用IP识别方法 + $region = $this->getIpInfo($ip); + // dump($region); + // 解析地区信息 + $regionParts = explode('|', $region); + $country = $regionParts[0] ?? ''; + // 判断国家是否在支持的语言列表中 + $language = ''; + if ($country && $country !== '0') { + $languageMap = [ + '中国' => 'zh', + '美国' => 'en', + '英国' => 'en', + '西班牙' => 'spa', + '法国' => 'fra', + '葡萄牙' => 'pt', + '阿拉伯联合酋长国' => 'ara', + '俄罗斯' => 'ru', + '德国' => 'de' + ]; + $language = $languageMap[$country] ?? ''; + } + // 检查语言是否在支持列表中 + $language_all = new Language(); + $isSupportedLanguage = array_key_exists($language, $language_all->getSupportedLanguages()); + + + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + $cfc = Db::connect('cfc_db'); + + $result = $cfc->table($this->kitchenscale_db_msg['version'])->order('is_del,id desc')->find(); + + if($result){ + $version = $result['version_num_original']; + $url = $result['download_url']; + }else{ + $version = ''; + $url = ''; + } + if($data['token'] == ''){ + return $this->msg(-2,'未登录',['version'=>$version,'url'=>$url,'language'=>'en']); + } + // dump($data); + $user_token_state = $this->token_time_validate($data['token']); + // dump($user_token_state); + $language_data = $this->pd_language($user_token_state['language'],$isSupportedLanguage,$language); + // dump($user_token_state); + // dump($language_data); + + if($user_token_state['state'] === false){ + return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>$language_data]); + }else{ + return $this->msg(['version'=>$version,'url'=>$url,'language'=>$language_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'] .= "方法: " . __METHOD__ . "\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); + } + } + // 添加IP信息获取方法 + protected function getIpInfo($ip) { + // 默认IP + $ip = $ip ?: request()->ip(); + try { + $ip2region = new \Ip2Region(); + $info = $ip2region->memorySearch($ip); + // 返回国家信息 + return $info['region'] ?: '未知'; + } catch (\Exception $e) { + return '未知'; + } + } + + // 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK) + public function get_default_config(){ + try { + $data = input('post.'); + $return_data = $this->get_default_config_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); + } + } + + // 首页搜索接口(OK) + public function search_column($data = ['search_data'=>'鱼','token'=>'caadd1be045a65f30b92aa805f1de54a','page'=>1]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('search_data', $data)){ + return $this->msg(10001); + } + if(!array_key_exists('page', $data)){ + return $this->msg(10001,'page is miss'); + } + if(!$this->verify_data_is_ok($data['search_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005,'page type is error'); + } + $return_data = $this->search_column_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'] .= "接口: (search_column)\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + + #######################################################################action####################################################################### + #######################################################################action####################################################################### + #######################################################################action####################################################################### + + // 新版 + public function get_default_config_action($data){ + $return_data = [ + 'business_cooperation'=>[], + 'banner_data'=>[], + 'search_history'=>['cookbook'=>[],'food'=>[]], + 'search_guess'=>[], + 'default_count_foot'=>[ + 'date'=>'', //时间 + "nutrients_four"=>[ + [ + "name"=>"卡路里", + "unit"=>"kcal", + "suggestion"=>0, + "today_intake"=>0, + "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_kcal.png", + "color"=>"#5180D8", + "proportion"=>0, + "proportion_fp"=>0 + ], + [ + "name"=>"碳水", + "unit"=>"g", + "suggestion"=>0, + "today_intake"=>0, + "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png", + "color"=>"#ED7886", + "proportion"=>0, + "proportion_fp"=>0 + ], + [ + "name"=>"蛋白质", + "unit"=>"g", + "suggestion"=>0, + "today_intake"=>0, + "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_protein.png", + "color"=>"#FFB169", + "proportion"=>0, + "proportion_fp"=>0 + ], + [ + "name"=>"脂肪", + "unit"=>"g", + "suggestion"=>0, + "today_intake"=>0, + "icon"=>"https://tc.pcxbc.com/kitchenscale_all/icon_fat.png", + "color"=>"#3CB383", + "proportion"=>0, + "proportion_fp"=>0 + ] + ], + 'remaining_kcal'=>0, //剩下可摄入卡路里量 + 'details'=>[ //当天营养元素能量占比 + 'carbohydrate'=>['name'=>'碳水','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_carbohydrate.png','color'=>'#ED7886','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + 'protein'=>['name'=>'蛋白质','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_protein.png','color'=>'#FFB169','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + 'fat'=>['name'=>'脂肪','icon'=>'https://tc.pcxbc.com/kitchenscale_all/icon_fat.png','color'=>'#3CB383','val'=>0,'unit'=>'g','proportion'=>'0.00','rank_list'=>[['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank1.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank2.png','name'=>'','pic_url'=>'','weight'=>''],['icon'=>'https://tc.pcxbc.com/kitchenscale_all/rank3.png','name'=>'','pic_url'=>'','weight'=>'']]], + ], + 'trace_elements_all_day' => [ + [ + 'name' => 'VitaminA', + 'name_ch' => '维生素A', + 'unit' => 'μg RAE', + 'value' => 0 + ], + [ + 'name' => 'VitaminB1', + 'name_ch' => '硫胺素', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB2', + 'name_ch' => '核黄素', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB6', + 'name_ch' => '维生素B6', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminB12', + 'name_ch' => '维生素B12', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'VitaminD', + 'name_ch' => '维生素D', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'VitaminK', + 'name_ch' => '维生素K', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Niacin', + 'name_ch' => '烟酸', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminC', + 'name_ch' => '维生素C', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'VitaminE', + 'name_ch' => '维生素E', + 'unit' => 'mg α-TE', + 'value' => 0 + ], + [ + 'name' => 'FolicAcid', + 'name_ch' => '叶酸', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Biotin', + 'name_ch' => '生物素', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'PantothenicAcid', + 'name_ch' => '泛酸', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'TotalCholine', + 'name_ch' => '总胆碱', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Ca', + 'name_ch' => '钙', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Phosphorus', + 'name_ch' => '磷', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Kalium', + 'name_ch' => '钾', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Mg', + 'name_ch' => '镁', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Na', + 'name_ch' => '钠', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Fe', + 'name_ch' => '铁', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Zn', + 'name_ch' => '锌', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Se', + 'name_ch' => '硒', + 'unit' => 'μg', + 'value' => 0 + ], + [ + 'name' => 'Cu', + 'name_ch' => '铜', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Mn', + 'name_ch' => '锰', + 'unit' => 'mg', + 'value' => 0 + ], + [ + 'name' => 'Iodine', + 'name_ch' => '碘', + 'unit' => 'μg', + 'value' => 0 + ] + ], + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + '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, + "nutrients_four"=> [ + [ + 'name'=>'卡路里', + 'unit'=>'kcal', + 'color'=>'', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'蛋白质', + 'unit'=>'g', + 'color'=>'#5180D8', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'脂肪', + 'unit'=>'g', + 'color'=>'#ED7886', + 'value'=>0, + 'proportion'=>0, + ], + [ + 'name'=>'碳水化合物', + 'unit'=>'g', + 'color'=>'#FFB169', + 'value'=>0, + 'proportion'=>0, + ], + ], + 'list'=>[], + ], + ], + ], + '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'], + ], + 'language_arr'=>$this->process_Language() + ]; + $cfc = Db::connect('cfc_db'); + + // 如果有账号信息 + if(array_key_exists('token', $data)){ + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + // 获取账号下信息以及用户信息 start + $user = $cfc->table($this->kitchenscale_db_msg['user'])->where(["token"=>$data['token']])->find(); + + if($user){ + // return $this->msg(20001,'账号信息错误'); + // 处理搜索历史 start + $search_history_cookbook = $cfc->table($this->kitchenscale_db_msg['search_history']) + ->where(["user_id"=>$user['id'],'is_del'=>0,'type'=>'cookbook']) + ->field('id,keyword,last_searched_at,type') + ->order('last_searched_at desc') + ->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(10) + ->select(); + // 去重 + foreach ($search_history_cookbook as $key => $value) { + unset($search_history_cookbook[$key]['type']); + unset($search_history_cookbook[$key]['ROW_NUMBER']); + } + foreach ($search_history_food as $key => $value) { + unset($search_history_food[$key]['type']); + unset($search_history_food[$key]['ROW_NUMBER']); + } + + $return_data['search_history']['cookbook'] = $search_history_cookbook; + $return_data['search_history']['food'] = $search_history_food; + // 处理搜索历史 end + } + // $return_data['user_data'] = $user; + // if($return_data['user_data']['birthday']){ + // $return_data['user_data']['age'] = $this->calculate_age($return_data['user_data']['birthday']); + // } + // unset($return_data['user_data']['id']); + // unset($return_data['user_data']['token']); + // unset($return_data['user_data']['update_time']); + // unset($return_data['user_data']['ROW_NUMBER']); + // 获取账号下信息以及用户信息 end + // // 处理计食器信息 start + // $kcal = $cfc->table($this->kitchenscale_db_msg['kcal_log'])->where(["aud_id"=>$user['id'],'is_del'=>0])->whereTime('create_time', 'today')->order('id desc')->select(); + // if(count($kcal)>0){ + // $return_data['kcal_data']['title'] = '今日已摄入热量(千卡)'.$kcal[0]['create_time']; + // $return_data['kcal_data']['time'] = $kcal[0]['create_time']; + // foreach ($kcal as $key => $value) { + + // $return_data['kcal_data']['kcal']['value'] = bcadd($return_data['kcal_data']['kcal']['value'],$value['kcal_val'],2); + // $return_data['kcal_data']['other_elements']['carbohydrate']['value'] = bcadd($return_data['kcal_data']['other_elements']['carbohydrate']['value'],$value['carbohydrate_val'],2); + // $return_data['kcal_data']['other_elements']['protein']['value'] = bcadd($return_data['kcal_data']['other_elements']['protein']['value'],$value['protein_val'],2); + // $return_data['kcal_data']['other_elements']['fat']['value'] = bcadd($return_data['kcal_data']['other_elements']['fat']['value'],$value['fat_val'],2); + // if($value['meals_type'] == '早餐'){ + // $return_data['kcal_data']['list'][0]['value'] = bcadd($return_data['kcal_data']['list'][0]['value'],$value['kcal_val'],2); + // }else if($value['meals_type'] == '午餐'){ + // $return_data['kcal_data']['list'][1]['value'] = bcadd($return_data['kcal_data']['list'][1]['value'],$value['kcal_val'],2); + // }else if($value['meals_type'] == '晚餐'){ + // $return_data['kcal_data']['list'][2]['value'] = bcadd($return_data['kcal_data']['list'][2]['value'],$value['kcal_val'],2); + // }else{ + // $return_data['kcal_data']['list'][3]['value'] = bcadd($return_data['kcal_data']['list'][3]['value'],$value['kcal_val'],2); + // } + // } + // foreach ($return_data['kcal_data']['list'] as $key => $value) { + // if($value['value'] <= 0){ + // $return_data['kcal_data']['list'][$key]['value'] = '-'; + // } + // } + // } + + // if($user['is_use_set_kcal'] == 1){ + // $nutrition_data['kcal'] = $user['set_kcal']; + // }else{ + // $user['age_num'] = $return_data['user_data']['age']; + // $nutrition_data = $this->count_user_nutrition_all($user); + // } + + // if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 0.9){ + // $return_data['kcal_data']['kcal']['standard'] = '不达标'; + // $return_data['kcal_data']['kcal']['color'] = '#F0AD4E'; + // }else if(bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) >= 0.9 && bcdiv($return_data['kcal_data']['kcal']['value'],$nutrition_data['kcal'],2) < 1.1){ + // $return_data['kcal_data']['kcal']['standard'] = '达标'; + // $return_data['kcal_data']['kcal']['color'] = '#4CD964'; + // }else{ + // $return_data['kcal_data']['kcal']['standard'] = '超标'; + // $return_data['kcal_data']['kcal']['color'] = '#FF0000'; + // } + // // 处理计食器信息 end + + + // dump($return_data); + + }else{ + + } + // 处理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 + // 使用三元运算符判断$user是否存在 + $user_id = isset($user) ? $user['id'] : 9999999; + $cnxh = new Guessyoulike; + $cookbook_data = $cnxh->getGuessYouLike($user_id,'cookbook'); + $food_data = $cnxh->getGuessYouLike($user_id,'food'); + foreach ($cookbook_data as $key => $value) { + $return_data['search_guess']['cookbook'][] = ['title'=>$key,'list'=>$value]; + } + foreach ($food_data as $key => $value) { + $return_data['search_guess']['food_data'][] = ['title'=>$key,'list'=>$value]; + } + // 处理猜你喜欢信息end + + // 添加商务合作信息start + $business_cooperation = $cfc->table($this->kitchenscale_db_msg['business_cooperation'])->where(["is_del"=>0])->field('id,title,data_url as jump_url')->find(); + $return_data['business_cooperation'] = $business_cooperation; + // 添加商务合作信息start + + // 添加菜谱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; + // 添加菜谱label end + + // 添加每餐背景图start + $return_data['meal_list'] = [ + ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1.png','name'=>'早餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_1_bg.jpg'], + ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2.png','name'=>'午餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_2_bg.jpg'], + ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3.png','name'=>'晚餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_3_bg.jpg'], + ['icon'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4.png','name'=>'加餐','icon_bg'=>'https://tc.pcxbc.com/kitchenscale_all/meal_4_bg.jpg'], + ]; + // 添加每餐背景图start + + + + + + return $this->msg($return_data); + } + + public function search_column_action($data){ + + // $cookbook = new Cookbook(); + $cfc = Db::connect('cfc_db'); + $page_now = array_key_exists('page',$data)?$data['page']:1; + $page_total = $page_now; + $page_num = 20; + // 获取菜谱信息 + $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook']) + ->where("title LIKE '%".$data['search_data']."%' OR describe_data LIKE '%".$data['search_data']."%'") + ->count(); + $page_total = ceil($content_num/$page_num); + + $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + ->alias('cookbook') + ->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT') + ->where("cookbook.title LIKE '%".$data['search_data']."%' OR cookbook.describe_data LIKE '%".$data['search_data']."%'") + ->field("cookbook.id,cookbook.title,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num,uploadimg.pic_url as cover") + ->page("$page_now,$page_num") + ->select(); + + + if(count($content_list)<=0){ + return $this->msg([]); + } + if(array_key_exists('token',$data)){ + if($data['token'] != ''){ + // 获取账号下信息以及用户信息 + $user_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find(); + if($user_data){ + // 获取用户收藏列表 + $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list']) + ->where(['token'=>$data['token']]) + ->column('cookbook_id'); + // dump(); + // 处理菜谱收藏信息 + foreach ($content_list as $key => $value) { + if(array_key_exists($value['id'],$my_collect_list)){ + $content_list[$key]['is_me_like_it'] = 'yes'; + }else{ + $content_list[$key]['is_me_like_it'] = 'no'; + } + if($value['cover'] == null){ + $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + } + unset($content_list[$key]['ROW_NUMBER']); + } + if($data['search_data'] != ''){ + $this->add_search_history_action(['id'=>$user_data['id'],'search_data'=>$data['search_data'],'type'=>'cookbook']); + } + + }else{ + foreach ($content_list as $key => $value) { + $content_list[$key]['is_me_like_it'] = 'no'; + if($value['cover'] == null){ + $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + } + unset($content_list[$key]['ROW_NUMBER']); + } + } + }else{ + foreach ($content_list as $key => $value) { + $content_list[$key]['is_me_like_it'] = 'no'; + if($value['cover'] == null){ + $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + } + unset($content_list[$key]['ROW_NUMBER']); + } + } + }else{ + foreach ($content_list as $key => $value) { + $content_list[$key]['is_me_like_it'] = 'no'; + if($value['cover'] == null){ + $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + } + unset($content_list[$key]['ROW_NUMBER']); + } + } + + + return $this->msg([ + 'page_now'=>$page_now, + 'page_total'=>$page_total, + 'content_list'=>$content_list + ]); + } + + + + + ######################################################################################################################################################################## + ######################################################################################################################################################################## + ######################################################################################################################################################################## + + + + + public function create_random_string($length = 12) + { + //创建随机字符 + $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + $str = ""; + for ($i = 0; $i < $length; $i++) { + $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); + } + return $str; + } + public function pd_language($user_language,$isSupportedLanguage,$language){ + if(!$user_language){ + if($isSupportedLanguage){ + $result = $language; + }else{ + $result = 'zh'; // 默认语言为中文 + } + }else{ + $result = $user_language; + } + return $result; + } + // 处理返回的语言数组 + public function process_Language(){ + $temporary_arr = []; + foreach ($this->language_country as $key => $value) { + array_push($temporary_arr,['name'=>$value[0],'val'=>$key,'key'=>$value[1]]); + } + return $temporary_arr; + } + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Language.php b/application/KitchenScale3/controller/app/Language.php new file mode 100644 index 0000000..0fc01e6 --- /dev/null +++ b/application/KitchenScale3/controller/app/Language.php @@ -0,0 +1,240 @@ + 'English', + 'zh-Hans' => 'Chinese', + 'es' => 'Spanish', + 'fr' => 'French', + 'pt' => 'Portuguese', + 'ar' => 'Arabic', + 'ru' => 'Russian', + 'de' => 'German' + ]; + + // 语言映射表 + protected $languageMap = [ + 'en' => [ + '操作成功' => 'Success', + '关键参数缺失' => 'Required parameter missing', + '操作失败' => 'Operation failed', + '信息核实错误' => 'Information verification error', + '未找到有效数据' => 'No valid data found', + '参数格式错误' => 'Parameter format error', + '参数不能为空' => 'Parameter cannot be empty', + '参数错误' => 'Parameter error', + '自定义信息' => 'Custom message', + '登录失效' => 'Login invalid', + '网络异常,请稍后重试' => 'Network error, please try again later', + '年龄' => 'Age', + '岁' => '', + '无' => 'none', + '体重' => 'Weight', + '身高' => 'Height', + '消瘦' => 'Slim', + '正常' => 'Normal', + '偏重' => 'Overweight', + '肥胖' => 'Obesity', + '反映和衡量一个人健康状况的重要标志之一' => "One of the important indicators reflecting and measuring a person's health status", + '人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大' => "The length of the longitudinal part of the human body is derived from its longitudinal growth and is greatly influenced by genetic factors", + 'BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。' => "BMI is the body mass index, which is currently a commonly used international standard for measuring the degree of body fat, thinness, and health.", + '公斤' => "kg", + 'CM' => "cm", + '年' => "-", + '月' => "-", + '日' => "", + '身体得分' => "Physical score", + '分' => "score", + '身体类型' => "body type", + '健美肌肉型' => "Bodybuilding muscle type", + '低' => "Low", + '偏低' => "Slightly low", + '标准' => "Standard", + '偏高' => "Slightly high", + '高' => "High", + '矮' => "Short", + '偏矮' => "Slightly short", + '脂肪率' => "Body Fat Percentage", + '体脂率是指身体成分中,脂肪组织所占的比率。测量体脂率比单纯的只测量体重更能反映我们身体的脂肪水平(肥胖程度)。' => "Body fat percentage refers to the proportion of fat tissue in body composition. Measuring it provides a more accurate reflection of body fat levels (degree of obesity) than weight measurement alone.", + '脂肪量' => "Fat Mass", + '人体脂肪的重量' => "Body Fat Weight", + '肌肉率' => "Muscle Percentage", + '优' => "Excellent", + '根据人体肌肉总量和人体体重、身高等相结合得到的人体的一个比例值,这个值的范围决定一个人的身体健康状况以及力量的多少。' => "Muscle percentage is a ratio derived from total muscle mass, body weight, height, etc. Its range determines a person's health status and strength level.", + '肌肉量' => "Muscle Mass", + '不足' => "Insufficient", + '肌肉量=实际体重*肌肉率' => "Muscle Mass = Actual Weight × Muscle Percentage", + '水分' => "Body Water", + '指人体内水分比例。' => "Refers to the proportion of water in the human body.", + '蛋白量' => "Protein Mass", + '蛋白量=实际体重*蛋白率' => "Protein Mass = Actual Weight × Protein Percentage", + '骨重' => "Bone Mass", + '单位体积内,骨组织、骨矿物质(钙、磷等)和骨基质(骨胶原、蛋白率、无机盐等等)含量,骨量代表它们骨骼健康的情况。' => "Bone mass refers to the content of bone tissue, minerals (calcium, phosphorus, etc.), and bone matrix (collagen, proteins, inorganic salts, etc.) per unit volume, reflecting skeletal health.", + '蛋白率' => "Protein Percentage", + '人体内蛋白率含量。' => "The proportion of protein in the human body.", + '基础代谢' => "Basal Metabolic Rate (BMR)", + '指人体在清醒而又极端安静的状态下,不受肌肉活动、环境温度、食物及精神紧张等影响时的能量代谢率' => "The energy expenditure rate when the body is awake, completely at rest, and unaffected by muscle activity, ambient temperature, food intake, or mental stress.", + '内脏指数' => "Visceral Fat Index", + '警惕' => "Caution", + '危险' => "Danger", + '内脏脂肪指数' => "Visceral Fat Level", + '皮下脂肪' => "Subcutaneous Fat", + '皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织' => "Subcutaneous fat refers to adipose tissue stored under the skin. About two-thirds of body fat is stored subcutaneously.", + '肥胖等级' => "Obesity Level", + '体重不足' => "Underweight", + '肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。' => "Obesity level indicates the disparity between actual and ideal weight, serving as a diagnostic criterion for obesity.", + '孩子可能存在营养不良:对于处在生长发育期的孩子而言,蛋白质、碳水化合物、维生素和矿物质这四类营养素非常重要。建议补充足够的蛋白质、锌、钙、铁、维生素D、赖氨酸等营养。建议补充含鸡内金山楂膏健脾开胃类药食同源食物。' => "The child may be malnourished: For growing children, protein, carbohydrates, vitamins, and minerals are critical. Ensure adequate intake of protein, zinc, calcium, iron, vitamin D, lysine, etc. Consider herbal foods like chicken gizzard-hawthorn paste to improve digestion and appetite.", + '孩子可能存在营养不良:对于处在生长发育期的孩子而言,最有利于长高的营养素是蛋白质、碳水化合物、维生素和矿物质四类。建议补充足够的蛋白质、锌、铁、钙、维生素D、赖氨酸等营养。' => "The child may be malnourished: For children in their growth and development stage, the most beneficial nutrients for height growth are proteins, carbohydrates, vitamins, and minerals. It is recommended to ensure adequate intake of nutrients such as protein, zinc, iron, calcium, vitamin D, and lysine.", + '坚持适当、科学的跳跃运动能够科学地增加学生体重,能够改善学 生体重过低的情况;同时运动会消耗能量并加速胃肠蠕动,这会使孩子的食欲大开,再配合均衡的营养有利于孩子增重。' => "Moderate, scientifically designed jumping exercises can help underweight students gain weight by boosting energy expenditure and gastrointestinal motility, thereby increasing appetite. Combined with balanced nutrition, this supports healthy weight gain.", + '3-7岁的孩子:骑两轮车、拍踢球、打篮球、游泳、爬山,每天高强度运动不超过30分钟。' => "Ages 3–7: Bicycling, ball games, basketball, swimming, hiking. Limit high-intensity exercise to 30 minutes daily.", + '该年龄段睡眠时间建议:9-11小时' => "Recommended sleep duration for this age group: 9–11 hours.", + '孩子开始对于赞赏、鼓励、认同和肯定有需求,而且此阶段父亲在孩子的性格塑造、情绪控制以及责任感培养方面扮演着重要的角色,必须告诉孩子什么事应该做、什么事不应该做,并经常性地给孩子一些积极地暗示。例如,可以时常向孩子表达“我会一直在你身边,不要害怕””我对你的进步都看在眼里等类似的话语。' => "Children begin to crave praise, encouragement, and validation. Fathers play a key role in shaping character, emotional regulation, and responsibility during this phase. Clearly define boundaries while offering positive affirmations (e.g., 'I’m always here for you,' 'I see your progress').", + '《中华人民共和国卫生行业标准WS/T 423-2022》' => "《Chinese Health Industry Standard WS 423-2022》", + '《中华人民共和国卫生行业标准WS/T 612-2018》' => "《Chinese Health Industry Standard WS/T 612-2018》", + '《中华人民共和国卫生行业标准WS/T 586-2018》' => "《Chinese Health Industry Standard WS/T 586-2018》", + '《WHO 5~19岁身高/体重判定标准》' => "《WHO Growth Reference for Children and Adolescents (5–19 Years)》", + '头围' => "Head Circumference", + '头围是指绕头部一周的最大长度,头围的大小与脑的发育密切相关' => "Head circumference refers to the maximum length around the head. Its measurement is closely related to brain development.", + '心率' => "Heart rate", + '过缓' => "Too slow", + '过速' => "Too fast", + '心率变化与心脏疾病密切相关,请随时关注心率变化情况,尤其是运动时期。' => "Heart rate changes are closely related to heart disease, please keep an eye on heart rate changes, especially during exercise.", + '心率图' => "heart rate chart", + '第1次' => "1st", + '第2次' => "2nd", + '第3次' => "3rd", + '第4次' => "4th​", + '第5次' => "5th​", + '第6次' => "6th​", + '第7次' => "7th​", + '第8次' => "8th​", + '第9次' => "9th​", + '第10次' => "10th​", + '第11次' => "11th​", + '第12次' => "12th​", + + ], + // 可以添加更多语言映射 + ]; + /** + * 处理多国语言翻译 + * + * @param string $language 目标语言代码 + * @param mixed $data 要翻译的数据(字符串或数组) + * @return mixed 翻译后的数据 + */ + public function handling_languages_from_multiple_countries($language, $data) + { + + // dump($data); + // 验证语言是否支持 + if (!$this->isLanguageSupported($language)) { + return $this->msg($data['data']); + } + + // 如果是数组,递归处理每个元素 + if (is_array($data)) { + // dump(2); + $data = $this->translateArray($language, $data); + return $this->msg($data['data']); + } + + // 如果是字符串,直接翻译 + if (is_string($data)) { + // dump(3); + return $this->translateString($language, $data); + } + + // dump($data); + // 其他类型直接返回 + return $this->msg($data['data']); + } + + /** + * 检查语言是否支持 + * + * @param string $language 语言代码 + * @return bool + */ + protected function isLanguageSupported($language) + { + return isset($this->supportedLanguages[$language]); + } + + /** + * 翻译数组 + * + * @param string $language 目标语言 + * @param array $array 要翻译的数组 + * @return array 翻译后的数组 + */ + protected function translateArray($language, array $array) + { + $result = []; + foreach ($array as $key => $value) { + // 保持键不变,只翻译值 + $result[$key] = is_array($value) + ? $this->translateArray($language, $value) + : $this->translateString($language, $value); + } + return $result; + } + + /** + * 翻译字符串 + * + * @param string $language 目标语言 + * @param string $string 要翻译的字符串 + * @return string 翻译后的字符串 + */ + protected function translateString($language, $string) + { + // dump($string); + // 检查是否有该语言的映射表 + if (!isset($this->languageMap[$language])) { + return $string; + } + + // 检查是否有对应的翻译 + return $this->languageMap[$language][$string] ?? $string; + } + + /** + * 获取支持的语言列表 + * + * @return array + */ + public function getSupportedLanguages() + { + return $this->supportedLanguages; + } + + /** + * 添加新的语言翻译 + * + * @param string $language 语言代码 + * @param array $translations 翻译映射数组 + * @return bool + */ + public function addTranslations($language, array $translations) + { + if (!$this->isLanguageSupported($language)) { + return false; + } + + if (!isset($this->languageMap[$language])) { + $this->languageMap[$language] = []; + } + + $this->languageMap[$language] = array_merge( + $this->languageMap[$language], + $translations + ); + + return true; + } +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Login.php b/application/KitchenScale3/controller/app/Login.php new file mode 100644 index 0000000..3284708 --- /dev/null +++ b/application/KitchenScale3/controller/app/Login.php @@ -0,0 +1,705 @@ +'app_account_number', + ]; + + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 注册 + public function register_action($data = ['data'=>13408173311,'password'=>'123','code'=>'746119']){ + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if(!$data['data'] || !$data['password'] || !$data['code']){ + return $this->msg(10006); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 验证是手机还是邮箱 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + + // 查询账号是否已经注册 + $inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count(); + + if($inspect_repeat > 0){ + return $this->msg(10002,'注册失败,账号已存在'); + } + + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10002,$code_result); + } + // 验证完之后 + $set_data = []; + if($montage_data == 'tel'){ + $set_data['tel'] = $data['data']; + }else{ + $set_data['email'] = $data['data']; + } + $set_data['password'] = $data['password']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.time(); + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "方法: " . __METHOD__ . "\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 reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if($data['password'] != $data['c_password']){ + return $this->msg(10003,'两次密码不一致'); + } + if($data['password'] == ''){ + return $this->msg(10003,'密码不能为空'); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10003,$code_result); + } + $t_y = $this->is_tel_email($data['data']); + if($t_y === false){ + return $this->msg(10003,'账号格式错误'); + } + // 检查账号是否存在 + $find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); + if(!$find_data){ + return $this->msg(10003); + } + $result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); + if($result){ + $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "方法: " . __METHOD__ . "\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 login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ + return $this->msg(10001); + } + // 检测是否为手机 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + + $verify_result[$montage_data] = $data['data']; + $verify_result['is_del'] = 0; + // 检测校验途径 + if($data['validate_type'] == 'code'){ + $code_name = $data['data']; + if($this->check_code($code_name,$data['validate_data']) === true){ + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find(); + if($result){ + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); + }else{ + $set_data['password'] = ''; + $set_data[$montage_data] = $data['data']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.$data['data']; + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + }else{ + $return_data = $this->msg(10002); + } + } + }else{ + $return_data = $this->msg(10003,'登录失败,验证码错误或失效'); + } + }else if($data['validate_type'] == 'password'){ + // $verify_result['password'] = $data['validate_data']; + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find(); + if($result){ + if($result['password'] == ''){ + $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); + } + if($data['validate_data'] != $result['password']){ + $return_data = $this->msg(10003,'账号密码错误'); + }else{ + + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + } + }else{ + $return_data = $this->msg(10003,'账号未注册,请先注册'); + } + }else{ + $return_data = $this->msg(10003,'校验参数错误'); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "方法: " . __METHOD__ . "\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 wechat_quick_login(){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('code', $data)){ + // return $this->msg(10001,''); + return $this->msg(10001,'code is miss'); + } + if(!array_key_exists('encryptedData', $data)){ + return $this->msg(10001,'encryptedData is miss'); + } + if(!array_key_exists('iv', $data)){ + return $this->msg(10001,'iv is miss'); + } + // 校验参数 + if (empty($data['code'])) { + return $this->msg(10001,'code is miss.'); + } + if (empty($data['encryptedData'])) { + return $this->msg(10001,'encryptedData is miss.'); + } + if (empty($data['iv'])) { + return $this->msg(10001,'iv is miss.'); + } + + // 调用Wechat服务类处理微信登录逻辑 + $wechatService = new Wechat(); + $result = $wechatService->handleWechatLogin($data['code'], $data['encryptedData'], $data['iv']); + + // die; + if($result['code'] == 0){ + // return $this->msg($result['code'],$result['msg']); + + $user_data = Db::table($this->login_use_db_name['1'])->where(['tel'=>$result['data']['phoneNumber'],'is_del'=>0])->find(); + + if($user_data){ + Db::table($this->login_use_db_name['1'])->where(['token'=>$user_data['token']])->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$user_data['token'],'aan_id'=>$user_data['id']]); + }else{ + $set_data['password'] = ''; + $set_data['tel'] = $result['data']['phoneNumber']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.$result['data']['phoneNumber']; + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($result['data']['phoneNumber'].$this->create_random_string(12).time()); + $set_user_result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($set_user_result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$set_user_result],'登录成功'); + }else{ + $return_data = $this->msg(10002); + } + } + return $return_data; + }else{ + return $this->msg($result['code'],$result['msg']); + } + + } 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'] .= "方法: " . __METHOD__ . "\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 user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + $return_data = $this->msg(20001); + } + + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "方法: " . __METHOD__ . "\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 delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "方法: " . __METHOD__ . "\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); + } + + } + + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + + + // 发送验证码 手机/邮箱 + /* 接口说明(发邮件) + * $data(手机或者邮箱信息) 字符串 + * $type(验证类型,是注册用,还是其他用途) 字符串 默认register(注册)(register、login、reset_password) + * $road(是手机还是邮箱还是其他) 字符串 默认tel或email + */ + //18736019909 + public function send_phone_email_code($data = ['data'=>'18736019909']){ + + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data)){ + return $this->msg(10001); + } + + if(cache($data['data'])){ + return $this->msg(10002,'60秒仅可发送一次验证码'); + } + + $num = mt_rand(100000,999999); + if (preg_match('/^\d{11}$/', $data['data'])) { + // 本公司短信 + $result = $this->send_tel_code($data['data'],$num); + // 阿里云短信 + // $sms_all = new Smsaliyun; + // $result = $sms_all->send_sms($data['data'],$num); + // dump($result); + $road = 'tel'; + }else{ + $result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]); + $road = 'email'; + } + if(is_array($result) && $result['code'] == 0){ + cache($data['data'], $num, $this->code_time); + // return $this->msg(['code'=>$num]); + return $this->msg([]); + // return true; + }else{ + return $this->msg(10010,'验证码发送失败'); + // return false; + } + } + + ################################内部调用################################ + /* 接口说明(发手机短信) + + */ + public function send_tel_code($tel,$code){ + // 初始化cURL会话 + $ch = curl_init(); + $headers = [ + 'Accept: application/json', + 'Content-Type: application/json', + ]; + // 设置头部信息 + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + // 设置请求的URL + $url = "http://sms.ybhdmob.com/Message/Send?token=ybhdmob"; + curl_setopt($ch, CURLOPT_URL, $url); + // 设置为POST请求 + curl_setopt($ch, CURLOPT_POST, 1); + // 设置POST数据 + $postData = array( + 'phone' => $tel, + // 'content' => '【巨天】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + // 'content' => '【郑州品传科技】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + // 'content' => '【每日一称】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + 'content' => '【小白健康】您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信' + ); + $postData = json_encode($postData); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); + // 设置返回结果不直接输出,而是返回到变量中 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + // 发送请求并获取响应 + $response = curl_exec($ch); + // dump($response); + // 检查是否有错误发生 + if (curl_errno($ch)) { + $error_message = curl_error($ch); + return "请求错误: " . $error_message; + } + // 关闭cURL会话 + curl_close($ch); + // 处理响应 + // dump(json_decode($response,true)); + if ($response) { + return json_decode($response,true); + } else { + echo "未收到响应"; + } + } + // 手机号区分 + function getCarrierByPhone($phone) { + // 验证手机号格式(11位数字且以1开头) + if (!preg_match('/^1[3-9]\d{9}$/', $phone)) { + return '无效手机号'; + } + + $prefix3 = substr($phone, 0, 3); + + // 2025年最新3位号段(排除4位号段) + $carriers = [ + '中国移动' => ['134', '135', '136', '137', '138', '139', '150', '151', '152', '157', '158', '159', '178', '182', '183', '184', '187', '188', '195', '197', '198'], + '中国联通' => ['130', '131', '132', '155', '156', '166', '175', '176', '185', '186', '196'], + '中国电信' => ['133', '153', '173', '177', '180', '181', '189', '190', '191', '193', '199'], + '中国广电' => ['192'] + ]; + + foreach ($carriers as $carrier => $segments) { + if (in_array($prefix3, $segments)) { + return $carrier; + } + } + + return '未知运营商'; + } + /* 接口说明(发邮件) + * $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......] + * $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123'] + * $annex(附件路径信息) 字符串 + */ + public function send_email_code($address,$content,$annex=''){ + // $ad = '460834639@qq.com'; + $ad1 = '295155911@qq.com'; + $mail = new PHPMailer(); //实例化 + $mail->IsSMTP(); // 启用SMTP + $mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子 + $mail->Port = 465; //邮件发送端口 + $mail->SMTPAuth = true; //启用SMTP认证 + $mail->SMTPSecure = 'ssl'; + $mail->CharSet = "UTF-8"; //字符集 + $mail->Encoding = "base64"; //编码方式 + $mail->Username = "tsf3920322@126.com"; //你的邮箱 + $mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码) + $mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱) + + // $mail->Subject = "微盟测试邮件"; //邮件标题 + $mail->Subject = $content['title']; //邮件标题 + + // $mail->FromName = "微盟体测中心"; //发件人姓名 + $mail->FromName = $content['from_user_name']; //发件人姓名 + + + for ($i=0; $i < count($address); $i++) { + $mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称) + } + + if($annex != ''){ + // $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg'; + $mail->AddAttachment($annex,''); // 添加附件,并指定名称 + } + + $mail->IsHTML(true); //支持html格式内容 + + $neirong = '
+ + + + + +
+ + + + + + + +
  + + + + + +
+
 
+
+ + + + + +
+
 
+ + Reedaw! + +
 
+
+ + + + + +
+
 
+ + 感谢您选择锐动产品! + +
 
+ + 以下6位数字是邮箱验证码,请在需要的位置填写以通过验证 + +
 
+ + (如果您从未请求发送邮箱验证码,请忽略此邮件) + +
 
+ + + + +
+ + + '.$content['content'].' + + +
+
 
+
+ + + + + +
+
 
+ + + + +
+
 
+ + © Zhengzhou Pinchuan Technology Co., Ltd. + +
 
+ + + +
 
+
+
+ +
 
+ +
+
'; + + $mail->Body = $neirong; //邮件主体内容 + //发送 + if (!$mail->Send()) { + + return ['code' => 10003,'msg'=>$mail->ErrorInfo]; + // return $mail->ErrorInfo; + } else { + return ['code' => 0]; + // return 'success'; + } + } + + + + public function check_code($data = 18530934717 , $code = 123456){ + // // 默认验证码正确 + + if(cache($data) == false){ + return '验证码过期'; + }else{ + if($code != cache($data)){ + return '验证码错误'; + } + } + return true; + } + ################################################################other################################################################ + ################################################################other################################################################ + ################################################################other################################################################ + + + public function create_random_string($length = 12) + { + //创建随机字符 + $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + $str = ""; + for ($i = 0; $i < $length; $i++) { + $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); + } + return $str; + } + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Product.php b/application/KitchenScale3/controller/app/Product.php new file mode 100644 index 0000000..d2d4191 --- /dev/null +++ b/application/KitchenScale3/controller/app/Product.php @@ -0,0 +1,75 @@ +table("ceshi3_option") + ->alias('xuanxiang') + ->join('ceshi2_configuration peizhi','xuanxiang.parent_id = peizhi.id','LEFT') + ->where(['peizhi.is_default'=>$this->is_default]) + ->field("xuanxiang.*,peizhi.name") + ->select(); + $temporary = []; + foreach ($content_num as $key => $value) { + $temporary[$value['name']]['id'] = $value['parent_id']; + $temporary[$value['name']]['name'] = $value['name']; + $temporary[$value['name']]['type'] = "configuration"; + $temporary[$value['name']]['list'][$value['value']] = []; + $temporary[$value['name']]['list'][$value['value']]['id'] = $value['id']; + $temporary[$value['name']]['list'][$value['value']]['name'] = $value['value']; + $temporary[$value['name']]['list'][$value['value']]['type'] = "parameter"; + $temporary[$value['name']]['list'][$value['value']]['list'] = []; + } + // dump($temporary); + // die; + return $this->msg($temporary); + } + + // 获取所点击选项的所有直属上级配置项 + private function getAncestorConfigurations($cfc, $optionId) + { + $ancestors = []; + + // 获取当前选项的配置项 + $currentConfig = $cfc->query(" + SELECT c.id, c.name, c.parent_id + FROM configurations c + JOIN options o ON c.id = o.config_id + WHERE o.id = ? + ", [$optionId]); + + if (!empty($currentConfig)) { + $currentConfig = $currentConfig[0]; + + // 获取直属上级配置项 + if ($currentConfig['parent_id']) { + $parentConfig = $cfc->query(" + SELECT c.id, c.name + FROM configurations c + WHERE c.id = ? + ", [$currentConfig['parent_id']]); + + if (!empty($parentConfig)) { + $parentConfig = $parentConfig[0]; + $ancestors[] = $parentConfig; + } + } + } + + return $ancestors; + } +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Usercenter.php b/application/KitchenScale3/controller/app/Usercenter.php new file mode 100644 index 0000000..f801a4c --- /dev/null +++ b/application/KitchenScale3/controller/app/Usercenter.php @@ -0,0 +1,892 @@ +'app_account_number',//账号表 + 'juese'=>'app_user_data',//角色表 + ]; + protected $kitchenscale_db_msg = [ + 'cookbook'=>'app_user_cookbook',//菜谱表 + 'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表 + 'uploadimg'=>'app_user_upload_img',//图片素材表 + 'foodlist1'=>'app_z_national_standard_food_type_1',//食材列表1 + 'foodlist2'=>'app_z_national_standard_food_type_2',//食材列表2 + 'foodlist3'=>'app_z_national_standard_food_type_3',//食材列表3 + 'collect_list'=>'app_user_collect_list',//点赞表 + 'banner'=>'app_banner_data',//banner + 'user'=>'app_user_data',//用户表 + 'search_history'=>'app_user_search_history',//用户搜索表 + 'business_cooperation'=>'app_business_cooperation_log',//商务合作 + 'eat_log'=>'app_user_kcal_log',//食材列表3 + ]; + protected $language_country = [ + 'zh' => '中文', // 中文(简体)★ + 'en' => 'English', // 英语(通用)★ + 'jp' => '日本語', // 日语(变化) + 'fra' => 'Français', // 法语(变化) + 'de' => 'Deutsch', // 德语 + 'kor' => '한국어', // 韩语(变化) + 'ru' => 'Русский', // 俄语 + 'pt' => 'Português', // 葡萄牙 + 'spa' => 'Español', // 西班牙(变化) + 'ara' => 'العربية', // 阿拉伯(变化) + ]; + + + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 获取角色信息 + public function get_user_msg(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $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); + } + } + // 修改用户 + public function update_user_msg(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001,'token is miss'); + } + if(!array_key_exists('nickname', $data)){ + return $this->msg(10001,'nickname is miss'); + } + if(!array_key_exists('gender', $data)){ + return $this->msg(10001,'gender is miss'); + } + if(!array_key_exists('birthday', $data)){ + return $this->msg(10001,'birthday is miss'); + } + if(!array_key_exists('height', $data)){ + return $this->msg(10001,'height is miss'); + } + if(!array_key_exists('weight', $data)){ + return $this->msg(10001,'weight is miss'); + } + if(!array_key_exists('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'); + } + if(!$this->verify_data_is_ok($data['nickname'],'str')){ + return $this->msg(10005,'nickname type is error'); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005,'gender type is error'); + } + if(!$this->verify_data_is_ok($data['birthday'],'datetime')){ + return $this->msg(10005,'birthday type is error'); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005,'height type is error'); + } + 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) { + // 捕获异常 + $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); + } + } + + // 获取用户收藏点赞列表(OK) + // public function get_user_collect_list(){ + // try { + // $data = input('post.'); + // if(!array_key_exists('token', $data)){ + // return $this->msg(10001,'token is miss'); + // } + // if(!array_key_exists('page', $data)){ + // return $this->msg(10001,'page 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['page'],'intnum')){ + // return $this->msg(10005,'page type is error'); + // } + // $return_data = $this->get_user_collect_list_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 get_my_cookbook(){ + // try { + // $data = input('post.'); + // if(!array_key_exists('token', $data)){ + // return $this->msg(10001,'token is miss'); + // } + // if(!array_key_exists('page', $data)){ + // return $this->msg(10001,'page 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['page'],'intnum')){ + // return $this->msg(10005,'page type is error'); + // } + // $return_data = $this->get_my_cookbook_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 del_my_cookbook(){ + // try { + // $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('cookbook_id', $data)){ + // return $this->msg(10001,'cookbook_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['cookbook_id'],'intnum')){ + // return $this->msg(10005,'cookbook_id type is error'); + // } + // $return_data = $this->del_my_cookbook_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 del_search_history(){ + // 尝试捕获异常 + 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('del_arr', $data)){ + return $this->msg(10001,'del_arr is miss'); + } + if(!$this->verify_data_is_ok($data['del_arr'],'str')){ + return $this->msg(10005,'del_arr 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->del_search_history_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 business_cooperation(){ + 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); + } + } + + public function update_language(){ + try { + $data = input('post.'); + if(!array_key_exists('token', $data)){ + return $this->msg(10001,'token is miss'); + } + if(!array_key_exists('language', $data)){ + return $this->msg(10001,'language is miss'); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005,'token type is error'); + } + if(!array_key_exists($data['language'],$this->language_country)){ + return $this->msg(10005,'language type is error'); + } + + $return_data = $this->update_language_action($data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "接口: (get_default_config)\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + + + + + #######################################################################action####################################################################### + #######################################################################action####################################################################### + #######################################################################action####################################################################### + + public function get_user_msg_action($data){ + // 获取账号下信息以及用户信息 + $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic,tel,email')->find(); + if(!$user_data){ + return $this->msg(10004); + } + // $return_data = []; + // 获取账号下信息以及用户信息start + $user_all_data['aud_id'] = ''; + $user_all_data['token'] = $user_data['token']; + $user_all_data['nickname'] = $user_data['nickname']; + $user_all_data['head_pic'] = $user_data['head_pic']; + $user_all_data['gender'] = ''; + $user_all_data['age'] = ''; + $user_all_data['height'] = ''; + $user_all_data['weight'] = ''; + $user_all_data['set_kcal'] = ''; + $user_all_data['is_use_set_kcal'] = ''; + $user_all_data['tel'] = $user_data['tel']; + $user_all_data['email'] = $user_data['email']; + $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,activity_level') + ->find(); + if($user_account){ + if($user_account['set_kcal'] == '.00'){ + $user_account['set_kcal'] = 0; + } + $user_all_data['aud_id'] = $user_account['aud_id']; + $user_all_data['gender'] = $user_account['gender']; + $user_all_data['age'] = $user_account['age']?$user_account['age']:$this->calculate_age($user_account['birthday']); + $user_all_data['height'] = $user_account['height']; + $user_all_data['weight'] = $user_account['weight']; + $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['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); + } + + + // $return_data = $user_all_data; + return $this->msg($user_all_data); + // 获取账号下信息以及用户信息end + } + public function update_user_msg_action($data){ + if($data['gender'] == 0){ + return $this->msg(10005,'性别信息错误'); + } + // 获取账号下信息以及用户信息 + $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count(); + if($user_data<=0){ + return $this->msg(10005,'账号信息错误'); + } + + $cfc = Db::connect('cfc_db'); + + $is_user_true = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->count(); + + $user_msg['nickname'] = $data['nickname']; + $user_msg['head_pic'] = $data['gender'] == 1?'https://tc.pcxbc.com/tsf/1.png':'https://tc.pcxbc.com/tsf/2.png'; + $user_msg['gender'] = $data['gender']; + $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'); + $result = $cfc->table($this->kitchenscale_db_msg['user']) + ->where(['token'=>$data['token']]) + ->update($user_msg); + }else{ + $user_msg['token'] = $data['token']; + $result = $cfc->table($this->kitchenscale_db_msg['user']) + ->insert($user_msg); + } + Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->update(['nickname'=>$user_msg['nickname']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + public function get_user_collect_list_action($data){ + // 获取账号下信息以及用户信息 + $user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->count(); + if($user_data<=0){ + return $this->msg(10005,'账号信息错误'); + } + + $search_sql_str = "a.token = '".$data['token']."' AND a.is_del = 0 AND b.is_del = 0"; + if(!array_key_exists('search_data', $data)){ + $data['search_data'] = ""; + }else{ + if($data['search_data'] === ""){ + $data['search_data'] = ""; + }else{ + $data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')"; + } + } + $search_sql_str = $search_sql_str.$data['search_data']; + // "a.token = 'asdasdasdasda' AND a.is_del = 0 AND b.title LIKE '%鱼%' OR b.describe_data LIKE '%鱼%'"; + + $cfc = Db::connect('cfc_db'); + + $content_num = $cfc->table($this->kitchenscale_db_msg['collect_list']) + ->alias('a') + ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT') + ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT') + ->where($search_sql_str) + ->count(); + $page_total = ceil($content_num/$this->page_num);; + $collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list']) + ->alias('a') + ->join($this->kitchenscale_db_msg['cookbook'].' b','a.cookbook_id = b.id','LEFT') + ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT') + ->where($search_sql_str) + ->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname") + ->page($data['page'],$this->page_num) + ->select(); + + foreach ($collect_list as $key => $value) { + $collect_list[$key]['is_me_like_it'] = 'yes'; + + } + + return $this->msg([ + 'page_now'=>$data['page'], + 'page_total'=>$page_total, + '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(); + if($user_data<=0){ + return $this->msg(10005,'账号信息错误'); + } + + $search_sql_str = "b.create_user_token = '".$data['token']."' AND b.is_del = 0"; + if(!array_key_exists('search_data', $data)){ + $data['search_data'] = ""; + }else{ + if($data['search_data'] === ""){ + $data['search_data'] = ""; + }else{ + $data['search_data'] = " AND (b.title LIKE '%".$data['search_data']."%' OR b.describe_data LIKE '%".$data['search_data']."%')"; + } + } + $search_sql_str = $search_sql_str.$data['search_data']; + + $cfc = Db::connect('cfc_db'); + $content_num = $cfc->table($this->kitchenscale_db_msg['cookbook']) + ->alias('b') + ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT') + ->where($search_sql_str) + ->count(); + $page_total = ceil($content_num/$this->page_num);; + $content_list = $cfc->table($this->kitchenscale_db_msg['cookbook']) + ->alias('b') + ->join($this->kitchenscale_db_msg['uploadimg'].' c','b.cover = c.id','LEFT') + ->where($search_sql_str) + ->field("b.id,b.title,b.cover as cover_id,c.pic_url as cover_url,b.likes_num,b.create_user_token,b.create_user_head_pic,b.create_user_nickname") + ->page($data['page'],$this->page_num) + ->select(); + + // 获取用户收藏列表 + $my_collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list']) + ->where(['token'=>$data['token'],'is_del'=>0]) + ->column('cookbook_id'); + // dump($my_collect_list); + // 处理菜谱收藏信息 + foreach ($content_list as $key => $value) { + // if(in_array($value['id'],$my_collect_list)){ + if(array_key_exists($value['id'],$my_collect_list)){ + $content_list[$key]['is_me_like_it'] = 'yes'; + }else{ + $content_list[$key]['is_me_like_it'] = 'no'; + } + // if($value['cover'] == null){ + // $content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg'; + // } + unset($content_list[$key]['ROW_NUMBER']); + } + + // foreach ($collect_list as $key => $value) { + // $collect_list[$key]['is_me_like_it'] = 'yes'; + + // } + + return $this->msg([ + 'page_now'=>$data['page'], + 'page_total'=>$page_total, + '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(); + if($user_data<=0){ + return $this->msg(10005,'账号信息错误'); + } + + $cfc = Db::connect('cfc_db'); + + $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id'],'create_user_token'=>$data['token']])->find(); + + if($cookbook_data){ + + // 启动事务 + $cfc->startTrans(); + try{ + $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->update(['is_del'=>1]); + $result_banner = $cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->count(); + if($result_banner > 0){ + $cfc->table($this->kitchenscale_db_msg['banner'])->where(['cookbook_id'=>$cookbook_data['id']])->update(['is_del'=>1]); + } + // 提交事务 + $cfc->commit(); + return $this->msg([]); + } catch (\Exception $e) { + // 回滚事务 + $cfc->rollback(); + return $this->msg(10002); + } + }else{ + return $this->msg(10003); + } + + } + public function del_search_history_action($data){ + + // $data['del_arr'] = strval($data['del_arr']); + // $data['del_arr'] = trim($data['del_arr']); + + // // 正确的判断逻辑:如果不是all 并且 不是ID列表,就报错 + // if (strtolower($data['del_arr']) !== 'all' && preg_match('/^\d+(,\d+)*$/', $data['del_arr']) !== 1) { + // return $this->msg(10005, 'del_arr type is error'); + // } + + + + $cfc = Db::connect('cfc_db'); + $user = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,token')->find(); + if(!$user){ + return $this->msg(20001,'账号信息错误'); + } + if($data['del_arr'] == 'all'){ + $result = $cfc->table($this->kitchenscale_db_msg['search_history']) + ->where(['user_id'=>$user['id']]) + ->update(['is_del'=>1]); + }else{ + $result = $cfc->table($this->kitchenscale_db_msg['search_history']) + ->where("user_id = ".$user['id']." AND id IN (".$data['del_arr'].")") + ->update(['is_del'=>1]); + } + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + + + // 获取菜谱分类标签end + } + public function business_cooperation_action(){ + $data = input(); + + $cfc = Db::connect('cfc_db'); + $result = $cfc->table($this->kitchenscale_db_msg['business_cooperation']) + ->insert([ + 'name'=>$data['name'], + 'tel'=>$data['phone'], + 'company'=>$data['company'], + 'intention_data'=> implode(',',$data['selectedValues']), + 'notes_data'=>$data['remark'], + 'create_time'=>date('Y-m-s H:i:s'), + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + public function set_nutrition_proportion_action($data){ + $cfc = Db::connect('cfc_db'); + $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{ + return $this->msg(10002); + } + } + 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 $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); + } + } + + public function update_language_action($data){ + $cfc = Db::connect('cfc_db'); + $result = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->update(['language'=>$data['language']]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg([10002]); + } + } + + + + + + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/controller/app/Wechat.php b/application/KitchenScale3/controller/app/Wechat.php new file mode 100644 index 0000000..93e3013 --- /dev/null +++ b/application/KitchenScale3/controller/app/Wechat.php @@ -0,0 +1,121 @@ +getSessionKey($code); + + if (empty($sessionData['openid']) || empty($sessionData['session_key'])) { + // throw new Exception('获取openid或session_key失败'); + // return false; + // return $this->msg(10001); + return ['code'=>10002,'msg'=>'获取openid或session_key失败']; + } + + // 2. 解密用户信息 + $userInfo = $this->decryptData($encryptedData, $iv, $sessionData['session_key']); + + if(array_key_exists('phoneNumber',$userInfo)){ + return ['code'=>0,'msg'=>'seccess','data'=>$userInfo]; + }else{ + return ['code'=>10002,'msg'=>'解密用户信息失败']; + } + // if (empty($userInfo['phoneNumber'])) { + // // throw new Exception('获取手机号失败'); + + // }else{ + + // } + + // // 3. 保存或更新用户信息 + // $user = User::where('openid', $sessionData['openid'])->find(); + // if (!$user) { + // $user = new User(); + // $user->openid = $sessionData['openid']; + // } + // $user->phone = $userInfo['phoneNumber']; + // $user->save(); + + // 返回成功信息 + // return ['code' => 0, 'msg' => '登录成功', 'data' => $user]; + // } catch (Exception $e) { + // // 返回错误信息 + // return ['code' => 500, 'msg' => $e->getMessage()]; + // } + } + /** + * 通过code获取openid和session_key + * + * @param string $code + * @return array + * @throws Exception + */ + private function getSessionKey($code) + { + $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$this->app_id}&secret={$this->app_secret}&js_code={$code}&grant_type=authorization_code"; + $result = file_get_contents($url); + $data = json_decode($result, true); + + if (isset($data['openid']) && isset($data['session_key'])) { + return $data; + } else { + return ['code'=>10002,'msg'=>'获取openid或session_key失败']; + } + } + + /** + * 解密用户信息 + * + * @param string $encryptedData + * @param string $iv + * @param string $sessionKey + * @return array + * @throws Exception + */ + private function decryptData($encryptedData, $iv, $sessionKey) + { + // require_once 'wx_crypt/WXBizDataCrypt.php'; // 引入微信解密类 + // require_once env('root_path') . 'extend/wx_crypt/WXBizDataCrypt.php'; + // dump(ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php'); + require_once ROOT_PATH . 'extend\wx_crypt\wxBizDataCrypt.php'; + + $pc = new \WXBizDataCrypt($this->app_id, $sessionKey); + $errCode = $pc->decryptData($encryptedData, $iv, $data); + + if ($errCode == 0) { + return json_decode($data, true); + } else { + return ['code'=>10002,'msg'=>'解密用户信息失败('.$errCode.')']; + // throw new Exception('解密失败: ' . $errCode); + } + } + + + // 注册 + + + +} \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/base/pic_index.html b/application/KitchenScale3/view/admin/base/pic_index.html new file mode 100644 index 0000000..ae123b5 --- /dev/null +++ b/application/KitchenScale3/view/admin/base/pic_index.html @@ -0,0 +1,209 @@ + + + + + 图片管理 + + + + + + + + + + + + +
+
+ {volist name="result" id="vo"} +
+ {/volist} +
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/cookbook/add_cookbook.html b/application/KitchenScale3/view/admin/cookbook/add_cookbook.html new file mode 100644 index 0000000..9480e45 --- /dev/null +++ b/application/KitchenScale3/view/admin/cookbook/add_cookbook.html @@ -0,0 +1,420 @@ + + + + + + 菜谱管理 + + + + + + + + + + + +
+
+
+
+ +
+ +
+
+ +
+ +
+
点击选择
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + +
+
+
+ +
+
+ +
+ +
+
+
+
+ + +
+
+ 步骤图片预览 + +
+ + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/cookbook/card_edit.html b/application/KitchenScale3/view/admin/cookbook/card_edit.html new file mode 100644 index 0000000..d448a5c --- /dev/null +++ b/application/KitchenScale3/view/admin/cookbook/card_edit.html @@ -0,0 +1,232 @@ + + + + + + app版本管理 + + + + + + + + + + + + +
+
+
+
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/cookbook/index.html b/application/KitchenScale3/view/admin/cookbook/index.html new file mode 100644 index 0000000..1e7f477 --- /dev/null +++ b/application/KitchenScale3/view/admin/cookbook/index.html @@ -0,0 +1,288 @@ + + + + + 所有卡片管理 + + + + + + + + + + + +
+
+
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + {volist name="result" id="vo"} + + + + + + + + + + + + {/volist} + +
ID食谱名称预览图创建人点赞数阅读数创建时间状态操作
{$vo.id}{$vo.title}{$vo.create_user_nickname}{$vo.likes_num}{$vo.read_it}{$vo.create_time} + {if condition="$vo.is_del == 1"} + 已停用 + {else /} + 已启用 + {/if} + + +
+
+
+
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/index/index.html b/application/KitchenScale3/view/admin/index/index.html new file mode 100644 index 0000000..2e3e1f9 --- /dev/null +++ b/application/KitchenScale3/view/admin/index/index.html @@ -0,0 +1,230 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+ +
+ + + +
+
+
    +
  • + 我的桌面
+
+
+
关闭当前
+
关闭其它
+
关闭全部
+
+
+
+ +
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/index/welcome.html b/application/KitchenScale3/view/admin/index/welcome.html new file mode 100644 index 0000000..f362ddd --- /dev/null +++ b/application/KitchenScale3/view/admin/index/welcome.html @@ -0,0 +1,219 @@ + + + + + 欢迎页面-X-admin2.2 + + + + + + + + + + +
+
+ +
+
+
最新一周新增用户
+
+
+ +
+
+
+
+
+
最新一周PV/UV量
+
+
+ +
+
+
+
+
+
用户来源
+
+
+ +
+
+
+
+
+
硬盘使用量
+
+
+ +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/KitchenScale3/view/admin/login/login.html b/application/KitchenScale3/view/admin/login/login.html new file mode 100644 index 0000000..56b9866 --- /dev/null +++ b/application/KitchenScale3/view/admin/login/login.html @@ -0,0 +1,77 @@ + + + + + 后台登录-X-admin2.2 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/application/KitchenScale3/view/app/usercenter/business_cooperation.html b/application/KitchenScale3/view/app/usercenter/business_cooperation.html new file mode 100644 index 0000000..7b0a490 --- /dev/null +++ b/application/KitchenScale3/view/app/usercenter/business_cooperation.html @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + 商务合作 + + + + + + + +
+
+ +
+
商务合作意向登记表
+
+ +
+
+
+ *  1.姓名 +
+
+ +
+
+
+
+ *  2.联系电话 +
+
+ +
+
+
+
+ *  3.行业 +
+
+ +
+
+
+
+ *  4.合作意向 +
+
+
+
此题已选择 0/4 项
+
+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+ *  5.备注 +
+
+ +
+
+
+ 商务合作电话/微信:13590959084 +
+ +
+
提交
+
+
+ + + + \ No newline at end of file diff --git a/application/route.php b/application/route.php index e88e51d..2d7b7ac 100644 --- a/application/route.php +++ b/application/route.php @@ -461,8 +461,8 @@ Route::any('/open_wechat_content', 'app/Msginformation/open_wechat_content'); -################################################################下面是厨房秤################################################################ -########################################################################################################################################### +################################################################下面是厨房秤(国内版)################################################################ +#################################################################################################################################################### #########################################################前端接口############################################################ // 微信小程序快捷登录接口 @@ -640,6 +640,96 @@ Route::any('/k/a/cookbook/find_food_list', 'app/kitchenscale/admin.cookbook/find Route::any('/k/a/cookbook/stop_and_run', 'app/kitchenscale/admin.cookbook/stop_and_run'); +################################################################下面是厨房秤(国际版)################################################################ +#################################################################################################################################################### + +#########################################################前端接口############################################################ + + +// 公共内容################################################################ + + + +// 首页内容################################################################ +// 检测版本及判断是否登录失效 +Route::any('/kitchenscale2/login_invalid_version', 'app/kitchenscale2/app.Index/login_invalid_version'); +// 获取配置类信息 +Route::any('/kitchenscale2/get_default_config', 'app/Kitchenscale2/app.Index/get_default_config'); +// 首页搜索接口 +Route::any('/kitchenscale2/search_column', 'app/kitchenscale2/app.index/search_column'); + + +// 菜谱内容################################################################ + +// 根据菜谱标签查询列表(首页用) +// Route::any('/kitchenscale2/find_by_cook_label', 'app/kitchenscale2/app.cookbook/find_by_cook_label'); +// 根据食材详细查找列表 +// Route::any('/kitchenscale2/find_by_food', 'app/kitchenscale2/app.cookbook/find_by_food'); +// 查询食谱的详情 +// Route::any('/kitchenscale2/cookbook_details', 'app/kitchenscale2/app.cookbook/cookbook_details'); +// 收藏菜谱 +// Route::any('/kitchenscale2/cookbook_like', 'app/kitchenscale2/app.cookbook/cookbook_like'); +// 获取当前食材重量卡路里 +// Route::any('/kitchenscale2/food_count_kcal', 'app/kitchenscale2/app.cookbook/food_count_kcal'); +// 食材列表查询接口 +Route::any('/kitchenscale2/find_food', 'app/kitchenscale2/app.cookbook/find_food'); +// 获取所有食材列表 +Route::any('/kitchenscale2/get_food_list', 'app/kitchenscale2/app.cookbook/get_food_list'); +// 获取查询页页面导航食材列表 +Route::any('/kitchenscale2/get_search_food_page_list', 'app/kitchenscale2/app.cookbook/get_search_food_page_list'); + + +// 计食器################################################################ +// 添加每日摄入记录 +Route::any('/kitchenscale2/add_intake_food', 'app/kitchenscale2/app.countfood/add_intake_food'); +// 获取记食器板块内容 +Route::any('/kitchenscale2/get_countfoot_content', 'app/kitchenscale2/app.countfood/get_countfoot_content'); +// 获取记食器记录 +Route::any('/kitchenscale2/get_log_list', 'app/kitchenscale2/app.countfood/get_log_list'); +// 计食器板块-设置内容 +Route::any('/kitchenscale2/set_up_content', 'app/kitchenscale2/app.countfood/set_up_content'); +// 删除用户某个饮食记录 +Route::any('/kitchenscale2/del_user_eat_log', 'app/kitchenscale/app.countfood/del_user_eat_log'); +// 删除用户某个饮食记录 +Route::any('/kitchenscale2/del_user_eat_list_log', 'app/kitchenscale2/app.countfood/del_user_eat_list_log'); +// 获取指定饮食记录的四大营养分析 +Route::any('/kitchenscale2/current_food_statistics', 'app/kitchenscale2/app.countfood/current_food_statistics'); + + + + + +// 我的################################################################ +// 获取角色信息 +Route::any('/kitchenscale2/get_user_msg', 'app/kitchenscale2/app.usercenter/get_user_msg'); +// 修改角色信息 +Route::any('/kitchenscale2/update_user_msg', 'app/kitchenscale2/app.usercenter/update_user_msg'); +// 账号收藏点赞列表 +// Route::any('/kitchenscale2/get_user_collect_list', 'app/kitchenscale2/app.usercenter/get_user_collect_list'); +// 我的菜谱 +// Route::any('/kitchenscale2/get_my_cookbook', 'app/kitchenscale2/app.usercenter/get_my_cookbook'); +// 菜谱删除 +// Route::any('/kitchenscale2/del_my_cookbook', 'app/kitchenscale2/app.usercenter/del_my_cookbook'); +// 删除用户搜索记录 +Route::any('/kitchenscale2/del_search_history', 'app/kitchenscale2/app.usercenter/del_search_history'); +// 商务合作 +Route::any('/kitchenscale2/business_cooperation', 'app/kitchenscale2/app.usercenter/business_cooperation'); +// 商务合作提交 +Route::any('/kitchenscale2/business_cooperation_action', 'app/kitchenscale2/app.usercenter/business_cooperation_action'); +// ☆设置用户的卡路里&营养占比 +Route::any('/kitchenscale2/set_user_kcal', 'app/kitchenscale2/app.usercenter/set_nutrition_proportion'); +// ☆重置密码 +Route::any('/kitchenscale2/update_my_password', 'app/kitchenscale2/app.usercenter/update_my_password'); +// ☆修改个人信息 +Route::any('/kitchenscale2/update_my_account_msg', 'app/kitchenscale2/app.usercenter/update_my_account_msg'); +// ☆修改语言设置(多语言) +Route::any('/kitchenscale2/update_language', 'app/kitchenscale2/app.usercenter/update_language'); + + +#########################################################管理后台############################################################ + + + ################################################################下面是增杰SN码打印################################################################ ################################################################################################################################################