<?php

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

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

class WebMngrController extends Controller
{
    //保存轮播信息
    public function SaveLunBo()
    {
        $urls = request('urls');
        $links = request('links');
        $urls = json_encode($urls);
        $u = DB::table('configs')->where(['label' => '首页轮播'])->update([
            'value' => $urls
        ]);
        if(isset($links)){
            $u = DB::table('configs')->where(['label' => '轮播链接'])->update([
                'value' =>json_encode($links)
            ]);
        }
        if ($u) {
            return \Yz::Return(true, '保存成功', []);
        } else {
            return \Yz::echoError1("没有数据更新");
        }
    }

    public function GetAllConfigs()
    {
        $configArray = request('configArray');
        $all = DB::table('configs')->whereIn('label',$configArray)->get();
        foreach ($all as $key=>$v){
            if(in_array($v->label,['首页轮播','轮播链接','广告图片','广告链接'])){
                $all[$key]->value= json_decode($v->value, true);
            }
        }
        return \Yz::Return(true, '保存成功', $all);
    }
    public function SaveWebConfig()
    {
        $configInfo = request('configInfo');
        if(!empty($configInfo)){
           foreach ($configInfo as $key=>$item){
              DB::table('configs')->where(['label'=>$item['label']])->update([
                   'value'=>$item['value']
               ]);
           }
            return \Yz::Return(true, '保存成功', []);
        }else{
            return \Yz::echoError1("没有数据更新");
        }
    }
}
