<?php

namespace Api\PhpServices\Comment;

use Api\PhpUtils\Http\Request;
use App\Exception\custom\CodeSpecialException;
class Comment
{
    const UNSUAL_CODE       = 999999; // 请求上游接口返回异常，比如服务器挂了
    const REQUEST_ERROR     = 100001; // 上游接口返回的请求异常，会附带一些错误信息
    const PARAMS_ERROR      = 100010; // 上游接口返回参数错误
    const NOTNORMAL_ERROR   = 100037; // 上游接口返回非法用户
    const SUCCESS_CODE      = 100000; // 上游接口返回成功码

    /**
     * 添加评论/回复评论
     * POST
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 新增评论接口接口 接口地址 comment/addComment
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @return array
     */
    public static function add(array $params){
        $url =  config("interface","service.comment.add");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->post($url, $params);
        if(!isset($res['response']) || empty($res['response'])){
            throw new CodeSpecialException("comment_unusual");
        }
        $res = $res['response'];
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_add",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 评论列表
     * GET
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据docId获取评论 接口地址 comment/getCommentByDocId
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     */
    public static function getListByDocid(array $params){
        $url =  config("interface","service.comment.list_by_docid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params);
        if(!isset($res['response']) || !isset($res['response']["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        $res = $res['response'];
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 评论点赞
     * POST
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 赞/踩互动接口 接口地址 like/getLikeNumber
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @throws CodeSpecialException
     * @return true
     */
    public static function like(array $params){
        $url =  config("interface","service.comment.like");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->post($url, $params);
        if(!isset($res['response']) || !isset($res['response']["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        $res = $res['response'];
        if( $res['code'] == self::REQUEST_ERROR ) {
            throw new CodeSpecialException("comment_unusual", $res['message']);
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_like",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 表情
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据业务ID获取表情 接口地址 expression/getAppExpression
     * @param int $businessId 业务ID运营中台定义
     * @throws CodeSpecialException
     */
    public static function getExpression(int $businessId){
        $params = [
            'businessId'=>$businessId
        ];
        $url =  config("interface","service.comment.expression");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params);
        if(!isset($res['response']) || !isset($res['response']["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        $res = $res['response'];
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据userid和docid获取用户评论列表
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据业务ID获取表情 接口地址 comment/getCommentByUserId
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @throws CodeSpecialException
     */
    public static function getLikeListByUseridByDocid( array $params )
    {
        $url =  config("interface","service.comment.like_list_byuserid_bydocid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 评论删除
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 删除评论 接口地址 comment/deleteComment
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @return true
     * @throws CodeSpecialException
     */
    public static function delete(array $params){
        $url =  config("interface","service.comment.delete");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->post($url, $params,300);
        if(!isset($res['response']) || !isset($res['response']["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        $res = $res['response'];
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }

        if( $res["code"] == self::SUCCESS_CODE ){
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
//            if( isset($res['data']) && $res['data']['result'] === true ) {
//                return true;
//            }else{
//                throw new CodeSpecialException("comment_delete",$res['result']??'请求失败');
//            }
        }

        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_delete",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据commentId获取评论详情
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据commentId获取评论 接口地址 comment/getCommentByCommentId
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @return array
     * @throws CodeSpecialException
     */
    public static function getDetailByTopComentId(array $params){
        $url =  config("interface","service.comment.list_bytop_commentid");
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据userid获取用户评论列表
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据commentId获取评论 接口地址 comment/getCommentByUserId
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @return array
     * @throws CodeSpecialException
     */
    public static function getListByUserid(array $params){
        $url =  config("interface","service.comment.list_byuserid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据userid和docid获取用户评论列表方法
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据commentId获取评论 接口地址 comment/getCommentByUserId
     * @param array $params 请求参数 详细的参数看运营中台接口文档
     * @return array
     * @throws CodeSpecialException
     */
    public static function getListByUseridByDocid(array $params){
        $url =  config("interface","service.comment.list_byuserid_bydocid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据docid获取评论的数量
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据docId获取评论数量 接口地址 comment/getCommentNumberByDocId
     * @param int $businessId 业务ID
     * @param int $docId 文章ID
     * @return array
     * @throws CodeSpecialException
     */
    public static function getCommentNumByDocid(int $businessId, string $docId){
        $params = [
            'businessId'=>$businessId,
            'docId'=>$docId
        ];
        $url =  config("interface","service.comment.num_bydocid");
        if(!$url){
            return [];
            //throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            return [];
            // throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            return [];
            //throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res['data'] ?? [];
        }
        return [];
    }

    /**
     * 根据commentId获取回复数量
     * @doc 运营中台接口文档地址http://ydwiki.yidian-inc.com/pages/viewpage.action?pageId=59701834
     * @doc method 接口名称 根据docId获取评论数量 接口地址 comment/getCommentNumberByCommentId
     * @param int $businessId 业务ID
     * @param int $commentId 评论ID
     * @return array
     * @throws CodeSpecialException
     */
    public static function getReplyNumByCommentId(int $commentId, int $businessId){
        $params = [
            'commentId'=>$commentId,
            'businessId'=>$businessId
        ];
        $url =  config("interface","service.comment.replynum_bycommentid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据userid获取回复数量
     * @param array $params
     * @return true
     * @throws CodeSpecialException
     */
    public static function getReplyNumByUserid(array $params){
        $url =  config("interface","service.comment.replynum_byuserid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['status']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error",$res['status']??'服务内部错误');
        }
    }

    /**
     * 根据commentid获取点赞数量方法
     * @param array $params
     * @return true
     * @throws CodeSpecialException
     */
    public static function getLikeNumByCommentId(int $commentId, int $businessId, int $type){
        $params = [
            'commentId'=>$commentId,
            'businessId'=>$businessId,
            'type'=>$type
        ];
        $url =  config("interface","service.comment.likenum_bycommentid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 根据userid获取点赞数量
     * @param array $params
     * @return true
     * @throws CodeSpecialException
     */
    public static function getLikeNumByUserid(int $userid,int $businessId, int $type){
        $params = [
            'userId'=>$userid,
            'businessId'=>$businessId,
            'type'=>$type
        ];
        $url =  config("interface","service.comment.likenum_byuserid");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->get($url, $params, 500);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }
        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_request_error",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 评论举报
     * @param array $params
     * @return true
     * @throws CodeSpecialException
     */
    public static function report(array $params){
        $url =  config("interface","service.comment.report");
        if(!$url){
            throw new CodeSpecialException("comment_url_error");
        }
        $res = (new Request())->post($url, $params,300);
        if(!$res || !isset($res["code"])){
            throw new CodeSpecialException("comment_unusual");
        }
        if( $res['code'] == self::UNSUAL_CODE ) {
            throw new CodeSpecialException("comment_unusual");
        }

        if($res["code"] == self::SUCCESS_CODE){
            if( isset($res['result']) ) {
                unset($res['result']);
            }
            if( isset($res['request_time']) ) {
                unset($res['request_time']);
            }
            if( isset($res['code']) ) {
                unset($res['code']);
            }
            if( isset($res['status']) ) {
                unset($res['status']);
            }
            return $res;
        }
        switch ($res["code"]/1){
            case self::REQUEST_ERROR:
                throw new CodeSpecialException("comment_report",$res['message']??'请求失败');
            case self::PARAMS_ERROR:
                throw new CodeSpecialException("comment_params_error");
            case self::NOTNORMAL_ERROR:
                throw new CodeSpecialException("comment_notnormal_user");
            default:
                throw new CodeSpecialException("comment_inner_error");
        }
    }

    /**
     * 异步并发请求文章评论和文章下用户点赞
     * @param $params [[根据docid获取列表的参数],[根据用户ID+文章ID获取点赞评论]]
     * @return array
     * @throws CodeSpecialException
     */
    public static function getDocListAndUserLike($params){
        $send_params = array_values($params);
        $send_params_keys = array_keys($params);
        $urls = [
            config("interface","service.comment.list_by_docid"),
            config("interface","service.comment.like_list_byuserid_bydocid")
        ];
        $res = (new Request())->concurrencyGet($urls, $send_params, [], 1);
        if(!$res || !is_array($res)){
            throw new CodeSpecialException("comment_unusual");
        }
        $return_data = [];
        foreach ($res as $k=>$v) {
            $v = $v['response'];
            $return_data[$send_params_keys[$k]]['data'] = [];
            if($v['code'] == self::SUCCESS_CODE) {
                $return_data[$send_params_keys[$k]]['data'] = $v['data'];
            }
//            if( $v['code'] == self::UNSUAL_CODE ) {
//                throw new CodeSpecialException('comment_unusual');
//            }
//            if( $v['code'] == self::REQUEST_ERROR ){
//                throw new CodeSpecialException("comment_request_error",$v['message']??'请求失败');
//            }
//            if( $v['code'] == self::PARAMS_ERROR ) {
//                throw new CodeSpecialException("comment_params_error");
//            }
//            if( $v['code'] == self::NOTNORMAL_ERROR ) {
//                throw new CodeSpecialException("comment_notnormal_user");
//            }
//            // 成功之后数据处理
//            if( $v['code'] == self::SUCCESS_CODE ) {
//                $return_data[$send_params_keys[$k]]['data'] = $v['data'];
//            }else{
//                throw new CodeSpecialException("comment_inner_error");
//            }
        }
        return $return_data;
    }

    /**
     * 批量获取文章的评论数
     * @param int $businessId 业务ID
     * @param array $docids   多个文章ID
     */
    public static function getCommentNumByDocids( int $businessId, array $docids )
    {
        $return_data = [];
        $url =  config("interface","service.comment.num_bydocid");
        if(!$url){
            return $return_data;
        }
        // 拼接请求的url
        foreach ($docids as $docid){
            $urls[] = $url;
            $params[] = [
                'businessId'=>$businessId,
                'docId'=>$docid
            ];
        }
        $res = (new Request())->concurrencyGet($urls, $params, [500,500],1);
        if(!$res || !is_array($res)){
            // throw new CodeSpecialException("comment_unusual");
            return $return_data;
        }

        foreach ($res as $val){
            if(isset($val['data']['docId']) && !empty($val['data'])){
                $return_data[$val['data']['docId']] = $val['data'];
            }
        }
        return $return_data;
    }
}