嗯,一个页面同时刷这8个接口,我说能不能合并到一个网络接口,不用一个页面并发8个请求,他说太长了,不好合并。
我看了一下他代码,也是醉了,写了8个接口,访问的都是一个表,然后每个接口重复if else十多次。
附上其中一个接口:
//移民生活 public function immiLiving() { $cid = $_POST[‘cid‘]; $db = M(‘infolist‘); if($cid == 1){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘2‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 2){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘3‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 3){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘4‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 5){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘8‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 6){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘6‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 7){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘9‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 8){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘11‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 9){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘5‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 10){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘10‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 11){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘22‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 12){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘7‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 15){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘19‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 16){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘21‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 22){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘29‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }elseif($cid == 23){ $data[‘classid‘] = ‘183‘; $data[‘mainid‘] = ‘18‘; $data[‘delstate‘] = ‘‘; $data[‘checkinfo‘] = true; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); if($insurance){ $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘data‘] = $insurance; echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } } }
类似的还有好几个,修正一下如下:
//生活百科 public function life() { $cid = $_POST[‘cid‘]; $db = M(‘infolist‘); //生活百科 $arr1 = array(‘1‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘3‘), ‘3‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘180‘,‘mainid‘=>‘18‘)); //移民生活 $arr3 = array(‘1‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘3‘), ‘3‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘183‘,‘mainid‘=>‘18‘)); //当地教育 $arr4 = array(‘1‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘3‘), ‘3‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘181‘,‘mainid‘=>‘18‘)); //移民政策 $arr5 = array(‘1‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘3‘), ‘3‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘182‘,‘mainid‘=>‘18‘)); //税收福利 $arr6 = array(‘1‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘3‘), ‘3‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘184‘,‘mainid‘=>‘18‘)); //常见问题 $arr7 = array(‘1‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘2‘), ‘2‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘2‘), //原函数这里是2,不是3 ‘3‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘4‘), ‘5‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘8‘), ‘6‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘6‘), ‘7‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘9‘), ‘8‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘11‘), ‘9‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘5‘), ‘10‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘10‘), ‘11‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘22‘), ‘12‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘7‘), ‘15‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘19‘), ‘16‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘21‘), ‘22‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘29‘), ‘23‘=>array(‘classid‘=>‘43‘,‘mainid‘=>‘18‘)); //where $data[‘delstate‘] = $val[‘dekstate‘]; $data[‘checkinfo‘] = $val[‘checkinfo‘]; //生活百科 foreach($arr1 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $life = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } //移民生活 foreach($arr3 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $immiLiving = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } //当地教育 foreach($arr4 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $localEducation = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } //移民政策 foreach($arr5 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $immiPolicy = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } //税收福利 foreach($arr6 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $taxBenefits = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } //常见问题 foreach($arr7 as $key => $val){ if($key == $cid){ //取数组里面的参数 $data[‘classid‘] = $val[‘classid‘]; $data[‘mainid‘] = $val[‘mainid‘]; $commProblems = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); break; } } if($cid == 1){ //保险咨询 $data[‘classid‘] = ‘53‘; $data[‘mainid‘] = ‘2‘; $insurance = $db->field(‘id,title,classid,posttime,linkurl‘)->where($data)->order(‘orderid desc‘)->limit(4)->select(); //文件下载 $db2 = M(‘soft‘); $data2[‘delstate‘] = ‘‘; $data2[‘checkinfo‘] = true; $download = $db2->field(‘id,title,classid,posttime,dlurl‘)->where($data2)->order(‘orderid desc‘)->limit(4)->select(); } if($life) { $response[‘status‘] = ‘Y‘; $response[‘msg‘] = ‘成功‘; $response[‘life‘] = $life; $response[‘immiLiving‘] = $immiLiving; $response[‘localEducation‘] = $localEducation; $response[‘immiPolicy‘] = $immiPolicy; $response[‘taxBenefits‘] = $taxBenefits; $response[‘commProblems‘] = $commProblems; if($cid==1){ $response[‘insurance‘] = $insurance; $response[‘download‘] = $download; } echo json_encode($response); }else{ $response[‘status‘] = ‘N‘; $response[‘msg‘] = ‘失败‘; echo json_encode($response); } }
时间: 2024-11-09 07:39:52