Commit b53f8a89 authored by clone's avatar clone

1

parent 7b9064f1
...@@ -703,4 +703,36 @@ class StoreFeeService ...@@ -703,4 +703,36 @@ class StoreFeeService
$fCostModel = new FStoreCost(); $fCostModel = new FStoreCost();
return $fCostModel->findByOne("id", ["setting_date" => $setting_date]); return $fCostModel->findByOne("id", ["setting_date" => $setting_date]);
} }
public function importStoreFee($file_path)
{
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$spreadsheet = "";
try {
$spreadsheet = $reader->load($file_path);
} catch (\Exception $exception) {
return "找不到文件路径";
}
$sheet = $spreadsheet->getActiveSheet();
$highestRow = $sheet->getHighestRow(); // 最大行数
$highestColumn = $sheet->getHighestColumn(); // 最大列数
$highestColumn = "AB";
// 把下标变成数字,如A-Z分别对应1-26,AA对应27,AB对应28,以此类推
$highestColumnIndex = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highestColumn);
/* if($highestRow <= 2){ // 因为students.xlsx表格数据是从第三行开始的
exit('Excel没有任何数据');
}*/
$data = array();
for ($row = 0; $row <= $highestRow; $row++) {
$tempData['name'] = $sheet->getCellByColumnAndRow(1, $row)->getValue();
$tempData['chinese'] = $sheet->getCellByColumnAndRow(2, $row)->getValue();
$tempData['math'] = $sheet->getCellByColumnAndRow(3, $row)->getValue();
$tempData['English'] = $sheet->getCellByColumnAndRow(4, $row)->getValue();
$data[] = $tempData;
}
dump($data);
}
} }
\ No newline at end of file
<?php <?php
namespace app\api_broker\service; namespace app\api_broker\service;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -20,26 +21,25 @@ class UploadFileService ...@@ -20,26 +21,25 @@ class UploadFileService
* @param array $ext * @param array $ext
* @return array * @return array
*/ */
public function upload($_upload_file, $type, $size = 15000000, $ext = [ 'jpg','png','jpeg','xlsx','doc','docx','pdf','ppt','pptx','xls','gif','mp4','video/mp4']) public function upload($_upload_file, $type, $size = 15000000, $ext = ['jpg', 'png', 'jpeg', 'xlsx', 'doc', 'docx', 'pdf', 'ppt', 'pptx', 'xls', 'gif', 'mp4', 'video/mp4'])
{ {
/** /**
* *
upload($_FILE['file']) * upload($_FILE['file'])
*
*
array(2) { * array(2) {
[0] => array(3) { * [0] => array(3) {
["code"] => int(200) * ["code"] => int(200)
["img_path"] => string(19) "201807021804140.jpg" * ["img_path"] => string(19) "201807021804140.jpg"
["img_ext"] => string(3) "jpg" * ["img_ext"] => string(3) "jpg"
} * }
[1] => array(3) { * [1] => array(3) {
["code"] => int(200) * ["code"] => int(200)
["img_path"] => string(20) "2018070218041401.jpg" * ["img_path"] => string(20) "2018070218041401.jpg"
["img_ext"] => string(3) "jpg" * ["img_ext"] => string(3) "jpg"
} * }
} * }
*/ */
$check = $this->checkUploadFile($_upload_file, $size, $ext); $check = $this->checkUploadFile($_upload_file, $size, $ext);
...@@ -65,93 +65,97 @@ class UploadFileService ...@@ -65,93 +65,97 @@ class UploadFileService
} }
break; break;
case 'user_header' : case 'user_header' :
$path .= 'static/user_header/'; $path .= 'static/user_header/';
$internet_path = ''; $internet_path = '';
break; break;
case 'agent_header' : case 'agent_header' :
$path .= 'static/head_portrait/'; $path .= 'static/head_portrait/';
$internet_path = ''; $internet_path = '';
break; break;
case 'house_img': case 'house_img':
$path .= 'resource/lib/Attachments/images/'; $path .= 'resource/lib/Attachments/images/';
$internet_path = ''; $internet_path = '';
break; break;
case 'business_school' : case 'business_school' :
$path .= 'static/business_school/'; $path .= 'static/business_school/';
$internet_path = 'static/business_school/'; $internet_path = 'static/business_school/';
break; break;
case 'business_school_file' : case 'business_school_file' :
$path .= 'static/business_school_file/'; $path .= 'static/business_school_file/';
$internet_path = 'static/business_school_file/'; $internet_path = 'static/business_school_file/';
break; break;
case 'shop_image_depot' : case 'shop_image_depot' :
$path .= 'static/shop_image_depot/'; $path .= 'static/shop_image_depot/';
$internet_path = 'static/shop_image_depot/'; $internet_path = 'static/shop_image_depot/';
break; break;
case 'exclusive_file' : case 'exclusive_file' :
$path .= 'static/exclusive_file/'; $path .= 'static/exclusive_file/';
$internet_path = 'static/exclusive_file/'; $internet_path = 'static/exclusive_file/';
break; break;
case 'agent_black_list_img': case 'agent_black_list_img':
$path .= 'static/agent_black_list/'; $path .= 'static/agent_black_list/';
$internet_path = 'static/agent_black_list/'; $internet_path = 'static/agent_black_list/';
break; break;
case 'check': case 'check':
$path .= 'static/check/'; $path .= 'static/check/';
$internet_path = 'static/check/'; $internet_path = 'static/check/';
break; break;
case 'house_video': case 'house_video':
$path .= 'resource/lib/Attachments/video/'; $path .= 'resource/lib/Attachments/video/';
$internet_path = ''; $internet_path = '';
break; break;
case 'user_id_card' : case 'user_id_card' :
$path .= 'static/user_id_card/'; $path .= 'static/user_id_card/';
$internet_path = '';
break;
case 'excel_import' :
$path .= 'static/excel/';
$internet_path = ''; $internet_path = '';
break; break;
default : default :
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = "上传图片类型错误"; $data['msg'] = "上传图片类型错误";
return $data; return $data;
} }
$date = date('Ymd'); $date = date('Ymd');
$path .= $date; $path .= $date;
$name_str = date('YmdHis'); $name_str = date('YmdHis');
if (is_array($_upload_file['tmp_name'])) { if (is_array($_upload_file['tmp_name'])) {
foreach ($_upload_file['tmp_name'] as $k => $v) { foreach ($_upload_file['tmp_name'] as $k => $v) {
$name_str .= mt_rand(10,10000); $name_str .= mt_rand(10, 10000);
$_file = new File($v); $_file = new File($v);
$file_info = pathinfo($_upload_file['name'][$k]); $file_info = pathinfo($_upload_file['name'][$k]);
$info = $_file->validate($valid_date)->move($path, $name_str . '.' . $file_info['extension']); $info = $_file->validate($valid_date)->move($path, $name_str . '.' . $file_info['extension']);
if ($info) { if ($info) {
$data['code'] = 200; $data['code'] = 200;
$data["msg"][$k]['img_path'] = $date .'/'. $info->getSaveName(); //生成的图片路径 $data["msg"][$k]['img_path'] = $date . '/' . $info->getSaveName(); //生成的图片路径
$data["msg"][$k]['internet_img_name'] = $internet_path . $data["msg"][$k]['img_path']; $data["msg"][$k]['internet_img_name'] = $internet_path . $data["msg"][$k]['img_path'];
$data["msg"][$k]['img_ext'] = $info->getExtension(); $data["msg"][$k]['img_ext'] = $info->getExtension();
$data["msg"][$k]['imgformer_name'] = $file_info['basename']; $data["msg"][$k]['imgformer_name'] = $file_info['basename'];
} else { } else {
$data['code'] = 101; $data['code'] = 101;
$data["msg"][$k]['error'] = $_file->getError(); $data["msg"][$k]['error'] = $_file->getError();
} }
} }
} else { } else {
$name_str .= mt_rand(10,1000); $name_str .= mt_rand(10, 1000);
$_file = new File($_upload_file['tmp_name']); $_file = new File($_upload_file['tmp_name']);
$file_info = pathinfo($_upload_file['name']); $file_info = pathinfo($_upload_file['name']);
$info = $_file->validate($valid_date)->move($path, $name_str . '.' . $file_info['extension']); $info = $_file->validate($valid_date)->move($path, $name_str . '.' . $file_info['extension']);
if ($info) { if ($info) {
$data['code'] = 200; $data['code'] = 200;
$data["msg"]['img_path'] = $date .'/'. $info->getSaveName(); //生成的图片路径 $data["msg"]['img_path'] = $date . '/' . $info->getSaveName(); //生成的图片路径
$data["msg"]['internet_img_name'] = $internet_path . $data["msg"]['img_path']; $data["msg"]['internet_img_name'] = $internet_path . $data["msg"]['img_path'];
$data["msg"]['img_ext'] = $info->getExtension(); $data["msg"]['img_ext'] = $info->getExtension();
$data["msg"]['imgformer_name'] = $file_info['basename']; $data["msg"]['imgformer_name'] = $file_info['basename'];
} else { } else {
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = $_file->getError(); $data['msg'] = $_file->getError();
} }
} }
...@@ -176,14 +180,14 @@ class UploadFileService ...@@ -176,14 +180,14 @@ class UploadFileService
$file_info = pathinfo($_upload_file['name'][$k]); $file_info = pathinfo($_upload_file['name'][$k]);
if (filesize($v) > $size) { if (filesize($v) > $size) {
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = '文件太大无法上传'; $data['msg'] = '文件太大无法上传';
break; break;
} }
if (!in_array($file_info['extension'], $ext)) { if (!in_array($file_info['extension'], $ext)) {
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = '文件类型不符无法上传'; $data['msg'] = '文件类型不符无法上传';
break; break;
} }
...@@ -191,14 +195,14 @@ class UploadFileService ...@@ -191,14 +195,14 @@ class UploadFileService
} else { } else {
if (filesize($_upload_file['tmp_name']) > $size) { if (filesize($_upload_file['tmp_name']) > $size) {
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = '文件太大无法上传'; $data['msg'] = '文件太大无法上传';
} }
$file_info = pathinfo($_upload_file['name']); $file_info = pathinfo($_upload_file['name']);
if (!in_array($file_info['extension'], $ext)) { if (!in_array($file_info['extension'], $ext)) {
$data['code'] = 101; $data['code'] = 101;
$data['msg'] = '文件类型不符无法上传'; $data['msg'] = '文件类型不符无法上传';
} }
} }
......
...@@ -12,6 +12,7 @@ namespace app\index\controller; ...@@ -12,6 +12,7 @@ namespace app\index\controller;
use app\api_broker\service\PushMessageService; use app\api_broker\service\PushMessageService;
use app\api_broker\service\RedisCacheService; use app\api_broker\service\RedisCacheService;
use app\api_broker\service\StoreFeeService; use app\api_broker\service\StoreFeeService;
use app\api_broker\service\UploadFileService;
use app\api_broker\validate\StoreFeeValidate; use app\api_broker\validate\StoreFeeValidate;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\model\AAgents; use app\model\AAgents;
...@@ -120,6 +121,22 @@ class StoreFee extends Basic ...@@ -120,6 +121,22 @@ class StoreFee extends Basic
} }
} }
public function importStoreFee()
{
header('Access-Control-Allow-Origin:*');
set_time_limit(0);
$file = $_FILES['file'];
$type = request()->param('type'); //excel_import
$uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) {
$result = $this->service_->importStoreFee($uploadResult["msg"]);
return $this->response("200", "excel上传成功", $uploadResult["msg"]);
} else {
return $this->response("101", $uploadResult["msg"]);
}
}
/** /**
* 新增办公室 * 新增办公室
* @return \think\Response * @return \think\Response
......
...@@ -14,10 +14,10 @@ class ImportExcelUntil ...@@ -14,10 +14,10 @@ class ImportExcelUntil
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true); $reader->setReadDataOnly(true);
$spreadsheet = ""; $spreadsheet = "";
try{ try {
$spreadsheet = $reader->load($file_path); $spreadsheet = $reader->load($file_path);
}catch (\Exception $exception){ } catch (\Exception $exception) {
return "找不到文件路径"; return "找不到文件路径";
} }
$sheet = $spreadsheet->getActiveSheet(); $sheet = $spreadsheet->getActiveSheet();
...@@ -39,4 +39,32 @@ class ImportExcelUntil ...@@ -39,4 +39,32 @@ class ImportExcelUntil
} }
dump($data); dump($data);
} }
public function uploadExcel($_FILES)
{
if (!empty($_FILES['excel']['name'])) {
$fileName = $_FILES['excel']['name']; //得到文件全名
$dotArray = explode('.', $fileName); //把文件名安.区分,拆分成数组
$type = end($dotArray);
if ($type != "xls" && $type != "xlsx") {
return "不是Excel文件,请重新上传!";
}
//取数组最后一个元素,得到文件类型
$path = ROOT_PATH . 'public/static/excel/';
$uploadDir = $path . date("Y-m-d") . '/';//设置文件保存目录 注意包含
if (!file_exists($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$path = $uploadDir . md5(uniqid(rand())) . '.' . $type; //产生随机文件名
//下面必须是tmp_name 因为是从临时文件夹中移动
move_uploaded_file($_FILES['excel']['tmp_name'], $path); //从服务器临时文件拷贝到相应的文件夹下
if (!file_exists($path)) {
return "上传文件丢失!" . $_FILES['excel']['error'];
} else {
return ["path" => $path];
}
}
}
} }
\ No newline at end of file
...@@ -476,12 +476,12 @@ Route::group('index', [ ...@@ -476,12 +476,12 @@ Route::group('index', [
'downloadFile' => ['index/news/downloadFile', ['method' => 'GET|POST']], //新增商学院资讯 'downloadFile' => ['index/news/downloadFile', ['method' => 'GET|POST']], //新增商学院资讯
'addAgentsBlackList' => ['index/broker/addAgentsBlackList', ['method' => 'GET|POST']],//添加黑名单 'addAgentsBlackList' => ['index/broker/addAgentsBlackList', ['method' => 'GET|POST']],//添加黑名单
'getAgentsBlackList' => ['index/broker/getAgentsBlackList', ['method' => 'GET|POST']],//黑名单列表 'getAgentsBlackList' => ['index/broker/getAgentsBlackList', ['method' => 'GET|POST']],//黑名单列表
'getBlackListInfo' => ['index/broker/getBlackListInfo', ['method' => 'GET|POST']],//黑名单详情 'getBlackListInfo' => ['index/broker/getBlackListInfo', ['method' => 'GET|POST']],//黑名单详情
'delAgentsBlackListImg' => ['index/broker/delAgentsBlackListImg', ['method' => 'GET|POST']],//黑名单删除图片 'delAgentsBlackListImg' => ['index/broker/delAgentsBlackListImg', ['method' => 'GET|POST']],//黑名单删除图片
'getSystemMessageByUser' => ['index/broker/getSystemMessageByUser', ['method' => 'GET']],//未读消息列表 'getSystemMessageByUser' => ['index/broker/getSystemMessageByUser', ['method' => 'GET']],//未读消息列表
'updateSystemMessageIsRead' => ['index/broker/updateSystemMessageIsRead', ['method' => 'POST']],//已读状态 'updateSystemMessageIsRead' => ['index/broker/updateSystemMessageIsRead', ['method' => 'POST']],//已读状态
'updateSystemMessageCheckIsRead' => ['index/broker/updateSystemMessageCheckIsRead', ['method' => 'POST']],//审核消息-已读状态 'updateSystemMessageCheckIsRead' => ['index/broker/updateSystemMessageCheckIsRead', ['method' => 'POST']],//审核消息-已读状态
'userDetail' => ['index/UserLog/userDetail', ['method' => 'get|post']], 'userDetail' => ['index/UserLog/userDetail', ['method' => 'get|post']],
...@@ -559,6 +559,7 @@ Route::group('index', [ ...@@ -559,6 +559,7 @@ Route::group('index', [
'getStoreOffice' => ['index/Store/getStoreOffice', ['method' => 'GET']],//获取费用承担办公室 'getStoreOffice' => ['index/Store/getStoreOffice', ['method' => 'GET']],//获取费用承担办公室
'creationStoreFee' => ['index/StoreFee/creationStoreFee', ['method' => 'POST|GET']], 'creationStoreFee' => ['index/StoreFee/creationStoreFee', ['method' => 'POST|GET']],
'getStoreFeeDetail' => ['index/StoreFee/getStoreFeeDetail', ['method' => 'POST|GET']], 'getStoreFeeDetail' => ['index/StoreFee/getStoreFeeDetail', ['method' => 'POST|GET']],
'importStoreFee' => ['index/StoreFee/importStoreFee', ['method' => 'POST']],
'getStoreCostParameterList' => ['index/CostParameter/getStoreCostParameterList', ['method' => 'POST|GET']], 'getStoreCostParameterList' => ['index/CostParameter/getStoreCostParameterList', ['method' => 'POST|GET']],
'editCostParameter' => ['index/CostParameter/editCostParameter', ['method' => 'POST|GET']], 'editCostParameter' => ['index/CostParameter/editCostParameter', ['method' => 'POST|GET']],
......
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