$params['examine_type'], 'temp_name' => $params['temp_name'], 'create_user' => $params['create_user'], 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time() ]); foreach($params['detail'] as &$v){ $v['examine_temp_id'] = $res['id']; $v['create_time'] = time(); } (new OaExamineTempItem)->saveAll($params['detail']); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑考核模板 * @param array $params * @return bool * @author likeadmin * @date 2024/06/03 13:35 */ public static function edit(array $params): bool { Db::startTrans(); try { OaExamineTemp::where('id', $params['id'])->update([ 'examine_type' => $params['examine_type'], 'temp_name' => $params['temp_name'], 'update_time' => time() ]); foreach($params['detail'] as $v){ if(!empty($v['id'])){ OaExamineTempItem::where('id',$v['id'])->update([ 'examine_temp_id' => $params['id'], 'examine_item' => $v['examine_item'], 'score' => $v['score'], 'examine_desc' => $v['examine_desc'], 'update_time' => time(), ]); }else{ OaExamineTempItem::create([ 'examine_temp_id' => $params['id'], 'examine_item' => $v['examine_item'], 'score' => $v['score'], 'examine_desc' => $v['examine_desc'], 'create_time' => time() ]); } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除考核模板 * @param array $params * @return bool * @author likeadmin * @date 2024/06/03 13:35 */ public static function delete(array $params): bool { Db::startTrans(); try { //删除考核模板 OaExamineTemp::destroy($params['id']); //删除考核模板考核项 OaExamineTempItem::destroy(function($query)use($params){ $query->where('examine_temp_id','=',$params['id']); }); //删除关联的自评记录 OaSelfExamine::destroy(function($query)use($params){ $query->where('examine_temp_id','=',$params['id']); }); //删除关联的自评记录的考核项 OaSelfExamineDetail::destroy(function($query)use($params){ $self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id'); $query->where('self_examine_id','in',$self_examine_ids); }); //删除关联的考核记录 OaExamine::destroy(function($query)use($params){ $self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id'); $query->where('self_examine_id','in',$self_examine_ids); }); //删除关联的考核记录的考核项 OaExamineDetail::destroy(function($query)use($params){ $self_examine_ids = OaSelfExamine::where('examine_temp_id','=',$params['id'])->column('id'); $examine_ids = OaExamine::where('self_examine_id','in',$self_examine_ids)->column('id'); $query->where('examine_id','in',$examine_ids); }); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 获取考核模板详情 * @param $params * @return array * @author likeadmin * @date 2024/06/03 13:35 */ public static function detail($params): array { $data = OaExamineTemp::withoutField('update_time,delete_time')->findOrEmpty($params['id']); $data['examine_type_text'] = $data->examine_type_text; $data['total_score'] = OaExamineTempItem::where('examine_temp_id',$params['id'])->sum('score'); $data['detail'] = OaExamineTempItem::field('id,examine_item,score,examine_desc')->where('examine_temp_id',$params['id'])->select()->toArray(); return $data->toArray(); } }