| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 | 
							- <?php
 
- namespace app\common\controller;
 
- use app\BaseController;
 
- use app\common\middleware\Auth;
 
- use think\facade\Db;
 
- use app\enterprise\api\TalentApi;
 
- use app\common\api\TalentLogApi;
 
- use app\common\api\DictApi;
 
- use app\common\model\CurrentcyFileType;
 
- use app\common\model\TalentCommonFile;
 
- use app\common\api\UploadApi;
 
- use app\common\api\TalentConditionApi;
 
- use app\common\api\CompanyApi;
 
- /**
 
-  * 需要权限的公共方法放这
 
-  * Description of Tool
 
-  *
 
-  * @author sgq
 
-  */
 
- class Api extends BaseController {
 
-     protected $middleware = [Auth::class];
 
-     protected $user;
 
-     public function __construct(\think\App $app) {
 
-         parent::__construct($app);
 
-         $this->user = session("user");
 
-     }
 
-     public function findIdentifyConditionByLevel() {
 
-         $params = $this->request->param();
 
-         $id = $params["id"];
 
-         if ($this->user["usertype"] == 2) {
 
-             $type = $this->user["type"];
 
-         } else {
 
-             $talentInfo = TalentApi::getOne($id);
 
-             $enterprise = \app\common\model\Enterprise::findOrEmpty($talentInfo["enterprise_id"]);
 
-             $type = $enterprise["type"];
 
-         }
 
-         $list = TalentConditionApi::getList($params["level"], $type);
 
-         return json($list, 200);
 
-     }
 
-     public function getTalentCondtionUploadFile() {
 
-         $param = $this->request->param();
 
-         $id = $param["mainId"];
 
-         $order = $param["order"];
 
-         $project = $param["project"];
 
-         $type = $param["type"];
 
-         $talent_condition = $param["talent_condition"];
 
-         $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
 
-         if (!$condition_info["bindFileTypes"])
 
-             return json(["rows" => null]);
 
-         $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
 
-         $rows = Db::table("new_common_filetype")->where($whr)->order("sn " . $order)->select()->toArray();
 
-         if ($id) {
 
-             foreach ($rows as $key => $row) {
 
-                 $where = [];
 
-                 $where[] = ["mainId", "=", $id];
 
-                 $where[] = ["typeId", "=", $row["id"]];
 
-                 $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
 
-                 foreach ($files as &$file) {
 
-                     $file["url"] = "/storage/" . $file["url"];
 
-                 }
 
-                 $rows[$key]["files"] = $files;
 
-             }
 
-         }
 
-         return json(["rows" => $rows]);
 
-     }
 
-     public function getCheckLog() {
 
-         $params = $this->request->param();
 
-         $mainId = $params["mainId"];
 
-         $type = $params["type"];
 
-         $talentInfo = TalentApi::getOne($mainId);
 
-         $condition = TalentConditionApi::getOne($talentInfo["talent_condition"]);
 
-         $needDeptVerify = false;
 
-         if ($condition["companyIds"])
 
-             $needDeptVerify = true;
 
-         $list = TalentLogApi::getList($type, $mainId);
 
-         $new_list = [];
 
-         foreach ($list as $item) {
 
-             if($item['type'] == 10){//姑且按type还区分
 
-                 switch ($item['state']){
 
-                     case -2:
 
-                         $new_item["stateName"] = "<span class='label label-success'>待提交</span>";
 
-                         break;
 
-                     case -1:
 
-                         $new_item["stateName"] = "<span class='label label-success'>审核不通过</span>";
 
-                         break;
 
-                     case 1:
 
-                         $new_item["stateName"] = "<span class='label label-success'>待审核</span>";
 
-                         break;
 
-                     case 2:
 
-                         $new_item["stateName"] = "<span class='label label-danger'>审核驳回</span>";
 
-                         break;
 
-                     case 3:
 
-                         $new_item["stateName"] = "<span class='label label-primary'>审核通过</span>";
 
-                         break;
 
-                     case 4:
 
-                         $new_item["stateName"] = "<span class='label label-warm'>上级驳回</span>";
 
-                         break;
 
-                     case 8:
 
-                         $new_item["stateName"] = "<span class='label label-primary'>提交审核</span>";
 
-                         break;
 
-                     case 9:
 
-                         $new_item["stateName"] = "<span class='label label-primary'>重新提交</span>";
 
-                         break;
 
-                     case 10:
 
-                         $new_item["stateName"] = "<span class='label label-default'>冻结</span>";
 
-                         break;
 
-                     case 11:
 
-                         $new_item["stateName"] = "<span class='label label-primary'>撤销审核</span>";
 
-                         break;
 
-                 }
 
-             }else{
 
-                 $new_item["stepName"] = DictApi::getTalentInfoStepByState($item["new_state"]);
 
-                 if ($item["state"] == 13) {
 
-                     $new_item["stateName"] = '<span class="label label-success">审核不通过</span>';
 
-                 } else if (in_array($item["state"], [3, 7, 9, 11])) {
 
-                     $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
 
-                 } else if (in_array($item["state"], [4, 8, 10, 12])) {
 
-                     $new_item["stateName"] = '<span class="label label-danger">审核驳回</span>';
 
-                 } else {
 
-                     $new_item["stateName"] = '<span class="label label-success">待审核</span>';
 
-                 }
 
-             }
 
-             if ($item["step"] == 3) {
 
-                 $company = CompanyApi::getOne($item["companyId"]);
 
-                 if ($item["active"] == 0) {
 
-                     $new_item["stateChange"] = str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["last_state"], $item["step"], $needDeptVerify));
 
-                 } else {
 
-                     $new_item["stateChange"] = sprintf("%s -> %s", str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["last_state"], $item["step"], $needDeptVerify)), DictApi::getTalentInfoStateName($item["new_state"], $item["step"], $needDeptVerify));
 
-                 }
 
-             } else {
 
-                 if ($item["last_state"] && $item["new_state"]) {
 
-                     $new_item["stateChange"] = sprintf("%s -> %s", DictApi::getTalentInfoStateName($item["last_state"], $item["step"], $needDeptVerify), DictApi::getTalentInfoStateName($item["new_state"], $item["step"], $needDeptVerify));
 
-                 } else {
 
-                     $new_item["stateChange"] = $item['stateChange'];
 
-                 }
 
-             }
 
-             $new_item["description"] = $item["description"];
 
-             $new_item["createUser"] = $item["updateUser"] ?: $item["createUser"];
 
-             $new_item["createTime"] = $item["updateTime"] ?: $item["createTime"];
 
-             $new_list[] = $new_item;
 
-         }
 
-         return json(["rows" => $new_list]);
 
-     }
 
-     public function findCommonFileType() {
 
-         $param = $this->request->param();
 
-         $id = $param["mainId"];
 
-         $order = $param["order"];
 
-         $project = $param["project"];
 
-         $type = $param["type"];
 
-         $checkState = $param["checkState"];
 
-         $talent_condition = $param["talent_condition"];
 
-         if (in_array($checkState, [0, 1, 2])) {
 
-             $where[] = ["step", "=", 1]; //只查找人才第一步所需文件
 
-         } else {
 
-             $where[] = ["isConditionFile", "=", 0]; //排除人才条件上传文件
 
-         }
 
-         $where[] = ["project", "=", $project];
 
-         $where[] = ["type", "=", $type];
 
-         if ($talent_condition) {
 
-             $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
 
-             if ($condition_info["bindFileTypes"]) {
 
-                 $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
 
-             }
 
-         }
 
-         if ($whr) {
 
-             $rows = Db::table("new_common_filetype")->whereOr([$where, $whr])->order("sn " . $order)->select()->toArray();
 
-         } else {
 
-             $rows = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
 
-         }
 
-         if ($id) {
 
-             foreach ($rows as $key => $row) {
 
-                 $where = [];
 
-                 $where[] = ["mainId", "=", $id];
 
-                 $where[] = ["typeId", "=", $row["id"]];
 
-                 $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
 
-                 foreach ($files as &$file) {
 
-                     $file["url"] = "/storage/" . $file["url"];
 
-                 }
 
-                 $rows[$key]["files"] = $files;
 
-             }
 
-         }
 
-         return json(["rows" => $rows]);
 
-     }
 
-     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");
 
-         if (!TalentApi::checkIsEditable($mainId)) {
 
-             $res = ["msg" => "当前状态不能修改附件", "obj" => $index];
 
-             echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
 
-             exit();
 
-         }
 
-         $mime = $file->getMime();
 
-         switch ($mime) {
 
-             case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"://xlsx
 
-             case "application/pdf"://pdf
 
-             case "application/vnd.ms-excel"://xls
 
-                 $filestd = $upload->uploadOne($file, "file", "talent_files");
 
-                 break;
 
-             case "image/jpg":
 
-             case "image/jpeg":
 
-             case "image/png":
 
-             case "image/gif":
 
-                 $filestd = $upload->uploadOne($file, "image", "talent_files");
 
-                 break;
 
-             default:
 
-                 $res = ["msg" => "不支持的附件类型", "obj" => $index];
 
-                 echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
 
-                 exit();
 
-                 break;
 
-         }
 
-         $change = false;
 
-         if ($fileId) {
 
-             if (!$this->chkIsFileOwner($mainId, $type)) {
 
-                 $res = ["msg" => "删除失败", "obj" => $index];
 
-                 echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
 
-                 exit();
 
-             }
 
-             $old = Db::table("new_talent_file")->findOrEmpty($fileId);
 
-             $old_filepath = "storage/" . $old["url"];
 
-             if (file_exists($old_filepath))
 
-                 unlink($old_filepath);
 
-             $data["id"] = $fileId;
 
-             $change = true;
 
-         }
 
-         $data["mainId"] = $mainId;
 
-         $data["type"] = $type;
 
-         $data["typeId"] = $fileTypeId;
 
-         $data["orignName"] = $file->getOriginalName();
 
-         $data["url"] = $filestd->filepath;
 
-         $data["sn"] = $index;
 
-         $data["createTime"] = time();
 
-         if ($fileId) {
 
-             Db::table("new_talent_file")->save($data);
 
-         } else {
 
-             $fileId = Db::table("new_talent_file")->insertGetId($data);
 
-         }
 
-         TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
 
-         $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "info" => "/storage/" . $filestd->filepath, "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
 
-         echo sprintf("<script>parent.%s(%s);</script>", $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 (!TalentApi::checkIsEditable($file["mainId"]))
 
-             return json(["msg" => "当前状态不能删除"]);
 
-         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"]);
 
-             TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
 
-             return json(["code" => 200, "msg" => "删除成功"]);
 
-         }
 
-         return json(["msg" => "不能删除"]);
 
-     }
 
-     /**
 
-      * 下载文件
 
-      */
 
-     public function downloadFile() {
 
-         $param = $this->request->param();
 
-         $type = $param["type"];
 
-         $id = $param["id"];
 
-         $where = [];
 
-         $where[] = ["id", "=", $id];
 
-         $where[] = ["type", "=", $type];
 
-         $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
 
-         $filename = $fileinfo["orignName"];
 
-         $filepath = "storage/" . $fileinfo["url"];     // 下载文件名
 
-         if (!file_exists($filepath)) {
 
-             header('HTTP/1.1 404 NOT FOUND');
 
-         } else {
 
-             $file = fopen($filepath, "rb");
 
-             Header("Content-type: application/octet-stream");
 
-             Header("Accept-Ranges: bytes");
 
-             Header("Accept-Length: " . filesize($filepath));
 
-             Header("Content-Disposition: attachment; filename=" . $filename);
 
-             echo fread($file, filesize($filepath));
 
-             fclose($file);
 
-             exit();
 
-         }
 
-     }
 
-     /**
 
-      * 打包下载人才申请附件
 
-      */
 
-     public function downloadZip() {
 
-         $param = $this->request->param();
 
-         $type = $param["type"];
 
-         $id = $param["id"];
 
-         $where = [];
 
-         $where[] = ["mainId", "=", $id];
 
-         $where[] = ["type", "=", $type];
 
-         $files = Db::table("new_talent_file")->where($where)->select()->toArray();
 
-         if (!$files)
 
-             die("没有附件不能打包下载");
 
-         $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
 
-         $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
 
-         $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
 
-         $tmp_path = "storage/temp/";
 
-         $tmp_file_path = $tmp_path . $zip_filename;
 
-         if (!file_exists($tmp_path)) {
 
-             mkdir($tmp_path);
 
-         }
 
-         $zip = new \ZipArchive();
 
-         if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
 
-             header('HTTP/1.1 404 NOT FOUND');
 
-         }
 
-         foreach ($files as $file) {
 
-             $filepath = "storage/" . $file["url"];
 
-             $filename = $file["orignName"];
 
-             $zip->addFile($filepath, $filename);
 
-         }
 
-         $zip->close();
 
-         if (file_exists($tmp_file_path)) {
 
-             header("Cache-Control: public");
 
-             header("Content-Description: File Transfer");
 
-             header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
 
-             header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
 
-             header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
 
-             header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
 
-             @readfile($tmp_file_path);
 
-         }
 
-         //删除临时文件
 
-         @unlink($tmp_file_path);
 
-     }
 
-     private function chkIsFileOwner($mainId, $type) {
 
-         if (!$mainId)
 
-             return true;
 
-         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;
 
-     }
 
-     public function getCompanyKvs() {
 
-         $companys = \app\common\model\Company::field("name,id")->select();
 
-         return json($companys);
 
-     }
 
-     /**
 
-      * 通过人才类别查找人才认定第二步骤支持的所有文件类型
 
-      * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
 
-      */
 
-     public function getConditionFileTypesByType() {
 
-         $params = $this->request->param();
 
-         $type = $params["type"]; //人才类型不默认,需要传
 
-         $declare_type = $params["project"] ?: 1; //默认人才认定
 
-         $active = $params["active"] ?: 1; //默认查找启用的附件
 
-         $where[] = ["type", "=", $type];
 
-         $where[] = ["project", "=", $declare_type];
 
-         $where[] = ["active", "=", $active];
 
-         $where[] = ["isConditionFile", "=", 1];
 
-         $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
 
-         return json($list);
 
-     }
 
-     public function listCurrencyFileType() {
 
-         $where = [
 
-             'type' => $this->request['type'],
 
-             'active' => 1
 
-         ];
 
-         $rows = CurrentcyFileType::where($where)->select();
 
-         return json(["rows" => $rows, 'total' => count($rows)]);
 
-     }
 
-     public function listTalentCommonFile() {
 
-         $where = [];
 
-         if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
 
-             $where[] = ['mainId', '=', $this->request['mainId']];
 
-         }
 
-         if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
 
-             $where[] = ['typeId', '=', $this->request['typeId']];
 
-         }
 
-         $res = TalentCommonFile::where($where)->order('sn')->select();
 
-         if ($res) {
 
-             foreach ($res as $k => &$v) {
 
-                 $v['url'] = "/storage/" . $v['url'];
 
-             }
 
-         }
 
-         return json($res);
 
-     }
 
-     public function addTalentCommonFile() {
 
-         $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
 
-         $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
 
-         $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
 
-         $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
 
-         $index = \StrUtil::getRequestDecodeParam($this->request, "index");
 
-         if ($backName == "EpChangeEdit.callBack") {
 
-             $type = 1;
 
-             $error = "文件格式不正确,只能上传图片";
 
-         } else {
 
-             $type = 4;
 
-             $error = "文件格式不正确,只能上传pdf和图片";
 
-         }
 
-         $uploadapi = new UploadApi();
 
-         $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
 
-         if ($file_check_res->code == 500) {
 
-             return \StrUtil::back($file_check_res, "Register.epCallBack");
 
-         }
 
-         $file_data = [
 
-             'id' => getStringId(),
 
-             'mainId' => $mainId,
 
-             'typeId' => $typeId,
 
-             'orignName' => $this->request->file('fileUrl')->getOriginalName(),
 
-             'url' => $file_check_res->filepath
 
-         ];
 
-         if (\StrUtil::isEmpOrNull($id)) {
 
-             $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
 
-             if ($tc) {
 
-                 $file_data['sn'] = $tc['sn'] + 1;
 
-             } else {
 
-                 $file_data['sn'] = 1;
 
-             }
 
-             $file_data['createTime'] = date("Y-m-d H:i:s");
 
-             TalentCommonFile::create($file_data);
 
-             $response_object = new \StdClass();
 
-             $response_object->code = 200;
 
-             $response_object->msg = "附件上传成功!";
 
-             $response_object->obj = $index;
 
-             return \StrUtil::back($response_object, $backName);
 
-         } else {
 
-             $tf = TalentCommonFile::findOrEmpty($id);
 
-             $tf->originalName = $file_data['orignName'];
 
-             $tf->updateTime = date("Y-m-d H:i:s");
 
-             $tf->url = $file_check_res->filepath;
 
-             $tf->save();
 
-             $response_object = new \StdClass();
 
-             $response_object->code = 200;
 
-             $response_object->msg = "附件修改成功!";
 
-             $response_object->obj = $index;
 
-             return \StrUtil::back($response_object, $backName);
 
-         }
 
-     }
 
- }
 
 
  |