feat(后台): 完善商品列表二维码

master
yin5th 2023-10-09 11:13:50 +08:00
parent dacfe1b5b4
commit 91fa03da14
5 changed files with 207 additions and 6 deletions

View File

@ -34,6 +34,7 @@ use app\admin\logic\goods\ColumnLogic;
use app\shop\logic\goods\CategoryLogic as ShopCategoryLogic;
use think\exception\ValidateException;
use app\admin\validate\goods\GoodsValidate;
use think\facade\Db;
/**
* 商品管理
@ -165,4 +166,96 @@ class Goods extends AdminBase
return JsonServer::success('获取成功', GoodsLogic::statistics());
}
}
public function export()
{
// ini_set("max_execution_time", 0);
set_time_limit(0);
ini_set('memory_limit', '1024M');
if ($this->request->isAjax()) {
try {
$shopName = input('post.shop_name', '');
$goodsName = input('post.goods_name', '');
$goodsType = input('post.goods_type', '');
$platformCateId = input('post.platform_cate_id', 0);
// $goodsColumnId = input('post.goods_column_id', 0);
$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 = [
'ID','商品名称','商品规格'
];
$writer->writeSheetHeader('Sheet1', $fieldsArr);
$where = [];
if(!empty($shopName) || $shopName == '0') {
$where[] = ['s.name','like','%'.$shopName.'%'];
}
if(!empty($goodsName) || $goodsName == '0') {
$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')
->leftJoin('shop s', 'g.shop_id = s.id')
->leftJoin('goods_item gi', 'gi.goods_id = g.id')
->where($where)->count();
if ($total > 10000) {
return JsonServer::error('导出条数不能超过1W条');
}
if ($total == 0) {
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";
$query = GoodsModel::alias('g')
->leftJoin('shop s', 'g.shop_id = s.id')
->leftJoin('goods_item gi', 'gi.goods_id = g.id');
$cursor = $query
->where($where)
->limit(100)
->fieldRaw($fieldRaw)
->group('g.id')
// ->select();
// ->field('g.*,s.name as shop_name')
->cursor();
foreach($cursor as $k => $item) {
$row = [];
// foreach ($fields as $field) {
// $row[] = $item[$field] ?? '';
// }
$row[] = $item['id'];
$row[] = $item['name'];
$row[] = $item['sku_list'];
var_dump($row);
// $writer->writeSheetRow('Sheet1', $row);
}
$writer->writeToFile('goods.xlsx');
} catch (\Exception $e) {
return JsonServer::error($e->getMessage());
}
}
return JsonServer::success('导出完成 本次使用内存#'.floor((memory_get_peak_usage())/1024/1024)."MB", input('post.'));
}
}

View File

@ -14,6 +14,7 @@
<div class="layui-colla-content layui-show">
<p>*平台审核商家发布的商品,当商品审核通过并且处于销售中状态时,商家可以销售该商品</p>
<p>*平台可通过“违规重审”,下架违规商品并标记为审核未通过。</p>
<!-- <p>*商品导出说明最大导出条数不超过1w条导出时将按照左侧筛选条件进行过滤</p>-->
</div>
</div>
</div>
@ -56,7 +57,7 @@
</select>
</div>
</div>
<div class="layui-inline">
<div class="layui-inline layui-hide">
<label class="layui-form-label">商品栏目:</label>
<div class="layui-input-block">
<select name="goods_column_id" id="goods_column_id" placeholder="请选择商品栏目" >
@ -70,6 +71,8 @@
<div class="layui-inline">
<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-normal" lay-filter="import">导入</button>-->
<!-- <button class="layui-btn layui-btn-sm layui-btn-normal goods-export">导出</button>-->
</div>
</div>
</div>
@ -98,7 +101,8 @@
</script>
<script type="text/html" id="qr-info">
<img src="/images/share/share_qr_test.png" style="height:60px;width: 60px" class="image-show">
<button type="button" class="layui-btn layui-btn-xs layui-btn-primary show-qr" data-url="{$Request.domain}/share-qr?id=" data-id="{{d.id}}">查看</button>
<!-- <img src="/images/share/share_qr_test.png" style="height:60px;width: 60px" class="image-show">-->
</script>
<script type="text/html" id="goods-info">
@ -130,10 +134,14 @@
</div>
</div>
<div id="show-qrcode" style="width:400px; height:400px; margin-top:15px;padding: 5px;"></div>
<script src="__PUBLIC__/static/lib/qrcode/qrcode.min.js"></script>
<script>
layui.use(['table', 'form', 'element'], function(){
layui.use(['table', 'form', 'element', 'layer'], function(){
var $ = layui.$
,form = layui.form
,layer = layui.layer
,table = layui.table
,element = layui.element;
@ -162,6 +170,70 @@
});
});
//查看二维码
$(document).on('click', '.show-qr', function () {
// like.showImg(src,600);
let url = $(this).data('url');
let id = $(this).data('id');
let text = url+id;
$('#show-qrcode').text('');
var qrcode = new QRCode(document.getElementById("show-qrcode"), {
text: text,
width : 380,
height : 380
});
// qrcode.clear();
// qrcode.makeCode(text);
layer.open({
type: 1,
closeBtn: 1,
shade: false,
title: false,
shadeClose: true,
area: ["400px", "400px"],
content: $('#show-qrcode')
})
});
//导出
$(document).on('click', '.goods-export', function () {
layui.layer.load()
let shopName = $('#shop_name').val();
let goodsName = $('#goods_name').val();
let goodsType = $('#goods_type').val();
let platformCateId = $('#platform_cate_id').val();
$.ajax({
url:'{:url("goods.goods/export")}',
data:{shop_name: shopName, goods_name: goodsName, goods_type: goodsType, platform_cate_id:platformCateId},
type:"post",
success:function(res)
{
layui.layer.closeAll()
if(res.code === 1) {
layui.layer.msg(res.msg, {
offset: '15px'
, icon: 1
, time: 1000
},function () {
// window.location.href = window.location.href;
// updateTabNumber();
// table.reload('goods-lists');
});
} else {
layui.layer.msg(res.msg, {
offset: '15px'
, icon: 2
, time: 3000
})
}
}
});
});
$('.layui-btn.layuiadmin-btn-goods').on('click', function(){
var type = $(this).data('type');
@ -354,7 +426,8 @@
function getList(type) {
like.tableLists('#goods-lists', '{:url("goods.goods/lists")}?type='+type, [
{title: '商家信息',width:280, templet: '#shop-info'}
{checkbox:true}
,{title: '商家信息',width:280, templet: '#shop-info'}
,{title: '分享二维码',width:150, templet: '#qr-info'}
,{title: '商品信息',width:280, templet: '#goods-info'}
,{field: 'columnStr', title: '商品栏目',width:220}
@ -367,7 +440,7 @@
,{field: 'audit_remark', width: 220, title: '审核说明', align: 'center'}
,{field: 'create_time', width: 220, title:'发布日期', align: 'center'}
,{fixed: 'right', title: '操作', width: 280, align: 'center', toolbar: '#goods-operation'}
]);
],{}, {limits: [20, 50, 100, 500, 1000]});
// if(type == 5) { // 审核未通过,显示审核说明列(注意计时器时间控制先让动态表格渲染完成再去移除layui-hide)
// setTimeout(function() {
// $('.layui-table .layui-hide').removeClass('layui-hide');

View File

@ -151,4 +151,34 @@ class Goods extends Models
$query->where('id', 'in', $ids);
}
}
public static function exportFields()
{
return '';
}
public static function fieldName()
{
return [
'id' => 'ID',
'type' => '商品类型',
'name' => '商品名称',
'code' => '商品编码',
'shop_id' => '商家',
'shop_cate_id' => '商家商品分类',
'first_cate_id' => '平台商品一级分类',
'second_cate_id' => '平台商品二级分类',
'third_cate_id' => '平台商品三级分类',
'brand_id' => '品牌',
'unit_id' => '商品单位',
'image' => '商品主图',
'content' => '商品详情',
'sales_actual' => '商品实际销量',
'max_price' => '最高价格',
'min_price' => '最低价格',
'market_price' => '市场价',
'stock' => '总库存',
'custom_params' => '自定义参数',
];
}
}

View File

@ -39,7 +39,11 @@ class UrlServer
if (strstr($uri, 'http://')) return $uri;
if (strstr($uri, 'https://')) return $uri;
$engine = ConfigServer::get('storage', 'default', 'local');
$engine = session('storage_engine');
if (empty($engine)) {
$engine = ConfigServer::get('storage', 'default', 'local');
session('storage_engine', $engine);
}
if ($engine === 'local') {
//图片分享处理
if ($type && $type == 'share') {

File diff suppressed because one or more lines are too long