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
64304a05
authored
Jul 30, 2025
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
fix
parent
87c2c41e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
3 deletions
app/Console/Commands/SupplierRecallMailRemind.php
app/Console/Commands/SupplierRecallMailRemind.php
View file @
64304a05
...
...
@@ -28,6 +28,58 @@ class SupplierRecallMailRemind extends Command
*/
protected
$description
=
'寄售召回期邮件提醒(提前30天、7天)'
;
/**
* 上传CSV文件到文件系统
*
* @param string $filePath
* @param string $fileName
* @return string|null
*/
private
function
uploadCsvFile
(
$filePath
,
$fileName
)
{
try
{
// 检查文件是否存在
if
(
!
file_exists
(
$filePath
))
{
return
null
;
}
// 创建cURL文件对象
$cfile
=
curl_file_create
(
$filePath
,
'text/csv'
,
$fileName
);
// 准备POST数据
$post
=
[
[
'name'
=>
'file'
,
'contents'
=>
fopen
(
$filePath
,
'r'
),
],
];
$client
=
new
\GuzzleHttp\Client
();
$response
=
$client
->
request
(
'POST'
,
'https://files.ichunt.net/uploadFile?sys_type=5&create_uid=1000'
,
[
'multipart'
=>
$post
,
]);
// 检查是否有错误
if
(
$response
->
getStatusCode
()
!==
200
)
{
$error
=
$response
->
getBody
()
->
getContents
();
$this
->
error
(
"文件上传失败:
{
$error
}
"
);
return
null
;
}
// 解析响应
$result
=
json_decode
(
$response
->
getBody
()
->
getContents
(),
true
);
// 检查上传是否成功
if
(
isset
(
$result
[
'code'
])
&&
$result
[
'code'
]
==
0
&&
isset
(
$result
[
'data'
][
'oss_file_url'
]))
{
return
$result
[
'data'
][
'oss_file_url'
];
}
else
{
$errorMsg
=
isset
(
$result
[
'msg'
])
?
$result
[
'msg'
]
:
'未知错误'
;
$this
->
error
(
"文件上传失败:
{
$errorMsg
}
"
);
return
null
;
}
}
catch
(
\Exception
$e
)
{
$this
->
error
(
"文件上传异常: "
.
$e
->
getMessage
());
return
null
;
}
}
public
function
handle
()
{
$today
=
Carbon
::
today
();
...
...
@@ -103,8 +155,11 @@ class SupplierRecallMailRemind extends Command
$departmentIds
=
DB
::
table
(
'department'
)
->
where
(
'parent'
,
$purchaseUser
->
department_id
)
->
orWhere
(
'departmentId'
,
$purchaseUser
->
department_id
)
->
pluck
(
'departmentId'
)
->
toArray
();
->
pluck
(
'departmentId'
);
if
(
empty
(
$departmentIds
))
{
continue
;
}
$departmentIds
=
$departmentIds
->
toArray
();
$manager
=
DB
::
table
(
'user_info'
)
->
whereIn
(
'department_id'
,
$departmentIds
)
->
where
(
'position_name'
,
'采购经理'
)
...
...
@@ -130,13 +185,43 @@ class SupplierRecallMailRemind extends Command
$subject
=
"【寄售召回提醒】距离召回期仅剩
{
$diff
}
天"
;
$content
=
"请及时提醒供应商召回寄售商品
\n
供应商名称:
{
$supplierName
}
\n
召回期:
{
$recallTimeStr
}
"
;
if
(
empty
(
$skuDataList
))
{
continue
;
}
//生成csv
$csvFileName
=
'supplier_recall_skus_'
.
$supplier
->
id
.
'_'
.
time
()
.
'.csv'
;
$csvFilePath
=
storage_path
(
'app/'
.
$csvFileName
);
// 创建CSV文件
$fp
=
fopen
(
$csvFilePath
,
'w'
);
// 添加BOM头以支持中文
fwrite
(
$fp
,
"
\xEF\xBB\xBF
"
);
// 写入标题行
fputcsv
(
$fp
,
[
'商品名称'
,
'品牌'
,
'库存'
]);
// 写入数据行
foreach
(
$skuDataList
as
$sku
)
{
fputcsv
(
$fp
,
[
$sku
[
'spu_name'
],
$sku
[
'brand_name'
],
$sku
[
'stock'
]]);
}
fclose
(
$fp
);
// 上传CSV文件到文件系统
$fileUrl
=
$this
->
uploadCsvFile
(
$csvFilePath
,
$csvFileName
);
// 删除临时CSV文件
if
(
file_exists
(
$csvFilePath
))
{
unlink
(
$csvFilePath
);
}
// 组装邮件数据
$data
=
[
'data'
=>
[
'title'
=>
$subject
,
'content'
=>
$content
,
'content'
=>
$content
.
(
$fileUrl
?
"
\n
CSV文件:
{
$fileUrl
}
"
:
''
)
,
]
];
dump
(
$data
);
dump
(
$toEmails
,
$ccEmails
);
// // 发送邮件
// foreach ($toEmails as $to) {
...
...
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