<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Models\ServerInfo;

class ServerInfoController extends Controller
{

    /**
     * 创建活动
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(Request $request)
    {
        $id = $request->input('id');
        $server = $request->input('server');
        $content = $request->input('content');;
        $photo = $request->input('photo');
        $location = $request->input('location');
        if ($id) {
            $serverInfo = ServerInfo::find($id);
        } else {
            $serverInfo = new Campaign;
        }
        if ($server && $content) {
            $serverInfo->server = $server;
            $serverInfo->content = $content;
            $serverInfo->photo = $photo;
            $serverInfo->location = $location;
            $serverInfo->save();
            return Response()->json([
                "status" => 0,
                "message" => "保存成功!"
            ]);
        } else {
            return Response()->json([
                "status" => -1,
                "message" => "信息不能为空!"
            ]);
        }
    }

    /**
     * 每页20进行分页
     * @param Request $request
     * @return mixed
     */
    public function list(Request $request)
    {
        $top = ServerInfo::where("location", "top")->get();
        $bottom = ServerInfo::where("location", "bottom")->first();
        return Response()->json([
            "top" => $top,
            "introduce" => "服务介绍",
            "bottom" => $bottom
        ]);
    }
}
