public function getMenu($cai_id) { $key = 'top_menu_' . $cai_id; if (Cache::has($key)) { return json_decode(Cache::get($key), true); } $menus = Cai::find($cai_id)->caitype->menu()->select('m_id', 'title')->where('flag', '=', 1)->orderBy('sort', 'asc')->get(); $topMenus = []; foreach ($menus as $menu) { $wans = $menu->wan()->select('w_id', 'title')->where('flag', '=', 1)->orderBy('sort', 'asc')->get(); $topMenus[$menu->title] = $wans->toArray(); } Cache::put($key, json_encode($topMenus), 15); return $topMenus; }
private function gpCai($date) { $cais = Cai::where('flag', '=', 1)->select('cai_id', 'title')->orderBy('cai_id', 'asc')->get(); foreach ($cais as $cai) { Out::writeln('正在生成 ' . $cai->title . ' 的期号!'); $rules = $cai->stagerule()->where('flag', '=', 1)->orderBy('sort', 'asc')->get(); $cai_id = $cai->cai_id; foreach ($rules as $key => $rule) { if (strpos($rule->format, '*') !== false) { list($d, $c, $n) = explode('*', $rule->format); if ($key == 0) { $stage_num = $c + round(abs((strtotime($date) - strtotime($d)) / 86400)) * $n; } $is_add = true; } else { list($date_fromat, $num_format) = explode('-', $rule->format); if ($key == 0) { $stage_num = 1; } $is_add = false; } $sql = 'INSERT INTO `vz_stage`(`cai_id`, `close_time`, `lottery_time`, `title`) VALUES '; for ($timer = strtotime($rule->stime, $this->timestamp); $timer <= strtotime($rule->etime, $this->timestamp); $timer += $rule->interval) { if (!$is_add) { $title = date($date_fromat, $timer) . '-' . sprintf($num_format, $stage_num); } else { $title = $stage_num; } $close_time = $timer - $rule->delay; $lottery_time = $timer; $sql .= "({$cai_id}, {$close_time}, {$lottery_time}, '{$title}'),"; ++$stage_num; } $sql = trim($sql, ',') . ' ON DUPLICATE KEY UPDATE `close_time` = VALUES(`close_time`), `lottery_time` = VALUES(`lottery_time`);'; //if($cai_id == 1) // echo $sql . "\n\n"; DB::statement($sql); } } }