function correctAction(){ $semester_id = $this->_getParam("semester_id"); $day = $this->_getParam("day"); //todo... $where = array(); $where['lx_lessons.semester_id = ?'] = array("type"=>1,"val"=>$semester_id); $where['lx_lessons.lvalue = ?'] = array("type"=>1,"val"=>'1'); $where['lx_lessons.day = ?'] = array("type"=>1,"val"=>$day); $where['lx_lessons.user_id > ?'] = array("type"=>1,"val"=>0); $aLessons = $this->dao_lessons->getlessons($where,array('day desc','lorder desc','user_id desc'), false, false, false, array("id","day","lorder","lvalue","user_id","course_id")); $a = $c = $d = array(); foreach($aLessons as $key=>$val) { $a[$val['user_id']][$val['id']] = $val['lorder']; } foreach($a as $k=>$v) { $total = count($v); if($total > 1) { if($total !== count(array_unique($v))) { foreach ($v as $key2 => $value2) { $c[$k][$value2][] = $key2; } } } } foreach ($c as $key3 => $value3) { foreach ($value3 as $key4 => $value4) { if(count($value4) > 1) { $d[$key4] = $value4; } } } $total = $this->updateCourse($d); echo $total; } function updateCourse($data) { $total = 0; foreach ($data as $k => $v) { $count = count($v); foreach ($v as $k1 => $v1) { $dataLessons['id'] = $v1; $dataLessons['lvalue'] = 1/$count; $res = $this->dao_lessons->updateLessons($dataLessons); if($res){ $total ++; } } } return $total; }
<html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <head > <title></title> <link rel="stylesheet" type="text/css" href="/js/thickbox3.1/thickbox.css"> <link rel="stylesheet" type="text/css" href="/css/master.css" /> <link rel="stylesheet" type="text/css" href="/css/style.css" /> <link rel="stylesheet" type="text/css" href="/css/commonlist.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script type="text/javascript"> var jQuery2 = jQuery.noConflict(); </script> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="/js/common/png.js"></script> <script type="text/javascript" src="/js/common.js"></script> <script type="text/javascript" src="/js/thickbox3.1/thickbox.js"></script> <script type="text/javascript" src="/js/fc.js"></script> <script type="text/javascript" src="/js/common/commonlist.js"></script> <script type="text/javascript"> $(function(){ var gaodu1 = $(window).height()-137; var kuandu1 = $(window).width()-20; $("#waikuan").height(gaodu1); $("#waikuan").width(kuandu1); //$("body").append("<div id='main_bg'/>"); //$("#main_bg").append("<img src='/images/menubg.png' id='bigpic'>"); cover(); $(window).resize(function(){ //浏览器窗口变化 cover(); }); //提交 $("#import").click(function(){ if($("#excel").val()){//判断是否是excel,xls或xlsx var doc = $("#excel").val(); var pos = doc.lastIndexOf("."); var suffix = doc.substring(pos+1); if(suffix == 'xls' || suffix == 'xlsx'){ $("#form1").submit(); } }else{ alert("请选择excel文件"); } }); $("#correct").click(function(){ var semester_name = $("#semester_id").find("option:selected").text(); var r=confirm("确定校准"+semester_name+"课时?"); if (r==true) { testCourse(1); } }); }); function testCourse(day) { var semester_id = $("#semester_id").val(); $.ajax({ type: "POST", url: '/exam/sche/correct', data: "semester_id="+semester_id+"&day="+day, success: function(msg){ msg = "周"+day+"数据校准完毕,更新了"+msg+"条。"; if(day>=1){ msg += "<br/>"; } if(day == 1){ $("#testCourse").html(""); } $("#testCourse").append(msg); if(day < 6) { var newDay = parseInt(day)+1; testCourse(newDay); } } }); } function cover(){ var win_width = $(window).width(); var win_height = $(window).height(); $("#bigpic").attr({width:win_width,height:win_height}); } $(function(){ //$.toSelect("user_name","selectid"); $(".stripe_tb tr").addClass("bgwhite"); $(".stripe_tb tr").mouseover(function(){ //如果鼠标移到class为stripe_tb的表格的tr上时,执行函数 // $(this).addClass("over"); }) .mouseout(function(){ //给这行添加class值为over,并且当鼠标一出该行时执行函数 $(this).removeClass("over"); }) //移除该行的class $(".stripe_tb tr:even").addClass("alt"); //给class为stripe_tb的表格的偶数行添加class值为alt }); </script> </head> <body> <!--头部信息begin--> <!--{include file = '../../head.tpl'}--> <!--头部信息end--> <div id="main"> <div class="header"> <h1>导入学生数据表</h1> <div class="back"> <a href="/member"><img src="/images/backbt.png" /></a> </div> </div> <table width="90%" border="0" cellspacing="0" cellpadding="0" class="yuanjiao" > <tr> <td valign="top"> <form id="form1" name="form1" method="post" action="" enctype="multipart/form-data"> <div class="grey2" style="padding:30px 20px 10px 50px;"> <select name="semester_id" id="semester_id" class="ml10" > <!--{html_options options=$aSemesters selected=$curSemester}--> </select> <input type="file" name="excel" id="excel" value=""> </div> <div class="tijiao1 mt20"><span id="import">导入</span></div> <div class="tijiao1 mt20"><span id="correct">课时校准</span></div> </form> </td> </tr> </table> <table class="datalist"> <!--{if $aError}--> <!--{section name=data loop=$aError}--> <tr class="data_row"> <td class="left" style="text-align:left;"><span style="color:red">Error:</span><!--{$aError[data]}--></td> </tr> <!--{/section}--> <!--{/if}--> <div id="testCourse"></div> </table> </div> </body> </html>
function correct2Action(){ $semester_id = $this->_getParam("semester_id"); $day = $this->_getParam("day"); //todo... $where = array(); $where['lx_lessons.semester_id = ?'] = array("type"=>1,"val"=>$semester_id); //$where['lx_lessons.lvalue = ?'] = array("type"=>1,"val"=>'1'); $where['lx_lessons.day = ?'] = array("type"=>1,"val"=>$day); $where['lx_lessons.user_id > ?'] = array("type"=>1,"val"=>0); $aLessons = $this->dao_lessons->getlessons($where,false, false, false, false, array("COUNT(id) as num","day","lorder","user_id"),false,array('day','lorder','user_id')); foreach($aLessons as $key=>$val) { if($val['num'] == 1) { unset($aLessons[$key]); } } print_r($aLessons);exit;
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/3760807.html,如需转载请自行联系原作者