TalentAllowance.php 71 KB

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