Api.php 38 KB

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