Api.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. /**
  312. * 下载文件
  313. */
  314. public function downloadFile() {
  315. $param = $this->request->param();
  316. $type = $param["type"];
  317. $id = $param["id"];
  318. $where = [];
  319. $where[] = ["id", "=", $id];
  320. $where[] = ["type", "=", $type];
  321. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  322. $filename = $fileinfo["orignName"];
  323. $filepath = "storage/" . $fileinfo["url"]; // 下载文件名
  324. if (!file_exists($filepath)) {
  325. header('HTTP/1.1 404 NOT FOUND');
  326. } else {
  327. $file = fopen($filepath, "rb");
  328. Header("Content-type: application/octet-stream");
  329. Header("Accept-Ranges: bytes");
  330. Header("Accept-Length: " . filesize($filepath));
  331. Header("Content-Disposition: attachment; filename=" . $filename);
  332. echo fread($file, filesize($filepath));
  333. fclose($file);
  334. exit();
  335. }
  336. }
  337. /**
  338. * 打包下载人才申请附件
  339. */
  340. public function downloadZip() {
  341. $param = $this->request->param();
  342. $type = $param["type"];
  343. $id = $param["id"];
  344. $where = [];
  345. $where[] = ["mainId", "=", $id];
  346. $where[] = ["type", "=", $type];
  347. $files = Db::table("new_talent_file")->where($where)->select()->toArray();
  348. if (!$files)
  349. die("没有附件不能打包下载");
  350. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  351. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  352. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  353. $tmp_path = "storage/temp/";
  354. $tmp_file_path = $tmp_path . $zip_filename;
  355. if (!file_exists($tmp_path)) {
  356. mkdir($tmp_path);
  357. }
  358. $zip = new \ZipArchive();
  359. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  360. header('HTTP/1.1 404 NOT FOUND');
  361. }
  362. foreach ($files as $file) {
  363. $filepath = "storage/" . $file["url"];
  364. $filename = $file["orignName"];
  365. $zip->addFile($filepath, $filename);
  366. }
  367. $zip->close();
  368. if (file_exists($tmp_file_path)) {
  369. header("Cache-Control: public");
  370. header("Content-Description: File Transfer");
  371. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  372. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  373. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  374. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  375. @readfile($tmp_file_path);
  376. }
  377. //删除临时文件
  378. @unlink($tmp_file_path);
  379. }
  380. private function chkIsFileOwner($mainId, $type) {
  381. if (!$mainId)
  382. return true;
  383. switch ($type) {
  384. case 1:
  385. if ($this->user["usertype"] == 2) {
  386. $user_id = $this->user["uid"];
  387. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  388. if ($user_id == $talent_info["enterprise_id"])
  389. return true;
  390. }
  391. break;
  392. }
  393. return false;
  394. }
  395. public function getCompanyKvs() {
  396. $companys = \app\common\model\Company::field("name,id")->select();
  397. return json($companys);
  398. }
  399. public function getLayerCatsByLayer() {
  400. $lv = $this->request->param("level");
  401. return json(DictApi::getLayerCatsByLayer($lv));
  402. }
  403. /**
  404. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  405. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  406. */
  407. public function getConditionFileTypesByType() {
  408. $params = $this->request->param();
  409. $type = $params["type"]; //人才类型不默认,需要传
  410. $declare_type = $params["project"] ?: 1; //默认人才认定
  411. $active = $params["active"] ?: 1; //默认查找启用的附件
  412. $where[] = ["type", "=", $type];
  413. $where[] = ["project", "=", $declare_type];
  414. $where[] = ["active", "=", $active];
  415. $where[] = ["delete", "=", 0];
  416. $where[] = ["isConditionFile", "=", 1];
  417. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  418. return json($list);
  419. }
  420. public function listCurrencyFileType() {
  421. $where = [
  422. 'type' => $this->request['type'],
  423. 'active' => 1
  424. ];
  425. $rows = CurrentcyFileType::where($where)->select();
  426. return json(["rows" => $rows, 'total' => count($rows)]);
  427. }
  428. public function listTalentCommonFile() {
  429. $where = [];
  430. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  431. $where[] = ['mainId', '=', $this->request['mainId']];
  432. }
  433. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  434. $where[] = ['typeId', '=', $this->request['typeId']];
  435. }
  436. $res = TalentCommonFile::where($where)->order('sn')->select();
  437. if ($res) {
  438. foreach ($res as $k => &$v) {
  439. $v['url'] = getStoragePath($v['url']);
  440. }
  441. }
  442. return json($res);
  443. }
  444. public function addTalentCommonFile() {
  445. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  446. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  447. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  448. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  449. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  450. if ($backName == "EpChangeEdit.callBack") {
  451. $type = 1;
  452. $error = "文件格式不正确,只能上传图片";
  453. } else {
  454. $type = 4;
  455. $error = "文件格式不正确,只能上传pdf和图片";
  456. }
  457. $uploadapi = new UploadApi();
  458. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  459. if ($file_check_res->code == 500) {
  460. return \StrUtil::back($file_check_res, "Register.epCallBack");
  461. }
  462. $file_data = [
  463. 'id' => getStringId(),
  464. 'mainId' => $mainId,
  465. 'typeId' => $typeId,
  466. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  467. 'url' => $file_check_res->filepath
  468. ];
  469. if (\StrUtil::isEmpOrNull($id)) {
  470. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  471. if ($tc) {
  472. $file_data['sn'] = $tc['sn'] + 1;
  473. } else {
  474. $file_data['sn'] = 1;
  475. }
  476. $file_data['createTime'] = date("Y-m-d H:i:s");
  477. TalentCommonFile::create($file_data);
  478. $response_object = new \StdClass();
  479. $response_object->code = 200;
  480. $response_object->msg = "附件上传成功!";
  481. $response_object->obj = $index;
  482. return \StrUtil::back($response_object, $backName);
  483. } else {
  484. $tf = TalentCommonFile::findOrEmpty($id);
  485. $tf->originalName = $file_data['orignName'];
  486. $tf->updateTime = date("Y-m-d H:i:s");
  487. $tf->url = $file_check_res->filepath;
  488. $tf->save();
  489. $response_object = new \StdClass();
  490. $response_object->code = 200;
  491. $response_object->msg = "附件修改成功!";
  492. $response_object->obj = $index;
  493. return \StrUtil::back($response_object, $backName);
  494. }
  495. }
  496. public function changePwd() {
  497. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  498. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  499. //数据校验(原密码与新密码不能为空)
  500. if (\StrUtil::isEmpOrNull($password)) {
  501. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  502. }
  503. if (\StrUtil::isEmpOrNull($newPassword)) {
  504. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  505. }
  506. try {
  507. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  508. $ep = EnterpriseApi::getOne(session("user")['uid']);
  509. if (!$ep) {
  510. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  511. }
  512. if ($ep->password != hash('md5', $password)) {
  513. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  514. }
  515. $ep->password = hash('md5', $newPassword);
  516. $ep->updateUser = session("user")['uid'];
  517. $ep->updateTime = date("Y-m-d H:i:s");
  518. $ep->save();
  519. TalentChecklog::create([
  520. 'id' => getStringId(),
  521. 'category' => 'enterprise_change',
  522. 'mainId' => $ep->id,
  523. 'type' => 10,
  524. 'typeField' => null,
  525. 'active' => 1,
  526. 'state' => 1,
  527. 'step' => 100,
  528. 'stateChange' => null,
  529. 'description' => '用户修改密码',
  530. 'createTime' => date("Y-m-d H:i:s", time()),
  531. 'createUser' => '用户'
  532. ]);
  533. return json(['code' => 200, 'msg' => "修改成功!"]);
  534. } catch (ValidateException $e) {
  535. $error = $e->getError();
  536. return json(['code' => 500, 'msg' => array_pop($error)]);
  537. }
  538. }
  539. }