Api.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. $itemIds = $param["itemId"];
  288. $redis = \app\common\Redis::instance(\think\facade\Config::get("cache.stores.redis.select"));
  289. $fileTypeIds = [];
  290. foreach ($itemIds as $item_id) {
  291. $integral_item = json_decode($redis->hGet("IntegralItem", $item_id), true);
  292. if ($integral_item["fileTypeId"]) {
  293. $fileTypeIds = array_filter(array_merge($fileTypeIds, explode(",", $integral_item["fileTypeId"])));
  294. }
  295. }
  296. //$integral_item = \app\common\api\IntegralItemApi::getOne($itemId);
  297. if ($integral_item && $integral_item["fileTypeId"]) {
  298. $where[] = ["id", "in", $fileTypeIds];
  299. } else {
  300. return json([]);
  301. }
  302. break;
  303. }
  304. if ($whr) {
  305. $rows = Db::table("new_common_filetype")->whereOr([$where, $whr])->order("must asc")->order("sn " . $order)->select()->toArray();
  306. } else {
  307. $rows = Db::table("new_common_filetype")->where($where)->order("must asc")->order("sn " . $order)->select()->toArray();
  308. }
  309. if ($id) {
  310. foreach ($rows as $key => $row) {
  311. $where = [];
  312. $where[] = ["mainId", "=", $id];
  313. $where[] = ["typeId", "=", $row["id"]];
  314. $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
  315. foreach ($files as &$file) {
  316. $file["ext"] = pathinfo($file["url"])["extension"];
  317. $file["url"] = getStoragePath($file["url"]);
  318. }
  319. $rows[$key]["files"] = $files;
  320. }
  321. }
  322. return json(["rows" => $rows]);
  323. }
  324. public function listTalentFile() {
  325. $param = $this->request->param();
  326. $mainId = $param["mainId"];
  327. $typeId = $param["fileTypeId"];
  328. $where = [["mainId", "=", $mainId], ["typeId", "=", $typeId]];
  329. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  330. foreach ($list as $key => $item) {
  331. $list[$key]["url"] = getStoragePath($item["url"]);
  332. }
  333. return json($list);
  334. }
  335. public function addTalentFile() {
  336. $backName = $this->request->param("backName");
  337. $fileId = $this->request->param("fileId");
  338. $mainId = $this->request->param("mainId");
  339. $fileTypeId = $this->request->param("fileTypeId");
  340. $index = $this->request->param("index");
  341. $type = $this->request->param("type");
  342. $upload = new \app\common\api\UploadApi();
  343. $file = $this->request->file("fileUrl");
  344. if (!TalentApi::checkIsEditable($mainId)) {
  345. $res = ["msg" => "当前状态不能修改附件", "obj" => $index];
  346. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  347. exit();
  348. }
  349. $mime = $file->getMime();
  350. switch ($mime) {
  351. case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"://xlsx
  352. case "application/pdf"://pdf
  353. case "application/vnd.ms-excel"://xls
  354. $filestd = $upload->uploadOne($file, "file", "talent_files");
  355. break;
  356. case "image/jpg":
  357. case "image/jpeg":
  358. case "image/png":
  359. case "image/gif":
  360. $filestd = $upload->uploadOne($file, "image", "talent_files");
  361. break;
  362. default:
  363. $res = ["msg" => "不支持的附件类型", "obj" => $index];
  364. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  365. exit();
  366. break;
  367. }
  368. $change = false;
  369. if ($fileId) {
  370. if (!$this->chkIsFileOwner($mainId, $type)) {
  371. $res = ["msg" => "删除失败", "obj" => $index];
  372. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  373. exit();
  374. }
  375. $old = Db::table("new_talent_file")->findOrEmpty($fileId);
  376. $old_filepath = "storage/" . $old["url"];
  377. if (file_exists($old_filepath))
  378. unlink($old_filepath);
  379. $data["id"] = $fileId;
  380. $change = true;
  381. }
  382. $data["mainId"] = $mainId;
  383. $data["type"] = $type;
  384. $data["typeId"] = $fileTypeId;
  385. $data["orignName"] = $file->getOriginalName();
  386. $data["url"] = $filestd->filepath;
  387. $data["sn"] = $index;
  388. $data["createTime"] = time();
  389. if ($fileId) {
  390. Db::table("new_talent_file")->save($data);
  391. } else {
  392. $fileId = Db::table("new_talent_file")->insertGetId($data);
  393. }
  394. $ext = pathinfo($filestd->filepath)["extension"];
  395. TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
  396. $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "ext" => $ext, "info" => getStoragePath($filestd->filepath), "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
  397. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  398. }
  399. public function deleteFile() {
  400. $param = $this->request->param();
  401. $where = [["id", "=", $param["id"]]];
  402. $file = Db::table("new_talent_file")->where($where)->findOrEmpty();
  403. if (!TalentApi::checkIsEditable($file["mainId"]))
  404. return json(["msg" => "当前状态不能删除"]);
  405. if ($this->chkIsFileOwner($file["mainId"], $file["type"])) {
  406. $filepath = "storage/" . $file["url"];
  407. if (file_exists($filepath)) {
  408. unlink($filepath);
  409. }
  410. Db::table("new_talent_file")->delete($file["id"]);
  411. TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  412. return json(["code" => 200, "msg" => "删除成功"]);
  413. }
  414. return json(["msg" => "不能删除"]);
  415. }
  416. public function deleteTalentCommonFile() {
  417. $param = $this->request->param();
  418. $where = [["id", "=", $param["id"]]];
  419. $file = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  420. $filepath = "storage/" . $file["url"];
  421. if (file_exists($filepath)) {
  422. unlink($filepath);
  423. }
  424. Db::table("new_talent_common_file")->delete($file["id"]);
  425. //TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  426. return json(["code" => 200, "msg" => "删除成功"]);
  427. return json(["msg" => "不能删除"]);
  428. }
  429. /**
  430. * 下载文件
  431. */
  432. public function downloadFile() {
  433. $param = $this->request->param();
  434. $type = $param["type"];
  435. $id = $param["id"];
  436. $where = [];
  437. $where[] = ["id", "=", $id];
  438. $url = "";
  439. switch ($type) {
  440. case 1:
  441. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  442. $filename = $fileinfo["orignName"];
  443. $url = $fileinfo["url"];
  444. break;
  445. case 2:
  446. $fileinfo = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  447. $filename = $fileinfo["orignName"];
  448. $url = $fileinfo["url"];
  449. break;
  450. case 3:
  451. $fileinfo = Db::table("new_currency_filetype")->where($where)->findOrEmpty();
  452. $filename = $fileinfo["templateUrl"];
  453. $url = $fileinfo["templateUrl"];
  454. break;
  455. case 4:
  456. $fileinfo = Db::table("sys_common_file")->where($where)->findOrEmpty();
  457. $filename = $fileinfo["orignName"];
  458. $url = $fileinfo["url"];
  459. break;
  460. case 5:
  461. $fileinfo = Db::table("new_common_filetype")->where($where)->findOrEmpty();
  462. $filename = $fileinfo["templateUrl"];
  463. $url = $fileinfo["templateUrl"];
  464. break;
  465. }
  466. $filepath = "storage/" . $url; // 下载文件名
  467. if (!file_exists($filepath)) {
  468. header('HTTP/1.1 404 NOT FOUND');
  469. } else {
  470. $file = fopen($filepath, "rb");
  471. Header("Content-type: application/octet-stream");
  472. Header("Accept-Ranges: bytes");
  473. Header("Accept-Length: " . filesize($filepath));
  474. Header("Content-Disposition: attachment; filename=" . $filename);
  475. echo fread($file, filesize($filepath));
  476. fclose($file);
  477. exit();
  478. }
  479. }
  480. /**
  481. * 打包下载人才申请附件
  482. */
  483. public function downloadZip() {
  484. $param = $this->request->param();
  485. $type = $param["type"];
  486. $id = $param["id"];
  487. $where = [];
  488. $where[] = ["mainId", "=", $id];
  489. $where[] = ["type", "=", $type];
  490. $files = Db::table("new_talent_file")->where($where)->select()->toArray();
  491. if (!$files)
  492. die("没有附件不能打包下载");
  493. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  494. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  495. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  496. $tmp_path = "storage/temp/";
  497. $tmp_file_path = $tmp_path . $zip_filename;
  498. if (!file_exists($tmp_path)) {
  499. mkdir($tmp_path);
  500. }
  501. $zip = new \ZipArchive();
  502. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  503. header('HTTP/1.1 404 NOT FOUND');
  504. }
  505. foreach ($files as $file) {
  506. $filepath = "storage/" . $file["url"];
  507. $filename = $file["orignName"];
  508. $zip->addFile($filepath, $filename);
  509. }
  510. $zip->close();
  511. if (file_exists($tmp_file_path)) {
  512. header("Cache-Control: public");
  513. header("Content-Description: File Transfer");
  514. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  515. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  516. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  517. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  518. @readfile($tmp_file_path);
  519. }
  520. //删除临时文件
  521. @unlink($tmp_file_path);
  522. }
  523. private function chkIsFileOwner($mainId, $type) {
  524. if (!$mainId)
  525. return true;
  526. switch ($type) {
  527. case 1:
  528. if ($this->user["usertype"] == 2) {
  529. $user_id = $this->user["uid"];
  530. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  531. if ($user_id == $talent_info["enterprise_id"])
  532. return true;
  533. }
  534. break;
  535. }
  536. return false;
  537. }
  538. public function getCompanyKvs() {
  539. $companys = \app\common\model\Company::field("name,id")->select();
  540. return json($companys);
  541. }
  542. public function getLayerCatsByLayer() {
  543. $lv = $this->request->param("level");
  544. return json(DictApi::getLayerCatsByLayer($lv));
  545. }
  546. /**
  547. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  548. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  549. */
  550. public function getConditionFileTypesByType() {
  551. $params = $this->request->param();
  552. $type = $params["type"]; //人才类型不默认,需要传
  553. $declare_type = $params["project"] ?: 1; //默认人才认定
  554. $active = $params["active"] ?: 1; //默认查找启用的附件
  555. $where[] = ["type", "=", $type];
  556. $where[] = ["project", "=", $declare_type];
  557. $where[] = ["active", "=", $active];
  558. $where[] = ["delete", "=", 0];
  559. $where[] = ["isConditionFile", "=", 1];
  560. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  561. return json($list);
  562. }
  563. public function listCurrencyFileType() {
  564. $where = [
  565. 'type' => $this->request['type'],
  566. 'active' => 1
  567. ];
  568. $rows = CurrentcyFileType::where($where)->select();
  569. return json(["rows" => $rows, 'total' => count($rows)]);
  570. }
  571. public function listTalentCommonFile() {
  572. $where = [];
  573. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  574. $where[] = ['mainId', '=', $this->request['mainId']];
  575. }
  576. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  577. $where[] = ['typeId', '=', $this->request['typeId']];
  578. }
  579. $res = TalentCommonFile::where($where)->order('sn')->select();
  580. if ($res) {
  581. foreach ($res as $k => &$v) {
  582. $v["ext"] = pathinfo($v["url"])["extension"];
  583. $v['url'] = getStoragePath($v['url']);
  584. }
  585. }
  586. return json($res);
  587. }
  588. public function addTalentCommonFile() {
  589. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  590. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  591. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  592. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  593. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  594. if ($backName == "EpChangeEdit.callBack") {
  595. $type = 1;
  596. $error = "文件格式不正确,只能上传图片";
  597. } else {
  598. $type = 4;
  599. $error = "文件格式不正确,只能上传pdf和图片";
  600. }
  601. $uploadapi = new UploadApi();
  602. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  603. if ($file_check_res->code == 500) {
  604. $file_check_res->obj = $index;
  605. return \StrUtil::back($file_check_res, $backName);
  606. }
  607. $file_data = [
  608. 'id' => getStringId(),
  609. 'mainId' => $mainId,
  610. 'typeId' => $typeId,
  611. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  612. 'url' => $file_check_res->filepath
  613. ];
  614. if (\StrUtil::isEmpOrNull($id)) {
  615. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  616. if ($tc) {
  617. $file_data['sn'] = $tc['sn'] + 1;
  618. } else {
  619. $file_data['sn'] = 1;
  620. }
  621. $file_data['createTime'] = date("Y-m-d H:i:s");
  622. TalentCommonFile::create($file_data);
  623. $response_object = new \StdClass();
  624. $response_object->code = 200;
  625. $response_object->msg = "附件上传成功!";
  626. $response_object->obj = $index;
  627. return \StrUtil::back($response_object, $backName);
  628. } else {
  629. $tf = TalentCommonFile::findOrEmpty($id);
  630. $tf->originalName = $file_data['orignName'];
  631. $tf->updateTime = date("Y-m-d H:i:s");
  632. $tf->url = $file_check_res->filepath;
  633. $tf->save();
  634. $response_object = new \StdClass();
  635. $response_object->code = 200;
  636. $response_object->msg = "附件修改成功!";
  637. $response_object->obj = $index;
  638. return \StrUtil::back($response_object, $backName);
  639. }
  640. }
  641. public function changePwd() {
  642. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  643. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  644. //数据校验(原密码与新密码不能为空)
  645. if (\StrUtil::isEmpOrNull($password)) {
  646. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  647. }
  648. if (\StrUtil::isEmpOrNull($newPassword)) {
  649. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  650. }
  651. try {
  652. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  653. $ep = EnterpriseApi::getOne(session("user")['uid']);
  654. if (!$ep) {
  655. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  656. }
  657. if ($ep->password != hash('md5', $password)) {
  658. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  659. }
  660. $ep->password = hash('md5', $newPassword);
  661. $ep->updateUser = session("user")['uid'];
  662. $ep->updateTime = date("Y-m-d H:i:s");
  663. $ep->save();
  664. TalentChecklog::create([
  665. 'id' => getStringId(),
  666. 'category' => 'enterprise_change',
  667. 'mainId' => $ep->id,
  668. 'type' => 10,
  669. 'typeField' => null,
  670. 'active' => 1,
  671. 'state' => 1,
  672. 'step' => 100,
  673. 'stateChange' => null,
  674. 'description' => '用户修改密码',
  675. 'createTime' => date("Y-m-d H:i:s", time()),
  676. 'createUser' => '用户'
  677. ]);
  678. return json(['code' => 200, 'msg' => "修改成功!"]);
  679. } catch (ValidateException $e) {
  680. $error = $e->getError();
  681. return json(['code' => 500, 'msg' => array_pop($error)]);
  682. }
  683. }
  684. function getIntegralProjectsByType() {
  685. $projectType = $this->request->param("projectType") ?: 0;
  686. if (session("user")["usertype"] == 2) {
  687. $where[] = ["type", "=", 2];
  688. } else {
  689. $type = $this->request->param("type") ?: 0;
  690. $where[] = ["type", "=", $type];
  691. }
  692. $where[] = ["projectType", "=", $projectType];
  693. $where[] = ["active", "=", 1];
  694. $list = \app\common\api\IntegralProjectApi::getAll($where);
  695. return json($list);
  696. }
  697. public function getIntegralItemsByProject() {
  698. $projectId = $this->request->param("projectId") ?: 0;
  699. $where[] = ["projectId", "=", $projectId];
  700. $where[] = ["active", "=", 1];
  701. $list = \app\common\api\IntegralItemApi::getAll($where);
  702. return json($list);
  703. }
  704. }