This commit is contained in:
2025-12-22 01:16:09 +08:00
parent 110c0b39cf
commit d9d7396557
3 changed files with 152 additions and 22 deletions

View File

@ -888,6 +888,11 @@ Route::any('/xishuju1/next_pass_action', 'test/xishuju1/next_pass_action');
Route::any('/xishuju1/new_step1_action', 'test/xishuju1/new_step1_action'); Route::any('/xishuju1/new_step1_action', 'test/xishuju1/new_step1_action');
Route::any('/xishuju1/new_step2_action', 'test/xishuju1/new_step2_action');
Route::any('/xishuju1/new_step3_action', 'test/xishuju1/new_step3_action');
Route::any('/xishuju1/ceshiyong', 'test/xishuju1/ceshiyong');

View File

@ -326,8 +326,12 @@ class Xishuju1 extends Controller{
// 处理食物表数据 // 处理食物表数据
$cfc = Db::connect('cfc_db'); $cfc = Db::connect('cfc_db');
// 获取一条数据 // 获取一条数据
$shicai_data = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where("food_name is null")->order('id')->find(); $shicai_data = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where("food_name = ''")->order('id')->find();
if(!$shicai_data){
return $this->msg(10004,'没了');
}
// dump($shicai_data); // dump($shicai_data);
// die;
$baidufanyi = new Baidufanyi; $baidufanyi = new Baidufanyi;
$result = $baidufanyi->fanyi_action($shicai_data['food_name_en'], 'en', 'zh'); $result = $baidufanyi->fanyi_action($shicai_data['food_name_en'], 'en', 'zh');
// dump($result); // dump($result);
@ -335,14 +339,14 @@ class Xishuju1 extends Controller{
// die; // die;
// $fanyi_result = ''; // $fanyi_result = '';
if($result['success'] == true){ if($result['success'] == true){
$fanyi_result = $cfc->table('app_z_national_standard_food_type_3_multilingual')->where(['id'=>$shicai_data['id']])->update(['food_name'=>$result['data']['trans_result'][0]['dst']]); $fanyi_result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$shicai_data['id']])->update(['food_name'=>$result['data']['trans_result'][0]['dst']]);
if($fanyi_result){ if($fanyi_result){
return $this->msg([]); return $this->msg([]);
}else{ }else{
return $this->msg(10002); return $this->msg(10002);
} }
}else{ }else{
return $this->msg(12002); return $this->msg(10002,'翻译失败');
} }
} }
@ -1397,6 +1401,108 @@ class Xishuju1 extends Controller{
} }
public function new_step2_action(){
$foodCategories = [
'Dairy and Egg Products' => 1,
'Spices and Herbs' => 2,
'Baby Foods' => 3,
'Fats and Oils' => 4,
'Poultry Products' => 5,
'Soups, Sauces, and Gravies' => 6,
'Sausages and Luncheon Meats' => 7,
'Breakfast Cereals' => 8,
'Fruits and Fruit Juices' => 9,
'Pork Products' => 10,
'Vegetables and Vegetable Products' => 11,
'Nut and Seed Products' => 12,
'Beef Products' => 13,
'Beverages' => 14,
'Finfish and Shellfish Products' => 15,
'Legumes and Legume Products' => 16,
'Lamb, Veal, and Game Products' => 17,
'Baked Products' => 18,
'Sweets' => 19,
'Cereal Grains and Pasta' => 20,
'Fast Foods' => 21,
'Meals, Entrees, and Side Dishes' => 22,
'Snacks' => 23,
'American Indian/Alaska Native Foods' => 24,
'Restaurant Foods' => 25,
'Branded Food Products Database' => 26,
'Quality Control Materials' => 27,
'Alcoholic Beverages' => 28
];
$cfc = Db::connect('cfc_db');
$congfu_num = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')
->where("status is null")
->order('id')
->find();
if(!$congfu_num){
return $this->msg(11006,'没了');
}
if(array_key_exists($congfu_num['two_id'],$foodCategories)){
$result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['two_id'=>$foodCategories[$congfu_num['two_id']],'status'=>'ok']);
}else{
$result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['two_id'=>$foodCategories[$congfu_num['two_id']],'status'=>'nothing']);
}
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
public function new_step3_action(){
$foodCategories = [
'Dairy and Egg Products' => 1,
'Spices and Herbs' => 2,
'Baby Foods' => 3,
'Fats and Oils' => 4,
'Poultry Products' => 5,
'Soups, Sauces, and Gravies' => 6,
'Sausages and Luncheon Meats' => 7,
'Breakfast Cereals' => 8,
'Fruits and Fruit Juices' => 9,
'Pork Products' => 10,
'Vegetables and Vegetable Products' => 11,
'Nut and Seed Products' => 12,
'Beef Products' => 13,
'Beverages' => 14,
'Finfish and Shellfish Products' => 15,
'Legumes and Legume Products' => 16,
'Lamb, Veal, and Game Products' => 17,
'Baked Products' => 18,
'Sweets' => 19,
'Cereal Grains and Pasta' => 20,
'Fast Foods' => 21,
'Meals, Entrees, and Side Dishes' => 22,
'Snacks' => 23,
'American Indian/Alaska Native Foods' => 24,
'Restaurant Foods' => 25,
'Branded Food Products Database' => 26,
'Quality Control Materials' => 27,
'Alcoholic Beverages' => 28
];
$cfc = Db::connect('cfc_db');
$congfu_num = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')
->where("Calorie_unit = 'kJ'")
->order('id')
->find();
if(!$congfu_num){
return $this->msg(11006,'没了');
}
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
$kcal_val = bcdiv($congfu_num['Calorie_val'],4.184,2);
$result = $cfc->table('app_z_national_standard_food_type_3_multilingual_copy1')->where(['id'=>$congfu_num['id']])->update(['Calorie_unit'=>'KCAL','Calorie_val'=>$kcal_val]);
if($result){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}
/** /**
@ -1448,7 +1554,9 @@ class Xishuju1 extends Controller{
################################################################################################################### ###################################################################################################################
################################################################################################################### ###################################################################################################################
################################################################################################################### ###################################################################################################################
public function ceshiyong(){
}
public function msg($data,$str='',$result = []){ public function msg($data,$str='',$result = []){
if(is_array($data)){ if(is_array($data)){

View File

@ -112,7 +112,8 @@
+ "<p>处理失败:"+content2+"项</p>" + "<p>处理失败:"+content2+"项</p>"
$('.centent').html(str) $('.centent').html(str)
setTimeout(() => { setTimeout(() => {
error_action(req.data.id,req.code) // error_action(req.data.id,req.code)
start_action()
}, 100); }, 100);
} }
}, },
@ -158,39 +159,55 @@
function start_action2(){ function start_action2(){
$.ajax({ $.ajax({
url:"new_step1_action", //请求的url地址 // url:"new_step1_action", //请求的url地址
// url:"new_step2_action", //请求的url地址
url:"new_step3_action", //请求的url地址
dataType:"json", //返回格式为json dataType:"json", //返回格式为json
async:true,//请求是否异步默认为异步这也是ajax重要特性 async:true,//请求是否异步默认为异步这也是ajax重要特性
data:{"page":page}, //参数值 data:{"page":page}, //参数值
type:"POST", //请求方式 type:"POST", //请求方式
success:function(req){ success:function(req){
//请求成功时处理 //请求成功时处理
// if(req.code == 0){
// success_num = success_num+req.data.success_num
// fail_num = fail_num+req.data.fail_num
// chongfu_num = chongfu_num+req.data.chongfu_num
// total_num = total_num+req.data.total_num
// str = "<p>处理成功:"+(success_num)+"项</p>"
// + "<p>处理失败:"+(fail_num)+"项</p>"
// + "<p>处理重复:"+(chongfu_num)+"项</p>"
// + "<p>总计处理:"+(total_num)+"项</p>"
// $('.centent').html(str)
// page = page+1
// setTimeout(() => {
// start_action2()
// }, 100);
// }else if(req.code == 10006){
// $('.centent').append('<p>处理完成!</p>');
// }else{
// setTimeout(() => {
// start_action2()
// }, 100);
// }
if(req.code == 0){ if(req.code == 0){
success_num = success_num+req.data.success_num success_num = success_num+1
fail_num = fail_num+req.data.fail_num total_num = total_num+1
chongfu_num = chongfu_num+req.data.chongfu_num
total_num = total_num+req.data.total_num
// console.log(success_num)
// console.log(chongfu_num)
// console.log(fail_num)
// console.log(total_num)
str = "<p>处理成功:"+(success_num)+"项</p>" str = "<p>处理成功:"+(success_num)+"项</p>"
+ "<p>处理失败:"+(fail_num)+"项</p>" + "<p>处理失败:"+(fail_num)+"项</p>"
+ "<p>处理重复:"+(chongfu_num)+"项</p>"
+ "<p>总计处理:"+(total_num)+"项</p>" + "<p>总计处理:"+(total_num)+"项</p>"
$('.centent').html(str) $('.centent').html(str)
page = page+1
setTimeout(() => { setTimeout(() => {
start_action2() start_action2()
}, 100); }, 100);
}else if(req.code == 10006){ }else if(req.code == 11006){
$('.centent').append('<p>处理完成!</p>'); $('.centent').append('<p>处理完成!</p>');
// $('.centent').html(str)
// setTimeout(() => {
// error_action(req.data.id,req.code)
// }, 100);
}else{ }else{
total_num = total_num+1
fail_num = fail_num+1
str = "<p>处理成功:"+(success_num)+"项</p>"
+ "<p>处理失败:"+(fail_num)+"项</p>"
+ "<p>总计处理:"+(total_num)+"项</p>"
$('.centent').html(str)
setTimeout(() => { setTimeout(() => {
start_action2() start_action2()
}, 100); }, 100);