StudentinfoController.php 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364
  1. <?php
  2. /**
  3. * 学生管理控制器类
  4. * @author jiangfei
  5. * @date 2015-07-21 9:50:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class StudentinfoController extends Controller
  9. {
  10. // 学生列表
  11. public function actionIndex()
  12. {
  13. $condition = array();
  14. $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
  15. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  16. $realname = safe_replace(Yii::app()->request->getQuery('realname'));
  17. $semester_id = safe_replace(Yii::app()->request->getQuery('semester_id'));
  18. $search_type = safe_replace(Yii::app()->request->getQuery('search_type'));
  19. $where = '';
  20. if ($realname) {
  21. if($search_type==1)
  22. {
  23. $condition = array("stu.realname like '%{$realname}%'");
  24. }else if($search_type==2)
  25. {
  26. $where = "school_id=".$this->schoolId." and username = '".$realname."'";
  27. }else if($search_type==3)
  28. {
  29. $realname = (int)$realname;
  30. $where = 'school_id='.$this->schoolId.' and student_card = '.$realname;
  31. }else if($search_type==4)
  32. {
  33. $where = "school_id=".$this->schoolId." and school_student_card = '".$realname."'";
  34. }else if($search_type==5)
  35. {
  36. $realname = (int)$realname;
  37. $where = 'school_id='.$this->schoolId.' and zhixue_student_card = '.$realname;
  38. }else{
  39. $field_array=array('field_1','field_2','field_3','field_4','field_5');
  40. if(in_array($search_type,$field_array)){
  41. $condition = array(" `".$search_type."`='".$realname."'");
  42. }
  43. }
  44. }
  45. $grade_class_array = array();
  46. $sort = '';
  47. if (isset($_GET['sort'])) {
  48. $sort = safe_replace(Yii::app()->request->getQuery('sort'));
  49. }
  50. if ($grade_id) {
  51. $grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id and class_type=1', array(':grade' => $grade_id, ':semester_id' => $this->semesterId));
  52. if ($grade_class_data) {
  53. foreach ($grade_class_data as $v) {
  54. $grade_class_array[$v->class_id] = $v->attributes;
  55. }
  56. }
  57. array_push($condition, "c.grade=" . $grade_id);
  58. }
  59. array_push($condition, "c.class_type=1" );
  60. if (empty($semester_id)) {
  61. $smid = Yii::app()->session['session_semester_id'];
  62. } else {
  63. $smid = $semester_id;
  64. }
  65. $classes = $this->schoolManager->getClasses();
  66. $resultClass = Arr::toObj($classes);
  67. if (empty($class_id) && $classes) {
  68. foreach ($classes as $v) {
  69. $class_ids[$v['class_id']] = $v['class_id'];
  70. }
  71. $rs = $this->schoolManager->getClassStudentsListWithAccounts($class_ids, $condition, 20,$where);
  72. } else {
  73. $rs = $this->schoolManager->getClassStudentsListWithAccounts($class_id, $condition, 20,$where);
  74. }
  75. $userList = $rs["rs"];
  76. $studentClass=array();
  77. $studentIds=array();
  78. if($rs["rs"]){
  79. foreach ($rs["rs"] as $key =>$val){
  80. $studentIds[]=$val['student_id'];
  81. }
  82. //查询所有走班
  83. $studentClass=$this->schoolManager->getAllClassByStudentId($studentIds);
  84. }
  85. $data = array();
  86. // 处理学生按学号排序
  87. if ($sort == 1) {
  88. $sort = 2;
  89. } elseif ($sort == 2) {
  90. $sort = 1;
  91. }
  92. // 获取所有学期
  93. //$data['allSemester']= Semester::model()->findAll();
  94. //扩展字段
  95. $studentExtend=$this->schoolManager->getStudentExtend();
  96. $data['studentExtend']=$studentExtend;
  97. $data['grade_id'] = $grade_id;
  98. $data['userList'] = $userList;
  99. $data['pages'] = $rs['pager'];
  100. $data['page_total'] = $rs['pager']->rowsCount;
  101. $data['class_id'] = $class_id;
  102. $data['search_type'] = $search_type;
  103. $data['realname'] = $realname;
  104. $data['grade_class'] = $grade_class_array;
  105. $data['semester_id'] = $smid;
  106. $data['classInfo'] = $resultClass;
  107. $data['sort'] = $sort;
  108. $data['calssName'] = ClassModel::model()->getClassName($class_id);
  109. $data['student_class'] = $studentClass;
  110. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  111. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  112. } else {
  113. $data["use_zhixue"] = 0;
  114. }
  115. unset($resultClass, $classes);
  116. $this->render('index', $data);
  117. }
  118. public function actionClassstu()
  119. {
  120. $orderid = Yii::app()->request->getParam('orderid');
  121. $cid = Yii::app()->request->getParam('cid');
  122. $classname = ClassModel::model()->find('class_id=:cid', array(":cid" => $cid));
  123. $order_data = CMSOrder::model()->find('id=:id',array(':id'=>$orderid));
  124. if($order_data->classify!=2){
  125. $stu = CMSOrderStudent::model()->findAll("order_id =:orderid and clazz_id=:cid", array(":orderid" => $orderid, ":cid" => $cid));
  126. }else{
  127. $stu = SStudentInfo::model()->findAll("class_id=:cid", array(":cid" => $cid));
  128. }
  129. $this->render("stuinfo", array("stu" => $stu, "classname" => $classname));
  130. }
  131. // 添加学生
  132. public function actionAdd()
  133. {
  134. checkAuthority(2); // 非当前使用学期无法操作
  135. if (Yii::app()->request->getIsPostRequest()) {
  136. $redis_add_student_status = Yii::app()->add_student_status->hmget('add_students_status_'.$this->schoolId,array('status'));
  137. if($redis_add_student_status && $redis_add_student_status[0]){
  138. Yii::app()->jump->error('请稍后再试!');
  139. }
  140. Yii::app()->add_student_status->hmset('add_students_status_'.$this->schoolId,array('status'=>1));
  141. Yii::app()->add_student_status->expire('add_students_status_'.$this->schoolId,10);
  142. $realname = Yii::app()->request->getPost('realname');
  143. $class_id = Yii::app()->request->getPost('class_id');
  144. $userno = Yii::app()->request->getPost('userno');
  145. $sex = Yii::app()->request->getPost('sex');
  146. $school_student_card = (string)Yii::app()->request->getPost('school_student_card');
  147. $is_outer = Yii::app()->request->getPost('is_outer');
  148. $id_number = Yii::app()->request->getPost('id_number');
  149. //扩展设置
  150. $field_1=-1;
  151. $field_2=-1;
  152. $field_3=-1;
  153. $field_4=-1;
  154. $field_5=-1;
  155. $regex = '/^[a-zA-Z0-9]+$/u';
  156. $studentExtend=$this->schoolManager->getStudentExtend();
  157. if($studentExtend){
  158. foreach($studentExtend as $key=>$val){
  159. if($val['is_enable']==1){
  160. $check_field_value=Yii::app()->request->getPost($key);
  161. if($check_field_value && !preg_match($regex, $check_field_value)){
  162. Yii::app()->jump->error('自定义考号内容只能是数字和字母');
  163. }
  164. $$key=$check_field_value;
  165. }
  166. }
  167. }
  168. //验证身份证
  169. if($id_number){
  170. $check_id_number=$this->sConn->createCommand("select student_id from student_info where id_number='".$id_number."'")->queryRow();
  171. if($check_id_number){
  172. Yii::app()->jump->error('身份证号已存在!');
  173. }
  174. }
  175. /**
  176. * 学校准考证号
  177. */
  178. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  179. /**
  180. * 智学网准考证号
  181. */
  182. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  183. $zhixue_student_card = (string)Yii::app()->request->getPost('zhixue_student_card');
  184. if ($zhixue_student_card) {
  185. if(!is_numeric($zhixue_student_card)){
  186. Yii::app()->jump->error('智学网准考证号格式不正确!');
  187. }
  188. $b_student_data = BusinessStudent::model()->find(array('select'=>array('student_id'),'condition'=>'school_id =:school_id and zhixue_student_card=:zhixue_student_card','params'=>array(':school_id'=>$this->schoolId,':zhixue_student_card' => $zhixue_student_card)));
  189. if ($b_student_data) {
  190. Yii::app()->jump->error('智学网准考证号已存在!');
  191. }
  192. }
  193. } else {
  194. $zhixue_student_card = '';
  195. }
  196. if($school_student_card)
  197. {
  198. if(!is_numeric($school_student_card)){
  199. Yii::app()->jump->error('学校准考证号格式不正确!');
  200. }
  201. $semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
  202. if ($semester_class_data)
  203. {
  204. foreach ($semester_class_data as $v)
  205. {
  206. $class_ids[$v->class_id] = $v->class_id;
  207. }
  208. }
  209. $criteria = new CDbCriteria();
  210. $criteria->addInCondition('class_id',$class_ids);
  211. $criteria->addCondition('status=0');
  212. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  213. if(!$semester_student_class_data)
  214. {
  215. $s_student_ids = array();
  216. }else
  217. {
  218. foreach($semester_student_class_data as $v)
  219. {
  220. $s_student_ids[$v->student_id] = $v->student_id;
  221. }
  222. }
  223. unset($criteria);
  224. $criteria = new CDbCriteria();
  225. $criteria->select = 'student_id,school_student_card';
  226. $criteria->addCondition('school_id=:school_id');
  227. $criteria->addInCondition('student_id',$s_student_ids);
  228. $criteria->params[':school_id'] = $this->schoolId;
  229. $s_student_data = BusinessStudent::model()->findAll($criteria);
  230. if($s_student_data)
  231. {
  232. foreach($s_student_data as $v)
  233. {
  234. $school_student_studentId[$v->school_student_card] = $v->student_id;
  235. }
  236. }
  237. unset($s_student_data);
  238. if(isset($school_student_studentId[$school_student_card]) && !empty($school_student_studentId[$school_student_card]) )
  239. {
  240. Yii::app()->jump->error('学校准考证号已存在!');
  241. }
  242. /**
  243. * 获取班级信息
  244. */
  245. $_school_student_card = '';
  246. $_school_student_status = 0;
  247. $grade_data = SGradeModel::model()->findAll();
  248. if($class_data && $grade_data)
  249. {
  250. foreach($grade_data as $v)
  251. {
  252. if($class_data->grade == $v->id)
  253. {
  254. $_school_student_card = $v->card_length;
  255. $_school_student_status = $v->card_status;
  256. }
  257. }
  258. if($_school_student_status)
  259. {
  260. if($_school_student_card)
  261. {
  262. if(strlen((string)$school_student_card) != $_school_student_card)
  263. {
  264. Yii::app()->jump->error('准考证长度与学校设置长度不一致!');
  265. }
  266. }else
  267. {
  268. Yii::app()->jump->error('学校未设置准考证位数,请到学校管理中设置');
  269. }
  270. }
  271. }
  272. }
  273. $telephone = 0;
  274. $serial_number = 1;
  275. $student_phone = Yii::app()->request->getPost('student_phone');
  276. if (empty($realname) || empty($class_id)) {
  277. Yii::app()->jump->error('请确认学生个人信息是否填写完整!');
  278. }
  279. if ($class_data) {
  280. $semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $class_data->semester_id));
  281. if ($semester_class_data) {
  282. foreach ($semester_class_data as $v) {
  283. $class_ids[$v->class_id] = $v->class_id;
  284. }
  285. }
  286. }
  287. if (!$class_ids) {
  288. Yii::app()->jump->error('不在当前学期!');
  289. }
  290. $student_class_data = SStudentClassRelation::model()->find(array(
  291. 'select' => 'serial_number',
  292. 'order' => 'serial_number desc',
  293. 'condition' => 'class_id=:class_id and status=:status',
  294. 'limit' => 1,
  295. 'params' => array(':class_id' => $class_id, ':status' => 0)
  296. ));
  297. if ($student_class_data) {
  298. if ($student_class_data->serial_number) {
  299. $serial_number = $student_class_data->serial_number + 1;
  300. }
  301. }
  302. /*
  303. $b_student_data = BusinessStudent::model()->find(array(
  304. 'select' => 'student_card',
  305. 'order' => 'student_card desc',
  306. 'condition' => 'school_id=:school_id',
  307. 'limit' => 1,
  308. 'params' => array(':school_id' => $this->schoolId)
  309. ));
  310. */
  311. $b_student_data=$this->conn->createCommand("SELECT student_card FROM (SELECT student_card FROM `student` `t` WHERE school_id='".$this->schoolId."') sc ORDER BY student_card DESC LIMIT 1;")->queryRow();
  312. $student_cart = 0;
  313. if ($b_student_data) {
  314. if (!$b_student_data['student_card']) {
  315. if ($this->schoolId < 100) {
  316. $student_cart = '9' . $this->schoolId . '00100';
  317. } else {
  318. $student_cart = $this->schoolId . '00100';
  319. }
  320. } else {
  321. $student_cart = $b_student_data['student_card'] + 1;
  322. }
  323. } else {
  324. if ($this->schoolId < 100) {
  325. $student_cart = '9' . $this->schoolId . '00100';
  326. } else {
  327. $student_cart = $this->schoolId . '00100';
  328. }
  329. }
  330. if($id_number){
  331. $student_all_data = $this->sConn->createCommand("SELECT student_id FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "' and id_number='".$id_number."'")->queryAll();
  332. }else{
  333. $student_all_data = $this->sConn->createCommand("SELECT student_id FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "'")->queryAll();
  334. }
  335. //unset($criteria);
  336. $student_data = array();
  337. if ($student_all_data) {
  338. if (count($student_all_data) > 1) {
  339. $_student_ids = array();
  340. foreach($student_all_data as $v)
  341. {
  342. $_student_ids[$v['student_id']] = $v['student_id'];
  343. }
  344. $criteria = new CDbCriteria();
  345. $criteria->addInCondition('student_id',$_student_ids);
  346. $criteria->addCondition('status=:status');
  347. $criteria->params[':status'] = 0;
  348. $student_c_r = SStudentClassRelation::model()->findAll($criteria);
  349. if($student_c_r)
  350. {
  351. Yii::app()->jump->error('已经存在此学生!');
  352. }
  353. }
  354. foreach ($student_all_data as $v) {
  355. $student_data = $v;
  356. }
  357. $student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status', array(':student_id' => $student_data['student_id'], ':status' => 0));
  358. if ($this->schoolId == Yii::app()->session['coachInfo']['school_id']) {
  359. if ($student_class_data) {
  360. Yii::app()->jump->error('创建学生失败,学生账号已存在!');
  361. }
  362. $_serial_number_data = SStudentClassRelation::model()->find('class_id=:class_id and status=:status and serial_number=:serial_number', array(':class_id' => $class_id, ':status' => 0, ':serial_number' => $serial_number));
  363. if ($_serial_number_data) {
  364. Yii::app()->jump->error('班级序号已存在!');
  365. }
  366. // $b_student_one_data = BusinessStudent::model()->find(array(
  367. // 'select' => 'student_card',
  368. // 'condition' => 'school_id=:school_id and student_card=:student_card',
  369. // 'params' => array(':school_id' => $this->schoolId,':student_card'=>$student_cart)
  370. // ));
  371. // if($b_student_one_data){
  372. // Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  373. // }
  374. // $b_student_one_data = BusinessStudent::model()->find(array(
  375. // 'select' => 'student_card',
  376. // 'condition' => 'school_id=:school_id and username=:username',
  377. // 'params' => array(':school_id' => $this->schoolId,':username'=>$student_cart)
  378. // ));
  379. // if($b_student_one_data){
  380. // Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  381. // }
  382. $b_student_one_data = BusinessStudent::model()->find(array(
  383. 'select' => 'student_card',
  384. 'condition' => 'student_card=:student_card ',
  385. 'params' => array(':student_card'=>$student_cart)
  386. ));
  387. if($b_student_one_data){
  388. Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  389. }else{
  390. $b_student_one_data = BusinessStudent::model()->find(array(
  391. 'select' => 'student_card',
  392. 'condition' => 'username=:username',
  393. 'params' => array(':username'=>$student_cart)
  394. ));
  395. if($b_student_one_data){
  396. Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  397. }
  398. }
  399. // $studentId = getUUID();
  400. $studentId = getUniqueId($this->schoolId);
  401. // 判断登录账号是否已存在
  402. //if (BusinessStudent::model()->count('username=:name and status=0',array(':name'=>$username))) {
  403. // throw new CException('登录账号已存在!');
  404. //}
  405. // 将学生登录账号插入主数据
  406. $studentModel = new BusinessStudent();
  407. $studentModel->username = $student_cart;
  408. $studentModel->password = md5(sha1($student_cart . 'wy') . 'fengche');
  409. $studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
  410. $studentModel->student_id = $studentId;
  411. $studentModel->student_card = $student_cart;
  412. $studentModel->school_student_card = $school_student_card;
  413. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  414. $studentModel->zhixue_student_card = $zhixue_student_card;
  415. }
  416. $studentModel->register_time = time();
  417. if (!$studentModel->save()) {
  418. throw new CException('主数据库录入信息失败!');
  419. }
  420. $transaction = StudentInfo::model()->dbConnection->beginTransaction();
  421. try {
  422. // 学校库插入学生基本信息
  423. $userModel = new StudentInfo();
  424. $studentToClass = new StudentToClass();
  425. $userModel->student_id = $studentId;
  426. $userModel->realname = $realname;
  427. $userModel->school_id = Yii::app()->session['coachInfo']['school_id'];
  428. $userModel->class_id = $class_id;
  429. $userModel->add_time = time();
  430. $userModel->update_time = time();
  431. $userModel->sex = $sex;
  432. $userModel->is_outer = $is_outer;
  433. $userModel->student_phone = $student_phone;
  434. if($id_number){
  435. $userModel->id_number = $id_number;
  436. }
  437. //扩展数据
  438. if($field_1!=-1){
  439. $userModel->field_1 = $field_1;
  440. }
  441. if($field_2!=-1){
  442. $userModel->field_2 = $field_2;
  443. }
  444. if($field_3!=-1){
  445. $userModel->field_3 = $field_3;
  446. }
  447. if($field_4!=-1){
  448. $userModel->field_4 = $field_4;
  449. }
  450. if($field_5!=-1){
  451. $userModel->field_5 = $field_5;
  452. }
  453. $studentToClass->userno = $userno;
  454. $studentToClass->serial_number = $serial_number;
  455. $studentToClass->student_id = $studentId;
  456. $studentToClass->update_time = time();
  457. $studentToClass->class_id = $class_id;
  458. if (!$userModel->save() || !$studentToClass->save()) {
  459. Yii::app()->jump->error('学校数据库录入失败!');
  460. }
  461. // 创建学生与班级关联关系
  462. /*$studentClass = new StudentToClass();
  463. $studentClass->class_id = $class_id;
  464. $studentClass->student_id = $studentId;
  465. if (!$studentClass->save()) {
  466. Yii::app()->jump->error('创建学生与班级关系失败!');
  467. }*/
  468. $transaction->commit();
  469. } catch (Exception $e) {
  470. //如果操作失败, 数据回滚
  471. $transaction->rollback();
  472. Yii::app()->jump->error('创建学生失败!');
  473. }
  474. } else {
  475. Yii::app()->jump->error('登录账号已在其他学校使用!');
  476. }
  477. } else {
  478. // $b_student_one_data = BusinessStudent::model()->find(array(
  479. // 'select' => 'student_card',
  480. // 'condition' => 'school_id=:school_id and student_card=:student_card',
  481. // 'params' => array(':school_id' => $this->schoolId,':student_card'=>$student_cart)
  482. // ));
  483. // if($b_student_one_data){
  484. // Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  485. // }
  486. // $b_student_one_data = BusinessStudent::model()->find(array(
  487. // 'select' => 'student_card',
  488. // 'condition' => 'school_id=:school_id and username=:username',
  489. // 'params' => array(':school_id' => $this->schoolId,':username'=>$student_cart)
  490. // ));
  491. // if($b_student_one_data){
  492. // Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  493. // }
  494. $b_student_one_data = BusinessStudent::model()->find(array(
  495. 'select' => 'student_card',
  496. 'condition' => 'username=:username',
  497. 'params' => array(':username'=>$student_cart)
  498. ));
  499. if($b_student_one_data){
  500. Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  501. }else{
  502. $b_student_one_data = BusinessStudent::model()->find(array(
  503. 'select' => 'student_card',
  504. 'condition' => 'student_card=:student_card',
  505. 'params' => array(':student_card'=>$student_cart)
  506. ));
  507. if($b_student_one_data){
  508. Yii::app()->jump->error('生成的学生准考证号已存在,请重新添加!');
  509. }
  510. }
  511. // 创建学生事务
  512. //$transaction = Yii::app()->db->beginTransaction();
  513. //$studentId = getUUID();
  514. $studentId=getUniqueId($this->schoolId);
  515. // 判断登录账号是否已存在
  516. //if (BusinessStudent::model()->count('username=:name and status=0',array(':name'=>$username))) {
  517. // throw new CException('登录账号已存在!');
  518. //}
  519. // 将学生登录账号插入主数据
  520. $studentModel = new BusinessStudent();
  521. $studentModel->username = $student_cart;
  522. $studentModel->password = md5(sha1($student_cart . 'wy') . 'fengche');
  523. $studentModel->school_id = Yii::app()->session['coachInfo']['school_id'];
  524. $studentModel->student_id = $studentId;
  525. $studentModel->student_card = $student_cart;
  526. $studentModel->school_student_card = $school_student_card;
  527. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  528. $studentModel->zhixue_student_card = $zhixue_student_card;
  529. }
  530. $studentModel->register_time = time();
  531. if (!$studentModel->save()) {
  532. throw new CException('主数据库录入信息失败!');
  533. }
  534. $transaction = StudentInfo::model()->dbConnection->beginTransaction();
  535. try {
  536. // 学校库插入学生基本信息
  537. $userModel = new StudentInfo();
  538. $studentToClass = new StudentToClass();
  539. $userModel->student_id = $studentId;
  540. $userModel->realname = $realname;
  541. $userModel->school_id = Yii::app()->session['coachInfo']['school_id'];
  542. $userModel->class_id = $class_id;
  543. $userModel->add_time = time();
  544. $userModel->update_time = time();
  545. $userModel->sex = $sex;
  546. $userModel->is_outer = $is_outer;
  547. $userModel->student_phone = $student_phone;
  548. if($id_number){
  549. $userModel->id_number = $id_number;
  550. }
  551. $studentToClass->userno = $userno;
  552. $studentToClass->serial_number = $serial_number;
  553. $studentToClass->student_id = $studentId;
  554. $studentToClass->update_time = time();
  555. $studentToClass->class_id = $class_id;
  556. if (!$userModel->save() || !$studentToClass->save()) {
  557. Yii::app()->jump->error('学校数据库录入失败!');
  558. }
  559. $transaction->commit();
  560. } catch (Exception $e) {
  561. //如果操作失败, 数据回滚
  562. $transaction->rollback();
  563. Yii::app()->jump->error('创建学生失败!');
  564. }
  565. }
  566. Yii::app()->add_student_status->del('add_students_status_'.$this->schoolId);
  567. $this->redirect(array('studentinfo/index'));
  568. }
  569. $data = array();
  570. $cid = safe_replace(Yii::app()->request->getQuery('cid'));
  571. $cname = ClassModel::model()->getClassName($cid);
  572. // 获取当前学校班级
  573. $getClass = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and class_type=1 and is_hide=0');
  574. $resultClass = $getClass;
  575. if (Yii::app()->session['coachInfo']['leader'] != 1) {
  576. $resultClass = array();
  577. $coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
  578. foreach ($getClass as $t) {
  579. foreach ($coachClass as $tt) {
  580. if ($t->class_id == $tt->class_id) {
  581. $resultClass[] = $t;
  582. }
  583. }
  584. }
  585. }
  586. $data['cid'] = $cid;
  587. $data['cname'] = $cname;
  588. $data['classInfo'] = $resultClass;
  589. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  590. $data['use_zhixue'] = $this->schoolInfo->use_zhixue;
  591. } else {
  592. $data['use_zhixue'] = 0;
  593. }
  594. //判断扩展字段设置
  595. $studentExtend=$this->schoolManager->getStudentExtend();
  596. if(!$studentExtend){
  597. $studentExtend=$this->schoolManager->setDefaultStudentExtend();
  598. }
  599. $data['studentExtend']=$studentExtend;
  600. unset($transaction, $getClass);
  601. $this->render('add2', $data);
  602. }
  603. // 编辑学生
  604. public function actionEdit()
  605. {
  606. checkAuthority(2); // 非当前使用学期无法操作
  607. $studentId = safe_replace(Yii::app()->request->getQuery('stid'));
  608. if (empty($studentId)) {
  609. Yii::app()->jump->error('您访问的页面不存在!');
  610. }
  611. // 学生信息
  612. $userInfo = StudentInfo::model()->find('student_id=:stid', array(':stid' => $studentId));
  613. $studentInfo = $this->schoolManager->getStudentInfo($studentId, "OBJ");
  614. if (empty($userInfo) || empty($studentInfo)) {
  615. Yii::app()->jump->error('未找到该学生信息!');
  616. }
  617. // 获取学生登录名密码等
  618. $studentAccount = BusinessStudent::model()->find('student_id=:stid', array(':stid' => $studentId));
  619. if (empty($studentAccount)) {
  620. Yii::app()->jump->error('未找到该学生信息!');
  621. }
  622. if (Yii::app()->request->getIsPostRequest()) {
  623. $class_ids = array();
  624. $username = safe_replace(Yii::app()->request->getPost('username'));
  625. $password = safe_replace(Yii::app()->request->getPost('password'));
  626. $password2 = safe_replace(Yii::app()->request->getPost('password2'));
  627. $school_student_card = safe_replace(Yii::app()->request->getPost('school_student_card'));
  628. $is_outer = safe_replace(Yii::app()->request->getPost('is_outer'));
  629. $class_id = safe_replace(Yii::app()->request->getPost('class_id'));
  630. $status = safe_replace(Yii::app()->request->getPost('status'));
  631. $logoutStatus = safe_replace(Yii::app()->request->getPost('logout_status'));
  632. $id_number = safe_replace(Yii::app()->request->getPost('id_number'));
  633. $id_number = Yii::app()->request->getPost('id_number');
  634. //扩展设置
  635. $field_1=-1;
  636. $field_2=-1;
  637. $field_3=-1;
  638. $field_4=-1;
  639. $field_5=-1;
  640. $regex = '/^[a-zA-Z0-9]+$/u';
  641. $studentExtend=$this->schoolManager->getStudentExtend();
  642. if($studentExtend){
  643. foreach($studentExtend as $key=>$val){
  644. if($val['is_enable']==1){
  645. $check_field_value=Yii::app()->request->getPost($key);
  646. if($check_field_value && !preg_match($regex, $check_field_value)){
  647. Yii::app()->jump->error('自定义考号内容只能是数字和字母');
  648. }
  649. $$key=$check_field_value;
  650. }
  651. }
  652. }
  653. //验证身份证
  654. if($id_number){
  655. $check_id_number=$this->sConn->createCommand("select student_id from student_info where id_number='".$id_number."' and student_id <>'".$studentId."'")->queryRow();
  656. if($check_id_number){
  657. Yii::app()->jump->error('身份证号已存在!');
  658. }
  659. }
  660. /**
  661. * 学校班级信息
  662. */
  663. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$class_id));
  664. /**
  665. * 智学网准考证号
  666. */
  667. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  668. $zhixue_student_card = safe_replace(Yii::app()->request->getPost('zhixue_student_card'));
  669. if ($zhixue_student_card) {
  670. if(!is_numeric($zhixue_student_card)){
  671. Yii::app()->jump->error('智学网准考证号格式不正确!');
  672. }
  673. $b_student_data = BusinessStudent::model()->findAll('school_id =:school_id and zhixue_student_card=:zhixue_student_card', array(':school_id'=>$this->schoolId,':zhixue_student_card' => $zhixue_student_card));
  674. if ($b_student_data && $studentAccount->zhixue_student_card != $zhixue_student_card) {
  675. Yii::app()->jump->error('智学网准考证号已存在!');
  676. }
  677. }
  678. } else {
  679. $zhixue_student_card = '';
  680. }
  681. /**
  682. * 学校准考证号
  683. */
  684. $semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
  685. if ($semester_class_data)
  686. {
  687. foreach ($semester_class_data as $v)
  688. {
  689. $class_ids[$v->class_id] = $v->class_id;
  690. }
  691. }
  692. $s_student_ids = array();
  693. $school_student_studentId = array();
  694. if($school_student_card)
  695. {
  696. if(!is_numeric($school_student_card)){
  697. Yii::app()->jump->error('学校准考证号格式不正确!');
  698. }
  699. $criteria = new CDbCriteria();
  700. $criteria->addInCondition('class_id',$class_ids);
  701. $criteria->addCondition('status=0');
  702. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  703. if(!$semester_student_class_data)
  704. {
  705. $s_student_ids = array();
  706. }else
  707. {
  708. foreach($semester_student_class_data as $v)
  709. {
  710. $s_student_ids[$v->student_id] = $v->student_id;
  711. }
  712. }
  713. unset($semester_student_class_data);
  714. unset($criteria);
  715. $criteria = new CDbCriteria();
  716. $criteria->addInCondition('student_id',$s_student_ids);
  717. $criteria->addCondition('school_student_card=:school_student_card');
  718. $criteria->params[':school_student_card'] = $school_student_card;
  719. $s_student_data = BusinessStudent::model()->findAll($criteria);
  720. if($s_student_data)
  721. {
  722. foreach($s_student_data as $v)
  723. {
  724. $school_student_studentId[(string)$v->student_id] = $v->student_id;
  725. }
  726. }
  727. unset($criteria);
  728. unset($s_student_ids);
  729. unset($s_student_data);
  730. //print_r($school_student_studentId)
  731. if($school_student_studentId)
  732. {
  733. if(!isset($school_student_studentId[(string)$studentId]) )
  734. {
  735. Yii::app()->jump->error('学校准考证号已存在!');
  736. }
  737. }
  738. unset($school_student_studentId);
  739. /**
  740. * 获取班级信息
  741. */
  742. $_school_student_card = '';
  743. $_school_student_status = 0;
  744. $grade_data = SGradeModel::model()->findAll();
  745. if($class_data && $grade_data)
  746. {
  747. foreach($grade_data as $v)
  748. {
  749. if($class_data->grade == $v->id)
  750. {
  751. $_school_student_card = $v->card_length;
  752. $_school_student_status = $v->card_status;
  753. }
  754. }
  755. if($_school_student_status)
  756. {
  757. if($_school_student_card)
  758. {
  759. if(strlen((string)$school_student_card) != $_school_student_card)
  760. {
  761. Yii::app()->jump->error('准考证长度与学校设置长度不一致!');
  762. }
  763. }else
  764. {
  765. Yii::app()->jump->error('学校未设置准考证位数,请到学校管理中设置');
  766. }
  767. }
  768. }
  769. }
  770. $realname = Yii::app()->request->getPost('realname');
  771. $serial_number = Yii::app()->request->getPost('serial_number');
  772. $userno = Yii::app()->request->getPost('userno');
  773. $sex = Yii::app()->request->getPost('sex');
  774. $is_outer = Yii::app()->request->getPost('is_outer');
  775. $student_phone = Yii::app()->request->getPost('student_phone');
  776. if (!$class_ids)
  777. {
  778. Yii::app()->jump->error('不在当前学期!');
  779. }
  780. if (empty($realname))
  781. {
  782. Yii::app()->jump->error('请确认学生信息是否填写完整!');
  783. }
  784. $class_ids = array_merge($class_ids);
  785. if($id_number){
  786. $student_info_data = $this->sConn->createCommand("SELECT * FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "' and id_number='".$id_number."'")->queryAll();
  787. }else{
  788. $student_info_data = $this->sConn->createCommand("SELECT * FROM `student_info` `t` WHERE class_id IN (" . implode(',', $class_ids) . ") and realname='" . $realname . "'")->queryAll();
  789. }
  790. if ($student_info_data)
  791. {
  792. if (count($student_info_data) > 1)
  793. {
  794. $student_ids = array();
  795. foreach($student_info_data as $v)
  796. {
  797. $student_ids[$v['student_id']] = $v['student_id'];
  798. }
  799. $criteria = new CDbCriteria();
  800. $criteria->addInCondition('student_id',$student_ids);
  801. $criteria->addCondition('status=0');
  802. $student_class_datas = SStudentClassRelation::model()->findAll($criteria);
  803. if( count($student_class_datas)>1)
  804. {
  805. Yii::app()->jump->error('学生真实姓名已经存在');
  806. }
  807. if($student_class_datas && $student_class_datas[0]['student_id']!=$studentId)
  808. {
  809. Yii::app()->jump->error('学生真实姓名已经存在');
  810. }
  811. unset($student_class_datas);
  812. } else
  813. {
  814. $student_class_datas = SStudentClassRelation::model()->find('student_id=:student_id and status=:status',array(':student_id'=>$student_info_data[0]['student_id'],':status'=>0));
  815. if($student_class_datas)
  816. {
  817. if ($student_info_data[0]['student_id'] != $studentId)
  818. {
  819. Yii::app()->jump->error('学生真实姓名已经存在');
  820. }
  821. }
  822. }
  823. }
  824. $serial_number_student_class = SStudentClassRelation::model()->find('class_id=:class_id and serial_number=:serial_number and status=:status', array(':class_id' => $class_id, ':serial_number' => $serial_number, ':status' => 0));
  825. if ($serial_number_student_class)
  826. {
  827. $student_number_student_class = SStudentClassRelation::model()->find('class_id=:class_id and student_id=:student_id and serial_number=:serial_number and status=:status', array(':class_id' => $class_id, ':student_id' => $studentId, ':serial_number' => $serial_number, ':status' => 0));
  828. if (!$student_number_student_class)
  829. {
  830. Yii::app()->jump->error('班级序号已经存在');
  831. }
  832. unset($student_number_student_class);
  833. }
  834. // 创建学生事务
  835. $_password = '';
  836. $update_arr = array();
  837. // 更新主库学生登录账号信息
  838. if (!empty($password) && !empty($password2))
  839. {
  840. if ($password != $password2)
  841. {
  842. Yii::app()->jump->error('两次密码输入不一致!');
  843. } else
  844. {
  845. $_password = md5(sha1($password . 'wy') . 'fengche');
  846. }
  847. $update_arr['password'] = $_password;
  848. //更新密码,清除缓存
  849. $studentLoginKey='zsy:login_verify_token_'.$studentId;
  850. $studentZBKLoginKey='zbk:login_verify_token_'.$studentId;
  851. $server = Yii::app()->params["student_login_cache"]["servers"];
  852. $redis = new Redis();
  853. foreach ($server as $value){
  854. $redis->connect($value["hostname"], $value["port"]);
  855. if(isset($value['password'])){
  856. $redis->auth($value['password']);
  857. }
  858. $redis->select($value['database']);
  859. $redis->del($studentLoginKey);
  860. $redis->del($studentZBKLoginKey);
  861. }
  862. }
  863. $update_arr['zhixue_student_card'] = $zhixue_student_card;
  864. $update_arr['school_student_card'] = $school_student_card;
  865. $update_arr['status'] = $status;
  866. $update_arr['logout_status'] = $logoutStatus;
  867. if (false === (BusinessStudent::model()->updateAll($update_arr, 'student_id=:stid', array(':stid' => $studentId)))) {
  868. Yii::app()->jump->error('主数据库更新失败!');
  869. }
  870. //更新REDIS
  871. Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
  872. $transaction = $studentAccount->dbConnection->beginTransaction();
  873. try {
  874. $updateArr=array(
  875. 'realname' => $realname,
  876. 'student_phone' => $student_phone,
  877. 'sex' => $sex,
  878. 'is_outer' => $is_outer,
  879. 'update_time' => time(),
  880. 'id_number'=>$id_number
  881. );
  882. //扩展数据
  883. if($field_1!=-1){
  884. $updateArr['field_1'] = $field_1;
  885. }
  886. if($field_2!=-1){
  887. $updateArr['field_2'] = $field_2;
  888. }
  889. if($field_3!=-1){
  890. $updateArr['field_3'] = $field_3;
  891. }
  892. if($field_4!=-1){
  893. $updateArr['field_4'] = $field_4;
  894. }
  895. if($field_5!=-1){
  896. $updateArr['field_5'] = $field_5;
  897. }
  898. SStudentInfo::model()->updateAll($updateArr, 'student_id=:stid', array(':stid' => $studentId));
  899. SStudentClassRelation::model()->updateAll(array(
  900. 'userno' => $userno, 'serial_number' => $serial_number
  901. ), 'student_id=:student_id and class_id =:class_id', array(':student_id' => $studentId, ':class_id' => $class_id));
  902. $transaction->commit();
  903. if(Yii::app()->params['handle_log_on_off'])
  904. {
  905. writeFileLog(jsonEncode(array(
  906. "student_id" => $studentId,
  907. "operate_project" => 'zsyas2',
  908. "school_id" => $this->schoolId,
  909. "title" => '编辑学生',
  910. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  911. "operate_method" => $this->action,
  912. "operate_url" => $this->getRoute(),
  913. "operate_sql" =>'',
  914. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  915. "date"=>date('Y-m-d H:i:s')
  916. )));
  917. }
  918. } catch (Exception $e) {
  919. //如果操作失败, 数据回滚
  920. $transaction->rollback();
  921. Yii::app()->jump->error('编辑学生失败!');
  922. }
  923. $this->redirect(array('studentinfo/index'));
  924. };
  925. //$this->redirect(array('studentinfo/index'));
  926. $data = array();
  927. // 获取当前学校班级
  928. $data['classInfo'] = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and is_hide=0');
  929. $studentClass=SStudentClassRelation::model()->find('student_id=:sid and status=:status and class_type=1', array(':sid' => $studentId, ':status' => 0));
  930. $data['studentClass']=$studentClass->class_id;
  931. $data['userInfo'] = $studentInfo;
  932. $data['studentInfo'] = $studentAccount;
  933. $data["studentId"] = $studentId;
  934. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  935. $data['use_zhixue'] = $this->schoolInfo->use_zhixue;
  936. } else {
  937. $data['use_zhixue'] = 0;
  938. }
  939. //$data['use_zhixue'] = $this->schoolInfo->use_zhixue;
  940. //判断扩展字段设置
  941. $data['studentExtend']=$this->schoolManager->getStudentExtend();
  942. //判断学校是否设置平板登陆权限
  943. $school_data = BusinessSchool::model()->find("school_id=:sid",array(':sid'=>Yii::app()->session['coachInfo']['school_id']));
  944. $data['is_login_permission'] = $school_data['is_login_permission'];
  945. // $stu_login_id = Yii::app()->stu_login_permission->getValue('zsy_student:student_app_unique_no:'.$studentId);
  946. // 获取设备号
  947. require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
  948. $group_redis_obj = RedisLoginCtrl::getRedisObj($studentId);
  949. $stu_login_id = $group_redis_obj->hGet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no');
  950. if($stu_login_id){
  951. $data['stu_login_id'] = 1;
  952. }else{
  953. $data['stu_login_id'] = 0;
  954. }
  955. $this->render('edit2', $data);
  956. }
  957. // 根据班级id获取学生
  958. public function actionGetstudent()
  959. {
  960. $cid = safe_replace($_POST['cid']);
  961. if (empty($cid)) {
  962. $json['flag'] = false;
  963. echo json_encode($json);
  964. die;
  965. }
  966. //$getStudent = StudentInfo::model()->findAll('class_id=:cid',array('cid'=>$cid));
  967. $getStudent = $this->schoolManager->getClassStudents($cid);
  968. if (empty($getStudent)) {
  969. $json['flag'] = false;
  970. $json['number'] = 1;
  971. echo json_encode($json);
  972. die;
  973. }
  974. $resArray = array();
  975. $student_ids = array();
  976. foreach ($getStudent as $key => $val) {
  977. $student_ids[$val->student_id] = $val->student_id;
  978. }
  979. $criteria = new CDbCriteria();
  980. $b_student = array();
  981. $criteria->addInCondition('student_id',$student_ids);
  982. $b_student_data = BusinessStudent::model()->findAll($criteria);
  983. if($b_student_data)
  984. {
  985. foreach($b_student_data as $v)
  986. {
  987. $b_student[$v->student_id] = $v->student_card;
  988. }
  989. foreach ($getStudent as $key => $val) {
  990. $resArray[$key]['student_id'] = $val->student_id;
  991. $resArray[$key]['realname'] = $val->realname;
  992. if(isset($b_student[$val->student_id]) && !empty($b_student[$val->student_id]))
  993. {
  994. $resArray[$key]['student_card'] = $b_student[$val->student_id];
  995. }else{
  996. $resArray[$key]['student_card'] = '';
  997. }
  998. }
  999. }else{
  1000. foreach ($getStudent as $key => $val) {
  1001. $resArray[$key]['student_id'] = $val->student_id;
  1002. $resArray[$key]['realname'] = $val->realname;
  1003. $resArray[$key]['student_card'] = '';
  1004. }
  1005. }
  1006. unset($getStudent);
  1007. $json['flag'] = true;
  1008. $json['resArray'] = $resArray;
  1009. echo json_encode($json);exit;
  1010. }
  1011. // ajax验证登录账号是否存在
  1012. public function actionVerifyname()
  1013. {
  1014. //$getName = safe_replace($_POST['name']);
  1015. //$getSid = safe_replace($_POST['sid']);
  1016. $getName = Req::post("name");
  1017. $getSid = Req::post("sid");
  1018. if (!empty($getName)) {
  1019. if ($getSid != 1) {
  1020. $getCount = BusinessStudent::model()->count('username=:name and student_id!=:sid', array(':name' => $getName, ':sid' => $getSid));
  1021. if ($getCount) {
  1022. exit('1'); // 已存在
  1023. } else {
  1024. exit('2'); // 不存在
  1025. }
  1026. } else {
  1027. $student_data = BusinessStudent::model()->find('username=:name', array(':name' => $getName));
  1028. if ($student_data) {
  1029. $student_info_data = StudentInfo::model()->find('student_id=:student_id', array(':student_id' => $student_data->student_id));
  1030. if ($student_info_data) {
  1031. $student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status', array(':student_id' => $student_data->student_id, ':status' => 0));
  1032. if (!$student_class_data) {
  1033. exit('2');
  1034. }
  1035. }
  1036. exit('1'); // 已存在
  1037. }
  1038. exit('2'); // 不存在
  1039. }
  1040. } else {
  1041. exit('1'); // 已存在
  1042. }
  1043. }
  1044. public function actionVerifyrealname()
  1045. {
  1046. $getName = preg_replace("/[^\x{2E80}-\x{FE4F}]+/u", "", exsl_safe_replace(Req::post("realname")));
  1047. $p_type = Req::post("p_type");
  1048. $cid = Req::post("cid");
  1049. $class_ids = array();
  1050. if (!$cid) {
  1051. echo json_encode(array('status' => 0));
  1052. exit;
  1053. }
  1054. $class_data = ClassModel::model()->find('class_id=:class_id', array(':class_id' => $cid));
  1055. if ($class_data) {
  1056. $semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $class_data->semester_id));
  1057. if ($semester_class_data) {
  1058. foreach ($semester_class_data as $v) {
  1059. $class_ids[$v->class_id] = $v->class_id;
  1060. }
  1061. }
  1062. }
  1063. if ($p_type && $p_type == 2) {
  1064. $student_id = Req::post("student_id");
  1065. $studentinfo_data = SStudentInfo::model()->find('student_id=:student_id', array(':student_id' => $student_id));
  1066. if ($studentinfo_data) {
  1067. if ($studentinfo_data->realname == $getName) {
  1068. echo json_encode(array('status' => 1));
  1069. exit;
  1070. } else {
  1071. $criteria = new CDbCriteria();
  1072. $criteria->addInCondition('class_id', $class_ids);
  1073. $criteria->addCondition('realname=:realname');
  1074. $criteria->params[':realname'] = $getName;
  1075. $student_data = SStudentInfo::model()->findAll($criteria);
  1076. unset($criteria);
  1077. if ($student_data) {
  1078. if (count($student_data) > 1) {
  1079. $_student_ids = array();
  1080. foreach($student_data as $v)
  1081. {
  1082. $_student_ids[$v->student_id] = $v->student_id;
  1083. }
  1084. $criteria = new CDbCriteria();
  1085. $criteria->addInCondition('student_id',$_student_ids);
  1086. $criteria->addCondition('status=:status');
  1087. $criteria->params[':status'] = 0;
  1088. $student_c_r = SStudentClassRelation::model()->findAll($criteria);
  1089. if($student_c_r)
  1090. {
  1091. echo json_encode(array('status' => 0));
  1092. exit;
  1093. }
  1094. echo json_encode(array('status' => 1));
  1095. exit;
  1096. } else {
  1097. $student_class_all_data = SStudentClassRelation::model()->findAll('student_id=:student_id and status=:status', array(':student_id' => $student_data[0]->student_id, ':status' => 0));
  1098. if ($student_class_all_data) {
  1099. echo json_encode(array('status' => 0));
  1100. exit;
  1101. }
  1102. echo json_encode(array('status' => 1));
  1103. exit;
  1104. }
  1105. } else {
  1106. echo json_encode(array('status' => 1));
  1107. exit;
  1108. }
  1109. }
  1110. }
  1111. echo json_encode(array('status' => 0));
  1112. exit;
  1113. } else {
  1114. /*$cid = Req::post("cid");
  1115. if($cid <= 0)
  1116. {
  1117. echo json_encode(array('status'=>2));exit;
  1118. }
  1119. $class_data = ClassModel::model()->find('class_id=:class_id and semester_id=:semester_id',array(':class_id'=>$cid,':semester_id'=>$this->semesterId));
  1120. if(!$class_data)
  1121. {
  1122. echo json_encode(array('status'=>3));exit;
  1123. }*/
  1124. if (!empty($getName)) {
  1125. $criteria = new CDbCriteria();
  1126. $criteria->addInCondition('class_id', $class_ids);
  1127. $criteria->addCondition('realname=:realname');
  1128. $criteria->params[':realname'] = $getName;
  1129. $student_data = SStudentInfo::model()->findAll($criteria);
  1130. //$student_data = SStudentInfo::model()->findAll('realname=:realname',array(':realname'=>$getName));
  1131. if ($student_data) {
  1132. if (count($student_data) > 1) {
  1133. $_student_ids = array();
  1134. foreach($student_data as $v)
  1135. {
  1136. $_student_ids[$v->student_id] = $v->student_id;
  1137. }
  1138. $criteria = new CDbCriteria();
  1139. $criteria->addInCondition('student_id',$_student_ids);
  1140. $criteria->addCondition('status=:status');
  1141. $criteria->params[':status'] = 0;
  1142. $student_c_r = SStudentClassRelation::model()->findAll($criteria);
  1143. if($student_c_r)
  1144. {
  1145. echo json_encode(array('status' => 0));
  1146. exit;
  1147. }
  1148. echo json_encode(array('status' => 1));
  1149. exit;
  1150. } else {
  1151. $student_class_all_data = SStudentClassRelation::model()->findAll('student_id=:student_id and status=:status', array(':student_id' => $student_data[0]->student_id, ':status' => 0));
  1152. if ($student_class_all_data) {
  1153. echo json_encode(array('status' => 0));
  1154. exit;
  1155. }
  1156. echo json_encode(array('status' => 1));
  1157. exit;
  1158. }
  1159. } else {
  1160. echo json_encode(array('status' => 1));
  1161. exit;
  1162. }
  1163. }
  1164. echo json_encode(array('status' => 0));
  1165. exit;
  1166. }
  1167. }
  1168. // ajax验证学号、序号是否重复
  1169. public function actionVerifynum()
  1170. {
  1171. //$getNum = safe_replace($_POST['pnumber']);
  1172. //$getSid = safe_replace($_POST['sid']);
  1173. //$type = (int)$_POST['type'];
  1174. $getNum = Req::post("pnumber");
  1175. $getSid = Req::post("sid");
  1176. $type = Req::post("type");
  1177. if ($type == 1) { // 验证唯一的学号
  1178. if (!empty($getNum)) {
  1179. if ($getSid == 1) { // 表示新加数据
  1180. $countNum = SStudentClassRelation::model()->count('userno=:uno and status=:status and class_id=:class_id', array(':uno' => $getNum, ':status' => 0, ':class_id' => $getSid));
  1181. if ($countNum) {
  1182. exit('1'); // 已存在
  1183. } else {
  1184. exit('2'); // 不存在
  1185. }
  1186. } else {
  1187. $countNum = SStudentClassRelation::model()->count('userno=:uno and status=:status and class_id=:class_id', array(':uno' => $getNum, ':status' => 0, ':class_id' => $getSid));
  1188. if ($countNum) {
  1189. exit('1'); // 已存在
  1190. } else {
  1191. exit('2'); // 不存在
  1192. }
  1193. }
  1194. }
  1195. } elseif ($type == 2) {
  1196. //$getCid = safe_replace($_POST['cid']);
  1197. $getCid = Req::post("cid");
  1198. if (!empty($getNum)) {
  1199. if ($getSid == 1) { // 表示新加数据
  1200. //$countNum = StudentInfo::model()->count('class_id=:cid and serial_number=:uno',array(':uno'=>$getNum,':cid'=>$getCid));
  1201. $countNum = $this->schoolManager->serialNumberExistsInClass($getNum, $getCid);
  1202. if ($countNum) {
  1203. echo json_encode(array('status' => 1));
  1204. exit;
  1205. } else {
  1206. echo json_encode(array('status' => 2));
  1207. exit;
  1208. }
  1209. } else {
  1210. //$countNum = StudentInfo::model()->count('class_id=:cid and serial_number=:uno and student_id!=:sid',array(':uno'=>$getNum,':cid'=>$getCid,':sid'=>$getSid));
  1211. $countNum = $this->schoolManager->serialNumberExistsInClass($getNum, $getCid, $getSid);
  1212. if ($countNum) {
  1213. echo json_encode(array('status' => 1));
  1214. exit;
  1215. } else {
  1216. echo json_encode(array('status' => 2));
  1217. exit;
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. public function actionKick()
  1224. {
  1225. }
  1226. public function actionDelStudentAct()
  1227. {
  1228. $studentId = Req::post("studentId");
  1229. $classId = Req::post("classId");
  1230. $logTitle='删除学生';
  1231. if($classId){
  1232. $classInfo=$this->schoolManager->getClass($classId);
  1233. if($classInfo['class_type']==2){
  1234. $logTitle='删除教学班学生';
  1235. }
  1236. }
  1237. if(Yii::app()->params['handle_log_on_off'])
  1238. {
  1239. writeFileLog(jsonEncode(array(
  1240. "exam_group_id" => 0,
  1241. "operate_project" => 'zsyas2',
  1242. "school_id" => $this->schoolId,
  1243. "title" => $logTitle,
  1244. "operate_account" => Yii::app()->session['coachInfo']['coach_name'],
  1245. "operate_method" => $this->action,
  1246. "operate_url" => $this->getRoute(),
  1247. "operate_sql" =>json_encode(array('delete'=>array('student_id'=>$studentId))),
  1248. "operate_param" =>json_encode(array('post'=>$_POST,'get'=>$_GET)),
  1249. "date"=>date('Y-m-d H:i:s')
  1250. )));
  1251. }
  1252. $delAntherClass=0;
  1253. if($classId && $classInfo && $classInfo['class_type']==2){
  1254. $delAntherClass=$classId;
  1255. }
  1256. //更新REDIS
  1257. Yii::app()->redis_business_student->del('redis_business_del_student:'.$this->schoolId);
  1258. if(isset(Yii::app()->session['testFlag']) && Yii::app()->session['testFlag']==1)
  1259. {
  1260. echo json_encode($this->schoolManager->purgeStudent($studentId,1,$delAntherClass));exit;
  1261. }
  1262. echo json_encode($this->schoolManager->purgeStudent($studentId,0,$delAntherClass));exit;
  1263. }
  1264. public function actionInputRecord()
  1265. {
  1266. $studentId = Req::get("studentId");
  1267. }
  1268. public function actionSchoolCard()
  1269. {
  1270. $this->render('schoolcard');
  1271. }
  1272. public function actionImport()
  1273. {
  1274. if (Yii::app()->request->getIsPostRequest()) {
  1275. $uploader = new Uploader("upload/tmpDir/UploadClassesStudentsList/{$this->schoolId}/");
  1276. $uploader->allowTypes = array("xls");
  1277. $file = $uploader->act();
  1278. $file = Arr::current(Arr::current($file));
  1279. if (!$file || !isset($file["error"]))
  1280. Yii::app()->jump->error('请选择上传的Excel!');
  1281. if ($file["error"] != 0) {
  1282. switch ($file["error"]) {
  1283. case 2001:
  1284. Yii::app()->jump->error('文件类型不符');
  1285. break;
  1286. case 2002:
  1287. Yii::app()->jump->error('文件大小超出允许范围');
  1288. break;
  1289. default:
  1290. Yii::app()->jump->error('上传失败');
  1291. break;
  1292. }
  1293. }
  1294. $inputFileName = $file["src"];
  1295. Yii::import('application.extensions.*');
  1296. require_once('phpexcel/PHPExcel/IOFactory.php');
  1297. $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
  1298. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  1299. //FIXME 2019-12-02
  1300. @unlink($file["src"]);
  1301. unset($sheetData[1]);
  1302. krsort($sheetData);
  1303. $sheetData = array_reverse($sheetData);
  1304. if ($sheetData)
  1305. {
  1306. $_err = array();
  1307. //获取学校
  1308. $school_data = BusinessSchool::model()->find('school_id=:school_id',array(':school_id'=>$this->schoolId));
  1309. if(!$school_data)
  1310. {
  1311. Yii::app()->jump->error('非法学校');
  1312. }
  1313. $semester_class_data = ClassModel::model()->findAll('semester_id=:semester_id', array(':semester_id' => $this->semesterId));
  1314. if ($semester_class_data)
  1315. {
  1316. foreach ($semester_class_data as $v)
  1317. {
  1318. $class_ids[$v->class_id] = $v->class_id;
  1319. }
  1320. }
  1321. $criteria = new CDbCriteria();
  1322. $criteria->addInCondition('class_id',$class_ids);
  1323. $criteria->addCondition('status=0');
  1324. $semester_student_class_data = SStudentClassRelation::model()->findAll($criteria);
  1325. if(!$semester_student_class_data)
  1326. {
  1327. Yii::app()->jump->error('当前学期无数据!');
  1328. }
  1329. foreach($semester_student_class_data as $v)
  1330. {
  1331. $s_student_ids[$v->student_id] = $v->student_id;
  1332. }
  1333. unset($criteria);
  1334. $criteria = new CDbCriteria();
  1335. $criteria->addInCondition('student_id',$s_student_ids);
  1336. $s_student_data = BusinessStudent::model()->findAll($criteria);
  1337. if($s_student_data)
  1338. {
  1339. foreach($s_student_data as $v)
  1340. {
  1341. $school_student_studentId[$v->school_student_card] = $v->student_id;
  1342. }
  1343. }
  1344. foreach ($sheetData as $key => $val)
  1345. {
  1346. if ( empty($val['A']) || empty($val['B']) || empty($val['C']) )
  1347. {
  1348. continue;
  1349. }
  1350. $realname = preg_replace("/[^\x{4E00}-\x{9FFF}^0-9·]+/u", "", exsl_safe_replace($val['A']));
  1351. $student_card = safe_replace($val['B']);
  1352. $school_student_card = safe_replace($val['C']);
  1353. //验证长度
  1354. /*if(strlen((string)$school_student_card) != $school_data->card_length)
  1355. {
  1356. $_err[$key]['school_student_card'] = $school_student_card;
  1357. $_err[$key]['student_card'] = $student_card;
  1358. $_err[$key]['username'] = $realname;
  1359. $_err[$key]['msg'] = '准考证长度与学校设置长度不一致';
  1360. continue;
  1361. }*/
  1362. //验证是否已存在
  1363. if(isset($school_student_studentId[$school_student_card]) && !empty($school_student_studentId[$school_student_card]) )
  1364. {
  1365. $_err[$key]['school_student_card'] = $school_student_card;
  1366. $_err[$key]['student_card'] = $student_card;
  1367. $_err[$key]['username'] = $realname;
  1368. $_err[$key]['msg'] = '同学期同学校,学校准考证号为唯一,学校准考证号已存在';
  1369. continue;
  1370. }
  1371. $is_student_card = BusinessStudent::model()->find('school_id=:school_id and student_card=:student_card ',array(':school_id'=>$this->schoolId,':student_card'=>$student_card));
  1372. if(!$is_student_card)
  1373. {
  1374. $_err[$key]['school_student_card'] = $school_student_card;
  1375. $_err[$key]['student_card'] = $student_card;
  1376. $_err[$key]['username'] = $realname;
  1377. $_err[$key]['msg'] = '学生准考证号不存在';
  1378. continue;
  1379. }
  1380. $student_class_data = SStudentClassRelation::model()->find('student_id=:student_id and status=:status',array(':student_id'=>$is_student_card->student_id,':status'=>0));
  1381. if(!$student_class_data)
  1382. {
  1383. $_err[$key]['school_student_card'] = $school_student_card;
  1384. $_err[$key]['student_card'] = $student_card;
  1385. $_err[$key]['username'] = $realname;
  1386. $_err[$key]['msg'] = '学生已被删除';
  1387. continue;
  1388. }
  1389. $class_data = ClassModel::model()->find('class_id=:class_id',array(':class_id'=>$student_class_data->class_id));
  1390. if(!$class_data)
  1391. {
  1392. $_err[$key]['school_student_card'] = $school_student_card;
  1393. $_err[$key]['student_card'] = $student_card;
  1394. $_err[$key]['username'] = $realname;
  1395. $_err[$key]['msg'] = '学生所在班级不存在';
  1396. }
  1397. //验证长度
  1398. $grade_data = SGradeModel::model()->find('id=:id',array(':id'=>$class_data->grade));
  1399. if($grade_data->card_status)
  1400. {
  1401. if(strlen((string)$school_student_card) != $grade_data->card_length)
  1402. {
  1403. $_err[$key]['school_student_card'] = $school_student_card;
  1404. $_err[$key]['student_card'] = $student_card;
  1405. $_err[$key]['username'] = $realname;
  1406. $_err[$key]['msg'] = '准考证长度与学校设置长度不一致';
  1407. continue;
  1408. }
  1409. }
  1410. $flage=BusinessStudent::model()->updateAll(array('school_student_card'=>$school_student_card),'student_card=:student_card',array(':student_card'=>$student_card));
  1411. if(!$flage)
  1412. {
  1413. $_err[$key]['school_student_card'] = $school_student_card;
  1414. $_err[$key]['student_card'] = $student_card;
  1415. $_err[$key]['username'] = $realname;
  1416. $_err[$key]['msg'] = '写入失败';
  1417. continue;
  1418. }
  1419. }
  1420. if($_err)
  1421. {
  1422. $this->create_xls($_err);
  1423. }else
  1424. {
  1425. Yii::app()->jump->success('全部学生关联成功');exit;
  1426. }
  1427. }
  1428. }
  1429. }
  1430. public function create_xls($_err)
  1431. {
  1432. if(!$_err)
  1433. {
  1434. return false;
  1435. }
  1436. $objPHPExcel = new PHPExcel();
  1437. $objPHPExcel->getProperties()->setCreator("ctos")
  1438. ->setLastModifiedBy("ctos")
  1439. ->setTitle("导入学校准考证号")
  1440. ->setSubject("导入学校准考证号")
  1441. ->setDescription("导入学校准考证号")
  1442. ->setKeywords("excel")
  1443. ->setCategory("result file");
  1444. $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
  1445. $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
  1446. $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
  1447. $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);
  1448. $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);
  1449. $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
  1450. $objPHPExcel->setActiveSheetIndex(0)
  1451. ->setCellValue('A1', '姓名(当前学期唯一)')
  1452. ->setCellValue('B1', '系统准考证号')
  1453. ->setCellValue('C1', '学校准考证号')
  1454. ->setCellValue('D1', '错误原因');
  1455. $i = 1;
  1456. foreach($_err as $v)
  1457. {
  1458. $i = $i + 1;
  1459. $objPHPExcel->getActiveSheet(0)->setCellValue('A' . $i, $v['username']);
  1460. $objPHPExcel->getActiveSheet(0)->setCellValueExplicit('B' . $i, (string)$v['student_card'], PHPExcel_Cell_DataType::TYPE_STRING);
  1461. $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getNumberFormat()->setFormatCode("@");
  1462. $objPHPExcel->getActiveSheet(0)->setCellValue('C' . $i, $v['school_student_card']);
  1463. $objPHPExcel->getActiveSheet(0)->setCellValue('D' . $i, $v['msg']);
  1464. }
  1465. $objPHPExcel->getActiveSheet()->setTitle('学校准考证号关联失败');
  1466. $objPHPExcel->setActiveSheetIndex(0);
  1467. ob_end_clean(); // Added by me
  1468. header("Accept-Ranges:bytes");
  1469. header('Content-Type:application/vnd.ms-excel');
  1470. header("Content-type:application/vnd.ms-excel;charset=UTF-8");
  1471. header('Content-Disposition:attachment;filename="学校准考证号关联失败.xls"');
  1472. header('Cache-Control:max-age=0');
  1473. $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
  1474. $objWriter->save('php://output');
  1475. }
  1476. //待分班学生
  1477. public function actionWaitlist(){
  1478. $condition = array();
  1479. $class_id = safe_replace(Yii::app()->request->getQuery('class_id'));
  1480. $grade_id = safe_replace(Yii::app()->request->getQuery('grade_id'));
  1481. $realname = safe_replace(Yii::app()->request->getQuery('realname'));
  1482. $search_type = safe_replace(Yii::app()->request->getQuery('search_type'));
  1483. $where = '';
  1484. $semester_id = $this->schoolManager->getPrevSemesterId();
  1485. //dd($semester_id);
  1486. if ($realname) {
  1487. if($search_type==1)
  1488. {
  1489. $condition = array("stu.realname like '%{$realname}%'");
  1490. }
  1491. if($search_type==2)
  1492. {
  1493. $where = "school_id=".$this->schoolId." and username = '".$realname."'";
  1494. }
  1495. if($search_type==3)
  1496. {
  1497. $realname = (int)$realname;
  1498. $where = 'school_id='.$this->schoolId.' and student_card = '.$realname;
  1499. }
  1500. if($search_type==4)
  1501. {
  1502. $where = "school_id=".$this->schoolId." and school_student_card = '".$realname."'";
  1503. }
  1504. if($search_type==5)
  1505. {
  1506. $realname = (int)$realname;
  1507. $where = 'school_id='.$this->schoolId.' and zhixue_student_card = '.$realname;
  1508. }
  1509. }
  1510. $grade_class_array = array();
  1511. $sort = '';
  1512. if (isset($_GET['sort'])) {
  1513. $sort = safe_replace(Yii::app()->request->getQuery('sort'));
  1514. }
  1515. if ($grade_id) {
  1516. $grade_class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id', array(':grade' => $grade_id, ':semester_id' => $semester_id));
  1517. if ($grade_class_data) {
  1518. foreach ($grade_class_data as $v) {
  1519. $grade_class_array[$v->class_id] = $v->attributes;
  1520. }
  1521. }
  1522. array_push($condition, "c.grade=" . $grade_id);
  1523. }
  1524. array_push($condition, "c.semester_id=" . $semester_id);
  1525. array_push($condition, "scr.status=2" );
  1526. $classes = $this->schoolManager->getClassesBySemesterId($semester_id);
  1527. $resultClass = Arr::toObj($classes);
  1528. if (empty($class_id) && $classes) {
  1529. foreach ($classes as $v) {
  1530. $class_ids[$v['class_id']] = $v['class_id'];
  1531. }
  1532. $rs = $this->schoolManager->getPrevSemesterClassStudentsList($class_ids, $condition, 20,$where);
  1533. } else {
  1534. $rs = $this->schoolManager->getPrevSemesterClassStudentsList($class_id, $condition, 20,$where);
  1535. }
  1536. $userList = $rs["rs"];
  1537. $data = array();
  1538. // 处理学生按学号排序
  1539. if ($sort == 1) {
  1540. $sort = 2;
  1541. } elseif ($sort == 2) {
  1542. $sort = 1;
  1543. }
  1544. // 获取所有学期
  1545. //$data['allSemester']= Semester::model()->findAll();
  1546. //读取待分班学生数量
  1547. $waitStudent=$this->schoolManager->getWaitStudent();
  1548. $data['waitStudent'] = $waitStudent;
  1549. $data['grade_id'] = $grade_id;
  1550. $data['userList'] = $userList;
  1551. $data['pages'] = $rs['pager'];
  1552. $data['page_total'] = $rs['pager']->rowsCount;
  1553. $data['class_id'] = $class_id;
  1554. $data['search_type'] = $search_type;
  1555. $data['realname'] = $realname;
  1556. $data['grade_class'] = $grade_class_array;
  1557. $data['semester_id'] = $semester_id;
  1558. $data['classInfo'] = $resultClass;
  1559. $data['sort'] = $sort;
  1560. $data['calssName'] = ClassModel::model()->getClassName($class_id);
  1561. if (isset($this->schoolInfo->use_zhixue) && !empty($this->schoolInfo->use_zhixue)) {
  1562. $data["use_zhixue"] = $this->schoolInfo->use_zhixue;
  1563. } else {
  1564. $data["use_zhixue"] = 0;
  1565. }
  1566. unset($resultClass, $classes);
  1567. $this->render('index_prev_semester', $data);
  1568. }
  1569. //获取上学期班级
  1570. public function actionGetPrevSemesterClassByGrade(){
  1571. $grade_id = Req::post("grade_id");
  1572. $class_array = array();
  1573. if(!in_array($grade_id,array(0,1,2,3)))
  1574. {
  1575. echo json_encode(array('status'=>0,'result'=>array()));exit;
  1576. }
  1577. $semester_id = $this->schoolManager->getPrevSemesterId();
  1578. $class_data = ClassModel::model()->findAll('grade=:grade and semester_id=:semester_id',array(':grade' => $grade_id,':semester_id'=>$semester_id));
  1579. if($class_data){
  1580. foreach($class_data as $v )
  1581. {
  1582. $class_array[] = $v->attributes;
  1583. }
  1584. echo json_encode(array('status'=>1,'result'=>$class_array));exit;
  1585. }
  1586. echo json_encode(array('status'=>0,'result'=>array()));exit;
  1587. }
  1588. //待分配学生分配
  1589. public function actionAssignStudent()
  1590. {
  1591. $class_id = Req::post('class_id');
  1592. $studentId = Req::post('student_id');
  1593. $result['status'] = 0;
  1594. if (!is_array($studentId) || count($studentId) == 0 || !$class_id) {
  1595. $result['msg'] = '参数错误';
  1596. exit(json_encode($result));
  1597. }
  1598. $classStudentSql = "insert into student_class_relation(`class_id`,`student_id`,`status`,`serial_number`,`userno`,`update_time`,`operation`) values ";
  1599. $classStudentValues = array();
  1600. $oldClassIds = array();
  1601. foreach ($studentId as $sid) {
  1602. $classStudent = $this->sConn->createCommand("select student_id,serial_number,userno from student_class_relation where student_id='" & $sid & "' and status=2 ")->queryRow();
  1603. $classStudentValues[] = "('" . $class_id . "','" . $sid . "',0,'" . $classStudent['serial_number'] . "','" . $classStudent['userno'] . "','" . time() . "',0)";
  1604. $oldClassIds[] = $classStudent['class_id'];
  1605. }
  1606. if ($classStudentValues) {
  1607. $classStudentSql = $classStudentSql . implode(',', $classStudentValues);
  1608. }
  1609. $updateStudentInfoSql = "update student_info set class_id='" . $class_id . "' where student_id in(" . implode(',', $studentId) . ") ;";
  1610. $updateClassStudentSql = "update student_class_relation set status=1,operation=3 where class_id in(" . implode(',', $oldClassIds) . ") and student_id in(" . implode(',', $studentId) . ") and status=2; ";
  1611. $trans = $this->sConn->beginTransaction();
  1612. try {
  1613. $this->sConn->createCommand($classStudentSql)->execute();
  1614. $this->sConn->createCommand($updateClassStudentSql)->execute();
  1615. $this->sConn->createCommand($updateStudentInfoSql)->execute();
  1616. $trans->commit();
  1617. $result['status'] = 1;
  1618. } catch (Exception $e) {
  1619. $trans->rollBack();
  1620. $result['msg'] = '分班失败';
  1621. }
  1622. exit(json_encode($result));
  1623. }
  1624. public function actionCheck(){
  1625. $data=array();
  1626. $this->render('check', $data);
  1627. }
  1628. //设置扩展字段
  1629. public function actionAjaxStudentExtendSetting(){
  1630. $field_1=Req::post('field_1');
  1631. $field_1_status=Req::post('field_1_status');
  1632. $field_2=Req::post('field_2');
  1633. $field_2_status=Req::post('field_2_status');
  1634. $field_3=Req::post('field_3');
  1635. $field_3_status=Req::post('field_3_status');
  1636. $field_4=Req::post('field_4');
  1637. $field_4_status=Req::post('field_4_status');
  1638. $field_5=Req::post('field_5');
  1639. $field_5_status=Req::post('field_5_status');
  1640. if($field_1_status=='true'){
  1641. $field_1_is_enable=1;
  1642. }else{
  1643. $field_1_is_enable=0;
  1644. }
  1645. if($field_2_status=='true'){
  1646. $field_2_is_enable=1;
  1647. }else{
  1648. $field_2_is_enable=0;
  1649. }
  1650. if($field_3_status=='true'){
  1651. $field_3_is_enable=1;
  1652. }else{
  1653. $field_3_is_enable=0;
  1654. }
  1655. if($field_4_status=='true'){
  1656. $field_4_is_enable=1;
  1657. }else{
  1658. $field_4_is_enable=0;
  1659. }
  1660. if($field_5_status=='true'){
  1661. $field_5_is_enable=1;
  1662. }else{
  1663. $field_5_is_enable=0;
  1664. }
  1665. $result['status']=0;
  1666. $insert="insert into student_info_extend(`field_name`,`field_mean`,`is_enable`) values ";
  1667. $insert.="('field_1','".$field_1."','".$field_1_is_enable."'),";
  1668. $insert.="('field_2','".$field_2."','".$field_2_is_enable."'),";
  1669. $insert.="('field_3','".$field_3."','".$field_3_is_enable."'),";
  1670. $insert.="('field_4','".$field_4."','".$field_4_is_enable."'),";
  1671. $insert.="('field_5','".$field_5."','".$field_5_is_enable."')";
  1672. $transcation = $this->sConn->beginTransaction();
  1673. try {
  1674. $del_sql = "truncate `student_info_extend`;";
  1675. $this->sConn->createCommand($del_sql)->execute();
  1676. $this->sConn->createCommand($insert)->execute();
  1677. $transcation->commit();
  1678. $result['status']=1;
  1679. }catch (Exception $e){
  1680. $transcation->rollback();
  1681. }
  1682. exit(json_encode($result));
  1683. }
  1684. //添加教学班学生
  1685. public function actionAddClassified(){
  1686. $gradeArr=array(
  1687. 1=>'高一',
  1688. 2=>'高二',
  1689. 3=>'高三',
  1690. );
  1691. $data = array();
  1692. $cid = safe_replace(Yii::app()->request->getQuery('cid'));
  1693. // $cname = ClassModel::model()->getClassName($cid);
  1694. $classInfo = $this->schoolManager->getClassInfo($cid);
  1695. $subjects=$this->schoolManager->getSubjectByClass($cid);
  1696. // 获取当前学校班级
  1697. $getClass = ClassModel::model()->findAll('semester_id="' . Yii::app()->session['session_semester_id'] . '" and class_type=1 and grade="'.$classInfo['grade'].'" and is_hide=0');
  1698. $resultClass = $getClass;
  1699. if (Yii::app()->session['coachInfo']['leader'] != 1) {
  1700. $resultClass = array();
  1701. $coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
  1702. foreach ($getClass as $t) {
  1703. foreach ($coachClass as $tt) {
  1704. if ($t->class_id == $tt->class_id) {
  1705. $resultClass[] = $t;
  1706. }
  1707. }
  1708. }
  1709. }
  1710. $data['cid'] = $cid;
  1711. $data['grade']=$classInfo['grade'];
  1712. $data['gradeName']=$gradeArr[$classInfo['grade']];
  1713. $data['cname'] = $classInfo['class_name'];
  1714. $data['classInfo'] = $resultClass;
  1715. $data['subjects'] = $subjects;
  1716. $this->render('add_classified', $data);
  1717. }
  1718. //加载未走班学生
  1719. public function actionGetStudentByClassified(){
  1720. $class_id=Req::post('class_id');
  1721. $subjects=Req::post('subjects');
  1722. $grade=Req::post('grade');
  1723. //读取科目下已走班学生
  1724. $studentIds=$this->schoolManager->getStudentBySubjects($subjects,$grade,$this->semesterId);
  1725. $studentList=array();
  1726. //读取当前班级学生
  1727. $studentInfo=$this->schoolManager->getClassStudents($class_id,array(),'ARR');
  1728. if($studentInfo){
  1729. foreach ($studentInfo as $item){
  1730. if(!in_array((string)$item['student_id'],$studentIds,true)){
  1731. //查询系统准考证
  1732. $studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$item['student_id']}'")->queryRow();
  1733. if($studentInfo){
  1734. $item['realname']=$item['realname'].'('.$studentInfo['student_card'].')';
  1735. }
  1736. $studentList[]=$item;
  1737. }
  1738. }
  1739. }
  1740. $result['status']=1;
  1741. $result['data']=$studentList;
  1742. exit(json_encode($result));
  1743. }
  1744. //查询未走班学生
  1745. public function actionSearchStudentByClassified(){
  1746. $realname = safe_replace(Req::post('realname'));
  1747. $subjects=Req::post('subjects');
  1748. $grade=(int)Req::post('grade');
  1749. //查询学生
  1750. $students=$this->schoolManager->getClassifiedStudentByName($realname,$subjects,$grade,$this->semesterId);
  1751. $result['status']=1;
  1752. $result['data']=$students;
  1753. exit(json_encode($result));
  1754. }
  1755. //添加走班学生
  1756. public function actionAddClassifiedStudent(){
  1757. $classId=Req::post('cid');
  1758. $studentIds=Req::post('student_id');
  1759. $result['status']=0;
  1760. if(!$classId || !$studentIds || !is_array($studentIds)){
  1761. $result['msg']='参数异常';
  1762. exit(json_encode($result));
  1763. }
  1764. $classInfo = $this->schoolManager->getClassInfo($classId);
  1765. if(!$classInfo){
  1766. $result['msg']='未找到班级信息';
  1767. exit(json_encode($result));
  1768. }
  1769. $rs=$this->schoolManager->addClassifiedStudent($studentIds,$classId);
  1770. if($rs==-1){
  1771. $result['msg']='已有走班科目记录,不能重复添加走班记录';
  1772. exit(json_encode($result));
  1773. }elseif($rs){
  1774. $result['status']=1;
  1775. }
  1776. exit(json_encode($result));
  1777. }
  1778. //教学班转班加载学生
  1779. public function actionGetClassifiedStudent(){
  1780. $class_id=Req::post('class_id'); //来源班级
  1781. $subjects=Req::post('subjects');
  1782. $grade=Req::post('grade');
  1783. $semester=Req::post('semester');
  1784. $to_class_id=Req::post('to_class_id'); //目标班级
  1785. //读取目标班级已有学生
  1786. $studentIds=array();
  1787. $studentList=$this->schoolManager->getClassStudents($to_class_id,array(),'ARR');
  1788. if($studentList){
  1789. foreach ($studentList as $val){
  1790. $studentIds[]=$val['student_id'];
  1791. }
  1792. }
  1793. //读取来源班级学生
  1794. $resultStudentList=array();
  1795. $fromStudentList=$this->schoolManager->getClassStudents($class_id,array(),'ARR');
  1796. if($fromStudentList){
  1797. foreach ($fromStudentList as $key => $item){
  1798. if(!inArray($item['student_id'],$studentIds)){
  1799. //查询系统准考证
  1800. $studentInfo=$this->conn->createCommand("select student_card from student where student_id='{$item['student_id']}'")->queryRow();
  1801. if($studentInfo){
  1802. $item['realname']=$item['realname'].'('.$studentInfo['student_card'].')';
  1803. }
  1804. $resultStudentList[]=$item;
  1805. }
  1806. }
  1807. }
  1808. $result['status']=1;
  1809. $result['data']=$resultStudentList;
  1810. exit(json_encode($result));
  1811. }
  1812. //教学班按改名搜索
  1813. public function actionGetClassifiedStudentByName(){
  1814. $classIds=Req::post('classIds'); //来源班级
  1815. $to_class_id=Req::post('to_class_id'); //目标班级
  1816. $realname = safe_replace(Req::post('realname'));
  1817. //读取目标班级已有学生
  1818. $studentIds=array();
  1819. $studentList=$this->schoolManager->getClassStudents($to_class_id,array(),'ARR');
  1820. if($studentList){
  1821. foreach ($studentList as $val){
  1822. $studentIds=$val['student_id'];
  1823. }
  1824. }
  1825. $resultStudentList=$this->schoolManager->searchStudentByClassIdsStudentName($classIds,$realname,$studentIds);
  1826. $resultStudentList=array_values($resultStudentList);
  1827. $result['status']=1;
  1828. $result['data']=$resultStudentList;
  1829. exit(json_encode($result));
  1830. }
  1831. //教学班转班
  1832. public function actionCopyClassified(){
  1833. $to_class_id=Req::post('cid'); //目标班级
  1834. $studentData=Req::post('student_id');
  1835. $result['status']=0;
  1836. if(!$studentData || !$to_class_id){
  1837. $result['msg']='参数异常';
  1838. exit(json_encode($result));
  1839. }
  1840. $classInfo = $this->schoolManager->getClassInfo($to_class_id);
  1841. if(!$classInfo){
  1842. $result['msg']='未找到班级信息';
  1843. exit(json_encode($result));
  1844. }
  1845. //分解学生班级信息
  1846. $classAndStudent=array();
  1847. foreach($studentData as $val){
  1848. $temp=@explode('///',$val);
  1849. if(isset($temp[0]) && isset($temp[1])){
  1850. $classAndStudent[$temp[1]]=$temp[0];
  1851. }
  1852. }
  1853. if($this->schoolManager->copyClassified($to_class_id,$classAndStudent)){
  1854. $result['status']=1;
  1855. exit(json_encode($result));
  1856. }
  1857. exit(json_encode($result));
  1858. }
  1859. // 目标院校管理
  1860. public function actionTarget()
  1861. {
  1862. $page = Req::get('page') ? Req::get('page') : 1;
  1863. $gradeName = Req::get('grade_name');
  1864. $className = Req::get('class_name');
  1865. $studentName = Req::get('student_name');
  1866. $pageLimit=10;
  1867. $userModel=new BusinessStudentTargetUniversity();
  1868. $result = $userModel->getStudentTargetList($this->schoolId,$gradeName,$className,$studentName,$page,$pageLimit);
  1869. return $this->render('target', array(
  1870. 'dataList' => $result['dataList'],
  1871. 'pages' => $result['pages'],
  1872. 'page'=>$page,
  1873. 'gradeName' => $gradeName,
  1874. 'className' => $className,
  1875. 'studentName' => $studentName,
  1876. ));
  1877. }
  1878. //重制学生设备登陆ID
  1879. public function actionAjaxResetLoginId(){
  1880. $error = array();
  1881. $studentId = (string)Req::post('studentId') ? (string)Req::post('studentId') : "";
  1882. if(!$studentId){
  1883. $error[] = "学生ID错误";
  1884. }
  1885. if(!$error){
  1886. // 获取设备号
  1887. // $stu_login_id = Yii::app()->stu_login_permission->getValue('zsy_student:student_app_unique_no:'.$studentId);
  1888. require_once(Yii::app()->basePath . '/extensions/RedisLoginCtrl.php');
  1889. $group_redis_obj = RedisLoginCtrl::getRedisObj($studentId);
  1890. $stu_login_id = $group_redis_obj->hGet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no');
  1891. if ($stu_login_id) {
  1892. foreach (range(0, RedisLoginCtrl::getRedisNum()) as $redisNun) {
  1893. RedisLoginCtrl::getRedisObj($redisNun)->del('zsy_student:device_unique_no:' . $stu_login_id);
  1894. }
  1895. $group_redis_obj->hSet('zsy_student:zxhx_login_info:' . $studentId, 'bind_unique_no', '');
  1896. } else {
  1897. $error[] = "重制失败";
  1898. }
  1899. }
  1900. if($error){
  1901. $result['status'] = 0;
  1902. $result['msg']=implode("<br>",$error);
  1903. }else{
  1904. $result['status'] = 1;
  1905. }
  1906. exit(json_encode($result));exit;
  1907. }
  1908. //英语能力等级管理
  1909. public function actionLevel()
  1910. {
  1911. $page = Req::get('page') ? Req::get('page') : 1;
  1912. $grade = Req::get('grade');
  1913. $classId = Req::get('classId');
  1914. $studentName = Req::get('name');
  1915. $pageLimit=20;
  1916. $userModel=new SStudentInfo();
  1917. $result = $userModel->getStudentLevelList($grade,$classId,$studentName,$this->semesterId, $page,$pageLimit);
  1918. $classes = $grade ? $this->schoolManager->getClasses($grade) : array();
  1919. return $this->render('level', array(
  1920. 'dataList' => $result['dataList'],
  1921. 'pages' => $result['pages'],
  1922. 'page'=>$page,
  1923. 'grade' => $grade,
  1924. 'classId' => $classId,
  1925. 'studentName' => $studentName,
  1926. 'classes' => $classes
  1927. ));
  1928. }
  1929. //手动更新英语人工等级
  1930. public function actionAjaxUpdateLevel(){
  1931. $error = array();
  1932. $studentIds = (array)Req::post('studentIds') ? (array)Req::post('studentIds') : array();
  1933. $type = (int)Req::post('type') ? (int)Req::post('type') : 0;
  1934. $level = (int)Req::post('level') ? (int)Req::post('level') : 0;
  1935. if(!$studentIds){
  1936. $error[] = "学生ID错误";
  1937. }
  1938. if(!$type && !$level){
  1939. $error[] = "参数错误";
  1940. }
  1941. $result['status'] = 0;
  1942. if(!$error){
  1943. $trans = $this->sConn->beginTransaction();
  1944. try {
  1945. $studentIdsStr = implode(',', $studentIds);
  1946. if($level){
  1947. $sql = "update student_info set english_level_artificial={$level} where student_id in ({$studentIdsStr})";
  1948. }else{
  1949. switch ($type){
  1950. case 1:
  1951. $sql = "update student_info set english_level_artificial=if(english_level_one+1>10,10, english_level_one+1) where student_id in ({$studentIdsStr})";
  1952. break;
  1953. case 2:
  1954. $sql = "update student_info set english_level_artificial=if(english_level_one+2>10,10, english_level_one+2) where student_id in ({$studentIdsStr})";
  1955. break;
  1956. case 3:
  1957. $sql = "update student_info set english_level_artificial=if(english_level_one<2, 1, english_level_one-1) where student_id in ({$studentIdsStr})";
  1958. break;
  1959. case 4:
  1960. $sql = "update student_info set english_level_artificial=if(english_level_one<3, 1, english_level_one-2) where student_id in ({$studentIdsStr})";
  1961. break;
  1962. }
  1963. }
  1964. $this->sConn->createCommand($sql)->execute();
  1965. $trans->commit();
  1966. $result['status'] = 1;
  1967. } catch (Exception $e) {
  1968. $trans->rollBack();
  1969. $result['msg'] = '操作失败';
  1970. }
  1971. }
  1972. if($error){
  1973. $result['msg']=implode("<br>",$error);
  1974. }else{
  1975. $result['status'] = 1;
  1976. }
  1977. exit(json_encode($result));exit;
  1978. }
  1979. }