Api.php 27 KB

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