|
@@ -34,9 +34,10 @@ class DeptController extends Curd
|
|
|
public function select(Request $request): Response
|
|
|
{
|
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
|
- if (!isset($where['dept_category'])) {
|
|
|
- $where['dept_category'] = '医护科室';
|
|
|
- }
|
|
|
+ // if (!isset($where['dept_category'])) {
|
|
|
+ // $where['dept_category'] = '医护科室';
|
|
|
+ // }
|
|
|
+ $limit = 1000;
|
|
|
$format = 'tree';
|
|
|
$order = $request->get('order', 'desc');
|
|
|
$field = $field ?? 'dept_addtimes';
|
|
@@ -61,19 +62,19 @@ class DeptController extends Curd
|
|
|
$primary_key = $this->model->getKeyName();
|
|
|
$model_class = get_class($this->model);
|
|
|
$model = new $model_class;
|
|
|
- $model->dept_category = '医护科室';
|
|
|
- $model->dept_super_path = "#" . $hospitalId . "#";
|
|
|
+ // $model->dept_category = '医护科室';
|
|
|
+ // $model->dept_super_path = "/0/";
|
|
|
foreach ($data as $key => $val) {
|
|
|
$model->{$key} = $val;
|
|
|
}
|
|
|
$model->save();
|
|
|
-// if ($model->dept_pid != 0) {
|
|
|
-// $superior = $this->model->getByPrimaryKey($model->dept_pid);
|
|
|
-// $model->dept_path = $superior->dept_path . $model->dept_id . '/';
|
|
|
-// } else {
|
|
|
-// $model->dept_path = '/0/' . $model->dept_id . '/';
|
|
|
-// }
|
|
|
-// $model->save();
|
|
|
+ if ($model->dept_super_id != 0) {
|
|
|
+ $superior = $this->model->getByPrimaryKey($model->dept_super_id);
|
|
|
+ $model->dept_super_path = $superior->dept_super_path . $model->dept_id . '/';
|
|
|
+ } else {
|
|
|
+ $model->dept_super_path = '/0/' . $model->dept_id . '/';
|
|
|
+ }
|
|
|
+ $model->save();
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
dump($e->getMessage());
|
|
@@ -97,30 +98,31 @@ class DeptController extends Curd
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
$model = $this->model->find($id);
|
|
|
- $oldDeptPid = $model->dept_pid;
|
|
|
- $oldDeptPath = $model->dept_path;
|
|
|
+ $oldDeptPid = $model->dept_super_id;
|
|
|
+ $oldDeptPath = $model->dept_super_path;
|
|
|
foreach ($data as $key => $val) {
|
|
|
$model->{$key} = $val;
|
|
|
}
|
|
|
-// // 上级
|
|
|
-// if ($model->dept_pid != 0) {
|
|
|
-// $superior = $this->model->getByPrimaryKey($model->dept_pid);
|
|
|
-// $model->dept_path = $superior->dept_path . $model->dept_id . '/';
|
|
|
-// }
|
|
|
-//
|
|
|
+ // 上级
|
|
|
+ if ($model->dept_super_id != 0) {
|
|
|
+ $superior = $this->model->getByPrimaryKey($model->dept_super_id);
|
|
|
+ $model->dept_super_path = $superior->dept_super_path.$model->dept_id . '/';
|
|
|
+ }
|
|
|
+
|
|
|
$model->save();
|
|
|
-// // pid变动,如果有下级,path应跟着变
|
|
|
-// if ($data['dept_pid'] != $oldDeptPid) {
|
|
|
-// $subs = $this->model->getAllSubDept($oldDeptPath);
|
|
|
-// if ($subs) {
|
|
|
-// foreach ($subs as $sub) {
|
|
|
-// $this->model->where('dept_id', $sub['dept_id'])->update(['dept_path' => str_replace($oldDeptPath, $model->dept_path, $sub['dept_path'])]);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ // pid变动,如果有下级,path应跟着变
|
|
|
+ if ($data['dept_super_id'] != $oldDeptPid) {
|
|
|
+ $subs = $this->model->getAllSubDept($oldDeptPath);
|
|
|
+ if ($subs) {
|
|
|
+ foreach ($subs as $sub) {
|
|
|
+ $this->model->where('dept_id', $sub['dept_id'])->update(['dept_super_path' => str_replace($oldDeptPath, $model->dept_super_path, $sub['dept_super_path'])]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollBack();
|
|
|
+ dump($e->getMessage());
|
|
|
throw new BusinessException('数据更新失败~');
|
|
|
}
|
|
|
}
|
|
@@ -158,7 +160,7 @@ class DeptController extends Curd
|
|
|
'name' => $item->dept_name,
|
|
|
'value' => (string)$item->dept_id,
|
|
|
'id' => $item->dept_id,
|
|
|
- 'pid' => $item->dept_pid,
|
|
|
+ 'pid' => $item->dept_super_id,
|
|
|
'dept_id' => $item->dept_id,
|
|
|
'dept_pid' => $item->dept_pid,
|
|
|
'dept_name' => $item->dept_name,
|