getSql($kvPairs['owner_id'], $kvPairs['counting_month'])->paginate($kvPairs['paginateParams']['paginate'] ?? 50); } public function getSql($owner_id, $counting_month): Builder { list($start, $end) = $this->getStartAndEnd($counting_month); $OwnerPriceOperationQuery = OwnerPriceOperation::query() ->select('id') ->where('operation_type', '出库'); return OwnerFeeOperation::query() ->with(['details', 'model', 'commodity.barcodes']) ->whereIn('model_id', $OwnerPriceOperationQuery) ->whereBetween('worked_at', [$start, $end]) ->where('owner_id', $owner_id); } public function switchType($type) { // TODO: Implement switchType() method. } public function buildExport($details): array { $result = []; foreach ($details as $detail) { // $row = ['作业时间', '作业名称', '上游单号', '订单号', '商家编码', '商品条码', '商品名称', '商品数量', '单价', '价格描述', '合计']; $result[] = [ $detail->worked_at ?? '', $detail->model->name ?? '', $detail->source_number, $detail->doc_number ?? '', $detail->commodity->sku ?? '', $detail->source_number ?? '', $detail->commodity->name ?? '', $detail->details[0]->amount ?? '', $detail->details[0]->price ?? '', $detail->fee_description ?? '', $detail->fee ?? '', ]; } return $result; } public function add(array $model) { // TODO: Implement add() method. } /** * 查询指定货主 月份 按照货主 计费模型汇总的 作业费(出入库费)和税费 * @param $owner_id * @param $counting_month * @return Builder[]|Collection */ public function getTotalFee($owner_id, $counting_month) { list($start, $end) = $this->getStartAndEnd($counting_month); return OwnerFeeDetail::query() ->selectRaw("owner_price_operation_id, sum(work_fee) as work_fee, sum(work_tax_fee) as work_tax_fee ") ->where('owner_id', $owner_id) ->whereBetween('created_at', [$start, $end]) ->groupBy('owner_id', 'owner_price_operation_id') ->get(); } }