TalentAllowance.php 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. namespace app\enterprise\controller;
  8. use app\enterprise\common\EnterpriseController;
  9. use app\common\state\CommonConst;
  10. use app\common\api\BatchApi;
  11. use app\common\api\TalentAllowanceApi;
  12. use app\common\state\ProjectState;
  13. use app\common\api\DictApi;
  14. use app\common\state\MainState;
  15. use app\common\model\TalentAllowance as TaModel;
  16. use app\common\state\AllowanceProjectEnum;
  17. use app\common\model\TalentChecklog;
  18. use think\facade\Db;
  19. use app\common\api\Response;
  20. use app\common\api\UploadApi;
  21. use app\enterprise\model\TalentTypeChange;
  22. use app\common\state\AllowanceTypeEnum;
  23. use app\common\state\AllowanceStateEnum;
  24. /**
  25. * Description of TalentAllowance
  26. *
  27. * @author sgq
  28. */
  29. class TalentAllowance extends EnterpriseController {
  30. public function index() {
  31. $tpl = "";
  32. switch ($this->user["type"]) {
  33. case CommonConst::ENTERPRISE_WJ:
  34. case CommonConst::ENTERPRISE_GJ:
  35. case CommonConst::ENTERPRISE_JC:
  36. $tpl = "indexIC";
  37. break;
  38. }
  39. return view($tpl, ['type' => $this->user["type"]]);
  40. }
  41. public function list() {
  42. $res = TalentAllowanceApi::getList($this->request);
  43. return json($res);
  44. }
  45. public function calculator($id) {
  46. $cal = TalentAllowanceApi::validateAllowanceType($id);
  47. return json($cal);
  48. }
  49. /**
  50. * 申请
  51. */
  52. public function apply(\think\Request $request) {
  53. $param = $request->param();
  54. $id = isset($param["id"]) ? $param["id"] : 0;
  55. $info = null;
  56. if ($id) {
  57. $info = TalentAllowanceApi::getInfoById($id);
  58. $this->translateToChinese($info);
  59. }
  60. if ($request->isPost()) {
  61. return $this->save($info, $request);
  62. }
  63. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  64. return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
  65. }
  66. /**
  67. * 批量提交申请
  68. * @return Response
  69. */
  70. public function batchApply() {
  71. $ids = $this->request["ids"];
  72. $ids = array_filter(explode(",", $ids));
  73. $allowanceType = $this->request["allowanceType"];
  74. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  75. if (!$batch) {
  76. return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
  77. }
  78. for ($i = 0; $i < count($ids); $i++) {
  79. queue("app\job\TalentAllowance", ["type" => 1, "method" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
  80. }
  81. return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
  82. }
  83. /**
  84. * 批量导入申请
  85. * @return Response
  86. */
  87. public function batchImportApply() {
  88. $maxFileSize = 10; //mb
  89. $tmp = $this->request->file("file");
  90. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  91. if (!$batch) {
  92. return \StrUtil::back(new Response(Response::ERROR, "当前并无有效的申报批次进行中"), "TalentAllowanceInfo.importCallBack");
  93. }
  94. if (!$tmp) {
  95. return \StrUtil::back(new Response(Response::ERROR, "没有上传批量申请文档"), "TalentAllowanceInfo.importCallBack");
  96. }
  97. if (!isExcelFile($tmp->getMime())) {
  98. //return \StrUtil::back(new Response(Response::ERROR, "只能识别Excel文档"), "TalentAllowanceInfo.importCallBack");
  99. }
  100. if (round($tmp->getSize() / 1024 / 1024, 2) > $maxFileSize) {
  101. return \StrUtil::back(new Response(Response::ERROR, "文档大小不能超过10MB"), "TalentAllowanceInfo.importCallBack");
  102. }
  103. $filepath = $tmp->getPathname();
  104. try {
  105. $rows = getExcelDatas($filepath);
  106. } catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
  107. return \StrUtil::back(new Response(Response::ERROR, "文件识别错误!"), "TalentAllowanceInfo.importCallBack");
  108. }
  109. array_shift($rows); //去标题行
  110. //检查excel文件有没有问题
  111. $checkMonths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
  112. $titles = ["姓名", "身份证", "申请补贴类型", "个税缴纳月份", "工资发放月份", "考勤情况", "养老保险", "失业保险", "医疗保险"];
  113. $allowanceTypes = ["工作津贴", "一次性交通补贴"];
  114. $idCards = [];
  115. foreach ($rows as $key => $row) {
  116. $no = $key + 2;
  117. $idCard = trim($row[1]);
  118. $allowanceType = trim($row[2]);
  119. if (!$idCard) {
  120. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证不能放空,请仔细检查内容完整后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  121. }
  122. if (in_array($idCard, $idCards)) {
  123. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证存在重复,请请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  124. } else {
  125. $idCards[] = $idCard;
  126. }
  127. if (!in_array($allowanceType, $allowanceTypes)) {
  128. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行申请补贴类型错误,请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  129. }
  130. if ($allowanceType == "工作津贴") {
  131. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($this->user["type"]);
  132. for ($i = 3; $i < 9; $i++) {
  133. $project = 1;
  134. switch ($i) {
  135. case 3:
  136. $project = AllowanceProjectEnum::PROJECT_TAX;
  137. break;
  138. case 4:
  139. $project = AllowanceProjectEnum::PROJECT_WAGES;
  140. break;
  141. case 5:
  142. $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
  143. break;
  144. case 6:
  145. $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
  146. break;
  147. case 7:
  148. $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
  149. break;
  150. case 8:
  151. $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
  152. break;
  153. }
  154. if (!in_array($project, $projects))
  155. continue;
  156. $monthstr = str_replace([" ", ","], ",", trim($row[$i]));
  157. $months = array_filter(explode(",", $monthstr));
  158. if (!$months)
  159. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
  160. if (array_diff($months, $checkMonths))
  161. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
  162. }
  163. } else {
  164. $monthstr = str_replace([" ", ","], ",", trim($row[5]));
  165. $monthstr = str_replace(":", ":", $monthstr);
  166. $months = array_filter(explode(",", $monthstr));
  167. if (!$months)
  168. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
  169. foreach ($months as $m) {
  170. list($a, $b) = explode(":", $m);
  171. if (!in_array($a, $checkMonths) || !is_numeric($b) || $b > 31 || $b < 0)
  172. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
  173. }
  174. }
  175. }
  176. for ($i = 0; $i < count($rows); $i++) {
  177. queue("app\job\TalentAllowance", ["type" => 1, "method" => 2, "data" => $rows[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => trim($rows[$i][2]) == "工作津贴" ? 1 : 2]);
  178. }
  179. return \StrUtil::back(new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认"), "TalentAllowanceInfo.importCallBack");
  180. }
  181. private function save($talentAllowance, \think\Request $request) {
  182. $response = new \stdClass();
  183. $response->code = 500;
  184. $param = $request->param();
  185. if (!$param) {
  186. $response->msg = "请填写信息后在提交";
  187. return $response;
  188. }
  189. if (\StrUtil::isEmpOrNull($param["talentId"])) {
  190. $response->msg = "请选择申报对象";
  191. return $response;
  192. }
  193. if (!$param["id"]) {
  194. $where = [];
  195. $where[] = ["year", "=", $param["year"]];
  196. $where[] = ["idCard", "=", $param["idCard"]];
  197. $where[] = ["delete", "=", 0];
  198. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  199. $exists = TaModel::where($where)->find();
  200. if ($exists) {
  201. $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
  202. return $response;
  203. }
  204. $user = $this->user;
  205. $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
  206. if ($ti["talent_type"] == 1 && $ti["enterpriseType"] == CommonConst::ENTERPRISE_WJ && $param["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  207. $response->msg = "现有人才暂时不能申请一次性交通贴补";
  208. return $response;
  209. }
  210. $data = [
  211. "talentId" => $param["talentId"],
  212. "enterpriseId" => $ti["enterprise_id"],
  213. "enterpriseName" => $user["name"],
  214. "year" => $param["year"],
  215. "source" => $ti["source"],
  216. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  217. "talentType" => $ti["enterpriseTag"],
  218. "address" => $ti["street"],
  219. "name" => $ti["name"],
  220. "sex" => $ti["sex"],
  221. "cardType" => $ti["card_type"],
  222. "idCard" => $ti["card_number"],
  223. "firstInJJTime" => $ti["fst_work_time"],
  224. "entryTime" => $ti["cur_entry_time"],
  225. "post" => $ti["position"],
  226. "phone" => $ti["phone"],
  227. "talentArrange" => $ti["talent_arrange"],
  228. "identifyCondition" => $ti["talent_condition"],
  229. "identifyGetTime" => $ti["identifyGetTime"],
  230. "identifyOutTime" => $ti["identifyExpireTime"],
  231. "identifyConditionName" => $ti["identifyConditionName"],
  232. "identifyMonth" => $ti["identifyMonth"],
  233. "bank" => $ti["bank"],
  234. "bankNetwork" => $ti["bank_branch_name"],
  235. "bankAccount" => $ti["bank_account"],
  236. "bankNumber" => $ti["bank_number"],
  237. "checkState" => 1,
  238. "type" => $user["type"],
  239. "provinceCode" => $ti["province"],
  240. "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
  241. "cityCode" => $ti["city"],
  242. "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
  243. "countyCode" => $ti["county"],
  244. "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
  245. "isSupple" => 2,
  246. "createTime" => date("Y-m-d H:i:s"),
  247. "createUser" => $user["uid"],
  248. "id" => getStringId(),
  249. "wage" => $param["wage"],
  250. "allowanceType" => $param["allowanceType"]
  251. ];
  252. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  253. $identifyYear = date("Y", strtotime($submitTime));
  254. $year = substr($param["year"], 0, 4);
  255. if ((($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  256. $response->msg = "该人员的人才认定时间晚于申报津补贴的年份,不符合申报条件";
  257. return $response;
  258. }
  259. /* * 1.获取上一年度的人才层次 */
  260. $arrangeList = $this->getLastYearTalentType($data, $ti);
  261. if (!$arrangeList) {
  262. $response->msg = "上一年度暂无有效的人才层次";
  263. return $response;
  264. }
  265. /* * 2.获取上一年度所在单位* */
  266. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  267. if (!$contractDetailList) {
  268. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  269. return $response;
  270. }
  271. TaModel::insert($data);
  272. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  273. /**
  274. * 4.添加津补贴核查项目
  275. */
  276. //核查项目详情表
  277. $this->createAllowanceProject($data, $contractDetailList);
  278. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  279. //添加日志
  280. TalentChecklog::create([
  281. 'id' => getStringId(),
  282. 'mainId' => $data['id'],
  283. 'type' => intval(ProjectState::JBT),
  284. 'typeFileId' => null,
  285. 'active' => 1,
  286. 'state' => 1,
  287. 'step' => 0,
  288. 'stateChange' => "保存未提交",
  289. 'description' => "添加津补贴申报",
  290. 'createTime' => date("Y-m-d H:i:s", time()),
  291. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  292. ]);
  293. $response->msg = "保存成功";
  294. $response->code = 200;
  295. $response->obj = $data;
  296. return $response;
  297. } else {
  298. TaModel::update($param);
  299. $response->msg = "修改成功";
  300. $response->code = 200;
  301. return $response;
  302. }
  303. }
  304. public function getInfoByIdAndYear($id, $year) {
  305. $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
  306. $data = [
  307. "talentId" => $id,
  308. "year" => $year,
  309. "idCard" => $ti["card_number"],
  310. "id" => getStringId(),
  311. "type" => $ti["enterpriseType"]
  312. ];
  313. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  314. $identifyYear = date("Y", strtotime($submitTime));
  315. $year = substr($year, 0, 4);
  316. if ((($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  317. return new Response(Response::ERROR, "该人员的人才认定时间晚于申报津补贴的年份,不符合申报条件");
  318. }
  319. /* * 1.获取上一年度的人才层次 */
  320. $arrangeList = $this->getLastYearTalentType($data, $ti);
  321. if (!$arrangeList) {
  322. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  323. }
  324. /* * 2.获取上一年度所在单位* */
  325. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  326. if (!$contractDetailList) {
  327. return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
  328. }
  329. return new Response(Response::SUCCESS, "", $ti);
  330. }
  331. /**
  332. * 删除优秀人才津补贴
  333. */
  334. public function delete() {
  335. $id = $this->request["id"];
  336. $info = TalentAllowanceApi::getInfoById($id);
  337. if ($info["checkState"] != 1) {
  338. return new Response(Response::ERROR, "删除失败!此数据已提交审核,无法删除!");
  339. }
  340. Db::startTrans();
  341. try {
  342. /* 硬删
  343. //删除核查项目表
  344. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  345. //删除合同情况表
  346. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  347. //删除人才层次变更表
  348. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  349. //删除日志
  350. $where[] = ["mainId", "=", $id];
  351. $where[] = ["type", "=", ProjectState::JBT];
  352. Db::table("new_talent_checklog")->where($where)->delete();
  353. //删除主表
  354. Db::table("un_talent_allowance_info")->delete($id);
  355. *
  356. */
  357. $data["id"] = $id;
  358. $data["delete"] = 1;
  359. $data["deleteUser"] = $this->user["uid"];
  360. $data["deleteTime"] = date("Y-m-d H:i:s");
  361. Db::table("un_talent_allowance_info")->update($data);
  362. Db::commit();
  363. return new Response(Response::SUCCESS, "删除成功");
  364. } catch (think\db\exception\DbException $e) {
  365. Db::rollback();
  366. return new Response(Response::ERROR, $e->getMessage());
  367. }
  368. }
  369. public function detail(\think\Request $request) {
  370. $param = $request->param();
  371. $id = $param["id"];
  372. $info = TalentAllowanceApi::getInfoById($id);
  373. $this->translateToChinese($info);
  374. return view("", ["row" => $info]);
  375. }
  376. private function translateToChinese(&$obj) {
  377. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  378. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  379. }
  380. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  381. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  382. }
  383. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  384. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  385. }
  386. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  387. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  388. }
  389. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  390. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  391. }
  392. }
  393. /* * 获取上一年度的人才层次变更信息 */
  394. private function getLastYearTalentType($info, $talentInfo) {
  395. $year = substr($info["year"], 0, 4);
  396. $arrangeList = [];
  397. /* * * 添加人才层次记录 */
  398. $oldStartTimeField = "oldIdentifyMonth";
  399. $newStartTimeField = "newIdentifyMonth";
  400. if ($info["type"] == CommonConst::ENTERPRISE_JC) {
  401. $oldStartTimeField = "oldIdentifyGetTime";
  402. $newStartTimeField = "newIdentifyGetTime";
  403. }
  404. if (in_array($info["type"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && date("Y", strtotime($talentInfo["identifyMonth"])) == "2023") {
  405. $talentInfo["identifyMonth"] = "2022-12-01"; //让卫健高教包含2023全年
  406. }
  407. $where = [];
  408. $where[] = ["idCard", "=", $info["idCard"]];
  409. $where[] = ["checkState", "=", MainState::PASS];
  410. $where[] = ["isPublic", ">=", 5];
  411. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  412. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  413. $typeList[] = [
  414. "oldTalentArrange" => $talentInfo["talent_arrange"],
  415. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  416. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  417. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  418. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  419. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  420. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  421. "newIdentifyMonth" => $year . "-12-31",
  422. "newIdentifyGetTime" => $year . "-12-31"
  423. ];
  424. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  425. /* * 获取上一年度有效的人才层次 */
  426. usort($typeList, function($a, $b) {
  427. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  428. });
  429. $commonMonth = [];
  430. foreach ($typeList as $talentTypeChange) {
  431. $startTime = $talentTypeChange[$oldStartTimeField];
  432. $endTime = $talentTypeChange[$newStartTimeField];
  433. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  434. if ($monthList) {
  435. $monthList = array_intersect($monthList, $totalMonth);
  436. }
  437. if ($monthList) {
  438. $months = implode(",", $monthList);
  439. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  440. return !in_array($value, $commonMonth);
  441. });
  442. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  443. if (count($monthList) > 0) {
  444. $arrange = [
  445. "id" => getStringId(),
  446. "mainId" => $info["id"],
  447. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  448. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  449. "startTime" => $startTime,
  450. "endTime" => $endTime,
  451. "prepareMonths" => null,
  452. "description" => "申报年度有效月份:" . $months,
  453. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  454. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  455. ];
  456. $sb = '';
  457. foreach ($monthList as $month) {
  458. $sb .= substr($month, 5, 2) . ",";
  459. }
  460. $arrange["prepareMonths"] = rtrim($sb, ",");
  461. $arrangeList[] = $arrange;
  462. }
  463. }
  464. }
  465. return $arrangeList;
  466. }
  467. /**
  468. * @param
  469. * @returns void
  470. * @author Liu
  471. * @date 2020/4/26
  472. * @description 获取上一年度所在单位
  473. * */
  474. private function getConcatList($talentInfo, $info, $year) {
  475. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  476. /** 添加申报人才上一年度工作单位记录 */
  477. $where = [];
  478. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  479. $where[] = ["checkState", "=", 3];
  480. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  481. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  482. if ($talentInfo["active"] == 1) {
  483. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  484. $starttime = $labor_contract_rangetime[0];
  485. $endtime = $labor_contract_rangetime[1];
  486. $quitList[] = [
  487. "enterpriseId" => $talentInfo["enterprise_id"],
  488. "enterpriseName" => $talentInfo["enterpriseName"],
  489. "talentType" => $talentInfo["enterpriseTag"],
  490. "identifyGetTime" => $talentInfo["identifyGetTime"],
  491. "starttime" => $starttime,
  492. "endtime" => $endtime,
  493. "entryTime" => $talentInfo["cur_entry_time"],
  494. "quitTime" => null,
  495. "post" => $talentInfo["position"]
  496. ];
  497. }
  498. $list = [];
  499. foreach ($quitList as $quit) {
  500. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  501. $monthList = array_intersect($monthList, $totalMonth);
  502. if ($monthList) {
  503. $sb = '';
  504. foreach ($monthList as $month) {
  505. $sb .= substr($month, 5, 2) . ",";
  506. }
  507. $list[] = [
  508. "id" => getStringId(),
  509. "mainId" => $info["id"],
  510. "enterpriseId" => $quit["enterpriseId"],
  511. "talentType" => $quit["talentType"],
  512. "startTime" => $quit["starttime"],
  513. "endTime" => $quit["endtime"],
  514. "entryTime" => $quit["entryTime"],
  515. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  516. "letterTime" => $quit["letterTime"],
  517. "gygb" => $quit["gygb"],
  518. "identifyGetTime" => $quit["identifyGetTime"],
  519. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  520. "post" => $quit["post"],
  521. "months" => rtrim($sb, ",")
  522. ];
  523. }
  524. }
  525. return $list;
  526. }
  527. private function createAllowanceProject($info, $contractList) {
  528. $count = 0;
  529. foreach ($contractList as $detail) {
  530. $count++;
  531. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  532. $list = [];
  533. foreach ($projects as $project) {
  534. $months = "";
  535. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  536. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  537. $list[] = [
  538. "mainId" => $info["id"],
  539. "baseId" => $detail["id"],
  540. "enterpriseId" => $detail["enterpriseId"],
  541. "project" => $project,
  542. "months" => $months,
  543. "isLock" => 1,
  544. "createTime" => date("Y-m-d H:i:s")
  545. ];
  546. }
  547. \app\common\model\TalentAllowanceProject::insertAll($list);
  548. }
  549. }
  550. /**
  551. * 查询工作单位
  552. */
  553. public function findAllowanceContractDetail() {
  554. $mainId = $this->request["mainId"];
  555. $offset = $this->request["offset"] ?: 0;
  556. $limit = $this->request["limit"] ?: 1000;
  557. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  558. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  559. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  560. foreach ($list as &$row) {
  561. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  562. }unset($row);
  563. return json(["rows" => $list, "total" => $count]);
  564. }
  565. /**
  566. * 查询核查项目情况
  567. */
  568. public function findAllowanceProject() {
  569. $mainId = $this->request["mainId"];
  570. $baseId = $this->request["baseId"];
  571. $offset = $this->request["offset"] ?: 0;
  572. $limit = $this->request["limit"] ?: 1000;
  573. $where = [];
  574. $where[] = ["mainId", "=", $mainId];
  575. $where[] = ["baseId", "=", $baseId];
  576. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  577. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  578. $info = TalentAllowanceApi::getInfoById($mainId);
  579. foreach ($list as &$project) {
  580. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  581. if ($info["checkState"] == 1) {
  582. $project["isEdit"] = in_array($project["project"], [
  583. //AllowanceProjectEnum::PROJECT_CONTRACT,
  584. AllowanceProjectEnum::PROJECT_TAX,
  585. AllowanceProjectEnum::PROJECT_WAGES,
  586. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  587. AllowanceProjectEnum::PROJECT_SB_PENSION,
  588. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  589. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  590. //AllowanceProjectEnum::PROJECT_WORKDAY
  591. ]) ? 1 : 2;
  592. } else if ($info["checkState"] == 10) {
  593. $projects = explode(",", $info["projects"]);
  594. if (in_array($project["id"], $projects)) {
  595. $project["isEdit"] = 1;
  596. } else {
  597. $project["isEdit"] = 2;
  598. }
  599. } else {
  600. $project["isEdit"] = 2;
  601. }
  602. }unset($project);
  603. return json(["rows" => $list, "total" => $count]);
  604. }
  605. /**
  606. * 查询人才层次变更记录
  607. */
  608. public function findAllowanceArrange() {
  609. $mainId = $this->request["mainId"];
  610. $offset = $this->request["offset"] ?: 0;
  611. $limit = $this->request["limit"] ?: 1000;
  612. $where = [];
  613. $where[] = ["mainId", "=", $mainId];
  614. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  615. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  616. foreach ($list as &$arrange) {
  617. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  618. $arrange["identifyConditionText"] = $condition["name"];
  619. $arrange["talentArrangeName"] = app\common\state\CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  620. }unset($arrange);
  621. return json(["rows" => $list, "total" => $count]);
  622. }
  623. /**
  624. * 修改合同起止时间
  625. */
  626. public function editContract() {
  627. $response = new \stdClass();
  628. $response->code = 500;
  629. $param = $this->request->param();
  630. if (!$param["id"]) {
  631. $response->msg = "系统错误,请联系管理员";
  632. return $response;
  633. }
  634. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  635. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  636. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  637. $response->msg = "请选择合同起始时间";
  638. return $response;
  639. }
  640. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  641. $response->msg = "请选择合同截止时间";
  642. return $response;
  643. }
  644. \app\common\model\TalentAllowancecontractDetail::update($param);
  645. //添加日志
  646. TalentChecklog::create([
  647. 'id' => getStringId(),
  648. 'mainId' => $info['id'],
  649. 'type' => intval(ProjectState::JBT),
  650. 'typeFileId' => $param["id"],
  651. 'active' => 1,
  652. 'state' => null,
  653. 'step' => 0,
  654. 'stateChange' => null,
  655. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  656. 'createTime' => date("Y-m-d H:i:s", time()),
  657. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  658. ]);
  659. $response->msg = "修改成功";
  660. $response->code = 200;
  661. return $response;
  662. }
  663. /**
  664. * 修改项目
  665. */
  666. public function editProject() {
  667. $response = new \stdClass();
  668. $response->code = 500;
  669. $param = $this->request->param();
  670. if (!$param["id"]) {
  671. $response->msg = "系统错误,请联系管理员";
  672. return $response;
  673. }
  674. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  675. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  676. \app\common\model\TalentAllowanceProject::update($param);
  677. //添加日志
  678. TalentChecklog::create([
  679. 'id' => getStringId(),
  680. 'mainId' => $info['id'],
  681. 'type' => intval(ProjectState::JBT),
  682. 'typeFileId' => $param["id"],
  683. 'active' => 1,
  684. 'state' => null,
  685. 'step' => 0,
  686. 'stateChange' => null,
  687. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  688. 'createTime' => date("Y-m-d H:i:s", time()),
  689. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  690. ]);
  691. $response->msg = "修改成功";
  692. $response->code = 200;
  693. return $response;
  694. }
  695. /**
  696. * 判断是否可以修改
  697. */
  698. public function validateIsEdit() {
  699. $id = $this->request["id"];
  700. $type = $this->request["type"];
  701. $info = null;
  702. if ($type == 1) { //编辑合同
  703. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  704. } else if ($type == 2) { //编辑项目
  705. $detail = \app\common\model\TalentAllowanceProject::find($id);
  706. }
  707. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  708. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  709. if ($info["checkState"] == -1) {
  710. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  711. } else if ($info["checkState"] == 30) {
  712. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  713. } else {
  714. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  715. }
  716. }
  717. return new Response(Response::SUCCESS, "");
  718. }
  719. /**
  720. * 提交审核
  721. */
  722. public function submitToCheck() {
  723. $data = $this->request->param();
  724. $response = new \stdClass();
  725. $response->code = 500;
  726. if (!$data || !$data["id"]) {
  727. $response->msg = "提交审核失败,请先填写基础信息";
  728. return $response;
  729. }
  730. $old = TalentAllowanceApi::getInfoById($data["id"]);
  731. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  732. if ($batch["code"] != 200) {
  733. $response->msg = $batch["msg"];
  734. return $response;
  735. }
  736. if ($old["checkState"] != 1 && $old["checkState"] != 10) {
  737. $response->msg = "不能重复提交审核";
  738. return $response;
  739. }
  740. if (!$old["allowanceType"]) {
  741. $response->msg = "没有明确津贴类型";
  742. return $response;
  743. }
  744. //因为工作津贴和交通补贴两者的考勤分别记录的是月份和天数,如果没有手动修改值会导致数据不对口,如修改类型却未修改考勤记录,则手动改为空。
  745. $where = [];
  746. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_ATTENDANCE];
  747. $where[] = ["mainId", "=", $data["id"]];
  748. $attendanceList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  749. if ($old["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  750. //因为天数保存格式为 月份=天数 如 01=31,02=20,03=15,月份保存格式为01,02,03,所以可以从有没有=号判断是否有进行考勤的修改保存操作
  751. foreach ($attendanceList as $a) {
  752. //$a["months"]有值但是没有包含=号则一般可认为是类型修改为交通补贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  753. if ($a["months"] && strpos($a["months"], "=") === false) {
  754. $_updProject["id"] = $a["id"];
  755. $_updProject["months"] = "";
  756. \app\common\model\TalentAllowanceProject::update($_updProject);
  757. }
  758. }
  759. } else {
  760. foreach ($attendanceList as $a) {
  761. //$a["months"]有值但是包含了=号则一般可认为是类型修改为工作津贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  762. if ($a["months"] && strpos($a["months"], "=") !== false) {
  763. $_updProject["id"] = $a["id"];
  764. $_updProject["months"] = "";
  765. \app\common\model\TalentAllowanceProject::update($_updProject);
  766. }
  767. }
  768. }
  769. $where = [];
  770. $where[] = ["type", "=", $old["type"]];
  771. $where[] = ["project", "=", ProjectState::JBT];
  772. $where[] = ["isConditionFile", "=", $old["allowanceType"]];
  773. $where[] = ["active", "=", 1];
  774. $where[] = ["delete", "=", 0];
  775. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  776. $where = [];
  777. $where[] = ["enterpriseId", "=", $old["enterpriseId"]];
  778. $where[] = ["batch", "=", $old["year"]];
  779. $commonFiles = Db::table("un_talent_allowance_common_file")->alias("f")->leftJoin("new_common_filetype ft", "ft.id=f.fileTypeId")->field("f.*,ft.relationIds")->where($where)->select()->toArray();
  780. $relationIds = [];
  781. foreach ($commonFiles as $key => $row) {
  782. $_relationIds = array_filter(explode(",", $row["relationIds"]));
  783. $relationIds = array_merge($relationIds, $_relationIds);
  784. }
  785. foreach ($filetypes as $key => $filetype) {
  786. if (in_array($filetype["id"], $relationIds)) {
  787. $filetypes[$key]["must"] = 2;
  788. }
  789. }
  790. $sb = [];
  791. $sb[] = "以下为必传附件:";
  792. foreach ($filetypes as $filetype) {
  793. if ($filetype["must"] == 1) {
  794. $where = [];
  795. $where[] = ["mainId", "=", $data["id"]];
  796. $where[] = ["typeId", "=", $filetype["id"]];
  797. $count = Db::table("new_talent_file")->where($where)->count();
  798. if ($count == 0) {
  799. $sb[] = $filetype["name"] . ";";
  800. }
  801. }
  802. }
  803. if (count($sb) > 1) {
  804. $response->msg = implode("<br>", $sb);
  805. return $response;
  806. }
  807. /**
  808. * 初步判断合同是否满两年
  809. */
  810. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  811. foreach ($detailList as $detail) {
  812. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  813. $response->msg = "合同起止时间不能为空";
  814. return $response;
  815. }
  816. }
  817. foreach ($detailList as $detail) {
  818. $contractEndTime = strtotime($detail["endTime"]);
  819. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  820. $where = [];
  821. $where[] = ["mainId", "=", $data["id"]];
  822. $where[] = ["baseId", "=", $detail["id"]];
  823. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  824. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  825. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  826. }
  827. $data["checkMsg"] = "";
  828. $data["checkState"] = AllowanceStateEnum::NEED_CHECK;
  829. $ep = \app\common\api\EnterpriseApi::getOne($this->user["uid"]);
  830. if ($ep->isGeneral == 2 && \app\common\api\Nhc::hasGeneralHospital($ep->medicalCommunityId)) {
  831. $data["checkState"] = AllowanceStateEnum::NEED_GENERAL_CHECK; //分院并且有总院
  832. }
  833. $data["files"] = "";
  834. $data["projects"] = "";
  835. $data["concats"] = "";
  836. $data["fields"] = "";
  837. $data["toDep"] = "";
  838. $data["process"] = null;
  839. if (!$old["firstSubmitTime"]) {
  840. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  841. }
  842. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  843. TaModel::update($data);
  844. //添加日志
  845. TalentChecklog::create([
  846. 'id' => getStringId(),
  847. 'mainId' => $data['id'],
  848. 'type' => intval(ProjectState::JBT),
  849. 'typeFileId' => null,
  850. 'active' => 1,
  851. 'state' => 1,
  852. 'step' => 0,
  853. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
  854. 'description' => "确认提交审核",
  855. 'createTime' => date("Y-m-d H:i:s", time()),
  856. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  857. ]);
  858. $response->msg = "提交审核成功";
  859. $response->code = 200;
  860. $response->obj = 5;
  861. return $response;
  862. }
  863. public function updateSuppleState() {
  864. $id = $this->request["id"];
  865. $response = new \stdClass();
  866. $response->code = 500;
  867. if (\StrUtil::isEmpOrNull($id)) {
  868. $response->msg = "系统错误,请联系管理员";
  869. return $response;
  870. }
  871. $data["id"] = $id;
  872. $data["isSupple"] = 1;
  873. TaModel::update($data);
  874. $response->msg = "状态更新成功";
  875. $response->code = 200;
  876. return $response;
  877. }
  878. public function uploadCommonFile() {
  879. $batchId = $this->request["batch"];
  880. if (!$batchId) {
  881. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  882. }
  883. $batchInfo = BatchApi::getOne($batchId);
  884. if (!$batchInfo) {
  885. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  886. }
  887. if (!$this->request->file()) {
  888. return json(new Response(Response::ERROR, "没有上传任何材料"));
  889. }
  890. $file = $this->request->file("file");
  891. $upload = new UploadApi();
  892. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  893. if ($result->code != 200) {
  894. return json(new Response(Response::ERROR, $result->msg));
  895. }
  896. $data["id"] = getStringId();
  897. $data["enterpriseId"] = $this->user["uid"];
  898. $data["batchId"] = $batchId;
  899. $data["batch"] = $batchInfo["batch"];
  900. $data["url"] = $result->filepath;
  901. $data["originalName"] = $file->getOriginalName();
  902. $data["createTime"] = date("Y-m-d H:i:s");
  903. $data["createUser"] = $this->user["uid"];
  904. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  905. return json(new Response(Response::SUCCESS, "上传成功"));
  906. }
  907. public function listCommonFile() {
  908. $param = $this->request->param();
  909. $batchId = $param["batch"];
  910. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  911. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  912. $whr[] = ["type", "=", $this->user["type"]];
  913. $whr[] = ["project", "=", ProjectState::JBT];
  914. $whr[] = ["isConditionFile", "=", 0];
  915. $whr[] = ["delete", "=", 0];
  916. if ($this->user["type"] == CommonConst::ENTERPRISE_JC) {
  917. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->whereRaw("find_in_set(:enterpriseId,enterpriseIds)", ["enterpriseId" => $this->user["uid"]])->select()->toArray();
  918. } else {
  919. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->select()->toArray();
  920. }
  921. foreach ($list as $key => $item) {
  922. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  923. $list[$key]["url"] = getStoragePath($item["url"]);
  924. $list[$key]["fileTypes"] = $commonFileTypes;
  925. }
  926. return json(["rows" => $list]);
  927. }
  928. public function bindCommonFileWithFileType() {
  929. $params = $this->request->param();
  930. $fileId = $params["fileId"];
  931. $fileTypeId = $params["fileTypeId"];
  932. $upd["id"] = $fileId;
  933. $upd["fileTypeId"] = $fileTypeId ?: 0;
  934. $upd["updateTime"] = date("Y-m-d H:i:s");
  935. $upd["updateUser"] = $this->user["uid"];
  936. try {
  937. Db::table("un_talent_allowance_common_file")->update($upd);
  938. if ($fileTypeId > 0) {
  939. $msg = "关联成功";
  940. } else {
  941. $msg = "取消关联成功";
  942. }
  943. return json(new Response(Response::SUCCESS, $msg));
  944. } catch (\think\db\exception\DbException $e) {
  945. return json(new Response(Response::ERROR, $e->getMessage()));
  946. }
  947. }
  948. public function deleteCommonFile() {
  949. $id = $this->request["id"];
  950. $where = [];
  951. $where[] = ["id", "=", $id];
  952. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  953. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  954. if (!$file) {
  955. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  956. }
  957. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  958. if (!empty($file["url"])) {
  959. $filepath = "storage/" . $file["url"];
  960. if (file_exists($filepath)) {
  961. unlink($filepath);
  962. }
  963. }
  964. return json(new Response(Response::SUCCESS, "删除成功"));
  965. }
  966. }
  967. public function findTalentAllowance() {
  968. $res = [];
  969. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  970. $year = $batch["batch"];
  971. if ($year) {
  972. $ids = null;
  973. //根据申报年度查询当前企业已申报的人才
  974. $where = [];
  975. $where[] = ["year", "=", $year];
  976. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  977. $talentAllowances = TaModel::where($where)->select()->toArray();
  978. $ids = array_unique(array_column($talentAllowances, "talentId"));
  979. $whr = [];
  980. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  981. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  982. $whr[] = ["e.type", "=", $this->user["type"]];
  983. $whr[] = ["ti.id", "not in", $ids];
  984. $list = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.id,ti.name,ti.card_number as idCard,ti.cur_entry_time,e.`type` as eType")->where($whr)->select()->toArray();
  985. foreach ($list as $info) {
  986. $identifyTime = $info["identifyMonth"];
  987. if ($info["eType"] == CommonConst::ENTERPRISE_JC) {
  988. $identifyTime = $info["identifyGetTime"] ?: $info["identifyMonth"];
  989. }
  990. if (strtotime($year . "-12-31") >= strtotime($identifyTime)) {
  991. $res[] = $info;
  992. } else {
  993. $whereTypeChange = [];
  994. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  995. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  996. $whereTypeChange[] = ["isPublic", "=", 6];
  997. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  998. foreach ($typeChanges as $typeChange) {
  999. $oldIdentifyTime = $typeChange["oldIdentifyMonth"];
  1000. if ($typeChange["type"] == CommonConst::ENTERPRISE_JC) {
  1001. $oldIdentifyTime = $typeChange["oldIdentifyGetTime"] ?: $typeChange["oldIdentifyMonth"];
  1002. }
  1003. if (strtotime($year . "-12-31") >= strtotime($oldIdentifyTime)) {
  1004. $res[] = $info;
  1005. break;
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  1012. }
  1013. public function export() {
  1014. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  1015. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  1016. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  1017. $obj["allowanceType"] = \StrUtil::getRequestDecodeParam($this->request, "allowanceType");
  1018. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  1019. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  1020. $where = [];
  1021. $where[] = ["ta.delete", "=", 0];
  1022. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  1023. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  1024. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  1025. }
  1026. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  1027. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  1028. }
  1029. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  1030. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  1031. }
  1032. if (\StrUtil::isNotEmpAndNull($obj["allowanceType"])) {
  1033. $where[] = ["ta.allowanceType", "=", $obj["allowanceType"]];
  1034. }
  1035. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  1036. $where[] = ["ta.address", "=", $obj["address"]];
  1037. }
  1038. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  1039. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  1040. }
  1041. $projects = [
  1042. AllowanceProjectEnum::PROJECT_TAX,
  1043. AllowanceProjectEnum::PROJECT_WAGES,
  1044. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  1045. AllowanceProjectEnum::PROJECT_SB_PENSION,
  1046. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  1047. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  1048. ];
  1049. $months = [];
  1050. for ($m = 1; $m <= 12; $m++) {
  1051. $months[] = $m . "月";
  1052. }
  1053. $columns = [["年度", [1, 2]], ["所属镇街", [1, 2]], ["姓名", [1, 2]], ["性别", [1, 2]], ["证件号码", [1, 2]], ["人才层次", [1, 2]], ["认定条件", [1, 2]], ["认定条件取得时间", [1, 2]], ["认定条件名称", [1, 2]], ["公布入选月份", [1, 2]], ["津补贴类型", [1, 2]], ["试算结果", [1, 2]], ["兑现月份", [1, 2]], ["兑现金额", [1, 2]], ["金额说明", [1, 2]], ["审核状态", [1, 2]], ["缴纳单位", [1, 2]]];
  1054. $infoCols = count($columns);
  1055. for ($i = 0; $i < count($projects); $i++) {
  1056. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  1057. }
  1058. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  1059. ->field("ta.id,ta.year,ta.enterpriseId as curEnterpriseId,ta.address,ta.name,ta.sex,ta.idCard,ta.talentArrange,ta.identifyCondition,ta.identifyGetTime,ta.identifyConditionName,ta.virtualAmount,ta.identifyMonth,ta.allowanceType,ta.months,ta.money,ta.moneyDesc,ta.checkState,ta.publicState,pro.project,pro.months as pre_months,con.enterpriseId,con.startTime,con.endTime,con.entryTime,con.quitTime,con.isQuit")
  1060. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  1061. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  1062. ->where($where)
  1063. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  1064. ->select()->toArray();
  1065. $tmpList = [];
  1066. $levelMap = DictApi::selectByParentCode("talent_arrange");
  1067. $streetMap = DictApi::selectByParentCode("street");
  1068. $where = [];
  1069. $where[] = ["id", "in", array_column($list, "identifyCondition")];
  1070. $icmap = \app\common\model\TalentCondition::where($where)->column("name", "id");
  1071. $where = [];
  1072. $where[] = ["id", "in", array_column($list, "enterpriseId")];
  1073. $enterpriseMap = \app\common\model\Enterprise::where($where)->column("name", "id");
  1074. foreach ($list as $item) {
  1075. //组装数据
  1076. if (!$tmpList[$item["id"]]) {
  1077. $tmpList[$item["id"]]["curEnterpriseId"] = $item["curEnterpriseId"];
  1078. $tmpList[$item["id"]]["info"] = [$item["year"], $streetMap[$item["address"]], $item["name"], $item["sex"] == 1 ? "男" : "女", $item["idCard"], $levelMap[$item["talentArrange"]],
  1079. $icmap[$item["identifyCondition"]], $item["identifyGetTime"], $item["identifyConditionName"], $item["identifyMonth"], AllowanceTypeEnum::getTypeName($item["allowanceType"]), $item["virtualAmount"], $item["months"], $item["money"],
  1080. $item["moneyDesc"], $this->getCheckStateName($item["checkState"], $item["publicState"], $item["allowanceType"])];
  1081. }
  1082. if (!$tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]) {
  1083. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]] = [
  1084. "startTime" => $item["startTime"],
  1085. "endTime" => $item["endTime"],
  1086. "entryTime" => $item["entryTime"],
  1087. "isQuit" => $item["isQuit"]
  1088. ];
  1089. }
  1090. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]["projects"][$item["project"]] = $item["pre_months"];
  1091. }
  1092. $rows = [];
  1093. $colorset = [];
  1094. foreach ($tmpList as $id => $item) {
  1095. foreach ($item["enterprise"] as $enterpriseId => $enterprise) {
  1096. $row = $item["info"];
  1097. $row[] = $this->user["uid"] == $enterpriseId ? "本单位" : $enterpriseMap[$enterpriseId];
  1098. for ($i = 0; $i < count($projects); $i++) {
  1099. if (strpos($enterprise["projects"][$projects[$i]], "=") === false) {
  1100. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1101. for ($m = 1; $m <= 12; $m++) {
  1102. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1103. if (in_array($_month, $months)) {
  1104. $row[] = "✔";
  1105. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1106. } else {
  1107. $row[] = "";
  1108. }
  1109. }
  1110. } else {
  1111. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1112. $_months = [];
  1113. foreach ($months as $month) {
  1114. $kv = explode("=", $month);
  1115. $_months[$kv[0]] = $kv[1];
  1116. }
  1117. for ($m = 1; $m <= 12; $m++) {
  1118. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1119. $days = $_months[$_month];
  1120. if ($days && $days > 0) {
  1121. $row[] = $days . "天";
  1122. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1123. } else {
  1124. $row[] = "";
  1125. }
  1126. }
  1127. }
  1128. }
  1129. $rows[] = $row;
  1130. }
  1131. }
  1132. $cols = $infoCols + count($projects) * 12 - 1;
  1133. $settings = [
  1134. "width" => [["A", 8], ["C", 12], ["D", 6], ["E", 20], ["F", 12], ["G", 70], ["H", 12], ["I", 15], ["J", 12], ["K", 12], ["P", 30]],
  1135. "height" => [18],
  1136. "freeze" => "D3",
  1137. "color" => $colorset
  1138. ];
  1139. for ($i = 0; $i < count($projects) * 12; $i++) {
  1140. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  1141. }
  1142. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  1143. export($columns, $rows, "津补贴申报名单", $settings);
  1144. }
  1145. /**
  1146. * 审核列表页
  1147. */
  1148. public function examineCenter() {
  1149. $tpl = "";
  1150. switch ($this->user["type"]) {
  1151. case CommonConst::ENTERPRISE_WJ:
  1152. $tpl = "/talent_allowance/examine_center"; //卫健医院
  1153. break;
  1154. }
  1155. return view($tpl);
  1156. }
  1157. /**
  1158. * 审核列表页
  1159. */
  1160. public function examineList() {
  1161. $res = TalentAllowanceApi::getHospitalExamineList($this->request);
  1162. return json($res);
  1163. }
  1164. public function examinePage() {
  1165. $id = $this->request->param("id");
  1166. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  1167. return view("/talent/hospital/view", ["row" => $info]);
  1168. }
  1169. private function getCheckStateName($checkState, $publicState, $allowanceType) {
  1170. switch ($checkState) {
  1171. case 1:
  1172. return "待提交";
  1173. case 3:
  1174. case 5:
  1175. case 13:
  1176. case 15:
  1177. case 20:
  1178. case 25:
  1179. case 35:
  1180. return "审核中";
  1181. case 8:
  1182. return "总院驳回";
  1183. case 9:
  1184. case 10:
  1185. return "已驳回";
  1186. case - 1:
  1187. if ($publicState >= 3) {
  1188. return "审核不通过";
  1189. } else {
  1190. return "审核中";
  1191. }
  1192. break;
  1193. case 30:
  1194. if ($publicState == 1) {
  1195. return "待核查征信";
  1196. } else if ($publicState == 2) {
  1197. return "待公示";
  1198. } else if ($publicState == 3) {
  1199. return "公示中";
  1200. } else if ($publicState == 4) {
  1201. return $allowanceType != 3 ? "待兑现" : "不予兑现";
  1202. } else if ($publicState == 5) {
  1203. return "已兑现";
  1204. }
  1205. default:
  1206. return "未知状态";
  1207. }
  1208. }
  1209. }