Api.php 30 KB

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