diff --git a/application/route.php b/application/route.php index 3c16c4c..e88e51d 100644 --- a/application/route.php +++ b/application/route.php @@ -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_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'); + diff --git a/application/test/controller/Xishuju1.php b/application/test/controller/Xishuju1.php index 85980e5..d68e73a 100644 --- a/application/test/controller/Xishuju1.php +++ b/application/test/controller/Xishuju1.php @@ -326,8 +326,12 @@ class Xishuju1 extends Controller{ // 处理食物表数据 $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); + // die; $baidufanyi = new Baidufanyi; $result = $baidufanyi->fanyi_action($shicai_data['food_name_en'], 'en', 'zh'); // dump($result); @@ -335,14 +339,14 @@ class Xishuju1 extends Controller{ // die; // $fanyi_result = ''; 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){ return $this->msg([]); }else{ return $this->msg(10002); } }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 = []){ if(is_array($data)){ diff --git a/application/test/view/xishuju1/xishuju1_qd_page.html b/application/test/view/xishuju1/xishuju1_qd_page.html index 1e3425d..6b2c756 100644 --- a/application/test/view/xishuju1/xishuju1_qd_page.html +++ b/application/test/view/xishuju1/xishuju1_qd_page.html @@ -112,7 +112,8 @@ + "
处理失败:"+content2+"项
" $('.centent').html(str) setTimeout(() => { - error_action(req.data.id,req.code) + // error_action(req.data.id,req.code) + start_action() }, 100); } }, @@ -158,39 +159,55 @@ function start_action2(){ $.ajax({ - url:"new_step1_action", //请求的url地址 + // url:"new_step1_action", //请求的url地址 + // url:"new_step2_action", //请求的url地址 + url:"new_step3_action", //请求的url地址 dataType:"json", //返回格式为json async:true,//请求是否异步,默认为异步,这也是ajax重要特性 data:{"page":page}, //参数值 type:"POST", //请求方式 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 = "处理成功:"+(success_num)+"项
" + // + "处理失败:"+(fail_num)+"项
" + // + "处理重复:"+(chongfu_num)+"项
" + // + "总计处理:"+(total_num)+"项
" + // $('.centent').html(str) + // page = page+1 + // setTimeout(() => { + // start_action2() + // }, 100); + // }else if(req.code == 10006){ + // $('.centent').append('处理完成!
'); + // }else{ + // setTimeout(() => { + // start_action2() + // }, 100); + // } 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 - // console.log(success_num) - // console.log(chongfu_num) - // console.log(fail_num) - // console.log(total_num) + success_num = success_num+1 + total_num = total_num+1 str = "处理成功:"+(success_num)+"项
" + "处理失败:"+(fail_num)+"项
" - + "处理重复:"+(chongfu_num)+"项
" + "总计处理:"+(total_num)+"项
" $('.centent').html(str) - page = page+1 setTimeout(() => { start_action2() }, 100); - }else if(req.code == 10006){ + }else if(req.code == 11006){ $('.centent').append('处理完成!
'); - // $('.centent').html(str) - // setTimeout(() => { - // error_action(req.data.id,req.code) - // }, 100); }else{ + total_num = total_num+1 + fail_num = fail_num+1 + str = "处理成功:"+(success_num)+"项
" + + "处理失败:"+(fail_num)+"项
" + + "总计处理:"+(total_num)+"项
" + $('.centent').html(str) setTimeout(() => { start_action2() }, 100);