<?php

//namespace zjhj_mall;
$entry = '/public/';
//$res = `cd ../addons/online_album/vendor && ls -la`;
//print_r(__DIR__ . '/vendor');
//if (!file_exists(__DIR__ . '/vendor')) {
//    die('请先进入项目根目录online_album运行composer install以便初始化项目');
//}
//print_r($res);die;

if (file_exists(__DIR__ . $entry)) {
    global $_W;
    $path = __DIR__ . "/.env";
    $content = file_get_contents($path);
    $content = str_replace('http://local.album.com/', $_W['siteroot'], $content);
    file_put_contents($path, $content);
    $wUser = [
        'uid' => $_W['user']['uid'],
        'name' => $_W['user']['name'],
        'username' => $_W['user']['username'],
        'groupid' => $_W['user']['groupid'],
    ];
    $wAccount = [
        'acid' => $_W['account']['acid'],
        'name' => $_W['account']['name'],
    ];

    require __DIR__ . '/vendor/autoload.php';
    $request = new Illuminate\Http\Request;
    session_start();
    $_SESSION["store_id"] = $_W['uniacid'];
    $_SESSION["wUser"] = $wUser;
    $_SESSION["wAccount"] = $wAccount;
    $_SESSION["route"] = 'Admin/Auth/Login/wxLogin';
    $uri = $_W['siteroot'] . 'addons/' . $_W['current_module']['name'] . $entry .'?route=Admin/Auth/Login/wxLogin';
    header('Location: ' . $uri);
    exit;
} else {
    die('应用入口文件缺失，请联系开发者处理！');
}