Api.php 45 KB

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