Commit b7ef5208 by mushishixian

分配采购员

parent eec48d51
...@@ -100,7 +100,6 @@ class SupplierApiController extends Controller ...@@ -100,7 +100,6 @@ class SupplierApiController extends Controller
$channel = $request->only($channelMap); $channel = $request->only($channelMap);
$service = new SupplierService(); $service = new SupplierService();
$result = $service->saveSupplier($channel); $result = $service->saveSupplier($channel);
dd($result);
if (!$result) { if (!$result) {
$this->response(-1, '操作失败'); $this->response(-1, '操作失败');
} }
...@@ -304,22 +303,31 @@ class SupplierApiController extends Controller ...@@ -304,22 +303,31 @@ class SupplierApiController extends Controller
//分配采购员(支持批量操作) //分配采购员(支持批量操作)
public function AllocateChannelUser($request) public function AllocateChannelUser($request)
{ {
$purchaseUid = $request->get('channel_uid'); $channelUid = $request->get('channel_uid');
$supplierId = $request->get('supplier_id'); $supplierId = $request->get('supplier_id');
if (empty($purchaseUid)) { if (empty($channelUid)) {
$this->response(-1, '采购员不能为空'); $this->response(-1, '采购员不能为空');
} }
$adminService = new AdminUserService(); $adminService = new AdminUserService();
$check = $adminService->checkIsResignedByCodeId($purchaseUid); $check = $adminService->checkIsResignedByCodeId($channelUid);
if ($check) { if ($check) {
$this->response(-1, '该采购员已经离职,请选择其他人员'); $this->response(-1, '该采购员已经离职,请选择其他人员');
} }
$model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first();
$supplier = $supplier ? $supplier->toArray() : [];
$preChannelUid = $supplier['channel_uid'];
$preChannelUid = explode(',', $preChannelUid);
//如果之前已经存在对应的采购,直接返回错误
if (in_array($channelUid, $preChannelUid)) {
$this->response(-1, '此采购员已经存在,请重新选择');
}
$service = new SupplierService(); $service = new SupplierService();
$result = $service->allocatePurchaseUser($supplierId, $purchaseUid); $result = $service->allocateChannelUser($supplierId, $channelUid);
if (!$result) { if (!$result) {
$this->response(-1, '分配采购员失败'); $this->response(-1, '添加采购员失败');
} }
$this->response(0, '分配采购员成功'); $this->response(0, '添加采购员成功');
} }
//转正供应商 //转正供应商
...@@ -335,6 +343,7 @@ class SupplierApiController extends Controller ...@@ -335,6 +343,7 @@ class SupplierApiController extends Controller
$this->response(0, '转正供应商成功'); $this->response(0, '转正供应商成功');
} }
//发送金蝶同步请求
public function SyncToErp($request) public function SyncToErp($request)
{ {
$supplierId = $request->get('supplier_id'); $supplierId = $request->get('supplier_id');
...@@ -344,6 +353,7 @@ class SupplierApiController extends Controller ...@@ -344,6 +353,7 @@ class SupplierApiController extends Controller
$this->response(0, '已发送同步请求'); $this->response(0, '已发送同步请求');
} }
//设置云芯账号
public function SetYunxinChannelUid($request) public function SetYunxinChannelUid($request)
{ {
$supplierId = $request->get('supplier_id'); $supplierId = $request->get('supplier_id');
...@@ -368,4 +378,17 @@ class SupplierApiController extends Controller ...@@ -368,4 +378,17 @@ class SupplierApiController extends Controller
$this->response(-1, '设置云芯采购失败'); $this->response(-1, '设置云芯采购失败');
} }
} }
//检查能否审核(只有最后一次修改人和当前审核人是属于同部门的,才能审核)
public function CheckCanAuditSupplier($request)
{
$supplierId = $request->get('supplier_id');
$supplierAuditService = new SupplierAuditService();
$check = $supplierAuditService->CheckCanAuditSupplier($supplierId);
if ($check) {
$this->response(0, '可以审核');
} else {
$this->response(-1, '无法进行审核操作,因为该供应商最后修改人和您不属于同一个部门');
}
}
} }
...@@ -5,6 +5,7 @@ namespace App\Http\Services; ...@@ -5,6 +5,7 @@ namespace App\Http\Services;
//后台用户相关信息服务 //后台用户相关信息服务
use App\Model\IntracodeModel; use App\Model\IntracodeModel;
use App\Model\UserDepartmentModel;
use App\Model\UserInfoModel; use App\Model\UserInfoModel;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
...@@ -19,12 +20,6 @@ class AdminUserService ...@@ -19,12 +20,6 @@ class AdminUserService
return $userInfoModel->where('userId', $adminId)->first(); return $userInfoModel->where('userId', $adminId)->first();
} }
public function getCodeIdByUserId($userId)
{
$intracodeModel = new IntracodeModel();
return $intracodeModel->where('admin_id', $userId)->value('code_id');
}
public function getCodeIdsByUserIds($userIds) public function getCodeIdsByUserIds($userIds)
{ {
$intracodeModel = new IntracodeModel(); $intracodeModel = new IntracodeModel();
...@@ -73,5 +68,4 @@ class AdminUserService ...@@ -73,5 +68,4 @@ class AdminUserService
return $users; return $users;
} }
} }
\ No newline at end of file
...@@ -9,11 +9,6 @@ use DB; ...@@ -9,11 +9,6 @@ use DB;
class DepartmentService class DepartmentService
{ {
public function getDepartmentId($departmentName)
{
return DB::table('user_department')->where('department_name', $departmentName)->value('department_id');
}
public function getSubordinateUserIds($adminId) public function getSubordinateUserIds($adminId)
{ {
$departmentId = DB::table('user_info')->where('userId', $adminId)->value('department_id'); $departmentId = DB::table('user_info')->where('userId', $adminId)->value('department_id');
......
...@@ -38,35 +38,48 @@ class SupplierAuditService ...@@ -38,35 +38,48 @@ class SupplierAuditService
if ($result) { if ($result) {
//记录日志 //记录日志
if ($disableExist) { if ($disableExist) {
$auditStatus = $status == -2 ? '审核通过,禁用供应商' : '审核不通过,原因是 : ' . $rejectReason; $auditStatus = $status == SupplierChannelModel::STATUS_DISABLE ? '审核通过,禁用供应商' : '审核不通过,原因是 : ' . $rejectReason;
if ($status == -2) { if ($status == SupplierChannelModel::STATUS_DISABLE) {
//发送队列消息同步到金蝶 //发送队列消息同步到金蝶
$service = new SyncSupplierService(); $service = new SyncSupplierService();
$service->syncSupplierToErp($supplierId); $service->syncSupplierToErp($supplierId);
} }
} else { } else {
$auditStatus = $status == 2 ? '审核通过' : '审核不通过,原因是 : ' . $rejectReason; $auditStatus = $status == SupplierChannelModel::STATUS_PASSED ? '审核通过' : '审核不通过,原因是 : ' . $rejectReason;
} }
$logService = new LogService(); $logService = new LogService();
$content = $auditStatus; $content = $auditStatus;
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', $content); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '审核供应商', $content);
} }
//发送队列消息同步到金蝶
$service = new SyncSupplierService(); //审核状态为待审核(即第一次新增)时,不需要推送到金蝶
$service->syncSupplierToErp($supplierId); if ($status != SupplierChannelModel::STATUS_PENDING) {
return $result; //发送队列消息同步到金蝶
$service = new SyncSupplierService();
$service->syncSupplierToErp($supplierId);
return $result;
}
} }
//判断是否是可以由当前用户审核 //判断是否是可以由当前用户审核
//要判断审核供应商的最后修改人,是不是属于当前审批人的部门或者部下,是才能让他审核 //要判断审核供应商的最后修改人,是不是属于当前审批人的部门或者部下,是才能让他审核
public function CheckCanAuditSupplier($supplierId) public function CheckCanAuditSupplier($supplierId)
{ {
if (checkPerm('IgnoreAuditCheck')) {
return true;
}
$auditUserId = request()->user->userId; $auditUserId = request()->user->userId;
$logModel = new LogModel(); $logModel = new LogModel();
$log = $logModel->where('supplier_id', $supplierId) $log = $logModel->where('supplier_id', $supplierId)
->where('type', LogModel::UPDATE_OPERATE)->orderBy('id', 'desc')->first(); ->where('type', LogModel::UPDATE_OPERATE)->orderBy('id', 'desc')->first();
$supplier['last_update_'] = $log['admin_name'] ?: '无';
$lastUpdateUserId = $log['admin_id']; $lastUpdateUserId = $log['admin_id'];
//审批人只能审批自己的部下修改的供应商
$departmentService = new DepartmentService();
$subordinateUserIds = $departmentService->getSubordinateUserIds($auditUserId);
if (in_array($lastUpdateUserId, $subordinateUserIds)) {
return true;
}
return false;
} }
//判断是否为待跟进供应商 //判断是否为待跟进供应商
......
...@@ -316,40 +316,39 @@ class SupplierService ...@@ -316,40 +316,39 @@ class SupplierService
} }
//分配采购员 //分配采购员
public function allocateChannelUser($supplierId, $purchaseUid) public function allocateChannelUser($supplierId, $channelUid)
{ {
$model = new SupplierChannelModel(); $model = new SupplierChannelModel();
$supplier = $model->where('supplier_id', $supplierId)->first(); $supplier = $model->where('supplier_id', $supplierId)->first();
$supplier = $supplier ? $supplier->toArray() : []; $supplier = $supplier ? $supplier->toArray() : [];
$prePurchaseUid = $supplier['purchase_uid']; $preChannelUid = $supplier['channel_uid'];
$preChannelUid = explode(',', $preChannelUid);
$preChannelUid[] = $channelUid;
$preChannelUid = implode(',', $preChannelUid);
$result = $model->where('supplier_id', $supplierId)->update([ $result = $model->where('supplier_id', $supplierId)->update([
'update_time' => time(), 'update_time' => time(),
'purchase_uid' => $purchaseUid, 'channel_uid' => $preChannelUid,
]); ]);
$contactResult = false;
if ($result) { if ($result) {
//重新分配渠道开发并且开发人员有变更的时候,就去检查是否需要跟进 $contactModel = new SupplierContactModel();
if ($supplier['purchase_uid'] != $purchaseUid) { $contact = [
$auditService = new SupplierAuditService(); 'supplier_id' => $supplierId,
//还要判断是否为待跟进供应商 'can_check_uids' => $channelUid,
if ($auditService->checkIsNeedToFollowUpSupplier($supplierId)) { ];
$model->where('supplier_id', $supplierId)->update([ $contactResult = $contactModel->insert($contact);
'to_follow_up' => 1, }
]); if ($contactResult) {
} //记录日志
}
//还要去记录日志
$adminUserService = new AdminUserService(); $adminUserService = new AdminUserService();
$prePurchaseUser = $adminUserService->getAdminUserInfoByCodeId($prePurchaseUid); $channelUser = $adminUserService->getAdminUserInfoByCodeId($channelUid);
$prePurchaseUserName = array_get($prePurchaseUser, 'name', ' '); $channelUserName = array_get($channelUser, 'name', ' ');
$purchaseUser = $adminUserService->getAdminUserInfoByCodeId($purchaseUid);
$purchaseUserName = array_get($purchaseUser, 'name', '');
$logService = new LogService(); $logService = new LogService();
$content = "将渠道开发员由 [${prePurchaseUserName}] 改为 [${purchaseUserName}]"; $content = "添加采购员 : " . $channelUserName;
$logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '分配渠道开发员', $content); $logService->AddLog($supplierId, LogModel::UPDATE_OPERATE, '添加采购员', $content);
} }
return $result; return $contactResult;
} }
//判断并且修改待跟进 //判断并且修改待跟进
......
...@@ -10,7 +10,7 @@ class SupplierChannelModel extends Model ...@@ -10,7 +10,7 @@ class SupplierChannelModel extends Model
protected $table = 'supplier_channel'; protected $table = 'supplier_channel';
public $timestamps = false; public $timestamps = false;
//待审核(没有补充所有必填信息) //待审核(第一次新增)
const STATUS_PENDING = -1; const STATUS_PENDING = -1;
//待复审 //待复审
const STATUS_IN_REVIEW = 1; const STATUS_IN_REVIEW = 1;
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
class UserDepartmentModel extends Model
{
protected $table='user_department';
protected $primaryKey = 'department_id';
public $timestamps = false;
}
...@@ -11,7 +11,7 @@ return [ ...@@ -11,7 +11,7 @@ return [
'notAuth' => [ 'notAuth' => [
'SwitchWarehouse', 'SwitchWarehouse',
'SkuList', 'SkuList',
'BatchOffShelf' 'BatchOffShelf',
]//不用验证权限的方法 ]//不用验证权限的方法
], ],
]; ];
...@@ -32,14 +32,13 @@ ...@@ -32,14 +32,13 @@
form.on('submit(auditSupplier)', function (data) { form.on('submit(auditSupplier)', function (data) {
admin.btnLoading('.submit-loading'); admin.btnLoading('.submit-loading');
let supplierId = getQueryVariable('supplier_id'); let supplierId = getQueryVariable('supplier_id');
let url = '/api/supplier/AllocatePurchaseUser?supplier_id=' + supplierId; let url = '/api/supplier/AllocateChannelUser?supplier_id=' + supplierId;
let res = ajax(url, data.field); let res = ajax(url, data.field);
if (!res) { if (!res) {
layer.msg('网络错误,请重试', {icon: 6}); layer.msg('网络错误,请重试', {icon: 6});
} else { } else {
if (res.err_code === 0) { if (res.err_code === 0) {
admin.closeThisDialog(); admin.closeThisDialog();
//修改罗盘显示数量(cao)
parent.layer.msg(res.err_msg, {icon: 6}); parent.layer.msg(res.err_msg, {icon: 6});
} else { } else {
admin.btnLoading('.submit-loading',false); admin.btnLoading('.submit-loading',false);
......
...@@ -227,6 +227,11 @@ ...@@ -227,6 +227,11 @@
layer.msg('要待复审的供应商才可以审核', {icon: 5}); layer.msg('要待复审的供应商才可以审核', {icon: 5});
return return
} }
let checkAuditMsg = checkCanAudit(supplierId);
if (checkAuditMsg !== '') {
layer.msg(checkAuditMsg, {icon: 5});
return
}
layer.open({ layer.open({
type: 2, type: 2,
content: '/supplier/AuditSupplier?view=iframe&supplier_id=' + supplierId, content: '/supplier/AuditSupplier?view=iframe&supplier_id=' + supplierId,
...@@ -279,20 +284,59 @@ ...@@ -279,20 +284,59 @@
} }
}) })
//新增配置采购员 //批量修改(分配)渠道员
$("#batch_allocate_purchase_user").click(function () {
let checkStatus = table.checkStatus('list');
let data = checkStatus.data;
let supplierIds = Array.from(data, ({supplier_id}) => supplier_id);
if (!data.length) {
layer.msg('请先选择要操作的供应商', {icon: 5})
} else {
let status = Array.from(data, ({status}) => status);
//分配采购员的多选操作,需要先去判断是否存在审核中的供应商,存在的话,要提示
if (status.indexOf(1) !== -1 || status.indexOf(-1) !== -1) {
layer.msg('选择的供应商里,存在审核状态的供应商,无法分配采购员', {icon: 5})
return
}
let supplierId = data[0].supplier_id;
layer.open({
type: 2,
content: '/supplier/AllocateChannelUser?view=iframe&supplier_id=' + supplierId,
area: ['600px', '70%'],
title: '新增采购员',
end: function () {
// saveRefreshData('detail', supplierId)
// table.reload('list');
supplierStatistics();
}
});
}
})
//分配采购员
$("#allocate_channel_user").click(function () { $("#allocate_channel_user").click(function () {
let checkStatus = table.checkStatus('list'); let checkStatus = table.checkStatus('list');
let data = checkStatus.data; let data = checkStatus.data;
if (!data.length) { if (!data.length) {
layer.msg('请先选择要操作的供应商', {icon: 5}) layer.msg('请先选择要操作的供应商', {icon: 5})
} else { } else {
if (data.length > 1) {
layer.msg('该操作不支持多选', {icon: 5})
return;
}
const is_type = data[0].is_type;
if (is_type === 1) {
layer.msg('该供应商为非正式供应商,请先将该供应商转正', {icon: 5})
return false;
}
const status = data[0].status; const status = data[0].status;
if ((status === 3 || status === 2 || status === -2)) { if ((status === 3 || status === 2 || status === -2)) {
let supplierId = data[0].supplier_id; let supplierId = data[0].supplier_id;
layer.open({ layer.open({
type: 2, type: 2,
content: '/supplier/AllocateChannelUser?view=iframe&supplier_id=' + supplierId, content: '/supplier/AllocateChannelUser?view=iframe&supplier_id=' + supplierId,
area: ['600px', '70%'], area: ['650px', '80%'],
title: '新增采购员', title: '新增采购员',
end: function () { end: function () {
saveRefreshData('detail', supplierId) saveRefreshData('detail', supplierId)
...@@ -301,7 +345,7 @@ ...@@ -301,7 +345,7 @@
} }
}); });
} else { } else {
layer.msg('只能对已通过/未通过/禁用状态的供应商进行渠道员分配', {icon: 5}) layer.msg('审核状态的供应商无法分配采购员', {icon: 5})
return false; return false;
} }
...@@ -396,4 +440,15 @@ ...@@ -396,4 +440,15 @@
}); });
}); });
//检查是否能够审核,因为审核人只能审自己相关部门人员修改的供应商记录
function checkCanAudit(supplierId) {
let url = '/api/supplier/CheckCanAuditSupplier?supplier_id=' + supplierId;
let res = ajax(url);
if (res.err_code !== 0) {
return res.err_msg;
} else {
return '';
}
}
</script> </script>
\ No newline at end of file
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<div class="layui-inline" style="margin-left: -30px"> <div class="layui-inline" style="margin-left: -30px">
@inject('statusPresenter','App\Presenters\StatusPresenter') @inject('statusPresenter','App\Presenters\StatusPresenter')
{!! $statusPresenter->render('channel_uid','采购员','', {!! $statusPresenter->render('channel_uid','新增采购员','',
$userCodes,['required'=>true,'width'=>'120px']) !!} $userCodes,['required'=>true,'width'=>'120px']) !!}
</div> </div>
</div> </div>
...@@ -47,6 +47,11 @@ ...@@ -47,6 +47,11 @@
</div> </div>
</div> </div>
<blockquote class="layui-elem-quote layui-text"> <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> <b>操作日志</b>
</blockquote> </blockquote>
<table class="layui-table" id="logList" lay-filter="logList"></table> <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