$params['project_id'], 'node_name' => $params['node_name'], 'node_type' => $params['node_type'], 'node_code' => $params['node_code'], 'pid' => $params['pid'], 'inspection_basis' => $params['inspection_basis'], 'reference_law' => $params['reference_law'], ]); if(!empty($params['check_item_detail'])){ foreach($params['check_item_detail'] as $v){ SupervisionCheckItemDetail::create([ 'node_id' => $res->id, 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], ]); } } 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/02/26 15:34 */ public static function edit(array $params): bool { Db::startTrans(); try { SupervisionCheckItem::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'node_name' => $params['node_name'], 'node_type' => $params['node_type'], 'node_code' => $params['node_code'], 'pid' => $params['pid'], 'inspection_basis' => $params['inspection_basis'], 'reference_law' => $params['reference_law'], 'update_time' => time(), ]); if(!empty($params['check_item_detail'])){ foreach($params['check_item_detail'] as $v){ if(!empty($v['id'])){ SupervisionCheckItemDetail::where('id',$v['id'])->update([ 'node_id' => $params['id'], 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], 'update_time' => time(), ]); }else{ SupervisionCheckItemDetail::create([ 'node_id' => $params['id'], 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], ]); } } } 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/02/26 15:34 */ public static function delete(array $params): bool { $data = SupervisionCheckItem::where('pid',$params['id'])->findOrEmpty(); if(!$data->isEmpty()){ self::setError('当前节点下存在子节点,请先删除子节点'); return false; } return SupervisionCheckItem::destroy($params['id']); } /** * @notes 获取工程监理--新增检查项详情 * @param $params * @return array * @author likeadmin * @date 2024/02/26 15:34 */ public static function detail($params): array { $data = SupervisionCheckItem::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']); $project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); $pid = SupervisionCheckItem::field('node_name')->where('id',$data['pid'])->findOrEmpty(); $data['project_name'] = $project['project_name']; $data['p_node_name'] = $pid['node_name']; $data['node_type_text'] = $data->node_type_text; return $data->toArray(); } }