TalentAllowance.php 72 KB

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