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
ce33544a
authored
Jan 03, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
数据脚本完善
parent
94953e01
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
36 deletions
app/Http/Services/DataService.php
app/Http/routes.php
app/Providers/AppServiceProvider.php
app/Http/Services/DataService.php
View file @
ce33544a
...
...
@@ -1000,6 +1000,7 @@ class DataService
$supplierCode
=
trim
(
$data
[
0
]);
$dataFollowers
=
trim
(
$data
[
2
]);
$onlinePurchaser
=
trim
(
$data
[
3
]);
$onlinePurchaser
=
preg_replace
(
'/[^\x{4e00}-\x{9fa5}]/u'
,
''
,
$onlinePurchaser
);
// 处理多个数据跟单员的情况
$followerList
=
[];
...
...
@@ -1023,12 +1024,14 @@ class DataService
return
;
}
$adminUserService
=
new
AdminUserService
();
$intracodeModel
=
new
IntracodeModel
();
$historicalSuppliers
=
array_slice
(
$historicalSuppliers
,
0
,
50
);
// 只处理前5个进行测试
foreach
(
$historicalSuppliers
as
$supplierCode
=>
$supplierInfo
)
{
\dump
(
"----------------------------------------------------------------"
);
\dump
(
"开始处理供应商: "
.
$supplierCode
.
'----'
.
$supplierInfo
[
'name'
]);
// 查找供应商
$supplier
=
SupplierChannelModel
::
where
(
'supplier_code'
,
$supplierCode
)
->
first
();
if
(
!
$supplier
)
{
\dump
(
"供应商不存在: "
.
$supplierCode
);
continue
;
}
...
...
@@ -1052,12 +1055,16 @@ class DataService
$followerCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'邱沛敏'
);
if
(
$followerCodeId
)
{
$dataFollowersCodeIds
[]
=
$followerCodeId
;
}
else
{
dd
(
'找不到邱沛敏'
,
$supplierCode
,
$supplier
->
region
,
$supplier
);
}
}
else
{
// 其他区域分配李尚文杰
$followerCodeId
=
$adminUserService
->
getCodeIdByUserName
(
'李尚文杰'
);
if
(
$followerCodeId
)
{
$dataFollowersCodeIds
[]
=
$followerCodeId
;
}
else
{
dd
(
'找不到李尚文杰'
,
$supplierCode
,
$supplier
->
region
,
$supplier
);
}
}
}
...
...
@@ -1071,62 +1078,95 @@ class DataService
$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
()
]);
\dump
(
'跟单采购员 : '
.
implode
(
','
,
$dataFollowersCodeIds
));
\dump
(
'所有采购员 : '
.
implode
(
','
,
$allChannelUids
));
$onlinePurchaserCodeId
=
$adminUserService
->
getCodeIdByUserName
(
$onlinePurchaser
);
\dump
(
$onlinePurchaserCodeId
);
\dump
(
'需要获取联系人的采购员 : '
.
$onlinePurchaserCodeId
);
if
(
empty
(
$onlinePurchaserCodeId
))
{
\dump
(
'表格里的线上采购员不存在,跳过'
);
continue
;
}
//
为每个数据跟单员创建联系人记录
//3.2 数据跟单员的联系人信息:初始化为【线上采购员】维护的联系人信息
//
如果数据跟单员已经存在在供应商的采购员里,也需要把他对应的联系人初始化成线上采购员对应的联系人信息
foreach
(
$dataFollowersCodeIds
as
$followerCodeId
)
{
$onlinePurchaserContact
=
SupplierContactModel
::
where
(
'can_check_uids'
,
$onlinePurchaserCodeId
)
->
first
();
if
(
!
empty
(
$onlinePurchaserContact
))
{
$onlinePurchaserContact
=
$onlinePurchaserContact
->
toArray
();
}
$contactData
=
[
'supplier_id'
=>
$supplierId
,
'supplier_consignee'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_consignee'
])
?
$onlinePurchaserContact
[
'supplier_consignee'
]
:
''
,
'supplier_telephone'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_telephone'
])
?
$onlinePurchaserContact
[
'supplier_telephone'
]
:
''
,
'supplier_fax'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_fax'
])
?
$onlinePurchaserContact
[
'supplier_fax'
]
:
''
,
'supplier_qq'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_qq'
])
?
$onlinePurchaserContact
[
'supplier_qq'
]
:
''
,
'supplier_mobile'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_mobile'
])
?
$onlinePurchaserContact
[
'supplier_mobile'
]
:
''
,
'supplier_email'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_email'
])
?
$onlinePurchaserContact
[
'supplier_email'
]
:
''
,
'supplier_position'
=>
!
empty
(
$onlinePurchaserContact
[
'supplier_position'
])
?
$onlinePurchaserContact
[
'supplier_position'
]
:
''
,
];
// 检查是否已存在该数据跟单员的联系人记录
$exists
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$followerCodeId
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_
LIEXIN
)
->
where
(
'channel_user_type'
,
SupplierContactModel
::
CHANNEL_USER_TYPE_
INVENTORY
)
->
exists
();
if
(
$exists
)
{
\dump
(
'已经存在跟单联系人 : '
.
$followerCodeId
.
' 跳过'
);
continue
;
}
if
(
!
$exists
)
{
// 创建联系人记录
$contactData
=
[
'supplier_id'
=>
$supplierId
,
// 联系人不存在,需要创建
//先去判断已经有的供应商联系人里面有没有一样的采购员
$existingContact
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
where
(
'can_check_uids'
,
$followerCodeId
)
->
where
(
'supplier_telephone'
,
'!='
,
''
)
->
first
();
if
(
!
empty
(
$existingContact
))
{
$existingContact
=
$existingContact
->
toArray
();
\dump
(
'已存在线上采购员相同联系人 : '
.
$followerCodeId
.
' 进行信息覆盖'
);
$contactData
=
[
'supplier_id'
=>
$supplierId
,
'supplier_consignee'
=>
!
empty
(
$existingContact
[
'supplier_consignee'
])
?
$existingContact
[
'supplier_consignee'
]
:
''
,
'supplier_telephone'
=>
!
empty
(
$existingContact
[
'supplier_telephone'
])
?
$existingContact
[
'supplier_telephone'
]
:
''
,
'supplier_fax'
=>
!
empty
(
$existingContact
[
'supplier_fax'
])
?
$existingContact
[
'supplier_fax'
]
:
''
,
'supplier_qq'
=>
!
empty
(
$existingContact
[
'supplier_qq'
])
?
$existingContact
[
'supplier_qq'
]
:
''
,
'supplier_mobile'
=>
!
empty
(
$existingContact
[
'supplier_mobile'
])
?
$existingContact
[
'supplier_mobile'
]
:
''
,
'supplier_email'
=>
!
empty
(
$existingContact
[
'supplier_email'
])
?
$existingContact
[
'supplier_email'
]
:
''
,
'supplier_position'
=>
!
empty
(
$existingContact
[
'supplier_position'
])
?
$existingContact
[
'supplier_position'
]
:
''
,
];
}
$contactData
=
array_merge
(
$contactData
,
[
'can_check_uids'
=>
$followerCodeId
,
'channel_user_type'
=>
4
,
// 数据跟单员
'add_time'
=>
time
(),
'admin_id'
=>
1000
// 系统管理员
];
\dump
(
'
Creating contact for follower:'
,
$followerCodeId
,
$supplierId
);
]
)
;
\dump
(
'
创建跟单联系人: '
.
$followerCodeId
.
' 供应商ID : '
.
$supplierId
.
' 供应商名称 : '
.
$supplierInfo
[
'name'
]
);
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
SupplierC
ontactModel
::
where
(
'contact_id'
,
$contact
->
contact_i
d
)
->
update
([
'channel_u
ser_type'
=>
4
$allChannelUids
=
SupplierContactModel
::
where
(
'supplier_id'
,
$supplierId
)
->
pluck
(
'can_check_uids'
)
->
toArray
();
$allChannelUids
=
array_unique
(
$allChannelUids
);
$allChannelUids
=
array_filter
(
$allChannelUids
,
function
(
$value
)
{
return
!
empty
(
$value
);
});
\dump
(
'最后更新的供应商采购员列表为 : '
.
\implode
(
','
,
$allChannelUids
)
);
if
(
$updateData
)
{
if
(
$allChannelUids
)
{
SupplierC
hannelModel
::
where
(
'supplier_id'
,
$supplierI
d
)
->
update
([
'channel_u
id'
=>
\implode
(
','
,
$allChannelUids
),
]);
}
}
}
Log
::
info
(
"供应商
{
$supplierCode
}
数据初始化完成"
);
}
Log
::
info
(
'历史供应商数据初始化完成'
);
}
}
app/Http/routes.php
View file @
ce33544a
...
...
@@ -96,7 +96,7 @@ Route::group(['middleware' => ['external'], 'namespace' => 'Sync'], function ()
});
Route
::
match
([
'get'
,
'post'
],
'/test'
,
function
()
{
DataService
::
initHistoricalSupplierData
();
DataService
::
initHistoricalSupplierData
(
false
);
// DataService::initSupplierReceiptNationId();
// SupplierAccountService::initYunxinAccountName();
// DataService::syncSupplierToErp();
...
...
app/Providers/AppServiceProvider.php
View file @
ce33544a
...
...
@@ -4,6 +4,8 @@ namespace App\Providers;
use
Illuminate\Support\Facades\View
;
use
Illuminate\Support\ServiceProvider
;
use
Symfony\Component\VarDumper\Cloner\VarCloner
;
use
Symfony\Component\VarDumper\Dumper\HtmlDumper
;
class
AppServiceProvider
extends
ServiceProvider
{
...
...
@@ -14,8 +16,33 @@ class AppServiceProvider extends ServiceProvider
*/
public
function
boot
()
{
//共享全局模板变量
// 只在本地环境生效
if
(
$this
->
app
->
environment
(
'local'
))
{
// 自定义一个新的 Handler
\Symfony\Component\VarDumper\VarDumper
::
setHandler
(
function
(
$var
)
{
$cloner
=
new
VarCloner
();
$dumper
=
new
HtmlDumper
();
// 关键:自定义白色背景的样式(覆盖默认黑色)
$dumper
->
setStyles
([
'default'
=>
'background-color:#fff; color:#222; line-height:1.5; font-weight: normal; font:12px Menlo, Monaco, Consolas, "Courier New", monospace; padding: 15px; border:1px solid #ddd; border-radius:4px; margin:10px 0;'
,
'num'
=>
'color:#a71d5d;'
,
'const'
=>
'color:#795da3;'
,
'str'
=>
'color:#df5000;'
,
'note'
=>
'color:#a71d5d;'
,
'ref'
=>
'color:#a0a0a0;'
,
'public'
=>
'color:#795da3;'
,
'protected'
=>
'color:#795da3;'
,
'private'
=>
'color:#795da3;'
,
'meta'
=>
'color:#b729d9;'
,
'key'
=>
'color:#df5000;'
,
'index'
=>
'color:#a71d5d;'
,
]);
// 正确传参:先 cloner 克隆,再 dumper 输出
$dumper
->
dump
(
$cloner
->
cloneVar
(
$var
));
});
}
}
/**
...
...
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