/** * 额外材料提交处理. * * @access public * @return void * @author Liuping <*****@*****.**> */ public function extraFilesAction() { $extraId = intval(I('post.extraStatus', '')); // 额外材料主键ID if (empty($extraId)) { $this->error('Invalid parameters'); } // 实例化额外信息 $modelExtra = M('member_upload_extra'); $extraInfo = $modelExtra->find($extraId); if (NULL === $extraInfo || FALSE === $extraInfo) { $this->error('Invalid parameters'); } $stuId = $extraInfo['s_id']; // 学生 id $ano = $extraInfo['a_no']; // 申请编号 $postExtraDetail = I('post.detail', ''); if (empty($postExtraDetail)) { $this->error('Please provide valid files'); } // 去掉为空的数据 $data = []; $_detailSrcs = isset($postExtraDetail['src']) ? $postExtraDetail['src'] : []; $_detailIds = isset($postExtraDetail['id']) ? $postExtraDetail['id'] : []; foreach ($_detailSrcs as $k => $v) { if (!empty($v)) { $data[] = ['id' => $_detailIds[$k], 'src' => $v]; } } if (empty($data)) { $this->error('Please provide valid files'); } $uid = session('uid'); // 组装数据 foreach ($data as &$row) { $row['fid'] = $extraId; $row['uid'] = $uid; $row['a_no'] = $ano; $_id = $row['id']; if (empty($_id)) { $row['reason'] = ''; $row['create_time'] = date('Y-m-d H:i:s', time()); $row['update_time'] = date('Y-m-d H:i:s', time()); $row['is_del'] = 0; } else { $row['update_time'] = date('Y-m-d H:i:s', time()); } } unset($row); $allowExtraNum = 5; // 同一个申请额外材料允许的最多条数 $data = array_slice($data, 0, $allowExtraNum); $modelExtra->startTrans(); // 开启事务 $res = $this->procExtraDetailInfo($data); // 更新状态为已完成上传 $res1 = $modelExtra->where('id=:id')->bind(':id', $extraId)->save(['is_complete' => 1]); if (FALSE !== $res1) { $res1 = TRUE; } // 写入日志 $modelStu = new MemberStuModel(); $aoInfo = $modelStu->fetchAoInfo($stuId); // 获取AO信息 $modelAppStatus = new ApplyStatusModel(); // 获取申请信息 $appStatusInfo = $modelAppStatus->where('s_no=:sno AND a_no=:ano')->bind([':sno' => $stuId, ':ano' => $ano])->find(); $strFullName = ''; if (!empty($appStatusInfo)) { $strFullName = $appStatusInfo['first_name'] . ' ' . $appStatusInfo['family_name']; } $res2 = TRUE; $res3 = TRUE; $_cont = '用户提交了额外材料'; $_cont1 = 'Your extra files have been received, application status changes to "Assessing by university"'; if (!empty($aoInfo) && !empty($appStatusInfo)) { $res2 = $modelStu->writeLog($aoInfo['ao_uid'], $appStatusInfo['uid'], $ano, 1, date('Y-m-d H:i:s') . ', ' . $_cont); $res3 = $modelStu->writeApplyLog($aoInfo['ao_uid'], $appStatusInfo['uid'], $ano, 1, $_cont1); } // 更新额外材料标志位 $res4 = $modelAppStatus->switchExtraFilesStatus($appStatusInfo['id'], 2); $res5 = $modelAppStatus->switchApplyStatus($appStatusInfo['id'], 5); // 评估中 if ($res && $res1 && $res2 && $res3 && $res4 && $res5) { $modelExtra->commit(); // 提交事务 // 都成功, 给 AO 发送邮件 if (!empty($aoInfo) && !empty($appStatusInfo)) { $resubmitTime = date('Y-m-d H:i:s', time()); $emailTitle = $strFullName . ' ' . $_cont; $emailContent = <<<MAIL 学生姓名: {$strFullName}. 提交时间: {$resubmitTime}. 描述: {$_cont}. MAIL; // 发送邮件 MemberStuModel::sendEmail($aoInfo['ao_user_email'], $emailTitle, $emailContent); } $this->success('Successful!', U('studentDetail', ['id' => $stuId])); } else { $modelExtra->rollback(); $this->error('Action failed'); } }
/** * @上传额外材料操作 * @Author: 段涛 * @function name: extraFilesAction */ public function extraFilesAction() { $ano = I('get.ano'); if (empty($ano)) { $this->error(L('MSG_VALIDATE18'), U('/Home/index')); } $data = I('post.'); if ($data['detail']['src'][0] == '') { $this->error('Please upload at least one file.'); } $model1 = M('member_upload_extra'); $model1->startTrans(); $model2 = M('member_upload_extra_deputy'); $model2->startTrans(); $status = 1; // $isComplete=$model1->where(array('a_no'=>$ano))->getField('is_complete'); // if($isComplete==1){ // $this->error('对不起,您已经提交过了,切勿重复提交!'); // } foreach ($data['detail']['id'] as $k => $rs) { if (empty($data['detail']['src'][$k])) { //如果为空,则删除 $result = $model2->where(array('id' => $rs))->delete(); if ($result === false) { $status = 0; } } elseif (!empty($data['detail']['src'][$k]) && empty($rs)) { //链接不为空,和数据ID为空,则为添加 $data['fid'] = $data['extraStatus']; $data['uid'] = session('uid'); $data['a_no'] = $ano; $data['src'] = $data['detail']['src'][$k]; $data['create_time'] = date("Y-m-d H:i:s", strtotime(time())); $data['name'] = '学生'; $result = $model2->add($data); if ($result === false) { $status = 0; } } else { //不为空则为添加 $result = $model2->save(array('id' => $rs, 'src' => $data['detail']['src'][$k])); if ($result === false) { $status = 0; } } } //更新额外材料主附表 $result2 = $model1->save(array('id' => $data['extraStatus'], 'is_complete' => 1, 'updata_time' => time())); // 写入日志 $stuId = M('member_stu')->where(array('uid' => session('uid')))->getField('id'); if ($stuId == "") { $model2->rollback(); $model1->rollback(); $this->error(L('data error')); } $modelStu = new MemberStuModel(); $aoInfo = $modelStu->fetchAoInfo($stuId); // 获取AO信息 $modelAppStatus = new ApplyStatusModel(); // 获取申请信息 $appStatusInfo = $modelAppStatus->where('s_no=:sno AND a_no=:ano')->bind([':sno' => $stuId, ':ano' => $ano])->find(); $strFullName = ''; if (!empty($appStatusInfo)) { $strFullName = $appStatusInfo['first_name'] . ' ' . $appStatusInfo['family_name']; } $res2 = TRUE; $res3 = TRUE; $_cont = '用户提交了额外材料'; $_cont1 = 'Your extra files have been received, application status changes to "Assessing by university"'; if (!empty($aoInfo) && !empty($appStatusInfo)) { $res2 = $modelStu->writeLog($aoInfo['ao_uid'], $appStatusInfo['uid'], $ano, 1, date('Y-m-d H:i:s') . ', ' . $_cont); $res3 = $modelStu->writeApplyLog($aoInfo['ao_uid'], $appStatusInfo['uid'], $ano, 1, $_cont1); } // 更新额外材料标志位 $res4 = $modelAppStatus->switchExtraFilesStatus($appStatusInfo['id'], 2); $res5 = $modelAppStatus->switchApplyStatus($appStatusInfo['id'], 5); // 评估中 if ($status && $result2 && $res2 && $res3 && $res4 && $res5) { $model2->commit(); $model1->commit(); // 都成功, 给 AO 发送邮件 if (!empty($aoInfo) && !empty($appStatusInfo)) { $resubmitTime = date('Y-m-d H:i:s', time()); $emailTitle = $strFullName . ' ' . $_cont; $emailContent = <<<MAIL 学生姓名: {$strFullName}. 提交时间: {$resubmitTime}. 描述: {$_cont}. MAIL; // 发送邮件 MemberStuModel::sendEmail($aoInfo['ao_user_email'], $emailTitle, $emailContent); //给学生发邮件 $this->sentMailToUser($ano); } $this->success(L('MSG_VALIDATE22'), U('Home/Member/index')); } else { $model2->rollback(); $model1->rollback(); $this->error(L('MSG_VALIDATE23')); } }