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
0b7e1243
authored
Dec 24, 2025
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
暂时的处理
parent
bf1160c9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
1 deletions
app/Http/Services/DataService.php
app/Http/routes.php
public/data/数据跟单员.csv
app/Http/Services/DataService.php
View file @
0b7e1243
...
...
@@ -924,6 +924,7 @@ class DataService
Log
::
info
(
'已将所有用户oauth的sales_id重置为0'
);
}
//供应商
public
static
function
initSupplierCacche
()
{
...
...
@@ -949,4 +950,183 @@ class DataService
$redis
->
hset
(
'lie_supplier_info'
,
$supplier
[
'supplier_id'
],
json_encode
(
$data
));
}
}
/**
* 初始化历史供应商数据
* 1. 初始化采购员、数据跟单员
* 2. 根据区域分配数据跟单员
* 3. 初始化数据跟单员的联系人信息
*/
public
static
function
initHistoricalSupplierData
(
$updateData
=
false
)
{
// 从CSV文件读取历史供应商数据
$csvFilePath
=
public_path
(
'data'
)
.
DIRECTORY_SEPARATOR
.
'数据跟单员.csv'
;
$historicalSuppliers
=
[];
if
(
file_exists
(
$csvFilePath
))
{
// 检测文件编码并正确读取
$content
=
file_get_contents
(
$csvFilePath
);
$encoding
=
mb_detect_encoding
(
$content
,
[
'UTF-8'
,
'GBK'
,
'GB2312'
,
'ASCII'
],
true
);
// 如果不是UTF-8编码,转换为UTF-8
if
(
$encoding
&&
$encoding
!==
'UTF-8'
)
{
$content
=
mb_convert_encoding
(
$content
,
'UTF-8'
,
$encoding
);
}
// 将内容写入临时内存流
$stream
=
fopen
(
'php://memory'
,
'r+'
);
fwrite
(
$stream
,
$content
);
rewind
(
$stream
);
// 跳过标题行
fgetcsv
(
$stream
);
while
((
$data
=
fgetcsv
(
$stream
))
!==
false
)
{
// 假设CSV格式为: 供应商编码,供应商名称,数据跟单员,线上采购员
if
(
count
(
$data
)
>=
4
)
{
// 确保数据是UTF-8编码
$data
=
array_map
(
function
(
$item
)
{
if
(
is_string
(
$item
))
{
// 确保字符串是UTF-8编码
$encoding
=
mb_detect_encoding
(
$item
,
[
'UTF-8'
,
'GBK'
,
'GB2312'
,
'ASCII'
],
true
);
if
(
$encoding
&&
$encoding
!==
'UTF-8'
)
{
return
mb_convert_encoding
(
$item
,
'UTF-8'
,
$encoding
);
}
return
$item
;
}
return
$item
;
},
$data
);
$supplierCode
=
trim
(
$data
[
0
]);
$dataFollowers
=
trim
(
$data
[
2
]);
$onlinePurchaser
=
trim
(
$data
[
3
]);
// 处理多个数据跟单员的情况
$followerList
=
[];
if
(
!
empty
(
$dataFollowers
))
{
// 分割多个跟单员(使用顿号、中文逗号、英文逗号)
$followerList
=
preg_split
(
'/[、,,]/u'
,
$dataFollowers
);
$followerList
=
array_map
(
'trim'
,
$followerList
);
$followerList
=
array_filter
(
$followerList
);
}
$historicalSuppliers
[
$supplierCode
]
=
[
'name'
=>
trim
(
$data
[
1
]),
'data_followers'
=>
$followerList
,
'online_purchaser'
=>
$onlinePurchaser
];
}
}
fclose
(
$stream
);
}
else
{
Log
::
error
(
'数据跟单员.csv文件未找到'
);
return
;
}
$adminUserService
=
new
AdminUserService
();
$intracodeModel
=
new
IntracodeModel
();
$historicalSuppliers
=
array_slice
(
$historicalSuppliers
,
0
,
50
);
// 只处理前5个进行测试
foreach
(
$historicalSuppliers
as
$supplierCode
=>
$supplierInfo
)
{
// 查找供应商
$supplier
=
SupplierChannelModel
::
where
(
'supplier_code'
,
$supplierCode
)
->
first
();
if
(
!
$supplier
)
{
continue
;
}
$supplierId
=
$supplier
->
supplier_id
;
// 处理数据跟单员
$dataFollowersCodeIds
=
[];
if
(
!
empty
(
$supplierInfo
[
'data_followers'
]))
{
foreach
(
$supplierInfo
[
'data_followers'
]
as
$followerName
)
{
$followerCodeId
=
$adminUserService
->
getCodeIdByUserName
(
$followerName
);
if
(
$followerCodeId
)
{
$dataFollowersCodeIds
[]
=
$followerCodeId
;
}
}
}
// 如果没有提供数据跟单员,则根据区域规则分配
if
(
empty
(
$dataFollowersCodeIds
))
{
// 国内区域分配邱沛敏
if
(
$supplier
->
region
==
SupplierChannelModel
::
REGION_CN
)
{
$followerCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'邱沛敏'
);
if
(
$followerCodeId
)
{
$dataFollowersCodeIds
[]
=
$followerCodeId
;
}
}
else
{
// 其他区域分配李尚文杰
$followerCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'李尚文杰'
);
if
(
$followerCodeId
)
{
$dataFollowersCodeIds
[]
=
$followerCodeId
;
}
}
}
// 更新供应商的channel_uid字段
if
(
!
empty
(
$dataFollowersCodeIds
))
{
// 获取现有的channel_uid
$existingChannelUids
=
explode
(
','
,
trim
(
$supplier
->
channel_uid
,
','
));
// 合并现有的和新的数据跟单员
$allChannelUids
=
array_unique
(
array_merge
(
$existingChannelUids
,
$dataFollowersCodeIds
));
$allChannelUids
=
array_filter
(
$allChannelUids
);
// 移除空值
\dump
(
'allChannelUids:'
,
$allChannelUids
);
if
(
$updateData
)
{
// 更新供应商的channel_uid
SupplierChannelModel
::
where
(
'supplier_id'
,
$supplierId
)
->
update
([
'channel_uid'
=>
implode
(
','
,
$allChannelUids
),
'update_time'
=>
time
()
]);
}
// 为每个数据跟单员创建联系人记录
foreach
(
$dataFollowersCodeIds
as
$followerCodeId
)
{
// 检查是否已存在该数据跟单员的联系人记录
$exists
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$followerCodeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_LIEXIN
)
->
exists
();
if
(
!
$exists
)
{
// 创建联系人记录
$contactData
=
[
'supplier_id'
=>
$supplierId
,
'can_check_uids'
=>
$followerCodeId
,
'channel_user_type'
=>
4
,
// 数据跟单员
'add_time'
=>
time
(),
'admin_id'
=>
1000
// 系统管理员
];
\dump
(
'Creating contact for follower:'
,
$followerCodeId
,
$supplierId
);
if
(
$updateData
)
{
SupplierContactModel
::
insert
(
$contactData
);
}
}
}
}
// 更新数据跟单员的联系人信息为线上采购员维护的联系人信息
if
(
!
empty
(
$dataFollowersCodeIds
))
{
foreach
(
$dataFollowersCodeIds
as
$followerCodeId
)
{
// 检查数据跟单员是否已存在对应的采购员code_id且channel_user_type=1
$contact
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$followerCodeId
)
->
where
(
'channel_user_type'
,
1
)
->
first
();
\dump
(
'Checking contact for follower:'
,
$followerCodeId
,
$supplierId
,
$contact
?
'exists'
:
'not exists'
,
$updateData
?
'update'
:
'no update'
);
if
(
$contact
&&
$updateData
)
{
// 更新channel_user_type为4
SupplierContactModel
::
where
(
'contact_id'
,
$contact
->
contact_id
)
->
update
([
'channel_user_type'
=>
4
]);
}
}
}
Log
::
info
(
"供应商
{
$supplierCode
}
数据初始化完成"
);
}
Log
::
info
(
'历史供应商数据初始化完成'
);
}
}
app/Http/routes.php
View file @
0b7e1243
...
...
@@ -96,7 +96,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
DataService
::
init
SupplierCacche
();
DataService
::
init
HistoricalSupplierData
();
// DataService::initSupplierReceiptNationId();
// SupplierAccountService::initYunxinAccountName();
// DataService::syncSupplierToErp();
...
...
public/data/数据跟单员.csv
0 → 100644
View file @
0b7e1243
This diff is collapsed.
Click to expand it.
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