<?php

namespace app\index\controller;

use think\Controller;

class Index extends Common
{


    /**
     * 获取敏感词
     *
     * @access public
     * @return array JsonString
     */
    public function sensitiveWords()
    {
        // 验证token.
        $tokenStatus = $this->verifyApiToken();
        $code        = -2;
        $msg         = '错误';
        if ($tokenStatus === false) {
            $msg = 'token错误';
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }

        try {
            // 获取敏感词.
            $wordsField = ['*'];
            $sysWordsWhere['sensitivewords_status'] = 1;
            $sysWordsWhere['sensitivewords_for']    = 1;
            // 查询客服敏感词.
            $userSensitive = model('sensitivewords')->selectWords($wordsField, $sysWordsWhere);
            // 获取敏感词.
            $wordsField = ['*'];
            $sysWordsWhere['sensitivewords_status'] = 1;
            $sysWordsWhere['sensitivewords_for']    = 2;
            // 查询用户敏感词.
            $serverSensitive = model('sensitivewords')->selectWords($wordsField, $sysWordsWhere);
            $data            = [
                'userSensitive'   => $userSensitive,
                'serverSensitive' => $serverSensitive,
            ];

            return json(['code' => 1, 'data' => $data, 'msg' => '成功']);
        } catch (\Exception $e) {
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }//end try

    }//end sensitiveWords()


    public function index()
    {
        return $this->fetch();
    }

    // pc客户端
    public function chat()
    {
        // 跳转到移动端
        if (request()->isMobile()) {
            $param = http_build_query([
                'id' => input('param.id'),
                'name' => input('param.name'),
                'group' => input('param.group'),
                'avatar' => input('param.avatar')
            ]);
            $this->redirect('/index/index/mobile?' . $param);
        }

        $this->assign([
            'socket' => config('socket'),
            'id' => input('param.id'),
            'name' => input('param.name'),
            'group' => input('param.group'),
            'avatar' => input('param.avatar'),
        ]);

        return $this->fetch();
    }

    // 移动客户端
    public function mobile()
    {
        $this->assign([
            'socket' => config('socket'),
            'id' => input('param.id'),
            'name' => input('param.name'),
            'group' => input('param.group'),
            'avatar' => input('param.avatar'),
        ]);

        return $this->fetch();
    }

    public function systime()
    {
        $now = time();
        $time = date('Y-m-d H:i', $now);
        $settings = db('settings')->where('id',1)->find();
        return json(['code' => 1, 'data' => ['time' => $time,'logo' => $settings['logo'],'enterprise_name' => $settings['enterprise_name']], 'msg' => '成功']);
    }

}
