Commit efd0a2e7 by 朱继来

导入品牌黑名单

parent 99feade5
......@@ -15,6 +15,7 @@ use App\Model\OrderModel;
use App\Model\CrmModel;
use App\Model\CmsModel;
use Excel;
use App\Model\BrandBlackListModel;
Class AddOrderController extends Controller
{
......@@ -888,4 +889,37 @@ Class AddOrderController extends Controller
}
}
// 批量导入品牌黑名单
public function batchImportBlackList(Request $request)
{
$file = $_FILES['file']; // $request->file('file')
$filePath = $file['tmp_name']; // 临时路径
// 获取导入内容
$excel = [];
Excel::load($filePath, function($reader) use(&$excel){
$data = $reader->getSheet(0);
$excel = $data->toArray();
}, 'GBK');
if (empty($excel)) return ['errcode' => 1, 'errmsg' => '未获取到模板内容,请检查模板内容数据格式'];
array_shift($excel); // 删除第一行
$BrandBlackListModel = new BrandBlackListModel;
$err = [];
foreach ($excel as $k => $v) {
$res = $BrandBlackListModel->setBlackList($request, $v[0], $v[1]);
if ($res[0] == 0) continue;
$err[] = '第'.($k+1).'行导入失败,原因:'.$res[1];
}
if (!empty($err)) return ['errcode' => 2, 'errmsg' => '请检查导入表格,'.implode('; ', $err)];
return ['errcode' => 0, 'errmsg' => '导入成功'];
}
}
\ No newline at end of file
......@@ -141,6 +141,9 @@ Route::group(['middleware' => 'web'], function () {
Route::post('/ajax/addGoods', 'AddOrderController@addGoods');
Route::post('/ajax/uploadContract', 'OrderController@uploadContract');
Route::post('/ajax/getOrderItemsTrack', 'OrderController@getOrderItemsTrack');
Route::post('/ajax/batchImportBlackList', 'AddOrderController@batchImportBlackList');
});
// 不需要登陆态
......
......@@ -80,11 +80,11 @@ class BrandBlackListModel extends Model
}
// 新增、编辑
public function setBlackList($request)
public function setBlackList($request, $brand_name='', $com_name='')
{
$id = $request->input('id', 0);
$data['brand_name'] = $request->input('brand_name', '');
$data['com_name'] = $request->input('com_name', '');
$data['brand_name'] = $brand_name ? $brand_name : $request->input('brand_name', '');
$data['com_name'] = $com_name ? $com_name : $request->input('com_name', '');
$res = $this->where($data)->first();
......
......@@ -184,5 +184,38 @@ layui.use(['form', 'table', 'laydate'], function(){
}
});
// 批量导入物料
$('.import').click(function() {
// 上传文件
var form = $('<form id="formUpload" method="post" enctype="multipart/form-data">\
<input type="file" name="upload" id="fileInput" accept="application/vnd.ms-excel, application/x-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, .csv">\
</form>');
form.find('input').change(function(){
var formData = new FormData();
formData.append('file', this.files[0]);
$.ajax({
type: "POST",
url: '/ajax/batchImportBlackList',
data: formData,
dataType: 'json',
cache: false,
processData: false,
contentType: false,
success: function(resp){
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
return false;
}
layer.alert(resp.errmsg);
}
})
})
form.find('input[type="file"]').trigger('click');
})
});
\ No newline at end of file
......@@ -184,5 +184,38 @@ layui.use(['form', 'table', 'laydate'], function(){
}
});
// 批量导入物料
$('.import').click(function() {
// 上传文件
var form = $('<form id="formUpload" method="post" enctype="multipart/form-data">\
<input type="file" name="upload" id="fileInput" accept="application/vnd.ms-excel, application/x-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, .csv">\
</form>');
form.find('input').change(function(){
var formData = new FormData();
formData.append('file', this.files[0]);
$.ajax({
type: "POST",
url: '/ajax/batchImportBlackList',
data: formData,
dataType: 'json',
cache: false,
processData: false,
contentType: false,
success: function(resp){
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
return false;
}
layer.alert(resp.errmsg);
}
})
})
form.find('input[type="file"]').trigger('click');
})
});
\ No newline at end of file
......@@ -42,6 +42,7 @@
<button lay-submit lay-filter="load" class="layui-btn" data-type="search">搜索</button>
<!-- <button type="button" class="layui-btn layui-btn-normal export">导出</button> -->
<a class="layui-btn layui-btn-normal add">新增</a>
<a class="layui-btn layui-btn-warm import">导入</a>
</div>
</div>
</form>
......
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 sign in to comment