redis->incr($key); $res = app()->redis->get($key); app()->redis->Expire($key, RedisKeys::STATISTICS_KEY_TIME); if ($res == 1) { $yestoday = Carbon::yesterday(); $today = Carbon::today(); $wallets = WalletLog::query() ->where('created_at', '>', $yestoday) ->where('created_at', '<', $today) ->whereIn('type', WalletLog::$subType) ->groupBy(['area_id']) ->select('area_id', DB::raw('SUM(money) as money_all')) ->get() ->toArray(); // print_r($wallets); $profit_arr = []; $profit_total = 0; foreach ($wallets as $k => &$v) { $put_bikes = Bike::query()->where('put_status', Bike::PUT_STATUS_YES)->where('put_area_id', $v['area_id'])->count(); $body = ['profit' => abs($v['money_all']), 'put_bikes' => $put_bikes]; $v['body'] = json_encode($body); $v['name'] = Statistic::$statisticsMaps[Statistic::SLUG_PROFIT_STATIC]; $v['slug'] = Statistic::SLUG_PROFIT_STATIC; $v['date'] = $yestoday; // $profit_arr[$v['area_id']] = $v['money_all']; $profit_total += $v['money_all']; unset($v['money_all']); } $profit_arr['area_id'] = config('statistic.all'); // 9999 表示总和 $all_put_bikes = Bike::query()->where('put_status', Bike::PUT_STATUS_YES)->count(); $all_body = ['profit' => abs($profit_total), 'put_bikes' => $all_put_bikes]; $profit_arr['body'] = json_encode($all_body); $profit_arr['name'] = Statistic::$statisticsMaps[Statistic::SLUG_PROFIT_STATIC]; $profit_arr['slug'] = Statistic::SLUG_PROFIT_STATIC; $profit_arr['date'] = $yestoday; array_push($wallets, $profit_arr); // print_r($profit_arr); $statistic = new Statistic(); $statistic->insert($wallets); } else { return; } Log::info($yestoday . '收益统计已执行'); } }