|
...
|
...
|
@@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
namespace app\school\controller\match;
|
|
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
|
|
|
use think\Db;
|
|
|
|
use app\common\controller\ManystoreBase;
|
|
|
|
use app\school\model\match\MatchItems;
|
|
...
|
...
|
@@ -147,9 +148,24 @@ class MatchItemPrize extends ManystoreBase |
|
|
|
|
|
|
|
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
|
|
|
|
$reader->setReadDataOnly(true);
|
|
|
|
$spreadsheet = $reader->load($file['save_path']); //载入excel表格
|
|
|
|
$PHPExcel = $reader->load($file['save_path']); //载入excel表格
|
|
|
|
|
|
|
|
$datas = $spreadsheet->getActiveSheet()->toArray();
|
|
|
|
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
|
|
|
|
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
|
|
|
|
$currentSheetName = $PHPExcel->getSheetNames(); //读取文件中的第一个工作表
|
|
|
|
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
|
|
|
|
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
|
|
|
|
$datas = [];
|
|
|
|
for ($currentRow = 3; $currentRow <= $allRow; $currentRow++) {
|
|
|
|
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
|
|
|
|
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
|
|
|
|
if(!$val){
|
|
|
|
//删除空行
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$datas[$currentRow][] = $val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unlink($_SERVER['DOCUMENT_ROOT'] . "/assets/file/".$tmpName);
|
|
|
|
if(empty($datas)) {
|
|
|
|
$this->error('更新失败');
|
|
...
|
...
|
@@ -157,19 +173,12 @@ class MatchItemPrize extends ManystoreBase |
|
|
|
$newArr = [];
|
|
|
|
$existsArr = [];
|
|
|
|
foreach ($datas as $key => &$val) {
|
|
|
|
if($key <= 1) {
|
|
|
|
unset($datas[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$addIds[] = $val[0];
|
|
|
|
$val[5] = $date = date('Y-m-d', ($val[5] - 25569) * 24 * 3600);
|
|
|
|
$val[5] = date('Y-m-d', ($val[5] - 25569) * 24 * 3600);
|
|
|
|
}
|
|
|
|
$exists = $this->model->whereIn('match_items_id',$addIds)->select();
|
|
|
|
foreach ($datas as $vval) {
|
|
|
|
$tmp['match_items_id'] = $vval[0]; //id
|
|
|
|
if(empty($vval[4]) || empty($vval[5])) {
|
|
|
|
$this->error('导入文件有误,请重新导入');
|
|
|
|
}
|
|
|
|
$tmp['prize_type'] = $vval[4]; //奖项类型
|
|
|
|
$tmp['get_time'] = $vval[5]; //获奖时间
|
|
|
|
if(!empty($vval[6])) {
|
|
...
|
...
|
@@ -195,7 +204,7 @@ class MatchItemPrize extends ManystoreBase |
|
|
|
}
|
|
|
|
$result = $this->model->saveAll($newArr);
|
|
|
|
Db::commit();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Db::rollback();
|
|
|
|
$this->error('导入失败,稍后请重试');
|
|
|
|
}
|
...
|
...
|
|