2025-11-21 19:13:01 +08:00
< ? php
namespace app\KitchenScale2\controller\app ;
use think\Db ;
2025-11-28 19:45:05 +08:00
use app\KitchenScale2\controller\app\Guessyoulike ;
2025-11-21 19:13:01 +08:00
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' , //用户表
'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' , //菜谱表
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 检测版本及判断是否登录失效
public function login_invalid_version ( $data = [ 'token' => '' ]){
try {
// 你的业务逻辑
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 ( $this -> token_time_validate ( $data [ 'token' ]) === false ){
$this -> record_api_log ( $data , null , [ 'code' =>- 1 , 'msg' => '未登录' ,[ 'version' => $version , 'url' => $url ]]);
return $this -> msg ( - 1 , '未登录' ,[ 'version' => $version , 'url' => $url ]);
} else {
$this -> record_api_log ( $data , null , [ 'code' => 0 , 'msg' => 'success' ,[ 'version' => $version , 'url' => $url ]]);
return $this -> msg ([ 'version' => $version , 'url' => $url ]);
}
} 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 $this -> msg ( 99999 );
}
}
// 微信手机号快捷登录
public function wechat_quick_login ( $data = [ 'code' => 'asdasdasd' , 'encryptedData' => 'adsadasdasd' , 'iv' => 'asdasdasdasd' ]){
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 ();
// die;
$result = $wechatService -> handleWechatLogin ( $data [ 'code' ], $data [ 'encryptedData' ], $data [ 'iv' ]);
// dump($result);
// die;
if ( $result [ 'code' ] == 0 ){
// return $this->msg($result['code'],$result['msg']);
$user_data = Db :: table ( $this -> reedaw_db_msg [ 'zhanghao' ]) -> where ([ 'tel' => $result [ 'data' ][ 'phoneNumber' ], 'is_del' => 0 ]) -> find ();
if ( $user_data ){
Db :: table ( $this -> reedaw_db_msg [ 'zhanghao' ]) -> 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 -> reedaw_db_msg [ 'zhanghao' ]) -> 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' ] .= " 方法: (wechat_quick_login) " . " \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_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' => [],
],
],
2025-11-28 19:45:05 +08:00
],
'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' ],
],
2025-11-21 19:13:01 +08:00
];
$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' )
2025-11-28 19:45:05 +08:00
-> limit ( 10 )
2025-11-21 19:13:01 +08:00
-> 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' )
2025-11-28 19:45:05 +08:00
-> limit ( 10 )
2025-11-21 19:13:01 +08:00
-> 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 {
}
2025-11-28 19:45:05 +08:00
// 处理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;
2025-11-21 19:13:01 +08:00
// 处理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
2025-11-28 19:45:05 +08:00
$cookbook_label = $cfc -> table ( $this -> kitchenscale_db_msg [ 'cookbook_label' ]) -> where ([ " is_del " => 0 ]) -> field ( 'id,name' ) -> select ();
$return_data [ 'cookbook_label' ] = $cookbook_label ;
2025-11-21 19:13:01 +08:00
// 添加菜谱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 ;
}
}