<?php
namespace app\api\controller;

use app\api\lists\GoodsReviewsLists;
use app\api\logic\GoodsReviewsLogic;
use app\api\validate\GoodsReviewsValidate;

/**
 * 商品评论控制器
 * Class GoodsReviewsController
 * @package app\api\controller
 */
class GoodsReviewsController extends BaseApiController
{
    public array $notNeedLogin = ['lists'];

    public function lists()
    {
        return $this->dataLists(new GoodsReviewsLists());
    }

    /**
     * 去评论
     * @return \think\response\Json
     */
    public function review()
    {
        $params = (new GoodsReviewsValidate())->post()->goCheck('add', [
            'user_id' => $this->userId,
            'user_info' => $this->userInfo
        ]);
        $result = GoodsReviewsLogic::add($params);
        if (false === $result) {
            return $this->fail(GoodsReviewsLogic::getError());
        }
        return $this->success('评论成功', [], 1, 1);
    }
}