小程序导出账单接口
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Services;
|
||||
use App\Models\BillModel;
|
||||
use App\Models\ProductModel;
|
||||
use App\Models\StoreOrderItemModel;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* 账单详情数据组装(后台门店账单页与小程序账单详情共用)
|
||||
@@ -24,6 +25,35 @@ class BillDetailService
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return $this->aggregateItems($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并后的商品明细(跨账单口径):按商品聚合多张账单的全部订单明细
|
||||
* 用于账单合并导出,单价同为加权平均口径
|
||||
*
|
||||
* @param array<int, int> $billIds 账单ID列表
|
||||
* @return array<int, array{product_id: int, product_name: string, product_spec: string, unit: string, price: string, quantity: int, weight: string, amount: string}>
|
||||
*/
|
||||
public function mergedItemsOfBills(array $billIds): array
|
||||
{
|
||||
$items = StoreOrderItemModel::query()
|
||||
->whereIn('bill_id', $billIds)
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
return $this->aggregateItems($items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按商品聚合订单明细:数量累加、重量/金额 bc 累加、单价加权平均,
|
||||
* 按「分类sort → 商品sort」排序
|
||||
*
|
||||
* @param Collection<int, StoreOrderItemModel> $items
|
||||
* @return array<int, array{product_id: int, product_name: string, product_spec: string, unit: string, price: string, quantity: int, weight: string, amount: string}>
|
||||
*/
|
||||
private function aggregateItems(Collection $items): array
|
||||
{
|
||||
// 排序键:分类 sort → 商品 sort(与采购单明细矩阵同序)
|
||||
$products = ProductModel::withTrashed()
|
||||
->with('category:id,sort')
|
||||
|
||||
Reference in New Issue
Block a user