目录
1.功能需求
2.数据库设计
3.流程设计
4.关键代码
4.1.设置题库
4.1.1数据请求示意图
4.1.2选择题库(index.php)数据请求代码
4.1.3取消题库(index.php)数据请求代码
4.1.4业务处理Service(xztk.php)
4.1.4.1代码
4.1.4.2业务处理逻辑流程图
4.2.设置答题人员
4.2.1数据请求示意图
4.2.2选择答题人员(index.php)数据请求代码
4.2.3取消答题人员(index.php)数据请求代码
4.2.4业务处理Service(xzfz.php)
4.2.4.1代码
4.2.4.2业务处理逻辑流程图
随机点名答题系统(类抽奖系统、在线答题系统、线上答题系统、在线点名系统、线上点名系统、在线考试系统、线上考试系统),是基于php(8.2.11),JavaScrip,MySQL开发的轻量化点名答题系统,分为数据管理和前端两部分。主要解决了随机抽点人员和随机抽点题目结合的业务需求,有很强的实用意义。
1.功能需求
需求点——
1.对人员进行分组,按分组进行数据准备,可多分组抽取;
2.对试题进行分组,按分组进行数据准备,可多分组抽取;
针对以上需求,系统设计了【设置题库】和【设置答题人员】、【程序初始化】3个功能模块。
【设置题库】选取需要作答的题库进入题库数据池,具有题库选择、取消、查询操作。
【设置答题人员】需求需要进行作答的人员分组进入人员数据池,具有选择、取消、查询功能。
【程序初始化】是将题库数据和人员数据进行数据加载和格式化,为后续抽点答题做准备。
2.数据库设计
设计了基础设置1张数据表,用于存储题库数据和人员数据信息。
表结构 :
基础设置表结构
3.流程设计
基础设置包括设置题库、设置答题人员、程序初始化3个模块。基本流程是:首先选择需要抽取的题库或者取消不需要抽取的题库,完成题库数据的选取,然后对答题人员进行选择和移除,设置完题库和人员后即可对程序进行初始化以加载题库数据和人员数据,完成抽点答题的数据准备。
4.关键代码
4.1.设置题库
4.1.1数据请求示意图
4.1.2选择题库(index.php)数据请求代码
function xztk_btn(tkmc){php_reload("xztk.php","#main_php",{tkmc:tkmc,flag:"xz"});}
4.1.3取消题库(index.php)数据请求代码
function qxtk_btn(tkmc){php_reload("xztk.php","#main_php",{tkmc:tkmc,flag:"qx"});}
4.1.4业务处理Service(xztk.php)
4.1.4.1代码
//打开数据库链接
$dbUtil = new \util\DBUtil();
$conn = $dbUtil->connect();$flag = $_POST['flag'];$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");
$tkmcs = array();
if (sizeof($rows_jcsz)>0){//判断是否在基础设置表里已经有数据,如果已经存在,那么进行修改操作,否则就新增一条$rows_jcsz2 = $rows_jcsz[0];if ($flag == 'xz'){//选择题库操作,数据存入基础设置表tk字段格式为:题库1|题库2|题库3$tkmc = $_POST['tkmc'];$tkmc = $tkmc.'|'.$rows_jcsz2['tk'];$data = array(\util\Config::$tk=>$tkmc);$dbUtil->update($conn,'t_jcsz',$data," id = '".$rows_jcsz2['id']."'");}if ($flag == 'qx'){//取消题库操作,从基础设置表tk字段中剔除相应题库$yctk = '';$tkmc = $_POST['tkmc'];$yctks = explode('|',$rows_jcsz2['tk']);for ($i=0;$i<sizeof($yctks)-1;$i++){if ($yctks[$i] != $tkmc){$yctk = $yctks[$i].'|'.$yctk;}}$data = array(\util\Config::$tk=>$yctk);$dbUtil->update($conn,'t_jcsz',$data," id = '".$rows_jcsz2['id']."'");}$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");$rows_jcsz2 = $rows_jcsz[0];if ($rows_jcsz2['tk'] != ""){$tkmcs = explode('|',$rows_jcsz2['tk']);}
}else{if ($flag == 'xz'){$tkmc = $_POST['tkmc'];$dbUtil->add($conn,"t_jcsz",array("id"=>time(),"tk"=>$tkmc,"zb"=>""));$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");$rows_jcsz2 = $rows_jcsz[0];$tkmcs = explode('|',$rows_jcsz2['tk']);}
}$where = " 1=1 ";if ($flag == 'cx'){//查询操作$tkmc = $_POST['tkmc'];$cjz = $_POST['cjz'];if ($tkmc != ""){$where = $where." and tk like '%".$tkmc."%' ";}if ($cjz != ""){$where = $where." and cjz like '%".$cjz."%'";}$where = $where." order by rq desc";$rows = $dbUtil->select($conn,"t_tiku",$where);
}else{$rows = $dbUtil->select($conn,"t_tiku","1=1 order by rq desc");
}//关闭数据库链接
$dbUtil->close($conn);
4.1.4.2业务处理逻辑流程图
4.2.设置答题人员
4.2.1数据请求示意图
4.2.2选择答题人员(index.php)数据请求代码
function xzzb_btn(id){php_reload("xzfz.php","#main_php",{zb:id,flag:"xz"});}
4.2.3取消答题人员(index.php)数据请求代码
function qxzb_btn(id){php_reload("xzfz.php","#main_php",{zb:id,flag:"qx"});}
4.2.4业务处理Service(xzfz.php)
4.2.4.1代码
$flag = $_POST['flag'];//打开数据库链接
$dbUtil = new \util\DBUtil();
$conn = $dbUtil->connect();$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");
$zbs = array();
if (sizeof($rows_jcsz)>0){//判断基础设置表中是否有数据,如果有进行更新操作,否则进行插入操作$rows_jcsz2 = $rows_jcsz[0];//取得基础设置表中的数据if ($flag == 'xz'){//选择答题人员操作$zbid = $_POST['zb'];//取得form提交数据$zbid = $zbid.'|'.$rows_jcsz2['zb'];//将form提交数据拼接到基础设置表的zb字段$data = array(\util\Config::$zb=>$zbid);$dbUtil->update($conn,'t_jcsz',$data," id = '".$rows_jcsz2['id']."'");}if ($flag == 'qx'){//取消选择答题人员操作$yczb = '';$zbid = $_POST['zb'];//取得form提交数据$yczbs = explode('|',$rows_jcsz2['zb']);for ($i=0;$i<sizeof($yczbs)-1;$i++){if ($yczbs[$i] != $zbid){//将form提交数据从基础设置表zb字段剔除$yczb = $yczbs[$i].'|'.$yczb;}}$data = array(\util\Config::$zb=>$yczb);$dbUtil->update($conn,'t_jcsz',$data," id = '".$rows_jcsz2['id']."'");}$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");$rows_jcsz2 = $rows_jcsz[0];if ($rows_jcsz2['zb'] != ""){$zbs = explode('|',$rows_jcsz2['zb']);}
}else{if ($flag == 'xz'){$zbid = $_POST['zb'];$dbUtil->add($conn,"t_jcsz",array("id"=>time(),"tk"=>"","zb"=>$zbid));$rows_jcsz = $dbUtil->select($conn,"t_jcsz"," 1=1 ");$rows_jcsz2 = $rows_jcsz[0];$zbs = explode('|',$rows_jcsz2['zb']);}
}if ($flag == 'cx'){$zb = $_POST['zb'];$where = " 1=1 ";if ($zb != ""){$where = $where." and zb like '%".$zb."%' ";}$where = $where." order by xh asc";$rows = $dbUtil->select($conn,"t_zubie",$where);
}else{$rows = $dbUtil->select($conn,"t_zubie"," 1=1 order by xh asc");
}
//关闭数据库链接
$dbUtil->close($conn);
4.2.4.2业务处理逻辑流程图
4.3程序初始化
4.3.1数据请求示意图
4.3.2数据请求代码
//初始化菜单$(document).on("click","#cshcx",function (){dataInit();$("#main_php").html( cjcxTips('抽点答题程序正在初始化,请耐心等待'));$.ajax({method: "post",url:"cjcx.php",data:{},success:function (res){res = JSON.parse(res);if(res["flag"]=="success_init") {setTimeout(function () {$("#main_php").html( cjcxTips('程序初始化完毕,请进行【抽点答题】'));}, 0);data_ry = res["renyuan"];//人员数据池data_tm = res["timu"];//题目数据池//初始化完毕后,为开始、停止、显示答案按钮绑定事件$("#ks").on("click",function (){startDraw();});$("#tz").on("click",function (){stopDraw();});$("#tm").on("click",function (){tmDraw();});$("#xsda").on("click",function (){displayDa();});}if (res["flag"] == "err_null"){$("#main_php").html( cjcxTips(res["data"]));}if (res["flag"] == "err_null_all"){$("#main_php").html( cjcxTips(res["data"]));}}});//php_reload("cjcx.php","#main_php",{});});
4.3.3业务处理Service(cjcx.php)
4.3.3.1代码
//打开数据库链接
$dbUtil = new \util\DBUtil();
$conn = $dbUtil->connect();$jcszs = $dbUtil->select($conn,"t_jcsz"," 1= 1");
$timus = array();
$renyuans = array();
$html = '';
//判断基础设置表中是否有数据
if (sizeof($jcszs) > 0){$jcsz = $jcszs[0];//判断基础设置表中的题库字段和组别字段是否有数据if ($jcsz['tk'] != '' and $jcsz['zb'] != ''){//将基础设置表中的题库字段和组别字段中的数据分隔成数组$tks = explode('|',$jcsz['tk']);$zbs = explode('|',$jcsz['zb']);//组装题目查询条件$where_tk = " tk in ( ";for ($i=0;$i<sizeof($tks);$i++){$where_tk = $where_tk."'".$tks[$i]."'";if ($i<sizeof($tks)-1){$where_tk = $where_tk.",";}}$where_tk = $where_tk.") order by th";//##################################################################################################//根据题库名称,从题目表中查询题目信息$timus = $dbUtil->select($conn,"t_timu",$where_tk);//获得所有参与抽选的题目信息$timuArr = array();for ($r=0;$r<sizeof($timus);$r++){$timu = $timus[$r];array_push($timuArr,json_encode(array("tg"=>$timu["tg"],"da"=>$timu["da"]))); //获得所有参加答题人员信息}//##################################################################################################//组装组别查询条件$where_zb = " id in ( ";for ($j=0;$j<sizeof($zbs);$j++){$where_zb = $where_zb."'".$zbs[$j]."'";if ($j<sizeof($zbs)-1){$where_zb = $where_zb.",";}}$where_zb = $where_zb.")";//根据组别名称,从组别表中查询组别信息$fzrys = $dbUtil->select($conn,"t_zubie",$where_zb);//逐条处理组别表中的人员分组字段信息for ($k=0;$k<sizeof($fzrys);$k++){$fzry_zb = $fzrys[$k];//将人员分组字段分隔成数组$fzry = explode('|',$fzry_zb['fzry']);//组装人员查询条件$where_fzry = " sfzh in (";for ($l=0;$l<sizeof($fzry);$l++){$where_fzry = $where_fzry."'".$fzry[$l]."'";if ($l<sizeof($fzry)-1){$where_fzry = $where_fzry.",";}}$where_fzry = $where_fzry.") order by xh";//根据身份证号信息,从人员表中查询人员信息$rys = $dbUtil->select($conn,"t_renyuan",$where_fzry);//将所有组别查询到的人员信息,添加到数组$renyuans = array_merge($renyuans,$rys); //获得所有参加答题人员信息}$renyuan2 = array();//人员去重//获取所有人员身份证号信息,存入数组$renyuan_sfzhfor ($n=0;$n<sizeof($renyuans);$n++){$renyuans3 = $renyuans[$n];$strRen=array("sfzh"=>$renyuans3['sfzh'],"xm"=>$renyuans3['xm'],"dw"=>$renyuans3['dw'],"zw"=>$renyuans3['zw']);array_push($renyuan2,json_encode($strRen));}//################################################$jsonData=array("flag"=>"success_init","renyuan"=>$renyuan2,"timu"=>$timuArr);$html = json_encode($jsonData);}else{$tips = '';if($jcsz['tk'] == ''){$tips = $tips.'请首先完成【设置题库】,再进行程序初始化</br>';}if($jcsz['zb'] == ''){$tips = $tips.'请首先完成【设置答题人员】,再进行程序初始化';}$html = json_encode(array("flag"=>"err_null","data"=>$tips));}}else{$html = json_encode(array("flag"=>"err_null_all","data"=>'请首先进行【设置题库】和【设置答题人员】,再进行程序初始化'));
}//关闭数据库链接
$dbUtil->close($conn);
4.3.3.2业务处理逻辑流程图