账单导出

This commit is contained in:
2026-10-30 10:51:09 +08:00
parent 42a3fa00d4
commit 7366d88baf
178 changed files with 1166 additions and 898 deletions
@@ -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/缺省=全部)
@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Recon;
use App\Exceptions\RepositoryException;
use App\Exports\BillBatchExport;
use App\Exports\BillExport;
use App\Models\BillModel;
use App\Models\StoreModel;
@@ -60,6 +61,27 @@ class BillController extends BaseController
return $this->success($data);
}
/**
* 批量导出账单:同一门店的账单合并在一张工作表,不同门店拆分为多个工作表
*/
#[GetRoute(route: '/batch-export', authorize: 'export')]
public function batchExport(Request $request): Response
{
$data = $request->validate([
'ids' => 'required|array|min:1|max:100',
'ids.*' => 'required|integer|distinct|exists:bill,id',
]);
$bills = BillModel::query()
->with('store:id,name')
->whereIn('id', $data['ids'])
->orderBy('bill_date')
->orderBy('id')
->get();
return Excel::download(new BillBatchExport($bills), '门店账单_批量导出.xlsx');
}
/**
* 单独导出账单:账单内明细按商品合并(可按一级分类过滤),
* 表尾汇总商品金额/配送费/附加金额/售后金额/总金额