where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
});
//利润
$costPrice = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
});
//已完成订单
$count = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
});
$dateTime = request('created_at', 0);
if ($dateTime) {
$price->whereBetween('created_at',$dateTime);
$costPrice->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',$dateTime);
}
$price = $price->sum('price');
$costPrice = $costPrice->sum('price');
$profit = bcsub($price,$costPrice,2);
$count = $count->count();
return $content
->body(
<<
HTML
)
->body(function (Row $row){
$row->column(6,function (Column $column){
$column->row(new \App\AdminSupplier\Tools\DataReportDate('data_report'));
});
})
->body(function (Row $row) use ($price, $profit, $count) {
$row->column(4, function (Column $column) use ($price) {
$column->row(Card::make('金额', function () use ($price) {
return <<
$price
HTML;
}));
});
$row->column(4, function (Column $column) use ($profit) {
$column->row(Card::make('利润', function () use ($profit) {
return <<
$profit
HTML;
}));
});
$row->column(4, function (Column $column) use ($count) {
$column->row(Card::make('已完成订单', function () use ($count) {
return <<
$count
HTML;
}));
});
})
->body(function (Row $row){
// 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
$menu = [
'1' => '日',
'30' => '月',
'365' => '年',
];
$buttonName = '日';
if (Arr::exists($menu, \request()->input('time_key', ''))) {
$buttonName = $menu[\request()->input('time_key')];
}
$dropdown = Dropdown::make($menu)
->button(current($menu))
->button($buttonName)
->click()
->map(function ($v, $k) {
$querys = \request()->all();
$querys['time_key'] = $k;
$queryString = http_build_query($querys);
$str = Str::replaceFirst('admin-supplier/','',request()->path());
$url = admin_url($str.'?'.$queryString);
// 此处设置的 data-xxx 属性会作为post数据发送到后端api
return "{$v}";
});
// 传递自定义参数
$bar = FinanceStatistics::make()
->fetching('$("#my-box").loading()') // 设置loading效果
->fetched('$("#my-box").loading(false)') // 移除loading效果
->click('.switch-bar'); // 设置图表点击菜单则重新发起请求,且被点击的目标元素上的 data-xxx 属性会被作为post数据发送到后端API
$box = Box::make('成本总额图表', $bar)
->id('my-box') // 设置盒子的ID
->tool($dropdown); // 设置下拉菜单按钮
$row->column(12, $box);
});
}
}