public function getExamineeData($examinee_id) { // 个人胜任力前提 $this->examinee_check($examinee_id); //核心 $result = $this->modelsManager->createBuilder()->columns(array('Index.chs_name as chs_name', 'avg(IndexAns.score) as score'))->from('Examinee')->join('IndexAns', "IndexAns.examinee_id = Examinee.id AND Examinee.id = {$examinee_id} ")->join('Index', 'Index.id = IndexAns.index_id')->groupBy('Index.id')->orderBy('avg(IndexAns.score) desc')->getQuery()->execute(); $result = $result->toArray(); $rt = array(); $result_count = count($result); if ($result_count > 8) { $advantage = array_slice($result, 0, 5); $disadvantage = array_slice($result, -3); $rt['count'] = 8; $rt['advantage']['count'] = 5; $rt['advantage']['value'] = $advantage; $rt['disadvantage']['count'] = 3; $rt['disadvantage']['value'] = $disadvantage; } else { if ($result_count >= 5) { $rt['count'] = $result_count; $advantage = array_slice($result, 0, 5); $rt['advantage']['count'] = 5; $rt['advantage']['value'] = $advantage; $rt['disadvantage']['count'] = $result_count - 5; $disadvantage = array_slice($result, 5, $rt['disadvantage']['count']); $rt['disadvantage']['value'] = $disadvantage; } else { $rt['count'] = $result_count; $advantage = $result; $rt['advantage']['count'] = $result_count; $rt['advantage']['value'] = $advantage; $rt['disadvantage']['count'] = 0; $rt['disadvantage']['value'] = null; } } $sum = 0; foreach ($rt['advantage']['value'] as &$value) { $value['score'] = sprintf("%.1f", $value['score'] * 12); $comment = CompetencyComment::findFirst(array('index_chs_name=?1', 'bind' => array(1 => $value['chs_name'])))->advantage; $comment = json_decode($comment, true); $rand_key = array_rand($comment); $value['comment'] = $comment[$rand_key]; $sum += $value['score']; } foreach ($rt['disadvantage']['value'] as &$value) { $value['score'] = sprintf("%.1f", $value['score'] * 12); $comment = CompetencyComment::findFirst(array('index_chs_name=?1', 'bind' => array(1 => $value['chs_name'])))->disadvantage; $comment = json_decode($comment, true); $rand_key = array_rand($comment); $value['comment'] = $comment[$rand_key]; $sum += $value['score']; } //disadvantage 顺序排序 $rt['disadvantage']['value'] = array_reverse($rt['disadvantage']['value']); $number = $rt['count']; $rt['value'] = sprintf('%.1f', $sum / $number); return $rt; }
public static function insertCompetency($data) { try { $manager = new TxManager(); $transaction = $manager->get(); foreach ($data as $value) { $competencycomment = new CompetencyComment(); $competencycomment->setTransaction($transaction); foreach ($value as $skey => $svalue) { $competencycomment->{$skey} = $svalue; } if ($competencycomment->save() == false) { $transaction->rollback('数据更新失败-3'); } } $transaction->commit(); return true; } catch (TxFailed $e) { throw new Exception($e->getMessage()); } }