feat: 修改了导出订单功能,优化了代码逻辑,增加了异常处理,并更新了文档。

This commit is contained in:
mkm 2024-08-18 12:11:39 +08:00
parent 1f2863ff97
commit 7f62e89ecb
3 changed files with 13 additions and 7 deletions

View File

@ -159,13 +159,18 @@ class StoreOrderController extends BaseAdminController
$total_price=0;
foreach ($data as $key => &$value) {
$find=StoreProduct::where('id',$value->product_id)->find();
$value->store_name=$find['store_name'];
$value->store_info=$find['store_info'];
$value->unit_name=StoreProductUnit::where('id',$value->unit_id)->value('name');
$value->store_name=$find['store_name']??'';
$value->store_info=$find['store_info']??'';
if(!empty($find['unit_id'])){
$value->unit_name=StoreProductUnit::where('id',$find['unit_id'])->value('name');
}else{
$value->unit_name='';
}
$total_num+=$value->cart_num;
$total_price+=$value->total_price;
}
$file_path = $xlsx->export($data,$system_store,$total_num,$total_price);
return response()->download($file_path, $system_store.'.xlsx');
return $this->success('导出成功', ['url' => $file_path]);
}
}

View File

@ -96,6 +96,6 @@ class StoreOrderCartInfoController extends BaseAdminController
$total_price+=$value->total_price;
}
$file_path = $xlsx->export($data,$system_store,$total_num,$total_price);
return response()->download($file_path, $system_store.'.xlsx');
return $this->success('导出成功', ['url' => $file_path]);
}
}

View File

@ -126,9 +126,10 @@ class OrderDetail
// 保存文件到 public 下
$writer = new Xlsx($spreadsheet);
$file_path = public_path() . '/export/' . date('Y-m') . '/' . $system_store . '.xlsx';
$url = '/export/' . date('Y-m') . '/' . $system_store . '.xlsx';
$file_path = public_path() . $url;
// 保存文件到 public 下
$writer->save($file_path);
return $file_path;
return getenv('APP_URL').$url;
}
}