Commit 1ab962f8 by cwy

0406

parent 1d2238a7
......@@ -90,13 +90,14 @@ class ExcelFile extends BaseController
foreach ($drawings as $index=>$drawing) {
// 图片类型:JPEG, PNG, GIF
$imageType = $drawing->getExtension();
$imageName = 'image_' . $index . '.' . $imageType;
$imageName = 'image_' . time().$index. '.' . $imageType;
$imagePath = 'images/' . $imageName;
$savePath = config("config.resource_address").'public/storage/images/'.$imageName;
// 保存图片到本地
$drawing->getPath() ?
Filesystem::put($imagePath, file_get_contents($drawing->getPath())) :
$drawing->save($imagePath);
array_push($imgList,$imagePath);
array_push($imgList,$savePath);
}
$data = $objWorksheet->toArray();
$list = []; // 所以表格格式化数据
......@@ -263,13 +264,196 @@ class ExcelFile extends BaseController
}
}
/**
* 文件导入
* @return \josn|void
*/
public function importFile()
{
try{
$task_id = input('task_id');
$normInfo = [];
$normInfo['task_id'] = input('task_id');
$normInfo['name'] = input('name');
$normInfo['level'] = input('level');
$normInfo['refer'] = input('refer');
$normInfo['price'] = input('price');
$normInfo['guide'] = input('guide');
$normInfo['sort'] = input('sort');
$normInfo['type'] = input('type');
$norm_id = Db::name('norm')->insertGetId($normInfo);
$file = request()->file('file');
// 上传到本地服务器
$savename = \think\facade\Filesystem::putFile( 'import', $file);
$res = $this->importFormat('storage/'.$savename);
$taskInfo = Db::name('task_package')->where('id',$task_id)->find();
$normInfo = Db::name('norm')->where('id',$norm_id)->find();
if(empty($taskInfo)){
$res['message'] = '获取不到任务信息';
return returnResult(config("config.code.error"),$res['message']);
}
if(empty($normInfo)){
$res['message'] = '获取不到子任务信息';
return returnResult(config("config.code.error"),$res['message']);
}
// 格式化信息错误
if($res['status']==0){
return returnResult(config("config.code.error"),$res['message']);
}
if(empty($res['data'])){
$res['message'] = '表格内容为空';
return returnResult(config("config.code.error"),$res['message']);
}
// 开启数据库事务
Db::startTrans();
$user_id = 1; //用户ID
$normExtendSql = []; // 指标自定义
// 展时端自定义
$extendName = [];
$extendValue =[];
// 用户端自定义
$extendUserName= [];
$extendUserValue =[];
foreach ($res['data'] as $value){
// 展示端自定义
foreach ($value['adminData'] as $kk){
if(in_array($kk['name'],$extendName)){
$key = array_search($kk['name'], $extendName);
if(!in_array($kk['value'],$extendValue[$key])){
array_push($extendValue[$key],$kk['value']);
}
}else{
array_push($extendName,$kk['name']);
array_push($extendValue,[$kk['value']]);
}
}
// 用户填写端自定义
foreach ($value['userData'] as $kk){
if(in_array($kk['name'],$extendUserName)){
$key = array_search($kk['name'], $extendUserName);
if(!in_array($kk['value'],$extendUserValue[$key])){
array_push($extendUserValue[$key],$kk['value']);
}
}else{
array_push($extendUserName,$kk['name']);
array_push($extendUserValue,[$kk['value']]);
}
}
// 指标列表
$arr = [
'norm_id'=>$norm_id,
'task_id'=>$task_id,
'name'=>$value['name'],
'level'=>$normInfo['level'],
'refer'=>$normInfo['refer'],
'price'=>$normInfo['price'],
'status'=>$normInfo['status'],
'num'=>0,
'sort'=>$normInfo['sort'],
'guide'=>$normInfo['guide'],
];
$norm_list_id = Db::name('norm_list')->insertGetId($arr);
// 指标列表扩展
foreach ($value['adminData'] as $kk){
$arr = [
'norm_id'=>$norm_id,
'norm_list_id'=>$norm_list_id,
'extend_name'=>$kk['name'],
'extend_value'=>$kk['value'],
'extend_type'=>1
];
Db::name('norm_list_extend')->insertGetId($arr);
}
// 指标领取
$arr = [
'task_id'=>$task_id,
'norm_list_id'=>$norm_list_id,
'norm_id'=>$norm_id,
'user_id'=>$user_id,
'status'=>4,
'time'=>date('Y-m-d H:i:s'),
'review_time'=>date('Y-m-d H:i:s'),
'not_collectible'=>$value['not_collectible'],
'not_collectible_remarks'=>$value['not_collectible_remarks'],
];
$norm_receives_id = Db::name('norm_receives')->insertGetId($arr);
$res = $this->importFormat('./import/测试.xlsx');
// 文件格式化有问题
if($res['status']==0){
return returnResult(config("config.code.error"),$res['message']);
// 用户填写指标
$arr = [
'task_id'=>$task_id,
'norm_id'=>$norm_id,
'norm_list_id'=>$norm_list_id,
'norm_receive_id'=>$norm_receives_id,
'user_id'=>$user_id,
'refer_type'=>$value['refer_type'],
'remark'=>$value['remark'],
'imgPath'=>$value['imgPath'],
];
$norm_collects_id = Db::name('norm_collects')->insertGetId($arr);
// 用户填写扩展
$info = Db::name('norm_list_extend')->where('norm_list_id',$norm_list_id)->find();
foreach ($value['userData'] as $val){
$arr = [
'norm_collects_id'=>$norm_collects_id,
'norm_list_extend_id'=>$info['id'],
'norm_receive_id'=>$norm_receives_id,
'task_id'=>$task_id,
'norm_id'=>$norm_id,
'extend_name'=>$val['name'],
'extend_value'=>$val['value'],
'extend_type'=>1,
];
Db::name('norm_collects_extend')->insertGetId($arr);
}
}
//======================处理指标扩展
// 处理指标展示端自定义扩展
foreach ($extendName as $index=>$value){
$normExtendArr = [
'norm_id'=>$norm_id,
'extend_name'=>$value,
'extend_value'=>implode(",",$extendValue[$index]),
'extend_type'=>1,
'required'=>1,
'user_filled'=>0,
'extend_remarks'=>'',
];
array_push($normExtendSql,$normExtendArr);
}
// 处理指标用户端自定义扩展
foreach ($extendUserName as $index=>$value){
$normExtendArr = [
'norm_id'=>$norm_id,
'extend_name'=>$value,
'extend_value'=>implode(",",$extendUserValue[$index]),
'extend_type'=>1,
'required'=>1,
'user_filled'=>1,
'extend_remarks'=>'',
];
array_push($normExtendSql,$normExtendArr);
}
// 指标扩展信息
Db::name('norm_extend')->insertAll($normExtendSql);
// 文件格式化有问题
if($res['status']==0){
Db::rollback();
return returnResult(config("config.code.error"),$res['message']);
}else{
Db::commit();
return returnResult(config("config.code.success"),config("config.describe.success"),'');
}
}catch (\Exception $e){
Db::rollback();
exception($e,'ExcelFile.importFile');
}
}
......@@ -401,7 +585,6 @@ class ExcelFile extends BaseController
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
// 设置为活动工作表
$spreadsheet->createSheet();
for ($i=0;$i<count($list);$i++){
$this->exportFile($spreadsheet,$i,$list[$i]['title'],$list[$i]['data']);
}
......@@ -555,8 +738,6 @@ class ExcelFile extends BaseController
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
// 设置为活动工作表
$spreadsheet->createSheet();
for ($i=0;$i<count($list);$i++){
$this->exportFile($spreadsheet,$i,$list[$i]['title'],$list[$i]['data']);
}
......@@ -573,6 +754,158 @@ class ExcelFile extends BaseController
}
}
/**
* @return void
* 按多个指标导出文件
*/
public function multipleExportFile()
{
try{
$Ids = input('ids');
if(empty($Ids)){
return returnResult(config("config.code.success"),'请选择导出的子任务!',[]);
}
$data = [];
foreach ($Ids as $value){
$info = Db::table('norm')->where('id', $value)->find();
array_push($data,$info);
}
if($data){
$list = [];
foreach ($data as $value){
$sheet = ['title'=>$value['name'],'data'=>[]];
$normList = Db::table('norm_list')->where('norm_id', $value['id'])->select();
foreach ($normList as $index=> $val){
$normReceives = Db::table('norm_receives')->where('norm_list_id', $val['id'])->find();
$normCollects = Db::table('norm_collects')->where('norm_list_id', $val['id'])->find();
$referType = '/'; // 信源类型
$imgPath = '/'; // 图片
$remark = '/';
$normCollectsId = '';
$not_collectible = '/';
$not_collectible_remarks='/';
$reviewStatus='/';
// 填写内容
if ($normCollects){
if($normCollects['refer_type']==1){
$referType = '官网/政府';
}else if ($normCollects['refer_type']==2){
$referType = '权威媒体';
}else{
$referType = '其他可信信源';
}
if ($normCollects['imgPath']){
$imgPath = $normCollects['imgPath'];
}
if ($normCollects['remark']){
$remark = $normCollects['remark'];
}
$normCollectsId = $normCollects['id'];
}
// 是否可以采集
if ($normReceives){
if($normReceives['not_collectible']==1){
$not_collectible = '不可采集';
$not_collectible_remarks = $normReceives['not_collectible_remarks'];
}else{
$not_collectible = '可采集';
}
if($normReceives['status']==0){
$reviewStatus = '已领取、未完成';
}else if($normReceives['status']==1){
$reviewStatus = '已完成、未审核';
}else if($normReceives['status']==2){
$reviewStatus = '审核不通过';
}else if($normReceives['status']==3){
$reviewStatus = '审核通过';
}else if($normReceives['status']==4){
$reviewStatus = '已经结算';
}else{
$reviewStatus = '/';
}
}
// 难度等级
if(isset($val['level'])){
$val['level'] =$val['level'].'级';
}else{
$val['level'] ='/';
}
if(isset($val['sort'])){
if ($val['sort'] ==1){
$val['sort'] ='低';
}else if($val['sort']==2){
$val['sort'] ='中';
}else{
$val['sort'] ='高';
}
}else{
$val['sort'] ='/';
}
$data = [
'name'=>$val['name'],
'level'=>$val['level'],
'refer'=>$val['refer'],
'price'=>$val['price'],
'guide'=>$value['guide'],
'sort'=>$val['sort'],
'remark'=>$remark,
'referType'=>$referType,
'admin'=>[],
'user'=>[],
'adminLength'=>0,
'userLength'=>0,
'imgPath'=>$imgPath,
'not_collectible'=>$not_collectible,
'not_collectible_remarks'=>$not_collectible_remarks,
'review_status'=>$reviewStatus,
];
$normListExtend = Db::table('norm_list_extend')->where('norm_list_id', $val['id'])->select();
// 添加展示端
foreach ($normListExtend as $extendValue){
$arr = ['name'=>$extendValue['extend_name'],'value'=>$extendValue['extend_value']];
array_push($data['admin'],$arr);
}
// 添加用户端
if($normCollectsId){
$collectsInfo = Db::table('norm_collects_extend')->where('norm_collects_id', $normCollectsId)->select();
foreach ($collectsInfo as $collectsValue){
$arr = ['name'=>$collectsValue['extend_name'],'value'=>$collectsValue['extend_value']];
array_push($data['user'],$arr);
}
}
// 添加第一条指标信息
array_push($sheet['data'],$data);
}
if($sheet['data']){
array_push($list,$sheet);
}
}
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
// 设置为活动工作表
for ($i=0;$i<count($list);$i++){
$this->exportFile($spreadsheet,$i,$list[$i]['title'],$list[$i]['data']);
}
// 保存 ExcelFile 文件
$writer = new Xlsx($spreadsheet);
$name = 'xlsx/多选子任务导出_'.date('YmdHis').'.xlsx';
$writer->save($name);
// header('Content-Type: application/vnd.ms-excel');
// header('Content-Disposition: attachment;filename="'.$task['name'].'_'.date('YmdHis').'.xlsx"');
// header('Cache-Control: max-age=0');
// // 输出Excel文件到浏览器
// $writer->save('php://output');
return returnResult(config("config.code.success"),config("config.describe.success"),config("config.resource_address").'public/'.$name);
}else{
return returnResult(config("config.code.error"),'没有该任务存在!',[]);
}
}catch (\Exception $e){
exception($e,'ExcelFile.multipleExportFile');
}
}
/**
* 格式化单页表格数据
* @param $spreadsheet
......@@ -584,6 +917,7 @@ class ExcelFile extends BaseController
public function exportFile($spreadsheet,$number,$title,$data)
{
try{
$spreadsheet->createSheet();
$spreadsheet->setActiveSheetIndex($number);
$spreadsheet->getActiveSheet($number)->setTitle($title);
$sheet = $spreadsheet->getActiveSheet($number);
......@@ -603,7 +937,7 @@ class ExcelFile extends BaseController
'单价',
'参考指南',
'优先级',
'收集指南',
'用户收集备注',
'信源类型',
];
$arr = [];
......@@ -689,7 +1023,12 @@ class ExcelFile extends BaseController
$drawing->setDescription('Sample Image');
$imgList = explode(",", $value['imgPath']);
$words = explode("storage", $imgList[0]);
$drawing->setPath('./storage'.$words[1]); // 图片路径
if(count($words)==2){
$path = './storage'.$words[1];
}else{
$path = './storage/'.$words[0];
}
$drawing->setPath($path); // 图片路径
$drawing->setCoordinates($column[$num+$position].$row); // 图片放置的单元格位置
$drawing->setWorksheet($sheet); // 关联到工作表
// 调整图片大小以适应单元格(可选)
......
......@@ -115,6 +115,7 @@ class Norm
'refer'=>$data['refer'],
'price'=>$data['price'],
'guide'=>$data['guide'],
'type'=>1,
'num'=>$this->num,
];
$normBus = new CommonBus('NormBus'); // 通过公共业务初始化指标类
......@@ -334,6 +335,7 @@ class Norm
public function editDele($queryArr)
{
try{
$data = array();
$normId = trim($queryArr['norm_id']);
$normBus = new CommonBus('NormBus'); // 通过公共业务初始化指标类
......@@ -370,7 +372,7 @@ class Norm
return returnResult(config("config.code.error"),'填写信息错误,请检查!');
}
$index = 1;
$control = 1;
// 指标数据
$normData = [
'task_id'=>$data['task_id'],
......@@ -391,7 +393,7 @@ class Norm
// 添加到指标表中
$normId = $normBus->addData($normData);
if(empty($normId)){
$index++;
$control++;
}
// 指标扩展数据
$normExtendList=[];
......@@ -409,7 +411,7 @@ class Norm
// 添加自定义数据到指标扩展表中
$normExtend = $normExtendBus->addData($normExtendList);
if(empty($normExtend)){
$index++;
$control++;
}
// 格式化数据
......@@ -450,7 +452,7 @@ class Norm
$normListBus = new CommonBus('NormListBus'); // 通过公共业务初始化用户待领取指标类
$normListId =$normListBus->addData($normList);
if(empty($normListId)){
$index++;
$control++;
}
// 添加到用户待领取扩展数据表
}else{
......@@ -462,13 +464,14 @@ class Norm
$normListExtendBus = new CommonBus('NormListExtendBus');// 通过公共业务初始化用户待领取指标扩展类
$res = $normListExtendBus->addData($normListExtend);
if(empty($res)){
$index++;
$control++;
}
}
}
}
// 全部添加完成提交
if($index ==1){
if($control ==1){
Db::commit();
return returnResult(config("config.code.success"),config("config.describe.success"),$res);
}else{
......
......@@ -16,7 +16,7 @@ class System extends BaseController
{
public function index()
{
$data = ['version'=>'v1.3.9','server'=>'DSIS'];
$data = ['version'=>'v1.3.9','server'=>'DSIS','resource_address'=>config("config.resource_address")];
return returnResult(config("config.code.success"),'正式版本',$data);
}
......
......@@ -39,8 +39,6 @@ Route::rule("menu/delete","Menu/delete"); // 删除路由
/***************************系统配置 */
Route::rule("system/version","System/index"); // 获取系统相关信息
//Route::rule("system/me","System/me"); // 获取系统相关信息
//Route::rule("system/menus","System/menus"); // 获取系统相关信息
Route::rule("system/departments","System/departments"); // 获取系统相关信息
//Route::rule("system/user","System/user"); // 获取系统相关信息
Route::rule("system/hospital_area","System/hospital_area"); // 获取系统相关信息
......@@ -95,6 +93,8 @@ Route::rule("normOrders/detail","NormOrders/detail"); //结算指标列表
Route::rule("taskExportFile","ExcelFile/taskExportFile"); //按任务导出数据
Route::rule("normExportFile","ExcelFile/normExportFile"); //按指标导出数据
Route::rule("multipleExportFile","ExcelFile/multipleExportFile"); //导出多个数据
Route::rule("importFile","ExcelFile/importFile"); //按任务导入指标信息
Route::rule("test","test/index"); //结算指标列表
\ No newline at end of file
......@@ -70,5 +70,5 @@ return [
],
// "resource_address"=>'https://data-collect.raisound.com/data-collect-api/',
// "resource_address"=>'http://192.168.10.168/data-collect-api/'
"resource_address"=>'http://gcspider.raisound.com:81/data-collect-api/'
"resource_address"=>'http://gcspider.raisound.com:81/data-collect-api-dev/'
];
a:1:{s:5:"users";a:10:{s:2:"id";i:3;s:4:"name";s:10:"管理员1";s:5:"phone";s:11:"18417180202";s:7:"account";s:8:"admin001";s:8:"password";s:32:"e10adc3949ba59abbe56e057f20f883e";s:6:"status";i:1;s:4:"type";i:1;s:11:"create_time";s:10:"1709196711";s:5:"email";s:0:"";s:13:"department_id";i:1;}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment