Api.php 30 KB

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