Api.php 36 KB

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