<?php
namespace app\index\controller;

/**
 * 评价类
 */
class Evaluate 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 {
            // 获取数据.
            $robot = model('Evaluate')->getEvaluate();

            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 putEvaluate()
    {
        // 验证token.
        $tokenStatus = $this->verifyApiToken();
        $code        = -2;
        $msg         = '错误';
        if ($tokenStatus === false) {
            $msg = 'token错误';
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }

        try {
            // 获取数据.
            $evaluateId               = input('get.evaluateId');
            $conversationId           = input('get.conversationId');
            $evaluateContent          = input('get.evaluateContent');
            $where['servicelog_id']   = $conversationId;
            $data['evaluate_content'] = $evaluateContent;
            $data['evaluate_id']      = $evaluateId;
            // 评价.
            $result = model('serviceLog')->getEvaluate($where, $data);

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

    }//end putEvaluate()


    /**
     * 最小回合
     *
     * @access public
     * @return array JsonString
     */
    public function minRound()
    {
        // 验证token.
        $tokenStatus = $this->verifyApiToken();
        $code        = -2;
        $msg         = '错误';
        if ($tokenStatus === false) {
            $msg = 'token错误';
            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
        }

        try {
            // 获取数据.
            $where['systemconfig_enName'] = 'round';
            // 评价.
            $result = model('systemconfig')->findSystemconfig($where);

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

    }//end minRound()


}
