/** * 导入被试信息列表 */ public static function insertExaminee($data, $project_id, $type = 0) { //对原有数据进行整理 $examinee = Examinee::find(array('project_id = :project_id:', "order" => "number desc", 'bind' => array('project_id' => $project_id))); $new_count = count($data); //1501 0001 $already_number = 0; if (count($examinee) == 0) { $already_number = 0; } else { $already_number = $examinee[0]->number - $project_id * 10000; } #异常 if ($new_count + $already_number > 9999) { throw new Exception('项目人数超限-9999'); } $start = $project_id * 10000 + $already_number + 1; try { $manager = new TxManager(); $transaction = $manager->get(); foreach ($data as $value) { $examinee = new Examinee(); $examinee->setTransaction($transaction); $examinee->project_id = $project_id; $examinee->state = 0; $examinee->number = $start++; foreach ($value as $skey => $svalue) { $examinee->{$skey} = $svalue; } $examinee->password = self::getRandString(); $examinee->type = $type; if ($examinee->save() == false) { $transaction->rollback("数据插入失败"); } } $transaction->commit(); return true; } catch (TxFailed $e) { throw new Exception($e->getMessage()); } }