<?php
namespace App\Services;

use Illuminate\Support\Facades\DB;

class ConfigService
{

    //获取配置信息
    public function GetConfigInfo($arr){
        $q=DB::table('configs')->select(['label','value'])->whereIn('label',$arr)->get();
        if(count($q)>0) {
            $result = [];
            foreach ($q as $k => $v) {
                $result[$v->label] = $v->value;
            }
            return \Yz::Return(true, '查询成功', $result);
        }else{
            return \Yz::Return(false, '查询失败');
        }
    }
    public function SaveConfig($name,$logo){
        $result=array();
        DB::beginTransaction();
        try {
            $d= DB::table('configs')->where('label', '=', '站点名称')->update(['value'=>$name]);
            $d= DB::table('configs')->where('label', '=', '站点图片')->update(['value'=>$logo]);
            DB::commit(); // 手动提交事务
            return \Yz::Return(true, '操作成功');
        } catch (\Exception $e) {
            DB::rollback(); // 发生异常时手动回滚事务
            return \Yz::Return(false, '操作失败');
        }


    }
}
