多门店3.1版本,使用云存储后,订单导入发货功能异常
源代码\app\common\controller\Order.php 的 hand_batch_delivery方法中
获取文件路径是用
$file = public_path() . substr($data['file'], 1);
实际开启了云存储后,这样会多拼接一个网站目录,应该改为:
if (str_contains($data['file'], 'http')) {//现在文件到本地临时文件
// 使用 cURL 获取内容
$file = $data['file'];
} else {
$file = public_path() . substr($data['file'], 1);
}
考虑到云存储可能会有仅能下载不能读取的读取权限问题,导致读取失败,改为保存到临时文件再读取
if (str_contains($data['file'], 'http')) {//现在文件到本地临时文件
// 使用 cURL 获取内容
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $data['file']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$excelContent = curl_exec($ch);
curl_close($ch);
$file = tempnam(sys_get_temp_dir(), 'excel') . '.xlsx';
file_put_contents($file, $excelContent);
} else {
$file = public_path() . substr($data['file'], 1);
}