Api.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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. $change = false;
  622. if ($fileId) {
  623. if (!$this->chkIsFileOwner($mainId, $type)) {
  624. $res = ["msg" => "删除失败", "obj" => $index];
  625. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  626. exit();
  627. }
  628. $old = Db::table("new_talent_file")->findOrEmpty($fileId);
  629. $old_filepath = "storage/" . $old["url"];
  630. if (file_exists($old_filepath))
  631. unlink($old_filepath);
  632. $data["id"] = $fileId;
  633. $change = true;
  634. }
  635. $data["mainId"] = $mainId;
  636. $data["relationId"] = $relationId;
  637. $data["description"] = $pageToken;
  638. $data["type"] = $type;
  639. $data["typeId"] = $fileTypeId;
  640. $data["orignName"] = $file->getOriginalName();
  641. $data["url"] = $filestd->filepath;
  642. $data["sn"] = $index;
  643. $data["createTime"] = date("Y-m-d H:i:s");
  644. if ($fileId) {
  645. Db::table("new_talent_file")->save($data);
  646. } else {
  647. $fileId = Db::table("new_talent_file")->insertGetId($data);
  648. }
  649. $ext = pathinfo($filestd->filepath)["extension"];
  650. TalentLogApi::write($type, $mainId, 0, sprintf("%s附件,附件名为:%s", $change ? "修改" : "添加", $data["orignName"]), 1, $fileTypeId, $fileId);
  651. $res = ["code" => 200, "msg" => "上传附件成功", "obj" => $index, "ext" => $ext, "info" => getStoragePath($filestd->filepath), "typeId" => $fileTypeId, "id" => $fileId, "orignName" => $data["orignName"]];
  652. echo sprintf("<script>parent.%s(%s);</script>", $backName, json_encode($res));
  653. }
  654. public function deleteFile() {
  655. $param = $this->request->param();
  656. $where = [["id", "=", $param["id"]]];
  657. $file = Db::table("new_talent_file")->where($where)->findOrEmpty();
  658. if (!TalentApi::checkIsEditable($file["mainId"]))
  659. return json(["msg" => "当前状态不能删除或者文件已删除,请刷新重试。"]);
  660. if ($this->chkIsFileOwner($file["mainId"], $file["type"])) {
  661. if (!empty($file["url"])) {
  662. $filepath = "storage/" . $file["url"];
  663. if (file_exists($filepath)) {
  664. unlink($filepath);
  665. }
  666. }
  667. Db::table("new_talent_file")->delete($file["id"]);
  668. TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  669. return json(["code" => 200, "msg" => "删除成功"]);
  670. }
  671. return json(["msg" => "不能删除"]);
  672. }
  673. public function deleteTalentCommonFile() {
  674. $param = $this->request->param();
  675. $where = [["id", "=", $param["id"]]];
  676. $file = Db::table("new_talent_common_file")->where($where)->findOrEmpty();
  677. $filepath = "storage/" . $file["url"];
  678. if (file_exists($filepath)) {
  679. unlink($filepath);
  680. }
  681. Db::table("new_talent_common_file")->delete($file["id"]);
  682. //TalentLogApi::write($file["type"], $file["mainId"], 0, sprintf("删除附件,附件名为:%s", $file["orignName"]), 1, $file["typeId"], $param["id"]);
  683. return json(["code" => 200, "msg" => "删除成功"]);
  684. return json(["msg" => "不能删除"]);
  685. }
  686. public function deleteNonPredefinedFile() {
  687. $param = $this->request->param();
  688. $where = [["id", "=", $param["id"]]];
  689. $file = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  690. $filepath = "storage/" . $file["url"];
  691. if (file_exists($filepath) && $file["url"]) {
  692. @unlink($filepath);
  693. }
  694. Db::table("new_non_predefined_file")->delete($file["id"]);
  695. return json(["code" => 200, "msg" => "删除成功"]);
  696. }
  697. /**
  698. * 下载文件
  699. */
  700. public function downloadFile() {
  701. $param = $this->request->param();
  702. $type = $param["type"];
  703. $id = $param["id"];
  704. $where = [];
  705. $where[] = ["id", "=", $id];
  706. $url = "";
  707. switch ($type) {
  708. case 1:
  709. case 2:
  710. case 8:
  711. case 19:
  712. $fileinfo = Db::table("new_talent_file")->where($where)->findOrEmpty();
  713. $filename = $fileinfo["orignName"];
  714. $url = $fileinfo["url"];
  715. break;
  716. case 3:
  717. $fileinfo = Db::table("new_currency_filetype")->where($where)->findOrEmpty();
  718. $filename = $fileinfo["templateUrl"];
  719. $url = $fileinfo["templateUrl"];
  720. break;
  721. case 4:
  722. $fileinfo = Db::table("sys_common_file")->where($where)->findOrEmpty();
  723. $filename = $fileinfo["orignName"];
  724. $url = $fileinfo["url"];
  725. break;
  726. case 5:
  727. $fileinfo = Db::table("new_common_filetype")->where($where)->findOrEmpty();
  728. $filename = $fileinfo["templateUrl"];
  729. $url = $fileinfo["templateUrl"];
  730. break;
  731. case 6://预定义外的文件类型下载
  732. $fileinfo = Db::table("new_non_predefined_file")->where($where)->findOrEmpty();
  733. $filename = $fileinfo["originalName"];
  734. $url = $fileinfo["url"];
  735. break;
  736. }
  737. $filepath = "storage/" . $url; // 下载文件名
  738. if (!file_exists($filepath)) {
  739. header('HTTP/1.1 404 NOT FOUND');
  740. } else {
  741. $file = fopen($filepath, "rb");
  742. Header("Content-type: application/octet-stream");
  743. Header("Accept-Ranges: bytes");
  744. Header("Accept-Length: " . filesize($filepath));
  745. Header("Content-Disposition: attachment; filename=" . $filename);
  746. echo fread($file, filesize($filepath));
  747. fclose($file);
  748. exit();
  749. }
  750. }
  751. /**
  752. * 打包下载人才申请附件
  753. */
  754. public function downloadZip() {
  755. $table = "new_talent_file";
  756. $param = $this->request->param();
  757. $type = $param["type"];
  758. $id = $param["id"];
  759. $where = [];
  760. switch ($type) {
  761. case ProjectState::TALENT:
  762. $where[] = ["type", "=", $type];
  763. $talent_info = \app\enterprise\model\Talent::findOrEmpty($id);
  764. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($talent_info["enterprise_id"]);
  765. $zip_filename = sprintf("%s(%s)人才申报材料.zip", $talent_info["name"], $enterprise_info["name"]);
  766. break;
  767. case ProjectState::JBT:
  768. $where[] = ["type", "=", $type];
  769. $info = \app\common\model\TalentAllowance::findOrEmpty($id);
  770. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  771. $zip_filename = sprintf("%s(%s)津补贴申报材料.zip", $info["talentName"], $enterprise_info["name"]);
  772. break;
  773. case ProjectState::QUIT:
  774. $table = "new_talent_common_file";
  775. $info = \app\common\model\TalentQuit::findOrEmpty($id);
  776. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  777. $zip_filename = sprintf("%s(%s)离职材料.zip", $info["talentName"], $enterprise_info["name"]);
  778. break;
  779. case ProjectState::WORKCHANGE:
  780. $table = "new_talent_common_file";
  781. $info = \app\common\model\TalentWorkUnitChange::findOrEmpty($id);
  782. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  783. $zip_filename = sprintf("%s(%s)工作单位变更材料.zip", $info["talentName"], $enterprise_info["name"]);
  784. break;
  785. case ProjectState::LEVELCHANGE:
  786. $info = \app\enterprise\model\TalentTypeChange::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::INTEGRAL:
  791. $where[] = ["type", "=", $type];
  792. $record = \app\common\api\IntegralRecordApi::getOne($id);
  793. $zip_filename = sprintf("%s(%s)积分申报材料.zip", $record["name"], $record["enterprise"]["name"]);
  794. break;
  795. case 109:
  796. $table = "un_enterpriseclose_record";
  797. $record = \app\common\model\EnterpriseCloseAccount::where("id", $id)->find();
  798. $zip_filename = sprintf("%s(%s)注销申请材料.zip", $record["name"], $record["username"]);
  799. $files = json_decode($record["files"], true);
  800. break;
  801. }
  802. $where[] = ["mainId", "=", $id];
  803. if (!$files)
  804. $files = Db::table($table)->where($where)->select()->toArray();
  805. if (!$files) {
  806. //die("没有附件不能打包下载");
  807. echo "<script>parent.layer.alert('没有附件不能打包下载');window.history.go(-1);</script>";
  808. }
  809. $tmp_path = "storage/temp/";
  810. $tmp_file_path = $tmp_path . $zip_filename;
  811. if (!file_exists($tmp_path)) {
  812. mkdir($tmp_path);
  813. }
  814. $zip = new \ZipArchive();
  815. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  816. header('HTTP/1.1 404 NOT FOUND');
  817. }
  818. foreach ($files as $file) {
  819. if (is_array($file)) {
  820. $filepath = "storage/" . $file["url"];
  821. $fileTypeInfo = Db::table("new_common_filetype")->where("id", $file["typeId"])->find();
  822. $filename = $fileTypeInfo["name"] . "/" . $file["orignName"];
  823. $zip->addFile($filepath, $filename);
  824. } else {
  825. $filepath = "storage/" . $file;
  826. $filename = basename($filepath);
  827. $zip->addFile($filepath, $filename);
  828. }
  829. }
  830. $zip->close();
  831. if (file_exists($tmp_file_path)) {
  832. header("Cache-Control: public");
  833. header("Content-Description: File Transfer");
  834. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  835. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  836. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  837. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  838. @readfile($tmp_file_path);
  839. }
  840. //删除临时文件
  841. @unlink($tmp_file_path);
  842. }
  843. /**
  844. * 打包下载人才申请附件
  845. */
  846. public function downloadCommonZip() {
  847. $table = "un_talent_allowance_common_file";
  848. $param = $this->request->param();
  849. $id = $param["id"];
  850. $year = $param["year"];
  851. $info = \app\common\model\TalentAllowance::findOrEmpty($id);
  852. $enterprise_info = \app\common\model\Enterprise::findOrEmpty($info["enterpriseId"]);
  853. $zip_filename = sprintf("%s(%s)津补贴申报通用材料.zip", $info["talentName"], $enterprise_info["name"]);
  854. $where = [];
  855. $where[] = ["enterpriseId", "=", $info["enterpriseId"]];
  856. $where[] = ["batch", "=", $year];
  857. $files = Db::table($table)->where($where)->select()->toArray();
  858. if (!$files) {
  859. //die("没有附件不能打包下载");
  860. echo "<script>parent.layer.alert('没有附件不能打包下载');window.history.go(-1);</script>";
  861. }
  862. $tmp_path = "storage/temp/";
  863. $tmp_file_path = $tmp_path . $zip_filename;
  864. if (!file_exists($tmp_path)) {
  865. mkdir($tmp_path);
  866. }
  867. $zip = new \ZipArchive();
  868. if (!$zip->open($tmp_file_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
  869. header('HTTP/1.1 404 NOT FOUND');
  870. }
  871. foreach ($files as $file) {
  872. if (is_array($file)) {
  873. $filepath = "storage/" . $file["url"];
  874. $fileTypeInfo = Db::table("new_common_filetype")->where("id", $file["fileTypeId"])->find();
  875. $filename = $fileTypeInfo["name"] . "/" . $file["originalName"];
  876. $zip->addFile($filepath, $filename);
  877. } else {
  878. $filepath = "storage/" . $file;
  879. $filename = basename($filepath);
  880. $zip->addFile($filepath, $filename);
  881. }
  882. }
  883. $zip->close();
  884. if (file_exists($tmp_file_path)) {
  885. header("Cache-Control: public");
  886. header("Content-Description: File Transfer");
  887. header('Content-disposition: attachment; filename=' . $zip_filename); //文件名
  888. header("Content-Type: application/octet-stream;charset=utf-8"); //zip格式的
  889. header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件
  890. header('Content-Length: ' . filesize($tmp_file_path)); //告诉浏览器,文件大小
  891. @readfile($tmp_file_path);
  892. }
  893. //删除临时文件
  894. @unlink($tmp_file_path);
  895. }
  896. private function chkIsFileOwner($mainId, $type) {
  897. if (!$mainId)
  898. return true;
  899. switch ($type) {
  900. case ProjectState::TALENT:
  901. if ($this->user["usertype"] == 2) {
  902. $user_id = $this->user["uid"];
  903. $talent_info = Db::table("new_talent_info")->findOrEmpty($mainId);
  904. if ($user_id == $talent_info["enterprise_id"])
  905. return true;
  906. }
  907. break;
  908. case ProjectState::JBT:
  909. if ($this->user["usertype"] == 2) {
  910. $user_id = $this->user["uid"];
  911. $talent_info = \app\common\model\TalentAllowance::findOrEmpty($mainId);
  912. if ($user_id == $talent_info["enterpriseId"])
  913. return true;
  914. }
  915. if ($this->user["usertype"] == 1) {
  916. return true;
  917. }
  918. break;
  919. case ProjectState::EDUCATION:
  920. if ($this->user["usertype"] == 3) {
  921. $user_id = $this->user["uid"];
  922. $talent_info = \app\common\model\EducationSchool::findOrEmpty($mainId);
  923. if ($user_id == $talent_info["personId"])
  924. return true;
  925. }
  926. break;
  927. case ProjectState::LEVELCHANGE:
  928. if ($this->user["usertype"] == 2) {
  929. $user_id = $this->user["uid"];
  930. $talent_info = \app\enterprise\model\TalentTypeChange::findOrEmpty($mainId);
  931. if ($user_id == $talent_info["enterpriseId"])
  932. return true;
  933. }
  934. break;
  935. case ProjectState::LIVINGALLOWANCE:
  936. if ($this->user["usertype"] == 2) {
  937. $user_id = $this->user["uid"];
  938. $record = Db::table("md_living_allowance_info")->findOrEmpty($mainId);
  939. if ($user_id == $record["enterpriseId"])
  940. return true;
  941. }
  942. break;
  943. case ProjectState::INTEGRAL:
  944. if ($this->user["usertype"] == 2) {
  945. $user_id = $this->user["uid"];
  946. $record = Db::table("new_integral_record")->findOrEmpty($mainId);
  947. if ($user_id == $record["enterprise_id"])
  948. return true;
  949. }
  950. break;
  951. case ProjectState::BASICCHANGE:
  952. if ($this->user["usertype"] == 2) {
  953. $user_id = $this->user["uid"];
  954. $record = Db::table("un_talent_basic_change")->findOrEmpty($mainId);
  955. if ($user_id == $record["enterpriseId"])
  956. return true;
  957. }
  958. break;
  959. }
  960. return false;
  961. }
  962. public function getCompanyKvs() {
  963. $companys = \app\common\model\Company::field("name,id")->select();
  964. return json($companys);
  965. }
  966. public function getEnterpriseKvs() {
  967. $where[] = ["type", "=", $this->user["type"]];
  968. $enterprises = \app\common\model\Enterprise::field("name,id")->where($where)->select();
  969. return json($enterprises);
  970. }
  971. public function getLayerCatsByLayer() {
  972. $lv = $this->request->param("level");
  973. return json(DictApi::getLayerCatsByLayer($lv));
  974. }
  975. /**
  976. * 通过人才类别查找人才认定第二步骤支持的所有文件类型
  977. * 默认人才认定第二步骤,当前只有人才认定分了两步,所以此方法目前默认参数高度匹配人才认定第二阶段附件的查找
  978. */
  979. public function getConditionFileTypesByType() {
  980. $params = $this->request->param();
  981. $type = $params["type"]; //人才类型不默认,需要传
  982. $declare_type = $params["project"] ?: 1; //默认人才认定
  983. $active = $params["active"] ?: 1; //默认查找启用的附件
  984. $where[] = ["type", "=", $type];
  985. $where[] = ["project", "=", $declare_type];
  986. $where[] = ["active", "=", $active];
  987. $where[] = ["delete", "=", 0];
  988. $where[] = ["isConditionFile", "=", 1];
  989. $list = Db::table("new_common_filetype")->where($where)->order("sn " . $order)->select()->toArray();
  990. return json($list);
  991. }
  992. public function listCurrencyFileType() {
  993. $where = [
  994. 'type' => $this->request['type'],
  995. 'active' => 1
  996. ];
  997. $rows = CurrentcyFileType::where($where)->select();
  998. return json(["rows" => $rows, 'total' => count($rows)]);
  999. }
  1000. public function listTalentCommonFile() {
  1001. $where = [];
  1002. if (\StrUtil::isNotEmpAndNull($this->request['mainId'])) {
  1003. $where[] = ['mainId', '=', $this->request['mainId']];
  1004. }
  1005. if (\StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  1006. $where[] = ['typeId', '=', $this->request['typeId']];
  1007. }
  1008. $res = TalentCommonFile::where($where)->order('sn')->select()->toArray();
  1009. if (\StrUtil::isNotEmpAndNull($this->request['mainId']) && \StrUtil::isNotEmpAndNull($this->request['typeId'])) {
  1010. $_where = [["mainId", "=", $this->request['mainId']], ["typeId", "=", $this->request['typeId']]];
  1011. $old_list = Db::table("un_talent_common_file")->where($_where)->select()->toArray();
  1012. }
  1013. if ($old_list) {
  1014. $res = array_merge($res, $old_list);
  1015. }
  1016. if ($res) {
  1017. foreach ($res as $k => &$v) {
  1018. $v["ext"] = pathinfo($v["url"])["extension"];
  1019. $v['url'] = getStoragePath($v['url']);
  1020. }
  1021. }
  1022. return json($res);
  1023. }
  1024. public function addTalentCommonFile() {
  1025. $backName = \StrUtil::getRequestDecodeParam($this->request, 'backName');
  1026. $id = \StrUtil::getRequestDecodeParam($this->request, "fileId");
  1027. $mainId = \StrUtil::getRequestDecodeParam($this->request, "mainId");
  1028. $typeId = \StrUtil::getRequestDecodeParam($this->request, "typeId");
  1029. $index = \StrUtil::getRequestDecodeParam($this->request, "index");
  1030. if ($backName == "EpChangeEdit.callBack") {
  1031. $type = 1;
  1032. $error = "文件格式不正确,只能上传图片";
  1033. } else {
  1034. $type = 4;
  1035. $error = "文件格式不正确,只能上传pdf和图片";
  1036. }
  1037. $uploadapi = new UploadApi();
  1038. $file_check_res = $uploadapi->uploadOne($this->request->file('fileUrl'), 'system');
  1039. if ($file_check_res->code == 500) {
  1040. $file_check_res->obj = $index;
  1041. return \StrUtil::back($file_check_res, $backName);
  1042. }
  1043. $file_data = [
  1044. 'id' => getStringId(),
  1045. 'mainId' => $mainId,
  1046. 'typeId' => $typeId,
  1047. 'orignName' => $this->request->file('fileUrl')->getOriginalName(),
  1048. 'url' => $file_check_res->filepath
  1049. ];
  1050. if (\StrUtil::isEmpOrNull($id)) {
  1051. $tc = TalentCommonFile::where('mainId', $mainId)->where('typeId', $typeId)->order('sn', 'desc')->findOrEmpty();
  1052. if ($tc) {
  1053. $file_data['sn'] = $tc['sn'] + 1;
  1054. } else {
  1055. $file_data['sn'] = 1;
  1056. }
  1057. $file_data['createTime'] = date("Y-m-d H:i:s");
  1058. TalentCommonFile::create($file_data);
  1059. $response_object = new \StdClass();
  1060. $response_object->code = 200;
  1061. $response_object->msg = "附件上传成功!";
  1062. $response_object->obj = $index;
  1063. return \StrUtil::back($response_object, $backName);
  1064. } else {
  1065. $tf = TalentCommonFile::findOrEmpty($id);
  1066. $tf->originalName = $file_data['orignName'];
  1067. $tf->updateTime = date("Y-m-d H:i:s");
  1068. $tf->url = $file_check_res->filepath;
  1069. $tf->save();
  1070. $response_object = new \StdClass();
  1071. $response_object->code = 200;
  1072. $response_object->msg = "附件修改成功!";
  1073. $response_object->obj = $index;
  1074. return \StrUtil::back($response_object, $backName);
  1075. }
  1076. }
  1077. public function changePwd() {
  1078. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  1079. $newPassword = \StrUtil::getRequestDecodeParam($this->request, 'newPassword');
  1080. //数据校验(原密码与新密码不能为空)
  1081. if (\StrUtil::isEmpOrNull($password)) {
  1082. return json(['code' => 500, 'msg' => "请填写原密码!"]);
  1083. }
  1084. if (\StrUtil::isEmpOrNull($newPassword)) {
  1085. return json(['code' => 500, 'msg' => "请填写新密码!"]);
  1086. }
  1087. try {
  1088. validate(Enterprise::class)->batch(true)->scene('changePwd')->check(['password' => $password, 'password' => $newPassword]);
  1089. $ep = EnterpriseApi::getOne(session("user")['uid']);
  1090. if (!$ep) {
  1091. return json(['code' => 500, 'msg' => "请刷新页面后重试!"]);
  1092. }
  1093. if ($ep->password != hash('md5', $password)) {
  1094. return json(['code' => 500, 'msg' => "旧密码不正确!"]);
  1095. }
  1096. $ep->password = hash('md5', $newPassword);
  1097. $ep->updateUser = session("user")['uid'];
  1098. $ep->updateTime = date("Y-m-d H:i:s");
  1099. $ep->save();
  1100. TalentChecklog::create([
  1101. 'id' => getStringId(),
  1102. 'category' => 'enterprise_change',
  1103. 'mainId' => $ep->id,
  1104. 'type' => 10,
  1105. 'typeFileId' => null,
  1106. 'active' => 1,
  1107. 'state' => 1,
  1108. 'step' => 100,
  1109. 'stateChange' => null,
  1110. 'description' => '用户修改密码',
  1111. 'createTime' => date("Y-m-d H:i:s", time()),
  1112. 'createUser' => '用户'
  1113. ]);
  1114. return json(['code' => 200, 'msg' => "修改成功!"]);
  1115. } catch (ValidateException $e) {
  1116. $error = $e->getError();
  1117. return json(['code' => 500, 'msg' => array_pop($error)]);
  1118. }
  1119. }
  1120. function getIntegralRecordByIdCard() {
  1121. $cardType = $this->request->param("cardType");
  1122. $cardNumber = $this->request->param("cardNumber");
  1123. $tips = \app\common\api\IntegralRecordApi::getIntegralRecordByIdCard($cardType, $cardNumber);
  1124. return json(["tips" => $tips]);
  1125. }
  1126. function getIntegralProjectsByType() {
  1127. $projectType = $this->request->param("projectType") ?: 0;
  1128. if (session("user")["usertype"] == 2) {
  1129. $where[] = ["type", "=", 2];
  1130. } else {
  1131. $type = $this->request->param("type") ?: 0;
  1132. $where[] = ["type", "=", $type];
  1133. }
  1134. $where[] = ["projectType", "=", $projectType];
  1135. $where[] = ["active", "=", 1];
  1136. $list = \app\common\api\IntegralProjectApi::getAll($where);
  1137. return json($list);
  1138. }
  1139. public function getIntegralItemsByProject() {
  1140. $projectId = $this->request->param("projectId") ?: 0;
  1141. $where[] = ["projectId", "=", $projectId];
  1142. $where[] = ["active", "=", 1];
  1143. $list = \app\common\api\IntegralItemApi::getAll($where);
  1144. return json($list);
  1145. }
  1146. public function calIntegral() {
  1147. $params = $this->request->param();
  1148. $enterpriseId = $params["enterpriseId"];
  1149. $cardType = $params["cardType"];
  1150. $cardNumber = $params["cardNumber"];
  1151. $itemId = $params["itemId"];
  1152. $amount = $params["amount"];
  1153. if (session("user")["usertype"] == 2) {
  1154. //企业端只能通过企业自身id来查询积分
  1155. $enterpriseId = session("user")["uid"];
  1156. }
  1157. return json(\app\common\api\IntegralRecordApi::calIntegral($enterpriseId, $cardType, $cardNumber, $itemId, $amount));
  1158. }
  1159. public function imgViewer() {
  1160. $img = urldecode($this->request["picShow"]);
  1161. return view("", ["img" => $img]);
  1162. }
  1163. public function gotoFileShow() {
  1164. return view("admin@talent/filesShow");
  1165. }
  1166. public function getJbtFiletypesExceptCommon() {
  1167. $type = $this->user["type"];
  1168. $where[] = ["type", "=", $type];
  1169. $where[] = ["project", "=", 2];
  1170. $where[] = ["isConditionFile", "in", [1, 2]];
  1171. $fileTypes = \app\common\api\FileTypeApi::getAll($where);
  1172. foreach ($fileTypes as &$ft) {
  1173. $ft["name"] = sprintf("%s(%s)", $ft["name"], \app\common\state\AllowanceTypeEnum::getTypeName($ft["isConditionFile"]));
  1174. }
  1175. return json($fileTypes);
  1176. }
  1177. public function findContractFileType() {
  1178. $type = $this->request["type"];
  1179. $where[] = ["name", "like", "%工作%"];
  1180. $where[] = ["project", "=", 1];
  1181. $where[] = ["active", "=", 1];
  1182. $where[] = ["isConditionFile", "<>", 1];
  1183. $where[] = ["delete", "=", 0];
  1184. $where[] = ["type", "=", $type];
  1185. $rows = Db::table("new_common_filetype")->where($where)->order("must asc")->order("sn asc")->select()->toArray();
  1186. return json(["rows" => $rows]);
  1187. }
  1188. public function contractView() {
  1189. $id = $this->request["id"];
  1190. $talentInfo = \app\common\api\VerifyApi::getTalentInfoById($id);
  1191. $type = $talentInfo["enterpriseType"];
  1192. return view("", ["id" => $talentInfo["id"], "type" => $type]);
  1193. }
  1194. public function getEnterpriseData() {
  1195. }
  1196. }