Api.php 49 KB

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