<?php
/**
 *  ╔═══════════════════════════════════════════════════╗
 *  ║                                                   ║
 *  ║     ██╗  ██╗   █████╗    ██████╗                  ║
 *  ║     ██║  ██║  ██╔══██╗  ██╔═══██╗                 ║
 *  ║     ███████║  ███████║  ██║   ██║                 ║
 *  ║     ██╔══██║  ██╔══██║  ██║   ██║                 ║
 *  ║     ██║  ██║  ██║  ██║  ╚██████╔╝   SNS           ║
 *  ║                                                   ║    
 *  ║                                                   ║    
 *  ║     © 2023 HaoSNS™ All Rights Reserved            ║
 *  ║     官方网站: https://www.haosns.com                *
 *  ║     本代码由赣州乐易网络科技有限公司®提供             *
 *  ║                                                    *
 *  ║   未经授权禁止复制、传播或用于其他商业目的            *
 *  ║                                                   ║
 *  ╚═══════════════════════════════════════════════════╝
 */


namespace app\api\controller;

use app\api\logic\TopicLogic;
use app\api\validate\TopicValidate;

class Topic extends BaseShopController
{
    /**
     * 无需登录即可访问的方法
     * @var array|string[]
     */
    public array $notNeedLogin = ['lists','detail' ,'hot'];

    /**
     * @notes 话题列表
     * @return \think\response\Json
     */
    public function lists()
    {
        return $this->dataLists();
    }


    /**
     * @notes 热门话题列表
     * @return \think\response\Json
     */
    public function hot()
    {
        $params = $this->request->get();
        $lists = TopicLogic::hot($params);
        return $this->data($lists);
    }

    /**
     * @notes 创建新话题
     * @return \think\response\Json
     */
    public function add()
    {   
        $params = $this->request->post();
        try{
            TopicLogic::add($params,$this->userId);
            return $this->success();
        }catch(\Exception $e){

            return $this->fail($e->getMessage());
        }
        
        
    }

    /**
     * 圈子详情
     */
    public function detail(){

        $params = (new TopicValidate())->get()->goCheck();
        // $params = $this->request->get();
        $lists = TopicLogic::detail($params,$this->userId);
        return $this->data($lists);

    }

}