<?php

namespace App\Http\Controllers\API\Admin\YeWu;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ConfigsController extends Controller
{
    public function GetConfigs(Request $request)
    {
        $userid = $request->get('userid');//中间件产生的参数
        $group = $request->get('role');//中间件产生的参数
        if($group==1){
            $list=DB::table('configs')->get();
            return \Yz::Return(true,'',$list);
        }
    }
    public function SaveConfig(Request $request)
    {
        $userid = $request->get('userid');//中间件产生的参数
        $group = $request->get('role');//中间件产生的参数
        $label=request('label');
        $value=request('value');
        if($group==1){
            $u=DB::table('configs')->where(['label'=>$label])->update([
                'value'=>$value
            ]);
            if($u){
                return \Yz::Return(true,'操作成功',[]);
            }else{
                return \Yz::echoError1("操作失败");
            }

        }
    }
    //获取某些项目的配置信息
    public function GetConfigInArray()
    {
        $labels=request('labels');
        $list=DB::table('configs')->select('label','value')->whereIn('label',$labels)->get();
        if(count($list)>0){
            return \Yz::Return(true,'',$list);
        }else{
            return \Yz::echoError1("获取配置信息失败");
        }

    }
}
