Commit 39152d95 by 杨树贤

批量修改

parent 9bff5b8e
...@@ -7,6 +7,7 @@ use App\Http\Services\SkuService; ...@@ -7,6 +7,7 @@ use App\Http\Services\SkuService;
use App\Model\SkuUploadLogModel; use App\Model\SkuUploadLogModel;
use App\Model\SupplierChannelModel; use App\Model\SupplierChannelModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use function GuzzleHttp\Promise\all;
//通用API,比如获取品牌列表,分类列表等 //通用API,比如获取品牌列表,分类列表等
class SkuApiController extends Controller class SkuApiController extends Controller
...@@ -171,10 +172,46 @@ class SkuApiController extends Controller ...@@ -171,10 +172,46 @@ class SkuApiController extends Controller
//批量新增标签 //批量新增标签
public function BatchAddSkuTag($request) public function BatchAddSkuTag($request)
{ {
$type = $request->input('type');
$supplierCode = $request->input('supplier_code');
$skuIds = $request->get('sku_ids'); $skuIds = $request->get('sku_ids');
$skuTags = $request->get('sku_tags'); $skuTags = $request->get('sku_tags');
(new SkuService())->batchAddSkuTags($skuIds, $skuTags); if ($type == 1 && empty($skuIds)) {
$this->response(0, '设置标签成功'); $this->response(-1,'按型号设置标签,必须先选择型号');
}
if ($type == 2 && empty($supplierCode)) {
$this->response(-1,'按供应商设置标签,必须先选择供应商');
}
(new SkuService())->batchAddSkuTags($type,$supplierCode,$skuIds, $skuTags);
$text = $type == 1? '设置标签成功':'批量设置供应商SKU标签任务已开始,请等待任务完成';
$this->response(0, $text);
}
//批量新增标签
public function BatchUpdateGoodsLabel($request)
{
$type = $request->input('type');
$supplierCode = $request->input('supplier_code');
$skuIds = $request->get('sku_ids');
$goodsLabel = $request->get('goods_label');
if ($type == 1 && empty($skuIds)) {
$this->response(-1,'按型号设置显示类型,必须先选择型号');
}
if ($type == 2 && empty($supplierCode)) {
$this->response(-1,'按供应商设置显示类型,必须先选择供应商');
}
if (empty($goodsLabel)) {
$this->response(-1,'请选择显示类型');
}
(new SkuService())->batchUpdateGoodsLabel($type,$supplierCode,$skuIds, $goodsLabel);
$text = $type == 1? '设置显示类型成功':'批量设置供应SKU商显示类型任务已开始,请等待任务完成';
$this->response(0, $text);
} }
//获取所有系统标签 //获取所有系统标签
......
...@@ -105,9 +105,38 @@ class SkuController extends Controller ...@@ -105,9 +105,38 @@ class SkuController extends Controller
{ {
$this->data['title'] = '批量修改Sku标签'; $this->data['title'] = '批量修改Sku标签';
$suppliers = SupplierChannelModel::where('is_type', 0)->where('status', 2)
->select(['supplier_name', 'supplier_code'])->get();
$supplierCodes = [];
foreach ($suppliers as $supplier) {
$supplier = $supplier->toArray();
$supplierCodes[$supplier['supplier_code']] = $supplier['supplier_name'] . '(' . $supplier['supplier_code'] . ')';
}
$skuIds = $request->input('sku_ids');
if (!empty($skuIds)) {
$skuIds = explode(',', $skuIds);
$this->data['skuIds'] = $skuIds;
}
$this->data['supplierCodes'] = $supplierCodes;
return $this->view('批量修改Sku标签'); return $this->view('批量修改Sku标签');
} }
//批量设置sku显示类型
public function BatchUpdateGoodsLabel($request)
{
$this->data['title'] = '批量设置sku显示类型';
$suppliers = SupplierChannelModel::where('is_type', 0)->where('status', 2)
->select(['supplier_name', 'supplier_code'])->get();
$supplierCodes = [];
foreach ($suppliers as $supplier) {
$supplier = $supplier->toArray();
$supplierCodes[$supplier['supplier_code']] = $supplier['supplier_name'] . '(' . $supplier['supplier_code'] . ')';
}
$this->data['supplierCodes'] = $supplierCodes;
return $this->view('批量设置sku显示类型');
}
//设置供应商的过期时间 //设置供应商的过期时间
public function SetSupplierSkuCpTimeLimit($request) public function SetSupplierSkuCpTimeLimit($request)
{ {
......
...@@ -83,9 +83,9 @@ class SkuService ...@@ -83,9 +83,9 @@ class SkuService
} }
} }
} }
$standardBrandId = array_get($spu,'s_brand_id'); $standardBrandId = array_get($spu, 's_brand_id');
if ($standardBrandId) { if ($standardBrandId) {
$standardBrand = $redis->hget('standard_brand',$standardBrandId); $standardBrand = $redis->hget('standard_brand', $standardBrandId);
$standardBrand = json_decode($standardBrand, true); $standardBrand = json_decode($standardBrand, true);
$sku['standard_brand_name'] = $standardBrand['brand_name']; $sku['standard_brand_name'] = $standardBrand['brand_name'];
} }
...@@ -257,6 +257,20 @@ class SkuService ...@@ -257,6 +257,20 @@ class SkuService
$channel->basic_publish($msg, '', 'lie_footstone_update_sku_info_queue'); $channel->basic_publish($msg, '', 'lie_footstone_update_sku_info_queue');
} }
//批量修改商品信息队列
public function batchUpdateSkuInfoQueue($data)
{
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq2.host'),
config('database.connections.rabbitmq2.port'),
config('database.connections.rabbitmq2.login'),
config('database.connections.rabbitmq2.password'));
$channel = $conn->channel();
$channel->queue_declare('lie_footstone_update_sku_info_queue', false, true, false, false);
$msg = new AMQPMessage(json_encode($data),
array('content_type' => 'text/plain'));
$channel->basic_publish($msg, '', 'lie_footstone_update_sku_info_queue');
}
//批量更新sku状态,走队列的 //批量更新sku状态,走队列的
public function batchUpdateSkuStatus($data) public function batchUpdateSkuStatus($data)
{ {
...@@ -353,8 +367,11 @@ class SkuService ...@@ -353,8 +367,11 @@ class SkuService
return $result; return $result;
} }
public function batchAddSkuTags($skuIds, $skuTags) public function batchAddSkuTags($type, $supplierCode, $skuIds, $skuTags)
{ {
$skuTags = trim($skuTags, ',');
//判断是类型1(针对商品)还是类型2(针对供应商)
if ($type == 1) {
$redis = new RedisModel(); $redis = new RedisModel();
$skuIds = explode(',', $skuIds); $skuIds = explode(',', $skuIds);
$skuTags = explode(',', $skuTags); $skuTags = explode(',', $skuTags);
...@@ -372,6 +389,14 @@ class SkuService ...@@ -372,6 +389,14 @@ class SkuService
$redis->hset('goods_tag', $skuId, json_encode($goodsTag)); $redis->hset('goods_tag', $skuId, json_encode($goodsTag));
$redis->lpush('update_list_sku', $skuId); $redis->lpush('update_list_sku', $skuId);
} }
} else {
$skuTags = explode(',', $skuTags);
$data = [
'canal' => $supplierCode,
'customer_tag' => implode(" ", $skuTags),
];
$this->batchUpdateSkuInfoQueue($data);
}
} }
//设置上架有效期 //设置上架有效期
...@@ -451,4 +476,36 @@ class SkuService ...@@ -451,4 +476,36 @@ class SkuService
{ {
} }
public function batchUpdateGoodsLabel($type, $supplierCode, $skuIds, $goodsLabel)
{
$goodsLabel = (int)$goodsLabel;
//判断是类型1(针对商品)还是类型2(针对供应商)
if ($type == 1) {
$redis = new RedisModel();
$skuIds = explode(',', $skuIds);
foreach ($skuIds as $skuId) {
$skuId = (int)$skuId;
$skuCache = $redis->hget('sku', $skuId);
$skuCache = json_decode($skuCache, true);
$skuCache['goods_label'] = $goodsLabel;
$redis->hset('sku', $skuId, json_encode($skuCache));
$dbInfo = getSpuSkuDb($skuId);
$connection = DB::connection($dbInfo["db"]);
$table = $dbInfo['table'];
$connection->table($table)->where('goods_id', $skuId)->update([
'goods_label' => $goodsLabel,
]);
}
} else {
$data = [
'canal' => $supplierCode,
'goods_label' => (int)$goodsLabel,
];
$this->batchUpdateSkuInfoQueue($data);
}
}
} }
...@@ -47,6 +47,10 @@ return [ ...@@ -47,6 +47,10 @@ return [
1 => '国内现货', 1 => '国内现货',
2 => '国际现货', 2 => '国际现货',
3 => '猎芯期货', 3 => '猎芯期货',
4 => '询价现货',
5 => '原厂直售',
6 => '猎芯精选',
//-1 => '代购现货'
], ],
//SKU 标签 //SKU 标签
......
...@@ -8,6 +8,16 @@ ...@@ -8,6 +8,16 @@
let tagsInput = layui.tagsInput; let tagsInput = layui.tagsInput;
form.on('submit(addSkuTag)', function (data) { form.on('submit(addSkuTag)', function (data) {
if (data.field.sku_tags === '') {
layer.confirm('如果没有选择任何标签点击确认将把原标签全部删除,确定要删除吗?', function (index) {
addSkuTag(data);
});
} else {
addSkuTag(data);
}
});
function addSkuTag(data) {
admin.showLoading({ admin.showLoading({
type: 3 type: 3
}); });
...@@ -23,24 +33,37 @@ ...@@ -23,24 +33,37 @@
success: function (res) { success: function (res) {
admin.removeLoading(); admin.removeLoading();
if (res.err_code === 0) { if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6});
setTimeout(function () {
admin.closeThisDialog(); admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6}); }, 1000);
} else { } else {
parent.layer.msg(res.err_msg, {icon: 5}); layer.msg(res.err_msg, {icon: 5});
} }
}, },
error: function () { error: function () {
admin.removeLoading(); admin.removeLoading();
parent.layer.msg('网络错误', {icon: 5}); layer.msg('网络错误', {icon: 5});
} }
}); });
return false; }
});
form.on('submit(cancel)', function (data) { form.on('submit(cancel)', function (data) {
admin.closeThisDialog(); admin.closeThisDialog();
}); });
form.on('radio(type)', function (data) {
if (data.value === '1') {
$('#supplier_select_div').hide();
$('#selected_sku_id').show();
} else {
$('#supplier_select_div').show();
$('#selected_sku_id').hide();
}
});
function getTagOption(element) { function getTagOption(element) {
//获取系统标签列表 //获取系统标签列表
let url = '/api/sku/GetSystemTagList'; let url = '/api/sku/GetSystemTagList';
......
<script>
layui.use(['table', 'form', 'element', 'table', 'xmSelect', 'tagsInput', 'layer', 'admin'], function () {
let admin = layui.admin;
let form = layui.form;
let table = layui.table
let element = layui.element;
let xmSelect = layui.xmSelect;
let tagsInput = layui.tagsInput;
form.on('submit(updateGoodsLabel)', function (data) {
if (data.field.type == 1 && data.field.sku_tags === '') {
}
admin.showLoading({
type: 3
});
let url = '/api/sku/BatchUpdateGoodsLabel';
$.ajax({
url: url,
type: 'POST',
async: true,
data: data.field,
dataType: 'json',
timeout: 20000,
success: function (res) {
admin.removeLoading();
if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6});
setTimeout(function () {
admin.closeThisDialog();
},1000);
} else {
layer.msg(res.err_msg, {icon: 5});
}
},
error: function () {
admin.removeLoading();
layer.msg('网络错误', {icon: 5});
}
});
return false;
});
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
form.on('radio(type)', function (data) {
if (data.value === '1') {
$('#supplier_select_div').hide();
}else{
$('#supplier_select_div').show();
}
});
});
</script>
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
Split(['#s1', '#s2', '#s3'], {sizes: [7, 12, 8], minSize: 70}); Split(['#s1', '#s2', '#s3'], {sizes: [7, 12, 8], minSize: 70});
let table = layui.table; let table = layui.table;
let form = layui.form; let form = layui.form;
let layer = layui.layer;
let admin = layui.admin; let admin = layui.admin;
let xmSelect = layui.xmSelect; let xmSelect = layui.xmSelect;
let initCondition = {source_type: 'all'}; let initCondition = {source_type: 'all'};
...@@ -223,7 +224,7 @@ ...@@ -223,7 +224,7 @@
skuIds.push(value.goods_id); skuIds.push(value.goods_id);
}); });
if (skuIds.length === 0) { if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5}); layer.msg('请选择要操作的sku');
return; return;
} }
batchUpdateGoodsStatus(skuIds, 'passed'); batchUpdateGoodsStatus(skuIds, 'passed');
...@@ -238,7 +239,7 @@ ...@@ -238,7 +239,7 @@
skuIds.push(value.goods_id); skuIds.push(value.goods_id);
}); });
if (skuIds.length === 0) { if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5}); layer.msg('请选择要操作的sku');
return; return;
} }
batchUpdateGoodsStatus(skuIds, 'offshelf'); batchUpdateGoodsStatus(skuIds, 'offshelf');
...@@ -253,7 +254,7 @@ ...@@ -253,7 +254,7 @@
skuIds.push(value.goods_id); skuIds.push(value.goods_id);
}); });
if (skuIds.length === 0) { if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5}); layer.msg('请选择要操作的sku');
return; return;
} }
batchSetSkuPrefer(skuIds, 'set_prefer'); batchSetSkuPrefer(skuIds, 'set_prefer');
...@@ -268,7 +269,7 @@ ...@@ -268,7 +269,7 @@
skuIds.push(value.goods_id); skuIds.push(value.goods_id);
}); });
if (skuIds.length === 0) { if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5}); layer.msg('请选择要操作的sku');
return; return;
} }
batchSetSkuPrefer(skuIds, 'cancel_set_prefer'); batchSetSkuPrefer(skuIds, 'cancel_set_prefer');
...@@ -431,9 +432,24 @@ ...@@ -431,9 +432,24 @@
}); });
$("#set_sku_tag").click(function () { $("#set_sku_tag").click(function () {
// if (!isAdmin) {
// let now = new Date();
// let currentHour = now.getHours(); //获取当前小时数(0-23)
// let currentDay = now.getDay(); // 获取当前星期几(0为周日,1为周一,...6为周六)
// if (currentDay !== 0 && currentDay !== 6) { // 排除周六(6)和周日(0)
// if (currentHour >= 9 && currentHour < 18) {
// layer.msg('现在是工作时间,请下班后进行操作。');
// return false;
// }
// }
// }
let checkStatus = table.checkStatus('skuList'); let checkStatus = table.checkStatus('skuList');
let data = checkStatus.data; let data = checkStatus.data;
let skuIds = Array.from(data, ({goods_id}) => goods_id); let skuIds = Array.from(data, ({goods_id}) => goods_id);
// if (skuIds.length === 0) {
// layer.msg('请选择要操作的sku');
// return false;
// }
skuIds = skuIds.join(','); skuIds = skuIds.join(',');
layer.open({ layer.open({
type: 2, type: 2,
...@@ -441,12 +457,30 @@ ...@@ -441,12 +457,30 @@
area: ['800px', '600px'], area: ['800px', '600px'],
title: '批量设置SKU标签', title: '批量设置SKU标签',
end: function () { end: function () {
table.reload('skuList'); // table.reload('skuList');
// supplierStatistics(); // supplierStatistics();
} }
}); });
}); });
$("#update_goods_label").click(function () {
let checkStatus = table.checkStatus('skuList');
let data = checkStatus.data;
let skuIds = Array.from(data, ({goods_id}) => goods_id);
skuIds = skuIds.join(',');
layer.open({
type: 2,
content: '/sku/BatchUpdateGoodsLabel?view=iframe&sku_ids=' + skuIds,
area: ['800px', '600px'],
title: '批量设置SKU显示类型',
end: function () {
// table.reload('skuList');
// supplierStatistics();
}
});
});
$("#set_sku_cp_time_ruler").click(function () { $("#set_sku_cp_time_ruler").click(function () {
layer.open({ layer.open({
type: 2, type: 2,
......
...@@ -2,3 +2,10 @@ ...@@ -2,3 +2,10 @@
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script> <script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script> <script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/inspinia.min.js"></script> <script src="/js/inspinia.min.js"></script>
<script>
var isAdmin = false;
@if(!empty(request()->user->userId) && request()->user->userId==1000)
isAdmin = true;
@endif
</script>
...@@ -5,11 +5,59 @@ ...@@ -5,11 +5,59 @@
</style> </style>
<form class="layui-form" action=""> <form class="layui-form" action="">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-header" style="height: 230px"> <div class="layui-card-header" style="height: 100%">
@if(request()->get('sku_ids'))
<div id="selected_sku_id">
<blockquote class="layui-elem-quote layui-text">
<b>选择的sku</b>
</blockquote>
<div class="layui-form-item">
<table class="layui-table">
{{-- <thead>--}}
{{-- <tr>--}}
{{-- <th>商品ID</th>--}}
{{-- </tr>--}}
{{-- </thead>--}}
<tbody>
@foreach($skuIds as $skuId)
<tr>
<td>{{$skuId}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
<blockquote class="layui-elem-quote layui-text"> <blockquote class="layui-elem-quote layui-text">
<b>设置标签</b> <b>设置标签</b>
</blockquote> </blockquote>
<input type="hidden" name="sku_ids" id="sku_ids" value="{{request()->get('sku_ids')}}"> <input type="hidden" name="sku_ids" id="sku_ids" value="{{request()->get('sku_ids')}}">
<div class="layui-form-item">
<div class="layui-input-block" style="margin-left: -30px">
<div class="layui-form-item">
<label class="layui-form-label">
设置方式 : </label>
<div class="layui-input-block" style="margin-top: 10px">
<input type="radio" lay-filter="type" name="type" value="1" title="按型号" checked>
<input type="radio" lay-filter="type" name="type" value="2" title="按供应商">
</div>
</div>
</div>
</div>
<div class="layui-form-item" id="supplier_select_div" style="display: none">
<div class="layui-inline" style="margin-left: -30px">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('supplier_code','供应商选择 : ',null,
$supplierCodes,['required'=>true,'width'=>'400px']) !!}
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-input-block" style="margin-left: -30px"> <div class="layui-input-block" style="margin-left: -30px">
<div class="layui-form-item"> <div class="layui-form-item">
...@@ -21,11 +69,11 @@ ...@@ -21,11 +69,11 @@
<input type="hidden" name="sku_tags" <input type="hidden" name="sku_tags"
id="sku_tags"> id="sku_tags">
</div> </div>
<span style="margin-left: 110px">选择标签会覆盖原有标签</span> <span
style="margin-left: 110px;color: red">选择标签会覆盖原有标签.如果没有选择任何标签点击确认将把原标签全部删除</span>
</div> </div>
</div> </div>
</div> </div>
<div class="layui-form-item">
<div align="center" style="margin-top: 10px;text-align: right"> <div align="center" style="margin-top: 10px;text-align: right">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit <button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
lay-filter="addSkuTag">确认 lay-filter="addSkuTag">确认
......
<style>
.layui-form-item {
margin-bottom: 5px;
}
</style>
<form class="layui-form" action="">
<div class="layui-card">
<div class="layui-card-header" style="height: 400px">
<blockquote class="layui-elem-quote layui-text">
<b>设置标签</b>
</blockquote>
<input type="hidden" name="sku_ids" id="sku_ids" value="{{request()->get('sku_ids')}}">
<div class="layui-form-item">
<div class="layui-input-block" style="margin-left: -30px">
<div class="layui-form-item">
<label class="layui-form-label">
设置方式 : </label>
<div class="layui-input-block" style="margin-top: 10px">
<input type="radio" lay-filter="type" name="type" value="1" title="按型号" checked>
<input type="radio" lay-filter="type" name="type" value="2" title="按供应商">
</div>
</div>
</div>
</div>
<div class="layui-form-item" id="supplier_select_div" style="display: none">
<div class="layui-inline" style="margin-left: -30px">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('supplier_code','供应商选择 : ',null,
$supplierCodes,['required'=>true,'width'=>'400px']) !!}
</div>
</div>
<div class="layui-form-item" style="margin-left: -50px">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('goods_label','SKU显示类型 : ',null,
config('field.SkuGoodsLabel'),['required'=>true,'label_width'=>'100px']) !!}
</div>
<div align="center" style="margin-top: 10px;text-align: right">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
lay-filter="updateGoodsLabel">确认
</button>
<button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit
lay-filter="cancel">取消
</button>
</div>
</div>
</div>
</div>
</form>
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
@if (checkPerm('BatchUpdateEncoded')) @if (checkPerm('BatchUpdateEncoded'))
<button type="button" class="layui-btn layui-btn-sm" id="batch_update_encoded">批量修改内部编码</button> <button type="button" class="layui-btn layui-btn-sm" id="batch_update_encoded">批量修改内部编码</button>
@endif @endif
<button type="button" class="layui-btn layui-btn-sm" id="set_prefer">设置精选</button> {{-- <button type="button" class="layui-btn layui-btn-sm" id="set_prefer">设置精选</button>--}}
<button type="button" class="layui-btn layui-btn-sm" id="cancel_set_prefer">取消精选</button> {{-- <button type="button" class="layui-btn layui-btn-sm" id="cancel_set_prefer">取消精选</button>--}}
<button type="button" class="layui-btn layui-btn-sm" id="sync_erp_rate">同步ERP汇率</button> <button type="button" class="layui-btn layui-btn-sm" id="sync_erp_rate">同步ERP汇率</button>
<button type="button" class="layui-btn layui-btn-sm" id="set_sku_tag">设置标签</button> <button type="button" class="layui-btn layui-btn-sm" id="set_sku_tag">设置标签</button>
@if (checkPerm('SetSupplierSkuCpTimeLimit')) @if (checkPerm('SetSupplierSkuCpTimeLimit'))
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
@if(checkPerm('UpdateSku')) @if(checkPerm('UpdateSku'))
<button type="button" class="layui-btn layui-btn-sm" id="update_sku">修改商品信息</button> <button type="button" class="layui-btn layui-btn-sm" id="update_sku">修改商品信息</button>
@endif @endif
<button type="button" class="layui-btn layui-btn-sm" id="update_goods_label">设置SKU显示类型</button>
</div> </div>
<table class="layui-table" id="skuList" lay-filter="skuList"></table> <table class="layui-table" id="skuList" lay-filter="skuList"></table>
......
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