Api.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\api\EnterpriseApi;
  5. use app\common\middleware\Auth;
  6. use app\common\model\TalentChecklog;
  7. use app\common\validate\Enterprise;
  8. use think\exception\ValidateException;
  9. use think\facade\Db;
  10. use app\enterprise\api\TalentApi;
  11. use app\common\api\TalentLogApi;
  12. use app\common\api\DictApi;
  13. use app\common\model\CurrentcyFileType;
  14. use app\common\model\TalentCommonFile;
  15. use app\common\api\UploadApi;
  16. use app\common\api\TalentConditionApi;
  17. use app\common\api\CompanyApi;
  18. use app\common\api\TalentState;
  19. /**
  20. * 需要权限的公共方法放这
  21. * Description of Tool
  22. *
  23. * @author sgq
  24. */
  25. class Api extends BaseController {
  26. protected $middleware = [Auth::class];
  27. protected $user;
  28. public function __construct(\think\App $app) {
  29. parent::__construct($app);
  30. $this->user = session("user");
  31. }
  32. public function findIdentifyConditionByLevel() {
  33. $params = $this->request->param();
  34. $id = $params["id"];
  35. if ($this->user["usertype"] == 2) {
  36. $type = $this->user["type"];
  37. } else {
  38. $talentInfo = TalentApi::getOne($id);
  39. $enterprise = \app\common\model\Enterprise::findOrEmpty($talentInfo["enterprise_id"]);
  40. $type = $enterprise["type"];
  41. }
  42. $list = TalentConditionApi::getList($params["level"], $type, $params["cat"]);
  43. return json($list, 200);
  44. }
  45. public function getTalentCondtionUploadFile() {
  46. $param = $this->request->param();
  47. $id = $param["mainId"];
  48. $order = $param["order"];
  49. $project = $param["project"];
  50. $type = $param["type"];
  51. $talent_condition = $param["talent_condition"];
  52. $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
  53. if (!$condition_info["bindFileTypes"])
  54. return json(["rows" => null]);
  55. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  56. $whr[] = ["active", "=", 1];
  57. $whr[] = ["delete", "=", 0];
  58. $rows = Db::table("new_common_filetype")->where($whr)->order("sn " . $order)->select()->toArray();
  59. if ($id) {
  60. foreach ($rows as $key => $row) {
  61. $where = [];
  62. $where[] = ["mainId", "=", $id];
  63. $where[] = ["typeId", "=", $row["id"]];
  64. $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
  65. foreach ($files as &$file) {
  66. $file["ext"] = pathinfo($file["url"])["extension"];
  67. $file["url"] = getStoragePath($file["url"]);
  68. }
  69. $rows[$key]["files"] = $files;
  70. }
  71. }
  72. return json(["rows" => $rows, "info" => $condition_info]);
  73. }
  74. public function getCheckLog() {
  75. $params = $this->request->param();
  76. $mainId = $params["mainId"];
  77. $enterpriseId = $params["enterpriseId"];
  78. $type = $params["type"];
  79. /* $talentInfo = TalentApi::getOne($mainId);
  80. $condition = TalentConditionApi::getOne($talentInfo["talent_condition"]);
  81. $needDeptVerify = false;
  82. if ($condition["companyIds"] && $talentInfo["pass_dept_check"] != 1)
  83. $needDeptVerify = true; */
  84. $list = [];
  85. switch ($type) {
  86. case 1:
  87. case 20:
  88. $list = TalentLogApi::getList($type, $mainId);
  89. break;
  90. case 10:
  91. if ($enterpriseId) {
  92. $where[] = ["mainId", "=", $enterpriseId];
  93. $ids = \app\enterprise\model\EnterpriseRecord::where($where)->column("id");
  94. $ids[] = $enterpriseId;
  95. $where = [];
  96. $where[] = ["type", "=", $type];
  97. $where[] = ["active", "=", 1];
  98. $where[] = ["mainId", "in", $ids];
  99. $list = TalentChecklog::where($where)->order("createTime desc")->select();
  100. } else {
  101. $list = TalentLogApi::getList($type, $mainId);
  102. }
  103. break;
  104. }
  105. $new_list = [];
  106. foreach ($list as $key => $item) {
  107. switch ($item['type']) {
  108. case 20:
  109. $new_item["stepName"] = \app\common\state\IntegralState::getLogStepName($item["state"]);
  110. $new_item["stateName"] = \app\common\state\IntegralState::getLogStateName($item["state"]);
  111. break;
  112. case 10:
  113. if ($item["category"] == "enterprise_change") {
  114. switch ($item['step']) {
  115. case 100:
  116. $new_item["stepName"] = "<span class='label'>用户操作</span>";
  117. break;
  118. case 101:
  119. $new_item["stepName"] = "<span class='label label-primary'>审核</span>";
  120. break;
  121. case 102:
  122. $new_item["stepName"] = "<span class='label label-danger'>设置冻结</span>";
  123. break;
  124. case 103:
  125. $new_item["stepName"] = "<span class='label label-info'>重置密码</span>";
  126. break;
  127. }
  128. switch ($item['state']) {
  129. case 1:
  130. if ($item["stateChange"]) {
  131. $new_item["stateName"] = "<span class='label label-success'>待提交</span>";
  132. } else {
  133. $item['stateChange'] = "修改密码";
  134. }
  135. break;
  136. case 2:
  137. $new_item["stateName"] = "<span class='label label-success'>待审核</span>";
  138. break;
  139. case 3:
  140. $new_item["stateName"] = "<span class='label label-danger'>审核驳回</span>";
  141. break;
  142. case 4:
  143. $new_item["stateName"] = "<span class='label label-primary'>审核通过</span>";
  144. break;
  145. case 5:
  146. $new_item["stateName"] = "<span class='label label-warm'>重新提交</span>";
  147. break;
  148. case 6:
  149. $new_item["stateName"] = "<span class='label label-danger'>初审驳回</span>";
  150. break;
  151. case 7:
  152. $new_item["stateName"] = "<span class='label label-primary'>初审通过</span>";
  153. break;
  154. }
  155. $new_item["stateChange"] = $item['stateChange'];
  156. } else {
  157. switch ($item['step']) {
  158. case 100:
  159. $new_item["stepName"] = "<span class='label'>用户操作</span>";
  160. break;
  161. case 101:
  162. $new_item["stepName"] = "<span class='label label-primary'>注册审核</span>";
  163. break;
  164. case 102:
  165. $new_item["stepName"] = "<span class='label label-danger'>设置冻结</span>";
  166. break;
  167. case 103:
  168. $new_item["stepName"] = "<span class='label label-info'>重置密码</span>";
  169. break;
  170. }
  171. switch ($item['state']) {
  172. case 1:
  173. $new_item["stateName"] = "<span class='label label-success'>待审核</span>";
  174. break;
  175. case 2:
  176. $new_item["stateName"] = "<span class='label label-danger'>审核驳回</span>";
  177. break;
  178. case 3:
  179. $new_item["stateName"] = "<span class='label label-primary'>审核通过</span>";
  180. break;
  181. case 4:
  182. $new_item["stateName"] = "<span class='label label-primary'>重新提交</span>";
  183. break;
  184. case 5:
  185. $new_item["stateName"] = "<span class='label label-danger'>初审驳回</span>";
  186. break;
  187. case 6:
  188. $new_item["stateName"] = "<span class='label label-primary'>初审通过</span>";
  189. break;
  190. default:
  191. break;
  192. }
  193. $new_item["stateChange"] = $item['stateChange'];
  194. }
  195. break;
  196. case 1:
  197. $new_item["stepName"] = DictApi::getCheckLogStepName($item["state"], $item["step"]);
  198. if (in_array($item["state"], [TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
  199. $new_item["stateName"] = '<span class="label label-danger">审核不通过</span>';
  200. } else if (in_array($item["state"], [TalentState::BASE_VERIFY_PASS, TalentState::BASE_REVERIFY_PASS, TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS])) {
  201. if ($item["step"] == 3) {
  202. if ($item["new_state"] == TalentState::SCND_SUBMIT) {
  203. $new_item["stateName"] = '<span class="label label-danger">审核驳回</span>';
  204. } else if ($item["new_state"] == TalentState::DEPT_VERIFY_PASS) {
  205. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  206. } else {
  207. $new_item["stateName"] = '<span class="label label-success">待审核</span>';
  208. }
  209. } else {
  210. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  211. }
  212. } else if (in_array($item["state"], [TalentState::BASE_REJECT, TalentState::BASE_REVERIFY_REJECT, TalentState::FST_VERIFY_REJECT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT])) {
  213. $new_item["stateName"] = '<span class="label label-danger">审核驳回</span>';
  214. } else if (in_array($item["state"], [TalentState::ZX_PASS, TalentState::ANNOUNCED, TalentState::ANNOUNCED_REVERIFY_PASS, TalentState::PUBLISH_PASS, TalentState::CERTIFICATED])) {
  215. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  216. } else if (in_array($item["state"], [TalentState::FST_SAVE, TalentState::SCND_SAVE])) {
  217. $new_item["stateName"] = '<span class="label">保存未提交</span>';
  218. } else if ($item["state"] == 0) {
  219. $new_item["stateName"] = '<span class="label">添加附件</span>';
  220. } else {
  221. if (($item["last_state"] == TalentState::BASE_REJECT && $item["state"] == TalentState::FST_SUBMIT) || ($item["last_state"] == TalentState::FST_VERIFY_REJECT && $item["state"] == TalentState::SCND_SUBMIT)) {
  222. $new_item["stateName"] = '<span class="label label-success">待审核(重新提交)</span>';
  223. } else {
  224. $new_item["stateName"] = '<span class="label label-success">待审核</span>';
  225. }
  226. }
  227. if ($item["step"] == 3) {
  228. $company = CompanyApi::getOne($item["companyId"]);
  229. if ($item["active"] == 0) {
  230. $new_item["stateChange"] = str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["state"], $item["step"]));
  231. } else {
  232. $new_item["stateChange"] = sprintf("%s -> %s", str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["state"], $item["step"])), DictApi::getTalentInfoStateName($item["new_state"], $item["step"]));
  233. }
  234. } else {
  235. if ($item["last_state"] && $item["new_state"]) {
  236. $new_item["stateChange"] = sprintf("%s -> %s", DictApi::getTalentInfoStateName($item["last_state"], $list[$key + 1]["step"]), DictApi::getTalentInfoStateName($item["new_state"], $list[$key - 1]["step"], $item["last_state"]));
  237. } else {
  238. $new_item["stateChange"] = "";
  239. }
  240. }
  241. break;
  242. }
  243. $new_item["description"] = $item["description"];
  244. $new_item["createUser"] = $item["updateUser"] ?: $item["createUser"];
  245. if ($new_item["createUser"] != "用户") {
  246. list($name, $company) = explode("(", $new_item["createUser"]);
  247. $where = [];
  248. $where[] = ["name", "=", $name];
  249. $user = \app\admin\model\User::where($where)->find();
  250. $account = $user ? $user["account"] : "tmp_user";
  251. $new_item["createUser"] = implode("(", [$account, $company]);
  252. }
  253. $new_item["createTime"] = $item["updateTime"] ?: $item["createTime"];
  254. $new_list[] = $new_item;
  255. }
  256. return json(["rows" => $new_list]);
  257. }
  258. public function findCommonFileType() {
  259. $param = $this->request->param();
  260. $id = $param["mainId"];
  261. $source = $param["source"];
  262. $order = $param["order"];
  263. $project = $param["project"];
  264. $type = $param["type"];
  265. $checkState = $param["checkState"];
  266. $isMix = $param["isMix"] ?: 0;
  267. $talent_condition = $param["talent_condition"];
  268. $where[] = ["project", "=", $project];
  269. $where[] = ["active", "=", 1];
  270. $where[] = ["delete", "=", 0];
  271. $where[] = ["type", "=", $type];
  272. switch ($project) {
  273. case 1:
  274. if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, 0, TalentState::FST_SAVE, TalentState::FST_SUBMIT, TalentState::BASE_VERIFY_PASS]) && $isMix != 1) {
  275. $where[] = ["step", "=", 1]; //只查找人才第一步所需文件
  276. } else {
  277. $where[] = ["isConditionFile", "<>", 1]; //排除人才条件上传文件
  278. }
  279. if ($talent_condition && $source == 5) {
  280. $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
  281. if ($condition_info["bindFileTypes"]) {
  282. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  283. }
  284. }
  285. break;
  286. case 20:
  287. $itemId = $param["itemId"];
  288. $integral_item = \app\common\api\IntegralItemApi::getOne($itemId);
  289. if ($integral_item && $integral_item["fileTypeId"]) {
  290. $where[] = ["id", "in", explode(',', $integral_item["fileTypeId"])];
  291. } else {
  292. return json([]);
  293. }
  294. break;
  295. }
  296. if ($whr) {
  297. $rows = Db::table("new_common_filetype")->whereOr([$where, $whr])->order("must asc")->order("sn " . $order)->select()->toArray();
  298. } else {
  299. $rows = Db::table("new_common_filetype")->where($where)->order("must asc")->order("sn " . $order)->select()->toArray();
  300. }
  301. if ($id) {
  302. foreach ($rows as $key => $row) {
  303. $where = [];
  304. $where[] = ["mainId", "=", $id];
  305. $where[] = ["typeId", "=", $row["id"]];
  306. $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
  307. foreach ($files as &$file) {
  308. $file["ext"] = pathinfo($file["url"])["extension"];
  309. $file["url"] = getStoragePath($file["url"]);
  310. }
  311. $rows[$key]["files"] = $files;
  312. }
  313. }
  314. return json(["rows" => $rows]);
  315. }
  316. public function listTalentFile() {
  317. $param = $this->request->param();
  318. $mainId = $param["mainId"];
  319. $typeId = $param["fileTypeId"];
  320. $where = [["mainId", "=", $mainId], ["typeId", "=", $typeId]];
  321. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  322. foreach ($list as $key => $item) {
  323. $list[$key]["url"] = getStoragePath($item["url"]);
  324. }
  325. return json($list);
  326. }
  327. public function addTalentFile() {
  328. $backName = $this->request->param("backName");
  329. $fileId = $this->request->param("fileId");
  330. $mainId = $this->request->param("mainId");
  331. $fileTypeId = $this->request->param("fileTypeId");
  332. $index = $this->request->param("index");
  333. $type = $this->request->param("type");
  334. $upload = new \app\common\api\UploadApi();
  335. $file = $this->request->file("fileUrl");
  336. if (!TalentApi::checkIsEditable($mainId)) {
  337. $res = ["msg" => "当前状态不能修改附件", "obj" => $index];
  338. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  339. exit();
  340. }
  341. $mime = $file->getMime();
  342. switch ($mime) {
  343. case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"://xlsx
  344. case "application/pdf"://pdf
  345. case "application/vnd.ms-excel"://xls
  346. $filestd = $upload->uploadOne($file, "file", "talent_files");
  347. break;
  348. case "image/jpg":
  349. case "image/jpeg":
  350. case "image/png":
  351. case "image/gif":
  352. $filestd = $upload->uploadOne($file, "image", "talent_files");
  353. break;
  354. default:
  355. $res = ["msg" => "不支持的附件类型", "obj" => $index];
  356. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  357. exit();
  358. break;
  359. }
  360. $change = false;
  361. if ($fileId) {
  362. if (!$this->chkIsFileOwner($mainId, $type)) {
  363. $res = ["msg" => "删除失败", "obj" => $index];
  364. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  365. exit();
  366. }
  367. $old = Db::table("new_talent_file")->findOrEmpty($fileId);
  368. $old_filepath = "storage/" . $old["url"];
  369. if (file_exists($old_filepath))
  370. unlink($old_filepath);
  371. $data["id"] = $fileId;
  372. $change = true;
  373. }
  374. $data["mainId"] = $mainId;
  375. $data["type"] = $type;
  376. $data["typeId"] = $fileTypeId;
  377. $data["orignName"] = $file->getOriginalName();
  378. $data["url"] = $filestd->filepath;
  379. $data["sn"] = $index;
  380. $data["createTime"] = time();
  381. if ($fileId) {
  382. Db::table("new_talent_file")->save($data);
  383. } else {
  384. $fileId = Db::table("new_talent_file")->insertGetId($data);
  385. }
  386. $ext = pathinfo($filestd->filepath)["extension"];
  387. TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
  388. $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "ext" => $ext, "info" => getStoragePath($filestd->filepath), "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
  389. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  390. }
  391. public function deleteFile() {
  392. $param = $this->request->param();
  393. $where = [["id", "=", $param["id"]]];
  394. $file = Db::table("new_talent_file")->where($where)->findOrEmpty();
  395. if (!TalentApi::checkIsEditable($file["mainId"]))
  396. return json(["msg" => "当前状态不能删除"]);
  397. if ($this->chkIsFileOwner($file["mainId"], $file["type"])) {
  398. $filepath = "storage/" . $file["url"];
  399. if (file_exists($filepath)) {
  400. unlink($filepath);
  401. }
  402. Db::table("new_talent_file")->delete($file["id"]);
  403. TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  404. return json(["code" => 200, "msg" => "删除成功"]);
  405. }
  406. return json(["msg" => "不能删除"]);
  407. }
  408. public function deleteTalentCommonFile() {
  409. $param = $this->request->param();
  410. $where = [["id", "=", $param["id"]]];
  411. $file = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  412. $filepath = "storage/" . $file["url"];
  413. if (file_exists($filepath)) {
  414. unlink($filepath);
  415. }
  416. Db::table("new_talent_common_file")->delete($file["id"]);
  417. //TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  418. return json(["code" => 200, "msg" => "删除成功"]);
  419. return json(["msg" => "不能删除"]);
  420. }
  421. /**
  422. * 下载文件
  423. */
  424. public function downloadFile() {
  425. $param = $this->request->param();
  426. $type = $param["type"];
  427. $id = $param["id"];
  428. $where = [];
  429. $where[] = ["id", "=", $id];
  430. $url = "";
  431. switch ($type) {
  432. case 1:
  433. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  434. $filename = $fileinfo["orignName"];
  435. $url = $fileinfo["url"];
  436. break;
  437. case 2:
  438. $fileinfo = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  439. $filename = $fileinfo["orignName"];
  440. $url = $fileinfo["url"];
  441. break;
  442. case 3:
  443. $fileinfo = Db::table("new_currency_filetype")->where($where)->findOrEmpty();
  444. $filename = $fileinfo["templateUrl"];
  445. $url = $fileinfo["templateUrl"];
  446. break;
  447. case 4:
  448. $fileinfo = Db::table("sys_common_file")->where($where)->findOrEmpty();
  449. $filename = $fileinfo["orignName"];
  450. $url = $fileinfo["url"];
  451. break;
  452. }
  453. $filepath = "storage/" . $url; // 下载文件名
  454. if (!file_exists($filepath)) {
  455. header('HTTP/1.1 404 NOT FOUND');
  456. } else {
  457. $file = fopen($filepath, "rb");
  458. Header("Content-type: application/octet-stream");
  459. Header("Accept-Ranges: bytes");
  460. Header("Accept-Length: " . filesize($filepath));
  461. Header("Content-Disposition: attachment; filename=" . $filename);
  462. echo fread($file, filesize($filepath));
  463. fclose($file);
  464. exit();
  465. }
  466. }
  467. /**
  468. * 打包下载人才申请附件
  469. */
  470. public function downloadZip() {
  471. $param = $this->request->param();
  472. $type = $param["type"];
  473. $id = $param["id"];
  474. $where = [];
  475. $where[] = ["mainId", "=", $id];
  476. $where[] = ["type", "=", $type];
  477. $files = Db::table("new_talent_file")->where($where)->select()->toArray();
  478. if (!$files)
  479. die("没有附件不能打包下载");
  480. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  481. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  482. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  483. $tmp_path = "storage/temp/";
  484. $tmp_file_path = $tmp_path . $zip_filename;
  485. if (!file_exists($tmp_path)) {
  486. mkdir($tmp_path);
  487. }
  488. $zip = new \ZipArchive();
  489. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  490. header('HTTP/1.1 404 NOT FOUND');
  491. }
  492. foreach ($files as $file) {
  493. $filepath = "storage/" . $file["url"];
  494. $filename = $file["orignName"];
  495. $zip->addFile($filepath, $filename);
  496. }
  497. $zip->close();
  498. if (file_exists($tmp_file_path)) {
  499. header("Cache-Control: public");
  500. header("Content-Description: File Transfer");
  501. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  502. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  503. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  504. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  505. @readfile($tmp_file_path);
  506. }
  507. //删除临时文件
  508. @unlink($tmp_file_path);
  509. }
  510. private function chkIsFileOwner($mainId, $type) {
  511. if (!$mainId)
  512. return true;
  513. switch ($type) {
  514. case 1:
  515. if ($this->user["usertype"] == 2) {
  516. $user_id = $this->user["uid"];
  517. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  518. if ($user_id == $talent_info["enterprise_id"])
  519. return true;
  520. }
  521. break;
  522. }
  523. return false;
  524. }
  525. public function getCompanyKvs() {
  526. $companys = \app\common\model\Company::field("name,id")->select();
  527. return json($companys);
  528. }
  529. public function getLayerCatsByLayer() {
  530. $lv = $this->request->param("level");
  531. return json(DictApi::getLayerCatsByLayer($lv));
  532. }
  533. /**
  534. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  535. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  536. */
  537. public function getConditionFileTypesByType() {
  538. $params = $this->request->param();
  539. $type = $params["type"]; //人才类型不默认,需要传
  540. $declare_type = $params["project"] ?: 1; //默认人才认定
  541. $active = $params["active"] ?: 1; //默认查找启用的附件
  542. $where[] = ["type", "=", $type];
  543. $where[] = ["project", "=", $declare_type];
  544. $where[] = ["active", "=", $active];
  545. $where[] = ["delete", "=", 0];
  546. $where[] = ["isConditionFile", "=", 1];
  547. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  548. return json($list);
  549. }
  550. public function listCurrencyFileType() {
  551. $where = [
  552. 'type' => $this->request['type'],
  553. 'active' => 1
  554. ];
  555. $rows = CurrentcyFileType::where($where)->select();
  556. return json(["rows" => $rows, 'total' => count($rows)]);
  557. }
  558. public function listTalentCommonFile() {
  559. $where = [];
  560. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  561. $where[] = ['mainId', '=', $this->request['mainId']];
  562. }
  563. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  564. $where[] = ['typeId', '=', $this->request['typeId']];
  565. }
  566. $res = TalentCommonFile::where($where)->order('sn')->select();
  567. if ($res) {
  568. foreach ($res as $k => &$v) {
  569. $v["ext"] = pathinfo($v["url"])["extension"];
  570. $v['url'] = getStoragePath($v['url']);
  571. }
  572. }
  573. return json($res);
  574. }
  575. public function addTalentCommonFile() {
  576. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  577. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  578. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  579. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  580. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  581. if ($backName == "EpChangeEdit.callBack") {
  582. $type = 1;
  583. $error = "文件格式不正确,只能上传图片";
  584. } else {
  585. $type = 4;
  586. $error = "文件格式不正确,只能上传pdf和图片";
  587. }
  588. $uploadapi = new UploadApi();
  589. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  590. if ($file_check_res->code == 500) {
  591. $file_check_res->obj = $index;
  592. return \StrUtil::back($file_check_res, $backName);
  593. }
  594. $file_data = [
  595. 'id' => getStringId(),
  596. 'mainId' => $mainId,
  597. 'typeId' => $typeId,
  598. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  599. 'url' => $file_check_res->filepath
  600. ];
  601. if (\StrUtil::isEmpOrNull($id)) {
  602. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  603. if ($tc) {
  604. $file_data['sn'] = $tc['sn'] + 1;
  605. } else {
  606. $file_data['sn'] = 1;
  607. }
  608. $file_data['createTime'] = date("Y-m-d H:i:s");
  609. TalentCommonFile::create($file_data);
  610. $response_object = new \StdClass();
  611. $response_object->code = 200;
  612. $response_object->msg = "附件上传成功!";
  613. $response_object->obj = $index;
  614. return \StrUtil::back($response_object, $backName);
  615. } else {
  616. $tf = TalentCommonFile::findOrEmpty($id);
  617. $tf->originalName = $file_data['orignName'];
  618. $tf->updateTime = date("Y-m-d H:i:s");
  619. $tf->url = $file_check_res->filepath;
  620. $tf->save();
  621. $response_object = new \StdClass();
  622. $response_object->code = 200;
  623. $response_object->msg = "附件修改成功!";
  624. $response_object->obj = $index;
  625. return \StrUtil::back($response_object, $backName);
  626. }
  627. }
  628. public function changePwd() {
  629. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  630. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  631. //数据校验(原密码与新密码不能为空)
  632. if (\StrUtil::isEmpOrNull($password)) {
  633. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  634. }
  635. if (\StrUtil::isEmpOrNull($newPassword)) {
  636. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  637. }
  638. try {
  639. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  640. $ep = EnterpriseApi::getOne(session("user")['uid']);
  641. if (!$ep) {
  642. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  643. }
  644. if ($ep->password != hash('md5', $password)) {
  645. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  646. }
  647. $ep->password = hash('md5', $newPassword);
  648. $ep->updateUser = session("user")['uid'];
  649. $ep->updateTime = date("Y-m-d H:i:s");
  650. $ep->save();
  651. TalentChecklog::create([
  652. 'id' => getStringId(),
  653. 'category' => 'enterprise_change',
  654. 'mainId' => $ep->id,
  655. 'type' => 10,
  656. 'typeField' => null,
  657. 'active' => 1,
  658. 'state' => 1,
  659. 'step' => 100,
  660. 'stateChange' => null,
  661. 'description' => '用户修改密码',
  662. 'createTime' => date("Y-m-d H:i:s", time()),
  663. 'createUser' => '用户'
  664. ]);
  665. return json(['code' => 200, 'msg' => "修改成功!"]);
  666. } catch (ValidateException $e) {
  667. $error = $e->getError();
  668. return json(['code' => 500, 'msg' => array_pop($error)]);
  669. }
  670. }
  671. function getIntegralProjectsByType() {
  672. $projectType = $this->request->param("projectType") ?: 0;
  673. if (session("user")["usertype"] == 2) {
  674. $where[] = ["type", "=", 2];
  675. } else {
  676. $type = $this->request->param("type") ?: 0;
  677. $where[] = ["type", "=", $type];
  678. }
  679. $where[] = ["projectType", "=", $projectType];
  680. $where[] = ["active", "=", 1];
  681. $list = \app\common\api\IntegralProjectApi::getAll($where);
  682. return json($list);
  683. }
  684. public function getIntegralItemsByProject() {
  685. $projectId = $this->request->param("projectId") ?: 0;
  686. $where[] = ["projectId", "=", $projectId];
  687. $where[] = ["active", "=", 1];
  688. $list = \app\common\api\IntegralItemApi::getAll($where);
  689. return json($list);
  690. }
  691. }