Api.php 44 KB

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