This commit is contained in:
邓皓元 2019-02-12 10:53:54 +08:00
parent 02a6de9a5b
commit 40e2816b71

View File

@ -40,26 +40,25 @@ class CompanyReportService extends Service
'company_id', 'company_id',
'package_id', 'package_id',
'type', 'type',
DB::raw("MAX(order_id) as order_id"), 'virtual_orders.unit_price as unit_price',
DB::raw('COUNT(id) as counts'), DB::raw('SUM(counts) as counts'),
]; ];
$query = $this->orderCardPartitionRepository->select($select) $query = $this->orderCardPartitionRepository->select($select)
->withConditions($conditions) ->withConditions($conditions)
->groupBy(['company_id', 'package_id', 'type']) ->leftJoin('virtual_orders', 'virtual_orders.id', '=', 'order_id')
->groupBy(['company_id', 'package_id', 'type', 'virtual_orders.unit_price'])
->orderBy('company_id')->orderBy('type')->orderBy('package_id'); ->orderBy('company_id')->orderBy('type')->orderBy('package_id');
$res = $query->paginate($conditions['limit']); $res = $query->paginate($conditions['limit']);
$res->load('order:id,unit_price');
$res->map(function ($item) { $res->map(function ($item) {
$company = app(CompanyService::class)->load($item->company_id); $company = app(CompanyService::class)->load($item->company_id);
$package = app(PackageService::class)->load($item->package_id); $package = app(PackageService::class)->load($item->package_id);
$item->company_name = $company['name']; $item->company_name = $company['name'];
$item->package_name = $package['name']; $item->package_name = $package['name'];
$item->service_months = $package['service_months'] ?? 1; $item->service_months = $package['service_months'] ?? 1;
$item->unit_price = sprintf('%.02f', $item->order['unit_price']/100); $item->unit_price = sprintf('%.02f', $item->unit_price/100);
$item->month_price = sprintf('%.02f', $item->unit_price/$item->service_months); $item->month_price = sprintf('%.02f', $item->unit_price/$item->service_months);
$item->total_price = sprintf('%.02f', $item->month_price*$item->counts); $item->total_price = sprintf('%.02f', $item->month_price*$item->counts);
$item->type_name = self::$typeNames[$item->type]; $item->type_name = self::$typeNames[$item->type];