Api.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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. $showAll = $params["showAll"] == 1 ? true : false;
  39. if ($id) {
  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"], $showAll);
  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. $userType = session("user")["usertype"];
  78. $params = $this->request->param();
  79. $mainId = $params["mainId"];
  80. $enterpriseId = $params["enterpriseId"];
  81. $category = $params["category"];
  82. $type = $params["type"];
  83. $list = [];
  84. switch ($type) {
  85. case 1:
  86. $talentInfo = TalentApi::getOne($mainId);
  87. $talent_condition = TalentConditionApi::getOne($talentInfo["talent_condition"]);
  88. case 2:
  89. case 3:
  90. case 4:
  91. case 6:
  92. case 7:
  93. case 8:
  94. case 9:
  95. case 19:
  96. case 20:
  97. $list = TalentLogApi::getList($type, $mainId);
  98. break;
  99. case 10:
  100. if ($enterpriseId) {
  101. $where[] = ["mainId", "=", $enterpriseId];
  102. $ids = \app\enterprise\model\EnterpriseRecord::where($where)->column("id");
  103. $ids[] = $enterpriseId;
  104. $where = [];
  105. $where[] = ["type", "=", $type];
  106. $where[] = ["active", "=", 1];
  107. $where[] = ["mainId", "in", $ids];
  108. $list = TalentChecklog::where($where)->order("createTime desc")->select();
  109. } else {
  110. $list = TalentLogApi::getList($type, $mainId);
  111. }
  112. break;
  113. }
  114. $new_list = [];
  115. foreach ($list as $key => $item) {
  116. if (($item["createUser"] == "系统" || $item["updateUser"] == "系统") && $userType != 1)//非管理员用户不显示系统自动生成或修改的日志
  117. continue;
  118. $new_item["description"] = $item["description"];
  119. switch ($item['type']) {
  120. case 2:
  121. case 3:
  122. case 4:
  123. case 6:
  124. case 7:
  125. case 8:
  126. case 9:
  127. case 19:
  128. $new_item["stateName"] = \app\common\state\LivingAllowanceState::getStateName($item["state"]);
  129. $new_item["stepName"] = \app\common\state\LivingAllowanceState::getStepName($item["step"]);
  130. $new_item["stateChange"] = $item["stateChange"];
  131. break;
  132. case 20:
  133. $new_item["stepName"] = IntegralState::getLogStepName($item["state"]);
  134. $new_item["stateName"] = IntegralState::getLogStateName($item["state"], $item["last_state"]);
  135. if ($item["last_state"] && $item["new_state"]) {
  136. $new_item["stateChange"] = sprintf("%s -> %s", IntegralState::getLogChangeName($item["last_state"]), IntegralState::getLogChangeName($item["new_state"], $item["last_state"]));
  137. } else {
  138. $new_item["stateChange"] = "";
  139. }
  140. break;
  141. case 10:
  142. if ($item["category"] == "enterprise_change") {
  143. switch ($item['step']) {
  144. case 100:
  145. $new_item["stepName"] = "<span class='label'>用户操作</span>";
  146. break;
  147. case 101:
  148. $new_item["stepName"] = "<span class='label label-primary'>审核</span>";
  149. break;
  150. case 102:
  151. $new_item["stepName"] = "<span class='label label-danger'>设置冻结</span>";
  152. break;
  153. case 103:
  154. $new_item["stepName"] = "<span class='label label-info'>重置密码</span>";
  155. break;
  156. }
  157. if ($category == "close_account") {
  158. $new_item["stateName"] = \app\common\state\MainState::getStateName($item['state']);
  159. } else {
  160. switch ($item['state']) {
  161. case 1:
  162. if ($item["stateChange"]) {
  163. $new_item["stateName"] = "<span class='label label-success'>待提交</span>";
  164. } else {
  165. $item['stateChange'] = "修改密码";
  166. }
  167. break;
  168. case 2:
  169. $new_item["stateName"] = "<span class='label label-success'>待审核</span>";
  170. break;
  171. case 3:
  172. $new_item["stateName"] = "<span class='label label-danger'>审核驳回</span>";
  173. break;
  174. case 4:
  175. $new_item["stateName"] = "<span class='label label-primary'>审核通过</span>";
  176. break;
  177. case 5:
  178. $new_item["stateName"] = "<span class='label label-warm'>重新提交</span>";
  179. break;
  180. case 6:
  181. $new_item["stateName"] = "<span class='label label-danger'>初审驳回</span>";
  182. break;
  183. case 7:
  184. $new_item["stateName"] = "<span class='label label-primary'>初审通过</span>";
  185. break;
  186. }
  187. }
  188. $new_item["stateChange"] = $item['stateChange'];
  189. } else {
  190. switch ($item['step']) {
  191. case 100:
  192. $new_item["stepName"] = "<span class='label'>用户操作</span>";
  193. break;
  194. case 101:
  195. $new_item["stepName"] = "<span class='label label-primary'>注册审核</span>";
  196. break;
  197. case 102:
  198. $new_item["stepName"] = "<span class='label label-danger'>设置冻结</span>";
  199. break;
  200. case 103:
  201. $new_item["stepName"] = "<span class='label label-info'>重置密码</span>";
  202. break;
  203. }
  204. switch ($item['state']) {
  205. case 1:
  206. $new_item["stateName"] = "<span class='label label-success'>待审核</span>";
  207. break;
  208. case 2:
  209. $new_item["stateName"] = "<span class='label label-danger'>审核驳回</span>";
  210. break;
  211. case 3:
  212. $new_item["stateName"] = "<span class='label label-primary'>审核通过</span>";
  213. break;
  214. case 4:
  215. $new_item["stateName"] = "<span class='label label-primary'>重新提交</span>";
  216. break;
  217. case 5:
  218. $new_item["stateName"] = "<span class='label label-danger'>初审驳回</span>";
  219. break;
  220. case 6:
  221. $new_item["stateName"] = "<span class='label label-primary'>初审通过</span>";
  222. break;
  223. default:
  224. break;
  225. }
  226. $new_item["stateChange"] = $item['stateChange'];
  227. }
  228. break;
  229. case 1:
  230. if ($item["step"] && $item["step"] != 3) {
  231. $new_item["stepName"] = \app\common\state\LivingAllowanceState::getStepName($item["step"]);
  232. } else {
  233. $new_item["stepName"] = DictApi::getCheckLogStepName($item["state"], $item["step"]);
  234. }
  235. if (in_array($item["state"], [TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
  236. $new_item["stateName"] = '<span class="label label-danger">审核不通过</span>';
  237. } 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])) {
  238. if ($item["step"] == 3) {
  239. if ($item["new_state"] == TalentState::SCND_SUBMIT) {
  240. $new_item["stateName"] = '<span class="label label-danger">审核驳回</span>';
  241. } else if ($item["new_state"] == TalentState::DEPT_VERIFY_PASS) {
  242. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  243. } else {
  244. $new_item["stateName"] = '<span class="label label-success">待审核</span>';
  245. }
  246. if ($item["active"] === 0 && !in_array($item["companyId"], explode(",", $talent_condition["companyIds"]))) {
  247. $new_item["stateName"] = '<span class="label">已废弃</span>';
  248. }
  249. } else {
  250. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  251. }
  252. } else if (in_array($item["state"], [TalentState::BASE_REJECT, TalentState::BASE_REVERIFY_REJECT, TalentState::FST_VERIFY_REJECT, TalentState::DEPT_VERIFY_REJECT, TalentState::REVERIFY_REJECT])) {
  253. $new_item["stateName"] = '<span class="label label-danger">审核驳回</span>';
  254. } else if (in_array($item["state"], [TalentState::ZX_PASS, TalentState::ANNOUNCED, TalentState::ANNOUNCED_REVERIFY_PASS, TalentState::PUBLISH_PASS, TalentState::CERTIFICATED])) {
  255. $new_item["stateName"] = '<span class="label label-primary">审核通过</span>';
  256. } else if (in_array($item["state"], [TalentState::FST_SAVE, TalentState::SCND_SAVE])) {
  257. $new_item["stateName"] = '<span class="label">保存未提交</span>';
  258. } else if (in_array($item["state"], [TalentState::REVERIFY_CANCEL])) {
  259. $new_item["stateName"] = '<span class="label label-primary">撤销审核</span>';
  260. } else if (!$item["state"]) {
  261. if ($item["typeFileId"]) {
  262. $new_item["stateName"] = '<span class="label">添加附件</span>';
  263. }
  264. } else {
  265. if (($item["last_state"] == TalentState::BASE_REJECT && $item["state"] == TalentState::FST_SUBMIT) || ($item["last_state"] == TalentState::FST_VERIFY_REJECT && $item["state"] == TalentState::SCND_SUBMIT)) {
  266. $new_item["stateName"] = '<span class="label label-success">待审核(重新提交)</span>';
  267. } else {
  268. $new_item["stateName"] = '<span class="label label-success">待审核</span>';
  269. }
  270. }
  271. if ($item["step"] == 3) {
  272. $company = CompanyApi::getOne($item["companyId"]);
  273. if ($item["active"] == 0) {
  274. $new_item["description"] = "等待部门审核";
  275. $new_item["stateChange"] = str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["state"], $item["step"]));
  276. } else {
  277. $new_item["stateChange"] = sprintf("%s -> %s", str_replace("部门", '"' . $company["name"] . '"', DictApi::getTalentInfoStateName($item["state"], $item["step"])), DictApi::getTalentInfoStateName($item["new_state"], $item["step"]));
  278. }
  279. } else {
  280. if ($item["last_state"] && $item["new_state"]) {
  281. $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"]));
  282. } else {
  283. $new_item["stateChange"] = $item["stateChange"] ?: "";
  284. }
  285. }
  286. break;
  287. }
  288. $new_item["createUser"] = $item["updateUser"] && strpos($item["updateUser"], "企业用户") === false ? $item["updateUser"] : $item["createUser"]; //$item["updateUser"] ?: $item["createUser"];
  289. if ($new_item["createUser"] != "用户") {
  290. list($name, $company) = explode("(", $new_item["createUser"]);
  291. $where = [];
  292. $where[] = ["name", "=", $name];
  293. $user = \app\admin\model\User::where($where)->find();
  294. if ($user) {
  295. $new_item["createUser"] = implode("(", [$user["account"], $company]);
  296. }
  297. }
  298. $new_item["createTime"] = $item["updateTime"] ?: $item["createTime"];
  299. $new_list[] = $new_item;
  300. }
  301. if ($type == ProjectState::TALENT) {
  302. if ($talentInfo["oldId"]) {
  303. $where = [];
  304. $where[] = ["mainId", "=", $talentInfo["oldId"]];
  305. $where[] = ["type", "=", ProjectState::TALENT];
  306. $before_list = Db::table("un_talent_checklog")->where($where)->order("createTime desc")->select();
  307. foreach ($before_list as $before_item) {
  308. $new_list[] = [
  309. "stepName" => DictApi::getOldStepNameByStep($before_item["step"]),
  310. "stateName" => DictApi::getOldStateNameByState($before_item["state"]),
  311. "stateChange" => $before_item["stateChange"],
  312. "description" => $before_item["description"],
  313. "createUser" => $before_item["createUser"],
  314. "createTime" => $before_item["createTime"]
  315. ];
  316. }
  317. }
  318. }
  319. if ($type == ProjectState::LEVELCHANGE) {
  320. $where = [];
  321. $where[] = ["mainId", "=", $mainId];
  322. $where[] = ["type", "=", ProjectState::LEVELCHANGE];
  323. $before_list = Db::table("un_talent_checklog")->where($where)->order("createTime desc")->select();
  324. foreach ($before_list as $before_item) {
  325. $new_list[] = [
  326. "stepName" => DictApi::getOldStepNameByStep($before_item["step"]),
  327. "stateName" => DictApi::getOldStateNameByState($before_item["state"]),
  328. "stateChange" => $before_item["stateChange"],
  329. "description" => $before_item["description"],
  330. "createUser" => $before_item["createUser"],
  331. "createTime" => $before_item["createTime"]
  332. ];
  333. }
  334. }
  335. return json(["rows" => $new_list]);
  336. }
  337. public function findCommonFileType() {
  338. $param = $this->request->param();
  339. $id = $param["mainId"];
  340. $source = $param["source"];
  341. $order = $param["order"];
  342. $project = $param["project"];
  343. $type = $param["type"];
  344. $checkState = $param["checkState"];
  345. $isMix = $param["isMix"] ?: 0;
  346. $talent_condition = $param["talent_condition"];
  347. $token = $param["pageToken"];
  348. $where[] = ["project", "=", $project];
  349. $where[] = ["active", "=", 1];
  350. $where[] = ["delete", "=", 0];
  351. $where[] = ["type", "=", $type];
  352. switch ($project) {
  353. case 1:
  354. case 8:
  355. //if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, 0, TalentState::FST_SAVE, TalentState::FST_SUBMIT, TalentState::BASE_VERIFY_PASS]) && $isMix != 1) {
  356. //$where[] = ["step", "=", 1]; //只查找人才第一步所需文件
  357. //} else {
  358. $where[] = ["isConditionFile", "<>", 1]; //排除人才条件上传文件
  359. //}
  360. if (($talent_condition && in_array($source, [3, 4, 5])) || $type == \app\common\state\CommonConst::ENTERPRISE_WJ || $type == \app\common\state\CommonConst::ENTERPRISE_GJ) {
  361. $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
  362. if ($condition_info["bindFileTypes"]) {
  363. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  364. }
  365. }
  366. break;
  367. case 20:
  368. //积分申报的附件需要特殊处理
  369. $newList = [];
  370. $_where = $where;
  371. $_where[] = ["isConditionFile", "=", 1];
  372. $fileTypes = Db::table("new_common_filetype")->where($_where)->order("must asc")->order("sn " . $order)->select()->toArray();
  373. foreach ($fileTypes as $k => $ft) {
  374. $_whr = [];
  375. if ($id) {
  376. $_whr[] = ["mainId", "=", $id];
  377. } else {
  378. $_whr[] = ["description", "=", $token];
  379. }
  380. $_whr[] = ["relationId", "=", 0];
  381. $_whr[] = ["typeId", "=", $ft["id"]];
  382. $files = Db::table("new_talent_file")->where($_whr)->field("id,typeId,orignName,url,relationId")->order("sn asc")->select()->toArray();
  383. foreach ($files as $n => $file) {
  384. $files[$n]["ext"] = pathinfo($file["url"])["extension"];
  385. $files[$n]["url"] = getStoragePath($file["url"]);
  386. }
  387. $fileTypes[$k]["files"] = $files;
  388. }
  389. $newList[] = [
  390. "id" => 0,
  391. "name" => "公共附件",
  392. "fileTypes" => $fileTypes
  393. ];
  394. $itemIds = $param["itemId"];
  395. $redis = \app\common\Redis::instance(\think\facade\Config::get("cache.stores.redis.select"));
  396. if ($itemIds) {
  397. foreach ($itemIds as $key => $item_id) {
  398. $integral_item = json_decode($redis->hGet("IntegralItem", $item_id), true);
  399. if ($integral_item["fileTypeId"]) {
  400. $typeIds = array_filter(explode(",", $integral_item["fileTypeId"]));
  401. $whr = $where;
  402. $whr[] = ["id", "in", $typeIds];
  403. $whr[] = ["isConditionFile", "=", 0];
  404. $fileTypes = Db::table("new_common_filetype")->where($whr)->order("must asc")->order("sn " . $order)->select()->toArray();
  405. foreach ($fileTypes as $k => $ft) {
  406. $_whr = [];
  407. if ($id) {
  408. $_whr[] = ["mainId", "=", $id];
  409. } else {
  410. $_whr[] = ["description", "=", $token];
  411. }
  412. $_whr[] = ["relationId", "=", $item_id];
  413. $_whr[] = ["typeId", "=", $ft["id"]];
  414. $files = Db::table("new_talent_file")->where($_whr)->field("id,typeId,orignName,url,relationId")->order("sn asc")->select()->toArray();
  415. foreach ($files as $n => $file) {
  416. $files[$n]["ext"] = pathinfo($file["url"])["extension"];
  417. $files[$n]["url"] = getStoragePath($file["url"]);
  418. }
  419. $fileTypes[$k]["files"] = $files;
  420. }
  421. $newList[] = [
  422. "id" => $integral_item["id"],
  423. "name" => $integral_item["name"],
  424. "fileTypes" => $fileTypes
  425. ];
  426. }
  427. }
  428. }
  429. return json(["rows" => $newList]);
  430. break;
  431. }
  432. if ($whr) {
  433. $rows = Db::table("new_common_filetype")->whereOr([$where, $whr])->order("must asc")->order("sn " . $order)->select()->toArray();
  434. } else {
  435. $rows = Db::table("new_common_filetype")->where($where)->order("must asc")->order("sn " . $order)->select()->toArray();
  436. }
  437. if ($id) {
  438. foreach ($rows as $key => $row) {
  439. $where = [];
  440. $where[] = ["mainId", "=", $id];
  441. $where[] = ["typeId", "=", $row["id"]];
  442. $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
  443. foreach ($files as &$file) {
  444. $file["ext"] = pathinfo($file["url"])["extension"];
  445. $file["url"] = getStoragePath($file["url"]);
  446. }
  447. $rows[$key]["files"] = $files;
  448. }
  449. }
  450. $old_types = [];
  451. if ($project == ProjectState::LEVELCHANGE) {
  452. $where = [];
  453. $where[] = ["type", "=", $type];
  454. $where[] = ["project", "=", $project];
  455. $where[] = ["active", "=", 1];
  456. //$old_types = Db::table("un_common_filetype")->where($where)->order("must")->order("sn")->select()->toArray();
  457. }
  458. if ($old_types) {
  459. $rows = array_merge($rows, $old_types);
  460. }
  461. return json(["rows" => $rows, "old_types" => $old_types]);
  462. }
  463. public function listTalentFile() {
  464. $param = $this->request->param();
  465. $mainId = $param["mainId"];
  466. $typeId = $param["fileTypeId"];
  467. $where = [["mainId", "=", $mainId], ["typeId", "=", $typeId]];
  468. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  469. $_where = [["mainId", "=", $mainId], ["fileTypeId", "=", $typeId]];
  470. $old_list = Db::table("un_talent_file")->where($_where)->select()->toArray();
  471. if ($old_list) {
  472. $list = array_merge($list, $old_list);
  473. }
  474. foreach ($list as $key => $item) {
  475. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  476. $list[$key]["url"] = getStoragePath($item["url"]);
  477. }
  478. return json($list);
  479. }
  480. public function listNonPredefinedFiles() {
  481. $param = $this->request->param();
  482. $memo = $param["batch"];
  483. $fileTag = $param["fileTag"];
  484. $where = [["fileTag", "=", $fileTag], ["memo", "=", $memo]];
  485. $list = Db::table("new_non_predefined_file")->where($where)->select()->toArray();
  486. foreach ($list as $key => $item) {
  487. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  488. $list[$key]["url"] = getStoragePath($item["url"]);
  489. }
  490. return json(["rows" => $list]);
  491. }
  492. public function addTalentFile() {
  493. $backName = $this->request->param("backName");
  494. $fileId = $this->request->param("fileId");
  495. $mainId = $this->request->param("mainId");
  496. $fileTypeId = $this->request->param("fileTypeId");
  497. $relationId = $this->request->param("relationId");
  498. $pageToken = $this->request->param("pageToken");
  499. $index = $this->request->param("index");
  500. $type = $this->request->param("type");
  501. $upload = new \app\common\api\UploadApi();
  502. $file = $this->request->file("fileUrl");
  503. $isFileEditable = false;
  504. switch ($type) {
  505. case ProjectState::INTEGRAL:
  506. $isFileEditable = \app\common\api\IntegralRecordApi::checkIsEditable($mainId);
  507. break;
  508. default:
  509. $isFileEditable = TalentApi::checkIsEditable($mainId);
  510. break;
  511. }
  512. if (!$isFileEditable) {
  513. $res = ["msg" => "当前状态不能修改附件", "obj" => $index];
  514. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  515. exit();
  516. }
  517. $mime = $file->getMime();
  518. switch ($mime) {
  519. case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"://xlsx
  520. case "application/pdf"://pdf
  521. case "application/vnd.ms-excel"://xls
  522. $filestd = $upload->uploadOne($file, "file", "talent_files");
  523. break;
  524. case "image/jpg":
  525. case "image/jpeg":
  526. case "image/png":
  527. case "image/gif":
  528. $filestd = $upload->uploadOne($file, "image", "talent_files");
  529. break;
  530. default:
  531. $res = ["msg" => "不支持的附件类型", "obj" => $index];
  532. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  533. exit();
  534. break;
  535. }
  536. $change = false;
  537. if ($fileId) {
  538. if (!$this->chkIsFileOwner($mainId, $type)) {
  539. $res = ["msg" => "删除失败", "obj" => $index];
  540. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  541. exit();
  542. }
  543. $old = Db::table("new_talent_file")->findOrEmpty($fileId);
  544. $old_filepath = "storage/" . $old["url"];
  545. if (file_exists($old_filepath))
  546. unlink($old_filepath);
  547. $data["id"] = $fileId;
  548. $change = true;
  549. }
  550. $data["mainId"] = $mainId;
  551. $data["relationId"] = $relationId;
  552. $data["description"] = $pageToken;
  553. $data["type"] = $type;
  554. $data["typeId"] = $fileTypeId;
  555. $data["orignName"] = $file->getOriginalName();
  556. $data["url"] = $filestd->filepath;
  557. $data["sn"] = $index;
  558. $data["createTime"] = date("Y-m-d H:i:s");
  559. if ($fileId) {
  560. Db::table("new_talent_file")->save($data);
  561. } else {
  562. $fileId = Db::table("new_talent_file")->insertGetId($data);
  563. }
  564. $ext = pathinfo($filestd->filepath)["extension"];
  565. TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
  566. $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "ext" => $ext, "info" => getStoragePath($filestd->filepath), "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
  567. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  568. }
  569. public function deleteFile() {
  570. $param = $this->request->param();
  571. $where = [["id", "=", $param["id"]]];
  572. $file = Db::table("new_talent_file")->where($where)->findOrEmpty();
  573. if (!TalentApi::checkIsEditable($file["mainId"]))
  574. return json(["msg" => "当前状态不能删除或者文件已删除,请刷新重试。"]);
  575. if ($this->chkIsFileOwner($file["mainId"], $file["type"])) {
  576. if (!empty($file["url"])) {
  577. $filepath = "storage/" . $file["url"];
  578. if (file_exists($filepath)) {
  579. unlink($filepath);
  580. }
  581. }
  582. Db::table("new_talent_file")->delete($file["id"]);
  583. TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  584. return json(["code" => 200, "msg" => "删除成功"]);
  585. }
  586. return json(["msg" => "不能删除"]);
  587. }
  588. public function deleteTalentCommonFile() {
  589. $param = $this->request->param();
  590. $where = [["id", "=", $param["id"]]];
  591. $file = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  592. $filepath = "storage/" . $file["url"];
  593. if (file_exists($filepath)) {
  594. unlink($filepath);
  595. }
  596. Db::table("new_talent_common_file")->delete($file["id"]);
  597. //TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  598. return json(["code" => 200, "msg" => "删除成功"]);
  599. return json(["msg" => "不能删除"]);
  600. }
  601. public function deleteNonPredefinedFile() {
  602. $param = $this->request->param();
  603. $where = [["id", "=", $param["id"]]];
  604. $file = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  605. $filepath = "storage/" . $file["url"];
  606. if (file_exists($filepath) && $file["url"]) {
  607. @unlink($filepath);
  608. }
  609. Db::table("new_non_predefined_file")->delete($file["id"]);
  610. return json(["code" => 200, "msg" => "删除成功"]);
  611. }
  612. /**
  613. * 下载文件
  614. */
  615. public function downloadFile() {
  616. $param = $this->request->param();
  617. $type = $param["type"];
  618. $id = $param["id"];
  619. $where = [];
  620. $where[] = ["id", "=", $id];
  621. $url = "";
  622. switch ($type) {
  623. case 1:
  624. case 8:
  625. case 19:
  626. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  627. $filename = $fileinfo["orignName"];
  628. $url = $fileinfo["url"];
  629. break;
  630. case 2:
  631. $fileinfo = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  632. $filename = $fileinfo["orignName"];
  633. $url = $fileinfo["url"];
  634. break;
  635. case 3:
  636. $fileinfo = Db::table("new_currency_filetype")->where($where)->findOrEmpty();
  637. $filename = $fileinfo["templateUrl"];
  638. $url = $fileinfo["templateUrl"];
  639. break;
  640. case 4:
  641. $fileinfo = Db::table("sys_common_file")->where($where)->findOrEmpty();
  642. $filename = $fileinfo["orignName"];
  643. $url = $fileinfo["url"];
  644. break;
  645. case 5:
  646. $fileinfo = Db::table("new_common_filetype")->where($where)->findOrEmpty();
  647. $filename = $fileinfo["templateUrl"];
  648. $url = $fileinfo["templateUrl"];
  649. break;
  650. case 6://预定义外的文件类型下载
  651. $fileinfo = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  652. $filename = $fileinfo["originalName"];
  653. $url = $fileinfo["url"];
  654. break;
  655. }
  656. $filepath = "storage/" . $url; // 下载文件名
  657. if (!file_exists($filepath)) {
  658. header('HTTP/1.1 404 NOT FOUND');
  659. } else {
  660. $file = fopen($filepath, "rb");
  661. Header("Content-type: application/octet-stream");
  662. Header("Accept-Ranges: bytes");
  663. Header("Accept-Length: " . filesize($filepath));
  664. Header("Content-Disposition: attachment; filename=" . $filename);
  665. echo fread($file, filesize($filepath));
  666. fclose($file);
  667. exit();
  668. }
  669. }
  670. /**
  671. * 打包下载人才申请附件
  672. */
  673. public function downloadZip() {
  674. $table = "new_talent_file";
  675. $param = $this->request->param();
  676. $type = $param["type"];
  677. $id = $param["id"];
  678. $where = [];
  679. switch ($type) {
  680. case ProjectState::TALENT:
  681. $where[] = ["type", "=", $type];
  682. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  683. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  684. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  685. break;
  686. case ProjectState::QUIT:
  687. $table = "new_talent_common_file";
  688. $info = \app\common\model\TalentQuit::findOrEmpty($id);
  689. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  690. $zip_filename = sprintf("%s(%s)离职材料.zip", $info["talentName"], $enterprise_info["name"]);
  691. break;
  692. case ProjectState::WORKCHANGE:
  693. $table = "new_talent_common_file";
  694. $info = \app\common\model\TalentWorkUnitChange::findOrEmpty($id);
  695. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  696. $zip_filename = sprintf("%s(%s)工作单位变更材料.zip", $info["talentName"], $enterprise_info["name"]);
  697. break;
  698. case ProjectState::LEVELCHANGE:
  699. $info = \app\enterprise\model\TalentTypeChange::findOrEmpty($id);
  700. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  701. $zip_filename = sprintf("%s(%s)人才层次变更材料.zip", $info["talentName"], $enterprise_info["name"]);
  702. break;
  703. case ProjectState::INTEGRAL:
  704. $where[] = ["type", "=", $type];
  705. $record = \app\common\api\IntegralRecordApi::getOne($id);
  706. $zip_filename = sprintf("%s(%s)积分申报材料.zip", $record["name"], $record["enterprise"]["name"]);
  707. break;
  708. case 109:
  709. $table = "un_enterpriseclose_record";
  710. $record = \app\common\model\EnterpriseCloseAccount::where("id", $id)->find();
  711. $zip_filename = sprintf("%s(%s)注销申请材料.zip", $record["name"], $record["username"]);
  712. $files = json_decode($record["files"], true);
  713. break;
  714. }
  715. $where[] = ["mainId", "=", $id];
  716. if (!$files)
  717. $files = Db::table($table)->where($where)->select()->toArray();
  718. if (!$files) {
  719. //die("没有附件不能打包下载");
  720. echo "<script>parent.layer.alert('没有附件不能打包下载');window.history.go(-1);</script>";
  721. }
  722. $tmp_path = "storage/temp/";
  723. $tmp_file_path = $tmp_path . $zip_filename;
  724. if (!file_exists($tmp_path)) {
  725. mkdir($tmp_path);
  726. }
  727. $zip = new \ZipArchive();
  728. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  729. header('HTTP/1.1 404 NOT FOUND');
  730. }
  731. foreach ($files as $file) {
  732. if (is_array($file)) {
  733. $filepath = "storage/" . $file["url"];
  734. $fileTypeInfo = Db::table("new_common_filetype")->where("id", $file["typeId"])->find();
  735. $filename = $fileTypeInfo["name"] . "/" . $file["orignName"];
  736. $zip->addFile($filepath, $filename);
  737. } else {
  738. $filepath = "storage/" . $file;
  739. $filename = basename($filepath);
  740. $zip->addFile($filepath, $filename);
  741. }
  742. }
  743. $zip->close();
  744. if (file_exists($tmp_file_path)) {
  745. header("Cache-Control: public");
  746. header("Content-Description: File Transfer");
  747. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  748. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  749. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  750. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  751. @readfile($tmp_file_path);
  752. }
  753. //删除临时文件
  754. @unlink($tmp_file_path);
  755. }
  756. private function chkIsFileOwner($mainId, $type) {
  757. if (!$mainId)
  758. return true;
  759. switch ($type) {
  760. case ProjectState::TALENT:
  761. if ($this->user["usertype"] == 2) {
  762. $user_id = $this->user["uid"];
  763. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  764. if ($user_id == $talent_info["enterprise_id"])
  765. return true;
  766. }
  767. break;
  768. case ProjectState::JBT:
  769. if ($this->user["usertype"] == 2) {
  770. $user_id = $this->user["uid"];
  771. $talent_info = \app\common\model\TalentAllowance::findOrEmpty($mainId);
  772. if ($user_id == $talent_info["enterpriseId"])
  773. return true;
  774. }
  775. break;
  776. case ProjectState::EDUCATION:
  777. if ($this->user["usertype"] == 3) {
  778. $user_id = $this->user["uid"];
  779. $talent_info = \app\common\model\EducationSchool::findOrEmpty($mainId);
  780. if ($user_id == $talent_info["personId"])
  781. return true;
  782. }
  783. break;
  784. case ProjectState::LEVELCHANGE:
  785. if ($this->user["usertype"] == 2) {
  786. $user_id = $this->user["uid"];
  787. $talent_info = \app\enterprise\model\TalentTypeChange::findOrEmpty($mainId);
  788. if ($user_id == $talent_info["enterpriseId"])
  789. return true;
  790. }
  791. break;
  792. case ProjectState::LIVINGALLOWANCE:
  793. if ($this->user["usertype"] == 2) {
  794. $user_id = $this->user["uid"];
  795. $record = Db::table("md_living_allowance_info")->findOrEmpty($mainId);
  796. if ($user_id == $record["enterpriseId"])
  797. return true;
  798. }
  799. break;
  800. case ProjectState::INTEGRAL:
  801. if ($this->user["usertype"] == 2) {
  802. $user_id = $this->user["uid"];
  803. $record = Db::table("new_integral_record")->findOrEmpty($mainId);
  804. if ($user_id == $record["enterprise_id"])
  805. return true;
  806. }
  807. break;
  808. }
  809. return false;
  810. }
  811. public function getCompanyKvs() {
  812. $companys = \app\common\model\Company::field("name,id")->select();
  813. return json($companys);
  814. }
  815. public function getLayerCatsByLayer() {
  816. $lv = $this->request->param("level");
  817. return json(DictApi::getLayerCatsByLayer($lv));
  818. }
  819. /**
  820. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  821. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  822. */
  823. public function getConditionFileTypesByType() {
  824. $params = $this->request->param();
  825. $type = $params["type"]; //人才类型不默认,需要传
  826. $declare_type = $params["project"] ?: 1; //默认人才认定
  827. $active = $params["active"] ?: 1; //默认查找启用的附件
  828. $where[] = ["type", "=", $type];
  829. $where[] = ["project", "=", $declare_type];
  830. $where[] = ["active", "=", $active];
  831. $where[] = ["delete", "=", 0];
  832. $where[] = ["isConditionFile", "=", 1];
  833. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  834. return json($list);
  835. }
  836. public function listCurrencyFileType() {
  837. $where = [
  838. 'type' => $this->request['type'],
  839. 'active' => 1
  840. ];
  841. $rows = CurrentcyFileType::where($where)->select();
  842. return json(["rows" => $rows, 'total' => count($rows)]);
  843. }
  844. public function listTalentCommonFile() {
  845. $where = [];
  846. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  847. $where[] = ['mainId', '=', $this->request['mainId']];
  848. }
  849. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  850. $where[] = ['typeId', '=', $this->request['typeId']];
  851. }
  852. $res = TalentCommonFile::where($where)->order('sn')->select();
  853. if ($res) {
  854. foreach ($res as $k => &$v) {
  855. $v["ext"] = pathinfo($v["url"])["extension"];
  856. $v['url'] = getStoragePath($v['url']);
  857. }
  858. }
  859. return json($res);
  860. }
  861. public function addTalentCommonFile() {
  862. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  863. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  864. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  865. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  866. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  867. if ($backName == "EpChangeEdit.callBack") {
  868. $type = 1;
  869. $error = "文件格式不正确,只能上传图片";
  870. } else {
  871. $type = 4;
  872. $error = "文件格式不正确,只能上传pdf和图片";
  873. }
  874. $uploadapi = new UploadApi();
  875. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  876. if ($file_check_res->code == 500) {
  877. $file_check_res->obj = $index;
  878. return \StrUtil::back($file_check_res, $backName);
  879. }
  880. $file_data = [
  881. 'id' => getStringId(),
  882. 'mainId' => $mainId,
  883. 'typeId' => $typeId,
  884. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  885. 'url' => $file_check_res->filepath
  886. ];
  887. if (\StrUtil::isEmpOrNull($id)) {
  888. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  889. if ($tc) {
  890. $file_data['sn'] = $tc['sn'] + 1;
  891. } else {
  892. $file_data['sn'] = 1;
  893. }
  894. $file_data['createTime'] = date("Y-m-d H:i:s");
  895. TalentCommonFile::create($file_data);
  896. $response_object = new \StdClass();
  897. $response_object->code = 200;
  898. $response_object->msg = "附件上传成功!";
  899. $response_object->obj = $index;
  900. return \StrUtil::back($response_object, $backName);
  901. } else {
  902. $tf = TalentCommonFile::findOrEmpty($id);
  903. $tf->originalName = $file_data['orignName'];
  904. $tf->updateTime = date("Y-m-d H:i:s");
  905. $tf->url = $file_check_res->filepath;
  906. $tf->save();
  907. $response_object = new \StdClass();
  908. $response_object->code = 200;
  909. $response_object->msg = "附件修改成功!";
  910. $response_object->obj = $index;
  911. return \StrUtil::back($response_object, $backName);
  912. }
  913. }
  914. public function changePwd() {
  915. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  916. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  917. //数据校验(原密码与新密码不能为空)
  918. if (\StrUtil::isEmpOrNull($password)) {
  919. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  920. }
  921. if (\StrUtil::isEmpOrNull($newPassword)) {
  922. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  923. }
  924. try {
  925. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  926. $ep = EnterpriseApi::getOne(session("user")['uid']);
  927. if (!$ep) {
  928. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  929. }
  930. if ($ep->password != hash('md5', $password)) {
  931. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  932. }
  933. $ep->password = hash('md5', $newPassword);
  934. $ep->updateUser = session("user")['uid'];
  935. $ep->updateTime = date("Y-m-d H:i:s");
  936. $ep->save();
  937. TalentChecklog::create([
  938. 'id' => getStringId(),
  939. 'category' => 'enterprise_change',
  940. 'mainId' => $ep->id,
  941. 'type' => 10,
  942. 'typeFileId' => null,
  943. 'active' => 1,
  944. 'state' => 1,
  945. 'step' => 100,
  946. 'stateChange' => null,
  947. 'description' => '用户修改密码',
  948. 'createTime' => date("Y-m-d H:i:s", time()),
  949. 'createUser' => '用户'
  950. ]);
  951. return json(['code' => 200, 'msg' => "修改成功!"]);
  952. } catch (ValidateException $e) {
  953. $error = $e->getError();
  954. return json(['code' => 500, 'msg' => array_pop($error)]);
  955. }
  956. }
  957. function getIntegralRecordByIdCard() {
  958. $cardType = $this->request->param("cardType");
  959. $cardNumber = $this->request->param("cardNumber");
  960. $tips = \app\common\api\IntegralRecordApi::getIntegralRecordByIdCard($cardType, $cardNumber);
  961. return json(["tips" => $tips]);
  962. }
  963. function getIntegralProjectsByType() {
  964. $projectType = $this->request->param("projectType") ?: 0;
  965. if (session("user")["usertype"] == 2) {
  966. $where[] = ["type", "=", 2];
  967. } else {
  968. $type = $this->request->param("type") ?: 0;
  969. $where[] = ["type", "=", $type];
  970. }
  971. $where[] = ["projectType", "=", $projectType];
  972. $where[] = ["active", "=", 1];
  973. $list = \app\common\api\IntegralProjectApi::getAll($where);
  974. return json($list);
  975. }
  976. public function getIntegralItemsByProject() {
  977. $projectId = $this->request->param("projectId") ?: 0;
  978. $where[] = ["projectId", "=", $projectId];
  979. $where[] = ["active", "=", 1];
  980. $list = \app\common\api\IntegralItemApi::getAll($where);
  981. return json($list);
  982. }
  983. public function calIntegral() {
  984. $params = $this->request->param();
  985. $enterpriseId = $params["enterpriseId"];
  986. $cardType = $params["cardType"];
  987. $cardNumber = $params["cardNumber"];
  988. $itemId = $params["itemId"];
  989. $amount = $params["amount"];
  990. if (session("user")["usertype"] == 2) {
  991. //企业端只能通过企业自身id来查询积分
  992. $enterpriseId = session("user")["uid"];
  993. }
  994. return json(\app\common\api\IntegralRecordApi::calIntegral($enterpriseId, $cardType, $cardNumber, $itemId, $amount));
  995. }
  996. public function imgViewer() {
  997. $img = urldecode($this->request["picShow"]);
  998. return view("", ["img" => $img]);
  999. }
  1000. public function gotoFileShow() {
  1001. return view("admin@talent/filesShow");
  1002. }
  1003. }