Commit 2cb12144 by 杨树贤

转移供应商联系人完成

parent 04172cec
...@@ -174,12 +174,52 @@ class SupplierContactApiController extends Controller ...@@ -174,12 +174,52 @@ class SupplierContactApiController extends Controller
} }
//转移供应商联系人 //转移供应商联系人
public function TransferSupplierContact($supplierId, $originCanCheckUid, $newCanCheckUid) public function TransferSupplierContact($request)
{ {
return DB::connection('web')->transaction(function () use ($supplierId, $originCanCheckUid, $newCanCheckUid) { $supplierId = $request->input('supplier_id');
//直接去批量修改即可 $originCanCheckUids = $request->input('can_check_uids');
return SupplierContactModel::where('supplier_id', $supplierId)->where('can_check_uids', $originCanCheckUid) $newCanCheckUids = $request->input('new_can_check_uids');
->update(['can_check_uids' => $newCanCheckUid]);
if (empty($supplierId)) {
$this->response(-1, '供应商id不能为空');
}
if (empty($originCanCheckUids) || empty($newCanCheckUids)) {
$this->response(-1, '采购员信息不完整');
}
DB::connection('web')->transaction(function () use ($supplierId, $originCanCheckUids, $newCanCheckUids) {
//还要先去判断这个人是否存在于采购员里面,不存在的话还要去新增
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first()->toArray();
$channelUid = explode(',', $supplier['channel_uid']);
if (in_array($originCanCheckUids, $channelUid)) {
//删除
$channelUid = array_filter($channelUid, function ($value) use ($originCanCheckUids) {
return $value != $originCanCheckUids;
});
}
if (!in_array($newCanCheckUids, $channelUid)) {
$channelUid[] = $newCanCheckUids;
}
DB::connection('web')->transaction(function () use ($supplierId, $channelUid, $originCanCheckUids, $newCanCheckUids) {
//还要判断是否是芯链采购员
if (SupplierChannelModel::where('yunxin_channel_uid', $originCanCheckUids)->where('supplier_id', $supplierId)
->exists()) {
SupplierChannelModel::where('supplier_id', $supplierId)->update(['yunxin_channel_uid' => $newCanCheckUids]);
}
SupplierChannelModel::where('supplier_id', $supplierId)->update([
'channel_uid' => implode(',', $channelUid),
]);
//最后直接去批量修改即可
return SupplierContactModel::where('supplier_id', $supplierId)->where('can_check_uids', $originCanCheckUids)
->update(['can_check_uids' => $newCanCheckUids]);
});
}); });
$this->response(0, '转移供应商联系人成功');
} }
} }
...@@ -5,23 +5,31 @@ ...@@ -5,23 +5,31 @@
let table = layui.table let table = layui.table
let element = layui.element; let element = layui.element;
form.on('submit(blockSupplier)', function (data) { form.on('submit(transferSupplier)', function (data) {
admin.showLoading({ admin.showLoading({
type: 3, type: 3,
}); });
let url = '/api/supplier/transferSupplier?supplier_id=' + getQueryVariable('supplier_id'); let url = '/api/supplier_contact/TransferSupplierContact?supplier_id=' + getQueryVariable('supplier_id');
let res = ajax(url, data); let res = $.get(url, data.field, function (res) {
if (!res) { if (!res) {
admin.removeLoading(); admin.removeLoading();
layer.msg('网络错误,请重试', {icon: 6}); layer.msg('网络错误,请重试', {icon: 6});
} else {
if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6});
} else { } else {
admin.removeLoading(); admin.removeLoading();
layer.msg(res.err_msg, {icon: 5}); res = JSON.parse(res);
if (res.err_code === 0) {
layer.msg(res.err_msg, {icon: 6});
setTimeout(function () {
admin.closeThisDialog();
},500);
} else {
admin.removeLoading();
layer.msg(res.err_msg, {icon: 5});
return false;
}
} }
} });
return false; return false;
}); });
}); });
......
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