leftJoin('goods_sku','goods_sku.join_sku_goods_id','=','order_sheet.join_sheet_goods_id') ->selectRaw('app_goods.goods_id,SUM(app_order_sheet.order_sheet_num) as num,SUM(app_order_sheet.order_sheet_pay) as amount,app_goods.goods_id,app_goods_sku.goods_sku_id') ->groupBy(['goods.goods_id','goods_sku.goods_sku_id']) ->orderBy('num','DESC') ->get(); dump($rows); return json_success(''); } public function statistics() { $data['total'] = OrderSheet::whereIn('order_sheet_status',['PENDING','NOSTOCK','WAITING','ENDING','RECVING','SIGNED','CONFIRM','DONE']) ->selectRaw("SUM(order_sheet_pay) as pay_amount ,SUM(order_sheet_num) as goods_amount") ->first(); $data['entity'] = OrderSheet::leftJoin('goods','goods.goods_id','=','order_sheet.join_sheet_goods_id') ->where('goods.goods_classify','GOODS') ->whereIn('order_sheet_status',['PENDING','NOSTOCK','WAITING','ENDING','RECVING','SIGNED','CONFIRM','DONE']) ->selectRaw("SUM(order_sheet_pay) as pay_amount ,SUM(order_sheet_num) as goods_amount") ->first(); $data['service'] = OrderSheet::leftJoin('goods','goods.goods_id','=','order_sheet.join_sheet_goods_id') ->where('goods.goods_classify','SERVICE') ->whereIn('order_sheet_status',['PENDING','NOSTOCK','WAITING','ENDING','RECVING','SIGNED','CONFIRM','DONE']) ->selectRaw("SUM(order_sheet_pay) as pay_amount ,SUM(order_sheet_num) as goods_amount") ->first(); $data['package'] = OrderSheet::leftJoin('goods','goods.goods_id','=','order_sheet.join_sheet_goods_id') ->where('goods.goods_classify','PACKAGE') ->whereIn('order_sheet_status',['PENDING','NOSTOCK','WAITING','ENDING','RECVING','SIGNED','CONFIRM','DONE']) ->selectRaw("SUM(order_sheet_pay) as pay_amount ,SUM(order_sheet_num) as goods_amount") ->first(); return json_success('',$data); } }