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
7dcecc38
authored
Jan 04, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
376990bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
2 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Http/Services/DataService.php
View file @
7dcecc38
...
...
@@ -1264,7 +1264,7 @@ class DataService
}
}
//判断是否已经存在,不存在就新增,存在就更新
$exist
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
whereIn
(
'can_check_uids'
,
[
$exist
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
whereIn
(
'can_check_uids'
,
[
'10009'
,
'10546'
])
->
value
(
'contact_id'
);
...
...
@@ -1308,4 +1308,114 @@ class DataService
}
}
}
public
static
function
repair
(
$updateData
=
false
)
{
ini_set
(
'memory_limit'
,
-
1
);
// 从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
]);
$onlinePurchaser
=
preg_replace
(
'/[^\x{4e00}-\x{9fa5}]/u'
,
''
,
$onlinePurchaser
);
// 处理多个数据跟单员的情况
$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
;
}
$inXslSupplierCodes
=
array_keys
(
$historicalSuppliers
);
//获取所有供应商
$supplierList
=
SupplierChannelModel
::
whereIn
(
'supplier_code'
,
$inXslSupplierCodes
)
->
select
([
'supplier_id'
,
'channel_uid'
,
'supplier_code'
,
'yunxin_channel_uid'
,
'region'
])
->
get
();
foreach
(
$supplierList
as
$key
=>
$supplier
)
{
$yunxinChannelContact
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplier
[
'supplier_id'
])
->
where
(
'can_check_uids'
,
$supplier
[
'yunxin_channel_uid'
])
->
first
();
if
(
empty
(
$yunxinChannelContact
))
{
//并且有跟单采购员,那么取信息补充增减回去
$contact
=
SupplierContactModel
::
where
(
'channel_user_type'
,
4
)
->
where
(
'supplier_telephone'
,
'!='
,
''
)
->
first
();
if
(
empty
(
$contact
))
{
continue
;
}
//存在需要补回去的数据
\dump
(
'supplier_code : '
.
$supplier
[
'supplier_code'
]);
if
(
$updateData
)
{
//新增回去
SupplierContactModel
::
insert
([
'supplier_id'
=>
$supplier
[
'supplier_id'
],
'supplier_consignee'
=>
$contact
[
'supplier_consignee'
],
'supplier_telephone'
=>
$contact
[
'supplier_telephone'
],
'supplier_fax'
=>
$contact
[
'supplier_fax'
],
'supplier_qq'
=>
$contact
[
'supplier_qq'
],
'supplier_mobile'
=>
$contact
[
'supplier_mobile'
],
'supplier_email'
=>
$contact
[
'supplier_email'
],
'supplier_position'
=>
$contact
[
'supplier_position'
],
'can_check_uids'
=>
$contact
[
'can_check_uids'
],
'add_time'
=>
time
(),
'admin_id'
=>
$contact
[
'admin_id'
],
'channel_user_type'
=>
1
,
]);
}
}
}
}
}
app/Http/routes.php
View file @
7dcecc38
...
...
@@ -97,7 +97,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
DataService
::
initInventoryNotInXsl
();
DataService
::
repair
();
// DataService::initInventoryNotInXsl(true);
if
(
request
()
->
get
(
'delete'
))
{
}
...
...
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