TalentAllowance.php 76 KB

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