TalentAllowance.php 56 KB

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