Commit 52202507 by 杨树贤

批量修改采购员

parent cc223814
......@@ -417,6 +417,32 @@ class SupplierApiController extends Controller
$this->response(0, '添加采购员成功');
}
//分配采购员(支持批量操作)
public function BatchAllocateChannelUser($request)
{
$channelUid = $request->get('channel_uid');
$supplierIds = $request->get('supplier_ids');
if (empty($channelUid)) {
$this->response(-1, '采购员不能为空');
}
$adminService = new AdminUserService();
$check = $adminService->checkIsResignedByCodeId($channelUid);
if ($check) {
$this->response(-1, '该采购员已经离职,请选择其他人员');
}
$supplierIds = explode(',', $supplierIds);
$model = new SupplierChannelModel();
foreach ($supplierIds as $supplierId) {
$service = new SupplierService();
$result = $service->allocateChannelUser($supplierId, $channelUid);
if (!$result) {
$this->response(-1, '添加采购员失败');
}
}
$this->response(0, '添加采购员成功');
}
//转正供应商
public function ChangeSupplierIsType($request)
{
......
......@@ -272,16 +272,17 @@ class SupplierController extends Controller
return $this->view('批量分配渠道开发员');
}
//添加采购员
//批量添加采购员
public function AllocateChannelUser($request)
{
$supplierId = $request->get('supplier_id');
$supplierIds = $request->get('supplier_ids');
$this->data['supplierIds'] = $supplierIds;
$supplierIds = explode(',', $supplierIds);
$model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first();
$supplier = $supplier ? $supplier->toArray() : [];
$suppliers = $model->whereIn('supplier_id', $supplierIds)->get()->toArray();
$transformer = new SupplierTransformer();
$supplier = $transformer->transformInfo($supplier);
$this->data['supplier'] = $supplier;
$suppliers = $transformer->transformList($suppliers);
$this->data['suppliers'] = $suppliers;
$intraCodeModel = new IntracodeModel();
$this->data['userCodes'] = $intraCodeModel->getChannelUsersEncode(false);
return $this->view('添加采购员');
......
......@@ -427,6 +427,16 @@ class SupplierService
//分配采购员
public function allocateChannelUser($supplierId, $channelUid, $logFlag = true)
{
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if (empty($supplier)) {
return true;
}
$supplier = $supplier->toArray();
$preChannelUid = explode(',', $supplier['channel_uid']);
//如果之前已经存在对应的采购,直接返回
if (in_array($channelUid, $preChannelUid)) {
return true;
}
$result = DB::connection('web')->transaction(function () use ($supplierId, $channelUid, $logFlag) {
$model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first();
......@@ -460,7 +470,7 @@ class SupplierService
$contactResult = $contactModel->insert($contact);
}
if ($contactResult && $logFlag) {
//判断是否是非正式供应商,如果是,自动转正,并且修改为待审核状态
//判断是否是非正式(is_type=1)供应商,如果是,自动转正,并且修改为待审核状态
$this->autoChangeIsType($supplier);
//记录日志
$adminUserService = new AdminUserService();
......
......@@ -4,47 +4,33 @@
let form = layui.form;
let table = layui.table
let element = layui.element;
table.render({
elem: '#logList'
, url: '/api/log/GetLogList'
, method: 'post'
, size: 'sm'
, limit: 10
, cellMinWidth: 80 //全局定义常规单元格的最小宽度
, where: {
supplier_id:{{$supplier['supplier_id']}},
action: '添加采购员',
}
, loading: true
, first: true //不显示首页
, last: false //不显示尾页
, cols: [[
{field: 'add_time', title: '日志时间', width: 150, align: 'center'},
{
field: 'content', title: '日志内容', align: 'center', templet: function (data) {
return data.admin_name + data.content;
form.on('submit(auditSupplier)', function (data) {
admin.showLoading({
type: 3,
});
let supplierIds = getQueryVariable('supplier_ids');
let url = '/api/supplier/BatchAllocateChannelUser?supplier_ids=' + supplierIds;
$.ajax({
url: url,
type: 'GET',
async: true,
data: data.field,
dataType: 'json',
timeout: 20000,
success: function (res) {
if (res.err_code === 0) {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
admin.removeLoading();
parent.layer.msg(res.err_msg, {icon: 5});
}
},
]]
, id: 'logList'
, page: {}
});
form.on('submit(auditSupplier)', function (data) {
admin.btnLoading('.submit-loading');
let supplierId = getQueryVariable('supplier_id');
let url = '/api/supplier/AllocateChannelUser?supplier_id=' + supplierId;
let res = ajax(url, data.field);
if (!res) {
layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
admin.closeThisDialog();
parent.layer.msg(res.err_msg, {icon: 6});
} else {
admin.btnLoading('.submit-loading',false);
parent.layer.msg(res.err_msg, {icon: 5});
error: function () {
admin.removeLoading();
parent.layer.msg('网络错误', {icon: 5});
}
}
});
return false;
});
form.on('submit(cancel)', function (data) {
......
......@@ -413,36 +413,41 @@
})
//分配采购员
//分配采购员,现在改成可以批量的了
$("#allocate_channel_user").click(function () {
let checkStatus = table.checkStatus('list');
let data = checkStatus.data;
if (!data.length) {
layer.msg('请先选择要操作的供应商', {icon: 5})
} else {
if (data.length > 1) {
layer.msg('该操作不支持多选', {icon: 5})
return;
}
const status = data[0].status;
if ((status !== -1 || status !== 1)) {
let supplierId = data[0].supplier_id;
let status = Array.from(data, ({status}) => status);
let canApplyInReview = true;
$.each(status, function (index, value) {
console.log(value);
if (value === -1 || value === 1) {
canApplyInReview = false;
}
});
if (!canApplyInReview) {
layer.msg('选择的供应商里,存在 审核中/待复审 状态的供应商,无法申请审核', {icon: 5})
} else {
let supplierIds = Array.from(data, ({supplier_id}) => supplier_id);
if (supplierIds.length > 20) {
layer.msg('最多一次操作20个供应商', {icon: 5})
return;
}
supplierIds = supplierIds.join(',');
layer.open({
type: 2,
content: '/supplier/AllocateChannelUser?view=iframe&supplier_id=' + supplierId,
area: ['650px', '80%'],
content: '/supplier/AllocateChannelUser?view=iframe&supplier_ids=' + supplierIds,
area: ['80%', '80%'],
title: '新增采购员',
end: function () {
saveRefreshData('detail', supplierId)
table.reload('list');
supplierStatistics();
}
});
} else {
layer.msg('审核中/待复审状态的供应商无法分配采购员', {icon: 5})
return false;
}
}
})
......
......@@ -4,37 +4,21 @@
}
</style>
<div class="layui-card">
<div class="layui-card-header" style="height: 90px">
<div class="layui-row">
<div class="layui-col-xs6">
供应商名称 : <b>{{$supplier['supplier_name']}}</b>
</div>
<div class="layui-col-xs6">
状态 : {{$supplier['status_name']}}
</div>
<div class="layui-col-xs6">
公司性质 : {{$supplier['supplier_group_name']}}
</div>
<div class="layui-col-xs6">
合作类型 : {{$supplier['stockup_type']}}
</div>
<div class="layui-col-xs12">
当前采购 : {{$supplier['channel_username']}}
</div>
</div>
</div>
<div class="layui-card-body">
<div class="layui-card-header" style="height: 170px">
<blockquote class="layui-elem-quote layui-text">
<b>采购员设置</b>
</blockquote>
<form class="layui-form" action="">
<input type="hidden" name="supplier_id" value="{{$supplier['supplier_id']}}">
<input type="hidden" name="supplier_ids" value="{{$supplierIds}}">
<div class="layui-form-item">
<div class="layui-inline" style="margin-left: -30px">
@inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('channel_uid','新增采购员','',
{!! $statusPresenter->render('channel_uid','采购员',null,
$userCodes,['required'=>true,'width'=>'150px']) !!}
</div>
</div>
<div class="layui-form-item">
<div align="center" style="margin-top: 20px;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
lay-filter="auditSupplier">确认
</button>
......@@ -45,13 +29,35 @@
</div>
</form>
</div>
<div class="layui-card-body">
<blockquote class="layui-elem-quote layui-text">
<b style="color: red">注意 : 由于采购和联系人强制绑定的,所以这个页面添加采购,会默认添加一个与其对应空的联系人.</b>
<br>
<b style="margin-left: 35px;color: red">如果想要完善联系人,可以进供应商的修改页面进行修改</b>
</blockquote>
<blockquote class="layui-elem-quote layui-text">
<b>当前选中需要批量新增采购员的供应商列表</b>
</blockquote>
<table class="layui-table">
<colgroup>
<col width="200">
<col width="700">
<col>
</colgroup>
<thead>
<tr>
<th>供应商名称</th>
<th>当前采购员</th>
</tr>
</thead>
<tbody>
@foreach($suppliers as $supplier)
<tr>
<td>{{$supplier['supplier_name']}}</td>
<td>{{$supplier['channel_username']}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
<blockquote class="layui-elem-quote layui-text">
<b>注意 : 由于采购和联系人强制绑定的,所以这个页面添加采购,会默认添加一个与其对应空的联系人.</b>
<br>
<b style="margin-left: 35px">如果想要完善联系人,可以进供应商的修改页面进行修改</b>
</blockquote>
<blockquote class="layui-elem-quote layui-text">
<b>操作日志</b>
</blockquote>
<table class="layui-table" id="logList" lay-filter="logList"></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