<?php

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

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

class WebSiteController extends Controller
{
    //保存站点信息
    public function Save()
    {
        $SiteInfo =request('SiteInfo');
        $data=[
            'site_name'=>$SiteInfo['site_name'],
            'hospital'=>isset($SiteInfo['hospital'])? json_encode($SiteInfo['hospital']):null,
            'appid'=>isset($SiteInfo['appid'])? json_encode($SiteInfo['appid']):null,
            'domain'=>isset($SiteInfo['domain'])? json_encode($SiteInfo['domain']):null,
            'status'=>$SiteInfo['status'],
        ];
        if(isset($SiteInfo['id']) and $SiteInfo['id']!=0){
            $ex=DB::table('site_organization')->where(['id'=>$SiteInfo['id']])->update($data);
        }else{
            $ex=DB::table('site_organization')->insert($data);
        }
        if($ex){
            return \Yz::Return(true,"保存成功",[]);
        }else{
            return \Yz::echoError1("保存失败");
        }

    }
    public function GetList()
    {
        $page = request('page');
        $pageSize = request('pageSize');
        $searchInfo = request('searchInfo');
        $list =DB::table('site_organization')->where(['is_del'=>0]);
        $count=$list->count();
        $list=$list
        ->skip(($page-1)*$pageSize) // 跳过前9999条记录
    ->take($pageSize)->get();
        return \Yz::Return(true,"查询成功",['list'=>$list,'count'=>$count]);
    }
    public function GetDetail()
    {
        $id = request('id');
        $info=DB::table('site_organization')->where(['id'=>$id,'is_del'=>0])->first();
        if(!!$info){
            $info->hospital= $info->hospital?implode(',',json_decode( $info->hospital)):'';
            $info->appid=$info->appid?implode(',',json_decode( $info->appid)):'';
            $info->domain= $info->domain?implode(',',json_decode( $info->domain)):'';
            return \Yz::Return(true,'查询成功',$info);
        }else{
            return \Yz::echoError1("查询失败");
        }
    }
}
