TalentAllowance.php 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  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. if ($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) {
  263. $batchYear = substr($data["year"], 0, 4);
  264. $identifyYear = substr($data["identifyMonth"], 0, 4);
  265. if (!$batchYear || !$identifyYear || $identifyYear > $batchYear) {
  266. $response->msg = "上一年度暂无有效的人才层次";
  267. return $response;
  268. }
  269. } else {
  270. $response->msg = "上一年度暂无有效的人才层次";
  271. return $response;
  272. }
  273. }
  274. /* * 2.获取上一年度所在单位* */
  275. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  276. if (!$contractDetailList) {
  277. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  278. return $response;
  279. }
  280. TaModel::insert($data);
  281. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  282. /**
  283. * 4.添加津补贴核查项目
  284. */
  285. //核查项目详情表
  286. $this->createAllowanceProject($data, $contractDetailList);
  287. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  288. //添加日志
  289. TalentChecklog::create([
  290. 'id' => getStringId(),
  291. 'mainId' => $data['id'],
  292. 'type' => intval(ProjectState::JBT),
  293. 'typeFileId' => null,
  294. 'active' => 1,
  295. 'state' => 1,
  296. 'step' => 0,
  297. 'stateChange' => "保存未提交",
  298. 'description' => "添加津补贴申报",
  299. 'createTime' => date("Y-m-d H:i:s", time()),
  300. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  301. ]);
  302. $response->msg = "保存成功";
  303. $response->code = 200;
  304. $response->obj = $data;
  305. return $response;
  306. } else {
  307. TaModel::update($param);
  308. $response->msg = "修改成功";
  309. $response->code = 200;
  310. return $response;
  311. }
  312. }
  313. public function getInfoByIdAndYear($id, $year) {
  314. $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
  315. $data = [
  316. "talentId" => $id,
  317. "year" => $year,
  318. "idCard" => $ti["card_number"],
  319. "id" => getStringId(),
  320. "type" => $ti["enterpriseType"]
  321. ];
  322. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  323. $identifyYear = date("Y", strtotime($submitTime));
  324. $year = substr($year, 0, 4);
  325. if ((($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  326. return new Response(Response::ERROR, "该人员的人才认定时间晚于申报津补贴的年份,不符合申报条件");
  327. }
  328. /* * 1.获取上一年度的人才层次 */
  329. $arrangeList = $this->getLastYearTalentType($data, $ti);
  330. if (!$arrangeList) {
  331. if ($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) {
  332. $identifyYear = substr($ti["identifyMonth"], 0, 4);
  333. if (!$year || !$identifyYear || $identifyYear > $year) {
  334. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  335. }
  336. } else {
  337. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  338. }
  339. }
  340. /* * 2.获取上一年度所在单位* */
  341. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  342. if (!$contractDetailList) {
  343. return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
  344. }
  345. return new Response(Response::SUCCESS, "", $ti);
  346. }
  347. /**
  348. * 删除优秀人才津补贴
  349. */
  350. public function delete() {
  351. $id = $this->request["id"];
  352. $info = TalentAllowanceApi::getInfoById($id);
  353. if ($info["checkState"] != 1) {
  354. return new Response(Response::ERROR, "删除失败!此数据已提交审核,无法删除!");
  355. }
  356. Db::startTrans();
  357. try {
  358. /* 硬删
  359. //删除核查项目表
  360. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  361. //删除合同情况表
  362. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  363. //删除人才层次变更表
  364. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  365. //删除日志
  366. $where[] = ["mainId", "=", $id];
  367. $where[] = ["type", "=", ProjectState::JBT];
  368. Db::table("new_talent_checklog")->where($where)->delete();
  369. //删除主表
  370. Db::table("un_talent_allowance_info")->delete($id);
  371. *
  372. */
  373. $data["id"] = $id;
  374. $data["delete"] = 1;
  375. $data["deleteUser"] = $this->user["uid"];
  376. $data["deleteTime"] = date("Y-m-d H:i:s");
  377. Db::table("un_talent_allowance_info")->update($data);
  378. Db::commit();
  379. return new Response(Response::SUCCESS, "删除成功");
  380. } catch (think\db\exception\DbException $e) {
  381. Db::rollback();
  382. return new Response(Response::ERROR, $e->getMessage());
  383. }
  384. }
  385. public function detail(\think\Request $request) {
  386. $param = $request->param();
  387. $id = $param["id"];
  388. $info = TalentAllowanceApi::getInfoById($id);
  389. $this->translateToChinese($info);
  390. return view("", ["row" => $info]);
  391. }
  392. private function translateToChinese(&$obj) {
  393. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  394. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  395. }
  396. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  397. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  398. }
  399. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  400. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  401. }
  402. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  403. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  404. }
  405. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  406. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  407. }
  408. }
  409. /* * 获取上一年度的人才层次变更信息 */
  410. private function getLastYearTalentType($info, $talentInfo) {
  411. $year = substr($info["year"], 0, 4);
  412. $arrangeList = [];
  413. /* * * 添加人才层次记录 */
  414. $oldStartTimeField = "oldIdentifyMonth";
  415. $newStartTimeField = "newIdentifyMonth";
  416. if ($info["type"] == CommonConst::ENTERPRISE_JC) {
  417. $oldStartTimeField = "oldIdentifyGetTime";
  418. $newStartTimeField = "newIdentifyGetTime";
  419. }
  420. if (in_array($info["type"], [CommonConst::ENTERPRISE_WJ]) && date("Y", strtotime($talentInfo["identifyMonth"])) == "2023") {
  421. $talentInfo["identifyMonth"] = "2022-12-01"; //让卫健包含2023全年
  422. }
  423. $where = [];
  424. $where[] = ["idCard", "=", $info["idCard"]];
  425. $where[] = ["checkState", "=", MainState::PASS];
  426. $where[] = ["isPublic", ">=", 5];
  427. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  428. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  429. $typeList[] = [
  430. "oldTalentArrange" => $talentInfo["talent_arrange"],
  431. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  432. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  433. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  434. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  435. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  436. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  437. "newIdentifyMonth" => $year . "-12-31",
  438. "newIdentifyGetTime" => $year . "-12-31"
  439. ];
  440. if (in_array($info["idCard"], \app\common\api\VerifyApi::getTwiceIdentifyPersons())) {
  441. $whr = [];
  442. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  443. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  444. $whr[] = ["e.type", "=", $this->user["type"]];
  445. $whr[] = ["ti.id", "<>", $talentInfo["id"]];
  446. $whr[] = ["card_number", "=", $info["idCard"]];
  447. $otherChangeList = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.*,e.`type` as eType")->order("identifyMonth desc")->where($whr)->select()->toArray();
  448. foreach ($otherChangeList as $k => $oc) {
  449. if ($k == 0) {
  450. $newIdentifyMonth = $talentInfo["identifyMonth"];
  451. $newIdentifyGetTime = $talentInfo["identifyGetTime"];
  452. } else {
  453. $newIdentifyMonth = $oc[$k - 1]["identifyMonth"];
  454. $newIdentifyGetTime = $oc[$k - 1]["identifyGetTime"];
  455. }
  456. $typeList[] = [
  457. "oldTalentArrange" => $oc["talent_arrange"],
  458. "oldIdentifyCondition" => $oc["talent_condition"],
  459. "oldIdentifyGetTime" => $oc["identifyGetTime"],
  460. "oldIdentifyOutTime" => $oc["identifyExpireTime"],
  461. "oldIdentifyMonth" => $oc["identifyMonth"],
  462. "oldCertificateStartTime" => $oc["certificateGetTime"],
  463. "oldCertificateOutTime" => $oc["certificateExpireTime"],
  464. "newIdentifyMonth" => $newIdentifyMonth,
  465. "newIdentifyGetTime" => $newIdentifyGetTime
  466. ];
  467. }
  468. }
  469. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  470. /* * 获取上一年度有效的人才层次 */
  471. usort($typeList, function($a, $b) {
  472. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  473. });
  474. $commonMonth = [];
  475. foreach ($typeList as $talentTypeChange) {
  476. $startTime = $talentTypeChange[$oldStartTimeField];
  477. $endTime = $talentTypeChange[$newStartTimeField];
  478. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  479. if ($monthList) {
  480. $monthList = array_intersect($monthList, $totalMonth);
  481. }
  482. if ($monthList) {
  483. $months = implode(",", $monthList);
  484. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  485. return !in_array($value, $commonMonth);
  486. });
  487. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  488. if (count($monthList) > 0) {
  489. $arrange = [
  490. "id" => getStringId(),
  491. "mainId" => $info["id"],
  492. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  493. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  494. "startTime" => $startTime,
  495. "endTime" => $endTime,
  496. "prepareMonths" => null,
  497. "description" => "申报年度有效月份:" . $months,
  498. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  499. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  500. ];
  501. $sb = '';
  502. foreach ($monthList as $month) {
  503. $sb .= substr($month, 5, 2) . ",";
  504. }
  505. $arrange["prepareMonths"] = rtrim($sb, ",");
  506. $arrangeList[] = $arrange;
  507. }
  508. }
  509. }
  510. return $arrangeList;
  511. }
  512. /**
  513. * @param
  514. * @returns void
  515. * @author Liu
  516. * @date 2020/4/26
  517. * @description 获取上一年度所在单位
  518. * */
  519. private function getConcatList($talentInfo, $info, $year) {
  520. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  521. /** 添加申报人才上一年度工作单位记录 */
  522. $where = [];
  523. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  524. $where[] = ["checkState", "=", 3];
  525. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  526. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  527. if ($talentInfo["active"] == 1) {
  528. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  529. $starttime = $labor_contract_rangetime[0];
  530. $endtime = $labor_contract_rangetime[1];
  531. $quitList[] = [
  532. "enterpriseId" => $talentInfo["enterprise_id"],
  533. "enterpriseName" => $talentInfo["enterpriseName"],
  534. "talentType" => $talentInfo["enterpriseTag"],
  535. "identifyGetTime" => $talentInfo["identifyGetTime"],
  536. "starttime" => $starttime,
  537. "endtime" => $endtime,
  538. "entryTime" => $talentInfo["cur_entry_time"],
  539. "quitTime" => null,
  540. "post" => $talentInfo["position"]
  541. ];
  542. }
  543. $list = [];
  544. foreach ($quitList as $quit) {
  545. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  546. $monthList = array_intersect($monthList, $totalMonth);
  547. if ($monthList) {
  548. $sb = '';
  549. foreach ($monthList as $month) {
  550. $sb .= substr($month, 5, 2) . ",";
  551. }
  552. $list[] = [
  553. "id" => getStringId(),
  554. "mainId" => $info["id"],
  555. "enterpriseId" => $quit["enterpriseId"],
  556. "talentType" => $quit["talentType"],
  557. "startTime" => $quit["starttime"],
  558. "endTime" => $quit["endtime"],
  559. "entryTime" => $quit["entryTime"],
  560. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  561. "letterTime" => $quit["letterTime"],
  562. "gygb" => $quit["gygb"],
  563. "identifyGetTime" => $quit["identifyGetTime"],
  564. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  565. "post" => $quit["post"],
  566. "months" => rtrim($sb, ",")
  567. ];
  568. }
  569. }
  570. return $list;
  571. }
  572. private function createAllowanceProject($info, $contractList) {
  573. $count = 0;
  574. foreach ($contractList as $detail) {
  575. $count++;
  576. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  577. $list = [];
  578. foreach ($projects as $project) {
  579. $months = "";
  580. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  581. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  582. $list[] = [
  583. "mainId" => $info["id"],
  584. "baseId" => $detail["id"],
  585. "enterpriseId" => $detail["enterpriseId"],
  586. "project" => $project,
  587. "months" => $months,
  588. "isLock" => 1,
  589. "createTime" => date("Y-m-d H:i:s")
  590. ];
  591. }
  592. \app\common\model\TalentAllowanceProject::insertAll($list);
  593. }
  594. }
  595. /**
  596. * 查询工作单位
  597. */
  598. public function findAllowanceContractDetail() {
  599. $mainId = $this->request["mainId"];
  600. $offset = $this->request["offset"] ?: 0;
  601. $limit = $this->request["limit"] ?: 1000;
  602. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  603. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  604. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  605. foreach ($list as &$row) {
  606. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  607. }unset($row);
  608. return json(["rows" => $list, "total" => $count]);
  609. }
  610. /**
  611. * 查询核查项目情况
  612. */
  613. public function findAllowanceProject() {
  614. $mainId = $this->request["mainId"];
  615. $baseId = $this->request["baseId"];
  616. $offset = $this->request["offset"] ?: 0;
  617. $limit = $this->request["limit"] ?: 1000;
  618. $where = [];
  619. $where[] = ["mainId", "=", $mainId];
  620. $where[] = ["baseId", "=", $baseId];
  621. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  622. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  623. $info = TalentAllowanceApi::getInfoById($mainId);
  624. foreach ($list as &$project) {
  625. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  626. if ($info["checkState"] == 1) {
  627. $project["isEdit"] = in_array($project["project"], [
  628. //AllowanceProjectEnum::PROJECT_CONTRACT,
  629. AllowanceProjectEnum::PROJECT_TAX,
  630. AllowanceProjectEnum::PROJECT_WAGES,
  631. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  632. AllowanceProjectEnum::PROJECT_SB_PENSION,
  633. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  634. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  635. //AllowanceProjectEnum::PROJECT_WORKDAY
  636. ]) ? 1 : 2;
  637. } else if ($info["checkState"] == 10 || $info["checkState"] == 8) {
  638. $projects = explode(",", $info["projects"]);
  639. if (in_array($project["id"], $projects)) {
  640. $project["isEdit"] = 1;
  641. } else {
  642. $project["isEdit"] = 2;
  643. }
  644. } else {
  645. $project["isEdit"] = 2;
  646. }
  647. }unset($project);
  648. return json(["rows" => $list, "total" => $count]);
  649. }
  650. /**
  651. * 查询人才层次变更记录
  652. */
  653. public function findAllowanceArrange() {
  654. $mainId = $this->request["mainId"];
  655. $offset = $this->request["offset"] ?: 0;
  656. $limit = $this->request["limit"] ?: 1000;
  657. $where = [];
  658. $where[] = ["mainId", "=", $mainId];
  659. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  660. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  661. foreach ($list as &$arrange) {
  662. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  663. $arrange["identifyConditionText"] = $condition["name"];
  664. $arrange["talentArrangeName"] = CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  665. }unset($arrange);
  666. return json(["rows" => $list, "total" => $count]);
  667. }
  668. /**
  669. * 修改合同起止时间
  670. */
  671. public function editContract() {
  672. $response = new \stdClass();
  673. $response->code = 500;
  674. $param = $this->request->param();
  675. if (!$param["id"]) {
  676. $response->msg = "系统错误,请联系管理员";
  677. return $response;
  678. }
  679. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  680. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  681. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  682. $response->msg = "请选择合同起始时间";
  683. return $response;
  684. }
  685. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  686. $response->msg = "请选择合同截止时间";
  687. return $response;
  688. }
  689. \app\common\model\TalentAllowancecontractDetail::update($param);
  690. //添加日志
  691. TalentChecklog::create([
  692. 'id' => getStringId(),
  693. 'mainId' => $info['id'],
  694. 'type' => intval(ProjectState::JBT),
  695. 'typeFileId' => $param["id"],
  696. 'active' => 1,
  697. 'state' => null,
  698. 'step' => 0,
  699. 'stateChange' => null,
  700. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  701. 'createTime' => date("Y-m-d H:i:s", time()),
  702. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  703. ]);
  704. $response->msg = "修改成功";
  705. $response->code = 200;
  706. return $response;
  707. }
  708. /**
  709. * 修改项目
  710. */
  711. public function editProject() {
  712. $response = new \stdClass();
  713. $response->code = 500;
  714. $param = $this->request->param();
  715. if (!$param["id"]) {
  716. $response->msg = "系统错误,请联系管理员";
  717. return $response;
  718. }
  719. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  720. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  721. \app\common\model\TalentAllowanceProject::update($param);
  722. //添加日志
  723. TalentChecklog::create([
  724. 'id' => getStringId(),
  725. 'mainId' => $info['id'],
  726. 'type' => intval(ProjectState::JBT),
  727. 'typeFileId' => $param["id"],
  728. 'active' => 1,
  729. 'state' => null,
  730. 'step' => 0,
  731. 'stateChange' => null,
  732. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  733. 'createTime' => date("Y-m-d H:i:s", time()),
  734. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  735. ]);
  736. $response->msg = "修改成功";
  737. $response->code = 200;
  738. return $response;
  739. }
  740. /**
  741. * 判断是否可以修改
  742. */
  743. public function validateIsEdit() {
  744. $id = $this->request["id"];
  745. $type = $this->request["type"];
  746. $info = null;
  747. if ($type == 1) { //编辑合同
  748. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  749. } else if ($type == 2) { //编辑项目
  750. $detail = \app\common\model\TalentAllowanceProject::find($id);
  751. }
  752. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  753. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  754. if ($info["checkState"] == -1) {
  755. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  756. } else if ($info["checkState"] == 30) {
  757. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  758. } else {
  759. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  760. }
  761. }
  762. return new Response(Response::SUCCESS, "");
  763. }
  764. /**
  765. * 提交审核
  766. */
  767. public function submitToCheck() {
  768. $data = $this->request->param();
  769. $response = new \stdClass();
  770. $response->code = 500;
  771. if (!$data || !$data["id"]) {
  772. $response->msg = "提交审核失败,请先填写基础信息";
  773. return $response;
  774. }
  775. $old = TalentAllowanceApi::getInfoById($data["id"]);
  776. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  777. if ($batch["code"] != 200) {
  778. $response->msg = $batch["msg"];
  779. return $response;
  780. }
  781. if ($old["checkState"] != 1 && $old["checkState"] != 10 && $old["checkState"] != 8) {
  782. $response->msg = "不能重复提交审核";
  783. return $response;
  784. }
  785. if (!$old["allowanceType"]) {
  786. $response->msg = "没有明确津贴类型";
  787. return $response;
  788. }
  789. //因为工作津贴和交通补贴两者的考勤分别记录的是月份和天数,如果没有手动修改值会导致数据不对口,如修改类型却未修改考勤记录,则手动改为空。
  790. $where = [];
  791. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_ATTENDANCE];
  792. $where[] = ["mainId", "=", $data["id"]];
  793. $attendanceList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  794. if ($old["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  795. //因为天数保存格式为 月份=天数 如 01=31,02=20,03=15,月份保存格式为01,02,03,所以可以从有没有=号判断是否有进行考勤的修改保存操作
  796. foreach ($attendanceList as $a) {
  797. //$a["months"]有值但是没有包含=号则一般可认为是类型修改为交通补贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  798. if ($a["months"] && strpos($a["months"], "=") === false) {
  799. $_updProject["id"] = $a["id"];
  800. $_updProject["months"] = "";
  801. \app\common\model\TalentAllowanceProject::update($_updProject);
  802. }
  803. }
  804. } else {
  805. foreach ($attendanceList as $a) {
  806. //$a["months"]有值但是包含了=号则一般可认为是类型修改为工作津贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  807. if ($a["months"] && strpos($a["months"], "=") !== false) {
  808. $_updProject["id"] = $a["id"];
  809. $_updProject["months"] = "";
  810. \app\common\model\TalentAllowanceProject::update($_updProject);
  811. }
  812. }
  813. }
  814. $where = [];
  815. $where[] = ["type", "=", $old["type"]];
  816. $where[] = ["project", "=", ProjectState::JBT];
  817. $where[] = ["isConditionFile", "=", $old["allowanceType"]];
  818. $where[] = ["active", "=", 1];
  819. $where[] = ["delete", "=", 0];
  820. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  821. $where = [];
  822. $where[] = ["enterpriseId", "=", $old["enterpriseId"]];
  823. $where[] = ["batch", "=", $old["year"]];
  824. $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();
  825. $relationIds = [];
  826. foreach ($commonFiles as $key => $row) {
  827. $_relationIds = array_filter(explode(",", $row["relationIds"]));
  828. $relationIds = array_merge($relationIds, $_relationIds);
  829. }
  830. foreach ($filetypes as $key => $filetype) {
  831. if (in_array($filetype["id"], $relationIds)) {
  832. $filetypes[$key]["must"] = 2;
  833. }
  834. }
  835. $sb = [];
  836. $sb[] = "以下为必传附件:";
  837. foreach ($filetypes as $filetype) {
  838. if ($filetype["must"] == 1) {
  839. $where = [];
  840. $where[] = ["mainId", "=", $data["id"]];
  841. $where[] = ["typeId", "=", $filetype["id"]];
  842. $count = Db::table("new_talent_file")->where($where)->count();
  843. if ($count == 0) {
  844. $sb[] = $filetype["name"] . ";";
  845. }
  846. }
  847. }
  848. if (count($sb) > 1) {
  849. $response->msg = implode("<br>", $sb);
  850. return $response;
  851. }
  852. /**
  853. * 初步判断合同是否满两年
  854. */
  855. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  856. foreach ($detailList as $detail) {
  857. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  858. $response->msg = "合同起止时间不能为空";
  859. return $response;
  860. }
  861. }
  862. foreach ($detailList as $detail) {
  863. $contractEndTime = strtotime($detail["endTime"]);
  864. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  865. $where = [];
  866. $where[] = ["mainId", "=", $data["id"]];
  867. $where[] = ["baseId", "=", $detail["id"]];
  868. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  869. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  870. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  871. }
  872. $data["checkMsg"] = "";
  873. $data["checkState"] = AllowanceStateEnum::NEED_CHECK;
  874. $afterState = 7; //待初审
  875. /* $ep = \app\common\api\EnterpriseApi::getOne($this->user["uid"]);
  876. if ($ep->isGeneral == 2 && \app\common\api\Nhc::hasGeneralHospital($ep->medicalCommunityId)) {
  877. $data["checkState"] = AllowanceStateEnum::NEED_GENERAL_CHECK; //分院并且有总院
  878. $afterState = 3; //待审核
  879. } */
  880. $data["files"] = "";
  881. $data["projects"] = "";
  882. $data["concats"] = "";
  883. $data["fields"] = "";
  884. $data["toDep"] = "";
  885. $data["process"] = null;
  886. if (!$old["firstSubmitTime"]) {
  887. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  888. }
  889. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  890. TaModel::update($data);
  891. //添加日志
  892. TalentChecklog::create([
  893. 'id' => getStringId(),
  894. 'mainId' => $data['id'],
  895. 'type' => intval(ProjectState::JBT),
  896. 'typeFileId' => null,
  897. 'active' => 1,
  898. 'state' => 1,
  899. 'step' => 0,
  900. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc($afterState)),
  901. 'description' => "确认提交审核",
  902. 'createTime' => date("Y-m-d H:i:s", time()),
  903. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  904. ]);
  905. $response->msg = "提交审核成功";
  906. $response->code = 200;
  907. $response->obj = 5;
  908. return $response;
  909. }
  910. public function updateSuppleState() {
  911. $id = $this->request["id"];
  912. $response = new \stdClass();
  913. $response->code = 500;
  914. if (\StrUtil::isEmpOrNull($id)) {
  915. $response->msg = "系统错误,请联系管理员";
  916. return $response;
  917. }
  918. $data["id"] = $id;
  919. $data["isSupple"] = 1;
  920. TaModel::update($data);
  921. $response->msg = "状态更新成功";
  922. $response->code = 200;
  923. return $response;
  924. }
  925. public function uploadCommonFile() {
  926. $batchId = $this->request["batch"];
  927. if (!$batchId) {
  928. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  929. }
  930. $batchInfo = BatchApi::getOne($batchId);
  931. if (!$batchInfo) {
  932. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  933. }
  934. if (!$this->request->file()) {
  935. return json(new Response(Response::ERROR, "没有上传任何材料"));
  936. }
  937. $file = $this->request->file("file");
  938. $upload = new UploadApi();
  939. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  940. if ($result->code != 200) {
  941. return json(new Response(Response::ERROR, $result->msg));
  942. }
  943. $data["id"] = getStringId();
  944. $data["enterpriseId"] = $this->user["uid"];
  945. $data["batchId"] = $batchId;
  946. $data["batch"] = $batchInfo["batch"];
  947. $data["url"] = $result->filepath;
  948. $data["originalName"] = $file->getOriginalName();
  949. $data["createTime"] = date("Y-m-d H:i:s");
  950. $data["createUser"] = $this->user["uid"];
  951. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  952. return json(new Response(Response::SUCCESS, "上传成功"));
  953. }
  954. public function listCommonFile() {
  955. $param = $this->request->param();
  956. $batchId = $param["batch"];
  957. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  958. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  959. $whr[] = ["type", "=", $this->user["type"]];
  960. $whr[] = ["project", "=", ProjectState::JBT];
  961. $whr[] = ["isConditionFile", "=", 0];
  962. $whr[] = ["delete", "=", 0];
  963. if ($this->user["type"] == CommonConst::ENTERPRISE_JC) {
  964. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->whereRaw("find_in_set(:enterpriseId,enterpriseIds)", ["enterpriseId" => $this->user["uid"]])->select()->toArray();
  965. } else {
  966. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->select()->toArray();
  967. }
  968. foreach ($list as $key => $item) {
  969. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  970. $list[$key]["url"] = getStoragePath($item["url"]);
  971. $list[$key]["fileTypes"] = $commonFileTypes;
  972. }
  973. return json(["rows" => $list]);
  974. }
  975. public function bindCommonFileWithFileType() {
  976. $params = $this->request->param();
  977. $fileId = $params["fileId"];
  978. $fileTypeId = $params["fileTypeId"];
  979. $upd["id"] = $fileId;
  980. $upd["fileTypeId"] = $fileTypeId ?: 0;
  981. $upd["updateTime"] = date("Y-m-d H:i:s");
  982. $upd["updateUser"] = $this->user["uid"];
  983. try {
  984. Db::table("un_talent_allowance_common_file")->update($upd);
  985. if ($fileTypeId > 0) {
  986. $msg = "关联成功";
  987. } else {
  988. $msg = "取消关联成功";
  989. }
  990. return json(new Response(Response::SUCCESS, $msg));
  991. } catch (\think\db\exception\DbException $e) {
  992. return json(new Response(Response::ERROR, $e->getMessage()));
  993. }
  994. }
  995. public function deleteCommonFile() {
  996. $id = $this->request["id"];
  997. $where = [];
  998. $where[] = ["id", "=", $id];
  999. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1000. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  1001. if (!$file) {
  1002. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  1003. }
  1004. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  1005. if (!empty($file["url"])) {
  1006. $filepath = "storage/" . $file["url"];
  1007. if (file_exists($filepath)) {
  1008. unlink($filepath);
  1009. }
  1010. }
  1011. return json(new Response(Response::SUCCESS, "删除成功"));
  1012. }
  1013. }
  1014. public function findTalentAllowance() {
  1015. $res = [];
  1016. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  1017. $year = $batch["batch"];
  1018. if ($year) {
  1019. $ids = null;
  1020. //根据申报年度查询当前企业已申报的人才
  1021. $where = [];
  1022. $where[] = ["year", "=", $year];
  1023. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1024. $talentAllowances = TaModel::where($where)->select()->toArray();
  1025. $ids = array_unique(array_column($talentAllowances, "talentId"));
  1026. $whr = [];
  1027. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  1028. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  1029. $whr[] = ["e.type", "=", $this->user["type"]];
  1030. $whr[] = ["ti.id", "not in", $ids];
  1031. $twiceIdentifyPersons = \app\common\api\VerifyApi::getTwiceIdentifyPersons();
  1032. if ($twiceIdentifyPersons) {
  1033. $_whr = $whr;
  1034. $whr[] = ["card_number", "not in", $twiceIdentifyPersons];
  1035. $_whr[] = ["card_number", "in", $twiceIdentifyPersons];
  1036. $tmpList = \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();
  1037. $twiceIdentifyPersonList = [];
  1038. $otherTypeChangeList = [];
  1039. foreach ($tmpList as $person) {
  1040. if (!$twiceIdentifyPersonList[$person["idCard"]]) {
  1041. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1042. } else {
  1043. if ($person["talent_arrange"] < $twiceIdentifyPersonList[$person["idCard"]]["talent_arrange"]) {
  1044. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $twiceIdentifyPersonList[$person["idCard"]]["identifyMonth"], "oldIdentifyGetTime" => $twiceIdentifyPersonList[$person["idCard"]]["identifyGetTime"]];
  1045. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1046. } else {
  1047. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $person["identifyMonth"], "oldIdentifyGetTime" => $person["identifyGetTime"]];
  1048. }
  1049. }
  1050. }
  1051. sort($twiceIdentifyPersonList);
  1052. }
  1053. $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();
  1054. if ($twiceIdentifyPersonList) {
  1055. $list = array_merge((array) $list, $twiceIdentifyPersonList);
  1056. }
  1057. foreach ($list as $info) {
  1058. $identifyTime = $info["identifyMonth"];
  1059. if ($info["eType"] == CommonConst::ENTERPRISE_JC) {
  1060. $identifyTime = $info["identifyGetTime"] ?: $info["identifyMonth"];
  1061. }
  1062. if (strtotime($year . "-12-31") >= strtotime($identifyTime)) {
  1063. $res[] = $info;
  1064. } else {
  1065. $whereTypeChange = [];
  1066. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  1067. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  1068. $whereTypeChange[] = ["isPublic", "=", 6];
  1069. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  1070. if ($otherTypeChangeList[$info["idCard"]]) {
  1071. $typeChanges = array_merge($otherTypeChangeList[$info["idCard"]], (array) $typeChanges);
  1072. }
  1073. foreach ($typeChanges as $typeChange) {
  1074. $oldIdentifyTime = $typeChange["oldIdentifyMonth"];
  1075. if ($typeChange["type"] == CommonConst::ENTERPRISE_JC) {
  1076. $oldIdentifyTime = $typeChange["oldIdentifyGetTime"] ?: $typeChange["oldIdentifyMonth"];
  1077. }
  1078. if (strtotime($year . "-12-31") >= strtotime($oldIdentifyTime)) {
  1079. $res[] = $info;
  1080. break;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. }
  1086. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  1087. }
  1088. public function export() {
  1089. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  1090. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  1091. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  1092. $obj["allowanceType"] = \StrUtil::getRequestDecodeParam($this->request, "allowanceType");
  1093. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  1094. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  1095. $where = [];
  1096. $where[] = ["ta.delete", "=", 0];
  1097. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  1098. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  1099. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  1100. }
  1101. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  1102. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  1103. }
  1104. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  1105. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  1106. }
  1107. if (\StrUtil::isNotEmpAndNull($obj["allowanceType"])) {
  1108. $where[] = ["ta.allowanceType", "=", $obj["allowanceType"]];
  1109. }
  1110. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  1111. $where[] = ["ta.address", "=", $obj["address"]];
  1112. }
  1113. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  1114. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  1115. }
  1116. $projects = [
  1117. AllowanceProjectEnum::PROJECT_TAX,
  1118. AllowanceProjectEnum::PROJECT_WAGES,
  1119. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  1120. AllowanceProjectEnum::PROJECT_SB_PENSION,
  1121. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  1122. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  1123. ];
  1124. $months = [];
  1125. for ($m = 1; $m <= 12; $m++) {
  1126. $months[] = $m . "月";
  1127. }
  1128. $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]]];
  1129. $infoCols = count($columns);
  1130. for ($i = 0; $i < count($projects); $i++) {
  1131. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  1132. }
  1133. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  1134. ->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")
  1135. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  1136. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  1137. ->where($where)
  1138. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  1139. ->select()->toArray();
  1140. $tmpList = [];
  1141. $levelMap = DictApi::selectByParentCode("talent_arrange");
  1142. $streetMap = DictApi::selectByParentCode("street");
  1143. $where = [];
  1144. $where[] = ["id", "in", array_column($list, "identifyCondition")];
  1145. $icmap = \app\common\model\TalentCondition::where($where)->column("name", "id");
  1146. $where = [];
  1147. $where[] = ["id", "in", array_column($list, "enterpriseId")];
  1148. $enterpriseMap = \app\common\model\Enterprise::where($where)->column("name", "id");
  1149. foreach ($list as $item) {
  1150. //组装数据
  1151. if (!$tmpList[$item["id"]]) {
  1152. $tmpList[$item["id"]]["curEnterpriseId"] = $item["curEnterpriseId"];
  1153. $tmpList[$item["id"]]["info"] = [$item["year"], $streetMap[$item["address"]], $item["name"], $item["sex"] == 1 ? "男" : "女", $item["idCard"], $levelMap[$item["talentArrange"]],
  1154. $icmap[$item["identifyCondition"]], $item["identifyGetTime"], $item["identifyConditionName"], $item["identifyMonth"], AllowanceTypeEnum::getTypeName($item["allowanceType"]), $item["virtualAmount"], $item["months"], $item["money"],
  1155. $item["moneyDesc"], $this->getCheckStateName($item["checkState"], $item["publicState"], $item["allowanceType"])];
  1156. }
  1157. if (!$tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]) {
  1158. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]] = [
  1159. "startTime" => $item["startTime"],
  1160. "endTime" => $item["endTime"],
  1161. "entryTime" => $item["entryTime"],
  1162. "isQuit" => $item["isQuit"]
  1163. ];
  1164. }
  1165. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]["projects"][$item["project"]] = $item["pre_months"];
  1166. }
  1167. $rows = [];
  1168. $colorset = [];
  1169. foreach ($tmpList as $id => $item) {
  1170. foreach ($item["enterprise"] as $enterpriseId => $enterprise) {
  1171. $row = $item["info"];
  1172. $row[] = $this->user["uid"] == $enterpriseId ? "本单位" : $enterpriseMap[$enterpriseId];
  1173. for ($i = 0; $i < count($projects); $i++) {
  1174. if (strpos($enterprise["projects"][$projects[$i]], "=") === false) {
  1175. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1176. for ($m = 1; $m <= 12; $m++) {
  1177. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1178. if (in_array($_month, $months)) {
  1179. $row[] = "✔";
  1180. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1181. } else {
  1182. $row[] = "";
  1183. }
  1184. }
  1185. } else {
  1186. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1187. $_months = [];
  1188. foreach ($months as $month) {
  1189. $kv = explode("=", $month);
  1190. $_months[$kv[0]] = $kv[1];
  1191. }
  1192. for ($m = 1; $m <= 12; $m++) {
  1193. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1194. $days = $_months[$_month];
  1195. if ($days && $days > 0) {
  1196. $row[] = $days . "天";
  1197. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1198. } else {
  1199. $row[] = "";
  1200. }
  1201. }
  1202. }
  1203. }
  1204. $rows[] = $row;
  1205. }
  1206. }
  1207. $cols = $infoCols + count($projects) * 12 - 1;
  1208. $settings = [
  1209. "width" => [["A", 8], ["C", 12], ["D", 6], ["E", 20], ["F", 12], ["G", 70], ["H", 12], ["I", 15], ["J", 12], ["K", 12], ["P", 30]],
  1210. "height" => [18],
  1211. "freeze" => "D3",
  1212. "color" => $colorset
  1213. ];
  1214. for ($i = 0; $i < count($projects) * 12; $i++) {
  1215. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  1216. }
  1217. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  1218. export($columns, $rows, "津补贴申报名单", $settings);
  1219. }
  1220. /**
  1221. * 审核列表页
  1222. */
  1223. public function examineCenter() {
  1224. $tpl = "";
  1225. switch ($this->user["type"]) {
  1226. case CommonConst::ENTERPRISE_WJ:
  1227. $tpl = "/talent_allowance/examine_center"; //卫健医院
  1228. break;
  1229. }
  1230. return view($tpl);
  1231. }
  1232. /**
  1233. * 审核列表页
  1234. */
  1235. public function examineList() {
  1236. $res = TalentAllowanceApi::getHospitalExamineList($this->request);
  1237. return json($res);
  1238. }
  1239. /**
  1240. * 审核页面
  1241. * @return type
  1242. */
  1243. public function toCheckPage() {
  1244. $id = $this->request["id"];
  1245. $process = $this->request["process"];
  1246. $obj = TalentAllowanceApi::getInfoById($id);
  1247. $this->translateToChinese($obj);
  1248. return view("check", ["row" => $obj, "process" => $process]);
  1249. }
  1250. /**
  1251. * 查看详情
  1252. * @return type
  1253. */
  1254. public function toSelectPage() {
  1255. $id = $this->request["id"];
  1256. $process = $this->request["process"];
  1257. $obj = TalentAllowanceApi::getInfoById($id);
  1258. $this->translateToChinese($obj);
  1259. return view("check", ["row" => $obj, "process" => $process]);
  1260. }
  1261. /**
  1262. * 审核保存
  1263. */
  1264. public function check() {
  1265. $obj = $this->request->param();
  1266. if (!$obj["checkState"]) {
  1267. return new Response(Response::ERROR, "请选择审核状态");
  1268. }
  1269. $oldObj = TalentAllowanceApi::getInfoById($obj["id"]);
  1270. if (!$oldObj) {
  1271. return new Response(Response::ERROR, "审核对象不存在");
  1272. }
  1273. $ep = \app\common\api\EnterpriseApi::getOne($oldObj["enterpriseId"]);
  1274. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1275. return new Response(Response::ERROR, "不在审核范围内");
  1276. }
  1277. if ($oldObj["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $oldObj["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1278. return new Response(Response::ERROR, "不在审核范围内");
  1279. }
  1280. $newObj = [];
  1281. $newObj["id"] = $obj["id"];
  1282. $projectList = [];
  1283. $fileList = [];
  1284. if (\StrUtil::isNotEmpAndNull($obj["projects"])) {
  1285. $projectList = array_filter(explode(",", $obj["projects"]));
  1286. $newObj["projects"] = implode(",", $projectList);
  1287. }
  1288. if (\StrUtil::isNotEmpAndNull($obj["files"])) {
  1289. $fileList = array_filter(explode(",", $obj["files"]));
  1290. $newObj["files"] = implode(",", $fileList);
  1291. }
  1292. $newObj["concats"] = $obj["concats"];
  1293. $newObj["fields"] = $obj["fields"];
  1294. //}
  1295. TaModel::update($newObj);
  1296. //添加日志
  1297. TalentChecklog::create([
  1298. 'id' => getStringId(),
  1299. 'mainId' => $obj['id'],
  1300. 'type' => intval(ProjectState::JBT),
  1301. 'typeFileId' => null,
  1302. 'active' => 2,
  1303. 'state' => $obj["checkState"],
  1304. 'step' => -2,
  1305. 'stateChange' => null,
  1306. 'description' => $obj["checkMsg"],
  1307. 'createTime' => date("Y-m-d H:i:s", time()),
  1308. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1309. ]);
  1310. return new Response(Response::SUCCESS, "审核成功");
  1311. }
  1312. /**
  1313. * 提交审核
  1314. * @return Response
  1315. */
  1316. public function submitCheck() {
  1317. $id = $this->request["id"];
  1318. $process = -2;
  1319. $old = TalentAllowanceApi::getInfoById($id);
  1320. if (!$old) {
  1321. return new Response(Response::ERROR, "审核对象不存在");
  1322. }
  1323. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1324. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1325. return new Response(Response::ERROR, "不在审核范围内");
  1326. }
  1327. if ($old["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $old["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1328. return new Response(Response::ERROR, "不在审核范围内");
  1329. }
  1330. $updCheck = [];
  1331. $updCheck["id"] = $id;
  1332. $updCheck["type"] = $old["type"];
  1333. /* * 查询审核日志 */
  1334. $log = \app\common\api\TalentLogApi::getLastLogByStep($id, ProjectState::JBT, $process);
  1335. if (!$log) {
  1336. return new Response(Response::ERROR, "请先审核后再提交");
  1337. }
  1338. $updCheck["checkMsg"] = $log["description"];
  1339. /* * 判断到达的最高流程 */
  1340. $updCheck["highProcess"] = !$old["highProcess"] || $old["highProcess"] < $process ? $process : $old["process"];
  1341. switch ($log["state"]) {
  1342. case 3:
  1343. $updCheck["precheckPassTime"] = $old["precheckPassTime"];
  1344. if (!$old["precheckPassTime"]) {
  1345. $updCheck["precheckPassTime"] = date("Y-m-d H:i:s");
  1346. }
  1347. $updCheck["submitTime"] = date("Y-m-d H:i:s");
  1348. $updCheck["checkState"] = AllowanceStateEnum::NEED_CHECK;
  1349. break;
  1350. case 2:
  1351. $updCheck["checkState"] = AllowanceStateEnum::GENERAL_REJECT;
  1352. break;
  1353. case -1:
  1354. $updCheck["checkState"] = AllowanceStateEnum::NOTPASS;
  1355. $updCheck["recommendAllowanceType"] = 3;
  1356. $updCheck["recommendMoney"] = 0;
  1357. $updCheck["recommendAllowanceMsg"] = "审核不通过,不予兑现";
  1358. break;
  1359. default:
  1360. return new Response(Response::ERROR, "未知的审核状态");
  1361. }
  1362. //添加日志
  1363. TalentChecklog::create([
  1364. 'id' => getStringId(),
  1365. 'mainId' => $id,
  1366. 'type' => intval(ProjectState::JBT),
  1367. 'typeFileId' => null,
  1368. 'active' => 1,
  1369. 'state' => $log["state"],
  1370. 'step' => $process,
  1371. 'stateChange' => AllowanceStateEnum::getStateName($old["checkState"]) . "->" . AllowanceStateEnum::getStateName($updCheck["checkState"]),
  1372. 'description' => $log["description"],
  1373. 'createTime' => date("Y-m-d H:i:s", time()),
  1374. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1375. ]);
  1376. TalentChecklog::where("id", $log["id"])->delete();
  1377. TaModel::update($updCheck);
  1378. return new Response(Response::SUCCESS, "提交审核成功");
  1379. }
  1380. /**
  1381. * 校验是否在审核范围内
  1382. */
  1383. public function validateIsCheck() {
  1384. $id = $this->request["id"];
  1385. $type = $this->request["type"];
  1386. $info = null;
  1387. switch ($type) {
  1388. case 1: //编辑合同
  1389. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  1390. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  1391. break;
  1392. case 2: //编辑项目
  1393. $project = \app\common\model\TalentAllowanceProject::find($id);
  1394. $info = TalentAllowanceApi::getInfoById($project["mainId"]);
  1395. break;
  1396. case 3:
  1397. $info = TalentAllowanceApi::getInfoById($id);
  1398. break;
  1399. }
  1400. if (!$info) {
  1401. return new Response(Response::ERROR, "校验不通过,无法操作");
  1402. }
  1403. $ep = \app\common\api\EnterpriseApi::getOne($info["enterpriseId"]);
  1404. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1405. return new Response(Response::ERROR, "不在审核范围内");
  1406. }
  1407. $where = [];
  1408. $where[] = ["mainId", "=", $info["id"]];
  1409. $where[] = ["step", "=", -2];
  1410. $where[] = ["active", "=", 2];
  1411. $log = null;
  1412. if ($info["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $info["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1413. return new Response(Response::ERROR, "不在审核范围内");
  1414. }
  1415. $log = TalentChecklog::where($where)->order("createTime desc")->find();
  1416. if ($log != null) {
  1417. $info["checkState"] = $log["state"];
  1418. $info["checkMsg"] = $log["description"];
  1419. } else {
  1420. $info["checkState"] = null;
  1421. $info["checkMsg"] = "";
  1422. }
  1423. $res = [];
  1424. $res["info"] = $info;
  1425. if ($type == 3) {
  1426. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1427. $where = [];
  1428. $where[] = ["mainId", "=", $id];
  1429. $where[] = ["isLock", "=", 1];
  1430. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1431. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1432. $detailMap = array_reduce($detailList, function ($result, $item) {
  1433. $key = $item["id"];
  1434. $result[$key] = $item;
  1435. return $result;
  1436. }, []);
  1437. foreach ($detailList as &$detail) {
  1438. $detail["enterpriseName"] = sprintf("%s(%s至%s)", $enterpriseMap[$detail["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1439. }unset($detail);
  1440. foreach ($projectList as &$project) {
  1441. $detail = $detailMap[$project["baseId"]];
  1442. $project["projectName"] = sprintf("%s(%s(%s至%s))", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1443. }
  1444. $where = [];
  1445. $where[] = ["type", "=", $info["type"]];
  1446. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1447. $where[] = ["active", "=", 1];
  1448. $where[] = ["delete", "=", 0];
  1449. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1450. $res["files"] = $filetypes;
  1451. $res["projects"] = $projectList;
  1452. $res["concats"] = $detailList;
  1453. }
  1454. return new Response(Response::SUCCESS, "不在审核范围内", $res);
  1455. }
  1456. /**
  1457. * 初始化可修改的项目/附件/合同
  1458. * */
  1459. public function findFieldsAndFiles() {
  1460. $id = $this->request["id"];
  1461. if (\StrUtil::isEmpOrNull($id)) {
  1462. return new Response(Response::ERROR, "请选择需要修改的对象");
  1463. }
  1464. $info = TalentAllowanceApi::getInfoById($id);
  1465. if (!$info) {
  1466. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1467. }
  1468. if ($info["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1469. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1470. }
  1471. $res = [];
  1472. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1473. $where = [];
  1474. $where[] = ["mainId", "=", $id];
  1475. $where[] = ["isLock", "=", 1];
  1476. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1477. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1478. foreach ($detailList as &$detail) {
  1479. $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
  1480. }unset($detail);
  1481. foreach ($projectList as &$project) {
  1482. $detail = $detailMap[$project["baseId"]];
  1483. $project["projectName"] = sprintf("%s(%s)", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]]);
  1484. }unset($project);
  1485. $where = [];
  1486. $where[] = ["type", "=", $info["type"]];
  1487. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1488. $where[] = ["active", "=", 1];
  1489. $where[] = ["delete", "=", 0];
  1490. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1491. $res["files"] = $filetypes;
  1492. $res["projects"] = $projectList;
  1493. $res["concats"] = $detailList;
  1494. $res["info"] = $info;
  1495. return new Response(Response::SUCCESS, "", $res);
  1496. }
  1497. /**
  1498. * 修改驳回项目/附件/合同
  1499. * */
  1500. public function updateFieldsAndFiles() {
  1501. $data = $this->request->param();
  1502. if (!$data["id"]) {
  1503. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1504. }
  1505. $old = TalentAllowanceApi::getInfoById($data["id"]);
  1506. if (!$old) {
  1507. return new Response(Response::ERROR, "审核对象不存在");
  1508. }
  1509. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1510. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1511. return new Response(Response::ERROR, "不在审核范围内");
  1512. }
  1513. if ($old["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1514. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1515. }
  1516. TaModel::update($data);
  1517. return new Response(Response::SUCCESS, "修改成功");
  1518. }
  1519. private function checkExaminePriv($isGeneral, $medicalCommunityId) {
  1520. if ($this->user["medicalCommunityId"] == $medicalCommunityId && $this->user["isGeneral"] == 1 && $isGeneral == 2) {
  1521. return true;
  1522. }
  1523. return false;
  1524. }
  1525. private function getCheckStateName($checkState, $publicState, $allowanceType) {
  1526. switch ($checkState) {
  1527. case 1:
  1528. return "待提交";
  1529. case 3:
  1530. case 5:
  1531. case 13:
  1532. case 15:
  1533. case 20:
  1534. case 25:
  1535. case 35:
  1536. return "审核中";
  1537. case 8:
  1538. return "总院驳回";
  1539. case 9:
  1540. case 10:
  1541. return "已驳回";
  1542. case - 1:
  1543. if ($publicState >= 3) {
  1544. return "审核不通过";
  1545. } else {
  1546. return "审核中";
  1547. }
  1548. break;
  1549. case 30:
  1550. if ($publicState == 1) {
  1551. return "待核查征信";
  1552. } else if ($publicState == 2) {
  1553. return "待公示";
  1554. } else if ($publicState == 3) {
  1555. return "公示中";
  1556. } else if ($publicState == 4) {
  1557. return $allowanceType != 3 ? "待兑现" : "不予兑现";
  1558. } else if ($publicState == 5) {
  1559. return "已兑现";
  1560. }
  1561. default:
  1562. return "未知状态";
  1563. }
  1564. }
  1565. }