public function updateClassDetailStudentRela($classId, $classDetailId, $cameRelaIds = "", $notCameRelaIds = "") { try { $tId = session('instId'); $cameRelaIdsArr = array(); if ($cameRelaIds != "" && $cameRelaIds != null) { $cameRelaIdsArr = explode('|', $cameRelaIds); } $notCameRelaIdsArr = array(); if ($notCameRelaIds != "" && $notCameRelaIds != null) { $notCameRelaIdsArr = explode('|', $notCameRelaIds); } $class = new \Home\Model\ClassModel(); $student = new \Home\Model\StudentModel(); $class->startTrans(); //get tuition deduct mode $deductFlag = $class->getClassDeductFlag($classId, $tId); $deductFlag = $deductFlag[0]['deduct_flag']; //get all students tuition_per_class $studentTuitions = $class->showAllStudentsFromClassDetail($classDetailId, $tId); for ($i = 0; $i < count($studentTuitions); $i++) { $st = $studentTuitions[$i]; $studentTuitionMap[$st['id']] = $st['tuition_per_class']; } $count = 0; if (count($cameRelaIdsArr) > 0) { for ($i = 0; $i < count($cameRelaIdsArr); $i++) { $result = $class->updateClassDetailStudentRela($cameRelaIdsArr[$i], 0, $tId); $student->updateStudentBalance((int) $studentTuitionMap[$cameRelaIdsArr[$i]], $cameRelaIdsArr[$i], $tId); if ($result != 1) { $count++; } } } if (count($notCameRelaIdsArr) > 0) { for ($i = 0; $i < count($notCameRelaIdsArr); $i++) { $result = $class->updateClassDetailStudentRela($notCameRelaIdsArr[$i], 1, $tId); if ($deductFlag == 1) { $student->updateStudentBalance((int) $studentTuitionMap[$notCameRelaIdsArr[$i]], $notCameRelaIdsArr[$i], $tId); } if ($result != 1) { $count++; } } } //update status $isAbsentCheck = 1; $class = new \Home\Model\ClassModel(); $result = $class->updateClassDetailIsAbsentCheck($classDetailId, $tId, $isAbsentCheck); $class->commit(); $data = "true"; } catch (Exception $e) { $class->rollback(); $data = "false"; } $this->ajaxReturn($data); }