|
|
|
@ -16,10 +16,9 @@ use app\model\departments\Departments; |
|
|
|
use app\model\member\Member; |
|
|
|
use app\model\personnel\Personnel; |
|
|
|
use app\model\sys\SysRole; |
|
|
|
use app\service\core\member\CoreMemberService; |
|
|
|
use app\model\sys\SysUser; |
|
|
|
use core\base\BaseApiService; |
|
|
|
use core\exception\ApiException; |
|
|
|
use core\util\Barcode; |
|
|
|
use think\facade\Cache; |
|
|
|
use think\Model; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -36,7 +35,8 @@ class PersonnelService extends BaseApiService |
|
|
|
} |
|
|
|
|
|
|
|
//获取员工信息 |
|
|
|
public function info(array $where,string $field = '*'){ |
|
|
|
public function info(array $where, string $field = '*') |
|
|
|
{ |
|
|
|
$model = $this->model; |
|
|
|
|
|
|
|
$res = [ |
|
|
|
@ -56,9 +56,12 @@ class PersonnelService extends BaseApiService |
|
|
|
//查询用户角色校区部门信息 |
|
|
|
$campus_person_role = CampusPersonRole::where('person_id', $where['id']) |
|
|
|
->with([ |
|
|
|
'campus' => function ($query) {}, |
|
|
|
'sysRole' => function ($query) {}, |
|
|
|
'departments' => function ($query) {} |
|
|
|
'campus' => function ($query) { |
|
|
|
}, |
|
|
|
'sysRole' => function ($query) { |
|
|
|
}, |
|
|
|
'departments' => function ($query) { |
|
|
|
} |
|
|
|
]) |
|
|
|
->select()->toArray(); |
|
|
|
$role_id = array_unique(array_column($campus_person_role, 'role_id')); |
|
|
|
@ -130,7 +133,7 @@ class PersonnelService extends BaseApiService |
|
|
|
} else { |
|
|
|
$data = []; |
|
|
|
$res['code'] = 0; |
|
|
|
$res['msg'] = '为找到数据'; |
|
|
|
$res['msg'] = '未找到数据'; |
|
|
|
$res['data'] = $data; |
|
|
|
} |
|
|
|
|
|
|
|
@ -139,7 +142,8 @@ class PersonnelService extends BaseApiService |
|
|
|
} |
|
|
|
|
|
|
|
//员工信息-修改 |
|
|
|
public function edit(array $where,array $data){ |
|
|
|
public function edit(array $where, array $data) |
|
|
|
{ |
|
|
|
$data['update_time'] = date('Y-m-d H:i:s'); |
|
|
|
|
|
|
|
if (!$where) { |
|
|
|
@ -209,7 +213,96 @@ class PersonnelService extends BaseApiService |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
//验证旧密码 |
|
|
|
public function checkOldPwd(string $old_passowrd) |
|
|
|
{ |
|
|
|
$res = [ |
|
|
|
'code' => 0, |
|
|
|
'msg' => '操作失败', |
|
|
|
'data' => [] |
|
|
|
]; |
|
|
|
$personnel_id = $this->member_id; |
|
|
|
$phone = $this->model->where('id', $personnel_id)->value('phone'); |
|
|
|
|
|
|
|
$password = (new SysUser())->where('username', $phone)->value('password'); |
|
|
|
if (!check_password($old_passowrd, $password)) { |
|
|
|
$res['msg'] = '旧密码错误'; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
$res['code'] = 1; |
|
|
|
$res['msg'] = '密码正确'; |
|
|
|
$res['data'] = [ |
|
|
|
'key_value' => $this->setEditPasswordKey($phone) |
|
|
|
]; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
//设置新密码 |
|
|
|
public function edidPassword($phone, $new_password, $key_value) |
|
|
|
{ |
|
|
|
$checkEditPasswordKey = $this->checkEditPasswordKey($phone, $key_value);//验证修改密码允许的缓存key |
|
|
|
if (!$checkEditPasswordKey['code']) { |
|
|
|
return $checkEditPasswordKey; |
|
|
|
} |
|
|
|
//查询用户修改密码 |
|
|
|
$update = (new SysUser())->where('username', $phone)->update([ |
|
|
|
'password' => create_password($new_password),//创建密码 |
|
|
|
'update_time' => time(), |
|
|
|
]); |
|
|
|
if (!$update) { |
|
|
|
$res = [ |
|
|
|
'code' => 0, |
|
|
|
'msg' => '操作失败', |
|
|
|
'data' => [] |
|
|
|
]; |
|
|
|
} else { |
|
|
|
$res = [ |
|
|
|
'code' => 1, |
|
|
|
'msg' => '操作成功', |
|
|
|
'data' => [] |
|
|
|
]; |
|
|
|
} |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//生成修改密码允许的缓存key |
|
|
|
public function setEditPasswordKey(string $phone) |
|
|
|
{ |
|
|
|
$key_name = 'edit_password_' . $phone; |
|
|
|
//生成字符串,存入cache中 |
|
|
|
//check_password()//验证 |
|
|
|
//create_password()//创建 |
|
|
|
|
|
|
|
$key_value = create_password($key_name); |
|
|
|
// 缓存在3600秒之后过期 |
|
|
|
Cache::set($key_name, $key_value, 3600); |
|
|
|
return $key_value; |
|
|
|
} |
|
|
|
|
|
|
|
//验证修改密码允许的缓存key |
|
|
|
public function checkEditPasswordKey(string $phone, string $key_value) |
|
|
|
{ |
|
|
|
$res = [ |
|
|
|
'code' => 0, |
|
|
|
'msg' => '' |
|
|
|
]; |
|
|
|
$key_name = 'edit_password_' . $phone; |
|
|
|
$key_value_cache = Cache::get($key_name); |
|
|
|
if (empty($key_value_cache)) { |
|
|
|
$res['msg'] = '参数已过期,请重新输入旧密码进行验证'; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
//验证 |
|
|
|
if ($key_value_cache != $key_value) { |
|
|
|
$res['msg'] = '参数不正确,请重新输入旧密码进行验证'; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
$res['code'] = 1; |
|
|
|
$res['msg'] = '操作成功'; |
|
|
|
return $res; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -217,7 +310,8 @@ class PersonnelService extends BaseApiService |
|
|
|
* @param array $data |
|
|
|
* @return Member|array|mixed|Model !!! 仔细看,返回值是模型对象 如果想要判断是否为空 请用 $member->isEmpty() |
|
|
|
*/ |
|
|
|
public function findMemberInfo(array $data){ |
|
|
|
public function findMemberInfo(array $data) |
|
|
|
{ |
|
|
|
//会员账号 |
|
|
|
if (!empty($data['username'])) |
|
|
|
$where[] = ['username', '=', $data['username']]; |
|
|
|
|