Api.php 48 KB

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