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
0447cbcf
authored
Mar 02, 2026
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
001dbadf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
0 deletions
app/Console/Commands/SyncSupplierToErp.php
app/Console/Kernel.php
app/Console/Commands/SyncSupplierToErp.php
0 → 100644
View file @
0447cbcf
<?php
namespace
App\Console\Commands
;
use
App\Http\Services\SyncSupplierService
;
use
Illuminate\Console\Command
;
use
App\Model\SupplierChannelModel
;
// 同步供应商到ERP
class
SyncSupplierToErp
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'sync:supplier_to_erp {--num=0 : 处理数量限制(0=不限制)}'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'同步供应商到ERP'
;
/**
* Execute the console command.
*
* @return mixed
*/
public
function
handle
()
{
$num
=
(
int
)
$this
->
option
(
'num'
);
ini_set
(
'memory_limit'
,
-
1
);
set_time_limit
(
0
);
ignore_user_abort
(
true
);
ob_implicit_flush
(
true
);
$this
->
info
(
'========================================'
);
$this
->
info
(
'开始同步供应商到ERP'
);
$this
->
info
(
'处理数量: '
.
(
$num
>
0
?
$num
:
'不限制'
));
$this
->
info
(
'========================================'
);
// 构建查询:yunxin_channel_uid不为空且不为0
$query
=
SupplierChannelModel
::
where
(
'is_type'
,
0
)
->
where
(
'yunxin_channel_uid'
,
'!='
,
''
);
if
(
$num
>
0
)
{
$query
->
limit
(
$num
);
}
$suppliers
=
$query
->
get
();
$total
=
count
(
$suppliers
);
$this
->
info
(
"共找到
{
$total
}
个供应商需要同步"
);
$syncService
=
new
SyncSupplierService
();
$success
=
0
;
$failed
=
0
;
$count
=
0
;
foreach
(
$suppliers
as
$supplier
)
{
$count
++
;
$supplierId
=
$supplier
->
supplier_id
;
// 每100条重连数据库
if
(
$count
>
1
&&
$count
%
100
==
0
)
{
\DB
::
reconnect
(
'web'
);
}
echo
"[
{
$count
}
/
{
$total
}
] ID:
{
$supplierId
}
{
$supplier
->
supplier_name
}
... "
;
try
{
$result
=
$syncService
->
syncSupplierToErp
(
$supplierId
);
if
(
$result
)
{
$success
++
;
echo
"成功
\n
"
;
}
else
{
$failed
++
;
echo
"失败
\n
"
;
}
}
catch
(
\Exception
$e
)
{
$failed
++
;
echo
"异常: "
.
$e
->
getMessage
()
.
"
\n
"
;
}
}
$this
->
info
(
''
);
$this
->
info
(
'========================================'
);
$this
->
info
(
'处理完成'
);
$this
->
info
(
'总计: '
.
$total
);
$this
->
info
(
'成功: '
.
$success
);
$this
->
info
(
'失败: '
.
$failed
);
$this
->
info
(
'========================================'
);
return
0
;
}
}
app/Console/Kernel.php
View file @
0447cbcf
...
...
@@ -2,6 +2,7 @@
namespace
App\Console
;
use
App\Console\Commands\SyncSupplierToErp
;
use
Illuminate\Console\Scheduling\Schedule
;
use
Illuminate\Foundation\Console\Kernel
as
ConsoleKernel
;
...
...
@@ -20,6 +21,7 @@ class Kernel extends ConsoleKernel
Commands\SyncAllSupplierToErp
::
class
,
Commands\SupplierRecallMailRemind
::
class
,
Commands\RefreshHistoryPurchaseUser
::
class
,
Commands\SyncSupplierToErp
::
class
,
];
/**
...
...
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