feat: 导出基本完成
parent
c5acc666e7
commit
5e47ef98b0
|
@ -175,47 +175,61 @@ class Goods extends AdminBase
|
||||||
|
|
||||||
if ($this->request->isAjax()) {
|
if ($this->request->isAjax()) {
|
||||||
try {
|
try {
|
||||||
|
$ids = input('ids/a', []);
|
||||||
$shopName = input('post.shop_name', '');
|
$shopName = input('post.shop_name', '');
|
||||||
$goodsName = input('post.goods_name', '');
|
$goodsName = input('post.goods_name', '');
|
||||||
$goodsType = input('post.goods_type', '');
|
$goodsType = input('post.goods_type', '');
|
||||||
$platformCateId = input('post.platform_cate_id', 0);
|
$platformCateId = input('post.platform_cate_id', 0);
|
||||||
// $goodsColumnId = input('post.goods_column_id', 0);
|
|
||||||
|
|
||||||
$writer = new \XLSXWriter();
|
$writer = new \XLSXWriter();
|
||||||
|
|
||||||
// $fields = Db::query('SHOW COLUMNS FROM ls_goods');
|
|
||||||
// $fields = array_column($fields, 'Field');
|
|
||||||
|
|
||||||
$fieldsArr = [];
|
|
||||||
// foreach ($fields as $field) {
|
|
||||||
// $fieldsArr[$field] = 'string';
|
|
||||||
// }
|
|
||||||
|
|
||||||
$fieldsArr = [
|
$fieldsArr = [
|
||||||
'ID','商品名称','商品规格'
|
'ID' => 'string',
|
||||||
|
'商品名称' => 'string',
|
||||||
|
'商家名称' => 'string',
|
||||||
|
'单位' => 'string',
|
||||||
|
'品牌' => 'string',
|
||||||
|
'一级分类' => 'string',
|
||||||
|
'二级分类' => 'string',
|
||||||
|
'三级分类' => 'string',
|
||||||
|
'图片' => 'string',
|
||||||
|
'详情' => 'string',
|
||||||
|
'状态' => 'string',
|
||||||
|
'实际销量' => 'string',
|
||||||
|
'价格' => 'string',
|
||||||
|
'库存' => 'string',
|
||||||
|
'审核状态' => 'string',
|
||||||
|
'自定义参数' => 'string',
|
||||||
|
|
||||||
|
// '商品规格' => 'string'
|
||||||
];
|
];
|
||||||
$writer->writeSheetHeader('Sheet1', $fieldsArr);
|
$writer->writeSheetHeader('Sheet1', $fieldsArr);
|
||||||
|
|
||||||
|
|
||||||
$where = [];
|
$where = [];
|
||||||
if(!empty($shopName) || $shopName == '0') {
|
|
||||||
$where[] = ['s.name','like','%'.$shopName.'%'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($goodsName) || $goodsName == '0') {
|
if (!empty($ids)) {
|
||||||
$where[] = ['g.name','like','%'.$goodsName.'%'];
|
$where[] = ['g.id', 'in', $ids];
|
||||||
}
|
} else {
|
||||||
if(!empty($platformCateId)) {
|
if(!empty($shopName) || $shopName == '0') {
|
||||||
$where[] = ['g.first_cate_id|g.second_cate_id|g.third_cate_id','=', $platformCateId];
|
$where[] = ['s.name','like','%'.$shopName.'%'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($goodsType) || $goodsType == '0') {
|
if(!empty($goodsName) || $goodsName == '0') {
|
||||||
$where[] = ['g.type','=', $goodsType];
|
$where[] = ['g.name','like','%'.$goodsName.'%'];
|
||||||
|
}
|
||||||
|
if(!empty($platformCateId)) {
|
||||||
|
$where[] = ['g.first_cate_id|g.second_cate_id|g.third_cate_id','=', $platformCateId];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($goodsType) || $goodsType == '0') {
|
||||||
|
$where[] = ['g.type','=', $goodsType];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = GoodsModel::alias('g')
|
$total = GoodsModel::alias('g')
|
||||||
->leftJoin('shop s', 'g.shop_id = s.id')
|
->leftJoin('shop s', 'g.shop_id = s.id')
|
||||||
->leftJoin('goods_item gi', 'gi.goods_id = g.id')
|
// ->leftJoin('goods_item gi', 'gi.goods_id = g.id') // 先注释 不关联查询sku 否则非常慢
|
||||||
->where($where)->count();
|
->where($where)->count();
|
||||||
|
|
||||||
if ($total > 10000) {
|
if ($total > 10000) {
|
||||||
|
@ -226,36 +240,96 @@ class Goods extends AdminBase
|
||||||
return JsonServer::error('没有符合条件的数据');
|
return JsonServer::error('没有符合条件的数据');
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldRaw = "g.id as id, g.name as name, GROUP_CONCAT(CONCAT('规格名称:',gi.spec_value_str,' 规格ID:',gi.spec_value_ids,' 价格:',gi.price, ' 库存:',gi.stock) ORDER BY gi.spec_value_str SEPARATOR ';') AS sku_list";
|
$fieldRaw = "g.id as id, g.name as name,s.name as shop_name,gu.name as unit_name,gb.name as brand_name,
|
||||||
|
gc1.name as first_cate_name,gc2.name as second_cate_name,gc3.name as third_cate_name,
|
||||||
|
g.image,g.content,g.status,g.sales_actual,g.max_price,g.min_price,g.stock,g.audit_status,g.custom_params
|
||||||
|
";
|
||||||
|
|
||||||
|
// 先注释 不关联查询sku 否则非常慢
|
||||||
|
// $fieldRaw .= " ,GROUP_CONCAT(CONCAT('规格名称:',gi.spec_value_str,' 价格:',gi.price, ' 库存:',gi.stock) ORDER BY gi.spec_value_str SEPARATOR ';') AS sku_list";
|
||||||
$query = GoodsModel::alias('g')
|
$query = GoodsModel::alias('g')
|
||||||
->leftJoin('shop s', 'g.shop_id = s.id')
|
->leftJoin('shop s', 'g.shop_id = s.id')
|
||||||
->leftJoin('goods_item gi', 'gi.goods_id = g.id');
|
->leftJoin('goods_unit gu', 'g.unit_id = gu.id')
|
||||||
|
->leftJoin('goods_brand gb', 'g.brand_id = gb.id')
|
||||||
|
->leftJoin('goods_category gc1', 'g.first_cate_id = gc1.id')
|
||||||
|
->leftJoin('goods_category gc2', 'g.second_cate_id = gc2.id')
|
||||||
|
->leftJoin('goods_category gc3', 'g.third_cate_id = gc3.id');
|
||||||
|
// ->leftJoin('goods_item gi', 'gi.goods_id = g.id');// 先注释 不关联查询sku 否则非常慢
|
||||||
|
|
||||||
$cursor = $query
|
$cursor = $query
|
||||||
->where($where)
|
->where($where)
|
||||||
->limit(100)
|
->limit(10000)
|
||||||
->fieldRaw($fieldRaw)
|
->fieldRaw($fieldRaw)
|
||||||
->group('g.id')
|
->group('g.id')
|
||||||
// ->select();
|
|
||||||
// ->field('g.*,s.name as shop_name')
|
|
||||||
->cursor();
|
->cursor();
|
||||||
|
|
||||||
foreach($cursor as $k => $item) {
|
foreach($cursor as $k => $item) {
|
||||||
$row = [];
|
$row = [];
|
||||||
// foreach ($fields as $field) {
|
$row[] = (string)$item['id'];
|
||||||
// $row[] = $item[$field] ?? '';
|
|
||||||
// }
|
|
||||||
$row[] = $item['id'];
|
|
||||||
$row[] = $item['name'];
|
$row[] = $item['name'];
|
||||||
$row[] = $item['sku_list'];
|
$row[] = $item['shop_name'];
|
||||||
var_dump($row);
|
$row[] = $item['unit_name'];
|
||||||
// $writer->writeSheetRow('Sheet1', $row);
|
$row[] = $item['brand_name'];
|
||||||
|
$row[] = $item['first_cate_name'];
|
||||||
|
$row[] = $item['second_cate_name'];
|
||||||
|
$row[] = $item['third_cate_name'];
|
||||||
|
$row[] = $item['image'];
|
||||||
|
$row[] = $item['content'];
|
||||||
|
$status = '';
|
||||||
|
switch ($item['status'])
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
$status = '上架中';
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
$status = '仓库中';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$row[] = $status;
|
||||||
|
$row[] = $item['sales_actual'];
|
||||||
|
$price = $item['min_price'];
|
||||||
|
if ($item['max_price'] != $item['min_price']) {
|
||||||
|
$price = sprintf('%s - %s', $item['min_price'], $item['max_price']);
|
||||||
|
}
|
||||||
|
$row[] = $price;
|
||||||
|
$row[] = $item['stock'];
|
||||||
|
$auditStatus = '';
|
||||||
|
switch ($item['audit_status'])
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
$auditStatus = '审核通过';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$auditStatus = '审核失败';
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
$auditStatus = '待审核';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$row[] = $auditStatus;
|
||||||
|
$row[] = $item['custom_params'];
|
||||||
|
// $row[] = $item['sku_list'];// 先注释 不关联查询sku 否则非常慢
|
||||||
|
$writer->writeSheetRow('Sheet1', $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
$writer->writeToFile('goods.xlsx');
|
$src = 'uploads/export/goods_'.time().'.xlsx';
|
||||||
|
$writer->writeToFile($src);
|
||||||
|
// $domain = request()->domain();
|
||||||
|
return JsonServer::success('资料整理完成 等待下载', ['url' => '/admin/goods.Goods/download?url='.$src]);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return JsonServer::error($e->getMessage());
|
return JsonServer::error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return JsonServer::success('导出完成 本次使用内存#'.floor((memory_get_peak_usage())/1024/1024)."MB", input('post.'));
|
return JsonServer::success('导出完成 本次使用内存#'.floor((memory_get_peak_usage())/1024/1024)."MB", input('post.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function download()
|
||||||
|
{
|
||||||
|
$url = input('url');
|
||||||
|
$fullPath = public_path().$url;
|
||||||
|
if (file_exists($fullPath)) {
|
||||||
|
return download($fullPath, sprintf('商品导出_%s.xlsx', date('Y_m_d_H_i_s')));
|
||||||
|
}
|
||||||
|
echo '文件不存在';exit;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
<div class="layui-colla-content layui-show">
|
<div class="layui-colla-content layui-show">
|
||||||
<p>*平台审核商家发布的商品,当商品审核通过并且处于销售中状态时,商家可以销售该商品</p>
|
<p>*平台审核商家发布的商品,当商品审核通过并且处于销售中状态时,商家可以销售该商品</p>
|
||||||
<p>*平台可通过“违规重审”,下架违规商品并标记为审核未通过。</p>
|
<p>*平台可通过“违规重审”,下架违规商品并标记为审核未通过。</p>
|
||||||
<!-- <p>*商品导出说明:最大导出条数不超过1w条,导出时将按照左侧筛选条件进行过滤</p>-->
|
<p>*商品导出说明:点击导出按钮时,1. 若有手动勾选则导出勾选记录 2.没有手动勾选则导出符合筛选条件的所有记录 最大导出条数不超过1w条</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">查询</button>
|
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="search">查询</button>
|
||||||
<button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</button>
|
<button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="clear-search">重置</button>
|
||||||
<!-- <button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="import">导入</button>-->
|
<!-- <button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="import">导入</button>-->
|
||||||
<!-- <button class="layui-btn layui-btn-sm layui-btn-normal goods-export">导出</button>-->
|
<button class="layui-btn layui-btn-sm layui-btn-normal goods-export">导出</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -199,6 +199,7 @@
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 关闭二维码
|
||||||
$(document).on('click', '.layui-layer-close', function () {
|
$(document).on('click', '.layui-layer-close', function () {
|
||||||
$('#show-qrcode').text('');
|
$('#show-qrcode').text('');
|
||||||
console.log('ssss')
|
console.log('ssss')
|
||||||
|
@ -207,14 +208,29 @@
|
||||||
|
|
||||||
//导出
|
//导出
|
||||||
$(document).on('click', '.goods-export', function () {
|
$(document).on('click', '.goods-export', function () {
|
||||||
layui.layer.load()
|
|
||||||
let shopName = $('#shop_name').val();
|
let shopName = $('#shop_name').val();
|
||||||
let goodsName = $('#goods_name').val();
|
let goodsName = $('#goods_name').val();
|
||||||
let goodsType = $('#goods_type').val();
|
let goodsType = $('#goods_type').val();
|
||||||
let platformCateId = $('#platform_cate_id').val();
|
let platformCateId = $('#platform_cate_id').val();
|
||||||
|
let ids = [];
|
||||||
|
|
||||||
|
var check_status = table.checkStatus('goods-lists')
|
||||||
|
,user_list = check_status.data; //得到选中的数据
|
||||||
|
|
||||||
|
//是否已选数据
|
||||||
|
if(user_list.length > 0){
|
||||||
|
for (var i in user_list){
|
||||||
|
ids.push(user_list[i]['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(ids, 'ids')
|
||||||
|
|
||||||
|
layui.layer.load()
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url:'{:url("goods.goods/export")}',
|
url:'{:url("goods.goods/export")}',
|
||||||
data:{shop_name: shopName, goods_name: goodsName, goods_type: goodsType, platform_cate_id:platformCateId},
|
data:{ids: ids, shop_name: shopName, goods_name: goodsName, goods_type: goodsType, platform_cate_id:platformCateId},
|
||||||
type:"post",
|
type:"post",
|
||||||
success:function(res)
|
success:function(res)
|
||||||
{
|
{
|
||||||
|
@ -224,11 +240,9 @@
|
||||||
offset: '15px'
|
offset: '15px'
|
||||||
, icon: 1
|
, icon: 1
|
||||||
, time: 1000
|
, time: 1000
|
||||||
},function () {
|
|
||||||
// window.location.href = window.location.href;
|
|
||||||
// updateTabNumber();
|
|
||||||
// table.reload('goods-lists');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
window.location.href=res.data.url;
|
||||||
} else {
|
} else {
|
||||||
layui.layer.msg(res.msg, {
|
layui.layer.msg(res.msg, {
|
||||||
offset: '15px'
|
offset: '15px'
|
||||||
|
@ -436,7 +450,7 @@
|
||||||
,{title: '商家信息',width:280, templet: '#shop-info'}
|
,{title: '商家信息',width:280, templet: '#shop-info'}
|
||||||
,{title: '分享二维码',width:150, templet: '#qr-info'}
|
,{title: '分享二维码',width:150, templet: '#qr-info'}
|
||||||
,{title: '商品信息',width:280, templet: '#goods-info'}
|
,{title: '商品信息',width:280, templet: '#goods-info'}
|
||||||
,{field: 'columnStr', title: '商品栏目',width:220}
|
// ,{field: 'columnStr', title: '商品栏目',width:220}
|
||||||
,{field: 'price',title: '价格区间(元)', width: 180, align: 'center'}
|
,{field: 'price',title: '价格区间(元)', width: 180, align: 'center'}
|
||||||
,{field: 'sales_actual',width: 80,title: '总销售', align: 'center'}
|
,{field: 'sales_actual',width: 80,title: '总销售', align: 'center'}
|
||||||
,{field: 'stock',width: 80,title: '总库存', align: 'center'}
|
,{field: 'stock',width: 80,title: '总库存', align: 'center'}
|
||||||
|
|
Loading…
Reference in New Issue