<?php

namespace app\admin\controller;

use think\facade\View;
use think\Request;
use app\common\controller\Common;

/**
 * 系统设置控制器
 * Class Set
 * @package app\admin\controller
 */
class Gateway extends Common
{
    /**
     * 评价设置
     * @return string
     */
    public function index(Request $r)
    {
        if ($r->isAjax() && $r->isPost()) {
            $post = $r->post();
            $WSConfig = "<?php

return [
    // WS端口
    'WS_port'     => '{$post['ws_port']}',
    // WS地址
    'WS_address'  => '{$post['ws_address']}',
    // 分布式使用的内网ip
    'WS_intranet' => '{$post['ws_intranet']}',
    // Register服务器ip
    'Register_ip' => '{$post['register_ip']}',
    // Register服务器端口
    'Register_port' => '{$post['register_port']}',
];";
            @chmod(__DIR__ . '/../../../config/im.php', 0777);
            @file_put_contents(__DIR__ . '/../../../config/im.php', $WSConfig);

            return json(['code' => 200, 'data' => '设置成功']);
        }

        $config = config('im');

        View::assign('config', $config);

        return View::fetch();
    }

}
