Api.php 49 KB

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