<?php

namespace App\Http\Controllers;

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

class CompanyInfoController extends Controller
{
    /**
     * 创建公司介绍
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(Request $request)
    {
        $id = $request->input('id');
        $content = $request->input('content');
        if ($id) {
            $company = CompanyInfo::find($id);
        } else {
            $company = new CompanyInfo;
        }
        if ($content) {
            $company->content = $content;
            $company->save();
            return Response()->json([
                "status" => 0,
                "message" => "保存成功!"
            ]);
        } else {
            return Response()->json([
                "status" => -1,
                "message" => "信息不能为空!"
            ]);
        }
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function info(Request $request) {
        $company = CompanyInfo::first();
        return Response()->json([
            "status" => 0,
            "data" => $company
        ]);
    }
}
