Commit d9bda88f by 杨树贤

批量上下架

parent c416660e
......@@ -9,6 +9,7 @@ use App\Http\Services\SupplierStatisticsService;
use App\Http\Transformers\SupplierContactTransformer;
use App\Http\Validators\SupplierContactValidator;
use App\Model\RedisModel;
use App\Model\SkuUploadLogModel;
use App\Model\SupplierContactModel;
use Illuminate\Http\Request;
......@@ -58,36 +59,52 @@ class SkuApiController extends Controller
$supplierCode = $request->get('supplier_code');
$brandId = $request->get('brand_ids');
$brandId = str_replace(',', '', $brandId);
$updateTime = $request->get('update_time');
// $updateTime = $request->get('update_time');
if (empty($supplierCode)) {
$this->response(-1, '请选择供应商');
}
$startTime = $endTime = 0;
if ($updateTime) {
$updateTime = explode('~', $updateTime);
$startTime = $updateTime[0];
$endTime = $updateTime[1];
}
// $startTime = $endTime = 0;
// if ($updateTime) {
// $updateTime = explode('~', $updateTime);
// $startTime = $updateTime[0];
// $endTime = $updateTime[1];
// }
$uploadLogId = SkuUploadLogModel::where('supplier_code',$supplierCode)
->where('status',SkuUploadLogModel::STATUS_HANDLED)->value('id');
$map = [
$data = [
'supplier_code' => $supplierCode,
'brand_id' => $brandId,
'start_time' => $startTime,
'end_time' => $endTime,
'upload_log_id' => $uploadLogId,
];
$url = env('FOOTSTONE_URL') . '/uploadSkuApi/batchOffShelf';
$userId = $request->cookie('oa_user_id');
$sKey = $request->cookie('oa_skey');
$cookie = 'oa_user_id=' . $userId . '; oa_skey=' . $sKey;
$result = curl($url, $map, true, false, $cookie);
$result = json_decode($result, true);
if (isset($result['errcode']) && $result['errcode'] === 0) {
$this->response(0, '批量下架任务已经发送,请等待任务完成,期间你可以刷新列表查看下架情况');
} else {
$this->response(-1, '批量下架失败');
//改成队列
(new SkuService())->batchOffShelfSkuQueue($data);
$this->response(0, '批量下架任务已经发送,请等待任务完成,期间你可以刷新列表查看下架情况');
}
//批量上下架
public function batchUpdateSkuStatus(Request $request)
{
$data = $request->only([
'sku_ids',
'is_long_term',
'operate_type',
'cp_time',
]);
if ($data['operate_type'] == SkuService::OPERATE_TYPE_PUTAWAY) {
if ($data['is_long_term'] == -1 && empty($data['cp_time'])) {
return $this->setError('请设置上架有效期');
}
}
(new SkuService())->batchUpdateSkuStatus($data);
return $this->setSuccess('操作成功,请等待后台上下架任务完成刷新查看');
}
//设置精选Sku
public function SetPreferSku($request)
{
......@@ -97,7 +114,7 @@ class SkuApiController extends Controller
$this->response(-1, '请选择要操作的SKU', '0');
}
$skuService = new SkuService();
$result = $skuService->setPreferSku($skuIds,$prefer);
$result = $skuService->setPreferSku($skuIds, $prefer);
if ($result) {
$this->response(0, '操作成功');
} else {
......
<?php
namespace App\Http\Services;
use App\Http\Models\Cms\ConfigModel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class QueueService
{
public static function publishQueue($queueName, $data)
{
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
$channel = $conn->channel();
$channel->queue_declare($queueName, false, true, false, false);
$msg = new AMQPMessage(json_encode($data),
array('content_type' => 'text/plain'));
$channel->basic_publish($msg, '', $queueName);
}
}
......@@ -7,9 +7,17 @@ use App\Http\Controllers\Filter\SkuListFilter;
use App\Model\IntracodeModel;
use App\Model\RedisModel;
use Illuminate\Support\Facades\DB;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class SkuService
{
const OPERATE_TYPE_PUTAWAY = 1;
const OPERATE_TYPE_OFF_SHELVES = -1;
const LONG_TERM_TIMESTAMP = 2051193600;
//获取供应商列表需要统计的信息
public function getSkuList()
{
......@@ -141,4 +149,46 @@ class SkuService
$result = $redis->hget('goods_tag', $skuId);
return $result ? json_decode($result, true) : [];
}
//批量上下架队列
public function batchOffShelfSkuQueue($data)
{
$conn = new AMQPStreamConnection(config('database.connections.rabbitmq.host'),
config('database.connections.rabbitmq.port'),
config('database.connections.rabbitmq.login'),
config('database.connections.rabbitmq.password'));
$channel = $conn->channel();
$channel->queue_declare('test_batch_update_goods_status', false, true, false, false);
$msg = new AMQPMessage(json_encode($data),
array('content_type' => 'text/plain'));
$channel->basic_publish($msg, '', 'test_batch_update_goods_status');
}
//批量更新sku状态,走队列的
public function batchUpdateSkuStatus($data)
{
try {
$skuIds = explode(',', $data['sku_ids']);
//构建队列数据
//上架
$queueData = [];
if ($data['operate_type'] == self::OPERATE_TYPE_PUTAWAY) {
$data['cp_time'] = $data['is_long_term'] == 1 ? self::LONG_TERM_TIMESTAMP : strtotime($data['cp_time']);
foreach ($skuIds as $skuId) {
$queueData[] = [
'sku_id' => $skuId,
'cp_time' => $data['cp_time'],
];
}
} else {
$queueData['down_type'] = 2;
$queueData['data'] = $skuIds;
}
QueueService::publishQueue('test_update_goods_status', $queueData);
} catch (\Exception $exception) {
return $exception;
}
return true;
}
}
\ No newline at end of file
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class SkuUploadLogModel extends Model
{
protected $table='sku_upload_log';
protected $primaryKey = 'id';
protected $connection = 'spu';
public $timestamps = false;
const STATUS_HANDLED = 3;
}
<script>
layui.use(['table', 'form', 'laydate', 'layer', 'upload', 'element', 'admin'], function () {
let form = layui.form;
let admin = layui.admin;
let table = layui.table;
let element = layui.element;
let upload = layui.upload;
let layer = layui.layer;
let laydate = layui.laydate;
let $ = layui.$;
laydate.render({
elem: '#cp_time_selector', //指定元素
type: 'datetime'
});
form.render();
form.on('switch(is_long_term)', function (data) {
let element = $('#cp_time_selector');
if (data.elem.checked) {
element.addClass('layui-disabled');
element.attr('disabled', true);
form.render();
} else {
element.removeClass('layui-disabled');
element.attr('disabled', false);
form.render();
}
});
form.on('submit(batchUpdateSkuStatus)', function (data) {
let operate = data.field.operate_type > 0 ? '上架' : '下架';
layer.confirm('确定要' + operate + '商品吗', function (index) {
const url = '/api/sku/batchUpdateSkuStatus';
$.post(url, {
sku_ids: data.field.sku_ids,
is_long_term: data.field.is_long_term ? 1 : 0,
operate_type: data.field.operate_type,
cp_time: data.field.cp_time
}, function (res) {
if (res.code === 0) {
admin.closeThisDialog();
parent.layer.msg("修改成功", {icon: 6});
} else {
layer.msg(res.msg);
}
});
});
});
form.on('submit(cancel)', function (data) {
admin.closeThisDialog();
});
});
</script>
......@@ -231,38 +231,47 @@
});
//批量上下架操作
function batchUpdateGoodsStatus(skuId, status) {
function batchUpdateGoodsStatus(skuIds, status) {
let statusName = status === 'offshelf' ? '下架' : '上架';
layer.confirm('确定要' + statusName + "选中的这些商品吗", function (index) {
$.ajax({
type: 'post',
url: '/api/sku/UpdateSkuStatus',
timeout: 30000, //超时时间设置,单位毫秒
data: {
goods_id: skuId,
status: status
},
dataType: 'json',
success: function (resp) {
close();
if (!resp) {
layer.msg('网络连接失败', {icon: 5});
return false;
}
if (resp.err_code === 0) {
layer.msg('操作成功', {icon: 6});
let operateType = status === 'offshelf' ? '-1' : '1';
if (status !== 'offshelf') {
layer.open({
type: 2,
area: ['600px', '500px'],
offset: '100px',
fixed: false, //不固定
maxmin: true,
content: '/web/sku/batchUpdateSkuStatus?window=true&sku_ids=' + skuIds + '&operate_type=' + operateType,
title: statusName + '商品',
end: function () {
table.reload('skuList', {
page: {
curr: currentPage
},
});
}
});
}else{
layer.confirm('确定要下架选中的商品吗', function (index) {
$.post('/api/sku/batchUpdateSkuStatus', {
'sku_ids': skuIds.join(','),
'operate_type': -1,
}, function (res) {
if (res.code === 0) {
layer.msg(res.msg, {icon: 6});
table.reload('skuList', {
page: {
curr: currentPage
},
});
} else {
}else{
layer.msg(res.msg, {icon: 5});
return false;
}
}
});
});
layer.closeAll();
});
}
}
//批量设置精选
......
......@@ -26,12 +26,12 @@
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline" style="margin-left: -30px">
@inject('timeIntervalPresenter','App\Presenters\TimeIntervalPresenter')
{!! $timeIntervalPresenter->render('update_time','更新时间 : ') !!}
</div>
</div>
{{-- <div class="layui-form-item">--}}
{{-- <div class="layui-inline" style="margin-left: -30px">--}}
{{-- @inject('timeIntervalPresenter','App\Presenters\TimeIntervalPresenter')--}}
{{-- {!! $timeIntervalPresenter->render('update_time','更新时间 : ') !!}--}}
{{-- </div>--}}
{{-- </div>--}}
<div class="layui-form-item">
<div align="center" style="margin-top: 20px;text-align: right">
<button type="button" class="layui-btn layui-btn-sm layui-btn-info submit-loading" lay-submit
......
<div style="padding: 30px;">
<form class="layui-form">
<input type="hidden" name="sku_ids" value="{{request()->get('sku_ids')}}">
<input type="hidden" name="operate_type" value="{{request()->get('operate_type')}}">
<div class="layui-form-item">
<label class="layui-form-label"><span style="color: red">* </span>上架有效期:</label>
<div class="layui-input-inline">
<input type="text" class="layui-input" name="cp_time" id="cp_time_selector">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">长期有效:</label>
<div class="layui-input-inline">
<input type="checkbox" name="is_long_term" id="is_long_term" lay-filter="is_long_term" lay-skin="switch"
lay-text="是|否">
</div>
</div>
<div class="layui-form-item" style="margin-left: 260px;padding-bottom: 30px;margin-top:220px;">
<div class="layui-input-block">
<button type="button" class="layui-btn layui-btn-sm" lay-submit lay-filter="batchUpdateSkuStatus">确定
</button>
<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="cancel">取消</button>
</div>
</div>
</form>
</div>
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