protected function grid()
{
$grid = new Grid(new OrderGoods());
$sql = 'SELECT
`te_a`.*,
sum( te_a.num ) AS a_num,
sum( te_a.total_amount ) AS a_total_amount,
sum( te_a.cost_total_amount ) AS a_cost_total_amount
FROM
`te_order_goods` AS `te_a`
WHERE
EXISTS (
SELECT
1
FROM
`te_orders`
WHERE
te_orders.id = te_a.order_id
AND `state` IN (3,
4,
5))
AND `te_a`.`sku_id` <> 0
GROUP BY
`te_a`.`sku_id`';
$grid->model()->from(\DB::raw('('.$sql.') as te_order_goods'))
->orderByRaw('te_order_goods.a_num desc')
->select(['order_goods.*', 'order_goods.a_num', 'order_goods.a_total_amount', 'order_goods.a_cost_total_amount']);
$grid->column('a_num', __('销售数量'))->totalRow();
$grid->column('a_total_amount', __('销售金额'))->totalRow();
}
laravel_admin 列表分组统计,合计