<?php

namespace App\Http\Controllers;

use App\Models\HomePage;
use Illuminate\Http\Request;

class HomePageController extends Controller
{
    public function store(Request $request) {
        $introduce = $request->input("introduce");
        if($introduce) {
            $homePage = HomePage::find(1);
            if($homePage) {
                $homePage->introduce = $introduce;
                $homePage->save();
                return Response()->json([
                    "status" => 0,
                    "message" => "修改成功"
                ]);
            } else {
                return Response()->json([
                    "status" => -1,
                    "message" => "记录不存在"
                ]);
            }
        } else {
            return Response()->json([
                "status" => -1,
                "message" => "introduce不能为空！"
            ]);
        }
    }

    public function introduce(Request $request) {

        $homePage = HomePage::find(1);
        return Response()->json([
            "status" => 0,
            "data" => [
                "introduce" => $homePage->introduce,
                "content" => $homePage->introduce
            ]
        ]);
    }


    public function getBottom(Request $request) {

        $homePage = HomePage::find(1);
        return Response()->json([
            "status" => 0,
            "data" => [
                "content" => $homePage->content,
                "introduce" => $homePage->bottom_introduce,
                "photo" => $homePage->photo,
            ]
        ]);
    }



    public function bottom(Request $request) {
        $content = $request->input("content");
        $introduce = $request->input("introduce");
        $photo = $request->input("photo");
        if($content) {
            $homePage = HomePage::find(1);
            if($homePage) {
                $homePage->content = $content;
                $homePage->bottom_introduce = $introduce;
                $homePage->photo = $photo;
                $homePage->save();
                return Response()->json([
                    "status" => 0,
                    "message" => "修改成功"
                ]);
            } else {
                return Response()->json([
                    "status" => -1,
                    "message" => "记录不存在"
                ]);
            }
        } else {
            return Response()->json([
                "status" => -1,
                "message" => "introduce不能为空！"
            ]);
        }
    }
}
