user = session("user"); } public function findCommonFileType() { $param = $this->request->param(); $order = $param["order"]; $project = $param["project"]; $type = $param["type"]; $checkState = $param["checkState"]; if ($checkState == 0) { $where[] = ["step", "=", 1]; } $where[] = ["project", "=", $project]; $where[] = ["type", "=", $type]; return json(["rows" => Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()]); } public function listTalentFile() { $param = $this->request->param(); $mainId = $param["mainId"]; $typeId = $param["fileTypeId"]; $where = [["mainId", "=", $mainId], ["typeId", "=", $typeId]]; $list = Db::table("new_talent_file")->where($where)->select()->toArray(); foreach ($list as $key => $item) { $list[$key]["url"] = "/storage/" . $item["url"]; //获取系统配置无效,暂时这样 } return json($list); } public function addTalentFile() { $backName = $this->request->param("backName"); $fileId = $this->request->param("fileId"); $mainId = $this->request->param("mainId"); $fileTypeId = $this->request->param("fileTypeId"); $index = $this->request->param("index"); $type = $this->request->param("type"); $upload = new \app\common\api\UploadApi(); $file = $this->request->file("fileUrl"); $url = $upload->uploadOne($file, "talent_files"); if ($fileId) { if (!$this->chkIsFileOwner($mainId, $type)) return json(["msg" => "删除失败"]); $old = Db::table("new_talent_file")->findOrEmpty($fileId); $old_filepath = "storage/" . $old["url"]; if (file_exists($old_filepath)) unlink($old_filepath); $data["id"] = $fileId; } $data["mainId"] = $mainId; $data["type"] = $type; $data["typeId"] = $fileTypeId; $data["orignName"] = $file->getOriginalName(); $data["url"] = $url; $data["sn"] = $index; $data["createTime"] = time(); Db::table("new_talent_file")->save($data); $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "info" => $url]; echo sprintf("", $backName, json_encode($res)); } public function deleteFile() { $param = $this->request->param(); $where = [["id", "=", $param["id"]]]; $file = Db::table("new_talent_file")->where($where)->findOrEmpty(); if ($this->chkIsFileOwner($file["mainId"], $file["type"])) { $filepath = "storage/" . $file["url"]; if (file_exists($filepath)) { unlink($filepath); } Db::table("new_talent_file")->delete($file["id"]); return json(["code" => 200, "msg" => "删除成功"]); } return json(["msg" => "不能删除"]); } private function chkIsFileOwner($mainId, $type) { switch ($type) { case 1: if ($this->user["usertype"] == 2) { $user_id = $this->user["uid"]; $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId); if ($user_id == $talent_info["enterprise_id"]) return true; } break; } return false; } }