Api.php 38 KB

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