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
76c865f5
authored
Mar 23, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
2d5b9796
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
243 additions
and
1 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
76c865f5
...
@@ -1638,4 +1638,246 @@ class DataService
...
@@ -1638,4 +1638,246 @@ class DataService
$supplierService
->
saveSkuUploadRulerToRedis
(
$value
[
'supplier_id'
],
$ruler
);
$supplierService
->
saveSkuUploadRulerToRedis
(
$value
[
'supplier_id'
],
$ruler
);
}
}
}
}
/**
* 刷新数据跟单员数据(邱沛敏离职)
* 1.供应商数据跟单员为1人或4人时,需要将邱沛敏替换为李新华;并且将对应的邱沛敏的猎芯采购员给替换成李新华
* 2.供应商数据跟单员为2人或3人时,需补齐新数据跟单组的4人(如果原来有邱沛敏则替换为李新华,并且将对应的邱沛敏的猎芯采购员给替换成李新华,补齐的话,需要新增缺少的跟单采购员,并且要有对应的猎芯采购员(先判断再决定是否要新增猎芯采购员))
*
* @param int $num 处理数量限制,0表示不限制
* @param bool $updateData 是否真正修改数据库
*/
public
static
function
refreshDataFollower
(
$num
=
0
,
$updateData
=
false
)
{
$adminUserService
=
new
AdminUserService
();
$logService
=
new
LogService
();
// 获取李新华的codeId
$newCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'李新华'
,
true
);
if
(
!
$newCodeId
)
{
return
[
'code'
=>
-
1
,
'msg'
=>
'未找到李新华的用户信息'
];
}
// 获取邱沛敏的codeId(可能不存在,已离职)
$oldCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'邱沛敏'
,
false
);
// 获取数据跟单组4人配置
$dataFollowerGroup
=
config
(
'field.ShangpinDataFollowerGroup'
,
[]);
if
(
empty
(
$dataFollowerGroup
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'配置ShangpinDataFollowerGroup为空'
];
}
// 获取4人组的codeId列表
$groupCodeIds
=
[];
foreach
(
$dataFollowerGroup
as
$name
)
{
$codeId
=
$adminUserService
->
getCodeIdByUserName
(
$name
,
true
);
if
(
$codeId
)
{
$groupCodeIds
[
$name
]
=
$codeId
;
}
}
// 找出所有有数据跟单员的供应商
$allSupplierIds
=
SupplierContactModel
::
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
)
->
distinct
()
->
pluck
(
'supplier_id'
)
->
toArray
();
// 如果有num限制
if
(
$num
>
0
)
{
$allSupplierIds
=
array_slice
(
$allSupplierIds
,
0
,
$num
);
}
$total
=
count
(
$allSupplierIds
);
$success
=
0
;
$skip
=
0
;
$logs
=
[];
foreach
(
$allSupplierIds
as
$supplierId
)
{
$supplier
=
SupplierChannelModel
::
where
(
'supplier_id'
,
$supplierId
)
->
first
();
if
(
!
$supplier
)
{
continue
;
}
// 获取该供应商的所有数据跟单员
$dataFollowers
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
)
->
get
();
$currentFollowerCount
=
$dataFollowers
->
count
();
// 获取当前数据跟单员的codeId列表
$currentCodeIds
=
$dataFollowers
->
pluck
(
'can_check_uids'
)
->
toArray
();
$logItem
=
[
'supplier_id'
=>
$supplierId
,
'supplier_code'
=>
$supplier
->
supplier_code
,
'supplier_name'
=>
$supplier
->
supplier_name
,
'old_follower_count'
=>
$currentFollowerCount
,
'actions'
=>
[],
];
// 检查是否包含邱沛敏
$hasOldUser
=
$oldCodeId
&&
in_array
(
$oldCodeId
,
$currentCodeIds
);
// 如果已经有4人或以上,跳过
if
(
$currentFollowerCount
>=
4
&&
!
$hasOldUser
)
{
$skip
++
;
continue
;
}
// 1人或4人时:直接替换邱沛敏为李新华(包括猎芯采购员)
if
(
$currentFollowerCount
==
1
||
$currentFollowerCount
==
4
)
{
if
(
$hasOldUser
)
{
// 替换数据跟单员
if
(
$updateData
)
{
foreach
(
$dataFollowers
as
$follower
)
{
if
(
$follower
->
can_check_uids
==
$oldCodeId
)
{
$follower
->
can_check_uids
=
$newCodeId
;
$follower
->
save
();
break
;
}
}
// 替换对应的猎芯采购员
$liexinContact
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$oldCodeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
first
();
if
(
$liexinContact
)
{
$liexinContact
->
can_check_uids
=
$newCodeId
;
$liexinContact
->
save
();
}
}
$logItem
[
'actions'
][]
=
"数据跟单员:邱沛敏替换为李新华"
;
$logItem
[
'actions'
][]
=
"猎芯采购员:邱沛敏替换为李新华"
;
// 记录供应商日志
$logService
->
AddIgnoreAuditCheckLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'数据跟单员调整'
,
'邱沛敏离职,数据跟单员和猎芯采购员由邱沛敏替换为李新华'
);
$success
++
;
}
}
// 2人或3人时:替换邱沛敏为李新华,并补齐到4人
elseif
(
$currentFollowerCount
==
2
||
$currentFollowerCount
==
3
)
{
$actionContents
=
[];
// 替换邱沛敏为李新华(如果有)
if
(
$hasOldUser
)
{
if
(
$updateData
)
{
foreach
(
$dataFollowers
as
$follower
)
{
if
(
$follower
->
can_check_uids
==
$oldCodeId
)
{
$follower
->
can_check_uids
=
$newCodeId
;
$follower
->
save
();
break
;
}
}
// 替换对应的猎芯采购员
$liexinContact
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$oldCodeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
first
();
if
(
$liexinContact
)
{
$liexinContact
->
can_check_uids
=
$newCodeId
;
$liexinContact
->
save
();
}
}
$logItem
[
'actions'
][]
=
"数据跟单员:邱沛敏替换为李新华"
;
$logItem
[
'actions'
][]
=
"猎芯采购员:邱沛敏替换为李新华"
;
$actionContents
[]
=
"邱沛敏替换为李新华"
;
}
// 重新获取当前数据跟单员列表
if
(
$updateData
)
{
$currentCodeIds
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
}
else
{
// 如果不更新数据库,模拟替换后的状态
$currentCodeIds
=
array_diff
(
$currentCodeIds
,
[
$oldCodeId
]);
$currentCodeIds
[]
=
$newCodeId
;
}
// 补齐到4人
$addedFollowers
=
[];
foreach
(
$groupCodeIds
as
$name
=>
$codeId
)
{
if
(
!
in_array
(
$codeId
,
$currentCodeIds
))
{
if
(
$updateData
)
{
// 新增数据跟单员
SupplierContactModel
::
insert
([
'supplier_id'
=>
$supplierId
,
'can_check_uids'
=>
$codeId
,
'channel_user_type'
=>
SupplierContactModel
::
CHANNEL_USER_TYPE_INVENTORY
,
'add_time'
=>
time
(),
'admin_id'
=>
1000
,
]);
// 检查是否有对应的猎芯采购员,没有则新增
$hasLiexin
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$codeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
exists
();
if
(
!
$hasLiexin
)
{
SupplierContactModel
::
insert
([
'supplier_id'
=>
$supplierId
,
'can_check_uids'
=>
$codeId
,
'channel_user_type'
=>
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
,
'add_time'
=>
time
(),
'admin_id'
=>
1000
,
]);
}
}
$logItem
[
'actions'
][]
=
"新增数据跟单员:
{
$name
}
"
;
$logItem
[
'actions'
][]
=
"新增猎芯采购员:
{
$name
}
"
;
$addedFollowers
[]
=
$name
;
$currentCodeIds
[]
=
$codeId
;
if
(
count
(
$currentCodeIds
)
>=
4
)
{
break
;
}
}
}
// 记录供应商日志
$logContent
=
'邱沛敏离职,数据跟单员调整:'
;
if
(
$hasOldUser
)
{
$logContent
.=
'邱沛敏替换为李新华;'
;
}
if
(
!
empty
(
$addedFollowers
))
{
$logContent
.=
'补齐数据跟单员:'
.
implode
(
'、'
,
$addedFollowers
);
}
$logService
->
AddIgnoreAuditCheckLog
(
$supplierId
,
LogModel
::
UPDATE_OPERATE
,
'数据跟单员调整'
,
$logContent
);
$success
++
;
}
// 打印每个供应商的操作记录,方便调试
if
(
!
empty
(
$logItem
[
'actions'
]))
{
dump
(
"供应商:
{
$supplier
->
supplier_code
}
-
{
$supplier
->
supplier_name
}
"
);
dump
(
$logItem
[
'actions'
]);
}
$logs
[]
=
$logItem
;
}
// 记录系统日志
Log
::
info
(
'refreshDataFollower执行完成'
,
[
'total'
=>
$total
,
'success'
=>
$success
,
'skip'
=>
$skip
,
'updateData'
=>
$updateData
,
]);
return
[
'code'
=>
0
,
'msg'
=>
'处理完成'
,
'data'
=>
[
'total'
=>
$total
,
'success'
=>
$success
,
'skip'
=>
$skip
,
'updateData'
=>
$updateData
,
'logs'
=>
$logs
,
]
];
}
}
}
app/Http/routes.php
View file @
76c865f5
...
@@ -97,5 +97,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
...
@@ -97,5 +97,5 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
DataService
::
exportSupplier
(
);
DataService
::
refreshDataFollower
(
3
,
true
);
});
});
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