2025-01-04 19:08:03 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\KitchenScale\controller\app;
|
|
|
|
|
|
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
|
|
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 = [
|
2025-01-22 12:31:08 +08:00
|
|
|
|
'zhanghao'=>'app_account_number',//账号表
|
|
|
|
|
|
'juese'=>'app_user_data',//角色表
|
|
|
|
|
|
];
|
|
|
|
|
|
protected $kitchenscale_db_msg = [
|
|
|
|
|
|
'cookbook'=>'app_user_cookbook',//菜谱表
|
2025-03-12 18:03:31 +08:00
|
|
|
|
'cookbook_label'=>'app_user_cookbook_label',//菜谱标签表
|
2025-03-07 11:42:26 +08:00
|
|
|
|
'uploadimg'=>'app_user_upload_img',//图片素材表
|
|
|
|
|
|
'foodlist1'=>'app_food_type_one',//食材列表1
|
|
|
|
|
|
'foodlist2'=>'app_food_type_two',//食材列表2
|
|
|
|
|
|
'foodlist3'=>'app_food_type_three',//食材列表3
|
2025-03-12 18:03:31 +08:00
|
|
|
|
'collect_list'=>'app_user_collect_list',//点赞表
|
|
|
|
|
|
'banner'=>'app_banner_data',//banner
|
2025-01-04 19:08:03 +08:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 加 bcadd(,,20)
|
|
|
|
|
|
// 减 bcsub(,,20)
|
|
|
|
|
|
// 乘 bcmul(,,20)
|
|
|
|
|
|
// 除 bcdiv(,,20)
|
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
################################################################接口################################################################
|
|
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
// 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK)
|
|
|
|
|
|
public function get_default_config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
2025-01-04 19:08:03 +08:00
|
|
|
|
// try {
|
2025-03-07 11:42:26 +08:00
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
|
$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_default_config_action($data);
|
2025-01-04 19:08:03 +08:00
|
|
|
|
return $return_data;
|
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
|
// // 捕获异常
|
|
|
|
|
|
// $logContent["flie"] = $e->getFile();
|
|
|
|
|
|
// $logContent["line"] = $e->getLine();
|
|
|
|
|
|
// $logContent['all_content'] = "异常信息:\n";
|
|
|
|
|
|
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
2025-03-07 11:42:26 +08:00
|
|
|
|
// $logContent['all_content'] .= "接口: (get_default_config)\n";
|
2025-01-04 19:08:03 +08:00
|
|
|
|
// $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);
|
|
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
// 获取首页信息(banner,金刚区,label_list)(OK)
|
2025-01-22 12:31:08 +08:00
|
|
|
|
public function get_homepage_information($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// try {
|
2025-01-04 19:08:03 +08:00
|
|
|
|
// 你的业务逻辑
|
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
|
$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_homepage_information_action($data);
|
|
|
|
|
|
// 成功
|
|
|
|
|
|
$this->record_api_log($data, null, $return_data);
|
|
|
|
|
|
return $return_data;
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// } 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_homepage_information)\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);
|
|
|
|
|
|
// }
|
2025-03-07 11:42:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 首页搜索接口(OK)
|
|
|
|
|
|
public function search_column($data = ['search_data'=>'鱼','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// try {
|
2025-03-07 11:42:26 +08:00
|
|
|
|
// 你的业务逻辑
|
|
|
|
|
|
if(count(input('post.')) > 0){
|
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!array_key_exists('search_data', $data) || !array_key_exists('token', $data)){
|
|
|
|
|
|
return $this->msg(10001);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!$this->verify_data_is_ok($data['search_data'],'str')){
|
|
|
|
|
|
return $this->msg(10005);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!$this->verify_data_is_ok($data['token'],'str')){
|
|
|
|
|
|
return $this->msg(10005);
|
|
|
|
|
|
}
|
|
|
|
|
|
$return_data = $this->search_column_action($data);
|
|
|
|
|
|
return $return_data;
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// } 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);
|
|
|
|
|
|
// }
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}
|
2025-01-22 12:31:08 +08:00
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
#######################################################################action#######################################################################
|
|
|
|
|
|
#######################################################################action#######################################################################
|
2025-01-04 19:08:03 +08:00
|
|
|
|
#######################################################################action#######################################################################
|
|
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
public function get_default_config_action($data){
|
2025-01-22 12:31:08 +08:00
|
|
|
|
$return_data = [
|
|
|
|
|
|
'food_list'=>[],
|
2025-03-12 18:03:31 +08:00
|
|
|
|
'cook_label'=>[],
|
2025-03-07 11:42:26 +08:00
|
|
|
|
'account'=>[],
|
2025-01-22 12:31:08 +08:00
|
|
|
|
];
|
2025-03-12 18:03:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-01-22 12:31:08 +08:00
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// 获取食材分类列表start
|
|
|
|
|
|
$foodlist1 = $cfc->table($this->kitchenscale_db_msg['foodlist1'])->where("is_del = 0")->field('id,name')->select();
|
|
|
|
|
|
$foodlist2 = $cfc->table($this->kitchenscale_db_msg['foodlist2'])->where("is_del = 0")->field('id,name,one_id')->select();
|
|
|
|
|
|
$foodlist3 = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("is_del = 0")->field('id,name,two_id,kcal')->select();
|
|
|
|
|
|
// dump($foodlist3);
|
|
|
|
|
|
foreach ($foodlist1 as $key => $value) {
|
|
|
|
|
|
unset($foodlist1[$key]['ROW_NUMBER']);
|
|
|
|
|
|
$foodlist1[$key]['list'] = [];
|
|
|
|
|
|
foreach ($foodlist2 as $k => $v) {
|
|
|
|
|
|
$foodlist2[$k]['list'] = [];
|
|
|
|
|
|
foreach ($foodlist3 as $k3 => $v3) {
|
|
|
|
|
|
if($v3['two_id'] == $v['id']){
|
|
|
|
|
|
unset($foodlist3[$k3]['ROW_NUMBER']);
|
2025-03-12 18:03:31 +08:00
|
|
|
|
$foodlist3[$k3]['one_id'] = $v['one_id'];
|
2025-01-22 12:31:08 +08:00
|
|
|
|
array_push($foodlist2[$k]['list'],$foodlist3[$k3]);
|
|
|
|
|
|
// unset($foodlist3[$k3]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if($v['one_id'] == $value['id']){
|
|
|
|
|
|
unset($foodlist2[$k]['ROW_NUMBER']);
|
|
|
|
|
|
array_push($foodlist1[$key]['list'],$foodlist2[$k]);
|
|
|
|
|
|
// unset($foodlist2[$k]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$return_data['food_list'] = $foodlist1;
|
|
|
|
|
|
// 获取食材分类列表end
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// 获取菜谱分类标签start
|
|
|
|
|
|
$cook_label = $cfc->table($this->kitchenscale_db_msg['cookbook_label'])
|
|
|
|
|
|
->where("is_del = 0")
|
|
|
|
|
|
->field('id,name')
|
|
|
|
|
|
->select();
|
|
|
|
|
|
foreach ($cook_label as $key => $value) {
|
|
|
|
|
|
unset($cook_label[$key]['ROW_NUMBER']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$return_data['cook_label'] = $cook_label;
|
|
|
|
|
|
// 获取菜谱分类标签end
|
2025-03-07 11:42:26 +08:00
|
|
|
|
// 获取账号下信息以及用户信息start
|
|
|
|
|
|
$user_account = Db::table($this->reedaw_db_msg['zhanghao'])
|
|
|
|
|
|
->alias('zhanghao')
|
|
|
|
|
|
->join($this->reedaw_db_msg['juese'].' juese','zhanghao.id = juese.aan_id','LEFT')
|
|
|
|
|
|
->where(["zhanghao.token"=>$data['token'],'juese.is_del'=>0])
|
|
|
|
|
|
->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.grade,juese.head_pic')
|
|
|
|
|
|
->select();
|
|
|
|
|
|
$return_data['account'] = $user_account;
|
|
|
|
|
|
// 获取账号下信息以及用户信息end
|
2025-01-22 12:31:08 +08:00
|
|
|
|
return $this->msg($return_data);
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function get_homepage_information_action($data){
|
|
|
|
|
|
|
|
|
|
|
|
$return_data = [
|
|
|
|
|
|
'banner'=>[],
|
2025-03-07 11:42:26 +08:00
|
|
|
|
'jingang_region'=>[
|
|
|
|
|
|
['name'=>'菜谱分类','jump_url'=>'/xxx/xxx/xxx','icon'=>'/xxx/xxx/xxx'],
|
|
|
|
|
|
['name'=>'我的收藏','jump_url'=>'/xxx/xxx/xxx','icon'=>'/xxx/xxx/xxx'],
|
|
|
|
|
|
['name'=>'热量计算','jump_url'=>'/xxx/xxx/xxx','icon'=>'/xxx/xxx/xxx'],
|
|
|
|
|
|
['name'=>'健康食谱','jump_url'=>'/xxx/xxx/xxx','icon'=>'/xxx/xxx/xxx'],
|
2025-01-22 12:31:08 +08:00
|
|
|
|
],
|
2025-01-04 19:08:03 +08:00
|
|
|
|
];
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
2025-01-22 12:31:08 +08:00
|
|
|
|
|
2025-01-04 19:08:03 +08:00
|
|
|
|
// 获取banner
|
2025-03-12 18:03:31 +08:00
|
|
|
|
$banner_list = $cfc->query("select b.id,b.title,b.cover,b.create_user_head_pic,b.create_user_nickname
|
|
|
|
|
|
from ".$this->kitchenscale_db_msg['banner']." as a
|
|
|
|
|
|
LEFT JOIN ".$this->kitchenscale_db_msg['cookbook']." as b
|
|
|
|
|
|
on a.cookbook_id = b.id
|
|
|
|
|
|
where a.is_del=0
|
|
|
|
|
|
ORDER BY a.sort_num desc,a.id desc
|
|
|
|
|
|
");
|
|
|
|
|
|
$collect_list = $cfc->table($this->kitchenscale_db_msg['collect_list'])->where(['token'=>$data['token']])->column('cookbook_id');
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-04 19:08:03 +08:00
|
|
|
|
foreach ($banner_list as $key => $value) {
|
2025-03-12 18:03:31 +08:00
|
|
|
|
if(array_key_exists($value['id'],$collect_list)){
|
|
|
|
|
|
$banner_list[$key]['is_me_like_it'] = 1;
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}else{
|
2025-03-12 18:03:31 +08:00
|
|
|
|
$banner_list[$key]['is_me_like_it'] = 0;
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
unset($banner_list[$key]['ROW_NUMBER']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$return_data['banner'] = $banner_list;
|
|
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
|
2025-01-04 19:08:03 +08:00
|
|
|
|
// 获取菜谱列表
|
2025-03-12 18:03:31 +08:00
|
|
|
|
// $label_list = $cfc->query("select id,name from ".$this->kitchenscale_db_msg['cookbook_label']." where is_del=0 ORDER BY id");
|
|
|
|
|
|
// if(count($label_list) <= 0){
|
|
|
|
|
|
// $return_data['label_list'] = [];
|
|
|
|
|
|
// return $this->msg($return_data);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// $return_data['label_list'] = $label_list;
|
2025-03-07 11:42:26 +08:00
|
|
|
|
return $this->msg($return_data);
|
2025-01-04 19:08:03 +08:00
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function search_column_action($data){
|
|
|
|
|
|
$cookbook = new Cookbook();
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// 获取菜谱信息
|
2025-01-22 12:31:08 +08:00
|
|
|
|
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
2025-03-07 11:42:26 +08:00
|
|
|
|
->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']."%'")
|
2025-03-12 18:03:31 +08:00
|
|
|
|
->field("cookbook.id,cookbook.title,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.likes_num,uploadimg.pic_url as cover")
|
2025-01-22 12:31:08 +08:00
|
|
|
|
->select();
|
2025-03-07 11:42:26 +08:00
|
|
|
|
if(count($content_list)<=0){
|
|
|
|
|
|
return $this->msg([]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取用户收藏列表
|
|
|
|
|
|
$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'] = 1;
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$content_list[$key]['is_me_like_it'] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if($value['cover'] == null){
|
|
|
|
|
|
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
2025-01-22 12:31:08 +08:00
|
|
|
|
}
|
2025-03-07 11:42:26 +08:00
|
|
|
|
unset($content_list[$key]['ROW_NUMBER']);
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-07 11:42:26 +08:00
|
|
|
|
return $this->msg($content_list);
|
2025-01-04 19:08:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|