<?php

namespace App\Web\Controllers;

use App\Http\Controllers\BaseController;
use App\Web\Services\BlogService;
use App\Web\Services\DictService;
use Illuminate\Http\Request;


class DictController extends BaseController
{

    protected $service = null;

    /**
     * 构造函数
     * BlogController constructor.
     * @param BlogService $service
     */
    public function __construct(DictService $service)
    {
        $this->service = $service;
    }

    /**
     * 获取功能列表
     * */
    public function getDictFunctionList(Request $request){
        $params=$request->only(['page_size','page','status','keyword']);
        $ret=$this->service->getDictFunctionList($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 功能保存
     * */
    public function saveDictFunction(Request $request){
        $this->validate($request, [
            'name' => 'required',
        ], [
            'name.required' => '功能名称不能为空',
        ]);
        $params=$request->only(['id','name','remark','status']);
        $ret=$this->service->saveDictFunction($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 变更功能状态
     * */
    public function changeDictFunctionStatus(Request $request){
        $this->validate($request, [
            'id' => 'required',
        ], [
            'id.required' => 'id不能为空',
        ]);
        $params=$request->only(['id','status']);
        $ret=$this->service->saveDictFunction($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 获取行业列表
     * */
    public function getDictIndustryList(Request $request){
        $params=$request->only(['page_size','page','status','keyword']);
        $ret=$this->service->getDictIndustryList($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 行业保存
     * */
    public function saveDictIndustry(Request $request){
        $this->validate($request, [
            'name' => 'required',
        ], [
            'name.required' => '行业名称不能为空',
        ]);
        $params=$request->only(['id','name','pid','status','remark']);
        $ret=$this->service->saveDictIndustry($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

    /**
     * 变更行业状态
     * */
    public function changeDictIndustryStatus(Request $request){
        $this->validate($request, [
            'id' => 'required',
        ], [
            'id.required' => 'id不能为空',
        ]);
        $params=$request->only(['id','status']);
        $ret=$this->service->saveDictIndustry($params);
        return $this->jsonResponse(
            'ok',
            $ret
        );
    }

}
