weizong song 1 month ago
parent 17d7a7437f
commit 8be9fa6df4

@ -341,12 +341,14 @@ class StatisticsController extends CommonController
public function memberBalanceByDate(Request $request)
{
$is_export = $request->get('is_export', 0);
$projects = $this->_checkProjects();
if (!$projects->count()) {
return $this->error($this->noProjects);
}
$mode = $request->mode ?: 'customer';
$project_id = request()->project_id ?? $projects->first()->id;
$project = Project::find($project_id);
$before_date = $request->before_date ?: date("Y-m-d");
$before_datetime = strtotime($before_date . " 23:59:59");
$before_datetime_text = date("Y-m-d H:i:s", $before_datetime);
@ -406,6 +408,45 @@ class StatisticsController extends CommonController
"patient.name as patient_name",
DB::raw("COALESCE(SUM(balance.money), 0) as balance"),
]);
if ($is_export) {
$rows = $orderBalances->toArray();
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '项目名称');
$sheet->setCellValue('B1', '时点');
$sheet->setCellValue('C1', '订单号');
$sheet->setCellValue('D1', '订单状态');
$sheet->setCellValue('E1', '客户手机号');
$sheet->setCellValue('F1', '联系人');
$sheet->setCellValue('G1', '联系电话');
$sheet->setCellValue('H1', '被陪护人');
$sheet->setCellValue('I1', '服务开始');
$sheet->setCellValue('J1', '服务结束');
$sheet->setCellValue('K1', '时点余额');
$count = count($rows);
for ($i = 2; $i <= $count + 1; $i++) {
$row = $rows[$i - 2];
$sheet->setCellValue('A' . $i, $row['project_name']);
$sheet->setCellValue('B' . $i, $row['point_time']);
$sheet->setCellValue('C' . $i, $row['serial']);
$sheet->setCellValue('D' . $i, $row['status_name']);
$sheet->setCellValue('E' . $i, $row['customer_mobile']);
$sheet->setCellValue('F' . $i, $row['contact']);
$sheet->setCellValue('G' . $i, $row['contact_mobile']);
$sheet->setCellValue('H' . $i, $row['patient_name']);
$sheet->setCellValue('I' . $i, $row['from_date']);
$sheet->setCellValue('J' . $i, $row['to_date']);
$sheet->setCellValue('K' . $i, $row['balance']);
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . ($project ? $project->name : '项目') . '_订单时点余额_' . date('YmdHis') . '.xlsx"');
header('Cache-Control: max-age=0');
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
exit;
}
} else {
$customers = (new Customer())
->whereNull("deleted_at")

@ -47,9 +47,7 @@
<label class="control-label mr-1">截止日期</label><input
value="{{ $before_date }}" class="form-control mr-1" name="before_date"
data-plugin="date-picker">
@if(\App\Models\CommonModel::checkExport())
<button class="btn btn-primary ml-1" type="button" onclick="exportOrderBalanceExcel()">导出Excel</button>
@endif
<button class="btn btn-primary ml-1" type="button" onclick="exportOrderBalanceExcel()">导出Excel</button>
@endif
<button type="submit" class="btn btn-primary ml-1">查询</button>
</form>
@ -133,7 +131,9 @@
<script>
function exportOrderBalanceExcel() {
$('.dt-buttons .buttons-excel').first().click();
var url = "{{ url('admin/statistics/member-balance-by-date') }}";
var params = $('form.form-inline').serialize();
window.open(url + '?is_export=1&' + params);
}
</script>

Loading…
Cancel
Save