Api.php 56 KB

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