Api.php 37 KB

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