Commit e060e9c1 by 杨树贤

进一步优化

parent 09f4ec29
Showing with 39 additions and 28 deletions
...@@ -1077,23 +1077,37 @@ class SupplierService ...@@ -1077,23 +1077,37 @@ class SupplierService
$adminUserService = new AdminUserService(); $adminUserService = new AdminUserService();
// 检查供应商是否已有猎芯采购和数据跟单员,如果两者都有则跳过 // 获取供应商信息
$hasLiexinPurchase = SupplierContactModel::where('supplier_id', $supplierId) $supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if (empty($supplier)) {
$result['reason'] = '供应商不存在,supplierId: ' . $supplierId;
return $result;
}
$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) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->exists(); ->count();
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId) $dataFollowerCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists(); ->count();
if ($hasLiexinPurchase && $hasDataFollower) { // 检查是否已满足条件:猎芯采购和数据跟单员数量都要达到要求
// 已有猎芯采购和数据跟单员,跳过自动分配 if ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount >= $requiredCount) {
$result['success'] = true; $result['success'] = true;
$result['reason'] = '已有猎芯采购和数据跟单员,跳过'; $result['reason'] = '已有足够的猎芯采购(' . $liexinPurchaseCount . '个)和数据跟单员(' . $dataFollowerCount . '个),跳过';
return $result; return $result;
} }
// 如果有猎芯采购但没有数据跟单员,只分配数据跟单员 // 判断需要分配什么类型
$onlyAssignDataFollower = $hasLiexinPurchase && !$hasDataFollower; // 如果猎芯采购已够但数据跟单员不够,只分配数据跟单员
// 如果猎芯采购不够,需要同时分配猎芯采购和数据跟单员
$onlyAssignDataFollower = ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount < $requiredCount);
// 获取SKU采购员信息 // 获取SKU采购员信息
$skuPurchaseUser = $adminUserService->getAdminUserInfoByCodeId($skuPurchaseCodeId); $skuPurchaseUser = $adminUserService->getAdminUserInfoByCodeId($skuPurchaseCodeId);
...@@ -1109,14 +1123,6 @@ class SupplierService ...@@ -1109,14 +1123,6 @@ class SupplierService
return $result; return $result;
} }
// 获取供应商信息
$supplier = SupplierChannelModel::where('supplier_id', $supplierId)->first();
if (empty($supplier)) {
$result['reason'] = '供应商不存在,supplierId: ' . $supplierId;
return $result;
}
$supplierGroup = $supplier->supplier_group; // 供应商性质:1=代理商,2=现货商,4=原厂
// 获取用户所属部门及其所有上级部门ID // 获取用户所属部门及其所有上级部门ID
$departmentIds = $this->getParentDepartmentIds($skuPurchaseDepartmentId); $departmentIds = $this->getParentDepartmentIds($skuPurchaseDepartmentId);
...@@ -1302,23 +1308,28 @@ class SupplierService ...@@ -1302,23 +1308,28 @@ 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;
// 检查是否有猎芯采购和数据跟单员 // 获取现有的猎芯采购和数据跟单员数量
$hasLiexinPurchase = SupplierContactModel::where('supplier_id', $supplierId) $liexinPurchaseCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_LIEXIN)
->exists(); ->count();
$hasDataFollower = SupplierContactModel::where('supplier_id', $supplierId) $dataFollowerCount = SupplierContactModel::where('supplier_id', $supplierId)
->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY) ->where('channel_user_type', SupplierContactModel::CHANNEL_USER_TYPE_INVENTORY)
->exists(); ->count();
// 如果两者都有,跳过 // 如果数量都已满足,跳过
if ($hasLiexinPurchase && $hasDataFollower) { if ($liexinPurchaseCount >= $requiredCount && $dataFollowerCount >= $requiredCount) {
$result['skipped']++; $result['skipped']++;
$result['debug_info'][] = [ $result['debug_info'][] = [
'supplier_id' => $supplierId, 'supplier_id' => $supplierId,
'supplier_code' => $supplier->supplier_code, 'supplier_code' => $supplier->supplier_code,
'supplier_name' => $supplier->supplier_name, 'supplier_name' => $supplier->supplier_name,
'skip_reason' => '已有猎芯采购和数据跟单员', 'skip_reason' => '已有足够的猎芯采购(' . $liexinPurchaseCount . '个)和数据跟单员(' . $dataFollowerCount . '个)',
]; ];
// 回调进度 // 回调进度
...@@ -1326,7 +1337,7 @@ class SupplierService ...@@ -1326,7 +1337,7 @@ class SupplierService
$progressCallback([ $progressCallback([
'supplier_id' => $supplierId, 'supplier_id' => $supplierId,
'supplier_name' => $supplier->supplier_name, 'supplier_name' => $supplier->supplier_name,
'action' => '跳过:已有猎芯采购和数据跟单员', 'action' => '跳过:已有足够的采购员',
'status' => 'skip', 'status' => 'skip',
]); ]);
} }
...@@ -1363,7 +1374,7 @@ class SupplierService ...@@ -1363,7 +1374,7 @@ class SupplierService
}, $assignCodeIds); }, $assignCodeIds);
// 判断是新增还是补充 // 判断是新增还是补充
$isNew = !$hasLiexinPurchase && !$hasDataFollower; $isNew = ($liexinPurchaseCount < $requiredCount && $dataFollowerCount < $requiredCount);
$action = $isNew ? '分配猎芯采购和数据跟单员' : '仅分配数据跟单员'; $action = $isNew ? '分配猎芯采购和数据跟单员' : '仅分配数据跟单员';
$result['details'][] = [ $result['details'][] = [
......
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