TalentAllowance.php 78 KB

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