TalentAllowance.php 52 KB

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