<?php

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

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

class LinkUnitsController extends Controller
{
    public function GetList()
    {
        $page = request('page');
        $pageSize = request('pageSize');
        $searchInfo = request('searchInfo');
        $list=DB::table('link_units')->where(['is_del'=>0]);
        if(isset($searchInfo['name'])){
            $list = $list->where('name', 'like', '%' . $searchInfo['name'] . '%');
        }
        $count=$list->count();
        $list=$list
            ->skip(($page-1)*$pageSize) // 跳过前9999条记录
            ->take($pageSize)->get();

        return \Yz::Return(true,"查询完成",['list'=>$list,'count'=>$count]);
    }
    public function Save()
    {
        $Info = request('Info');
        $data=[
            'name'=>$Info['name'],
            'img'=>$Info['logo'],
            'url'=>$Info['url'],
            'type'=>$Info['type'],
            'status'=>$Info['status'],
        ];
        if($Info['id']==0){
            $data['created_at']=date('Y-m-d H:i:s');
            $u=DB::table('link_units')->insert($data);
        }else{
            $u=DB::table('link_units')->where(['id'=>$Info['id']])->update($data);
        }

        if($u){
            return \Yz::Return(true,"操作完成",[]);
        }else{
            return \Yz::echoError1("没有数据更新");
        }
    }
    public function Del()
    {
        $id = request('id');
        $d= DB::table('link_units')->where(['id'=>$id])->update([
            'is_del'=>1
        ]);
        if($d){
            return \Yz::Return(true,"操作完成",[]);
        }else{
            return \Yz::echoError1("删除失败");
        }
    }
}
