Commit 5c587825 by 杨树贤

fix

parent e060e9c1
Showing with 49 additions and 87 deletions
...@@ -1085,30 +1085,6 @@ class SupplierService ...@@ -1085,30 +1085,6 @@ class SupplierService
} }
$supplierGroup = $supplier->supplier_group; // 供应商性质:1=代理商,2=现货商,4=原厂 $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采购员信息 // 获取SKU采购员信息
$skuPurchaseUser = $adminUserService->getAdminUserInfoByCodeId($skuPurchaseCodeId); $skuPurchaseUser = $adminUserService->getAdminUserInfoByCodeId($skuPurchaseCodeId);
if (empty($skuPurchaseUser)) { if (empty($skuPurchaseUser)) {
...@@ -1199,49 +1175,61 @@ class SupplierService ...@@ -1199,49 +1175,61 @@ class SupplierService
$result['debug_info']['assign_code_ids'] = $assignCodeIds; $result['debug_info']['assign_code_ids'] = $assignCodeIds;
// 如果只是调试模式,不执行更新 // 检查每个采购员是否已存在于猎芯采购和数据跟单员中
if (!$executeUpdate) { $needAssignLiexin = array(); // 需要分配猎芯采购的codeId
$result['success'] = true; $needAssignDataFollower = array(); // 需要分配数据跟单员的codeId
$result['reason'] = '调试模式,未执行实际更新';
return $result;
}
// 分配采购员:根据情况分配
foreach ($assignCodeIds as $assignCodeId) { foreach ($assignCodeIds as $assignCodeId) {
// 如果只需要分配数据跟单员 // 检查是否已存在猎芯采购
if ($onlyAssignDataFollower) { $hasLiexin = SupplierContactModel::where('supplier_id', $supplierId)
// 检查是否已存在数据跟单员,不存在则分配
$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('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->exists(); ->exists();
if (!$hasLiexinPurchase) { if (!$hasLiexin) {
$this->allocateChannelUser($supplierId, $assignCodeId, SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN, true); $needAssignLiexin[] = $assignCodeId;
} }
// 检查是否已存在数据跟单员,不存在则分配 // 检查是否已存在数据跟单员
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId) $hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId)
->where('can_check_uids', $assignCodeId) ->where('can_check_uids', $assignCodeId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists(); ->exists();
if (!$hasDataFollower) { if (!$hasDataFollower) {
$this->allocateChannelUser($supplierId, $assignCodeId, SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY, true); $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;
$result['reason'] = '调试模式,未执行实际更新';
return $result;
} }
// 分配缺失的猎芯采购
foreach ($needAssignLiexin as $codeId) {
$this->allocateChannelUser($supplierId, $codeId, SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN, true);
} }
// 分配缺失的数据跟单员
foreach ($needAssignDataFollower as $codeId) {
$this->allocateChannelUser($supplierId, $codeId, SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY, true);
} }
$result['success'] = true; $result['success'] = true;
$result['reason'] = '分配成功'; $liexinCount = count($needAssignLiexin);
$followerCount = count($needAssignDataFollower);
$result['reason'] = '分配成功:新增' . $liexinCount . '个猎芯采购,' . $followerCount . '个数据跟单员';
return $result; return $result;
} }
...@@ -1308,41 +1296,6 @@ class SupplierService ...@@ -1308,41 +1296,6 @@ class SupplierService
$result['total']++; $result['total']++;
$supplierId = $supplier->supplier_id; $supplierId = $supplier->supplier_id;
$yunxinChannelUid = $supplier->yunxin_channel_uid; $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处理分配逻辑 // 调用autoAssignPurchaseUser处理分配逻辑
$assignResult = $supplierService->autoAssignPurchaseUser($supplierId, $yunxinChannelUid, $isProdMode); $assignResult = $supplierService->autoAssignPurchaseUser($supplierId, $yunxinChannelUid, $isProdMode);
...@@ -1373,9 +1326,16 @@ class SupplierService ...@@ -1373,9 +1326,16 @@ class SupplierService
return $adminUserService->getAdminUserNameByCodeId($codeId); return $adminUserService->getAdminUserNameByCodeId($codeId);
}, $assignCodeIds); }, $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); $isNew = ($liexinCount == count($assignCodeIds) && $followerCount == count($assignCodeIds));
$action = $isNew ? '分配猎芯采购和数据跟单员' : '仅分配数据跟单员'; $action = '新增' . $liexinCount . '个猎芯采购,' . $followerCount . '个数据跟单员';
$result['details'][] = [ $result['details'][] = [
'supplier_id' => $supplierId, 'supplier_id' => $supplierId,
...@@ -1385,6 +1345,8 @@ class SupplierService ...@@ -1385,6 +1345,8 @@ class SupplierService
'assign_code_ids' => $assignCodeIds, 'assign_code_ids' => $assignCodeIds,
'assign_names' => $assignNames, 'assign_names' => $assignNames,
'is_new' => $isNew, '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