Api.php 33 KB

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