<?php

namespace App\Http\Controllers;

use App\Models\ProductClassify;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ProductClassifyController extends Controller
{

    public function store(Request $request) {
        $id = $request->input('id');
        $classify = $request->input("classify");
        if($id) {
            $productClassify = ProductClassify::find($id);
            DB::update('update products set classify = ? where classify = ?', [$productClassify->classify, $classify]);
        } else {
            $productClassify = new ProductClassify;
        }
        if($classify) {
            $productClassify->classify = $classify;
            $productClassify->save();
            return response()->json([
                "status" => 0,
                "message" => '修改成功'
            ]);
        } else {
            return Response()->json([
                "status" => -1,
                "message" => "信息不能为空!"
            ]);
        }
    }

    public function list(Request $request) {
        $records = ProductClassify::all();
        return response()->json([
            "status" => 0,
            "data" => $records
        ]);
    }

}
