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
09f4ec29
authored
Mar 02, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
进一步优化
parent
9606ad6c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
277 deletions
app/Console/Commands/RefreshHistoryPurchaseUser.php
app/Http/Controllers/Api/SupplierApiController.php
app/Http/Services/SupplierService.php
app/Console/Commands/RefreshHistoryPurchaseUser.php
View file @
09f4ec29
...
...
@@ -65,15 +65,21 @@ class RefreshHistoryPurchaseUser extends Command
$supplierCode
=
isset
(
$detail
[
'supplier_code'
])
?
$detail
[
'supplier_code'
]
:
''
;
$supplierName
=
isset
(
$detail
[
'supplier_name'
])
?
$detail
[
'supplier_name'
]
:
''
;
$action
=
isset
(
$detail
[
'action'
])
?
$detail
[
'action'
]
:
''
;
$isNew
=
isset
(
$detail
[
'is_new'
])
?
$detail
[
'is_new'
]
:
false
;
// 获取分配的采购员信息
$assignInfo
=
''
;
if
(
isset
(
$detail
[
'assign_code_ids'
])
&&
!
empty
(
$detail
[
'assign_code_ids'
]))
{
$assignInfo
=
' 分配采购员codeId: '
.
implode
(
','
,
$detail
[
'assign_code_ids'
]);
if
(
isset
(
$detail
[
'assign_names'
])
&&
!
empty
(
$detail
[
'assign_names'
]))
{
$assignInfo
=
' 采购员: '
.
implode
(
','
,
$detail
[
'assign_names'
]);
}
elseif
(
isset
(
$detail
[
'assign_code_ids'
])
&&
!
empty
(
$detail
[
'assign_code_ids'
]))
{
$assignInfo
=
' 采购员codeId: '
.
implode
(
','
,
$detail
[
'assign_code_ids'
]);
}
$newFlag
=
$isNew
?
'[新增]'
:
'[补充]'
;
$this
->
info
(
sprintf
(
' [ID:%d %s] %s - %s%s'
,
' %s [ID:%d %s] %s - %s%s'
,
$newFlag
,
$supplierId
,
$supplierCode
,
$supplierName
,
...
...
app/Http/Controllers/Api/SupplierApiController.php
View file @
09f4ec29
...
...
@@ -883,16 +883,6 @@ class SupplierApiController extends Controller
}
}
//刷新历史数据:自动分配猎芯采购和数据跟单员
public
function
RefreshHistoryPurchaseUser
(
$request
)
{
$mode
=
$request
->
get
(
'mode'
,
'debug'
);
// prod=生产模式执行数据处理,其他=调试模式
$num
=
$request
->
get
(
'num'
,
50
);
// 处理数量限制
$result
=
SupplierService
::
refreshHistoryPurchaseUser
(
$mode
,
$num
);
$this
->
response
(
0
,
'刷新完成'
,
$result
);
}
//获取审核流程
public
function
GetAuditFlow
(
$request
)
{
...
...
app/Http/Services/SupplierService.php
View file @
09f4ec29
...
...
@@ -1092,6 +1092,9 @@ class SupplierService
return
$result
;
}
// 如果有猎芯采购但没有数据跟单员,只分配数据跟单员
$onlyAssignDataFollower
=
$hasLiexinPurchase
&&
!
$hasDataFollower
;
// 获取SKU采购员信息
$skuPurchaseUser
=
$adminUserService
->
getAdminUserInfoByCodeId
(
$skuPurchaseCodeId
);
if
(
empty
(
$skuPurchaseUser
))
{
...
...
@@ -1197,24 +1200,37 @@ class SupplierService
return
$result
;
}
// 分配采购员:
每个人都要分配猎芯采购和数据跟单员两种类型
// 分配采购员:
根据情况分配
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
);
}
// 如果只需要分配数据跟单员
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
);
}
// 检查是否已存在数据跟单员,不存在则分配
$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
);
// 检查是否已存在数据跟单员,不存在则分配
$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
);
}
}
}
...
...
@@ -1243,150 +1259,6 @@ class SupplierService
}
/**
* 刷新历史数据:自动分配猎芯采购和数据跟单员
* 规则:
* - 供应商无猎芯采购和数据跟单员的采购员类型时,按规则同时更新猎芯采购和数据跟单员
* - 供应商有猎芯采购的采购员类型无数据跟单员时,仅更新数据跟单员(将现有猎芯采购人员同时设为数据跟单员)
*
* @param string $mode 模式:prod=生产模式执行数据处理,其他=调试模式仅打印信息
* @param int $num 处理数量限制
* @return array 处理结果
*/
public
static
function
refreshHistoryPurchaseUser
(
$mode
=
'debug'
,
$num
=
50
)
{
ini_set
(
'memory_limit'
,
-
1
);
$supplierService
=
new
self
();
// 判断是否为生产模式
$isProdMode
=
(
$mode
===
'prod'
);
// 获取所有正式供应商
$suppliers
=
SupplierChannelModel
::
where
(
'is_type'
,
0
)
->
where
(
'yunxin_channel_uid'
,
'!='
,
''
)
->
whereNotNull
(
'yunxin_channel_uid'
)
->
limit
(
$num
)
->
get
();
$result
=
[
'mode'
=>
$isProdMode
?
'production'
:
'debug'
,
'total'
=>
0
,
'success'
=>
0
,
'failed'
=>
0
,
'skipped'
=>
0
,
'details'
=>
[],
'debug_info'
=>
[],
// 调试信息
];
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'
]
++
;
$result
[
'debug_info'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'skip_reason'
=>
'已有猎芯采购和数据跟单员'
,
];
continue
;
}
// 生产模式:执行数据更新
if
(
$isProdMode
)
{
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'
=>
'仅分配数据跟单员(基于现有猎芯采购)'
,
'assign_code_ids'
=>
$liexinPurchases
,
];
}
else
{
// 无猎芯采购和数据跟单员:按规则同时分配
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
,
true
);
if
(
$assignResult
[
'success'
])
{
$result
[
'success'
]
++
;
$assignCodeIds
=
isset
(
$assignResult
[
'debug_info'
][
'assign_code_ids'
])
?
$assignResult
[
'debug_info'
][
'assign_code_ids'
]
:
[];
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'分配猎芯采购和数据跟单员'
,
'assign_code_ids'
=>
$assignCodeIds
,
];
}
else
{
$result
[
'failed'
]
++
;
$result
[
'debug_info'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'fail_reason'
=>
isset
(
$assignResult
[
'reason'
])
?
$assignResult
[
'reason'
]
:
'autoAssignPurchaseUser返回false'
,
];
}
}
}
else
{
// 调试模式:只打印信息,不执行更新
$debugItem
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'supplier_group'
=>
$supplier
->
supplier_group
,
'yunxin_channel_uid'
=>
$yunxinChannelUid
,
'has_liexin'
=>
$hasLiexinPurchase
,
'has_data_follower'
=>
$hasDataFollower
,
];
if
(
$hasLiexinPurchase
&&
!
$hasDataFollower
)
{
// 获取现有猎芯采购人员
$liexinPurchases
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
$debugItem
[
'action'
]
=
'将现有猎芯采购设为数据跟单员'
;
$debugItem
[
'liexin_purchase_code_ids'
]
=
$liexinPurchases
;
}
else
{
// 模拟自动分配,获取失败原因
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
,
false
);
$debugItem
[
'action'
]
=
'自动分配猎芯采购和数据跟单员'
;
$debugItem
[
'assign_result'
]
=
$assignResult
;
}
$result
[
'details'
][]
=
$debugItem
;
}
}
return
$result
;
}
/**
* 刷新历史数据(带进度回调,用于Artisan命令)
* @param string $mode 模式
* @param int $num 处理数量
...
...
@@ -1399,6 +1271,8 @@ class SupplierService
set_time_limit
(
0
);
$supplierService
=
new
self
();
$adminUserService
=
new
AdminUserService
();
// 判断是否为生产模式
$isProdMode
=
(
$mode
===
'prod'
);
...
...
@@ -1459,134 +1333,77 @@ class SupplierService
continue
;
}
// 生产模式:执行数据更新
if
(
$isProdMode
)
{
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'
][]
=
[
// 调用autoAssignPurchaseUser处理分配逻辑
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
,
$isProdMode
);
if
(
$assignResult
[
'success'
])
{
// 判断是跳过还是真正分配了
if
(
strpos
(
$assignResult
[
'reason'
],
'跳过'
)
!==
false
)
{
$result
[
'skipped'
]
++
;
$result
[
'debug_info'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'仅分配数据跟单员(基于现有猎芯采购)'
,
'assign_code_ids'
=>
$liexinPurchases
,
'skip_reason'
=>
$assignResult
[
'reason'
],
];
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'
成功:分配数据跟单员'
,
'status'
=>
's
uccess
'
,
'action'
=>
'
跳过:'
.
$assignResult
[
'reason'
]
,
'status'
=>
's
kip
'
,
]);
}
}
else
{
// 无猎芯采购和数据跟单员:按规则同时分配
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
,
true
);
if
(
$assignResult
[
'success'
])
{
$result
[
'success'
]
++
;
$assignCodeIds
=
isset
(
$assignResult
[
'debug_info'
][
'assign_code_ids'
])
?
$assignResult
[
'debug_info'
][
'assign_code_ids'
]
:
[];
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'分配猎芯采购和数据跟单员'
,
'assign_code_ids'
=>
$assignCodeIds
,
];
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'成功:'
.
(
isset
(
$assignResult
[
'reason'
])
?
$assignResult
[
'reason'
]
:
'分配成功'
),
'status'
=>
'success'
,
]);
}
}
else
{
$result
[
'failed'
]
++
;
$result
[
'debug_info'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'fail_reason'
=>
isset
(
$assignResult
[
'reason'
])
?
$assignResult
[
'reason'
]
:
'autoAssignPurchaseUser返回false'
,
];
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'失败:'
.
(
isset
(
$assignResult
[
'reason'
])
?
$assignResult
[
'reason'
]
:
'未知原因'
),
'status'
=>
'failed'
,
]);
}
}
}
}
else
{
// 调试模式:只打印信息,不执行更新
$debugItem
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'supplier_group'
=>
$supplier
->
supplier_group
,
'yunxin_channel_uid'
=>
$yunxinChannelUid
,
'has_liexin'
=>
$hasLiexinPurchase
,
'has_data_follower'
=>
$hasDataFollower
,
];
$result
[
'success'
]
++
;
$assignCodeIds
=
isset
(
$assignResult
[
'debug_info'
][
'assign_code_ids'
])
?
$assignResult
[
'debug_info'
][
'assign_code_ids'
]
:
[];
$assignNames
=
array_map
(
function
(
$codeId
)
use
(
$adminUserService
)
{
return
$adminUserService
->
getAdminUserNameByCodeId
(
$codeId
);
},
$assignCodeIds
);
if
(
$hasLiexinPurchase
&&
!
$hasDataFollower
)
{
// 获取现有猎芯采购人员
$liexinPurchases
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
$debugItem
[
'action'
]
=
'将现有猎芯采购设为数据跟单员'
;
$debugItem
[
'liexin_purchase_code_ids'
]
=
$liexinPurchases
;
// 判断是新增还是补充
$isNew
=
!
$hasLiexinPurchase
&&
!
$hasDataFollower
;
$action
=
$isNew
?
'分配猎芯采购和数据跟单员'
:
'仅分配数据跟单员'
;
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'调试:将现有猎芯采购设为数据跟单员'
,
'status'
=>
'debug'
,
]);
}
}
else
{
// 模拟自动分配,获取失败原因
$assignResult
=
$supplierService
->
autoAssignPurchaseUser
(
$supplierId
,
$yunxinChannelUid
,
false
);
$debugItem
[
'action'
]
=
'自动分配猎芯采购和数据跟单员'
;
$debugItem
[
'assign_result'
]
=
$assignResult
;
$result
[
'details'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
$action
,
'assign_code_ids'
=>
$assignCodeIds
,
'assign_names'
=>
$assignNames
,
'is_new'
=>
$isNew
,
];
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'
调试:'
.
(
isset
(
$assignResult
[
'reason'
])
?
$assignResult
[
'reason'
]
:
'模拟分配'
)
,
'status'
=>
'
debug
'
,
'action'
=>
'
成功:'
.
$action
,
'status'
=>
'
success
'
,
]);
}
}
}
else
{
$result
[
'failed'
]
++
;
$result
[
'debug_info'
][]
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'fail_reason'
=>
$assignResult
[
'reason'
],
];
$result
[
'details'
][]
=
$debugItem
;
// 回调进度
if
(
$progressCallback
)
{
$progressCallback
([
'supplier_id'
=>
$supplierId
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'action'
=>
'失败:'
.
$assignResult
[
'reason'
],
'status'
=>
'failed'
,
]);
}
}
}
...
...
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