Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_supplier
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6a18da4f
authored
Mar 02, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调试代码
parent
8d472396
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
287 additions
and
2 deletions
app/Http/Controllers/Api/SupplierApiController.php
app/Http/Services/SupplierService.php
app/Model/SupplierChannelModel.php
config/field.php
app/Http/Controllers/Api/SupplierApiController.php
View file @
6a18da4f
...
...
@@ -634,6 +634,11 @@ class SupplierApiController extends Controller
$user
=
$adminService
->
getAdminUserInfoByCodeId
(
$channelUid
);
$logService
=
new
LogService
();
$logService
->
AddLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'设置线上采购员'
,
'设置线上采购员为 : '
.
$user
[
'name'
]);
// 自动分配猎芯采购和数据跟单员
$supplierService
=
new
SupplierService
();
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$channelUid
);
$this
->
response
(
0
,
'设置SKU采购成功'
);
}
else
{
$this
->
response
(
-
1
,
'设置SKU采购失败'
);
...
...
@@ -654,6 +659,16 @@ class SupplierApiController extends Controller
$this
->
response
(
-
1
,
'选择的供应商里面不存在对应的线上采购员'
);
}
$supplierService
->
batchAllocateYunxinChannelUser
(
$supplierIds
,
$channelUid
);
$userId
=
$request
->
user
->
userId
;
if
(
$userId
==
1000
)
{
// 批量自动分配猎芯采购和数据跟单员
foreach
(
$supplierIds
as
$supplierId
)
{
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$channelUid
);
}
}
$this
->
response
(
0
,
'批量分配线上采购员成功'
);
}
...
...
@@ -868,6 +883,16 @@ class SupplierApiController extends Controller
}
}
//刷新历史数据:自动分配猎芯采购和数据跟单员
public
function
RefreshHistoryPurchaseUser
(
$request
)
{
$updateData
=
$request
->
get
(
'update_data'
,
false
);
$limit
=
$request
->
get
(
'limit'
,
100
);
$result
=
SupplierService
::
refreshHistoryPurchaseUser
(
$updateData
,
$limit
);
$this
->
response
(
0
,
'刷新完成'
,
$result
);
}
//获取审核流程
public
function
GetAuditFlow
(
$request
)
{
...
...
app/Http/Services/SupplierService.php
View file @
6a18da4f
...
...
@@ -1054,4 +1054,241 @@ class SupplierService
$logService
->
AddLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'清空线上采购员'
,
'清空线上采购员'
);
return
$result
;
}
/**
* 自动分配猎芯采购和数据跟单员
* 规则:
* 1. 当设置的sku采购员所属子部门为主动兼国产供应链部/被动兼国产供应链部/商品供应链部:
* - 如供应商性质是现货商:则默认猎芯采购/数据跟单员为商品供应链部数据跟单采购组的4个人(共8个联系人:猎芯采购4人+数据跟单员4人)
* - 如供应商是代理商/原厂:则猎芯采购/数据跟单员随机选商品供应链部数据跟单采购组的其中1人(共2个联系人:猎芯采购1人+数据跟单员1人)
* 2. 当设置的sku采购员所属子部门为新质供应链部的,猎芯采购/数据跟单员默认欧阳海梅(共2个联系人)
*
* @param int $supplierId 供应商ID
* @param int $skuPurchaseCodeId 设置的SKU采购员codeId
* @return bool
*/
public
function
autoAssignPurchaseUser
(
$supplierId
,
$skuPurchaseCodeId
)
{
$adminUserService
=
new
AdminUserService
();
// 获取SKU采购员信息
$skuPurchaseUser
=
$adminUserService
->
getAdminUserInfoByCodeId
(
$skuPurchaseCodeId
);
if
(
empty
(
$skuPurchaseUser
))
{
return
false
;
}
// 获取SKU采购员的部门ID
$skuPurchaseDepartmentId
=
$skuPurchaseUser
[
'department_id'
];
if
(
empty
(
$skuPurchaseDepartmentId
))
{
return
false
;
}
// 获取供应商信息
$supplier
=
SupplierChannelModel
::
where
(
'supplier_id'
,
$supplierId
)
->
first
();
if
(
empty
(
$supplier
))
{
return
false
;
}
$supplierGroup
=
$supplier
->
supplier_group
;
// 供应商性质:1=代理商,2=现货商,4=原厂
// 获取用户所属部门及其所有上级部门ID
$departmentIds
=
$this
->
getParentDepartmentIds
(
$skuPurchaseDepartmentId
);
// 获取这些部门的名称
$departmentNames
=
\App\Model\DepartmentModel
::
whereIn
(
'department_id'
,
$departmentIds
)
->
pluck
(
'department_name'
)
->
toArray
();
$departmentNamesStr
=
implode
(
''
,
$departmentNames
);
// 根据部门名称判断属于哪个部门类型(检查部门链中是否包含目标部门)
$isZhuDongGuoChan
=
strpos
(
$departmentNamesStr
,
'主动兼国产供应链部'
)
!==
false
;
$isBeiDongGuoChan
=
strpos
(
$departmentNamesStr
,
'被动兼国产供应链部'
)
!==
false
;
$isShangPinGongYingLian
=
strpos
(
$departmentNamesStr
,
'商品供应链部'
)
!==
false
;
$isXinZhiGongYingLian
=
strpos
(
$departmentNamesStr
,
'新质供应链部'
)
!==
false
;
// 需要分配的采购员codeId列表
$assignCodeIds
=
[];
if
(
$isZhuDongGuoChan
||
$isBeiDongGuoChan
||
$isShangPinGongYingLian
)
{
// 属于主动兼国产供应链部/被动兼国产供应链部/商品供应链部
$dataFollowerGroup
=
config
(
'field.ShangpinDataFollowerGroup'
,
[]);
if
(
empty
(
$dataFollowerGroup
))
{
return
false
;
}
if
(
$supplierGroup
==
SupplierChannelModel
::
SUPPLIER_GROUP_SPOT
)
{
// 现货商:分配商品供应链部数据跟单采购组的4个人
foreach
(
$dataFollowerGroup
as
$followerName
)
{
$codeId
=
$adminUserService
->
getCodeIdByUserName
(
$followerName
);
if
(
$codeId
)
{
$assignCodeIds
[]
=
$codeId
;
}
}
}
else
{
// 代理商/原厂:随机选商品供应链部数据跟单采购组的其中1人
$randomFollower
=
$dataFollowerGroup
[
array_rand
(
$dataFollowerGroup
)];
$codeId
=
$adminUserService
->
getCodeIdByUserName
(
$randomFollower
);
if
(
$codeId
)
{
$assignCodeIds
[]
=
$codeId
;
}
dump
(
$assignCodeIds
);
}
}
elseif
(
$isXinZhiGongYingLian
)
{
// 属于新质供应链部:默认欧阳海梅
$defaultName
=
config
(
'field.XinzhiDefaultDataFollowerName'
,
'欧阳海梅'
);
$codeId
=
$adminUserService
->
getCodeIdByUserName
(
$defaultName
);
if
(
$codeId
)
{
$assignCodeIds
[]
=
$codeId
;
}
}
else
{
// 不属于以上部门,不自动分配
return
false
;
}
if
(
empty
(
$assignCodeIds
))
{
return
false
;
}
// 分配采购员:每个人都要分配猎芯采购和数据跟单员两种类型
foreach
(
$assignCodeIds
as
$assignCodeId
)
{
// 检查是否已存在猎芯采购,不存在则分配
$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
);
}
// 检查是否已存在数据跟单员,不存在则分配
$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
);
}
}
return
true
;
}
/**
* 获取部门及其所有上级部门ID
* @param int $departmentId 部门ID
* @return array 部门ID数组(包含自己及所有上级)
*/
private
function
getParentDepartmentIds
(
$departmentId
)
{
$departmentIds
=
[
$departmentId
];
$departmentModel
=
new
\App\Model\DepartmentModel
();
$department
=
$departmentModel
->
where
(
'department_id'
,
$departmentId
)
->
first
();
while
(
$department
&&
$department
->
parent_id
!=
0
)
{
$departmentIds
[]
=
$department
->
parent_id
;
$department
=
$departmentModel
->
where
(
'department_id'
,
$department
->
parent_id
)
->
first
();
}
return
array_unique
(
$departmentIds
);
}
/**
* 刷新历史数据:自动分配猎芯采购和数据跟单员
* 规则:
* - 供应商无猎芯采购和数据跟单员的采购员类型时,按规则同时更新猎芯采购和数据跟单员
* - 供应商有猎芯采购的采购员类型无数据跟单员时,仅更新数据跟单员(将现有猎芯采购人员同时设为数据跟单员)
*
* @param bool $updateData 是否真正更新数据
* @param int $limit 处理数量限制
* @return array 处理结果
*/
public
static
function
refreshHistoryPurchaseUser
(
$updateData
=
false
,
$limit
=
100
)
{
ini_set
(
'memory_limit'
,
-
1
);
$supplierService
=
new
self
();
// 获取所有正式供应商
$suppliers
=
SupplierChannelModel
::
where
(
'is_type'
,
0
)
->
where
(
'yunxin_channel_uid'
,
'!='
,
''
)
->
whereNotNull
(
'yunxin_channel_uid'
)
->
limit
(
$limit
)
->
get
();
$result
=
[
'total'
=>
0
,
'success'
=>
0
,
'failed'
=>
0
,
'skipped'
=>
0
,
'details'
=>
[],
];
foreach
(
$suppliers
as
$supplier
)
{
$result
[
'total'
]
++
;
$supplierId
=
$supplier
->
supplier_id
;
$yunxinChannelUid
=
$supplier
->
yunxin_channel_uid
;
// 检查是否有猎芯采购和数据跟单员
$hasLiexinPurchase
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
exists
();
$hasDataFollower
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
)
->
exists
();
// 如果两者都有,跳过
if
(
$hasLiexinPurchase
&&
$hasDataFollower
)
{
$result
[
'skipped'
]
++
;
continue
;
}
// 自动分配
if
(
$updateData
)
{
if
(
$hasLiexinPurchase
&&
!
$hasDataFollower
)
{
// 有猎芯采购但没有数据跟单员:将现有猎芯采购人员同时设为数据跟单员
$liexinPurchases
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
foreach
(
$liexinPurchases
as
$codeId
)
{
// 检查是否已存在数据跟单员记录
$exists
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$codeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
)
->
exists
();
if
(
!
$exists
)
{
$supplierService
->
allocateChannelUser
(
$supplierId
,
$codeId
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
,
false
);
}
}
$result
[
'success'
]
++
;
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'仅分配数据跟单员(基于现有猎芯采购)'
,
];
}
else
{
// 无猎芯采购和数据跟单员:按规则同时分配
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
);
if
(
$assignResult
)
{
$result
[
'success'
]
++
;
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'分配猎芯采购和数据跟单员'
,
];
}
else
{
$result
[
'failed'
]
++
;
}
}
}
else
{
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'has_liexin'
=>
$hasLiexinPurchase
,
'has_data_follower'
=>
$hasDataFollower
,
];
}
}
return
$result
;
}
}
app/Model/SupplierChannelModel.php
View file @
6a18da4f
...
...
@@ -34,7 +34,8 @@ class SupplierChannelModel extends Model
const
SYNC_UNITED_STATUS_OK
=
1
;
//供应商类型
const
SUPPLIER_GROUP_PROXY
=
1
;
//代理
const
SUPPLIER_GROUP_PROXY
=
1
;
//代理商
const
SUPPLIER_GROUP_SPOT
=
2
;
//现货商
const
SUPPLIER_GROUP_ORIGINAL
=
4
;
//原厂
const
SUPPLIER_GROUP_MIX
=
7
;
//混合分销商
...
...
config/field.php
View file @
6a18da4f
...
...
@@ -385,5 +385,27 @@ return [
'天'
=>
'月结'
,
'当月'
=>
'当月'
,
'当周'
=>
'当周'
,
]
],
// 自动分配采购员相关配置
// 子部门ID配置(需要根据实际数据库配置)
'AutoAssignDepartmentIds'
=>
[
'zhudong_guochan'
=>
121
,
// 主动兼国产供应链部
'beidong_guochan'
=>
122
,
// 被动兼国产供应链部
'shangpin_gongyinglian'
=>
142
,
// 商品供应链部
'xinzhi_gongyinglian'
=>
123
,
// 新质供应链部
'shuju_gendan_caigouzu'
=>
150
,
// 数据跟单采购组
],
// 新质供应链部默认数据跟单员姓名
'XinzhiDefaultDataFollowerName'
=>
'欧阳海梅'
,
// 商品供应链部数据跟单采购组人员名单(用于现货商默认分配4人)
'ShangpinDataFollowerGroup'
=>
[
// 需要配置实际姓名
'郑君'
,
'李尚文杰'
,
'陈雪梅'
,
'邱沛敏'
,
],
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment