账单导出
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Mini;
|
||||
|
||||
use App\Exceptions\RepositoryException;
|
||||
use App\Exports\BillBatchExport;
|
||||
use App\Exports\BillExport;
|
||||
use App\Models\BillModel;
|
||||
use App\Services\BillDetailService;
|
||||
@@ -86,6 +87,37 @@ class BillController extends BaseMiniController
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量导出账单:仅可导出本店账单,选中账单合并在同一工作表
|
||||
*/
|
||||
#[GetRoute('/bill/batch-export', authorize: true)]
|
||||
public function batchExport(Request $request): Response
|
||||
{
|
||||
$data = $request->validate([
|
||||
'ids' => 'required|array|min:1|max:100',
|
||||
'ids.*' => 'required|integer|distinct',
|
||||
], [
|
||||
'ids.required' => '请选择要导出的账单',
|
||||
'ids.max' => '单次最多导出 100 张账单',
|
||||
'ids.*.distinct' => '账单不能重复选择',
|
||||
]);
|
||||
|
||||
$store = $this->currentStore($request);
|
||||
$bills = BillModel::query()
|
||||
->with('store:id,name')
|
||||
->where('store_id', $store->id)
|
||||
->whereIn('id', $data['ids'])
|
||||
->orderBy('bill_date')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
if ($bills->count() !== count($data['ids'])) {
|
||||
throw new RepositoryException('包含不存在或不属于当前门店的账单');
|
||||
}
|
||||
|
||||
return Excel::download(new BillBatchExport($bills), '门店账单_批量导出.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 单独导出账单:仅可导出本店账单(强制 store_id 过滤);
|
||||
* ?category_id= 一级分类过滤(0/缺省=全部)
|
||||
|
||||
Reference in New Issue
Block a user