Api.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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. return json(["rows" => $new_list]);
  317. }
  318. public function findCommonFileType() {
  319. $param = $this->request->param();
  320. $id = $param["mainId"];
  321. $source = $param["source"];
  322. $order = $param["order"];
  323. $project = $param["project"];
  324. $type = $param["type"];
  325. $checkState = $param["checkState"];
  326. $isMix = $param["isMix"] ?: 0;
  327. $talent_condition = $param["talent_condition"];
  328. $token = $param["pageToken"];
  329. $where[] = ["project", "=", $project];
  330. $where[] = ["active", "=", 1];
  331. $where[] = ["delete", "=", 0];
  332. $where[] = ["type", "=", $type];
  333. switch ($project) {
  334. case 1:
  335. case 8:
  336. //if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, 0, TalentState::FST_SAVE, TalentState::FST_SUBMIT, TalentState::BASE_VERIFY_PASS]) && $isMix != 1) {
  337. //$where[] = ["step", "=", 1]; //只查找人才第一步所需文件
  338. //} else {
  339. $where[] = ["isConditionFile", "<>", 1]; //排除人才条件上传文件
  340. //}
  341. if (($talent_condition && in_array($source, [3, 4, 5])) || $type == \app\common\state\CommonConst::ENTERPRISE_WJ || $type == \app\common\state\CommonConst::ENTERPRISE_GJ) {
  342. $condition_info = Db::table("new_talent_condition")->findOrEmpty($talent_condition);
  343. if ($condition_info["bindFileTypes"]) {
  344. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  345. }
  346. }
  347. break;
  348. case 20:
  349. //积分申报的附件需要特殊处理
  350. $newList = [];
  351. $_where = $where;
  352. $_where[] = ["isConditionFile", "=", 1];
  353. $fileTypes = Db::table("new_common_filetype")->where($_where)->order("must asc")->order("sn " . $order)->select()->toArray();
  354. foreach ($fileTypes as $k => $ft) {
  355. $_whr = [];
  356. if ($id) {
  357. $_whr[] = ["mainId", "=", $id];
  358. } else {
  359. $_whr[] = ["description", "=", $token];
  360. }
  361. $_whr[] = ["relationId", "=", 0];
  362. $_whr[] = ["typeId", "=", $ft["id"]];
  363. $files = Db::table("new_talent_file")->where($_whr)->field("id,typeId,orignName,url,relationId")->order("sn asc")->select()->toArray();
  364. foreach ($files as $n => $file) {
  365. $files[$n]["ext"] = pathinfo($file["url"])["extension"];
  366. $files[$n]["url"] = getStoragePath($file["url"]);
  367. }
  368. $fileTypes[$k]["files"] = $files;
  369. }
  370. $newList[] = [
  371. "id" => 0,
  372. "name" => "公共附件",
  373. "fileTypes" => $fileTypes
  374. ];
  375. $itemIds = $param["itemId"];
  376. $redis = \app\common\Redis::instance(\think\facade\Config::get("cache.stores.redis.select"));
  377. if ($itemIds) {
  378. foreach ($itemIds as $key => $item_id) {
  379. $integral_item = json_decode($redis->hGet("IntegralItem", $item_id), true);
  380. if ($integral_item["fileTypeId"]) {
  381. $typeIds = array_filter(explode(",", $integral_item["fileTypeId"]));
  382. $whr = $where;
  383. $whr[] = ["id", "in", $typeIds];
  384. $whr[] = ["isConditionFile", "=", 0];
  385. $fileTypes = Db::table("new_common_filetype")->where($whr)->order("must asc")->order("sn " . $order)->select()->toArray();
  386. foreach ($fileTypes as $k => $ft) {
  387. $_whr = [];
  388. if ($id) {
  389. $_whr[] = ["mainId", "=", $id];
  390. } else {
  391. $_whr[] = ["description", "=", $token];
  392. }
  393. $_whr[] = ["relationId", "=", $item_id];
  394. $_whr[] = ["typeId", "=", $ft["id"]];
  395. $files = Db::table("new_talent_file")->where($_whr)->field("id,typeId,orignName,url,relationId")->order("sn asc")->select()->toArray();
  396. foreach ($files as $n => $file) {
  397. $files[$n]["ext"] = pathinfo($file["url"])["extension"];
  398. $files[$n]["url"] = getStoragePath($file["url"]);
  399. }
  400. $fileTypes[$k]["files"] = $files;
  401. }
  402. $newList[] = [
  403. "id" => $integral_item["id"],
  404. "name" => $integral_item["name"],
  405. "fileTypes" => $fileTypes
  406. ];
  407. }
  408. }
  409. }
  410. return json(["rows" => $newList]);
  411. break;
  412. }
  413. if ($whr) {
  414. $rows = Db::table("new_common_filetype")->whereOr([$where, $whr])->order("must asc")->order("sn " . $order)->select()->toArray();
  415. } else {
  416. $rows = Db::table("new_common_filetype")->where($where)->order("must asc")->order("sn " . $order)->select()->toArray();
  417. }
  418. if ($id) {
  419. foreach ($rows as $key => $row) {
  420. $where = [];
  421. $where[] = ["mainId", "=", $id];
  422. $where[] = ["typeId", "=", $row["id"]];
  423. $files = Db::table("new_talent_file")->where($where)->field("id,typeId,orignName,url")->order("sn asc")->select()->toArray();
  424. foreach ($files as &$file) {
  425. $file["ext"] = pathinfo($file["url"])["extension"];
  426. $file["url"] = getStoragePath($file["url"]);
  427. }
  428. $rows[$key]["files"] = $files;
  429. }
  430. }
  431. return json(["rows" => $rows]);
  432. }
  433. public function listTalentFile() {
  434. $param = $this->request->param();
  435. $mainId = $param["mainId"];
  436. $typeId = $param["fileTypeId"];
  437. $where = [["mainId", "=", $mainId], ["typeId", "=", $typeId]];
  438. $list = Db::table("new_talent_file")->where($where)->select()->toArray();
  439. foreach ($list as $key => $item) {
  440. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  441. $list[$key]["url"] = getStoragePath($item["url"]);
  442. }
  443. return json($list);
  444. }
  445. public function listNonPredefinedFiles() {
  446. $param = $this->request->param();
  447. $memo = $param["batch"];
  448. $fileTag = $param["fileTag"];
  449. $where = [["fileTag", "=", $fileTag], ["memo", "=", $memo]];
  450. $list = Db::table("new_non_predefined_file")->where($where)->select()->toArray();
  451. foreach ($list as $key => $item) {
  452. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  453. $list[$key]["url"] = getStoragePath($item["url"]);
  454. }
  455. return json(["rows" => $list]);
  456. }
  457. public function addTalentFile() {
  458. $backName = $this->request->param("backName");
  459. $fileId = $this->request->param("fileId");
  460. $mainId = $this->request->param("mainId");
  461. $fileTypeId = $this->request->param("fileTypeId");
  462. $relationId = $this->request->param("relationId");
  463. $pageToken = $this->request->param("pageToken");
  464. $index = $this->request->param("index");
  465. $type = $this->request->param("type");
  466. $upload = new \app\common\api\UploadApi();
  467. $file = $this->request->file("fileUrl");
  468. $isFileEditable = false;
  469. switch ($type) {
  470. case ProjectState::INTEGRAL:
  471. $isFileEditable = \app\common\api\IntegralRecordApi::checkIsEditable($mainId);
  472. break;
  473. default:
  474. $isFileEditable = TalentApi::checkIsEditable($mainId);
  475. break;
  476. }
  477. if (!$isFileEditable) {
  478. $res = ["msg" => "当前状态不能修改附件", "obj" => $index];
  479. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  480. exit();
  481. }
  482. $mime = $file->getMime();
  483. switch ($mime) {
  484. case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"://xlsx
  485. case "application/pdf"://pdf
  486. case "application/vnd.ms-excel"://xls
  487. $filestd = $upload->uploadOne($file, "file", "talent_files");
  488. break;
  489. case "image/jpg":
  490. case "image/jpeg":
  491. case "image/png":
  492. case "image/gif":
  493. $filestd = $upload->uploadOne($file, "image", "talent_files");
  494. break;
  495. default:
  496. $res = ["msg" => "不支持的附件类型", "obj" => $index];
  497. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  498. exit();
  499. break;
  500. }
  501. $change = false;
  502. if ($fileId) {
  503. if (!$this->chkIsFileOwner($mainId, $type)) {
  504. $res = ["msg" => "删除失败", "obj" => $index];
  505. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  506. exit();
  507. }
  508. $old = Db::table("new_talent_file")->findOrEmpty($fileId);
  509. $old_filepath = "storage/" . $old["url"];
  510. if (file_exists($old_filepath))
  511. unlink($old_filepath);
  512. $data["id"] = $fileId;
  513. $change = true;
  514. }
  515. $data["mainId"] = $mainId;
  516. $data["relationId"] = $relationId;
  517. $data["description"] = $pageToken;
  518. $data["type"] = $type;
  519. $data["typeId"] = $fileTypeId;
  520. $data["orignName"] = $file->getOriginalName();
  521. $data["url"] = $filestd->filepath;
  522. $data["sn"] = $index;
  523. $data["createTime"] = date("Y-m-d H:i:s");
  524. if ($fileId) {
  525. Db::table("new_talent_file")->save($data);
  526. } else {
  527. $fileId = Db::table("new_talent_file")->insertGetId($data);
  528. }
  529. $ext = pathinfo($filestd->filepath)["extension"];
  530. TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
  531. $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "ext" => $ext, "info" => getStoragePath($filestd->filepath), "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
  532. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  533. }
  534. public function deleteFile() {
  535. $param = $this->request->param();
  536. $where = [["id", "=", $param["id"]]];
  537. $file = Db::table("new_talent_file")->where($where)->findOrEmpty();
  538. if (!TalentApi::checkIsEditable($file["mainId"]))
  539. return json(["msg" => "当前状态不能删除或者文件已删除,请刷新重试。"]);
  540. if ($this->chkIsFileOwner($file["mainId"], $file["type"])) {
  541. if (!empty($file["url"])) {
  542. $filepath = "storage/" . $file["url"];
  543. if (file_exists($filepath)) {
  544. unlink($filepath);
  545. }
  546. }
  547. Db::table("new_talent_file")->delete($file["id"]);
  548. TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  549. return json(["code" => 200, "msg" => "删除成功"]);
  550. }
  551. return json(["msg" => "不能删除"]);
  552. }
  553. public function deleteTalentCommonFile() {
  554. $param = $this->request->param();
  555. $where = [["id", "=", $param["id"]]];
  556. $file = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  557. $filepath = "storage/" . $file["url"];
  558. if (file_exists($filepath)) {
  559. unlink($filepath);
  560. }
  561. Db::table("new_talent_common_file")->delete($file["id"]);
  562. //TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  563. return json(["code" => 200, "msg" => "删除成功"]);
  564. return json(["msg" => "不能删除"]);
  565. }
  566. public function deleteNonPredefinedFile() {
  567. $param = $this->request->param();
  568. $where = [["id", "=", $param["id"]]];
  569. $file = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  570. $filepath = "storage/" . $file["url"];
  571. if (file_exists($filepath) && $file["url"]) {
  572. @unlink($filepath);
  573. }
  574. Db::table("new_non_predefined_file")->delete($file["id"]);
  575. return json(["code" => 200, "msg" => "删除成功"]);
  576. }
  577. /**
  578. * 下载文件
  579. */
  580. public function downloadFile() {
  581. $param = $this->request->param();
  582. $type = $param["type"];
  583. $id = $param["id"];
  584. $where = [];
  585. $where[] = ["id", "=", $id];
  586. $url = "";
  587. switch ($type) {
  588. case 1:
  589. case 8:
  590. case 19:
  591. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  592. $filename = $fileinfo["orignName"];
  593. $url = $fileinfo["url"];
  594. break;
  595. case 2:
  596. $fileinfo = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  597. $filename = $fileinfo["orignName"];
  598. $url = $fileinfo["url"];
  599. break;
  600. case 3:
  601. $fileinfo = Db::table("new_currency_filetype")->where($where)->findOrEmpty();
  602. $filename = $fileinfo["templateUrl"];
  603. $url = $fileinfo["templateUrl"];
  604. break;
  605. case 4:
  606. $fileinfo = Db::table("sys_common_file")->where($where)->findOrEmpty();
  607. $filename = $fileinfo["orignName"];
  608. $url = $fileinfo["url"];
  609. break;
  610. case 5:
  611. $fileinfo = Db::table("new_common_filetype")->where($where)->findOrEmpty();
  612. $filename = $fileinfo["templateUrl"];
  613. $url = $fileinfo["templateUrl"];
  614. break;
  615. case 6://预定义外的文件类型下载
  616. $fileinfo = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  617. $filename = $fileinfo["originalName"];
  618. $url = $fileinfo["url"];
  619. break;
  620. }
  621. $filepath = "storage/" . $url; // 下载文件名
  622. if (!file_exists($filepath)) {
  623. header('HTTP/1.1 404 NOT FOUND');
  624. } else {
  625. $file = fopen($filepath, "rb");
  626. Header("Content-type: application/octet-stream");
  627. Header("Accept-Ranges: bytes");
  628. Header("Accept-Length: " . filesize($filepath));
  629. Header("Content-Disposition: attachment; filename=" . $filename);
  630. echo fread($file, filesize($filepath));
  631. fclose($file);
  632. exit();
  633. }
  634. }
  635. /**
  636. * 打包下载人才申请附件
  637. */
  638. public function downloadZip() {
  639. $table = "new_talent_file";
  640. $param = $this->request->param();
  641. $type = $param["type"];
  642. $id = $param["id"];
  643. $where = [];
  644. switch ($type) {
  645. case ProjectState::TALENT:
  646. $where[] = ["type", "=", $type];
  647. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  648. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  649. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  650. break;
  651. case ProjectState::QUIT:
  652. $table = "new_talent_common_file";
  653. $info = \app\common\model\TalentQuit::findOrEmpty($id);
  654. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  655. $zip_filename = sprintf("%s(%s)离职材料.zip", $info["talentName"], $enterprise_info["name"]);
  656. break;
  657. case ProjectState::WORKCHANGE:
  658. $table = "new_talent_common_file";
  659. $info = \app\common\model\TalentWorkUnitChange::findOrEmpty($id);
  660. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  661. $zip_filename = sprintf("%s(%s)工作单位变更材料.zip", $info["talentName"], $enterprise_info["name"]);
  662. break;
  663. case ProjectState::LEVELCHANGE:
  664. $info = \app\enterprise\model\TalentTypeChange::findOrEmpty($id);
  665. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  666. $zip_filename = sprintf("%s(%s)人才层次变更材料.zip", $info["talentName"], $enterprise_info["name"]);
  667. break;
  668. case ProjectState::INTEGRAL:
  669. $where[] = ["type", "=", $type];
  670. $record = \app\common\api\IntegralRecordApi::getOne($id);
  671. $zip_filename = sprintf("%s(%s)积分申报材料.zip", $record["name"], $record["enterprise"]["name"]);
  672. break;
  673. case 109:
  674. $table = "un_enterpriseclose_record";
  675. $record = \app\common\model\EnterpriseCloseAccount::where("id", $id)->find();
  676. $zip_filename = sprintf("%s(%s)注销申请材料.zip", $record["name"], $record["username"]);
  677. $files = json_decode($record["files"], true);
  678. break;
  679. }
  680. $where[] = ["mainId", "=", $id];
  681. if (!$files)
  682. $files = Db::table($table)->where($where)->select()->toArray();
  683. if (!$files){
  684. //die("没有附件不能打包下载");
  685. echo "<script>parent.layer.alert('没有附件不能打包下载');window.history.go(-1);</script>";
  686. }
  687. $tmp_path = "storage/temp/";
  688. $tmp_file_path = $tmp_path . $zip_filename;
  689. if (!file_exists($tmp_path)) {
  690. mkdir($tmp_path);
  691. }
  692. $zip = new \ZipArchive();
  693. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  694. header('HTTP/1.1 404 NOT FOUND');
  695. }
  696. foreach ($files as $file) {
  697. if (is_array($file)) {
  698. $filepath = "storage/" . $file["url"];
  699. $fileTypeInfo = Db::table("new_common_filetype")->where("id", $file["typeId"])->find();
  700. $filename = $fileTypeInfo["name"] . "/" . $file["orignName"];
  701. $zip->addFile($filepath, $filename);
  702. } else {
  703. $filepath = "storage/" . $file;
  704. $filename = basename($filepath);
  705. $zip->addFile($filepath, $filename);
  706. }
  707. }
  708. $zip->close();
  709. if (file_exists($tmp_file_path)) {
  710. header("Cache-Control: public");
  711. header("Content-Description: File Transfer");
  712. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  713. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  714. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  715. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  716. @readfile($tmp_file_path);
  717. }
  718. //删除临时文件
  719. @unlink($tmp_file_path);
  720. }
  721. private function chkIsFileOwner($mainId, $type) {
  722. if (!$mainId)
  723. return true;
  724. switch ($type) {
  725. case ProjectState::TALENT:
  726. if ($this->user["usertype"] == 2) {
  727. $user_id = $this->user["uid"];
  728. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  729. if ($user_id == $talent_info["enterprise_id"])
  730. return true;
  731. }
  732. break;
  733. case ProjectState::EDUCATION:
  734. if ($this->user["usertype"] == 3) {
  735. $user_id = $this->user["uid"];
  736. $talent_info = \app\common\model\EducationSchool::findOrEmpty($mainId);
  737. if ($user_id == $talent_info["personId"])
  738. return true;
  739. }
  740. break;
  741. case ProjectState::LEVELCHANGE:
  742. if ($this->user["usertype"] == 2) {
  743. $user_id = $this->user["uid"];
  744. $talent_info = \app\enterprise\model\TalentTypeChange::findOrEmpty($mainId);
  745. if ($user_id == $talent_info["enterpriseId"])
  746. return true;
  747. }
  748. break;
  749. case ProjectState::LIVINGALLOWANCE:
  750. if ($this->user["usertype"] == 2) {
  751. $user_id = $this->user["uid"];
  752. $record = Db::table("md_living_allowance_info")->findOrEmpty($mainId);
  753. if ($user_id == $record["enterpriseId"])
  754. return true;
  755. }
  756. break;
  757. case ProjectState::INTEGRAL:
  758. if ($this->user["usertype"] == 2) {
  759. $user_id = $this->user["uid"];
  760. $record = Db::table("new_integral_record")->findOrEmpty($mainId);
  761. if ($user_id == $record["enterprise_id"])
  762. return true;
  763. }
  764. break;
  765. }
  766. return false;
  767. }
  768. public function getCompanyKvs() {
  769. $companys = \app\common\model\Company::field("name,id")->select();
  770. return json($companys);
  771. }
  772. public function getLayerCatsByLayer() {
  773. $lv = $this->request->param("level");
  774. return json(DictApi::getLayerCatsByLayer($lv));
  775. }
  776. /**
  777. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  778. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  779. */
  780. public function getConditionFileTypesByType() {
  781. $params = $this->request->param();
  782. $type = $params["type"]; //人才类型不默认,需要传
  783. $declare_type = $params["project"] ?: 1; //默认人才认定
  784. $active = $params["active"] ?: 1; //默认查找启用的附件
  785. $where[] = ["type", "=", $type];
  786. $where[] = ["project", "=", $declare_type];
  787. $where[] = ["active", "=", $active];
  788. $where[] = ["delete", "=", 0];
  789. $where[] = ["isConditionFile", "=", 1];
  790. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  791. return json($list);
  792. }
  793. public function listCurrencyFileType() {
  794. $where = [
  795. 'type' => $this->request['type'],
  796. 'active' => 1
  797. ];
  798. $rows = CurrentcyFileType::where($where)->select();
  799. return json(["rows" => $rows, 'total' => count($rows)]);
  800. }
  801. public function listTalentCommonFile() {
  802. $where = [];
  803. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  804. $where[] = ['mainId', '=', $this->request['mainId']];
  805. }
  806. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  807. $where[] = ['typeId', '=', $this->request['typeId']];
  808. }
  809. $res = TalentCommonFile::where($where)->order('sn')->select();
  810. if ($res) {
  811. foreach ($res as $k => &$v) {
  812. $v["ext"] = pathinfo($v["url"])["extension"];
  813. $v['url'] = getStoragePath($v['url']);
  814. }
  815. }
  816. return json($res);
  817. }
  818. public function addTalentCommonFile() {
  819. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  820. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  821. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  822. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  823. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  824. if ($backName == "EpChangeEdit.callBack") {
  825. $type = 1;
  826. $error = "文件格式不正确,只能上传图片";
  827. } else {
  828. $type = 4;
  829. $error = "文件格式不正确,只能上传pdf和图片";
  830. }
  831. $uploadapi = new UploadApi();
  832. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  833. if ($file_check_res->code == 500) {
  834. $file_check_res->obj = $index;
  835. return \StrUtil::back($file_check_res, $backName);
  836. }
  837. $file_data = [
  838. 'id' => getStringId(),
  839. 'mainId' => $mainId,
  840. 'typeId' => $typeId,
  841. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  842. 'url' => $file_check_res->filepath
  843. ];
  844. if (\StrUtil::isEmpOrNull($id)) {
  845. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  846. if ($tc) {
  847. $file_data['sn'] = $tc['sn'] + 1;
  848. } else {
  849. $file_data['sn'] = 1;
  850. }
  851. $file_data['createTime'] = date("Y-m-d H:i:s");
  852. TalentCommonFile::create($file_data);
  853. $response_object = new \StdClass();
  854. $response_object->code = 200;
  855. $response_object->msg = "附件上传成功!";
  856. $response_object->obj = $index;
  857. return \StrUtil::back($response_object, $backName);
  858. } else {
  859. $tf = TalentCommonFile::findOrEmpty($id);
  860. $tf->originalName = $file_data['orignName'];
  861. $tf->updateTime = date("Y-m-d H:i:s");
  862. $tf->url = $file_check_res->filepath;
  863. $tf->save();
  864. $response_object = new \StdClass();
  865. $response_object->code = 200;
  866. $response_object->msg = "附件修改成功!";
  867. $response_object->obj = $index;
  868. return \StrUtil::back($response_object, $backName);
  869. }
  870. }
  871. public function changePwd() {
  872. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  873. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  874. //数据校验(原密码与新密码不能为空)
  875. if (\StrUtil::isEmpOrNull($password)) {
  876. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  877. }
  878. if (\StrUtil::isEmpOrNull($newPassword)) {
  879. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  880. }
  881. try {
  882. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  883. $ep = EnterpriseApi::getOne(session("user")['uid']);
  884. if (!$ep) {
  885. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  886. }
  887. if ($ep->password != hash('md5', $password)) {
  888. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  889. }
  890. $ep->password = hash('md5', $newPassword);
  891. $ep->updateUser = session("user")['uid'];
  892. $ep->updateTime = date("Y-m-d H:i:s");
  893. $ep->save();
  894. TalentChecklog::create([
  895. 'id' => getStringId(),
  896. 'category' => 'enterprise_change',
  897. 'mainId' => $ep->id,
  898. 'type' => 10,
  899. 'typeFileId' => null,
  900. 'active' => 1,
  901. 'state' => 1,
  902. 'step' => 100,
  903. 'stateChange' => null,
  904. 'description' => '用户修改密码',
  905. 'createTime' => date("Y-m-d H:i:s", time()),
  906. 'createUser' => '用户'
  907. ]);
  908. return json(['code' => 200, 'msg' => "修改成功!"]);
  909. } catch (ValidateException $e) {
  910. $error = $e->getError();
  911. return json(['code' => 500, 'msg' => array_pop($error)]);
  912. }
  913. }
  914. function getIntegralRecordByIdCard() {
  915. $cardType = $this->request->param("cardType");
  916. $cardNumber = $this->request->param("cardNumber");
  917. $tips = \app\common\api\IntegralRecordApi::getIntegralRecordByIdCard($cardType, $cardNumber);
  918. return json(["tips" => $tips]);
  919. }
  920. function getIntegralProjectsByType() {
  921. $projectType = $this->request->param("projectType") ?: 0;
  922. if (session("user")["usertype"] == 2) {
  923. $where[] = ["type", "=", 2];
  924. } else {
  925. $type = $this->request->param("type") ?: 0;
  926. $where[] = ["type", "=", $type];
  927. }
  928. $where[] = ["projectType", "=", $projectType];
  929. $where[] = ["active", "=", 1];
  930. $list = \app\common\api\IntegralProjectApi::getAll($where);
  931. return json($list);
  932. }
  933. public function getIntegralItemsByProject() {
  934. $projectId = $this->request->param("projectId") ?: 0;
  935. $where[] = ["projectId", "=", $projectId];
  936. $where[] = ["active", "=", 1];
  937. $list = \app\common\api\IntegralItemApi::getAll($where);
  938. return json($list);
  939. }
  940. public function calIntegral() {
  941. $params = $this->request->param();
  942. $enterpriseId = $params["enterpriseId"];
  943. $cardType = $params["cardType"];
  944. $cardNumber = $params["cardNumber"];
  945. $itemId = $params["itemId"];
  946. $amount = $params["amount"];
  947. if (session("user")["usertype"] == 2) {
  948. //企业端只能通过企业自身id来查询积分
  949. $enterpriseId = session("user")["uid"];
  950. }
  951. return json(\app\common\api\IntegralRecordApi::calIntegral($enterpriseId, $cardType, $cardNumber, $itemId, $amount));
  952. }
  953. public function imgViewer() {
  954. $img = urldecode($this->request["picShow"]);
  955. return view("", ["img" => $img]);
  956. }
  957. public function gotoFileShow() {
  958. return view("admin@talent/filesShow");
  959. }
  960. }