Api.php 44 KB

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