859 lines
38 KiB
PHP
859 lines
38 KiB
PHP
<?php
|
||
|
||
namespace app\KitchenScale3\controller\app;
|
||
|
||
use think\Db;
|
||
use app\KitchenScale3\controller\app\Guessyoulike;
|
||
use app\KitchenScale3\controller\app\Language;
|
||
|
||
class Index extends Base{
|
||
|
||
protected $code_time = 50;
|
||
// protected $token_time = 2592000;//30天的秒数
|
||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||
// protected $reedaw_db_msg = [
|
||
// 'zhanghao'=>'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_multilingual',//用户表
|
||
'kcal_log'=>'app_user_kcal_log',//饮食记录表
|
||
'search_history'=>'app_user_search_history_multilingual',//搜索历史表
|
||
'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')->field('id,version_num_original,download_url,is_del')->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'=>'zh']);
|
||
}else{
|
||
$user_token_state = $this->token_time_validate($data['token']);
|
||
if($user_token_state === false){
|
||
return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>'zh']);
|
||
}else{
|
||
$language_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,language')->find();
|
||
$language_str = $this->language_country[$language_data['language']][1];
|
||
return $this->msg(['version'=>$version,'url'=>$url,'language'=>$language_str]);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// dump($data);
|
||
|
||
|
||
|
||
// dump($user_token_state);
|
||
// dump($language_data);
|
||
|
||
// if($user_token_state['state'] === false){
|
||
// if($user_token_state === false){
|
||
// return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url,'language'=>'zh']);
|
||
// }else{
|
||
// $language_data = $cfc->table($this->kitchenscale_db_msg['user'])->where(['token'=>$data['token']])->field('id,language')->find();
|
||
// if(array_key_exists('language',$language_data)){
|
||
// $language_data = $language_data['language'];
|
||
// }else{
|
||
// $language_data = 'zh';
|
||
// }
|
||
// 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
|
||
}
|
||
}else{
|
||
|
||
}
|
||
// dump($user['language']);
|
||
// 处理猜你喜欢信息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',null,$user['language']);
|
||
// dump($food_data);
|
||
// die;
|
||
// 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
|
||
|
||
|
||
if($user){
|
||
if($user['language'] != 'zh'){
|
||
$Language_action = new Language;
|
||
|
||
$return_data = $Language_action->handling_languages_from_multiple_countries($user['language'],$return_data);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
} |