统计修改

This commit is contained in:
邓皓元 2019-04-25 16:18:07 +08:00
parent 9b285466e9
commit b73b978fe6
4 changed files with 12 additions and 8 deletions

View File

@ -53,7 +53,6 @@ class OrderService extends Service
'package_id',
'unit_price',
'pay_channel',
DB::raw('SUM(counts) as counts'),
DB::raw('SUM(custom_price) as custom_price'),
];
@ -70,23 +69,28 @@ class OrderService extends Service
$members = $repository->select([
'order_id',
DB::raw('COUNT(distinct sim) as counts'),
DB::raw('SUM(counts) as counts'),
DB::raw('COUNT(distinct sim) as members'),
])->withConditions(['order_id' => $order_ids])->groupBy('order_id')->get()->keyBy('order_id');
$orders->map(function ($item) use ($companies, $packages, $members) {
$item->unit_price = sprintf('%.02f', $item->unit_price/100);
$item->custom_price = sprintf('%.02f', $item->custom_price/100);
$item->company_name = $companies[$item->company_id];
$item->package_name = $packages[$item->package_id];
$order_ids = str_to_array($item->order_id);
$item->members = 0;
$item->counts = 0;
foreach ($order_ids as $id) {
$item->members += $members[$id]['counts'] ?? 0;
$item->members += $members[$id]['members'] ?? 0;
$item->counts += $members[$id]['counts'] ?? 0;
}
$item->custom_price = sprintf('%.02f', $item->unit_price * $item->counts/100);
$item->pay_channel_name = CommonService::namePayChannel($item->pay_channel);
});

View File

@ -28,7 +28,7 @@ class OrderCardExport extends AbstractExport implements FromQuery, WithHeadings,
public function query()
{
$builder = app(OrderCardPartitionRepository::class)->with('order')->forceNoReset()->select(['sim', 'order_id', 'counts', 'refunded_at'])
->withConditions($this->conditions)->orderBy('order_id')->orderBy('sim');
->withRefunded()->withConditions($this->conditions)->orderBy('order_id')->orderBy('sim');
return $builder;
}

View File

@ -257,7 +257,7 @@ class OrderController extends Controller
}
try {
$total = app(OrderCardPartitionRepository::class)->withConditions($conditions)->count();
$total = app(OrderCardPartitionRepository::class)->withRefunded()->withConditions($conditions)->count();
if ($total > 200000) {
throw new NotAllowedException('数据量过大,请筛选后再进行导出');

View File

@ -66,7 +66,7 @@ class OrderService extends Service
'order_id',
DB::raw('SUM(counts) as counts'),
DB::raw('SUM(CASE WHEN refunded_at IS NULL THEN 0 ELSE 1 END) as refunds')
])->withConditions([
])->withRefunded()->withConditions([
'order_id' => $res->pluck('id')->toArray(),
])->groupBy('order_id')->get()->keyBy('order_id');
@ -76,8 +76,8 @@ class OrderService extends Service
$item->unit_price = sprintf('%.02f', $item->unit_price/100);
$item->total_price = sprintf('%.02f', $item->total_price/100);
$item->custom_price = sprintf('%.02f', $item->custom_price/100);
$item->shipments = $orderShipments[$item->id]['counts'] ?? 0;
$item->refunds = $orderShipments[$item->id]['refunds'] ?? 0;
$item->shipments = isset($orderShipments[$item->id]) ? $orderShipments[$item->id]['counts'] - $orderShipments[$item->id]['refunds'] : 0;
});
return $res;