<?php

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

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

class AppMngrController extends Controller
{
    public function GetList()
    {
        $searchInfo =request('searchInfo');
        $list=DB::table('y_app');
        if(isset($searchInfo['status']) and $searchInfo['status'] !== null){
            $list=$list->where('status',$searchInfo['status']);
        }
        if(isset($searchInfo['info'])){
            $ssInfo='%'.$searchInfo['info'].'%';
            $list=$list  ->where(function($query) use ($ssInfo) {
                $query->where('app_name', 'like', $ssInfo)
                    ->orWhere('app_id', 'like',$ssInfo);
            });
        }
        $list=$list->where('is_del',0)->orderBy('id','desc')->get();
        return \Yz::Return(true,'',$list);
    }
    public function Save()
    {
        $info=request('info');
        $do=false;
        if($info['id']==0){
           $do= DB::table('y_app')->insert($info);
        }else{
           $do= DB::table('y_app')->where(['id'=>$info['id']])->update($info);
        }
        if($do){
         return   \Yz::Return(true,'',[]);
        }else{
            return \Yz::echoError1("操作失败");
        }
    }
    public function Del()
    {
        $id=request('id');
        $d=DB::table('y_app')->where(['id'=>$id])->update([
            'is_del'=>1
        ]);
        if($d){
            return \Yz::Return(true,'操作成功',[]);
        }else{
            return \Yz::Return(false,'删除失败',[]);
        }
    }
}
