statOrder(); } private function statUser() { $createdAt = time(); $recordAt = strtotime('-1 day', strtotime(date('Y-m-d'))); $statService = new StatisticalService($recordAt); $stats = $statService->getStatUser(); DB::beginTransaction(); foreach ($stats as $stat) { if (!StatUser::insert([ 'user_id' => $stat['user_Id'], 'u' => $stat['u'], 'd' => $stat['d'], 'server_rate' => $stat['server_rate'], 'created_at' => $createdAt, 'updated_at' => $createdAt, 'record_type' => 'd', 'record_at' => $recordAt ])) { DB::rollback(); break; } } DB::commit(); } private function statOrder() { $endAt = strtotime(date('Y-m-d')); $startAt = strtotime('-1 day', $endAt); $orderBuilder = Order::where('paid_at', '>=', $startAt) ->where('paid_at', '<', $endAt) ->whereNotIn('status', [0, 2]); $orderCount = $orderBuilder->count(); $orderAmount = $orderBuilder->sum('total_amount'); $commissionLogBuilder = CommissionLog::where('created_at', '>=', $startAt) ->where('created_at', '<', $endAt); $commissionCount = $commissionLogBuilder->count(); $commissionAmount = $commissionLogBuilder->sum('get_amount'); $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); } }