|
@@ -1277,18 +1277,15 @@ class EmployeeService extends Service
|
|
|
})
|
|
|
->get()->toArray();
|
|
|
|
|
|
- if(empty($res)) return [false,'账号不存在或已被删除!'];
|
|
|
- if(count($res) > 1) return [false,'该手机号检测出多个账户,请联系后台!'];
|
|
|
+ if(empty($res)) return [false,'账号不存在或已被删除'];
|
|
|
+ if(count($res) > 1) return [false,'该手机号检测出多个账户,请联系后台管理员'];
|
|
|
|
|
|
$res = reset($res);
|
|
|
- if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
|
|
|
- if($res['is_admin'] != Employee::IS_ADMIN) return [false,'该账号不能登录!'];
|
|
|
- if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
|
|
|
+ if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误'];
|
|
|
+ if($res['is_admin'] != Employee::IS_ADMIN) return [false,'账号限制登录'];
|
|
|
+ if($res['state'] == Employee::NOT_USE) return [false,'账号已停用'];
|
|
|
|
|
|
- //门店的信息
|
|
|
- $login_message = EmployeeService::getLoginMessage($res['id']);
|
|
|
-
|
|
|
- return [true, ['id'=>$res['id'],'name'=>$res['emp_name'],'all_top'=> $login_message]];
|
|
|
+ return [true, ['id'=>$res['id'],'name'=>$res['emp_name'], 'number' => $res['number']]];
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1321,9 +1318,8 @@ class EmployeeService extends Service
|
|
|
//组织
|
|
|
$role_id = array_unique(array_column($role,'role_id'));
|
|
|
asort($role_id);
|
|
|
- $role_id = array_values($role_id);
|
|
|
|
|
|
- return $role_id;
|
|
|
+ return array_values($role_id);
|
|
|
}
|
|
|
|
|
|
public static function getPersonRoleQx($role_id = []){
|
|
@@ -1507,201 +1503,21 @@ class EmployeeService extends Service
|
|
|
* @param $employee_id
|
|
|
* @return array|string[]
|
|
|
*/
|
|
|
- public static function getLoginDepart($employee_id, $top_depart_id = 0){
|
|
|
- if(empty($employee_id)) return [];
|
|
|
-
|
|
|
- //自己绑定的部门 启用的部门
|
|
|
- $depart = EmployeeDepartPermission::from('employee_depart_permission as a')
|
|
|
- ->join('depart as b','b.id','a.depart_id')
|
|
|
- ->where('a.employee_id',$employee_id)
|
|
|
- ->where('b.is_use',Depart::IS_UES)
|
|
|
- ->select('a.depart_id','b.is_main','b.parent_id','b.basic_type_id','b.title')
|
|
|
- ->orderBy('b.parent_id','asc')
|
|
|
- ->orderBy('b.is_main','desc')
|
|
|
- ->orderBy('a.depart_id','asc')
|
|
|
- ->get()->toArray();
|
|
|
-
|
|
|
- $top = $map = $rule = $head = [];
|
|
|
- $res_data = [];//获取当前所在部门(也可能是门店 为了 depart_id)
|
|
|
- $my_depart = [];//当前门店下 我勾选的门店以及部门信息
|
|
|
- $is_all_depart = 0;
|
|
|
- if(! empty($depart)){
|
|
|
- //库存校验
|
|
|
- $set_map = ProductInventorySet::where('del_time',0)->pluck('param_one','top_depart_id')->toArray();
|
|
|
-
|
|
|
- //所有部门
|
|
|
- $list = Depart::where('del_time',0)->get()->toArray();
|
|
|
- $depart_map = array_column($list,null,'id');
|
|
|
-
|
|
|
- foreach ($depart as $key => $value){
|
|
|
- if($value['parent_id'] == 0){
|
|
|
- $is_stock = $set_map[$value['depart_id']] ?? 1;
|
|
|
- $depart[$key]['is_stock'] = $is_stock;
|
|
|
- $top[$value['depart_id']] = [
|
|
|
- 'depart_id' => $value['depart_id'],
|
|
|
- 'is_main' => $value['is_main'],
|
|
|
- 'basic_type_id' => $value['basic_type_id'],
|
|
|
- 'title' => $value['title'],
|
|
|
- 'is_stock' => $is_stock,
|
|
|
- ];
|
|
|
- $map[$value['depart_id']] = $value['depart_id'];
|
|
|
-
|
|
|
- if($value['depart_id'] == $top_depart_id) {
|
|
|
- $my_depart[] = $depart[$key];
|
|
|
- if(empty($res_data)){
|
|
|
- $res_data = $depart[$key];
|
|
|
- }else{
|
|
|
- if($value['depart_id'] >= $res_data['depart_id']) $res_data = $depart[$key];
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- $t = self::getTopParentId($value['depart_id'],$list);
|
|
|
- if($t && isset($depart_map[$t])) {
|
|
|
- $is_stock = $set_map[$t] ?? 1;
|
|
|
- $depart[$key]['is_stock'] = $is_stock;
|
|
|
- $t_tmp = $depart_map[$t] ?? [];
|
|
|
- if( ! isset($top[$t_tmp['id']])){
|
|
|
- $top[$t_tmp['id']] = [
|
|
|
- 'depart_id' => $t_tmp['id'],
|
|
|
- 'is_main' => $t_tmp['is_main'],
|
|
|
- 'basic_type_id' => $t_tmp['basic_type_id'],
|
|
|
- 'title' => $t_tmp['title'],
|
|
|
- 'is_stock' => $set_map[$t] ?? 1,
|
|
|
- ];
|
|
|
- }
|
|
|
- $map[$value['depart_id']] = $t;
|
|
|
- }
|
|
|
- if($t == $top_depart_id){
|
|
|
- $my_depart[] = $depart[$key];
|
|
|
- if(empty($res_data)){
|
|
|
- $res_data = $depart[$key];
|
|
|
- }else{
|
|
|
- if($value['depart_id'] >= $res_data['depart_id']) $res_data = $depart[$key];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //-------------重组当前所在门店
|
|
|
- $top = array_values($top);
|
|
|
- usort($top, function($a, $b) {
|
|
|
- return $b['is_main'] - $a['is_main'];
|
|
|
- });
|
|
|
- if(! empty($top_depart_id)){
|
|
|
- $targetArray = null;
|
|
|
- foreach ($top as $key => $value) {
|
|
|
- if ($value['depart_id'] == $top_depart_id) {
|
|
|
- $targetArray = $value;
|
|
|
- unset($top[$key]); // 从原数组中移除目标数组
|
|
|
- break; // 找到后跳出循环
|
|
|
- }
|
|
|
- }
|
|
|
- if ($targetArray) array_unshift($top, $targetArray);
|
|
|
- }
|
|
|
- //-------------重组当前所在门店
|
|
|
-
|
|
|
- //-------------拥有的数据权限(门店、部门)
|
|
|
- $my_top = $top[0] ?? [];
|
|
|
- foreach ($my_depart as $value){
|
|
|
- if(in_array($value['depart_id'],$rule)) continue;
|
|
|
- if(! $value['parent_id']){ //顶级
|
|
|
- if(! empty($value['is_main']) && ! $is_all_depart) $is_all_depart = 1;
|
|
|
- if($value['is_main']) {//是总公司
|
|
|
- //所有部门都有
|
|
|
- $rule = array_column($list,'id');
|
|
|
- }else{//不是总公司
|
|
|
- //自己以及子部门
|
|
|
- $depart_id = array_merge(self::getAllIds($list,$map[$value['depart_id']]),[$map[$value['depart_id']]]);
|
|
|
- $rule = array_merge_recursive($rule,$depart_id);
|
|
|
- }
|
|
|
- }else{//非顶级
|
|
|
- if(! empty($my_top['is_main']) && $value['is_main'] && ! $is_all_depart) $is_all_depart = 1;
|
|
|
-
|
|
|
- if($value['is_main']) {//是总社
|
|
|
- $top_tmp = $map[$value['depart_id']];
|
|
|
- if(! empty($depart_map[$top_tmp]['is_main'])){
|
|
|
- //顶级公司是总公司 所有部门都有
|
|
|
- $rule = array_column($list,'id');
|
|
|
- }else{
|
|
|
- //顶级公司是分公司 分公司所有部门
|
|
|
- $depart_id = array_merge(self::getAllIds($list,$top_tmp),[$top_tmp]);
|
|
|
- $rule = array_merge_recursive($rule,$depart_id);
|
|
|
- }
|
|
|
- }else{//不是总社
|
|
|
- $rule = array_merge($rule,[$value['depart_id']]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //-------------拥有的数据权限(门店、部门)
|
|
|
-
|
|
|
- //总店
|
|
|
- foreach ($list as $value){
|
|
|
- if(empty($value['parent_id']) && ! empty($value['is_main'])) $head = $value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $rule = array_unique($rule);
|
|
|
-
|
|
|
- return [$depart,$top,$map,$rule,$is_all_depart,$head,$res_data];
|
|
|
- }
|
|
|
-
|
|
|
- //获取用户的所属门店信息
|
|
|
- public static function getLoginMessage($employee_id){
|
|
|
+ public static function getLoginDepart($employee_id){
|
|
|
if(empty($employee_id)) return [];
|
|
|
|
|
|
- //自己绑定的部门 启用的部门
|
|
|
+ //自己绑定的部门 且 启用的部门
|
|
|
$depart = EmployeeDepartPermission::from('employee_depart_permission as a')
|
|
|
->join('depart as b','b.id','a.depart_id')
|
|
|
->where('a.employee_id',$employee_id)
|
|
|
->where('b.is_use',Depart::IS_UES)
|
|
|
- ->select('a.depart_id','b.is_main','b.parent_id','b.basic_type_id','b.title')
|
|
|
+ ->select('a.depart_id','b.title')
|
|
|
->orderBy('b.parent_id','asc')
|
|
|
->orderBy('b.is_main','desc')
|
|
|
->orderBy('a.depart_id','asc')
|
|
|
->get()->toArray();
|
|
|
|
|
|
- $top = [];
|
|
|
- if(! empty($depart)){
|
|
|
- //所有部门
|
|
|
- $list = Depart::where('del_time',0)->get()->toArray();
|
|
|
- $depart_map = array_column($list,null,'id');
|
|
|
- foreach ($depart as $value){
|
|
|
- if($value['parent_id'] == 0){//顶级
|
|
|
- if(! isset($top[$value['depart_id']])){
|
|
|
- $top[$value['depart_id']] = [
|
|
|
- 'depart_id' => $value['depart_id'],
|
|
|
- 'is_main' => $value['is_main'],
|
|
|
- 'title' => $value['title'],
|
|
|
- ];
|
|
|
- }
|
|
|
- }else{
|
|
|
- //门店
|
|
|
- $t = self::getTopParentId($value['depart_id'],$list);
|
|
|
-
|
|
|
- if($t && isset($depart_map[$t])) {
|
|
|
- $t_tmp = $depart_map[$t] ?? [];
|
|
|
- $is_all_depart = 0;
|
|
|
- if(! empty($t_tmp['is_main']) && $value['is_main']) $is_all_depart = 1;
|
|
|
- if(! isset($top[$t_tmp['id']])){
|
|
|
- $top[$t_tmp['id']] = [
|
|
|
- 'depart_id' => $t_tmp['id'],
|
|
|
- 'is_main' => $is_all_depart,
|
|
|
- 'title' => $t_tmp['title'],
|
|
|
- ];
|
|
|
- }else{
|
|
|
- if(! empty($is_all_depart)) $top[$t_tmp['id']]['is_main'] = $is_all_depart;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $top = array_values($top);
|
|
|
- usort($top, function($a, $b) {
|
|
|
- return $b['is_main'] - $a['is_main'];
|
|
|
- });
|
|
|
-
|
|
|
- return $top;
|
|
|
+ return $depart;
|
|
|
}
|
|
|
|
|
|
/**
|