Api.php 60 KB

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