|
@@ -494,8 +494,6 @@ class EmployeeService extends Service
|
|
|
|
|
|
$model = new Role();
|
|
|
$model->title = $data['title'] ;
|
|
|
- $model->depart_id = $data['depart_id'] ?? 0;
|
|
|
- $model->top_depart_id = $data['top_depart_id'] ?? 0;
|
|
|
$model->save();
|
|
|
|
|
|
return [true,''];
|
|
@@ -535,8 +533,7 @@ class EmployeeService extends Service
|
|
|
* @return array
|
|
|
*/
|
|
|
public function roleList($data,$user){
|
|
|
- $model = Role::TopClear($user,$data);
|
|
|
- $model = $model->where('del_time',0)
|
|
|
+ $model = Role::where('del_time',0)
|
|
|
->select('title','crt_time','id','upd_time')
|
|
|
->orderBy('id','desc');
|
|
|
if(! empty($data['title'])) $model->where('title', 'LIKE', '%' . $data['title'] . '%');
|
|
@@ -555,21 +552,14 @@ class EmployeeService extends Service
|
|
|
public function roleRule(&$data,$user, $is_check = true){
|
|
|
if($this->isEmpty($data,'title')) return [false,'名称不能为空!'];
|
|
|
|
|
|
- //所属部门 以及 顶级部门
|
|
|
- if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
|
|
|
- $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
|
|
|
-
|
|
|
if($is_check){
|
|
|
$bool = Role::where('title',$data['title'])
|
|
|
- ->where('top_depart_id',$data['top_depart_id'])
|
|
|
->where('del_time',0)
|
|
|
->exists();
|
|
|
if($bool) return [false,'角色名称已存在!'];
|
|
|
}else{
|
|
|
if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
- $top_depart_id = Role::where('id',$data['id'])->value('top_depart_id');
|
|
|
$bool = Role::where('title',$data['title'])
|
|
|
- ->where('top_depart_id',$top_depart_id)
|
|
|
->where('id','<>',$data['id'])
|
|
|
->where('del_time',0)
|
|
|
->exists();
|
|
@@ -652,34 +642,6 @@ class EmployeeService extends Service
|
|
|
return [true, $role];
|
|
|
}
|
|
|
|
|
|
- public function departSetIndex($data,$user){
|
|
|
- if(empty($data['data'])) return [false, '指标数据不能为空'];
|
|
|
-
|
|
|
- $time = time();
|
|
|
- $insert = [];
|
|
|
- foreach ($data['data'] as $value){
|
|
|
- if(empty($value['top_depart_id'])) return [false, '请选择门店'];
|
|
|
- if(! isset($value['param_one'])) return [false, '请填写销售额'];
|
|
|
- if(floatval($value['param_one']) == 0.0) return [false,'销售额不能为空'];
|
|
|
- $insert[] = [
|
|
|
- 'top_depart_id' => $value['top_depart_id'],
|
|
|
- 'param_one' => $value['param_one'],
|
|
|
- 'crt_time' => $time,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- if(empty($insert)) return [true, ''];
|
|
|
-
|
|
|
- //删除指标
|
|
|
- DepartIndex::where('del_time',0)
|
|
|
- ->update(['del_time' => $time]);
|
|
|
-
|
|
|
- //写入指标
|
|
|
- DepartIndex::insert($insert);
|
|
|
-
|
|
|
- return [true, ''];
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 部门编辑
|
|
|
* @param $data
|
|
@@ -690,14 +652,9 @@ class EmployeeService extends Service
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
$update = $msg['data'][0];
|
|
|
-
|
|
|
$model = new Depart();
|
|
|
$model->where('id',$data['id'])->update($update);
|
|
|
|
|
|
- Storehouse::where('del_time',0)
|
|
|
- ->where('top_depart_id',$data['id'])
|
|
|
- ->update(['title' => $update['title']]);
|
|
|
-
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
@@ -714,83 +671,18 @@ class EmployeeService extends Service
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
- $time = time();
|
|
|
-
|
|
|
foreach ($msg['data'] as $value){
|
|
|
$model = new Depart();
|
|
|
$model->parent_id = $value['parent_id'];
|
|
|
$model->title = $value['title'];
|
|
|
$model->code = $value['code'];
|
|
|
$model->is_main = $value['is_main'];
|
|
|
- $model->basic_type_id = $value['basic_type_id'] ?? 0;
|
|
|
- $model->rate = $value['rate'] ?? 0;
|
|
|
- $model->notify_id = $value['notify_id'] ?? 0;
|
|
|
- $model->area = $value['area'] ?? 0;
|
|
|
- $model->province = $value['province'] ?? "";
|
|
|
$model->save();
|
|
|
$depart_id = $model->id;
|
|
|
if(empty($depart_id)) {
|
|
|
DB::rollBack();
|
|
|
return [false,'部门新建失败'];
|
|
|
}
|
|
|
-
|
|
|
- if(empty($value['parent_id'])){
|
|
|
- $m = new Storehouse();
|
|
|
- $m->title = $value['title'];
|
|
|
- $m->depart_id = $depart_id;
|
|
|
- $m->top_depart_id = $depart_id;
|
|
|
- $m->crt_id = $user['id'];
|
|
|
- $m->save();
|
|
|
- if(empty($m->id)) {
|
|
|
- DB::rollBack();
|
|
|
- return [false,'仓库生成失败'];
|
|
|
- }
|
|
|
-
|
|
|
- $employee = new Employee();
|
|
|
- $number = "admin" . $value['code'];
|
|
|
- $employee->number = $number;
|
|
|
- $employee->emp_name = $value['title'] . "管理员账号";
|
|
|
- $employee->entry_time = date('Y-m-d');
|
|
|
- $employee->state = 1;
|
|
|
- $employee->crt_id = $user['id'];
|
|
|
- $employee->is_admin = 1;
|
|
|
- $employee->account = $number;
|
|
|
- $employee->password = Hash::make("password");
|
|
|
- $employee->is_manager = 1;
|
|
|
- $employee->save();
|
|
|
- if(empty($employee->id)) {
|
|
|
- DB::rollBack();
|
|
|
- return [false,'管理员账号生成失败'];
|
|
|
- }
|
|
|
-
|
|
|
- $depart = new EmployeeDepartPermission();
|
|
|
- $depart->employee_id = $employee->id;
|
|
|
- $depart->depart_id = $depart_id;
|
|
|
- $depart->save();
|
|
|
-
|
|
|
- if(empty($depart->id)) {
|
|
|
- DB::rollBack();
|
|
|
- return [false,'管理员账号部门关联生成失败'];
|
|
|
- }
|
|
|
-
|
|
|
- //公司系统设置
|
|
|
- ProductInventorySet::insert(['top_depart_id' => $depart_id, 'param_one' => 1, 'crt_time' => $time]);
|
|
|
-
|
|
|
- //基础设置 产品分类 默认
|
|
|
- $this->createBasicType($depart_id);
|
|
|
-
|
|
|
-// if(! empty($value['is_main'])){
|
|
|
-// //总供应商 所有分社可见
|
|
|
-// Supplier::insert([
|
|
|
-// 'title' => $value['title'],
|
|
|
-// 'crt_id' => $user['id'],
|
|
|
-// 'crt_time' => $time,
|
|
|
-// 'depart_id' => $depart_id,
|
|
|
-// 'top_depart_id' => $depart_id,
|
|
|
-// 'is_main' => Supplier::is_main,
|
|
|
-// ]);
|
|
|
-// }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
@@ -802,30 +694,6 @@ class EmployeeService extends Service
|
|
|
return [true,'保存成功!'];
|
|
|
}
|
|
|
|
|
|
- private function createBasicType($depart_id = 0){
|
|
|
- $insert = [];
|
|
|
- $time = time();
|
|
|
- foreach (BasicType::$type as $key => $value){
|
|
|
- $insert[] = [
|
|
|
- 'title' => '默认',
|
|
|
- 'type' => $key,
|
|
|
- 'depart_id' => $depart_id,
|
|
|
- 'top_depart_id' => $depart_id,
|
|
|
- 'crt_time' => $time
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- BasicType::insert($insert);
|
|
|
-
|
|
|
- ProductCategory::insert([
|
|
|
- 'title' => '默认',
|
|
|
- 'parent_id' => 0,
|
|
|
- 'crt_time' => $time,
|
|
|
- 'depart_id' => $depart_id,
|
|
|
- 'top_depart_id' => $depart_id,
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 部门删除
|
|
|
* @param $data
|
|
@@ -855,9 +723,6 @@ class EmployeeService extends Service
|
|
|
|
|
|
if($this->checkDepartHasPerson($data['id'])) return [false,'部门下有人员档案!'];
|
|
|
|
|
|
- $bool = ProductInventory::whereIn('top_depart_id',$data['id'])->where('del_time',0)->exists();
|
|
|
- if($bool) return [false,'部门下的仓库有产品信息!'];
|
|
|
-
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
@@ -869,20 +734,9 @@ class EmployeeService extends Service
|
|
|
*/
|
|
|
public function departList($data,$user){
|
|
|
$model = Depart::where('del_time',0)
|
|
|
- ->select('title','id','code','parent_id','is_main','basic_type_id','rate','notify_id','channel_id','area','province')
|
|
|
+ ->select('title','id','code','parent_id')
|
|
|
->orderby('id', 'asc');
|
|
|
|
|
|
- if(! empty($data['get_top']) && $data['get_top'] == 1){
|
|
|
- //指派销售
|
|
|
- $depart_id = $this->getDepartIdListOfMySales($user);
|
|
|
- $model->whereIn('id', $depart_id);
|
|
|
- }else{
|
|
|
- if(! $user['is_all_depart'] && empty($data['is_top_qx'])){
|
|
|
- $depart_id = $this->getDepartIdList($user);
|
|
|
- $model->whereIn('id',$depart_id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if(isset($data['parent_id'])) $model->where('parent_id', $data['parent_id']);
|
|
|
if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
@@ -901,26 +755,6 @@ class EmployeeService extends Service
|
|
|
public function fillDepartList($list,$user){
|
|
|
if(empty($list)) return $list;
|
|
|
|
|
|
- $basic = BasicType::where('del_time',0)
|
|
|
- ->whereIn('id', array_unique(array_column($list,'basic_type_id')))
|
|
|
- ->pluck('title','id')->toArray();
|
|
|
- $emp_id = array_unique(array_merge_recursive(array_column($list,'notify_id'),array_column($list,'channel_id')));
|
|
|
- $emp_map = Employee::whereIn('id',$emp_id)
|
|
|
- ->pluck('emp_name','id')
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- //省
|
|
|
- $address_map = config('address');
|
|
|
- $address_map = array_column($address_map,'label','value');
|
|
|
- foreach ($list as $key => $value){
|
|
|
- $list[$key]['basic_type_title'] = $basic[$value['basic_type_id']] ?? '';
|
|
|
- $list[$key]['is_show_basic_type'] = $user['is_all_depart'];
|
|
|
- $list[$key]['notify_name'] = $emp_map[$value['notify_id']] ?? '';
|
|
|
- $list[$key]['channel_name'] = $emp_map[$value['channel_id']] ?? '';
|
|
|
- $list[$key]['area_name'] = Depart::$area[$value['area']] ?? '';
|
|
|
- $list[$key]['province_name'] = $address_map[$value['province']] ?? '';
|
|
|
- }
|
|
|
-
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
@@ -941,18 +775,6 @@ class EmployeeService extends Service
|
|
|
return array_unique($result);
|
|
|
}
|
|
|
|
|
|
- //获取指派销售时的部门
|
|
|
- public function getDepartIdListOfMySales($user){
|
|
|
- $top = $user['depart_top'][0] ?? [];
|
|
|
- $top = $top['depart_id'] ?? 0;
|
|
|
- $list = Depart::where('del_time',0)->select('id','parent_id')->get()->toArray();
|
|
|
- // 查找所有子级id
|
|
|
- $childIds = $this->findChildIds($top, $list);
|
|
|
- $result = array_merge($childIds, [$top]);
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 部门参数规则
|
|
|
* @param $data
|
|
@@ -981,48 +803,18 @@ class EmployeeService extends Service
|
|
|
if($title_count[$value] > 1) return [false,'名称不能重复'];
|
|
|
}
|
|
|
|
|
|
- $count = 0;
|
|
|
- foreach ($data['data'] as $value){
|
|
|
- if(empty($value['parent_id']) && ! empty($value['is_main'])) $count ++;
|
|
|
- }
|
|
|
- if($count > 1) return [false,'总社已存在!'];
|
|
|
- if($count == 1){
|
|
|
- $id = $data['id'] ?? 0;
|
|
|
- $bool = Depart::where('del_time',0)
|
|
|
- ->where('parent_id',0)
|
|
|
- ->where('is_main',1)
|
|
|
- ->when(! empty($id), function ($query) use ($id) {
|
|
|
- return $query->where('id', '<>',$id);
|
|
|
- })
|
|
|
- ->exists();
|
|
|
- if($bool) return [false,'总社已存在!'];
|
|
|
- }
|
|
|
-
|
|
|
- //省
|
|
|
- $address_map = config('address');
|
|
|
- $address_map = array_column($address_map,'label','value');
|
|
|
-
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
- if(! empty($value['area'])){
|
|
|
- $area = array_keys(Depart::$area);
|
|
|
- if(! in_array($value['area'], $area)) return [false, '门店所属大区不存在'];
|
|
|
- }
|
|
|
- if(! empty($value['province']) && ! isset($address_map[$value['province']])) return [false, '门店所属省份不存在'];
|
|
|
-
|
|
|
if(empty($value['parent_id'])) $data['data'][$key]['parent_id'] = 0;
|
|
|
|
|
|
$data['data'][$key]['upd_time'] = time();
|
|
|
|
|
|
- //Depart::whereRaw("(binary code = '{$value['code']}' OR title = '{$value['title']}')")
|
|
|
if($is_check){
|
|
|
- if(empty($user['is_all_depart']) && empty($value['parent_id'])) return [false,'上级部门必须选择'];
|
|
|
$data['data'][$key]['crt_time'] = time();
|
|
|
$bool = Depart::whereRaw("binary code = '{$value['code']}'")
|
|
|
->where('del_time',0)
|
|
|
->exists();
|
|
|
}else{
|
|
|
if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
|
|
|
- if($data['id'] == $user['head']['id'] && empty($value['is_main'])) return [false,'总社不支持变更!'];
|
|
|
$bool = Depart::whereRaw("binary code = '{$value['code']}'")
|
|
|
->where('id','<>',$data['id'])
|
|
|
->where('del_time',0)
|