Compare commits
8 Commits
8d3b39a59c
...
9d043259a6
| Author | SHA1 | Date |
|---|---|---|
|
|
9d043259a6 | |
|
|
b4711455c0 | |
|
|
c85235c243 | |
|
|
5a462a31f5 | |
|
|
086c314c10 | |
|
|
4bba6518cd | |
|
|
9d9de20948 | |
|
|
576b1cbeb5 |
|
|
@ -226,38 +226,38 @@ class Base extends Controller{
|
||||||
|
|
||||||
|
|
||||||
// dump($file);
|
// dump($file);
|
||||||
die;
|
// die;
|
||||||
|
|
||||||
if($file){
|
// if($file){
|
||||||
$name = $file->getInfo()['name'];
|
// $name = $file->getInfo()['name'];
|
||||||
// 使用 pathinfo() 函数获取文件名的扩展名
|
// // 使用 pathinfo() 函数获取文件名的扩展名
|
||||||
$pathinfo = pathinfo($name);
|
// $pathinfo = pathinfo($name);
|
||||||
$extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
// $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较
|
||||||
$file_name = $pathinfo['filename'];
|
// $file_name = $pathinfo['filename'];
|
||||||
// 判断扩展名是否不是 .png 或 .gif
|
// // 判断扩展名是否不是 .png 或 .gif
|
||||||
if ($extension !== 'png' && $extension !== 'gif') {
|
// if ($extension !== 'png' && $extension !== 'gif') {
|
||||||
// 修改文件名,将扩展名改为 .jpg
|
// // 修改文件名,将扩展名改为 .jpg
|
||||||
$new_filename = date('YmdHis').$file_name . '.jpg';
|
// $new_filename = date('YmdHis').$file_name . '.jpg';
|
||||||
} else {
|
// } else {
|
||||||
$new_filename = date('YmdHis').$name;
|
// $new_filename = date('YmdHis').$name;
|
||||||
}
|
// }
|
||||||
$info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'upload_pic',$new_filename);
|
// $info = $file->validate(['size'=>$this->file_size,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'upload_pic',$new_filename);
|
||||||
if($info){
|
// if($info){
|
||||||
$insert_data = [
|
// $insert_data = [
|
||||||
'url_data'=>"https://tc.pcxbc.com/upload_pic/".$new_filename,
|
// 'url_data'=>"https://tc.pcxbc.com/upload_pic/".$new_filename,
|
||||||
'name'=>$new_filename,
|
// 'name'=>$new_filename,
|
||||||
'create_time'=>date('Y-m-d H:i:s'),
|
// 'create_time'=>date('Y-m-d H:i:s'),
|
||||||
];
|
// ];
|
||||||
$pic_result = Db::table('admin_pic_manage')->insertGetId($insert_data);
|
// $pic_result = Db::table('admin_pic_manage')->insertGetId($insert_data);
|
||||||
if($pic_result){
|
// if($pic_result){
|
||||||
return $this->msg(['url'=>$insert_data['url_data'],'id'=>$pic_result]);
|
// return $this->msg(['url'=>$insert_data['url_data'],'id'=>$pic_result]);
|
||||||
}else{
|
// }else{
|
||||||
return $this->msg(10002,'图片数据保存失败');
|
// return $this->msg(10002,'图片数据保存失败');
|
||||||
}
|
// }
|
||||||
}else{
|
// }else{
|
||||||
return $this->msg(10002,'图片上传失败');
|
// return $this->msg(10002,'图片上传失败');
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use think\Db;
|
||||||
|
|
||||||
class Cookbook extends Base{
|
class Cookbook extends Base{
|
||||||
|
|
||||||
protected $code_time = 50;
|
|
||||||
// protected $token_time = 2592000;//30天的秒数
|
// protected $token_time = 2592000;//30天的秒数
|
||||||
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png';
|
||||||
protected $reedaw_db_msg = [
|
protected $reedaw_db_msg = [
|
||||||
|
|
@ -17,7 +17,8 @@ class Cookbook extends Base{
|
||||||
'cookbook'=>'app_user_cookbook',//菜谱表
|
'cookbook'=>'app_user_cookbook',//菜谱表
|
||||||
'uploadimg'=>'app_user_upload_img',//素材表
|
'uploadimg'=>'app_user_upload_img',//素材表
|
||||||
'followlist'=>'app_user_follow_list',//关注列表
|
'followlist'=>'app_user_follow_list',//关注列表
|
||||||
'collectlist'=>'app_user_collect_list',//收藏列表
|
'collect_list'=>'app_user_collect_list',//收藏列表
|
||||||
|
'foodlist3'=>'app_food_type_three',//食材列表3
|
||||||
];
|
];
|
||||||
|
|
||||||
// 加 bcadd(,,20)
|
// 加 bcadd(,,20)
|
||||||
|
|
@ -28,7 +29,7 @@ class Cookbook extends Base{
|
||||||
################################################################接口################################################################
|
################################################################接口################################################################
|
||||||
################################################################接口################################################################
|
################################################################接口################################################################
|
||||||
|
|
||||||
// 添加菜谱
|
// 添加菜谱(OK)
|
||||||
public function add_cookbook(){
|
public function add_cookbook(){
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
|
|
@ -88,8 +89,8 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// 根据菜谱标签查询列表(首页用)
|
// 根据菜谱标签查询列表(首页用)(OK)
|
||||||
public function find_by_cook_label($data=['token'=>'caadd1be045a65f3','cook_label'=>'早餐','page'=>'1']){
|
public function find_by_cook_label($data=['token'=>'caadd1be045a65f3','cook_label'=>'家常菜谱','page'=>'1']){
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -130,8 +131,7 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
// 根据食材详细查找列表(OK)
|
||||||
// 根据食材详细查找列表
|
|
||||||
public function find_by_food($data=['token'=>'caadd1be045a65f3','food_name'=>'猪肉','page'=>'1']){
|
public function find_by_food($data=['token'=>'caadd1be045a65f3','food_name'=>'猪肉','page'=>'1']){
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
|
|
@ -173,9 +173,8 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
// 查询食谱的详情(OK)
|
||||||
// 查询食谱的详情
|
public function cookbook_details($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'17']){
|
||||||
public function cookbook_details($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12']){
|
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -210,9 +209,8 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
// 关注行为(OK)
|
||||||
// 关注菜谱
|
public function cookbook_follow($data=['token'=>'caadd1be045a65f3','being_followed'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
public function cookbook_follow($data=['token'=>'caadd1be045a65f3','cookbook_id'=>'12']){
|
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -221,13 +219,13 @@ class Cookbook extends Base{
|
||||||
if(!array_key_exists('token', $data)){
|
if(!array_key_exists('token', $data)){
|
||||||
return $this->msg(10001,'token is miss');
|
return $this->msg(10001,'token is miss');
|
||||||
}
|
}
|
||||||
if(!array_key_exists('cookbook_id', $data)){
|
if(!array_key_exists('being_followed', $data)){
|
||||||
return $this->msg(10001,'cookbook_id is miss');
|
return $this->msg(10001,'cookbook_id is miss');
|
||||||
}
|
}
|
||||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||||
return $this->msg(10005,'token type is error');
|
return $this->msg(10005,'token type is error');
|
||||||
}
|
}
|
||||||
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
|
if(!$this->verify_data_is_ok($data['being_followed'],'str')){
|
||||||
return $this->msg(10005,'cookbook_id type is error');
|
return $this->msg(10005,'cookbook_id type is error');
|
||||||
}
|
}
|
||||||
$return_data = $this->cookbook_follow_action($data);
|
$return_data = $this->cookbook_follow_action($data);
|
||||||
|
|
@ -247,8 +245,8 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// 收藏菜谱
|
// 点赞收藏菜谱(OK)
|
||||||
public function cookbook_like($data=['token'=>'caadd1be045a65f3','cookbook_id'=>'12']){
|
public function cookbook_like($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12']){
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -283,9 +281,8 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
// 计算当前食材重量的卡路里(OK)
|
||||||
// 计算根据菜谱称重
|
public function food_count_kcal($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_name'=>'鸡肉','food_weight'=>456.37]){
|
||||||
public function cookbook_count_weight($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','cookbook_id'=>'12','food_weight'=>[]]){
|
|
||||||
// 尝试捕获异常
|
// 尝试捕获异常
|
||||||
// try {
|
// try {
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
|
|
@ -294,8 +291,8 @@ class Cookbook extends Base{
|
||||||
if(!array_key_exists('token', $data)){
|
if(!array_key_exists('token', $data)){
|
||||||
return $this->msg(10001,'token is miss');
|
return $this->msg(10001,'token is miss');
|
||||||
}
|
}
|
||||||
if(!array_key_exists('cookbook_id', $data)){
|
if(!array_key_exists('food_name', $data)){
|
||||||
return $this->msg(10001,'cookbook_id is miss');
|
return $this->msg(10001,'food_name is miss');
|
||||||
}
|
}
|
||||||
if(!array_key_exists('food_weight', $data)){
|
if(!array_key_exists('food_weight', $data)){
|
||||||
return $this->msg(10001,'food_weight is miss');
|
return $this->msg(10001,'food_weight is miss');
|
||||||
|
|
@ -303,11 +300,14 @@ class Cookbook extends Base{
|
||||||
if(!$this->verify_data_is_ok($data['token'],'str')){
|
if(!$this->verify_data_is_ok($data['token'],'str')){
|
||||||
return $this->msg(10005,'token type is error');
|
return $this->msg(10005,'token type is error');
|
||||||
}
|
}
|
||||||
if(!$this->verify_data_is_ok($data['cookbook_id'],'intnum')){
|
if(!$this->verify_data_is_ok($data['food_name'],'str')){
|
||||||
return $this->msg(10005,'cook_label type is error');
|
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->cookbook_count_weight_action($data);
|
$return_data = $this->food_count_kcal_action($data);
|
||||||
return $return_data;
|
return $return_data;
|
||||||
// } catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
// // 捕获异常
|
// // 捕获异常
|
||||||
|
|
@ -324,7 +324,43 @@ class Cookbook extends Base{
|
||||||
// return json(['status' => 'error', 'message' => '系统错误']);
|
// return json(['status' => 'error', 'message' => '系统错误']);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
// 保存每日餐食食物信息
|
||||||
|
public function save_food_list($data=['token'=>'caadd1be045a65f30b92aa805f1de54a','food_list'=>[['name'=>'鸡肉','weight'=>456.37,'kcal'=>761.52]]]){
|
||||||
|
// 尝试捕获异常
|
||||||
|
// 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_list', $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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$return_data = $this->save_food_list_action($data);
|
||||||
|
return $return_data;
|
||||||
|
// } catch (\Exception $e) {
|
||||||
|
// // 捕获异常
|
||||||
|
// $logContent["file"] = $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#######################################################################
|
#######################################################################action#######################################################################
|
||||||
|
|
||||||
public function add_cookbook_action($data){
|
public function add_cookbook_action($data){
|
||||||
|
|
@ -341,7 +377,7 @@ class Cookbook extends Base{
|
||||||
return $this->msg(10005,'食材缺少名称或者重量');
|
return $this->msg(10005,'食材缺少名称或者重量');
|
||||||
}
|
}
|
||||||
if(!$this->verify_data_is_ok($value['name'],'str')){
|
if(!$this->verify_data_is_ok($value['name'],'str')){
|
||||||
return $this->msg(10005,'食材名称格式错误,需字符串');
|
return $this->msg(10005,'食材名称格式错误');
|
||||||
}
|
}
|
||||||
if(!$this->verify_data_is_ok($value['weight'],'intnum')){
|
if(!$this->verify_data_is_ok($value['weight'],'intnum')){
|
||||||
return $this->msg(10005,'食材重量格式错误,需整数数字');
|
return $this->msg(10005,'食材重量格式错误,需整数数字');
|
||||||
|
|
@ -350,7 +386,6 @@ class Cookbook extends Base{
|
||||||
}
|
}
|
||||||
// 检验一下step_list是否合规(步骤列表)
|
// 检验一下step_list是否合规(步骤列表)
|
||||||
foreach ($data['step_list'] as $key => $value) {
|
foreach ($data['step_list'] as $key => $value) {
|
||||||
// if (!array_key_exists('description', $value) || !array_key_exists('foot_list', $value) || !array_key_exists('pic_list', $value)) {
|
|
||||||
if (!array_key_exists('description', $value) || !array_key_exists('pic_list', $value)) {
|
if (!array_key_exists('description', $value) || !array_key_exists('pic_list', $value)) {
|
||||||
return $this->msg(10005,'步骤缺少描述或者图片');
|
return $this->msg(10005,'步骤缺少描述或者图片');
|
||||||
}
|
}
|
||||||
|
|
@ -363,17 +398,6 @@ class Cookbook extends Base{
|
||||||
return $this->msg(10005,'步骤中图片ID错误,需整数数字');
|
return $this->msg(10005,'步骤中图片ID错误,需整数数字');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// foreach ($value['foot_list'] as $k => $v) {
|
|
||||||
// if (!array_key_exists('name', $v) || !array_key_exists('weight', $v)) {
|
|
||||||
// return $this->msg(10005,'步骤食材缺少名称或者重量');
|
|
||||||
// }
|
|
||||||
// if(!$this->verify_data_is_ok($v['name'],'str')){
|
|
||||||
// return $this->msg(10005,'步骤食材名称格式错误,需字符串');
|
|
||||||
// }
|
|
||||||
// if(!$this->verify_data_is_ok($v['weight'],'intnum')){
|
|
||||||
// return $this->msg(10005,'步骤食材重量格式错误,需整数数字');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
@ -381,14 +405,9 @@ class Cookbook extends Base{
|
||||||
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
|
$user_data = Db::table($this->reedaw_db_msg['zhanghao'])->where(['token'=>$data['token']])->field('id,token,nickname,head_pic')->find();
|
||||||
|
|
||||||
// 处理食材卡路里start
|
// 处理食材卡路里start
|
||||||
foreach ($data['food_list'] as $key => $value) {
|
$kcal_data = $this->count_calorie($data['food_list'],$data['step_list']);
|
||||||
$data['food_list'][$key]['kcal'] = '0kcal';
|
$data['food_list'] =$kcal_data[0];
|
||||||
}
|
$data['step_list'] = $kcal_data[1];
|
||||||
// foreach ($data['step_list'] as $key => $value) {
|
|
||||||
// foreach ($value['foot_list'] as $k => $v) {
|
|
||||||
// $data['step_list'][$key]['foot_list'][$k]['kcal'] = '0kcal';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// 处理食材卡路里end
|
// 处理食材卡路里end
|
||||||
|
|
||||||
$insert_data = [
|
$insert_data = [
|
||||||
|
|
@ -412,7 +431,6 @@ class Cookbook extends Base{
|
||||||
return $this->msg(10002);
|
return $this->msg(10002);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find_by_cook_label_action($data){
|
public function find_by_cook_label_action($data){
|
||||||
$page_now = $data['page'];
|
$page_now = $data['page'];
|
||||||
$page_total = $data['page'];
|
$page_total = $data['page'];
|
||||||
|
|
@ -423,6 +441,7 @@ class Cookbook extends Base{
|
||||||
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
$content_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||||
->where(['cook_label'=>$cook_label])
|
->where(['cook_label'=>$cook_label])
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$page_total = ceil($content_num/$page_num);
|
$page_total = ceil($content_num/$page_num);
|
||||||
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
$content_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])
|
||||||
->alias('cookbook')
|
->alias('cookbook')
|
||||||
|
|
@ -432,41 +451,30 @@ class Cookbook extends Base{
|
||||||
->page("$page_now,$page_num")
|
->page("$page_now,$page_num")
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
// 处理本人是否关注 start
|
// 获取用户收藏列表
|
||||||
$like_it_arr = [];
|
$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) {
|
foreach ($content_list as $key => $value) {
|
||||||
array_push($like_it_arr, $value['id']);
|
// if(in_array($value['id'],$my_collect_list)){
|
||||||
}
|
if(array_key_exists($value['id'],$my_collect_list)){
|
||||||
|
$content_list[$key]['is_me_like_it'] = 1;
|
||||||
$like_it_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
|
|
||||||
->where("token = '".$data['token']."' AND cookbook_id in (".implode(',',$like_it_arr).") AND is_del = 0")
|
|
||||||
->select();
|
|
||||||
$like_it_arr2 = [];
|
|
||||||
foreach ($like_it_data as $key => $value) {
|
|
||||||
array_push($like_it_arr2, $value['cookbook_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($content_list as $key => $value) {
|
|
||||||
if(in_array($value['id'],$like_it_arr2)){
|
|
||||||
$content_list[$key]['is_like'] = 1;
|
|
||||||
}else{
|
}else{
|
||||||
$content_list[$key]['is_like'] = 0;
|
$content_list[$key]['is_me_like_it'] = 0;
|
||||||
}
|
}
|
||||||
}
|
if($value['cover'] == null){
|
||||||
// 处理本人是否关注 end
|
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
unset($content_list[$key]['ROW_NUMBER']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->msg([
|
return $this->msg([
|
||||||
'page_now'=>$page_now,
|
'page_now'=>$page_now,
|
||||||
'page_total'=>$page_total,
|
'page_total'=>$page_total,
|
||||||
'content_list'=>$content_list
|
'content_list'=>$content_list
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find_by_food_action($data){
|
public function find_by_food_action($data){
|
||||||
$page_now = $data['page'];
|
$page_now = $data['page'];
|
||||||
$page_total = $data['page'];
|
$page_total = $data['page'];
|
||||||
|
|
@ -482,37 +490,27 @@ class Cookbook extends Base{
|
||||||
->alias('cookbook')
|
->alias('cookbook')
|
||||||
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
|
->join($this->kitchenscale_db_msg['uploadimg'].' uploadimg','cookbook.cover = uploadimg.id','LEFT')
|
||||||
->where("cookbook.food_type like '%$food_name%'")
|
->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.like_it')
|
->field('cookbook.id,cookbook.title,uploadimg.pic_url as cover,cookbook.create_user_head_pic,cookbook.create_user_nickname,cookbook.like_it as like_num')
|
||||||
->page("$page_now,$page_num")
|
->page("$page_now,$page_num")
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
// 处理本人是否关注 start
|
// 获取用户收藏列表
|
||||||
$like_it_arr = [];
|
$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) {
|
foreach ($content_list as $key => $value) {
|
||||||
array_push($like_it_arr, $value['id']);
|
// if(in_array($value['id'],$my_collect_list)){
|
||||||
}
|
if(array_key_exists($value['id'],$my_collect_list)){
|
||||||
|
$content_list[$key]['is_me_like_it'] = 1;
|
||||||
$like_it_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
|
|
||||||
->where("token = '".$data['token']."' AND cookbook_id in (".implode(',',$like_it_arr).") AND is_del = 0")
|
|
||||||
->select();
|
|
||||||
$like_it_arr2 = [];
|
|
||||||
foreach ($like_it_data as $key => $value) {
|
|
||||||
array_push($like_it_arr2, $value['cookbook_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($content_list as $key => $value) {
|
|
||||||
if(in_array($value['id'],$like_it_arr2)){
|
|
||||||
$content_list[$key]['is_like'] = 1;
|
|
||||||
}else{
|
}else{
|
||||||
$content_list[$key]['is_like'] = 0;
|
$content_list[$key]['is_me_like_it'] = 0;
|
||||||
}
|
}
|
||||||
}
|
if($value['cover'] == null){
|
||||||
// 处理本人是否关注 end
|
$content_list[$key]['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||||
|
|
||||||
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';
|
|
||||||
}
|
}
|
||||||
|
unset($content_list[$key]['ROW_NUMBER']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->msg([
|
return $this->msg([
|
||||||
|
|
@ -521,12 +519,9 @@ class Cookbook extends Base{
|
||||||
'content_list'=>$content_list
|
'content_list'=>$content_list
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cookbook_details_action($data){
|
public function cookbook_details_action($data){
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
||||||
$img_arr = [];
|
$img_arr = [];
|
||||||
|
|
||||||
// 查询菜谱详情
|
// 查询菜谱详情
|
||||||
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->find();
|
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->find();
|
||||||
if(!$cookbook_data){
|
if(!$cookbook_data){
|
||||||
|
|
@ -535,7 +530,6 @@ class Cookbook extends Base{
|
||||||
$cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true);
|
$cookbook_data['food_data'] = json_decode($cookbook_data['food_data'],true);
|
||||||
$cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true);
|
$cookbook_data['step_data'] = json_decode($cookbook_data['step_data'],true);
|
||||||
$cookbook_data_step_data_count = count($cookbook_data['step_data']);
|
$cookbook_data_step_data_count = count($cookbook_data['step_data']);
|
||||||
|
|
||||||
// 设置需要的图片id
|
// 设置需要的图片id
|
||||||
array_push($img_arr, $cookbook_data['cover']);
|
array_push($img_arr, $cookbook_data['cover']);
|
||||||
foreach ($cookbook_data['step_data'] as $key => $value) {
|
foreach ($cookbook_data['step_data'] as $key => $value) {
|
||||||
|
|
@ -548,7 +542,6 @@ class Cookbook extends Base{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$img_arr = implode(',',$img_arr);
|
$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();
|
$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 = [];
|
$cookbook_img_data = [];
|
||||||
|
|
@ -556,7 +549,6 @@ class Cookbook extends Base{
|
||||||
foreach ($img_arr_data as $key => $value) {
|
foreach ($img_arr_data as $key => $value) {
|
||||||
$cookbook_img_data[$value['id']] = $value['pic_url'];
|
$cookbook_img_data[$value['id']] = $value['pic_url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置菜谱图片
|
// 设置菜谱图片
|
||||||
foreach ($cookbook_data['step_data'] as $key => $value) {
|
foreach ($cookbook_data['step_data'] as $key => $value) {
|
||||||
$cookbook_data['step_data'][$key]['pic_list_ls'] = [];
|
$cookbook_data['step_data'][$key]['pic_list_ls'] = [];
|
||||||
|
|
@ -576,13 +568,11 @@ class Cookbook extends Base{
|
||||||
}else{
|
}else{
|
||||||
$cookbook_data['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
$cookbook_data['cover'] = 'https://tc.pcxbc.com/kitchenscale_all/diule.jpg';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 处理关注跟收藏信息
|
// 处理关注跟收藏信息
|
||||||
if($data['token'] == $cookbook_data['create_user_token']){
|
if($data['token'] == $cookbook_data['create_user_token']){
|
||||||
// 如果查询跟作者一致
|
// 如果查询跟作者一致
|
||||||
$cookbook_data['follow_status'] = 3;
|
$cookbook_data['follow_status'] = 'myself';
|
||||||
$cookbook_data['collect_status'] = 3;
|
$cookbook_data['collect_status'] = 'myself';
|
||||||
}else{
|
}else{
|
||||||
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
||||||
->where([
|
->where([
|
||||||
|
|
@ -593,17 +583,17 @@ class Cookbook extends Base{
|
||||||
if($follow_data){
|
if($follow_data){
|
||||||
if($follow_data['is_del'] == 0){
|
if($follow_data['is_del'] == 0){
|
||||||
// 如果有结果并且没被删过
|
// 如果有结果并且没被删过
|
||||||
$cookbook_data['follow_status'] = 1;
|
$cookbook_data['follow_status'] = 'yes';
|
||||||
}else{
|
}else{
|
||||||
// 如果有结果被删过
|
// 如果有结果被删过
|
||||||
$cookbook_data['follow_status'] = 0;
|
$cookbook_data['follow_status'] = 'no';
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// 如果没结果
|
// 如果没结果
|
||||||
$cookbook_data['follow_status'] = 0;
|
$cookbook_data['follow_status'] = 'no';
|
||||||
}
|
}
|
||||||
|
|
||||||
$collect_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
|
$collect_data = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||||
->where([
|
->where([
|
||||||
'token'=>$data['token'],
|
'token'=>$data['token'],
|
||||||
'cookbook_id'=>$data['cookbook_id'],
|
'cookbook_id'=>$data['cookbook_id'],
|
||||||
|
|
@ -612,52 +602,43 @@ class Cookbook extends Base{
|
||||||
if($collect_data){
|
if($collect_data){
|
||||||
if($collect_data['is_del'] == 0){
|
if($collect_data['is_del'] == 0){
|
||||||
// 如果有结果并且没被删过
|
// 如果有结果并且没被删过
|
||||||
$cookbook_data['collect_status'] = 1;
|
$cookbook_data['collect_status'] = 'yes';
|
||||||
}else{
|
}else{
|
||||||
// 如果有结果被删过
|
// 如果有结果被删过
|
||||||
$cookbook_data['collect_status'] = 0;
|
$cookbook_data['collect_status'] = 'no';
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
// 如果没结果
|
// 如果没结果
|
||||||
$cookbook_data['collect_status'] = 0;
|
$cookbook_data['collect_status'] = 'no';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加阅读量
|
// 添加阅读量
|
||||||
$read_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('read_it');
|
$read_num = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('read_it');
|
||||||
if($read_num){
|
if($read_num){
|
||||||
$cookbook_data['read_it'] = $cookbook_data['read_it']+1;
|
$cookbook_data['read_it'] = $cookbook_data['read_it']+1;
|
||||||
}
|
}
|
||||||
|
// unset($cookbook_data['create_user_token']);
|
||||||
unset($cookbook_data['create_user_token']);
|
|
||||||
unset($cookbook_data['create_time']);
|
unset($cookbook_data['create_time']);
|
||||||
unset($cookbook_data['cook_label']);
|
unset($cookbook_data['cook_label']);
|
||||||
unset($cookbook_data['food_type']);
|
unset($cookbook_data['food_type']);
|
||||||
unset($cookbook_data['ROW_NUMBER']);
|
unset($cookbook_data['ROW_NUMBER']);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $this->msg($cookbook_data);
|
return $this->msg($cookbook_data);
|
||||||
// dump($cookbook_data);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function cookbook_follow_action($data){
|
public function cookbook_follow_action($data){
|
||||||
// dump($data);
|
// dump($data);
|
||||||
$cfc = Db::connect('cfc_db');
|
$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();
|
// $cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find();
|
||||||
if(!$cookbook_data){
|
// if(!$cookbook_data){
|
||||||
return $this->msg(10002,'未找到菜谱');
|
// return $this->msg(10002,'未找到菜谱');
|
||||||
}
|
// }
|
||||||
if($data['token'] == $cookbook_data['create_user_token']){
|
if($data['token'] == $data['being_followed']){
|
||||||
// 如果查询跟作者一致
|
// 如果查询跟作者一致
|
||||||
return $this->msg(10002,'不能关注自己');
|
return $this->msg(10002,'不能关注自己');
|
||||||
}
|
}
|
||||||
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
$follow_data = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
||||||
->where([
|
->where([
|
||||||
'follow_user_token'=>$data['token'],
|
'follow_user_token'=>$data['token'],
|
||||||
'being_follow_user_token'=>$cookbook_data['create_user_token'],
|
'being_follow_user_token'=>$data['being_followed'],
|
||||||
])
|
])
|
||||||
->find();
|
->find();
|
||||||
$follow_data_state = 0;
|
$follow_data_state = 0;
|
||||||
|
|
@ -668,40 +649,34 @@ class Cookbook extends Base{
|
||||||
}else{
|
}else{
|
||||||
$follow_data_state = 0;
|
$follow_data_state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$follow_result= $cfc->table($this->kitchenscale_db_msg['followlist'])
|
$follow_result= $cfc->table($this->kitchenscale_db_msg['followlist'])
|
||||||
->where([
|
->where(['id'=>$follow_data['id']])
|
||||||
'follow_user_token'=>$data['token'],
|
|
||||||
'being_follow_user_token'=>$cookbook_data['create_user_token'],
|
|
||||||
])
|
|
||||||
->update(['is_del'=>$follow_data_state]);
|
->update(['is_del'=>$follow_data_state]);
|
||||||
}else{
|
}else{
|
||||||
$follow_result = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
$follow_result = $cfc->table($this->kitchenscale_db_msg['followlist'])
|
||||||
->insert([
|
->insert([
|
||||||
'follow_user_token'=>$data['token'],
|
'follow_user_token'=>$data['token'],
|
||||||
'being_follow_user_token'=>$cookbook_data['create_user_token'],
|
'being_follow_user_token'=>$data['being_followed'],
|
||||||
'create_time'=>date('Y-m-d H:i:s')
|
'create_time'=>date('Y-m-d H:i:s')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($follow_result){
|
if($follow_result){
|
||||||
return $this->msg([]);
|
return $this->msg([]);
|
||||||
}else{
|
}else{
|
||||||
return $this->msg(10001,'操作失败');
|
return $this->msg(10001,'操作失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cookbook_like_action($data){
|
public function cookbook_like_action($data){
|
||||||
$cfc = Db::connect('cfc_db');
|
$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();
|
$cookbook_data = $cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->field('id,create_user_token')->find();
|
||||||
if(!$cookbook_data){
|
if(!$cookbook_data){
|
||||||
return $this->msg(10002,'未找到菜谱');
|
return $this->msg(10002,'未找到菜谱');
|
||||||
}
|
}
|
||||||
if($data['token'] == $cookbook_data['create_user_token']){
|
// if($data['token'] == $cookbook_data['create_user_token']){
|
||||||
// 如果查询跟作者一致
|
// // 如果查询跟作者一致
|
||||||
return $this->msg(10002,'不能收藏自己');
|
// return $this->msg(10002,'不能收藏自己');
|
||||||
}
|
// }
|
||||||
$like_data = $cfc->table($this->kitchenscale_db_msg['collectlist'])
|
$like_data = $cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||||
->where([
|
->where([
|
||||||
'token'=>$data['token'],
|
'token'=>$data['token'],
|
||||||
'cookbook_id'=>$data['cookbook_id'],
|
'cookbook_id'=>$data['cookbook_id'],
|
||||||
|
|
@ -716,15 +691,11 @@ class Cookbook extends Base{
|
||||||
}else{
|
}else{
|
||||||
$like_data_state = 0;
|
$like_data_state = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 启动事务
|
// 启动事务
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try{
|
try{
|
||||||
$cfc->table($this->kitchenscale_db_msg['collectlist'])
|
$cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||||
->where([
|
->where(['id'=>$like_data['id']])
|
||||||
'token'=>$data['token'],
|
|
||||||
'cookbook_id'=>$data['cookbook_id'],
|
|
||||||
])
|
|
||||||
->update(['is_del'=>$like_data_state]);
|
->update(['is_del'=>$like_data_state]);
|
||||||
if($like_data_state == 0){
|
if($like_data_state == 0){
|
||||||
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('like_it');
|
$cfc->table($this->kitchenscale_db_msg['cookbook'])->where(['id'=>$data['cookbook_id']])->setInc('like_it');
|
||||||
|
|
@ -743,7 +714,7 @@ class Cookbook extends Base{
|
||||||
// 启动事务
|
// 启动事务
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try{
|
try{
|
||||||
$cfc->table($this->kitchenscale_db_msg['collectlist'])
|
$cfc->table($this->kitchenscale_db_msg['collect_list'])
|
||||||
->insert([
|
->insert([
|
||||||
'token'=>$data['token'],
|
'token'=>$data['token'],
|
||||||
'cookbook_id'=>$data['cookbook_id'],
|
'cookbook_id'=>$data['cookbook_id'],
|
||||||
|
|
@ -760,28 +731,99 @@ class Cookbook extends Base{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function food_count_kcal_action($data){
|
||||||
public function cookbook_count_weight_action($data){
|
$cfc = Db::connect('cfc_db');
|
||||||
$data['food_weight'] = [
|
$food_data = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where(['name'=>$data['food_name']])->field("kcal")->find();
|
||||||
[
|
if(!$food_data){
|
||||||
'food_name'=>'牛肉',
|
return $this->msg(10002,'未登记的食材');
|
||||||
'food_weight'=>'100',
|
}
|
||||||
'food_kcal'=>'190',
|
$weight = bcdiv($data['food_weight'],100,2);
|
||||||
],
|
$kcal = bcmul($weight,$food_data['kcal'],2);
|
||||||
[
|
return $this->msg(['value'=>$kcal,'unit'=>'kcal']);
|
||||||
'food_name'=>'狗肉',
|
}
|
||||||
'food_weight'=>'100',
|
public function save_food_list_action($data){
|
||||||
'food_kcal'=>'116',
|
$cfc = Db::connect('cfc_db');
|
||||||
],
|
foreach ($data['food_list'] as $key => $value) {
|
||||||
];
|
if(!array_key_exists('name', $value) || !array_key_exists('weight', $value) || !array_key_exists('kcal', $value)){
|
||||||
foreach ($variable as $key => $value) {
|
return $this->msg(10001,'food_list content lost');
|
||||||
if(!array_key_exists('food_name', $data['food_weight']) || !array_key_exists('food_weight', $data['food_weight']) || !array_key_exists('food_kcal', $data['food_weight'])){
|
}
|
||||||
return $this->msg(10001,'食材称重参数错误');
|
if(!$this->verify_data_is_ok($value['name'],'str')){
|
||||||
|
return $this->msg(10005,'name type is error');
|
||||||
|
}
|
||||||
|
if(!$this->verify_data_is_ok($value['weight'],'num')){
|
||||||
|
return $this->msg(10005,'weight type is error');
|
||||||
|
}
|
||||||
|
if(!$this->verify_data_is_ok($value['kcal'],'num')){
|
||||||
|
return $this->msg(10005,'kcal type is error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!array_key_exists('eat_time', $data)){
|
||||||
|
$data['eat_time'] = date('Y-m-d H:i:s');
|
||||||
|
}else{
|
||||||
|
if(!$this->verify_data_is_ok($value['kcal'],'datetime')){
|
||||||
|
return $this->msg(10005,'kcal type is error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $cfc->table($this->kitchenscale_db_msg['foodlist3'])
|
||||||
|
->insert([
|
||||||
|
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######################################################################小工具#######################################################################
|
||||||
|
#######################################################################小工具#######################################################################
|
||||||
|
#######################################################################小工具#######################################################################
|
||||||
|
|
||||||
|
// 处理食材的卡路里
|
||||||
|
public function count_calorie($data,$step){
|
||||||
|
|
||||||
|
$foot_name = array_column($data, 'name');
|
||||||
|
$foot_name = array_unique($foot_name);
|
||||||
|
$cfc = Db::connect('cfc_db');
|
||||||
|
$foot_kcal = $cfc->table($this->kitchenscale_db_msg['foodlist3'])->where("name in ('".implode("','", $foot_name)."')")->field("name,kcal")->select();
|
||||||
|
$foot_kcal2 = [];
|
||||||
|
foreach ($foot_kcal as $key => $value) {
|
||||||
|
$foot_kcal2[$value['name']] = $value['kcal'];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
if(array_key_exists($value['name'], $foot_kcal2)){
|
||||||
|
$data[$key]['kcal'] = $this->count_calorie_action($value['weight'],$foot_kcal2[$value['name']]).'kcal';
|
||||||
|
}else{
|
||||||
|
$data[$key]['kcal'] = '0kcal';
|
||||||
|
}
|
||||||
|
$data[$key]['weight'] = $data[$key]['weight'].'g';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($step as $key => $value) {
|
||||||
|
foreach ($value['foot_list'] as $k => $v) {
|
||||||
|
|
||||||
|
if(array_key_exists($v['name'], $foot_kcal2)){
|
||||||
|
$step[$key]['foot_list'][$k]['kcal'] = $this->count_calorie_action($v['weight'],$foot_kcal2[$v['name']]).'kcal';
|
||||||
|
}else{
|
||||||
|
$step[$key]['foot_list'][$k]['kcal'] = '0kcal';
|
||||||
|
}
|
||||||
|
$step[$key]['foot_list'][$k]['weight'] = $step[$key]['foot_list'][$k]['weight'].'g';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return [$data,$step];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 加 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,16 +13,14 @@ class Index extends Base{
|
||||||
'zhanghao'=>'app_account_number',//账号表
|
'zhanghao'=>'app_account_number',//账号表
|
||||||
'juese'=>'app_user_data',//角色表
|
'juese'=>'app_user_data',//角色表
|
||||||
'banner'=>'admin_notice_banner',//banner
|
'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 = [
|
protected $kitchenscale_db_msg = [
|
||||||
'cookbook'=>'app_user_cookbook',//菜谱表
|
'cookbook'=>'app_user_cookbook',//菜谱表
|
||||||
'uploadimg'=>'app_user_upload_img',//素材表
|
'uploadimg'=>'app_user_upload_img',//图片素材表
|
||||||
'foodlist1'=>'app_food_type_one',//素材表
|
'foodlist1'=>'app_food_type_one',//食材列表1
|
||||||
'foodlist2'=>'app_food_type_two',//素材表
|
'foodlist2'=>'app_food_type_two',//食材列表2
|
||||||
'foodlist3'=>'app_food_type_three',//素材表
|
'foodlist3'=>'app_food_type_three',//食材列表3
|
||||||
|
'collect_list'=>'app_user_collect_list',//素材表
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -34,12 +32,19 @@ class Index extends Base{
|
||||||
################################################################接口################################################################
|
################################################################接口################################################################
|
||||||
################################################################接口################################################################
|
################################################################接口################################################################
|
||||||
|
|
||||||
// 获取默认配置信息(包含:食材的分类列表)
|
// 获取默认配置信息(包含:食材的分类列表,用户角色信息)(OK)
|
||||||
public function get_default_config(){
|
public function get_default_config($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
// try {
|
// try {
|
||||||
$return_data = $this->get_default_config_action();
|
if(count(input('post.')) > 0){
|
||||||
// 成功
|
$data = input('post.');
|
||||||
// $this->record_api_log($data, null, $return_data);
|
}
|
||||||
|
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);
|
||||||
return $return_data;
|
return $return_data;
|
||||||
// } catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
// // 捕获异常
|
// // 捕获异常
|
||||||
|
|
@ -47,6 +52,7 @@ class Index extends Base{
|
||||||
// $logContent["line"] = $e->getLine();
|
// $logContent["line"] = $e->getLine();
|
||||||
// $logContent['all_content'] = "异常信息:\n";
|
// $logContent['all_content'] = "异常信息:\n";
|
||||||
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||||
|
// $logContent['all_content'] .= "接口: (get_default_config)\n";
|
||||||
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||||
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||||
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||||
|
|
@ -54,12 +60,11 @@ class Index extends Base{
|
||||||
// $this->record_api_log($data, $logContent, null);
|
// $this->record_api_log($data, $logContent, null);
|
||||||
// return $this->msg(99999);
|
// return $this->msg(99999);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取首页信息
|
// 获取首页信息(banner,金刚区,label_list)(OK)
|
||||||
public function get_homepage_information($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
public function get_homepage_information($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
// try {
|
try {
|
||||||
// 你的业务逻辑
|
// 你的业务逻辑
|
||||||
if(count(input('post.')) > 0){
|
if(count(input('post.')) > 0){
|
||||||
$data = input('post.');
|
$data = input('post.');
|
||||||
|
|
@ -74,26 +79,64 @@ class Index extends Base{
|
||||||
// 成功
|
// 成功
|
||||||
$this->record_api_log($data, null, $return_data);
|
$this->record_api_log($data, null, $return_data);
|
||||||
return $return_data;
|
return $return_data;
|
||||||
// } catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// // 捕获异常
|
// 捕获异常
|
||||||
// $logContent["flie"] = $e->getFile();
|
$logContent["flie"] = $e->getFile();
|
||||||
// $logContent["line"] = $e->getLine();
|
$logContent["line"] = $e->getLine();
|
||||||
// $logContent['all_content'] = "异常信息:\n";
|
$logContent['all_content'] = "异常信息:\n";
|
||||||
// $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
$logContent['all_content'] .= "消息: " . $e->getMessage() . "\n";
|
||||||
// $logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
$logContent['all_content'] .= "接口: (get_homepage_information)\n";
|
||||||
// $logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
$logContent['all_content'] .= "代码: " . $e->getCode() . "\n";
|
||||||
// $logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
$logContent['all_content'] .= "文件: " . $e->getFile() . "\n";
|
||||||
// $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
$logContent['all_content'] .= "行号: " . $e->getLine() . "\n";
|
||||||
// $this->record_api_log($data, $logContent, null);
|
$logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n";
|
||||||
// return $this->msg(99999);
|
$this->record_api_log($data, $logContent, null);
|
||||||
// }
|
return $this->msg(99999);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 首页搜索接口(OK)
|
||||||
|
public function search_column($data = ['search_data'=>'鱼','token'=>'caadd1be045a65f30b92aa805f1de54a']){
|
||||||
|
try {
|
||||||
|
// 你的业务逻辑
|
||||||
|
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;
|
||||||
|
} 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#######################################################################
|
#######################################################################action#######################################################################
|
||||||
|
|
||||||
public function get_default_config_action(){
|
public function get_default_config_action($data){
|
||||||
$return_data = [
|
$return_data = [
|
||||||
'food_list'=>[],
|
'food_list'=>[],
|
||||||
|
'account'=>[],
|
||||||
];
|
];
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
// 获取食材分类列表start
|
// 获取食材分类列表start
|
||||||
|
|
@ -122,30 +165,32 @@ class Index extends Base{
|
||||||
}
|
}
|
||||||
$return_data['food_list'] = $foodlist1;
|
$return_data['food_list'] = $foodlist1;
|
||||||
// 获取食材分类列表end
|
// 获取食材分类列表end
|
||||||
|
// 获取账号下信息以及用户信息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
|
||||||
return $this->msg($return_data);
|
return $this->msg($return_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_homepage_information_action($data){
|
public function get_homepage_information_action($data){
|
||||||
|
|
||||||
$return_data = [
|
$return_data = [
|
||||||
'account'=>[],
|
|
||||||
'banner'=>[],
|
'banner'=>[],
|
||||||
'content'=>[
|
'jingang_region'=>[
|
||||||
'label_list'=>[],
|
['name'=>'菜谱分类','jump_url'=>'/xxx/xxx/xxx','icon'=>'/xxx/xxx/xxx'],
|
||||||
'content_list'=>[],
|
['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'],
|
||||||
],
|
],
|
||||||
|
'label_list'=>[],
|
||||||
];
|
];
|
||||||
$cfc = Db::connect('cfc_db');
|
$cfc = Db::connect('cfc_db');
|
||||||
|
|
||||||
// 获取账号下信息以及用户信息
|
|
||||||
$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.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
|
||||||
$banner_list = Db::table($this->reedaw_db_msg['banner'])
|
$banner_list = Db::table($this->reedaw_db_msg['banner'])
|
||||||
->where("is_del = 0 AND scene_data IN (21)")
|
->where("is_del = 0 AND scene_data IN (21)")
|
||||||
|
|
@ -178,32 +223,52 @@ class Index extends Base{
|
||||||
}
|
}
|
||||||
$return_data['banner'] = $banner_list;
|
$return_data['banner'] = $banner_list;
|
||||||
|
|
||||||
|
|
||||||
// 获取菜谱列表
|
// 获取菜谱列表
|
||||||
$label_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])->group('cook_label')->field('cook_label,count(*) as num')->select();
|
$label_list = $cfc->table($this->kitchenscale_db_msg['cookbook'])->group('cook_label')->field('cook_label,count(*) as num')->select();
|
||||||
|
// dump($label_list);
|
||||||
if(count($label_list) <= 0){
|
if(count($label_list) <= 0){
|
||||||
$return_data['content']['label_list'] = [];
|
$return_data['label_list'] = [];
|
||||||
$return_data['content']['content_list'] = [];
|
|
||||||
return $this->msg($return_data);
|
return $this->msg($return_data);
|
||||||
}
|
}
|
||||||
|
$return_data['label_list'] = $label_list;
|
||||||
$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();
|
|
||||||
|
|
||||||
$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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$return_data['content']['content_list'] = $content_list;
|
|
||||||
|
|
||||||
return $this->msg($return_data);
|
return $this->msg($return_data);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search_column_action($data){
|
||||||
|
$cookbook = new Cookbook();
|
||||||
|
$cfc = Db::connect('cfc_db');
|
||||||
|
// 获取菜谱信息
|
||||||
|
$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.like_it as like_num,uploadimg.pic_url as cover")
|
||||||
|
->select();
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
unset($content_list[$key]['ROW_NUMBER']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->msg($content_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,210 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\app\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class Deepseek extends Base{
|
||||||
|
|
||||||
|
protected $msginformation_use_db_name = [
|
||||||
|
'1'=>'admin_editor_text_content',
|
||||||
|
'2'=>'admin_editor_text_like_up_log',
|
||||||
|
'3'=>'admin_notice_banner',
|
||||||
|
'4'=>'admin_business_cooperation'
|
||||||
|
];
|
||||||
|
protected $page_num = 10;
|
||||||
|
// 加 bcadd(,,20)
|
||||||
|
// 减 bcsub(,,20)
|
||||||
|
// 乘 bcmul(,,20)
|
||||||
|
// 除 bcdiv(,,20)
|
||||||
|
################################################################接口################################################################
|
||||||
|
################################################################接口################################################################
|
||||||
|
################################################################接口################################################################
|
||||||
|
|
||||||
|
|
||||||
|
public function test_index(){
|
||||||
|
|
||||||
|
return $this->fetch();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 获取板块,及板块下类型标签
|
||||||
|
public function send_msg_deepseek(){
|
||||||
|
// dump('456');
|
||||||
|
// die;
|
||||||
|
try {
|
||||||
|
$data = input('post.');
|
||||||
|
// dump($data);
|
||||||
|
// dump(array_key_exists('xinxi', $data));
|
||||||
|
|
||||||
|
if(!array_key_exists('xinxi', $data)){
|
||||||
|
return $this->msg(10001);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$this->verify_data_is_ok($data['xinxi'],'str')){
|
||||||
|
return $this->msg(10005);
|
||||||
|
}
|
||||||
|
// $data['msg'] = "";
|
||||||
|
// dump($data);
|
||||||
|
// die;
|
||||||
|
$return_data = $this->deepseek_only_onec_action($data);
|
||||||
|
// $return_data = $this->deepseek_ceshiyongjiekou($data);
|
||||||
|
return $return_data;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 捕获异常
|
||||||
|
$logContent["flie"] = $e->getFile();
|
||||||
|
$logContent["line"] = $e->getLine();
|
||||||
|
$logContent['all_content'] = "异常信息:\n";
|
||||||
|
$logContent['all_content'] = "接口:send_msg_deepseek\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([], $logContent, null);
|
||||||
|
return $this->msg(99999);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deepseek_only_onec_action($xinxi){
|
||||||
|
// DeepSeek API密钥
|
||||||
|
// $apiKey = 'sk-28dd23215ef84772b64d77011419e271';
|
||||||
|
$apiKey = 'bd739e8c-91af-40bb-85d4-0804060b2390';
|
||||||
|
// DeepSeek API的端点
|
||||||
|
// $apiUrl = 'https://api.deepseek.com/v1/chat/completions';
|
||||||
|
$apiUrl = 'https://ark.cn-beijing.volces.com/api/v3/chat/completions';
|
||||||
|
|
||||||
|
|
||||||
|
// 准备请求数据
|
||||||
|
$data = [
|
||||||
|
"messages" => [
|
||||||
|
[
|
||||||
|
"content" => "你是一个有关身体健康的专家,能根据用户提供的身体数据给出对应的分析和建议",
|
||||||
|
"role" => "system"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"content" => $xinxi['xinxi'],
|
||||||
|
"role" => "user"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
// "model" => "deepseek-chat",
|
||||||
|
"model" => "ep-20250304141108-x9d7l",
|
||||||
|
"frequency_penalty" => 0,
|
||||||
|
"max_tokens" => 2048,
|
||||||
|
"presence_penalty" => 0,
|
||||||
|
"response_format" => [
|
||||||
|
"type" => "text" //指定生成文本的格式。"type": 指定格式类型,例如"text"(纯文本)或"json"(JSON格式)。
|
||||||
|
],
|
||||||
|
"stop" => null,
|
||||||
|
"stream" => false,
|
||||||
|
"stream_options" => null,
|
||||||
|
"temperature" => 1,
|
||||||
|
"top_p" => 1,
|
||||||
|
"tools" => null,
|
||||||
|
"tool_choice" => "none",
|
||||||
|
"logprobs" => false,
|
||||||
|
"top_logprobs" => null
|
||||||
|
];
|
||||||
|
|
||||||
|
// 初始化cURL会话
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
// 设置cURL选项
|
||||||
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 禁用证书验证
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $apiUrl); // 设置API URL
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true); // 使用POST方法
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 设置POST数据
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||||
|
'Authorization: Bearer ' . $apiKey, // 设置API密钥
|
||||||
|
'Content-Type: application/json', // 设置请求头为JSON
|
||||||
|
]);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应而不是直接输出
|
||||||
|
|
||||||
|
// 执行cURL请求并获取响应
|
||||||
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
|
// 检查是否有cURL错误
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
echo 'cURL请求失败: ' . curl_error($ch);
|
||||||
|
} else {
|
||||||
|
// 获取HTTP状态码
|
||||||
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
if ($httpCode === 200) {
|
||||||
|
// 解析JSON响应
|
||||||
|
$result = json_decode($response, true);
|
||||||
|
// print_r($result); // 输出API响应
|
||||||
|
|
||||||
|
return $this->msg(0,$result['choices'][0]['message']['content']);
|
||||||
|
// dump($result);
|
||||||
|
} else {
|
||||||
|
return $this->msg(['code'=>$httpCode]);
|
||||||
|
// echo 'API请求失败,HTTP状态码: ' . $httpCode;
|
||||||
|
// echo '响应内容: ' . $response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭cURL会话
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deepseek_ceshiyongjiekou(){
|
||||||
|
$curl = curl_init();
|
||||||
|
|
||||||
|
curl_setopt_array($curl, array(
|
||||||
|
CURLOPT_URL => 'https://api.deepseek.com/chat/completions',
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_ENCODING => '',
|
||||||
|
CURLOPT_MAXREDIRS => 10,
|
||||||
|
CURLOPT_TIMEOUT => 0,
|
||||||
|
CURLOPT_FOLLOWLOCATION => true,
|
||||||
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
||||||
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
||||||
|
CURLOPT_POSTFIELDS =>'{
|
||||||
|
"messages": [
|
||||||
|
{
|
||||||
|
"content": "You are a helpful assistant",
|
||||||
|
"role": "system"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"content": "Hi",
|
||||||
|
"role": "user"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"model": "deepseek-chat",
|
||||||
|
"frequency_penalty": 0,
|
||||||
|
"max_tokens": 2048,
|
||||||
|
"presence_penalty": 0,
|
||||||
|
"response_format": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"stop": null,
|
||||||
|
"stream": false,
|
||||||
|
"stream_options": null,
|
||||||
|
"temperature": 1,
|
||||||
|
"top_p": 1,
|
||||||
|
"tools": null,
|
||||||
|
"tool_choice": "none",
|
||||||
|
"logprobs": false,
|
||||||
|
"top_logprobs": null
|
||||||
|
}',
|
||||||
|
CURLOPT_HTTPHEADER => array(
|
||||||
|
'Content-Type: application/json',
|
||||||
|
'Accept: application/json',
|
||||||
|
'Authorization: Bearer <TOKEN>'
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
|
$response = curl_exec($curl);
|
||||||
|
|
||||||
|
curl_close($curl);
|
||||||
|
echo $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -383,26 +383,26 @@ class Login extends Base{
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
// 设置为POST请求
|
// 设置为POST请求
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
// 设置POST数据
|
// 设置POST数据
|
||||||
$postData = array(
|
$postData = array(
|
||||||
'phone' => $tel,
|
'phone' => $tel,
|
||||||
// 'content' => '您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码三分钟内有效,若非本人操作,请忽略!'
|
// 'content' => '您好,欢迎使用Reedaw,您的手机验证码是:'.$code.',验证码三分钟内有效,若非本人操作,请忽略!'
|
||||||
'content' => '【Reedaw】您好,欢迎使用Reedaw,您的验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
'content' => '【Reedaw】您好,欢迎使用Reedaw,您的验证码是:'.$code.',验证码一分钟内有效,若非本人操作,请忽略本短信'
|
||||||
);
|
);
|
||||||
$postData = json_encode($postData);
|
$postData = json_encode($postData);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||||||
// 设置返回结果不直接输出,而是返回到变量中
|
// 设置返回结果不直接输出,而是返回到变量中
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
// 发送请求并获取响应
|
// 发送请求并获取响应
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
// 检查是否有错误发生
|
// 检查是否有错误发生
|
||||||
if (curl_errno($ch)) {
|
if (curl_errno($ch)) {
|
||||||
$error_message = curl_error($ch);
|
$error_message = curl_error($ch);
|
||||||
return "请求错误: " . $error_message;
|
return "请求错误: " . $error_message;
|
||||||
}
|
}
|
||||||
// 关闭cURL会话
|
// 关闭cURL会话
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
// 处理响应
|
// 处理响应
|
||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
return json_decode($response,true);
|
return json_decode($response,true);
|
||||||
|
|
|
||||||
|
|
@ -316,6 +316,7 @@ class Msginformation extends Base{
|
||||||
'page_num'=>$this->page_num,
|
'page_num'=>$this->page_num,
|
||||||
'content_data'=>[]
|
'content_data'=>[]
|
||||||
];
|
];
|
||||||
|
// return $this->msg($return_result);
|
||||||
if($data['type'] != 0){
|
if($data['type'] != 0){
|
||||||
$type_str = " AND type LIKE '%".$data['type']."%'";
|
$type_str = " AND type LIKE '%".$data['type']."%'";
|
||||||
}else{
|
}else{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1,minimum-scale=1, maximum-scale=1,user-scalable=no">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<meta http-equiv="Access-Control-Allow-Origin" content="*">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
|
<meta name="format-detection" content="telephone=no, email=no">
|
||||||
|
<meta name="full-screen" content="true">
|
||||||
|
<meta name="screen-orientation" content="portrait">
|
||||||
|
<meta name="x5-fullscreen" content="true">
|
||||||
|
<meta name="360-fullscreen" content="true">
|
||||||
|
<title>deepseek测试页面</title>
|
||||||
|
<script src="/x_admin/js/jq.js"></script>
|
||||||
|
<style>
|
||||||
|
*{
|
||||||
|
padding: 0 0;
|
||||||
|
margin: 0 0;
|
||||||
|
}
|
||||||
|
.big_box{
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.chat_box {
|
||||||
|
flex: 1;
|
||||||
|
/* overflow-y: auto; */
|
||||||
|
overflow-y: scroll;
|
||||||
|
padding: 10px;
|
||||||
|
border-bottom: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
.input_box {
|
||||||
|
display: flex;
|
||||||
|
padding: 10px;
|
||||||
|
border-top: 1px solid #ccc;
|
||||||
|
}
|
||||||
|
.input_box input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 10px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
.input_box button {
|
||||||
|
margin-left: 10px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border: none;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.message {
|
||||||
|
margin: 10px 0;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.message.user {
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
.message.bot {
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
.message .content {
|
||||||
|
max-width: 70%;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #f1f0f0;
|
||||||
|
}
|
||||||
|
.message.user .content {
|
||||||
|
background-color: #dcf8c6;
|
||||||
|
}
|
||||||
|
.fugai{
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 100vh;
|
||||||
|
color: white;
|
||||||
|
font-size: 10vw;
|
||||||
|
font-weight: bold;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body id="box_k">
|
||||||
|
<div class="big_box">
|
||||||
|
<div class="chat_box" id="chat_box">
|
||||||
|
<!-- 对话内容将在这里展示 -->
|
||||||
|
</div>
|
||||||
|
<div class="input_box">
|
||||||
|
<input type="text" id="message_input" placeholder="输入消息..." value="我是一个河南的25岁女性,身高64.52cm,体重68.00kg,请根据我的这个信息,从睡眠、饮食、运动三个方向给我一些健康建议。">
|
||||||
|
<button id="send_button">发送</button>
|
||||||
|
</div>
|
||||||
|
<div class='fugai'></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var pd = true;
|
||||||
|
$('#send_button').click(function() {
|
||||||
|
|
||||||
|
if(pd == false){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pd = false;
|
||||||
|
var message = $('#message_input').val();
|
||||||
|
if (message.trim() === '') {
|
||||||
|
$('.fugai').html('您没有填写内容')
|
||||||
|
$('.fugai').show()
|
||||||
|
setTimeout(() => {
|
||||||
|
$('.fugai').hide()
|
||||||
|
}, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 显示用户消息
|
||||||
|
$('#chat_box').append('<div class="message user"><div class="content">' + message + '</div></div>');
|
||||||
|
// document.getElementById('scroll_button').addEventListener('click', function() {
|
||||||
|
// var chatBox = document.getElementById('chat_box');
|
||||||
|
// chatBox.scrollTop = chatBox.scrollHeight;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// 清空输入框
|
||||||
|
$('#message_input').val('');
|
||||||
|
$('.fugai').html('思考中请稍等')
|
||||||
|
$('.fugai').show()
|
||||||
|
$.ajax({
|
||||||
|
url:"https://tc.pcxbc.com/ai/send_msg_deepseek", //请求的url地址
|
||||||
|
dataType:"json", //返回格式为json
|
||||||
|
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
|
data:{"xinxi":message}, //参数值
|
||||||
|
type:"POST", //请求方式
|
||||||
|
success:function(req){
|
||||||
|
$('.fugai').hide()
|
||||||
|
pd = true;
|
||||||
|
//请求成功时处理
|
||||||
|
if(req.code == 0){
|
||||||
|
$('#chat_box').append('<div class="message bot"><div class="content">' + req.msg + '</div></div>');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error:function(){
|
||||||
|
//请求出错处理
|
||||||
|
}});
|
||||||
|
// 模拟对方回复
|
||||||
|
// setTimeout(function() {
|
||||||
|
// var reply = '对方回复: ' + message;
|
||||||
|
// $('#chat_box').append('<div class="message bot"><div class="content">' + reply + '</div></div>');
|
||||||
|
// }, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
// // 按下回车键发送消息
|
||||||
|
// $('#message_input').keypress(function(e) {
|
||||||
|
// console.log(e)
|
||||||
|
// // if (e.which == 13) {
|
||||||
|
// // $('#send_button').click();
|
||||||
|
// // }
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<title>下载页面</title>
|
<title>下载页面</title>
|
||||||
<script src="/x_admin/js/jq.js"></script>
|
<script src="/x_admin/js/jq.js"></script>
|
||||||
<style>
|
<style>
|
||||||
*{
|
*{
|
||||||
padding: 0 0;
|
padding: 0 0;
|
||||||
margin: 0 0;
|
margin: 0 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,17 @@ Route::any('/device_api_1', 'admin/device/device_request_api');
|
||||||
Route::any('/see_device_msg', 'admin/device/see_device_msg');
|
Route::any('/see_device_msg', 'admin/device/see_device_msg');
|
||||||
|
|
||||||
|
|
||||||
|
// // ################################################################AI接口处理################################################################
|
||||||
|
// // ################################################################AI接口处理################################################################
|
||||||
|
// 调用deepseek接口
|
||||||
|
Route::any('/ai/send_msg_deepseek', 'app/deepseek/send_msg_deepseek');
|
||||||
|
// ai测试页面
|
||||||
|
Route::any('/ai/test_index', 'app/deepseek/test_index');
|
||||||
|
|
||||||
|
|
||||||
|
// Route::any('/testedition/get_all_record_data_group', 'testapp/pagingcontrast/get_all_record_data_group');
|
||||||
|
|
||||||
|
|
||||||
// // ################################################################管理后台################################################################
|
// // ################################################################管理后台################################################################
|
||||||
// // ################################################################管理后台################################################################
|
// // ################################################################管理后台################################################################
|
||||||
|
|
||||||
|
|
@ -407,11 +418,15 @@ Route::any('/testedition/kitchenscale/pic_upload_action', 'app/kitchenscale/test
|
||||||
|
|
||||||
// 首页内容################################################################
|
// 首页内容################################################################
|
||||||
// 获取配置类信息
|
// 获取配置类信息
|
||||||
Route::any('/kitchenscale/get_default_config', 'app/kitchenscale/app.index/get_default_config');
|
Route::any('/kitchenscale/get_default_config', 'app/Kitchenscale/app.Index/get_default_config');
|
||||||
Route::any('/testedition/kitchenscale/get_default_config', 'app/kitchenscale/testapp.index/get_default_config');
|
Route::any('/testedition/kitchenscale/get_default_config', 'app/kitchenscale/testapp.index/get_default_config');
|
||||||
// 获取首页页面展示数据
|
// 获取首页页面展示数据
|
||||||
Route::any('/kitchenscale/get_homepage_information', 'app/kitchenscale/app.index/get_homepage_information');
|
Route::any('/kitchenscale/get_homepage_information', 'app/kitchenscale/app.index/get_homepage_information');
|
||||||
Route::any('/testedition/kitchenscale/get_homepage_information', 'app/kitchenscale/testapp.index/get_homepage_information');
|
Route::any('/testedition/kitchenscale/get_homepage_information', 'app/kitchenscale/testapp.index/get_homepage_information');
|
||||||
|
// 首页搜索接口
|
||||||
|
Route::any('/kitchenscale/search_column', 'app/kitchenscale/app.index/search_column');
|
||||||
|
Route::any('/testedition/kitchenscale/search_column', 'app/kitchenscale/testapp.index/search_column');
|
||||||
|
|
||||||
|
|
||||||
// 菜谱内容################################################################
|
// 菜谱内容################################################################
|
||||||
// 添加菜谱
|
// 添加菜谱
|
||||||
|
|
@ -432,7 +447,9 @@ Route::any('/testedition/kitchenscale/cookbook_follow', 'app/kitchenscale/testap
|
||||||
// 收藏菜谱
|
// 收藏菜谱
|
||||||
Route::any('/kitchenscale/cookbook_like', 'app/kitchenscale/app.cookbook/cookbook_like');
|
Route::any('/kitchenscale/cookbook_like', 'app/kitchenscale/app.cookbook/cookbook_like');
|
||||||
Route::any('/testedition/kitchenscale/cookbook_like', 'app/kitchenscale/testapp.cookbook/cookbook_like');
|
Route::any('/testedition/kitchenscale/cookbook_like', 'app/kitchenscale/testapp.cookbook/cookbook_like');
|
||||||
|
// 获取当前食材重量卡路里
|
||||||
|
Route::any('/kitchenscale/food_count_kcal', 'app/kitchenscale/app.cookbook/food_count_kcal');
|
||||||
|
Route::any('/testedition/kitchenscale/food_count_kcal', 'app/kitchenscale/testapp.cookbook/food_count_kcal');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,8 @@
|
||||||
console.log(pair[0] + ': ' + pair[1]);
|
console.log(pair[0] + ': ' + pair[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(submit_data);
|
||||||
|
return
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://wm.tcxbc.com/kitchenscale/add_cookbook", // 请求的url地址
|
url: "http://wm.tcxbc.com/kitchenscale/add_cookbook", // 请求的url地址
|
||||||
contentType: false,
|
contentType: false,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
width: 95vw;
|
width: 95vw;
|
||||||
height: 100vw;
|
height: 100vw;
|
||||||
background-color: #ccc;
|
background-color: #ccc;
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 20%;
|
top: 20%;
|
||||||
left: 0;
|
left: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|
@ -100,7 +100,7 @@
|
||||||
<script>
|
<script>
|
||||||
// 设置最终提交变量(important)
|
// 设置最终提交变量(important)
|
||||||
var post_data = {
|
var post_data = {
|
||||||
"cook_label": '早餐', //菜谱标签,属于什么菜系之类的
|
"cook_label": '家常菜谱', //菜谱标签,属于什么菜系之类的
|
||||||
"token": 'caadd1be045a65f30b92aa805f1de54a', //菜谱标签,属于什么菜系之类的
|
"token": 'caadd1be045a65f30b92aa805f1de54a', //菜谱标签,属于什么菜系之类的
|
||||||
"cover": '', //封面图片
|
"cover": '', //封面图片
|
||||||
"title": '', //菜谱标题
|
"title": '', //菜谱标题
|
||||||
|
|
@ -402,8 +402,8 @@
|
||||||
// 最终数据格式示意end
|
// 最终数据格式示意end
|
||||||
console.log(post_data)
|
console.log(post_data)
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:"https://tc.pcxbc.com/kitchenscale/add_cookbook", //请求的url地址
|
// url:"https://tc.pcxbc.com/kitchenscale/add_cookbook", //请求的url地址
|
||||||
// url:"http://wm.tcxbc.com/kitchenscale/add_cookbook", //请求的url地址
|
url:"http://wm.tcxbc.com/kitchenscale/add_cookbook", //请求的url地址
|
||||||
dataType:"json", //返回格式为json
|
dataType:"json", //返回格式为json
|
||||||
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
async:true,//请求是否异步,默认为异步,这也是ajax重要特性
|
||||||
data:post_data, //参数值
|
data:post_data, //参数值
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue