多門店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);
}