currentUser($request); $store = $this->ensureStoreBound($user); $data = BillModel::query() ->where('store_id', $store->id) ->with('purchase:id,purchase_no,purchase_date') ->orderBy('bill_date', 'desc') ->orderBy('id', 'desc') ->paginate((int) $request->input('pageSize', 10)) ->toArray(); return $this->success($data); } /** 账单详情(校验归属:仅能查看本店账单;含合并后的商品明细与关联订单) */ #[GetRoute('/bill/{id}', authorize: true, where: ['id' => '[0-9]+'])] public function detail(int $id, Request $request): JsonResponse { $user = $this->currentUser($request); $store = $this->ensureStoreBound($user); $bill = BillModel::with('purchase:id,purchase_no,purchase_date') ->where('store_id', $store->id) ->find($id); if ($bill === null) { throw new RepositoryException('账单不存在'); } $orders = $bill->orders() ->orderBy('id') ->get(['id', 'order_no', 'order_date', 'total_quantity', 'total_weight', 'total_amount', 'status']) ->toArray(); return $this->success([ 'bill' => $bill->toArray(), 'items' => app(BillDetailService::class)->mergedItems($bill), 'orders' => $orders, ]); } /** * 在线支付(预留接口,本次不实现;当前为线下收款,由后台手动登记) */ #[PostRoute('/bill/{id}/pay', authorize: true, where: ['id' => '[0-9]+'])] public function pay(int $id, Request $request): JsonResponse { throw new RepositoryException('在线支付暂未开通,请线下付款后由商家登记收款'); } }