SchoolPhysicalExamination/application/KitchenScale/controller/app/Index.php

209 lines
9.5 KiB
PHP
Raw Normal View History

<?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',//角色表
'banner'=>'admin_notice_banner',//banner
'read_log'=>'admin_editor_text_like_up_log',//阅读记录
'cookbook'=>'app_user_cookbook',//菜谱表
'upload_img'=>'app_user_upload_img',//素材表
];
protected $kitchenscale_db_msg = [
'cookbook'=>'app_user_cookbook',//菜谱表
'uploadimg'=>'app_user_upload_img',//素材表
'foodlist1'=>'app_food_type_one',//素材表
'foodlist2'=>'app_food_type_two',//素材表
'foodlist3'=>'app_food_type_three',//素材表
];
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
2025-01-22 12:31:08 +08:00
// 获取默认配置信息(包含:食材的分类列表)
public function get_default_config(){
// try {
2025-01-22 12:31:08 +08:00
$return_data = $this->get_default_config_action();
// 成功
2025-01-22 12:31:08 +08:00
// $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'] .= "行号: " . $e->getLine() . "\n";
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
// $this->record_api_log($data, $logContent, null);
// return $this->msg(99999);
// }
}
// 获取首页信息
2025-01-22 12:31:08 +08:00
public function get_homepage_information($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
// try {
// 你的业务逻辑
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;
// } 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);
// }
}
2025-01-22 12:31:08 +08:00
#######################################################################action#######################################################################
public function get_default_config_action(){
2025-01-22 12:31:08 +08:00
$return_data = [
'food_list'=>[],
];
$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']);
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
return $this->msg($return_data);
}
public function get_homepage_information_action($data){
$return_data = [
'account'=>[],
'banner'=>[],
2025-01-22 12:31:08 +08:00
'content'=>[
'label_list'=>[],
'content_list'=>[],
],
];
$cfc = Db::connect('cfc_db');
2025-01-22 12:31:08 +08:00
// 获取账号下信息以及用户信息
$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])
2025-01-22 12:31:08 +08:00
// ->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.last_update_time,juese.grade,juese.head_pic,juese.weight,juese.height,juese.identity_name,juese.address,juese.identity_id,juese.weight')
->field('juese.id as aud_id,juese.nickname,juese.birthday,juese.gender,juese.grade,juese.head_pic')
->select();
$return_data['account'] = $user_account;
// 获取banner
$banner_list = Db::table($this->reedaw_db_msg['banner'])
->where("is_del = 0 AND scene_data IN (21)")
->order('sort_num desc,id desc')
->field('id,title,pic,type,jump_url,create_time,scene_data,sort_num,parameter_data')
->select();
foreach ($banner_list as $key => $value) {
if($value['type'] == '1'){
$banner_list[$key]['type'] = 'h5';
$banner_list[$key]['id'] = $value['parameter_data'];
}else{
$banner_list[$key]['type'] = 'wechat';
// 提取查询字符串部分(?后面的部分)
$queryString = substr($banner_list[$key]['jump_url'], strpos($banner_list[$key]['jump_url'], '?') + 1);
// 使用parse_str解析查询字符串
$params = [];
parse_str($queryString, $params);
// 提取appid和path的值
$appid = isset($params['appid']) ? $params['appid'] : null;
$path = isset($params['path']) ? $params['path'] : null;
$banner_list[$key]['appid'] = $appid;
$banner_list[$key]['path'] = $path;
// 重新定义跳转链接为中间页
$banner_list[$key]['jump_url'] = "https://tc.pcxbc.com/open_wechat_content";
}
unset($banner_list[$key]['scene_data']);
unset($banner_list[$key]['sort_num']);
unset($banner_list[$key]['ROW_NUMBER']);
unset($banner_list[$key]['parameter_data']);
}
$return_data['banner'] = $banner_list;
// 获取菜谱列表
2025-01-22 12:31:08 +08:00
$label_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])->group('cook_label')->field('cook_label,count(*) as num')->select();
if(count($label_list) <= 0){
$return_data['content']['label_list'] = [];
$return_data['content']['content_list'] = [];
return $this->msg($return_data);
}
2025-01-22 12:31:08 +08:00
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
->alias('zhanghao')
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','zhanghao.cover = uploadimg.id','LEFT')
->where(['zhanghao.cook_label'=>$label_list[0]['cook_label']])
->field('zhanghao.title,uploadimg.pic_url as cover,zhanghao.create_user_head_pic,zhanghao.create_user_nickname,zhanghao.like_it')
->page("1,20")
->select();
2025-01-22 12:31:08 +08:00
$return_data['content']['label_list'] = $label_list;
for ($i=0; $i < count($content_list); $i++) {
if($content_list[$i]['cover'] == null){
$content_list[$i]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
}
}
2025-01-22 12:31:08 +08:00
$return_data['content']['content_list'] = $content_list;
return $this->msg($return_data);
}
}