first(); if(!$approvalFlow) { return dataReturn(-1, '请先创建审批流程'); } $flowPath = $approvalFlow->flow_path; $ainfo = SecurityCosts::find($fid); if(!$ainfo) { return dataReturn(-1, '获取安全费用信息失败'); } if($ainfo->approval_flow_line_id) { return dataReturn(-1, '无需重复提交'); } $applicantOrg = $ainfo->projectOrg; $title = $applicantOrg->name.'安全费用'; $url = "/admin/guarantee/securityCosts/flowLineshow/".$ainfo->id; $builder = new ApprovalFlowBuilder($applicantOrg, $approvalFlow); $builder->setTitle($title); $builder->setSummary("{$applicantOrg->name}安全费用"); $builder->setContentUrl($url); // foreach ($flowPath as $path) { // $builder->addNodeNew($path,$ainfo->project_org_id,$ainfo->company_org_id); // } $roleIds = array_column($flowPath, 'roleid'); $roles = AdminRole::findMany($roleIds); foreach ($roles as $role) { $builder->addNode($role); } Db::beginTransaction(); try { $line = $builder->build(); $open_url = 'https://anquansys.sxlq.com:37100/admin/approval/approval/linenodeShow?id='.$ainfo->id.'&flid='.$line->id; $line->update(['open_url'=>$open_url]); $ainfo->update([ 'approval_flow_line_id' => $line->id, 'updatetime' => now() ]); DB::commit(); } catch (\Exception $e) { Db::rollBack(); // 回滚事务 throw $e; } return dataReturn(0, '提交成功'); } public function approvalCancel($fid) { $ainfo = SecurityCosts::find($fid); $approvalFlowLine = $ainfo->approvalFlowLine; $approvalFlowLineNode = new ApprovalFlowLineNode(); $nodes = $approvalFlowLineNode->getAllList(['approval_flow_line_id'=>$ainfo->approval_flow_line_id]); $approvalFlowLine->nodes()->delete(); $approvalFlowLine->delete(); $ainfo->update([ 'approval_flow_line_id' => 0, 'updatetime' => now() ]); return dataReturn(0, '撤销成功'); } public function flowshow($approval_flow_line_id) { $res = ApprovalFlowLine::with('nodes.approvalRole', 'nodes.approvalActualUser')->find($approval_flow_line_id); return dataReturn(0, 'success',$res); } public function flowLineshow($id) { $info = SecurityCosts::find($id); $company = AdminOrg::find($info->company_org_id); $company_title='山西路桥集团'.$company->name; $info->company = $company_title; $info->title='安全设施用品采购策划报备表'; $approvalFlowLineNode = new ApprovalFlowLineNode(); $node_group = $approvalFlowLineNode->select('flow_line_node_role_id')->where('approval_flow_line_id',$info['approval_flow_line_id'])->orderBy('id','asc')->get(); $role_ids=[]; foreach($node_group as $k=>&$item) { if(in_array($item['flow_line_node_role_id'],$role_ids)){ continue; } $role_ids[]=$item['flow_line_node_role_id']; $item['role_info'] = AdminRole::find($item['flow_line_node_role_id']); $item['list'] = $approvalFlowLineNode->getAllList(['approval_flow_line_id'=>$info->approval_flow_line_id,'flow_line_node_role_id'=>$item['flow_line_node_role_id']],['*'],[],['approvalActualUser']); } $info->node = $node_group; $info->files = json_decode($info->files,true); return dataReturn(0, 'success',$info); } /** * 列表 * @param $param * @return array */ public function getList($param) { $limit = $param['limit']; $name = $param['name']; $where = []; if (!empty($name)) { $where[] = ['name', 'like', '%' . $name . '%']; } $where[] = ['org_id','in',getOrgSelfAndChildrenIdsById(get_current_org_id())]; $securityCostsModel = new SecurityCosts(); $list = $securityCostsModel->getPaginateList($where, ['*'], ['id' => 'asc'], ['approvalFlowLine'], $limit); foreach($list['data'] as &$item) { $item['files'] = json_decode($item['files'],true); } return dataReturn(0, 'success', $list); } /** * 获取清单树状图 */ public function getTree($id,$name=''){ $feeList = new FeeList(); $standradService = new StandardListService(); $standardList = new StandardList(); $id=0; if($name) { $searchWhere = []; $searchWhere[] = ['name','like','%'.$name.'%']; $standInfo = $standardList->getInfoByWhere($searchWhere); if($standInfo) { $id = $standInfo['id']; } } $tree = $standradService->getAllList($id); $choose_list = $feeList->getAllList(['fid'=>$id],['sid']); $chooseIds = array_column($choose_list,'sid'); return dataReturn(0, 'success', ['tree'=>$tree,'chooseIds'=>$chooseIds]); } public function addFeeList($id,$data){ $feeList = new FeeList(); $standardListModel = new StandardList(); $insertData=[]; foreach($data as $k=>$v){ $ary = explode('&',$v); if(count($ary)<3){ throw new ApiException('操作失败,请联系管理员', -1); } $standradInfo = $standardListModel->getInfoById($ary[0]); if(!$standradInfo) { throw new ApiException('获取标准清单信息失败,请联系管理员', -1); } $aryData=[]; $aryData['fid'] = $id; $aryData['sid'] = $standradInfo['id']; $aryData['parent'] = $standradInfo['parent']; $aryData['pid'] = $standradInfo['pid']; $aryData['code'] = $standradInfo['code']; $aryData['name'] = $standradInfo['name']; $aryData['unit'] = $standradInfo['unit']; $aryData['specs'] = $standradInfo['specs']; if($standradInfo['price']>0){ $aryData['price'] = $ary[2]>=$standradInfo['price']?$standradInfo['price']:$ary[2]; $aryData['changePrice']=0; $item['maxPrice'] = $standradInfo['price']; }else{ $aryData['price'] = $ary[2]; $aryData['changePrice']=1; } $aryData['num'] = $ary[1]; $aryData['total'] = bcmul((string)$aryData['num'],(string)$aryData['price'],2); $insertData[]=$aryData; } $feeList->delByWhere(['fid'=>$id]); $feeList->insertBatch($insertData); return dataReturn(0, '操作成功'); } public function export($id){ $feeList = new FeeList(); $standardListModel = new StandardList(); $list = $feeList->getAllList(['fid'=>$id]); $total_price = $feeList->query()->where('fid',$id)->sum('total'); $ids=[]; $res=[]; $key=0; foreach($list as &$item){ $parent = trim($item['parent'],'[]'); $parent_ary = explode(',',$parent); $parent_count = count($parent_ary); foreach($parent_ary as $k=>$v){ if(!in_array($v,$ids)){ $ids[]=$v; $info = $standardListModel->getInfoById($v); if($key == 0 && $k==0) { $info['total_price'] = $total_price; $info['rate'] ='100%'; }else{ if($k+1==$parent_count){ $info_total_price = $feeList->query()->where('fid',$id)->where('pid',$v)->sum('total'); }else{ $info_total = Db::select("select sum(total) as total_price from sp_module_guarantee_fee_list where fid=".$id." and FIND_IN_SET(".$v.",parent)>0"); $info_total_price = $info_total[0]->total_price; } $info['total_price'] = $info_total_price; $info['rate'] =bcmul(bcdiv((string)$info_total_price,$total_price,4),'100',2).'%'; } $res[]=$info; } } $key++; $item['total_price'] = $item['total']; $item['rate'] = bcmul(bcdiv((string)$item['total'],$total_price,4),'100',2).'%'; $res[]=$item; } $info = SecurityCosts::find($id); $exportName = $info->project_org_name ."安全费用"; $exportField = ['序号','章次','费用类别','策划金额','策划比例']; $path = $this->excelExport($exportName,$exportField,$res,$info->project_org_name,$info->company_org_name); return $path; } private function excelExport($title="",$headArr = [], $data = [],$project_org_name='',$company_org_name='') { $spreadsheet = new Spreadsheet(); $objPHPExcel = $spreadsheet->getActiveSheet(); $objPHPExcel->setTitle($title); $objPHPExcel->setCellValueByColumnAndRow(1, 1, $title); // 设置表头 $key = ord("A"); $objPHPExcel->mergeCells('A1:E1'); $objPHPExcel->setCellValue('A1', '公路工程安全生产费汇总表'); $styleArray = [ 'alignment' => [ 'horizontal' => Alignment::HORIZONTAL_CENTER, //水平居中 'vertical' => Alignment::VERTICAL_CENTER, //垂直居中 ], ]; $objPHPExcel->mergeCells('A2:B2'); $objPHPExcel->mergeCells('C2:E2'); $objPHPExcel->setCellValue('A2', '实施单位: '.$project_org_name); $objPHPExcel->setCellValue('C2', '项目部: '.$company_org_name); $objPHPExcel->getStyle('A1')->applyFromArray($styleArray); $objPHPExcel->getDefaultColumnDimension()->setWidth(16); $objPHPExcel->getRowDimension('1')->setRowHeight(30); $objPHPExcel->getColumnDimension('A')->setWidth(15); $objPHPExcel->getColumnDimension('B')->setWidth(15); $objPHPExcel->getColumnDimension('C')->setWidth(30); $objPHPExcel->getColumnDimension('D')->setWidth(15); $objPHPExcel->getColumnDimension('E')->setWidth(15); $objPHPExcel->getStyle('A1')->getFont()->setBold(true)->setName('黑体')->setSize(16); foreach ($headArr as $v) { $colum = chr($key); $objPHPExcel->setCellValue($colum . '3', $v); $objPHPExcel->getStyle($colum . '3')->applyFromArray($styleArray)->getFill() ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) ->getStartColor() ->setARGB('aaaaaa'); $key += 1; } $column = 4; foreach ($data as $key => $row) { // 行写入 $objPHPExcel->setCellValue('A'.$column, $key+1); $objPHPExcel->setCellValue('B'.$column, $row['code']); $objPHPExcel->setCellValue('C'.$column, $row['name']); $objPHPExcel->setCellValue('D'.$column, $row['total_price']); $objPHPExcel->setCellValue('E'.$column, $row['rate']); $column++; } $objPHPExcel->getStyle('A3:'.'E'.$column)->applyFromArray($styleArray); $writer = new Xlsx($spreadsheet); $path = public_path().'/excel/'.$title.'.xlsx'; $path2 = '/excel/'.$title.'.xlsx'; $writer->save($path); // $url = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $url = "https://" . request()->host().':37100'; $res['url'] = $url.$path2; $res['name'] = $title; //删除临时的sheet $spreadsheet->disconnectWorksheets(); unset($spreadsheet); return $res; } public function getFeeStatistics($id){ $feeList = new FeeList(); $standardListModel = new StandardList(); // $list = $feeList->select('parent')->where('fid',$id)->orderBy('id','asc')->groupBy('parent')->get(); $list = $feeList->getAllList(['fid'=>$id]); $total_price = $feeList->query()->where('fid',$id)->sum('total'); $ids=[]; $res=[]; foreach($list as $key=>$item){ $parent = trim($item['parent'],'[]'); $parent_ary = explode(',',$parent); $parent_count = count($parent_ary); foreach($parent_ary as $k=>$v){ if($k>=2) { continue; } if(!in_array($v,$ids)){ $ids[]=$v; $info = $standardListModel->getInfoById($v); if($key == 0 && $k==0) { $info['total_price'] = $total_price; $info['rate'] ='100%'; }else{ if($k+1==$parent_count){ $info_total_price = $feeList->query()->where('fid',$id)->where('pid',$v)->sum('total'); }else{ $info_total = Db::select("select sum(total) as total_price from sp_module_guarantee_fee_list where fid=".$id." and FIND_IN_SET(".$v.",parent)>0"); $info_total_price = $info_total[0]->total_price; } $info['total_price'] = $info_total_price; $info['rate'] =bcmul(bcdiv((string)$info_total_price,$total_price,4),'100',2).'%'; } $res[]=$info; } } } return $res; } public function getFeeList($id){ $feeList = new FeeList(); $list = $feeList->getAllList(['fid'=>$id],['sid as id','parent','pid','code','name','unit','specs','num','price','changePrice','total','maxPrice']); $newList=[]; $ids=[]; foreach($list as $item){ if($item['pid'] && !in_array($item['pid'],$ids)){ $pid_list=$this->getPidInfo($item['pid'],$ids); $pids = array_column($pid_list,'id'); $ids = array_merge($ids,$pids); $newList = array_merge($newList,$pid_list); } $newList[]=$item; $ids[]=$item['id']; } return $newList; } public function getTableForm($id,$data) { $feeList = new FeeList(); $standardListModel = new StandardList(); $choosed_list = $feeList->getAllList(['fid'=>$id],['sid']); $choose_ary = array_column($choosed_list,'sid'); $list=[]; $ids=[]; foreach($data as $k=>$v){ $ary = explode('&',$v); if(count($ary)<2){ throw new ApiException('获取失败,请联系管理员', -1); } if($ary[0] && !in_array($ary[0],$ids)){ $pid_list=$this->getPidInfo($ary[0],$ids); $pids = array_column($pid_list,'id'); $ids = array_merge($ids,$pids); $list = array_merge($list,$pid_list); } $list[]=$standardListModel->getInfoById($ary[1]); $ids[]=$ary[1]; } foreach($list as &$item){ $item['num'] = 0; if($item['price']>0) { $item['changePrice'] = 0; $item['maxPrice'] = $item['price']; }else{ $item['changePrice'] = 1; } if(in_array($item['id'],$choose_ary)) { $choose_info = $feeList->getInfoByWhere(['fid'=>$id,'sid'=>$item['id']],['num','price']); $item['num'] = $choose_info['num']; $item['price'] = $choose_info['price']; } } return $list; } public function getPidInfo($id,$ids){ $new_data=[]; $standardListModel = new StandardList(); $info = $standardListModel->getInfoById($id); if($info['pid'] && !in_array($info['pid'],$ids)){ $new_data = $this->getPidInfo($info['pid'],$ids); $info['total']=0; $new_data[]=$info; return $new_data; } $info['total']=0; $new_data[]=$info; return $new_data; } /** * 添加 * @param $param */ public function store($param) { $securityCostsModel = new SecurityCosts(); if(isset($param['files'])) { $param['files'] = \json_encode($param['files']); } $org_info = get_current_org_info(); if($org_info['level'] == 2) { $param['company_org_id'] = $org_info['id']; $param['company_org_name'] = $org_info['name']; $param['company_org_deptcode'] = $org_info['deptcode']; }elseif($org_info['level'] == 3) { $param['project_org_id'] = $org_info['id']; $param['project_org_name'] = $org_info['name']; $param['project_org_deptcode'] = $org_info['deptcode']; if($org_info['pid']) { $company_org = getOrg($org_info['pid']); $param['company_org_id'] = $company_org['id']; $param['company_org_name'] = $company_org['name']; $param['company_org_deptcode'] = $company_org['deptcode']; } } $param['org_id'] = $org_info['id']; $param['org_name'] = $org_info['name']; $param['org_deptcode'] = $org_info['deptcode']; $securityCostsModel->insertOne($param); return dataReturn(0, '添加成功'); } /** * 编辑 * @param $param * @return array|\think\response\Json */ public function update($param) { $securityCostsModel = new SecurityCosts(); if(isset($param['files'])) { $param['files'] = \json_encode($param['files']); } $securityCostsModel->updateById($param, $param['id']); return dataReturn(0, '编辑成功'); } public function destroy($id){ $securityCostsModel = new SecurityCosts(); $feeList = new FeeList(); $feeList->delByWhere(['fid'=>$id]); $securityCostsModel->delById($id); return dataReturn(0, '删除成功'); } }