<?php

namespace App\Http\Controllers\V1;

use App\Models\Goods;
use App\Models\GoodsComment;
use App\Models\Order;
use App\Models\User;
use App\Services\Api\GoodsService;
use App\Services\Api\UserSearchService;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Validator;

class GoodsController extends Controller
{
    public function __construct()
    {
        $this->user = auth('api')->user();
        $this->userId = $this->user ? $this->user->id : 0;
    }

    //获取商品列表
    public function getList(Request $request)
    {
        $map = [];
        $keyword = $request->input('keyword', null);

        if (!empty($keyword)) {
            $map[] = ['name', 'like', '%' . htmlspecialchars($keyword) . '%'];
        }
        $list = GoodsService::getGoodsList($map, $request->input('page', 1), 20, $ids = []);

        return $this->success($list);
    }

    //商品详情
    public function detail(Request $request)
    {
        $goodsId = $request->goods_id;

        $data = GoodsService::getDetail($goodsId);

        return $this->success($data);
    }

}
