You've already forked guangan
导入
This commit is contained in:
@ -30,7 +30,8 @@
|
|||||||
"zoujingli/think-plugs-wechat": "^1.0",
|
"zoujingli/think-plugs-wechat": "^1.0",
|
||||||
"zoujingli/think-plugs-center": "^1.0",
|
"zoujingli/think-plugs-center": "^1.0",
|
||||||
"zoujingli/think-plugs-account": "^1.0",
|
"zoujingli/think-plugs-account": "^1.0",
|
||||||
"ext-json": "*"
|
"ext-json": "*",
|
||||||
|
"phpoffice/phpspreadsheet": "^4.0"
|
||||||
},
|
},
|
||||||
"repositories": {
|
"repositories": {
|
||||||
"jerryyan/think-plugs-cms": {
|
"jerryyan/think-plugs-cms": {
|
||||||
|
@ -14,6 +14,7 @@ use think\admin\Controller;
|
|||||||
use think\admin\helper\QueryHelper;
|
use think\admin\helper\QueryHelper;
|
||||||
use think\admin\model\SystemUser;
|
use think\admin\model\SystemUser;
|
||||||
use think\exception\HttpResponseException;
|
use think\exception\HttpResponseException;
|
||||||
|
use \PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 工单管理
|
* 工单管理
|
||||||
@ -363,4 +364,56 @@ class Ticket extends Controller
|
|||||||
->append(['imgs_arr', 'source_type_name', 'status_text', 'type_name', 'last_reply'])->with('approval');
|
->append(['imgs_arr', 'source_type_name', 'status_text', 'type_name', 'last_reply'])->with('approval');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @auth true
|
||||||
|
*/
|
||||||
|
public function import() {
|
||||||
|
$file = $this->app->request->post('file');
|
||||||
|
if (!$file) {
|
||||||
|
// 创建一个临时Excel模板用于下载
|
||||||
|
$this->redirect('/static/excel/ticket_import_template.xlsx');
|
||||||
|
};
|
||||||
|
$file = '.' . str_replace($this->app->request->domain(), '', $file);
|
||||||
|
//表格字段对应
|
||||||
|
$fields = [
|
||||||
|
'A' => 'title',
|
||||||
|
'B' => 'type_id',
|
||||||
|
'C' => 'content',
|
||||||
|
'D' => 'contact_name',
|
||||||
|
'E' => 'contact_phone',
|
||||||
|
'F' => 'contact_address',
|
||||||
|
'G' => 'ticket_address',
|
||||||
|
];
|
||||||
|
//加载文件
|
||||||
|
$spreadsheet = IOFactory::load($file);
|
||||||
|
|
||||||
|
$sheet = $spreadsheet->getActiveSheet(); // 获取表格
|
||||||
|
$highestRow = $sheet->getHighestRow(); // 取得总行数
|
||||||
|
$sheetData = [];
|
||||||
|
for ($row = 2; $row <= $highestRow; $row++) { // $row表示从第几行开始读取
|
||||||
|
foreach ($fields as $cell => $field) {
|
||||||
|
$value = $sheet->getCell($cell . $row)->getValue();
|
||||||
|
$value = trim($value);
|
||||||
|
$sheetData[$row][$field] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sheetData = array_values($sheetData);
|
||||||
|
foreach ($sheetData as $key => $value) {
|
||||||
|
if (!empty($value['type_id'])) {
|
||||||
|
$type = TicketType::query()->where(['id' => $value['type_id']])->find();
|
||||||
|
if (empty($type)) {
|
||||||
|
$this->error('工单类型【'.$value['type_id'].'】不存在');
|
||||||
|
} else {
|
||||||
|
$sheetData[$key]['type_id'] = $type['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sheetData[$key]['create_at'] = date('Y-m-d H:i:s');
|
||||||
|
$sheetData[$key]['user_id'] = $this->request->session('user')['id'];
|
||||||
|
$sheetData[$key]['status'] = 0;
|
||||||
|
}
|
||||||
|
TicketTicket::mk()->saveAll($sheetData);
|
||||||
|
$this->success("成功");
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,6 +5,10 @@
|
|||||||
<!--{if auth("add")}-->
|
<!--{if auth("add")}-->
|
||||||
<button type="button" class="layui-btn layui-btn-sm" data-modal='{:url("add")}' data-title="添加工单">添加工单</button>
|
<button type="button" class="layui-btn layui-btn-sm" data-modal='{:url("add")}' data-title="添加工单">添加工单</button>
|
||||||
<!--{/if}-->
|
<!--{/if}-->
|
||||||
|
<!--{if auth("import")}-->
|
||||||
|
<a class="layui-btn layui-btn-sm layui-btn-active" target="_blank" href="/static/ticket_import_template.xlsx">下载导入模板</a>
|
||||||
|
<button class='layui-btn layui-btn-sm layui-btn-success' data-file data-type="xlsx,xls" data-uptype='local' data-field="ticket_excel">导入工单</button>
|
||||||
|
<!--{/if}-->
|
||||||
{/block}
|
{/block}
|
||||||
|
|
||||||
{block name="content"}
|
{block name="content"}
|
||||||
@ -99,6 +103,28 @@
|
|||||||
]],
|
]],
|
||||||
page: true
|
page: true
|
||||||
})
|
})
|
||||||
|
/*!文件上传过程及事件处理 */
|
||||||
|
$('[data-file]').on('upload.choose', function (files) {
|
||||||
|
// 文件选择后的事件
|
||||||
|
}).on('upload.hash', function (event, file) {
|
||||||
|
// file 当前文件对象
|
||||||
|
}).on('upload.progress', function (event, obj) {
|
||||||
|
// obj.file 当前文件对象
|
||||||
|
// obj.event 文件上传进度事件
|
||||||
|
// obj.number 当前上传进度值
|
||||||
|
}).on('upload.done', function (event, obj) {
|
||||||
|
// obj.file 当前完成的文件对象,每个文件上传成功将会调用
|
||||||
|
// obj.data 当前文件上传后服务端返回的内容,部分云上传不会返回数据
|
||||||
|
|
||||||
|
// obj.file 当前完成的文件对象
|
||||||
|
// obj.data 当前文件上传后服务端返回的内容
|
||||||
|
console.log(obj.file);
|
||||||
|
console.log(obj.data);
|
||||||
|
/*! 提交数据并返回结果 */
|
||||||
|
if(obj.file.xurl) $.form.load('{:url("import")}', {file: obj.file.xurl}, 'post');
|
||||||
|
}).on('upload.complete', function (event) {
|
||||||
|
// 全部文件上传成功
|
||||||
|
});
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
{/block}
|
{/block}
|
BIN
public/static/ticket_import_template.xlsx
Normal file
BIN
public/static/ticket_import_template.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user