$params['project_id'], 'side_station_code' => data_unique_code('PZ'), 'side_station_type' => $params['side_station_type'], 'check_item_id' => $params['check_item_id'], 'position' => $params['position'], 'company_id' => $params['company_id'], 'start_time' => !empty($params['start_time']) ? strtotime($params['start_time']) : 0, 'end_time' => !empty($params['end_time']) ? strtotime($params['end_time']) : 0, 'workers' => $params['workers'], 'managers' => $params['managers'], 'situation' => $params['situation'], 'side_station_result' => $params['side_station_result'], 'side_station_user' => $params['side_station_user'], 'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null, 'annex' => $params['annex'] ? json_encode($params['annex']) : null, 'create_user' => $admin_id ]); if(!empty($params['side_result'])){ foreach($params['side_result'] as $v){ SupervisionSideStationResult::create([ 'side_station_id' => $res->id, 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], 'check_result' => $v['check_result'] ]); } } if(!empty($params['side_problem'])){ foreach($params['side_problem'] as $v){ SupervisionSideStationProblem::create([ 'side_station_id' => $res->id, 'problem_cate' => $v['problem_cate'], 'problem_description' => $v['problem_description'], 'problem_name' => $v['problem_name'], ]); } } 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/27 13:58 */ public static function edit(array $params): bool { Db::startTrans(); try { SupervisionSideStation::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'side_station_type' => $params['side_station_type'], 'check_item_id' => $params['check_item_id'], 'position' => $params['position'], 'company_id' => $params['company_id'], 'start_time' => !empty($params['start_time']) ? strtotime($params['start_time']) : 0, 'end_time' => !empty($params['end_time']) ? strtotime($params['end_time']) : 0, 'workers' => $params['workers'], 'managers' => $params['managers'], 'situation' => $params['situation'], 'side_station_result' => $params['side_station_result'], 'side_station_user' => $params['side_station_user'], 'check_item_detail_ids' => $params['check_item_detail_ids'] ? json_encode($params['check_item_detail_ids']) : null, 'annex' => $params['annex'] ? json_encode($params['annex']) : null, 'update_time' => time(), ]); if(!empty($params['side_result'])){ foreach($params['side_result'] as $v){ if(!empty($v['id'])){ SupervisionSideStationResult::where('id',$v['id'])->update([ 'side_station_id' => $params['id'], 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], 'check_result' => $v['check_result'], 'update_time' => time(), ]); }else{ SupervisionSideStationResult::create([ 'side_station_id' => $params['id'], 'check_type' => $v['check_type'], 'check_content' => $v['check_content'], 'must_check' => $v['must_check'], 'check_result' => $v['check_result'] ]); } } } if(!empty($params['side_problem'])){ foreach($params['side_problem'] as $v){ if(!empty($v['id'])){ SupervisionSideStationProblem::where('id',$v['id'])->update([ 'side_station_id' => $params['id'], 'problem_cate' => $v['problem_cate'], 'problem_description' => $v['problem_description'], 'problem_name' => $v['problem_name'], 'update_time' => time(), ]); }else{ SupervisionSideStationProblem::create([ 'side_station_id' => $params['id'], 'problem_cate' => $v['problem_cate'], 'problem_description' => $v['problem_description'], 'problem_name' => $v['problem_name'], ]); } } } 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/27 13:58 */ public static function delete(array $params): bool { $side_station_result = SupervisionSideStationResult::where('side_station_id',$params['id'])->findOrEmpty(); if(!$side_station_result->isEmpty()){ self::setError('该旁站内容下存在旁站结果数据,请先删除旁站结果数据'); return false; } $side_station_problem = SupervisionSideStationProblem::where('side_station_id',$params['id'])->findOrEmpty(); if(!$side_station_problem->isEmpty()){ self::setError('该旁站内容下存在旁站问题数据,请先删除旁站问题数据'); return false; } return SupervisionSideStation::destroy($params['id']); } /** * @notes 获取工程监理--旁站登记详情 * @param $params * @return array * @author likeadmin * @date 2024/02/27 13:58 */ public static function detail($params): array { $data = SupervisionSideStation::withoutField('update_time,delete_time')->findOrEmpty($params['id']); $project = SupervisionProject::field('project_name')->where('id',$data['project_id'])->findOrEmpty(); $check_item = SupervisionCheckItem::field('node_name')->where('id',$data['check_item_id'])->findOrEmpty(); $company = SupervisionParticipatingUnits::field('unit_name')->where('id',$data['company_id'])->findOrEmpty(); $check_item_detail = SupervisionCheckItem::where('id','in',$data['check_item_detail_ids'])->column('node_name'); $create_user = Admin::field('name')->where('id',$data['create_user'])->findOrEmpty(); $data['project_name'] = $project['project_name']; $data['check_item_name'] = $check_item['node_name']; $data['company_name'] = $company['unit_name']; $data['check_item_detail_name'] = implode(',',$check_item_detail); $data['create_user_name'] = $create_user['name']; $data['side_station_type_text'] = $data->side_station_type_text; $data['side_station_result_text'] = $data->side_station_result_text; return $data->toArray(); } }