Api.php 46 KB

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