You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.5 KiB
PHP
93 lines
3.5 KiB
PHP
<?php
|
|
namespace App\Services\Admin;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Services\Login\LoginService;
|
|
|
|
class UserService
|
|
{
|
|
public function GetInfoList($arr){
|
|
$q=DB::select("select a.id, a.cn_name as cname,a.username as uname,a.status,a.created_at,b.group_name from users as a left join `group` as b on a.`group` =b.id where a.status in(0,1) ");
|
|
$count=DB::select("select count(1) as c from users as a left join `group` as b on a.`group` =b.id where a.status in(0,1)");
|
|
$result['list']=$q;
|
|
$result['count']=$count[0]->c;
|
|
return $result;
|
|
}
|
|
public function Save($arr){
|
|
if($arr['info']['id']){
|
|
$query=DB::table('users')->where(['id'=>$arr['info']['id']])->update([
|
|
'group' => $arr['info']['groupId'],
|
|
'cn_name' => $arr['info']['cname'],
|
|
'username' => $arr['info']['uname'],
|
|
'status'=>$arr['info']['status'],
|
|
]);
|
|
}else{
|
|
$hash = password_hash('111111', PASSWORD_DEFAULT);
|
|
$c=DB::table('users')->where(['username'=>$arr['info']['uname']])->get();
|
|
if(count($c)){
|
|
$result['status']='no';
|
|
$result['msg']='用户名已存在';
|
|
return $result;
|
|
}
|
|
DB::beginTransaction();
|
|
try {
|
|
$id=DB::table('users')->insertGetId([
|
|
'group' => $arr['info']['groupId'],
|
|
'cn_name' => $arr['info']['cname'],
|
|
'username' => $arr['info']['uname'],
|
|
'pwd' => $hash,
|
|
'status'=>1
|
|
]);
|
|
if($arr['info']['groupId']==7){ //如果是新建体检机构,则在体检机构表插入数据
|
|
DB::table('medical_institution')->insert([
|
|
'org_name' => $arr['info']['cname'],
|
|
'link_user_id'=>$id,
|
|
'status'=>1
|
|
]);
|
|
}
|
|
DB::commit(); // 手动提交事务
|
|
if($id){
|
|
$result['status']='ok';
|
|
$result['msg']='操作成功';
|
|
}
|
|
} catch (\Exception $e) {
|
|
DB::rollback(); // 发生异常时手动回滚事务
|
|
$result['status']='no';
|
|
$result['msg']='操作失败';
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
public function GetDetail($arr){
|
|
$c=DB::table('users')->select(['id','cn_name','username','status','group','img'])->where(['id'=>$arr['id']])->whereIn('status',[0,1])->get();
|
|
if(count($c)){
|
|
$result['info']=$c;
|
|
$result['status']='ok';
|
|
$result['msg']='成功';
|
|
}else{
|
|
$result['status']='no';
|
|
$result['msg']='获取详情失败';
|
|
}
|
|
return $result;
|
|
}
|
|
public function ChangePwd($arr){
|
|
$result=array();
|
|
$s=app()->make(LoginService::class);
|
|
$check=$s->CheckPwd(['userid'=>$arr['id'],'password'=>$arr['oldpwd']]);
|
|
if($check['status']){
|
|
$hash = password_hash($arr['newpwd'], PASSWORD_DEFAULT);
|
|
$u=DB::table('users')->where(['id'=>$arr['id'],'status'=>1])->update(['pwd'=>$hash]);
|
|
if($u){
|
|
$result['status']='ok';
|
|
}else{
|
|
$result['status']='no';
|
|
$result['msg']='修改密码失败';
|
|
}
|
|
}else{
|
|
$result=$check;
|
|
}
|
|
return $result;
|
|
}
|
|
}
|