2025-07-23 21:32:05 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\test\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use think\Controller;
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
use app\bj\controller\Common;
|
|
|
|
|
|
use think\Log;
|
|
|
|
|
|
use \think\Validate;
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
2025-08-02 23:03:04 +08:00
|
|
|
|
use app\app\controller\Smsaliyun;
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
class Testuse extends Controller{
|
|
|
|
|
|
|
|
|
|
|
|
// 收集表A
|
|
|
|
|
|
public function readExcelFile_a() {
|
|
|
|
|
|
// Excel文件路径(示例)
|
|
|
|
|
|
$filePath = 'D:\数据\厨房秤\食谱\excelA.xlsx';
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 加载Excel文件
|
|
|
|
|
|
$spreadsheet = IOFactory::load($filePath);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取第一个工作表(Sheet1)
|
|
|
|
|
|
$sheet = $spreadsheet->getSheet(0);
|
|
|
|
|
|
|
|
|
|
|
|
// 将工作表数据转换为数组
|
|
|
|
|
|
$data = $sheet->toArray();
|
|
|
|
|
|
|
|
|
|
|
|
$temporary_arr_title = $data[0];
|
|
|
|
|
|
unset($data[0]);
|
|
|
|
|
|
$temporary_arr = [];
|
|
|
|
|
|
$temporary_arr2 = [];
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
|
if($value[0] == 112 || $value[0] == 113 || $value[0] == 114 || $value[0] == 115 || $value[0] == 116 || $value[0] == 117 || $value[0] == 118 || $value[0] == 119 || $value[0] == 120 || $value[0] == 121){
|
|
|
|
|
|
// unset();
|
|
|
|
|
|
unset($data[$key]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
|
$temporary_arr2 = [];
|
|
|
|
|
|
foreach ($temporary_arr_title as $k => $v) {
|
|
|
|
|
|
$temporary_arr2[$v] = $value[$k];
|
|
|
|
|
|
}
|
|
|
|
|
|
array_push($temporary_arr,$temporary_arr2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($temporary_arr as $key => $value) {
|
|
|
|
|
|
$temporary_arr[$key]['record_id'] = $value['id'];
|
|
|
|
|
|
$temporary_arr[$key]['Calorie_name'] = $value['Calorie'];
|
|
|
|
|
|
$temporary_arr[$key]['Protein_name'] = $value['Protein'];
|
|
|
|
|
|
$temporary_arr[$key]['Fat_name'] = $value['Fat'];
|
|
|
|
|
|
$temporary_arr[$key]['Carbohydrate_name'] = $value['Carbohydrate'];
|
|
|
|
|
|
$temporary_arr[$key]['food_name'] = $value['name'];
|
|
|
|
|
|
unset($temporary_arr[$key]['id']);
|
|
|
|
|
|
unset($temporary_arr[$key]['Calorie']);
|
|
|
|
|
|
unset($temporary_arr[$key]['Protein']);
|
|
|
|
|
|
unset($temporary_arr[$key]['Fat']);
|
|
|
|
|
|
unset($temporary_arr[$key]['Carbohydrate']);
|
|
|
|
|
|
unset($temporary_arr[$key]['name']);
|
|
|
|
|
|
|
|
|
|
|
|
if($value['image'] == ''){
|
|
|
|
|
|
$temporary_arr[$key]['pic_url'] = '/food_img/none.png';
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$result = $this->downloadImageWithName($value['image'], $value['id']);
|
|
|
|
|
|
if($result['success'] == true){
|
|
|
|
|
|
$temporary_arr[$key]['pic_url'] = '/food_img/'.$result['filename'];
|
|
|
|
|
|
}else{
|
|
|
|
|
|
$temporary_arr[$key]['pic_url'] = 'error';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
unset($temporary_arr[$key]['image']);
|
|
|
|
|
|
}
|
|
|
|
|
|
// dump($temporary_arr);
|
|
|
|
|
|
// die;
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// 获取账号下信息以及用户信息
|
|
|
|
|
|
$user_data = $cfc->table('app_z_national_standard_food_type_3')->insertAll($temporary_arr);
|
|
|
|
|
|
|
|
|
|
|
|
dump($user_data);
|
|
|
|
|
|
|
|
|
|
|
|
die;
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
// 输出错误信息
|
|
|
|
|
|
dump(['error' => true, 'message' => $e->getMessage()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 收集表B
|
|
|
|
|
|
public function readExcelFile_b() {
|
|
|
|
|
|
// Excel文件路径(示例)
|
|
|
|
|
|
$filePath = 'D:\数据\厨房秤\食谱\excelB.xlsx';
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 加载Excel文件
|
|
|
|
|
|
$spreadsheet = IOFactory::load($filePath);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取第一个工作表(Sheet1)
|
|
|
|
|
|
$sheet = $spreadsheet->getSheet(0);
|
|
|
|
|
|
|
|
|
|
|
|
// 将工作表数据转换为数组
|
|
|
|
|
|
$data = $sheet->toArray();
|
|
|
|
|
|
|
|
|
|
|
|
$temporary_arr_title = $data[0];
|
|
|
|
|
|
unset($data[0]);
|
|
|
|
|
|
$temporary_arr = [];
|
|
|
|
|
|
$temporary_arr2 = [];
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
|
if($value[0] == 112 || $value[0] == 113 || $value[0] == 114 || $value[0] == 115 || $value[0] == 116 || $value[0] == 117 || $value[0] == 118 || $value[0] == 119 || $value[0] == 120 || $value[0] == 121){
|
|
|
|
|
|
// unset();
|
|
|
|
|
|
unset($data[$key]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-26 16:35:42 +08:00
|
|
|
|
$type_arr = [
|
|
|
|
|
|
'Calorie' => 1,
|
|
|
|
|
|
'Protein' => 1,
|
|
|
|
|
|
'Fat' => 1,
|
|
|
|
|
|
'Carbohydrate' => 1,
|
|
|
|
|
|
'VitaminA' => 2,
|
|
|
|
|
|
'VitaminB1' => 2,
|
|
|
|
|
|
'VitaminB2' => 2,
|
|
|
|
|
|
'VitaminB6' => 2,
|
|
|
|
|
|
'VitaminB12' => 2,
|
|
|
|
|
|
'VitaminD' => 2,
|
|
|
|
|
|
'VitaminK' => 2,
|
|
|
|
|
|
'Niacin' => 2,
|
|
|
|
|
|
'VitaminC' => 2,
|
|
|
|
|
|
'VitaminE' => 2,
|
|
|
|
|
|
'FolicAcid' => 2,
|
|
|
|
|
|
'Biotin' => 2,
|
|
|
|
|
|
'PantothenicAcid' => 2,
|
|
|
|
|
|
'TotalCholine' => 2,
|
|
|
|
|
|
'Ca' => 3,
|
|
|
|
|
|
'Phosphorus' => 3,
|
|
|
|
|
|
'Kalium' => 3,
|
|
|
|
|
|
'Mg' => 3,
|
|
|
|
|
|
'Na' => 3,
|
|
|
|
|
|
'Fe' => 3,
|
|
|
|
|
|
'Zn' => 3,
|
|
|
|
|
|
'Se' => 3,
|
|
|
|
|
|
'Cu' => 3,
|
|
|
|
|
|
'Mn' => 3,
|
|
|
|
|
|
'Iodine' => 3,
|
|
|
|
|
|
];
|
2025-07-23 21:32:05 +08:00
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
|
$temporary_arr2 = [];
|
|
|
|
|
|
foreach ($temporary_arr_title as $k => $v) {
|
|
|
|
|
|
$temporary_arr2[$v] = $value[$k];
|
|
|
|
|
|
}
|
|
|
|
|
|
$temporary_arr2['name_ch'] = $temporary_arr2['desc'];
|
|
|
|
|
|
unset($temporary_arr2['desc']);
|
|
|
|
|
|
unset($temporary_arr2['description']);
|
2025-09-26 16:35:42 +08:00
|
|
|
|
$temporary_arr2['type'] = $type_arr[$temporary_arr2['name']];
|
2025-07-23 21:32:05 +08:00
|
|
|
|
array_push($temporary_arr,$temporary_arr2);
|
|
|
|
|
|
}
|
2025-09-26 16:35:42 +08:00
|
|
|
|
// dump($type_arr);
|
2025-07-23 21:32:05 +08:00
|
|
|
|
// dump($temporary_arr);
|
2025-09-26 16:35:42 +08:00
|
|
|
|
// die;
|
2025-07-23 21:32:05 +08:00
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// 获取账号下信息以及用户信息
|
|
|
|
|
|
$user_data = $cfc->table('app_z_national_standard_food_type_4')->insertAll($temporary_arr);
|
|
|
|
|
|
|
|
|
|
|
|
dump($user_data);
|
|
|
|
|
|
|
|
|
|
|
|
die;
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
// 输出错误信息
|
|
|
|
|
|
dump(['error' => true, 'message' => $e->getMessage()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function downloadImageWithName($remoteUrl, $name, $localDir = '')
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 设置默认本地目录
|
|
|
|
|
|
if (empty($localDir)) {
|
|
|
|
|
|
$localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\food_img';
|
|
|
|
|
|
// $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img';
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查并创建目录
|
|
|
|
|
|
if (!is_dir($localDir)) {
|
|
|
|
|
|
mkdir($localDir, 0755, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从URL中获取文件扩展名
|
|
|
|
|
|
$urlParts = parse_url($remoteUrl);
|
|
|
|
|
|
$pathInfo = pathinfo($urlParts['path']);
|
|
|
|
|
|
$extension = isset($pathInfo['extension']) ? $pathInfo['extension'] : 'jpg';
|
|
|
|
|
|
|
|
|
|
|
|
// 构建完整文件名和路径
|
|
|
|
|
|
$filename = $name . 'xt' . time() . '.jpg';
|
|
|
|
|
|
$localPath = rtrim($localDir, '/\\') . DIRECTORY_SEPARATOR . $filename;
|
|
|
|
|
|
|
|
|
|
|
|
// 使用cURL下载图片
|
|
|
|
|
|
$ch = curl_init($remoteUrl);
|
|
|
|
|
|
$fp = fopen($localPath, 'wb');
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
|
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
|
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证下载结果
|
|
|
|
|
|
if ($result === false || $httpCode != 200 || !file_exists($localPath)) {
|
|
|
|
|
|
throw new \Exception('图片下载或保存失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 返回简化结果
|
|
|
|
|
|
return [
|
|
|
|
|
|
'success' => true,
|
|
|
|
|
|
'filename' => $filename
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
Log::error('图片下载失败: ' . $e->getMessage() . ' URL: ' . $remoteUrl);
|
|
|
|
|
|
return [
|
|
|
|
|
|
'success' => false,
|
|
|
|
|
|
'filename' => ''
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function downloadImageWithName2($remoteUrl, $name, $localDir = ''){
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 设置默认本地目录
|
|
|
|
|
|
if (empty($localDir)) {
|
|
|
|
|
|
// $localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\food_img';
|
|
|
|
|
|
$localDir = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img';
|
|
|
|
|
|
}
|
|
|
|
|
|
// 检查并创建目录
|
|
|
|
|
|
if (!is_dir($localDir)) {
|
|
|
|
|
|
mkdir($localDir, 0755, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 从URL中获取文件扩展名
|
|
|
|
|
|
$urlParts = parse_url($remoteUrl);
|
|
|
|
|
|
$pathInfo = pathinfo($urlParts['path']);
|
|
|
|
|
|
$extension = isset($pathInfo['extension']) ? $pathInfo['extension'] : 'jpg';
|
|
|
|
|
|
|
|
|
|
|
|
// 构建完整文件名和路径
|
|
|
|
|
|
$filename = $name . 'cook' . time() . '.jpg';
|
|
|
|
|
|
$localPath = rtrim($localDir, '/\\') . DIRECTORY_SEPARATOR . $filename;
|
|
|
|
|
|
|
|
|
|
|
|
// 使用cURL下载图片
|
|
|
|
|
|
$ch = curl_init($remoteUrl);
|
|
|
|
|
|
$fp = fopen($localPath, 'wb');
|
|
|
|
|
|
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
|
|
|
|
|
|
|
|
|
$result = curl_exec($ch);
|
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
|
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
|
|
|
|
// 验证下载结果
|
|
|
|
|
|
if ($result === false || $httpCode != 200 || !file_exists($localPath)) {
|
|
|
|
|
|
return [
|
|
|
|
|
|
'success' => false,
|
|
|
|
|
|
'filename' => '图片下载或保存失败'
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 返回简化结果
|
|
|
|
|
|
return [
|
|
|
|
|
|
'success' => true,
|
|
|
|
|
|
'filename' => $filename
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
Log::error('图片下载失败: ' . $e->getMessage() . ' URL: ' . $remoteUrl);
|
|
|
|
|
|
return [
|
|
|
|
|
|
'success' => false,
|
|
|
|
|
|
'filename' => '图片下载或保存失败'
|
|
|
|
|
|
];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
// 偷数据存start#########################################################################################################
|
|
|
|
|
|
public function save_caidan_content(){
|
|
|
|
|
|
|
|
|
|
|
|
// 添加CORS响应头(必须放在任何输出之前)
|
|
|
|
|
|
header('Access-Control-Allow-Origin: https://www.nutridata.cn');
|
|
|
|
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是OPTIONS预检请求,直接返回204
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
|
|
header('HTTP/1.1 204 No Content');
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
|
$pic = 'none_str';
|
|
|
|
|
|
// if($data['image'] == ''){
|
|
|
|
|
|
// $pic = '/kitchenscale_all/food_img/none.png';
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
// $result = $this->downloadImageWithName2($data['image'], $data['id']);
|
|
|
|
|
|
// if($result['success'] == true){
|
|
|
|
|
|
// $pic = '/kitchenscale_all/cook_img/'.$result['filename'];
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
// $pic = 'error';
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
$save_data['content'] = json_encode($data);
|
|
|
|
|
|
// $save_data['pic_url'] = $pic;
|
|
|
|
|
|
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// 获取账号下信息以及用户信息
|
|
|
|
|
|
$user_data = $cfc->table('linshi_caidan_biao')->insert($save_data);
|
|
|
|
|
|
|
|
|
|
|
|
if($user_data){
|
|
|
|
|
|
return $this->msg(0,'success',[]);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return $this->msg(9999,'error',[]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 偷数据存end#########################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理(洗)偷过来的数据start#########################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
public function clean_data_all_page(){
|
|
|
|
|
|
return $this->fetch();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function clean_data_all(){
|
|
|
|
|
|
|
|
|
|
|
|
$page = 1;
|
|
|
|
|
|
$ok_num = 0;
|
|
|
|
|
|
$no_num = 0;
|
|
|
|
|
|
$jieshou_data = input();
|
|
|
|
|
|
|
|
|
|
|
|
$page = $jieshou_data['page'];
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$cha = $cfc->table('linshi_caidan_biao')->where('is_clean = 0')->page("$page,25")->select();
|
|
|
|
|
|
|
|
|
|
|
|
// dump();
|
|
|
|
|
|
// die;
|
|
|
|
|
|
if(count($cha) <= 0){
|
|
|
|
|
|
return $this->msg(99999,'失败',[]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($cha as $key => $value) {
|
|
|
|
|
|
$cha[$key]['data'] = json_decode($value['content'],true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$cookbook_arr = [];
|
|
|
|
|
|
$foodlist_arr = [];
|
|
|
|
|
|
|
|
|
|
|
|
$cookbook_nutrition = [];//营养
|
|
|
|
|
|
$cookbook_vitamin = [];//维生素
|
|
|
|
|
|
$cookbook_mineral = [];//矿物质
|
|
|
|
|
|
$cookbook_quantifier = [];//量词
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$foodlist_arr_temporary = [];
|
|
|
|
|
|
foreach ($cha as $key => $value) {
|
|
|
|
|
|
$cookbook_nutrition = [];//营养
|
|
|
|
|
|
$cookbook_vitamin = [];//维生素
|
|
|
|
|
|
$cookbook_mineral = [];//矿物质
|
|
|
|
|
|
$cookbook_quantifier = [];//量词
|
|
|
|
|
|
$cookbook_arr = [];
|
|
|
|
|
|
$foodlist_arr_temporary = [];
|
|
|
|
|
|
// 处理食谱详情
|
|
|
|
|
|
$cookbook_arr['title'] = $value['data']['name'];
|
|
|
|
|
|
$cookbook_arr['cover'] = 19;
|
|
|
|
|
|
$cookbook_arr['create_user_token'] = 'caadd1be045a65f30b92aa805f1de54a';
|
|
|
|
|
|
$cookbook_arr['create_user_head_pic'] = "https://tc.pcxbc.com/tsf/head_pic.png";
|
|
|
|
|
|
$cookbook_arr['create_user_nickname'] = "clown";
|
|
|
|
|
|
$cookbook_arr['describe_data'] = "";
|
|
|
|
|
|
$cookbook_arr['food_data'] = [];
|
|
|
|
|
|
$cookbook_arr['step_data'] = [];
|
|
|
|
|
|
$cookbook_arr['create_time'] = date('Y-m-d H:i:s');
|
|
|
|
|
|
$cookbook_arr['cook_label'] = 8;
|
|
|
|
|
|
$cookbook_arr['original_cookbook_id'] = $value['data']['id'];
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($value['data']['major'] as $k1 => $v1) {
|
|
|
|
|
|
$zhao = $cfc->table('app_z_national_standard_food_type_3')->where(['record_id'=>$v1['ingrId']])->select();
|
|
|
|
|
|
if(count($zhao) > 0){
|
|
|
|
|
|
array_push($cookbook_arr['food_data'],[
|
|
|
|
|
|
'id' => $zhao[0]['id'],
|
|
|
|
|
|
'name' => $zhao[0]['food_name'],
|
|
|
|
|
|
'weight' => $v1['note'],
|
|
|
|
|
|
'kcal' => $zhao[0]['Calorie_val'],
|
|
|
|
|
|
'unit' => 'g',
|
|
|
|
|
|
]);
|
|
|
|
|
|
array_push($foodlist_arr_temporary,$zhao[0]['id']);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($value['data']['dishCooksteps'] as $k2 => $v2) {
|
|
|
|
|
|
if($v2['content'] != ''){
|
|
|
|
|
|
array_push($cookbook_arr['step_data'],[
|
|
|
|
|
|
'pic_list' => [],
|
|
|
|
|
|
'description' => $v2['content']
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$cookbook_arr['food_data'] = json_encode($cookbook_arr['food_data']);
|
|
|
|
|
|
$cookbook_arr['step_data'] = json_encode($cookbook_arr['step_data']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理营养物质
|
|
|
|
|
|
foreach ($value['data']['nutritionMap']['能量及宏量营养素'] as $nutrition_k => $nutrition_v) {
|
|
|
|
|
|
array_push($cookbook_nutrition,[
|
|
|
|
|
|
'name_en'=>$nutrition_v['name'],
|
|
|
|
|
|
'name_ch'=>$nutrition_v['desc'],
|
|
|
|
|
|
'unit'=>$nutrition_v['unit'],
|
|
|
|
|
|
'value'=>$nutrition_v['value'],
|
|
|
|
|
|
'nrv'=>$nutrition_v['nrv'],
|
|
|
|
|
|
'nutriSort'=>$nutrition_v['nutriSort'],
|
|
|
|
|
|
'description'=>$nutrition_v['description'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理维生素
|
|
|
|
|
|
foreach ($value['data']['nutritionMap']['维生素'] as $vitamin_k => $vitamin_v) {
|
|
|
|
|
|
array_push($cookbook_vitamin,[
|
|
|
|
|
|
'name_en'=>$vitamin_v['name'],
|
|
|
|
|
|
'name_ch'=>$vitamin_v['desc'],
|
|
|
|
|
|
'unit'=>$vitamin_v['unit'],
|
|
|
|
|
|
'value'=>$vitamin_v['value'],
|
|
|
|
|
|
'nrv'=>$vitamin_v['nrv'],
|
|
|
|
|
|
'nutriSort'=>$vitamin_v['nutriSort'],
|
|
|
|
|
|
'description'=>$vitamin_v['description'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理矿物质
|
|
|
|
|
|
foreach ($value['data']['nutritionMap']['矿物质'] as $mineral_k => $mineral_v) {
|
|
|
|
|
|
array_push($cookbook_mineral,[
|
|
|
|
|
|
'name_en'=>$mineral_v['name'],
|
|
|
|
|
|
'name_ch'=>$mineral_v['desc'],
|
|
|
|
|
|
'unit'=>$mineral_v['unit'],
|
|
|
|
|
|
'value'=>$mineral_v['value'],
|
|
|
|
|
|
'nrv'=>$mineral_v['nrv'],
|
|
|
|
|
|
'nutriSort'=>$mineral_v['nutriSort'],
|
|
|
|
|
|
'description'=>$mineral_v['description'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理量词
|
|
|
|
|
|
foreach ($value['data']['unit'] as $quantifier_k => $quantifier_v) {
|
|
|
|
|
|
array_push($cookbook_quantifier,[
|
|
|
|
|
|
'name_ch'=>$quantifier_v['unit'],
|
|
|
|
|
|
'value'=>$quantifier_v['value'],
|
|
|
|
|
|
]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 启动事务
|
|
|
|
|
|
$cfc->startTrans();
|
|
|
|
|
|
try{
|
|
|
|
|
|
// 存食谱
|
|
|
|
|
|
$cook_book_id = $cfc->table('app_user_cookbook')->insertGetId($cookbook_arr);
|
|
|
|
|
|
// 存食谱所含食材
|
|
|
|
|
|
$foodlist_arr = [];
|
|
|
|
|
|
foreach ($foodlist_arr_temporary as $k3 => $v3) {
|
|
|
|
|
|
array_push($foodlist_arr,['cookbook_id'=>$cook_book_id,'food_id'=>$v3]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$cfc->table('app_user_cookbook_food_relation')->insertAll($foodlist_arr);
|
|
|
|
|
|
//存营养
|
|
|
|
|
|
foreach ($cookbook_nutrition as $k4 => $v4) {
|
|
|
|
|
|
$cookbook_nutrition[$k4]['cookbook_id'] = $cook_book_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
// dump($cookbook_nutrition);
|
|
|
|
|
|
$cfc->table('app_user_cookbook_nutrition')->insertAll($cookbook_nutrition);
|
|
|
|
|
|
//存维生素
|
|
|
|
|
|
foreach ($cookbook_vitamin as $k5 => $v5) {
|
|
|
|
|
|
$cookbook_vitamin[$k5]['cookbook_id'] = $cook_book_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
// dump($cookbook_vitamin);
|
|
|
|
|
|
$cfc->table('app_user_cookbook_vitamin')->insertAll($cookbook_vitamin);
|
|
|
|
|
|
//存矿物质
|
|
|
|
|
|
foreach ($cookbook_mineral as $k6 => $v6) {
|
|
|
|
|
|
$cookbook_mineral[$k6]['cookbook_id'] = $cook_book_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
// dump($cookbook_mineral);
|
|
|
|
|
|
$cfc->table('app_user_cookbook_mineral')->insertAll($cookbook_mineral);
|
|
|
|
|
|
// //存量词
|
|
|
|
|
|
foreach ($cookbook_quantifier as $k7 => $v7) {
|
|
|
|
|
|
$cookbook_quantifier[$k7]['cookbook_id'] = $cook_book_id;
|
|
|
|
|
|
}
|
|
|
|
|
|
$cfc->table('app_user_cookbook_quantifier')->insertAll($cookbook_quantifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改原始数据
|
|
|
|
|
|
$cfc->table('linshi_caidan_biao')->where(['id'=>$value['id']])->update(['is_clean'=>1,'name'=>$value['data']['name'],'yuanshi_id'=>$value['data']['id']]);
|
|
|
|
|
|
// 提交事务
|
|
|
|
|
|
$cfc->commit();
|
|
|
|
|
|
$ok_num = $ok_num+1;
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
// 回滚事务
|
|
|
|
|
|
$cfc->rollback();
|
|
|
|
|
|
$no_num = $no_num+1;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// dump($ok_num);
|
|
|
|
|
|
// dump($no_num);
|
|
|
|
|
|
// die;
|
|
|
|
|
|
return $this->msg(0,'成功',['ok'=>$ok_num,'no'=>$no_num]);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 处理(洗)偷过来的数据end#########################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取图片接口start#########################################################################################################
|
|
|
|
|
|
public function download_picture_api(){
|
|
|
|
|
|
// 添加CORS响应头(必须放在任何输出之前)
|
|
|
|
|
|
header('Access-Control-Allow-Origin: https://www.nutridata.cn');
|
|
|
|
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是OPTIONS预检请求,直接返回204
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
|
|
header('HTTP/1.1 204 No Content');
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$result = $cfc->table('linshi_caidan_biao')->where("pic_clean = 0")->field('id,pic_url,is_clean,name,yuanshi_id')->find();
|
|
|
|
|
|
if($result){
|
|
|
|
|
|
return $this->msg(0,'成功',$result);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return $this->msg(99999,'失败',[]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function update_cookbook_data_api(){
|
|
|
|
|
|
// 添加CORS响应头(必须放在任何输出之前)
|
|
|
|
|
|
header('Access-Control-Allow-Origin: https://www.nutridata.cn');
|
|
|
|
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是OPTIONS预检请求,直接返回204
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
|
|
header('HTTP/1.1 204 No Content');
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
|
// return $this->msg(0,'成功',$data);
|
|
|
|
|
|
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$result = $cfc->table('linshi_caidan_biao')->where(["yuanshi_id"=>$data['id']])->update(['category'=>$data['category']]);
|
|
|
|
|
|
if($result){
|
|
|
|
|
|
return $this->msg(0,'成功',$result);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
return $this->msg(99999,'失败',[]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function cun_bendi_pic()
|
|
|
|
|
|
{
|
|
|
|
|
|
// 记录接收到的数据
|
|
|
|
|
|
// file_put_contents('request_log.txt', date('Y-m-d H:i:s')."\n".json_encode($_POST)."\n\n", FILE_APPEND);
|
|
|
|
|
|
// 强制设置 JSON 响应头
|
|
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
|
|
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
|
|
exit;
|
|
|
|
|
|
}
|
|
|
|
|
|
$data = input('post.');
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$msg_str = '本次存储成功';
|
|
|
|
|
|
$update_data = [
|
|
|
|
|
|
'pic_clean'=>1
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
if(!array_key_exists('id',$data) || $data['id'] == ''){
|
|
|
|
|
|
// $update_data['pic_url'] = 'id_miss';
|
|
|
|
|
|
// $updateResult = $cfc->table('linshi_caidan_biao')
|
|
|
|
|
|
// ->where(["yuanshi_id" => $data['id']])
|
|
|
|
|
|
// ->update($update_data);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->msg(0, $msg_str,'id_miss');
|
|
|
|
|
|
}
|
|
|
|
|
|
if(!array_key_exists('image',$data) || $data['image'] == ''){
|
|
|
|
|
|
$update_data['pic_url'] = 'no_data';
|
|
|
|
|
|
$updateResult = $cfc->table('linshi_caidan_biao')
|
|
|
|
|
|
->where(["yuanshi_id" => $data['id']])
|
|
|
|
|
|
->update($update_data);
|
|
|
|
|
|
return $this->msg(0, $msg_str,'no_data');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$pic_result = $this->downloadImageWithName2($data['image'],$data['id']);
|
|
|
|
|
|
|
|
|
|
|
|
$update_data['pic_url'] = $pic_result['filename'];
|
|
|
|
|
|
|
|
|
|
|
|
// 更新数据库
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$updateResult = $cfc->table('linshi_caidan_biao')
|
|
|
|
|
|
->where(["yuanshi_id" => $data['id']])
|
|
|
|
|
|
->update($update_data);
|
|
|
|
|
|
|
|
|
|
|
|
return $this->msg(0, $msg_str,$updateResult);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public function cun_bendi_pic()
|
|
|
|
|
|
// {
|
|
|
|
|
|
// // 强制设置 JSON 响应头
|
|
|
|
|
|
// header('Content-Type: application/json; charset=utf-8');
|
|
|
|
|
|
// header('Access-Control-Allow-Origin: *');
|
|
|
|
|
|
// header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
|
|
|
|
// header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
|
|
|
|
|
|
|
|
// if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|
|
|
|
|
// exit;
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
// // 确保获取原始 POST 数据
|
|
|
|
|
|
// $rawData = file_get_contents('php://input');
|
|
|
|
|
|
// $data = json_decode($rawData, true);
|
|
|
|
|
|
|
|
|
|
|
|
// if (empty($data['id']) || empty($data['image'])) {
|
|
|
|
|
|
// throw new Exception('参数不完整');
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 验证 id 是否为整数
|
|
|
|
|
|
// if (!is_numeric($data['id'])) {
|
|
|
|
|
|
// throw new Exception('ID 必须为整数');
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// $id = (int)$data['id'];
|
|
|
|
|
|
// $ossUrl = trim($data['image']);
|
|
|
|
|
|
|
|
|
|
|
|
// // 验证 OSS 链接
|
|
|
|
|
|
// if (!filter_var($ossUrl, FILTER_VALIDATE_URL)) {
|
|
|
|
|
|
// throw new Exception('无效的 OSS 链接');
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// $filename = $id . 'cook' . time() . '.jpg';
|
|
|
|
|
|
// $savePath = 'D:/phpstudy_pro/WWW/reedaw/SchoolPhysicalExamination/public/kitchenscale_all/cook_img/';
|
|
|
|
|
|
|
|
|
|
|
|
// // 创建目录(如果不存在)
|
|
|
|
|
|
// if (!file_exists($savePath)) {
|
|
|
|
|
|
// mkdir($savePath, 0777, true);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 使用 cURL 获取 OSS 图片(更可靠)
|
|
|
|
|
|
// $ch = curl_init();
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_URL, $ossUrl);
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
|
|
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
// $imageData = curl_exec($ch);
|
|
|
|
|
|
|
|
|
|
|
|
// if (curl_errno($ch)) {
|
|
|
|
|
|
// throw new Exception('获取 OSS 图片失败: ' . curl_error($ch));
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
// curl_close($ch);
|
|
|
|
|
|
|
|
|
|
|
|
// if ($httpCode !== 200) {
|
|
|
|
|
|
// throw new Exception('OSS 返回错误状态码: ' . $httpCode);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 保存图片
|
|
|
|
|
|
// $result = file_put_contents($savePath . $filename, $imageData);
|
|
|
|
|
|
// if ($result === false) {
|
|
|
|
|
|
// throw new Exception('写入文件失败');
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 更新数据库
|
|
|
|
|
|
// $update_data = [
|
|
|
|
|
|
// 'pic_clean' => 1,
|
|
|
|
|
|
// 'pic_url' => $filename
|
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
|
|
// $cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// $updateResult = $cfc->table('linshi_caidan_biao')
|
|
|
|
|
|
// ->where(["yuanshi_id" => $id])
|
|
|
|
|
|
// ->update($update_data);
|
|
|
|
|
|
|
|
|
|
|
|
// // 返回成功响应
|
|
|
|
|
|
// echo json_encode([
|
|
|
|
|
|
// 'code' => 0,
|
|
|
|
|
|
// 'msg' => '图片保存成功',
|
|
|
|
|
|
// 'data' => [
|
|
|
|
|
|
// 'filename' => $filename,
|
|
|
|
|
|
// 'db_affected' => $updateResult
|
|
|
|
|
|
// ]
|
|
|
|
|
|
// ], JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
|
|
|
|
|
|
// } catch (Exception $e) {
|
|
|
|
|
|
// // 返回错误响应
|
|
|
|
|
|
// echo json_encode([
|
|
|
|
|
|
// 'code' => 1,
|
|
|
|
|
|
// 'msg' => $e->getMessage(),
|
|
|
|
|
|
// 'data' => null
|
|
|
|
|
|
// ], JSON_UNESCAPED_UNICODE);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// exit; // 确保没有其他输出
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 获取图片接口end#########################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function caipu_shuju_chuli()
|
|
|
|
|
|
{
|
2025-08-02 23:03:04 +08:00
|
|
|
|
// // 处理图片,查看本地文件,数据存到图片表,修改原始数据的状态start#######################################################################
|
|
|
|
|
|
// // 初始化SQL Server数据库连接
|
|
|
|
|
|
// $cfc = Db::connect('cfc_db');
|
|
|
|
|
|
// // 查询需要处理的原始数据
|
|
|
|
|
|
// $yuanshi_data = $cfc->table('linshi_caidan_biao')
|
|
|
|
|
|
// ->where(['pic_clean' => 1,'is_move_ok'=>0])
|
|
|
|
|
|
// ->page("1,100")
|
|
|
|
|
|
// ->field('id,pic_url,name,yuanshi_id,category,pic_clean')
|
|
|
|
|
|
// ->select();
|
|
|
|
|
|
// // dump($yuanshi_data);
|
|
|
|
|
|
// // die;
|
|
|
|
|
|
// if(count($yuanshi_data) <= 0){
|
|
|
|
|
|
// return $this->msg(99999,'ok',[]);
|
|
|
|
|
|
// }
|
2025-07-23 23:17:24 +08:00
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
// $yuanshi_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img';
|
|
|
|
|
|
// $new_mulu = 'D:\phpstudy_pro\WWW\reedaw\SchoolPhysicalExamination\public\kitchenscale_all\cook_img\linshi';
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
// $result = [
|
|
|
|
|
|
// 'all'=>count($yuanshi_data),
|
|
|
|
|
|
// 'ok'=>0,
|
|
|
|
|
|
// 'no'=>0,
|
|
|
|
|
|
// 'none'=>0,
|
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
|
|
// $temporary_arr_data = [];
|
|
|
|
|
|
// $temporary_arr_ok = [];
|
|
|
|
|
|
// $temporary_arr_none = [];
|
|
|
|
|
|
// foreach ($yuanshi_data as $key => $value) {
|
|
|
|
|
|
|
|
|
|
|
|
// // 先判断是不是个有效的图片名字
|
|
|
|
|
|
// if (preg_match('/\.jpg$/i', $value['pic_url'])) {
|
|
|
|
|
|
// // 是
|
|
|
|
|
|
// // 判断目录下是否有这个文件
|
|
|
|
|
|
// if (!file_exists($yuanshi_mulu.DS.$value['pic_url'])) {
|
|
|
|
|
|
// $result['none'] = $result['none']+1;
|
|
|
|
|
|
// array_push($temporary_arr_none,$value['yuanshi_id']);
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
// }else{
|
|
|
|
|
|
// $result['ok'] = $result['ok']+1;
|
|
|
|
|
|
// array_push($temporary_arr_ok,$value['yuanshi_id']);
|
|
|
|
|
|
// array_push($temporary_arr_data,[
|
|
|
|
|
|
// 'user_token' => 'caadd1be045a65f30b92aa805f1de54a',
|
|
|
|
|
|
// 'pic_name' => $value['pic_url'],
|
|
|
|
|
|
// 'pic_url' => "https://tc.pcxbc.com/kitchenscale_all/cook_img/".$value['pic_url'],
|
|
|
|
|
|
// 'create_time' => date('Y-m-d H:i:s'),
|
|
|
|
|
|
// 'special_record_str' => $value['yuanshi_id']
|
|
|
|
|
|
// ]);
|
|
|
|
|
|
// rename($yuanshi_mulu.DS.$value['pic_url'], $new_mulu.DS.$value['pic_url']);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// $result['none'] = $result['none']+1;
|
|
|
|
|
|
// array_push($temporary_arr_none,$value['yuanshi_id']);
|
|
|
|
|
|
// continue;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 启动事务
|
|
|
|
|
|
// $cfc->startTrans();
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
|
|
|
|
// if($result['ok'] > 0){
|
|
|
|
|
|
// $cfc->table('app_user_upload_img')->insertAll($temporary_arr_data);
|
|
|
|
|
|
// $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_ok)."')")->update(['is_move_ok'=>1]);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if($result['none'] > 0){
|
|
|
|
|
|
// $cfc->table('linshi_caidan_biao')->where("yuanshi_id in ('".implode("','",$temporary_arr_none)."')")->update(['is_move_ok'=>2]);
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// $cfc->commit();
|
|
|
|
|
|
// return json(['code'=>0,'msg'=>'成功','data'=>$result]);
|
|
|
|
|
|
// } catch (\Exception $e) {
|
|
|
|
|
|
// $cfc->rollback();
|
|
|
|
|
|
// return json(['code'=>99999,'msg'=>'成功','data'=>[]]);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 处理图片,查看本地文件,数据存到图片表,修改原始数据的状态end#######################################################################
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
//更新菜谱的图片数据为图片表的数据start#########################################
|
|
|
|
|
|
|
|
|
|
|
|
$cfc = Db::connect('cfc_db');
|
|
|
|
|
|
$page = 1;
|
|
|
|
|
|
$data = input();
|
|
|
|
|
|
$page = $data['page'];
|
|
|
|
|
|
// 查食谱
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $img_data = $cfc->table('app_user_upload_img')->where(["special_record_str"=>$cookbook_data[0]['original_cookbook_id']])->field('id,special_record_str')->select();
|
|
|
|
|
|
$img_data = $cfc->table('app_user_upload_img')->where(["operate_log"=>0])->page("$page,1")->field('id,special_record_str')->select();
|
|
|
|
|
|
if(count($img_data) <= 0){
|
|
|
|
|
|
return $this->msg(99999,'没了',[]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$cookbook_data = $cfc->table('app_user_cookbook')->where(['original_cookbook_id'=>$img_data[0]['special_record_str']])->field('id')->select();
|
|
|
|
|
|
if(count($cookbook_data) <= 0){
|
|
|
|
|
|
return $this->msg(0,'no1',[]);
|
2025-07-23 21:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
// 启动事务
|
|
|
|
|
|
$cfc->startTrans();
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
$cfc->table('app_user_cookbook')->where(['original_cookbook_id'=>$img_data[0]['special_record_str']])->update(['cover'=>$img_data[0]['id']]);
|
|
|
|
|
|
$cfc->table('app_user_upload_img')->where(['id'=>$img_data[0]['id']])->update(['operate_log'=>1]);
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
$cfc->commit();
|
2025-08-02 23:03:04 +08:00
|
|
|
|
return $this->msg(0,'ok',['num'=>$img_data[0]['special_record_str']]);
|
2025-07-23 21:32:05 +08:00
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
$cfc->rollback();
|
2025-08-02 23:03:04 +08:00
|
|
|
|
return $this->msg(0,'no2',[]);
|
2025-07-23 21:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
}
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-02 23:03:04 +08:00
|
|
|
|
// 从execl直接导入菜谱
|
|
|
|
|
|
public function execl_import_cookbook(){
|
2025-07-23 21:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###################################################################################################################
|
|
|
|
|
|
###################################################################################################################
|
|
|
|
|
|
###################################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function msg($code,$str,$data){
|
|
|
|
|
|
return json(['code'=>$code,'msg'=>$str,'data'=>$data]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|