check($param)) { throw new ApiException($validate->getError(), -1); } $adminOrgModel = new AdminOrg(); $has = $adminOrgModel->checkUnique([ 'name' => $param['name'] ]); if (!empty($has)) { throw new ApiException('组织名已经存在', -1); } if ($param['pid'] == 0) { $param['level'] = 1; } else { $parentInfo = $adminOrgModel->getInfoByWhere([ 'id' => $param['pid'] ], ['level']); $param['level'] = $parentInfo['level'] + 1; } $param['id'] = time(); $param['create_time'] = now(); $param['update_time'] = now(); $param['costsystem_deptcode'] = $param['deptcode'] = 'WL' . date('YmdHis'); $param['history_data_deadline'] = date('Y-m-d', strtotime('yesterday')); $adminOrgModel->insertOne($param); return dataReturn(0, '添加成功'); } public function editOrg($param) { if (isset($param['file'])) { unset($param['file']); } // 检验完整性 $validate = new OrgValidate(); if (!$validate->check($param)) { throw new ApiException($validate->getError(), -1); } $adminOrgModel = new AdminOrg(); $where[] = ['id', '<>', $param['id']]; $where[] = ['name', '=', $param['name']]; $has = $adminOrgModel->checkUnique($where); if (!empty($has)) { throw new ApiException('组织名已经存在', -1); } dump($param); $adminOrgModel->updateById($param, $param['id']); return dataReturn(0, '修改成功'); } }