存活数

This commit is contained in:
邓皓元 2019-11-19 21:42:20 +08:00
parent 3fc93b725b
commit eb37b84f46

View File

@ -184,9 +184,15 @@ class PropertyService extends Service
return $item->company_id . '_' . $item->package_id;
})->toArray();
$actives = app(OrderCardPartitionRepository::class)->selectRaw('company_id, package_id, count(*) as counts')
->withConditions(['type' => 0, 'card_status' => 2])->groupBy(['company_id', 'package_id'])->get()->keyBy(function ($item) {
return $item->company_id . '_' . $item->package_id;
})->toArray();
$carrierOperators = app(Dicts::class)->get('carrier_operator');
$list = $product->map(function ($item) use ($properties, $sells, $carrierOperators) {
$list = $product->map(function ($item) use ($properties, $sells, $actives, $carrierOperators) {
$item = $item->toArray();
$package = PackageService::load($item['package_id']);
$item['company_name'] = CompanyService::load($item['company_id'])['name'] ?? '';
@ -196,7 +202,9 @@ class PropertyService extends Service
$item['carrier_operator_name'] = $carrierOperators[$item['carrier_operator']] ?? '未知';
$property = $properties[$item['company_id'] . '_' . $item['package_id']];
$sell = $sells[$item['company_id'] . '_' . $item['package_id']];
$active = $actives[$item['company_id'] . '_' . $item['package_id']];
$item['counts'] = $sell ? $sell['counts'] : 0;
$item['actives'] = $active ? $active['counts'] : 0;
return array_merge($item, $property ?: self::$default);
});