<?php
/**
 * @desc: 动态绑定二级域名
 * @Author: Dr.Xing <ezfwork@foxmail.com>
 * @Since: 2018/1/28 15:18
 */

namespace seven\behavior;

use think\Route;
use think\Cache;

class BindDomain
{
    public function run()
    {
        $rules = Cache::get('rules');
        if(!$rules) {
            $rules = \app\common\model\Sites::refreshRulesCache();
        }

        foreach($rules as $k => $v){
            Route::domain($v['s'], 'index'. $v['p']);
            Route::domain('admin.'.$v['s'], 'admin'. $v['p']);
        }
    }

}