Api.php 36 KB

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