statOrder(); } private function statOrder() { $endAt = strtotime(date('Y-m-d')); $startAt = strtotime('-1 day', $endAt); $builder = Order::where('paid_at', '>=', $startAt) ->where('paid_at', '<', $endAt) ->whereNotIn('status', [0, 2]); $orderCount = $builder->count(); $orderAmount = $builder->sum('total_amount'); $builder = $builder->whereNotNull('actual_commission_balance'); $commissionCount = $builder->count(); $commissionAmount = $builder->sum('actual_commission_balance'); $data = [ 'order_count' => $orderCount, 'order_amount' => $orderAmount, 'commission_count' => $commissionCount, 'commission_amount' => $commissionAmount, 'record_type' => 'd', 'record_at' => $startAt ]; $statistic = StatOrder::where('record_at', $startAt) ->where('record_type', 'd') ->first(); if ($statistic) { $statistic->update($data); return; } StatOrder::create($data); } }