<?php
namespace app\index\controller;

/**
 * 智能问答类
 */
class Robot extends Common
{


    /**
     * 热点智能问答筛选
     *
     * @access public
     * @return array JsonString
     */
    public function index()
    {
        // 验证token.
        $tokenStatus = $this->verifyApiToken();
        $code        = -2;
        $msg         = '错误';
        if ($tokenStatus === false) {
            $msg = 'token错误';
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }

        try {
            // 获取查询条件.
            $groupsId       = input('get.groups_id');
            $robotgroups_id = input('get.robotgroups_id');
            if ($groupsId) {
                $robotWhere['groups_id'] = $groupsId;
            }

            if ($robotgroups_id) {
                $robotWhere['robotgroups_id'] = $robotgroups_id;
            }

            $robotWhere['robot_status'] = 1;
            $robotWhere['robot_host']   = 1;
            // 获取符合条件数据.
            $robot = model('Robot')->select($robotWhere);

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

    }//end index()


    /**
     * 智能问答分组
     *
     * @access public
     * @return array JsonString
     */
    public function getRobotGroups()
    {
        // 验证token.
        $tokenStatus = $this->verifyApiToken();
        $code        = -2;
        $msg         = '错误';
        if ($tokenStatus === false) {
            $msg = 'token错误';
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }

        try {
            $robotGroupsWhere['robotgroups_status'] = 1;
            // 获取符合条件数据.
            $robotGroups = model('Robotgroups')->select($robotGroupsWhere);

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

    }//end getRobotGroups()


}
