Commit 39152d95 by 杨树贤

批量修改

parent 9bff5b8e
......@@ -7,6 +7,7 @@ use App\Http\Services\SkuService;
use App\Model\SkuUploadLogModel;
use App\Model\SupplierChannelModel;
use Illuminate\Http\Request;
use function GuzzleHttp\Promise\all;
//通用API,比如获取品牌列表,分类列表等
class SkuApiController extends Controller
......@@ -171,10 +172,46 @@ class SkuApiController extends Controller
//批量新增标签
public function BatchAddSkuTag($request)
{
$type = $request->input('type');
$supplierCode = $request->input('supplier_code');
$skuIds = $request->get('sku_ids');
$skuTags = $request->get('sku_tags');
(new SkuService())->batchAddSkuTags($skuIds, $skuTags);
$this->response(0, '设置标签成功');
if ($type == 1 && empty($skuIds)) {
$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
{
$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标签');
}
//批量设置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)
{
......
......@@ -83,9 +83,9 @@ class SkuService
}
}
}
$standardBrandId = array_get($spu,'s_brand_id');
$standardBrandId = array_get($spu, 's_brand_id');
if ($standardBrandId) {
$standardBrand = $redis->hget('standard_brand',$standardBrandId);
$standardBrand = $redis->hget('standard_brand', $standardBrandId);
$standardBrand = json_decode($standardBrand, true);
$sku['standard_brand_name'] = $standardBrand['brand_name'];
}
......@@ -257,6 +257,20 @@ class SkuService
$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状态,走队列的
public function batchUpdateSkuStatus($data)
{
......@@ -353,8 +367,11 @@ class SkuService
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();
$skuIds = explode(',', $skuIds);
$skuTags = explode(',', $skuTags);
......@@ -372,6 +389,14 @@ class SkuService
$redis->hset('goods_tag', $skuId, json_encode($goodsTag));
$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
{
}
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 [
1 => '国内现货',
2 => '国际现货',
3 => '猎芯期货',
4 => '询价现货',
5 => '原厂直售',
6 => '猎芯精选',
//-1 => '代购现货'
],
//SKU 标签
......
......@@ -8,6 +8,16 @@
let tagsInput = layui.tagsInput;
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({
type: 3
});
......@@ -23,24 +33,37 @@
success: function (res) {
admin.removeLoading();
if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6});
setTimeout(function () {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
}, 1000);
} else {
parent.layer.msg(res.err_msg, {icon: 5});
layer.msg(res.err_msg, {icon: 5});
}
},
error: function () {
admin.removeLoading();
parent.layer.msg('网络错误', {icon: 5});
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();
$('#selected_sku_id').show();
} else {
$('#supplier_select_div').show();
$('#selected_sku_id').hide();
}
});
function getTagOption(element) {
//获取系统标签列表
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 @@
Split(['#s1', '#s2', '#s3'], {sizes: [7, 12, 8], minSize: 70});
let table = layui.table;
let form = layui.form;
let layer = layui.layer;
let admin = layui.admin;
let xmSelect = layui.xmSelect;
let initCondition = {source_type: 'all'};
......@@ -223,7 +224,7 @@
skuIds.push(value.goods_id);
});
if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5});
layer.msg('请选择要操作的sku');
return;
}
batchUpdateGoodsStatus(skuIds, 'passed');
......@@ -238,7 +239,7 @@
skuIds.push(value.goods_id);
});
if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5});
layer.msg('请选择要操作的sku');
return;
}
batchUpdateGoodsStatus(skuIds, 'offshelf');
......@@ -253,7 +254,7 @@
skuIds.push(value.goods_id);
});
if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5});
layer.msg('请选择要操作的sku');
return;
}
batchSetSkuPrefer(skuIds, 'set_prefer');
......@@ -268,7 +269,7 @@
skuIds.push(value.goods_id);
});
if (skuIds.length === 0) {
layer.msg('请选择要操作的sku', {icon: 5});
layer.msg('请选择要操作的sku');
return;
}
batchSetSkuPrefer(skuIds, 'cancel_set_prefer');
......@@ -431,9 +432,24 @@
});
$("#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 data = checkStatus.data;
let skuIds = Array.from(data, ({goods_id}) => goods_id);
// if (skuIds.length === 0) {
// layer.msg('请选择要操作的sku');
// return false;
// }
skuIds = skuIds.join(',');
layer.open({
type: 2,
......@@ -441,12 +457,30 @@
area: ['800px', '600px'],
title: '批量设置SKU标签',
end: function () {
table.reload('skuList');
// table.reload('skuList');
// 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 () {
layer.open({
type: 2,
......
......@@ -2,3 +2,10 @@
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.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 @@
</style>
<form class="layui-form" action="">
<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">
<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">
<div class="layui-input-block" style="margin-left: -30px">
<div class="layui-form-item">
......@@ -21,11 +69,11 @@
<input type="hidden" name="sku_tags"
id="sku_tags">
</div>
<span style="margin-left: 110px">选择标签会覆盖原有标签</span>
<span
style="margin-left: 110px;color: red">选择标签会覆盖原有标签.如果没有选择任何标签点击确认将把原标签全部删除</span>
</div>
</div>
</div>
<div class="layui-form-item">
<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="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 @@
@if (checkPerm('BatchUpdateEncoded'))
<button type="button" class="layui-btn layui-btn-sm" id="batch_update_encoded">批量修改内部编码</button>
@endif
<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="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="set_sku_tag">设置标签</button>
@if (checkPerm('SetSupplierSkuCpTimeLimit'))
......@@ -44,6 +44,7 @@
@if(checkPerm('UpdateSku'))
<button type="button" class="layui-btn layui-btn-sm" id="update_sku">修改商品信息</button>
@endif
<button type="button" class="layui-btn layui-btn-sm" id="update_goods_label">设置SKU显示类型</button>
</div>
<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