Api.php 46 KB

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