Api.php 44 KB

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