Api.php 25 KB

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