Commit 47cf7f6b authored by zhuwei's avatar zhuwei

门店考勤列表-批量上传

parent f295994c
......@@ -750,39 +750,4 @@ class StoreFeeService
}
/**
* 门店考勤列表-批量上传
* @param $file_path
* @return string
*/
public function readStoreFee($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
......@@ -3,6 +3,7 @@
namespace app\index\controller;
use app\api_broker\service\RedisCacheService;
use app\api_broker\service\UploadFileService;
use app\index\extend\Basic;
use app\api\service\ActivityService;
use app\index\untils\ExportExcelUntil;
......@@ -572,4 +573,113 @@ class CostParameter extends Basic
return $this->response("200", "成功");
}
/**
* 门店考勤列表-批量上传
* @return \think\Response
*/
public function storeDataExcel()
{
header('Access-Control-Allow-Origin:*');
set_time_limit(0);
$file = $_FILES['file'];
$type = request()->param('type');
$uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) {
$path = $_FILES['excel']['tmp_name'];
$result = $this->saveExcelData($path);
return $this->response("200", "excel上传成功", $uploadResult["msg"]);
} else {
return $this->response("101", $uploadResult["msg"]);
}
}
/**
* 保存数据
* @param $path
* @param $setting_date
* @return bool
*/
public function saveExcelData($path,$setting_date)
{
$list = $this->readExcel($path);
if(!$list)
return false;
foreach ($list as $k => $v) {
$f_params['c.store_id'] = $v['id'];
$f_params['c.setting_date'] = $setting_date;
$f_params['c.is_del'] = 0;
$field = 'a.id,a.store_name,b.office_name,d.name,d.phone,c.is_discounts,
c.transfer_charge,c.social_security_fee,c.attendance_num,c.official_receipts,
c.last_official_receipts,c.deduct';
$store_data_res = $this->m_store->getStoreCostParameter($field, $f_params);
if (!$store_data_res) {
if(!$v['store_id'])
continue;
$transfer_charge = $this->getTransferCharge($v['store_id'], $setting_date);
$list[$k]['transfer_charge'] = $transfer_charge;//手续费
$social_security_fee = $this->getLastSocialSecurityFee($v['id'], $setting_date);
$list[$k]['social_security_fee'] = $social_security_fee;//当月社保报销
$list[$k]['attendance_num'] = 0;//当月考勤
$list[$k]['official_receipts'] = 0;//当月合计总实收
$list[$k]['last_official_receipts'] = 0;//当月守护者实收
$list[$k]['deduct'] = 0;//盈利不足2万扣除
$save_params['store_id'] = $v['id'];
$save_params['setting_date'] = $setting_date;
$save_params['is_del'] = 0;
$save_params['transfer_charge'] = $transfer_charge;
$save_params['social_security_fee'] = $social_security_fee;
$this->saveStoreData($save_params);
}
}
return true;
}
/**
* 门店考勤列表-批量上传
* @param $file_path
* @return string
*/
public function readExcel($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++) {
for ($row = 1; $row <= $highestRow; $row++) {
$tempData['store_id'] = $sheet->getCellByColumnAndRow(1, $row)->getValue();
$tempData['social_security_fee'] = $sheet->getCellByColumnAndRow(2, $row)->getValue();
$tempData['attendance_num'] = $sheet->getCellByColumnAndRow(3, $row)->getValue();
$tempData['official_receipts'] = $sheet->getCellByColumnAndRow(4, $row)->getValue();
$tempData['last_official_receipts'] = $sheet->getCellByColumnAndRow(5, $row)->getValue();
$tempData['deduct'] = $sheet->getCellByColumnAndRow(6, $row)->getValue();
$data[] = $tempData;
}
$data[] = $tempData;
}
return $data;
}
}
\ No newline at end of file
<?php
namespace app\index\controller;
/**
* Created by PhpStorm.
* User: zhuwei
* Date:2018-10-18
* Time:10:50:55
*/
use app\index\extend\Basic;
class ReadExcel extends Basic
{
// protected $aSite;
public function __construct($request = null)
{
parent::__construct($request);
// $this->aSite = new ASite();
}
function readExcelTest()
{
if (!empty($_FILES['excel']['name'])) {
$fileName = $_FILES['excel']['name']; //得到文件全名
$dotArray = explode('.', $fileName); //把文件名安.区分,拆分成数组
$type = end($dotArray);
if ($type != "xls" && $type != "xlsx") {
$ret['res'] = "0";
$ret['msg'] = "不是Excel文件,请重新上传!";
return json_encode($ret);
}
$path = $_FILES['excel']['tmp_name'];
// $file = $_FILES['upload']['tmp_name'][0];
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$spreadsheet = "";
try {
$spreadsheet = $reader->load($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 = 1; $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);
dump($path);
}else{
return $this->response(101, '未上传excel');
}
}
}
\ No newline at end of file
......@@ -577,26 +577,7 @@ class StoreFee extends Basic
}
/**
* 门店考勤列表-批量上传
* @return \think\Response
*/
public function readStoreFee()
{
header('Access-Control-Allow-Origin:*');
set_time_limit(0);
$file = $_FILES['file'];
$type = request()->param('type');
$uploadFileService = new UploadFileService();
$uploadResult = $uploadFileService->upload($file, $type, 15000000, ['xls', 'xlsx']);
if ($uploadResult["code"] == 200) {
$path = $_FILES['excel']['tmp_name'];
$result = $this->service_->readStoreFee($path);
return $this->response("200", "excel上传成功", $uploadResult["msg"]);
} else {
return $this->response("101", $uploadResult["msg"]);
}
}
}
\ No newline at end of file
......@@ -577,8 +577,7 @@ Route::group('index', [
'qualityAssessment' => ['index/WorkLearning/qualityAssessment', ['method' => 'GET']], //素质测评
'valueAssessment' => ['index/WorkLearning/valueAssessment', ['method' => 'GET']], //价值观考核
'readExcelTest' => ['index/ReadExcel/readExcelTest', ['method' => 'POST']],
'storeDataExcel' => ['index/CostParameter/storeDataExcel', ['method' => 'POST']],
]);
......
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