<?php

namespace App\Http\Controllers\API\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Admin\UserService;

class UserController extends Controller
{
    public function GetInfoList(){
        $status =request('status');
        $cname =request('cname');
        $departmentid =request('departmentid');
        $ward =request('ward');
        $page =request('page');
        $pagesize =request('pageSize');
        $s=app()->make(UserService::class);
        return  $s->GetInfoList(['cname'=>$cname,'status'=>$status,'departmentid'=>$departmentid,'ward'=>$ward,'page'=>$page,'pagesize'=>$pagesize]);
    }
    public function Save(){
        $userInfo =request('userInfo');
        $s=app()->make(UserService::class);
        return  $s->Save(['info'=>$userInfo]);
    }
    public function GetDetail(){
        $id =request('id');
        $s=app()->make(UserService::class);
        return  $s->GetDetail(['id'=>$id]);
    }
    public function ChangePwd(Request $request){  //admin修改密码
        $userid = $request->get('userid');//中间件产生的参数
        $oldpwd =request('oldpwd');
        $newpwd =request('newpwd');
        if($oldpwd and $newpwd){
            $s=app()->make(UserService::class);
            return  $s->ChangePwd(['id'=>$userid,'oldpwd'=>$oldpwd,'newpwd'=>$newpwd]);
        }else{
            return \Yz::echoError("参数不完整");
        }

    }
    //重置密码
    public function resetPwd(Request $request)
    {
        $group = $request->get('role');//中间件产生的参数
        $password =request('password');
        $userid=request('userid');
        if(!isset($password)) return \Yz::echoError1('请输入密码');
        if(!isset($userid)) return \Yz::echoError1('用户id不能为空');
        $service= new UserService();
        return  $service->resetPwd($group,$password,$userid);
    }

    //修改自身信息
    public function ChangInfo(Request $request){
        $userid = $request->get('userid');//中间件产生的参数
        $headimg =request('headimg');
        $name =request('name');
        if(!isset($name)) return \Yz::echoError1('名称不可为空');
        $ser=new UserService();
        return  $ser->ChangInfo(['userid'=>$userid,'name'=>$name,'headimg'=>$headimg]);
    }
}
