|
@@ -2,11 +2,11 @@
|
|
|
|
|
|
namespace app\admin\controller\medical;
|
|
|
|
|
|
-use _PHPStan_cc8d35ffb\Nette\Neon\Exception;
|
|
|
use app\admin\validate\medical\DeptValidate;
|
|
|
use app\common\Tree;
|
|
|
use app\controller\Curd;
|
|
|
use app\model\MedicalDept;
|
|
|
+use app\model\SysDept;
|
|
|
use support\Db;
|
|
|
use support\exception\BusinessException;
|
|
|
use support\Request;
|
|
@@ -16,7 +16,8 @@ class DeptController extends Curd
|
|
|
{
|
|
|
public function __construct()
|
|
|
{
|
|
|
- $this->model = new MedicalDept();
|
|
|
+// $this->model = new MedicalDept();
|
|
|
+ $this->model = new SysDept();
|
|
|
$this->validate = true;
|
|
|
$this->validateClass = new DeptValidate();
|
|
|
}
|
|
@@ -33,10 +34,12 @@ 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'] = '医护科室';
|
|
|
+ }
|
|
|
$format = 'tree';
|
|
|
$order = $request->get('order', 'desc');
|
|
|
- $field = $field ?? 'dept_addTime';
|
|
|
- $where['dept_is_del'] = 0;
|
|
|
+ $field = $field ?? 'dept_addtimes';
|
|
|
$query = $this->doSelect($where, $field, $order);
|
|
|
return $this->doFormat($query, $format, $limit);
|
|
|
}
|
|
@@ -52,26 +55,30 @@ class DeptController extends Curd
|
|
|
*/
|
|
|
protected function doInsert(array $data)
|
|
|
{
|
|
|
+ $hospitalId = SysDept::where('dept_category', '医院')->value('dept_id');
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
$primary_key = $this->model->getKeyName();
|
|
|
$model_class = get_class($this->model);
|
|
|
$model = new $model_class;
|
|
|
+ $model->dept_category = '医护科室';
|
|
|
+ $model->dept_super_path = "#" . $hospitalId . "#";
|
|
|
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_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();
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
+ dump($e->getMessage());
|
|
|
Db::rollBack();
|
|
|
- throw new Exception('数据写入失败');
|
|
|
+ throw new \Exception('数据写入失败');
|
|
|
}
|
|
|
return $primary_key ? $model->$primary_key : null;
|
|
|
}
|
|
@@ -95,22 +102,22 @@ class DeptController extends Curd
|
|
|
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_pid != 0) {
|
|
|
+// $superior = $this->model->getByPrimaryKey($model->dept_pid);
|
|
|
+// $model->dept_path = $superior->dept_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_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'])]);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
Db::commit();
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollBack();
|
|
@@ -156,9 +163,12 @@ class DeptController extends Curd
|
|
|
'dept_pid' => $item->dept_pid,
|
|
|
'dept_name' => $item->dept_name,
|
|
|
'dept_type' => $item->dept_type,
|
|
|
- 'dept_sort' => $item->dept_sort,
|
|
|
- 'dept_addTime' => date("Y-m-d H:i:s", strtotime($item->dept_addTime)),
|
|
|
- 'dept_updateTime' => date("Y-m-d H:i:s", strtotime($item->dept_updateTime))
|
|
|
+ 'dept_telephone' => $item->dept_telephone,
|
|
|
+ 'dept_city_str' => $item->dept_city,
|
|
|
+ 'dept_city' => !empty($item->dept_city) ? explode(',', $item->dept_city) : '',
|
|
|
+ 'dept_address' => $item->dept_address,
|
|
|
+ 'dept_remark' => $item->dept_remark,
|
|
|
+ 'dept_addTime' => date("Y-m-d H:i:s", strtotime($item->dept_addtimes)),
|
|
|
];
|
|
|
}
|
|
|
$tree = new Tree($format_items);
|