老师,请问一下,下面这个有没有什么更优雅的写法呢?
$opening = OpeningView::whereBetween('complated_at', $ptime)
->where('isComplated', 1)
->where('price', '>', 0)
->select(
DB::raw('sum(price) as price'), //包含退款的实际业绩 + 退款
DB::raw('count(id) as open_count'),//包含退款总单数 + 退款
DB::raw('sum(case when price>0 then price end) as openPrice'),//不包含退款的业绩
DB::raw('count(case when price>0 then 1 end) as openCount'))//不包含退款的总单数
->first();