<?php

namespace app\admin\controller;

use app\admin\common\AdminController;

/**
 * Description of System
 *
 * @author sgq
 */
class System extends AdminController {

    /**
     * 生成缓存
     * @return type
     */
    public function cache() {
        $step = $this->request->param("step");
        if ($step) {
            $cache_kvs = [
                ["func" => "\app\common\model\IntegralProject::cache", "stepName" => "积分项目"],
                ["func" => "\app\common\model\IntegralItem::cache", "stepName" => "积分标准"]
            ];
            $cache = $cache_kvs[$step - 1];
            if ($cache) {
                $time1 = microtime(true);
                $cache["func"]();
                $time2 = microtime(true);
                $runtime = round($time2 - $time1, 2);
                $step++;
                echo '<script>window.parent.setText("<span class=\"highlight\">' . $cache["stepName"] . '</span>缓存成功！[用时 ' . $runtime . 's]");</script>';
                echo '<script>window.location.href="/admin/system/cache/step/' . $step . '";</script>';
            } else {
                echo '<script>window.parent.setText("缓存创建结束！");</script>';
            }
        } else {
            return view();
        }
    }

}
