|
@@ -13,215 +13,193 @@ use think\facade\Db;
|
|
|
class Hospital extends AdminController {
|
|
|
|
|
|
public function index() {
|
|
|
- return view("");
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["status", "<>", 3];
|
|
|
+ $medicalCommunities = Db::table("nhc_medical_community")->where($where)->order("num asc")->select()->toArray();
|
|
|
+ return view("", ["medicalCommunities" => $medicalCommunities]);
|
|
|
}
|
|
|
|
|
|
public function list() {
|
|
|
$order = trim($this->request->param("order")) ?: "desc";
|
|
|
- $offset = trim($this->request->param("offset")) ?: 0;
|
|
|
- $limit = trim($this->request->param("limit")) ?: 10;
|
|
|
- $type = trim($this->request->param("type"));
|
|
|
+ //$offset = trim($this->request->param("offset")) ?: 0;
|
|
|
+ //$limit = trim($this->request->param("limit")) ?: 10;
|
|
|
$name = trim($this->request->param("name"));
|
|
|
- $must = trim($this->request->param("must"));
|
|
|
- $active = trim($this->request->param("active"));
|
|
|
+ $communityId = trim($this->request->param("communityId"));
|
|
|
|
|
|
$where = [];
|
|
|
-
|
|
|
+ $where[] = ["h.status", "<>", 3];
|
|
|
if ($name) {
|
|
|
- $where[] = ["name", "like", "%" . $name . "%"];
|
|
|
- }
|
|
|
- if ($type) {
|
|
|
- $where[] = ["type", "=", $type];
|
|
|
+ $where[] = ["h.name", "like", "%" . $name . "%"];
|
|
|
}
|
|
|
- if ($must) {
|
|
|
- $where[] = ["must", "=", $must];
|
|
|
- }
|
|
|
- if ($active) {
|
|
|
- $where[] = ["active", "=", $active];
|
|
|
+ if ($communityId) {
|
|
|
+ $where[] = ["h.communityId", "=", $communityId];
|
|
|
}
|
|
|
|
|
|
+ //$count = Db::table("nhc_hospital")->alias("h")->leftJoin("nhc_medical_community mc", "mc.id=h.communityId")->where($where)->count();
|
|
|
+ $rows = Db::table("nhc_hospital")->alias("h")->leftJoin("nhc_medical_community mc", "mc.id=h.communityId")
|
|
|
+ ->field("h.*,mc.name as medicalCommunityName")
|
|
|
+ ->where($where)->order("mc.num asc,h.num asc,h.createTime " . $order)
|
|
|
+ ->select()->toArray();
|
|
|
|
|
|
- $count = \app\admin\model\CurrencyFiletype::where($where)->count();
|
|
|
- if ($count > 0) {
|
|
|
- $rows = \app\admin\model\CurrencyFiletype::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
|
|
|
- $typeName = DictApi::selectByParentCode("common_declareType");
|
|
|
- foreach ($rows as $k => &$v) {
|
|
|
- $v['typeName'] = $typeName[$v['type']];
|
|
|
- $v['templateUrl'] = getStoragePath($v['templateUrl']);
|
|
|
- }
|
|
|
- } else {
|
|
|
- $rows = [];
|
|
|
- }
|
|
|
+ return $rows;
|
|
|
+ }
|
|
|
|
|
|
- return ["total" => $count, "rows" => $rows];
|
|
|
+ public function add() {
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["status", "<>", 3];
|
|
|
+ $medicalCommunities = Db::table("nhc_medical_community")->where($where)->order("num asc")->select()->toArray();
|
|
|
+ return view("edit", ["medicalCommunities" => $medicalCommunities]);
|
|
|
}
|
|
|
|
|
|
- public function currencyFiletype_add() {
|
|
|
- return view("");
|
|
|
+ public function edit() {
|
|
|
+ $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
|
|
|
+ $info = Db::table("nhc_hospital")->where("id", $id)->find();
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["status", "<>", 3];
|
|
|
+ $medicalCommunities = Db::table("nhc_medical_community")->where($where)->order("num asc")->select()->toArray();
|
|
|
+ return view("edit", ["row" => $info, "medicalCommunities" => $medicalCommunities]);
|
|
|
}
|
|
|
|
|
|
- public function add() {
|
|
|
+ public function upsert() {
|
|
|
$response_obj = new \StdClass();
|
|
|
- $name = trim($this->request['name']);
|
|
|
- if (\StrUtil::isEmpOrNull($name)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '附件名称不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $type = trim($this->request['type']);
|
|
|
- if (\StrUtil::isEmpOrNull($type)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '申报类别不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $api = trim($this->request['api']);
|
|
|
- if (\StrUtil::isEmpOrNull($api)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = 'api不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $must = trim($this->request['must']);
|
|
|
- if (\StrUtil::isEmpOrNull($must)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '是否必传不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $active = trim($this->request['active']);
|
|
|
- if (\StrUtil::isEmpOrNull($active)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '是否有效不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $sn = trim($this->request['sn']);
|
|
|
- if (\StrUtil::isEmpOrNull($sn)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '排序不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ($this->request['templateFile']) {
|
|
|
- $uploadapi = new UploadApi();
|
|
|
- $file_check_res = $uploadapi->uploadOne($this->request->file('templateFile'), 'system');
|
|
|
- if ($file_check_res->code == 500) {
|
|
|
- return \StrUtil::back($file_check_res, "CurrencyFiletypeInfoDlg.callBack");
|
|
|
+ $response_obj->code = 500;
|
|
|
+ $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
|
|
|
+ $where = [];
|
|
|
+ if ($id) {
|
|
|
+ $info = Db::table("nhc_hospital")->where("id", $id)->find();
|
|
|
+ if (!$info) {
|
|
|
+ $response_obj->msg = '找不到记录';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
}
|
|
|
- $templateUrl = $file_check_res->filepath;
|
|
|
- } else {
|
|
|
- $templateUrl = "";
|
|
|
+ $where[] = ["id", "<>", $id];
|
|
|
}
|
|
|
|
|
|
+ $name = trim($this->request['name']);
|
|
|
+ if (\StrUtil::isEmpOrNull($name)) {
|
|
|
+ $response_obj->msg = '医院名称不能为空';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+ $where[] = ["name", "=", $name];
|
|
|
+ $repeat = Db::table("nhc_hospital")->where($where)->find();
|
|
|
+
|
|
|
+ if ($repeat) {
|
|
|
+ $response_obj->msg = '医院名称已经被使用';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+ $communityId = trim($this->request['communityId']);
|
|
|
+ if (!$communityId) {
|
|
|
+ $response_obj->msg = '请选择医院所属医共体';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+ $isGeneral = trim($this->request['isGeneral']);
|
|
|
+ if (!$isGeneral) {
|
|
|
+ $response_obj->msg = '请选择是否总院(当前医共体)';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+
|
|
|
+ $num = trim($this->request['num']);
|
|
|
+ if (\StrUtil::isNotEmpAndNull($num) && !is_numeric($num)) {
|
|
|
+ $response_obj->msg = '序号只能是数字';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+ $status = trim($this->request['status']);
|
|
|
+ if (\StrUtil::isEmpOrNull($status)) {
|
|
|
+ $response_obj->msg = '启用状态不能为空';
|
|
|
+ return \StrUtil::back($response_obj, 'HospitalInfo.callBack');
|
|
|
+ }
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ if ($isGeneral == 1) {
|
|
|
+ //各医共体下最多仅有一家总院,检查是否有其它设置,如有,变更为2,当前设为1
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["communityId", "=", $communityId];
|
|
|
+ $where[] = ["isGeneral", "=", 1];
|
|
|
+ if ($id) {
|
|
|
+ $where[] = ["id", "<>", $id];
|
|
|
+ }
|
|
|
+ $updOther["isGeneral"] = 2;
|
|
|
+ $updOther["updateTime"] = date("Y-m-d H:i:s");
|
|
|
+ $updOther["updateUser"] = $this->user["uid"];
|
|
|
+ Db::table("nhc_hospital")->where($where)->save($updOther);
|
|
|
+ }
|
|
|
|
|
|
- $data = [
|
|
|
- 'id' => getStringId(),
|
|
|
- 'type' => $type,
|
|
|
- 'name' => $name,
|
|
|
- 'api' => $api,
|
|
|
- 'must' => $must,
|
|
|
- 'active' => $active,
|
|
|
- 'sn' => $sn,
|
|
|
- 'checkCompany' => '1158293574504660993',
|
|
|
- 'description' => $this->request['description'],
|
|
|
- 'createTime' => date("Y-m-d H:i:s"),
|
|
|
- 'createUser' => session('user')['uid'],
|
|
|
- 'templateUrl' => $templateUrl
|
|
|
- ];
|
|
|
-
|
|
|
- \app\admin\model\CurrencyFiletype::create($data);
|
|
|
- $response_obj->code = 200;
|
|
|
- $response_obj->msg = '添加成功';
|
|
|
- return \StrUtil::back($response_obj, "CurrencyFiletypeInfoDlg.callBack");
|
|
|
- }
|
|
|
-
|
|
|
- public function currencyFiletype_update() {
|
|
|
- $id = trim($this->request->get('id'));
|
|
|
- if (\StrUtil::isEmpOrNull($id)) {
|
|
|
- return json(['msg' => 'id不能为空']);
|
|
|
+ $data["name"] = $name;
|
|
|
+ $data["communityId"] = $communityId;
|
|
|
+ $data["isGeneral"] = $isGeneral;
|
|
|
+ $data["status"] = $status;
|
|
|
+ $data["num"] = $num;
|
|
|
+ $data["description"] = \StrUtil::getRequestDecodeParam($this->request, "description");
|
|
|
+ if ($id) {
|
|
|
+ $data["id"] = $id;
|
|
|
+ $data["updateTime"] = date("Y-m-d H:i:s");
|
|
|
+ $data["updateUser"] = $this->user['uid'];
|
|
|
+ Db::table("nhc_hospital")->save($data);
|
|
|
+ } else {
|
|
|
+ $data["createTime"] = date("Y-m-d H:i:s");
|
|
|
+ $data["createUser"] = $this->user['uid'];
|
|
|
+ Db::table("nhc_hospital")->insert($data);
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ $response_obj->code = 200;
|
|
|
+ $response_obj->msg = '修改成功';
|
|
|
+ return \StrUtil::back($response_obj, "HospitalInfo.callBack");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $response_obj->msg = $e->getMessage();
|
|
|
+ return \StrUtil::back($response_obj, "HospitalInfo.callBack");
|
|
|
}
|
|
|
- $cft = \app\admin\model\CurrencyFiletype::findOrEmpty($id);
|
|
|
- return view("", ['item' => $cft]);
|
|
|
}
|
|
|
|
|
|
- public function update() {
|
|
|
- $response_obj = new \StdClass();
|
|
|
+ public function setGeneral() {
|
|
|
$id = \StrUtil::getRequestDecodeParam($this->request, 'id');
|
|
|
if (\StrUtil::isEmpOrNull($id)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = 'id不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft = \app\admin\model\CurrencyFiletype::findOrEmpty($id);
|
|
|
- if (!$cft) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '找不到记录';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
-
|
|
|
- $cft->name = $name = trim($this->request['name']);
|
|
|
- if (\StrUtil::isEmpOrNull($name)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '附件名称不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft->type = $type = trim($this->request['type']);
|
|
|
- if (\StrUtil::isEmpOrNull($type)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '申报类别不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft->api = $api = trim($this->request['api']);
|
|
|
- if (\StrUtil::isEmpOrNull($api)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = 'api不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft->must = $must = trim($this->request['must']);
|
|
|
- if (\StrUtil::isEmpOrNull($must)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '是否必传不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft->active = $active = trim($this->request['active']);
|
|
|
- if (\StrUtil::isEmpOrNull($active)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '是否有效不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
- }
|
|
|
- $cft->sn = $sn = trim($this->request['sn']);
|
|
|
- if (\StrUtil::isEmpOrNull($sn)) {
|
|
|
- $response_obj->code = 500;
|
|
|
- $response_obj->msg = '排序不能为空';
|
|
|
- return \StrUtil::back($response_obj, 'CurrencyFiletypeInfoDlg.callBack');
|
|
|
+ return json(['code' => 500, 'msg' => '缺少参数']);
|
|
|
}
|
|
|
- $files = $this->request->file();
|
|
|
|
|
|
-
|
|
|
- if (array_key_exists('templateFile', $files)) {
|
|
|
- $uploadapi = new UploadApi();
|
|
|
- $file_check_res = $uploadapi->uploadOne($this->request->file('templateFile'), 'system');
|
|
|
- if ($file_check_res->code == 500) {
|
|
|
- return \StrUtil::back($file_check_res, "CurrencyFiletypeInfoDlg.callBack");
|
|
|
- }
|
|
|
- $cft->templateUrl = $file_check_res->filepath;
|
|
|
- } else {
|
|
|
- $cft->templateUrl = "";
|
|
|
+ $info = Db::table("nhc_hospital")->where("id", $id)->find();
|
|
|
+
|
|
|
+ if (!$info) {
|
|
|
+ return json(['code' => 500, 'msg' => '没有查询到对应医院信息']);
|
|
|
+ }
|
|
|
+ $communityId = $info["communityId"];
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ //各医共体下最多仅有一家总院,检查是否有其它设置,如有,变更为2,当前设为1
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["communityId", "=", $communityId];
|
|
|
+ $where[] = ["isGeneral", "=", 1];
|
|
|
+ $where[] = ["id", "<>", $id];
|
|
|
+ $updOther["isGeneral"] = 2;
|
|
|
+ $updOther["updateTime"] = date("Y-m-d H:i:s");
|
|
|
+ $updOther["updateUser"] = $this->user["uid"];
|
|
|
+ Db::table("nhc_hospital")->where($where)->save($updOther);
|
|
|
+
|
|
|
+ $updOther["id"] = $id;
|
|
|
+ $updOther["isGeneral"] = 1;
|
|
|
+ Db::table("nhc_hospital")->save($updOther);
|
|
|
+ Db::commit();
|
|
|
+ return json(['code' => 200, 'msg' => "设置成功"]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return json(['code' => 500, 'msg' => $e->getMessage()]);
|
|
|
}
|
|
|
-
|
|
|
- $cft->updateTime = date("Y-m-d H:i:s");
|
|
|
- $cft->updateUser = session('user')['uid'];
|
|
|
- $cft->save();
|
|
|
- $response_obj->code = 200;
|
|
|
- $response_obj->msg = '修改成功';
|
|
|
- return \StrUtil::back($response_obj, "CurrencyFiletypeInfoDlg.callBack");
|
|
|
}
|
|
|
|
|
|
public function delete() {
|
|
|
- $id = \StrUtil::getRequestDecodeParam($this->request, 'currencyFiletypeId');
|
|
|
+ $id = \StrUtil::getRequestDecodeParam($this->request, 'id');
|
|
|
if (\StrUtil::isEmpOrNull($id)) {
|
|
|
return json(['code' => 500, 'msg' => '缺少参数']);
|
|
|
}
|
|
|
- \app\admin\model\CurrencyFiletype::destroy($id);
|
|
|
- return json(['code' => 200, 'msg' => '删除成功']);
|
|
|
+ $data["id"] = $id;
|
|
|
+ $data["status"] = 3;
|
|
|
+ $data["updateTime"] = date("Y-m-d H:i:s");
|
|
|
+ $data["updateUser"] = $this->user["uid"];
|
|
|
+ try {
|
|
|
+ Db::table("nhc_hospital")->save($data);
|
|
|
+ return json(['code' => 200, 'msg' => "删除成功"]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json(['code' => 500, 'msg' => $e->getMessage()]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|