Api.php 45 KB

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