1 回答
TA贡献1111条经验 获得超0个赞
如果您的频道有限(如 5-20),则使用以下代码:
<?php
$items = Revenue::groupBy('channel')->get(['channel']);
$re = [];
foreach ($items as $key => $value) {
$re['daily'][$value] = Revenue::where('channel',$value)->whereDate('created_at',date('Y-m-d'))->sum('amount');
$re['weekly'][$value] = Revenue::where('channel',$value)->whereBetween('date', [
Carbon::parse('last monday')->startOfDay(),
Carbon::parse('next friday')->endOfDay(),
])->sum('amount');
$re['monthly'][$value] = Revenue::where('channel',$value)->whereMonth('created_at',date('m'))->sum('amount');
$re['yearly'][$value] = Revenue::where('channel',$value)->whereYear('created_at',date('Y'))->sum('amount');
}
var_dump($re);
在这段代码中,我们首先分离通道,然后使用它们来计算所需的结果。顺便说一句,代码是要测试的。
- 1 回答
- 0 关注
- 228 浏览
添加回答
举报