Commit 5c587825 by 杨树贤

fix

parent e060e9c1
Showing with 55 additions and 93 deletions
......@@ -1085,30 +1085,6 @@ class SupplierService
}
$supplierGroup = $supplier->supplier_group; // 供应商性质:1=代理商,2=现货商,4=原厂
// 根据供应商性质确定需要的采购员数量
// 现货商需要4个,代理商/原厂需要1个
$requiredCount = ($supplierGroup == SupplierChannelModel::SUPPLIER_GROUP_SPOT) ? 4 : 1;
// 获取现有的猎芯采购和数据跟单员数量
$liexinPurchaseCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->count();
$dataFollowerCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->count();
// 检查是否已满足条件:猎芯采购和数据跟单员数量都要达到要求
if ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount >= $requiredCount) {
$result['success'] = true;
$result['reason'] = '已有足够的猎芯采购(' . $liexinPurchaseCount . '个)和数据跟单员(' . $dataFollowerCount . '个),跳过';
return $result;
}
// 判断需要分配什么类型
// 如果猎芯采购已够但数据跟单员不够,只分配数据跟单员
// 如果猎芯采购不够,需要同时分配猎芯采购和数据跟单员
$onlyAssignDataFollower = ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount < $requiredCount);
// 获取SKU采购员信息
$skuPurchaseUser = $adminUserService->getAdminUserInfoByCodeId($skuPurchaseCodeId);
if (empty($skuPurchaseUser)) {
......@@ -1199,6 +1175,40 @@ class SupplierService
$result['debug_info']['assign_code_ids'] = $assignCodeIds;
// 检查每个采购员是否已存在于猎芯采购和数据跟单员中
$needAssignLiexin = array(); // 需要分配猎芯采购的codeId
$needAssignDataFollower = array(); // 需要分配数据跟单员的codeId
foreach ($assignCodeIds as $assignCodeId) {
// 检查是否已存在猎芯采购
$hasLiexin = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->exists();
if (!$hasLiexin) {
$needAssignLiexin[] = $assignCodeId;
}
// 检查是否已存在数据跟单员
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists();
if (!$hasDataFollower) {
$needAssignDataFollower[] = $assignCodeId;
}
}
// 如果都存在,跳过
if (empty($needAssignLiexin) && empty($needAssignDataFollower)) {
$result['success'] = true;
$result['reason'] = '所有采购员已分配猎芯采购和数据跟单员,跳过';
return $result;
}
$result['debug_info']['need_assign_liexin'] = $needAssignLiexin;
$result['debug_info']['need_assign_data_follower'] = $needAssignDataFollower;
// 如果只是调试模式,不执行更新
if (!$executeUpdate) {
$result['success'] = true;
......@@ -1206,42 +1216,20 @@ class SupplierService
return $result;
}
// 分配采购员:根据情况分配
foreach ($assignCodeIds as $assignCodeId) {
// 如果只需要分配数据跟单员
if ($onlyAssignDataFollower) {
// 检查是否已存在数据跟单员,不存在则分配
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists();
if (!$hasDataFollower) {
$this->allocateChannelUser($supplierId, $assignCodeId, SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY, true);
}
} else {
// 同时分配猎芯采购和数据跟单员
// 检查是否已存在猎芯采购,不存在则分配
$hasLiexinPurchase = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->exists();
if (!$hasLiexinPurchase) {
$this->allocateChannelUser($supplierId, $assignCodeId, SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN, true);
}
// 分配缺失的猎芯采购
foreach ($needAssignLiexin as $codeId) {
$this->allocateChannelUser($supplierId, $codeId, SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN, true);
}
// 检查是否已存在数据跟单员,不存在则分配
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists();
if (!$hasDataFollower) {
$this->allocateChannelUser($supplierId, $assignCodeId, SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY, true);
}
}
// 分配缺失的数据跟单员
foreach ($needAssignDataFollower as $codeId) {
$this->allocateChannelUser($supplierId, $codeId, SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY, true);
}
$result['success'] = true;
$result['reason'] = '分配成功';
$liexinCount = count($needAssignLiexin);
$followerCount = count($needAssignDataFollower);
$result['reason'] = '分配成功:新增' . $liexinCount . '个猎芯采购,' . $followerCount . '个数据跟单员';
return $result;
}
......@@ -1308,41 +1296,6 @@ class SupplierService
$result['total']++;
$supplierId = $supplier->supplier_id;
$yunxinChannelUid = $supplier->yunxin_channel_uid;
$supplierGroup = $supplier->supplier_group;
// 根据供应商性质确定需要的采购员数量
// 现货商需要4个,代理商/原厂需要1个
$requiredCount = ($supplierGroup == SupplierChannelModel::SUPPLIER_GROUP_SPOT) ? 4 : 1;
// 获取现有的猎芯采购和数据跟单员数量
$liexinPurchaseCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->count();
$dataFollowerCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->count();
// 如果数量都已满足,跳过
if ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount >= $requiredCount) {
$result['skipped']++;
$result['debug_info'][] = [
'supplier_id' => $supplierId,
'supplier_code' => $supplier->supplier_code,
'supplier_name' => $supplier->supplier_name,
'skip_reason' => '已有足够的猎芯采购(' . $liexinPurchaseCount . '个)和数据跟单员(' . $dataFollowerCount . '个)',
];
// 回调进度
if ($progressCallback) {
$progressCallback([
'supplier_id' => $supplierId,
'supplier_name' => $supplier->supplier_name,
'action' => '跳过:已有足够的采购员',
'status' => 'skip',
]);
}
continue;
}
// 调用autoAssignPurchaseUser处理分配逻辑
$assignResult = $supplierService->autoAssignPurchaseUser($supplierId, $yunxinChannelUid, $isProdMode);
......@@ -1373,9 +1326,16 @@ class SupplierService
return $adminUserService->getAdminUserNameByCodeId($codeId);
}, $assignCodeIds);
// 获取需要分配的数量
$needAssignLiexin = isset($assignResult['debug_info']['need_assign_liexin']) ? $assignResult['debug_info']['need_assign_liexin'] : array();
$needAssignDataFollower = isset($assignResult['debug_info']['need_assign_data_follower']) ? $assignResult['debug_info']['need_assign_data_follower'] : array();
$liexinCount = count($needAssignLiexin);
$followerCount = count($needAssignDataFollower);
// 判断是新增还是补充
$isNew = ($liexinPurchaseCount < $requiredCount && $dataFollowerCount < $requiredCount);
$action = $isNew ? '分配猎芯采购和数据跟单员' : '仅分配数据跟单员';
$isNew = ($liexinCount == count($assignCodeIds) && $followerCount == count($assignCodeIds));
$action = '新增' . $liexinCount . '个猎芯采购,' . $followerCount . '个数据跟单员';
$result['details'][] = [
'supplier_id' => $supplierId,
......@@ -1385,6 +1345,8 @@ class SupplierService
'assign_code_ids' => $assignCodeIds,
'assign_names' => $assignNames,
'is_new' => $isNew,
'need_assign_liexin' => $liexinCount,
'need_assign_follower' => $followerCount,
];
// 回调进度
......
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