TalentAllowance.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  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 ($info["type"] == CommonConst::ENTERPRISE_WJ && 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", "in", [0, $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. $sb = [];
  758. $sb[] = "以下为必传附件:";
  759. foreach ($filetypes as $filetype) {
  760. if ($filetype["must"] == 1) {
  761. $where = [];
  762. $where[] = ["mainId", "=", $data["id"]];
  763. $where[] = ["typeId", "=", $filetype["id"]];
  764. $count = Db::table("new_talent_file")->where($where)->count();
  765. if ($count == 0) {
  766. $sb[] = $filetype["name"] . ";";
  767. }
  768. }
  769. }
  770. if (count($sb) > 1) {
  771. $response->msg = implode("<br>", $sb);
  772. return $response;
  773. }
  774. /**
  775. * 初步判断合同是否满两年
  776. */
  777. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  778. foreach ($detailList as $detail) {
  779. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  780. $response->msg = "合同起止时间不能为空";
  781. return $response;
  782. }
  783. }
  784. foreach ($detailList as $detail) {
  785. $contractEndTime = strtotime($detail["endTime"]);
  786. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  787. $where = [];
  788. $where[] = ["mainId", "=", $data["id"]];
  789. $where[] = ["baseId", "=", $detail["id"]];
  790. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  791. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  792. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  793. }
  794. $data["checkMsg"] = "";
  795. $data["checkState"] = 5;
  796. $data["files"] = "";
  797. $data["projects"] = "";
  798. $data["concats"] = "";
  799. $data["fields"] = "";
  800. $data["toDep"] = "";
  801. $data["process"] = null;
  802. if (!$old["firstSubmitTime"]) {
  803. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  804. }
  805. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  806. TaModel::update($data);
  807. //添加日志
  808. TalentChecklog::create([
  809. 'id' => getStringId(),
  810. 'mainId' => $data['id'],
  811. 'type' => intval(ProjectState::JBT),
  812. 'typeFileId' => null,
  813. 'active' => 1,
  814. 'state' => 1,
  815. 'step' => 0,
  816. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
  817. 'description' => "确认提交审核",
  818. 'createTime' => date("Y-m-d H:i:s", time()),
  819. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  820. ]);
  821. $response->msg = "提交审核成功";
  822. $response->code = 200;
  823. $response->obj = 5;
  824. return $response;
  825. }
  826. public function updateSuppleState() {
  827. $id = $this->request["id"];
  828. $response = new \stdClass();
  829. $response->code = 500;
  830. if (\StrUtil::isEmpOrNull($id)) {
  831. $response->msg = "系统错误,请联系管理员";
  832. return $response;
  833. }
  834. $data["id"] = $id;
  835. $data["isSupple"] = 1;
  836. TaModel::update($data);
  837. $response->msg = "状态更新成功";
  838. $response->code = 200;
  839. return $response;
  840. }
  841. public function uploadCommonFile() {
  842. $batchId = $this->request["batch"];
  843. if (!$batchId) {
  844. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  845. }
  846. $batchInfo = BatchApi::getOne($batchId);
  847. if (!$batchInfo) {
  848. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  849. }
  850. if (!$this->request->file()) {
  851. return json(new Response(Response::ERROR, "没有上传任何材料"));
  852. }
  853. $file = $this->request->file("file");
  854. $upload = new UploadApi();
  855. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  856. if ($result->code != 200) {
  857. return json(new Response(Response::ERROR, $result->msg));
  858. }
  859. $data["id"] = getStringId();
  860. $data["enterpriseId"] = $this->user["uid"];
  861. $data["batchId"] = $batchId;
  862. $data["batch"] = $batchInfo["batch"];
  863. $data["url"] = $result->filepath;
  864. $data["originalName"] = $file->getOriginalName();
  865. $data["createTime"] = date("Y-m-d H:i:s");
  866. $data["createUser"] = $this->user["uid"];
  867. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  868. return json(new Response(Response::SUCCESS, "上传成功"));
  869. }
  870. public function listCommonFile() {
  871. $param = $this->request->param();
  872. $batchId = $param["batch"];
  873. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  874. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  875. foreach ($list as $key => $item) {
  876. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  877. $list[$key]["url"] = getStoragePath($item["url"]);
  878. }
  879. return json(["rows" => $list]);
  880. }
  881. public function deleteCommonFile() {
  882. $id = $this->request["id"];
  883. $where = [];
  884. $where[] = ["id", "=", $id];
  885. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  886. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  887. if (!$file) {
  888. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  889. }
  890. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  891. if (!empty($file["url"])) {
  892. $filepath = "storage/" . $file["url"];
  893. if (file_exists($filepath)) {
  894. unlink($filepath);
  895. }
  896. }
  897. return json(new Response(Response::SUCCESS, "删除成功"));
  898. }
  899. }
  900. public function findTalentAllowance() {
  901. $res = [];
  902. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  903. $year = $batch["batch"];
  904. if ($year) {
  905. $ids = null;
  906. //根据申报年度查询当前企业已申报的人才
  907. $where = [];
  908. $where[] = ["year", "=", $year];
  909. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  910. $talentAllowances = TaModel::where($where)->select()->toArray();
  911. $ids = array_unique(array_column($talentAllowances, "talentId"));
  912. $whr = [];
  913. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  914. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  915. $whr[] = ["e.type", "=", $this->user["type"]];
  916. $whr[] = ["ti.id", "not in", $ids];
  917. $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();
  918. foreach ($list as $info) {
  919. $identifyTime = $info["identifyMonth"];
  920. if ($info["eType"] == CommonConst::ENTERPRISE_JC) {
  921. $identifyTime = $info["identifyGetTime"] ?: $info["identifyMonth"];
  922. }
  923. if (strtotime($year . "-12-31") >= strtotime($identifyTime)) {
  924. $res[] = $info;
  925. } else {
  926. $whereTypeChange = [];
  927. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  928. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  929. $whereTypeChange[] = ["isPublic", "=", 6];
  930. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  931. foreach ($typeChanges as $typeChange) {
  932. $oldIdentifyTime = $typeChange["oldIdentifyMonth"];
  933. if ($typeChange["type"] == CommonConst::ENTERPRISE_JC) {
  934. $oldIdentifyTime = $typeChange["oldIdentifyGetTime"] ?: $typeChange["oldIdentifyMonth"];
  935. }
  936. if (strtotime($year . "-12-31") >= strtotime($oldIdentifyTime)) {
  937. $res[] = $info;
  938. break;
  939. }
  940. }
  941. }
  942. }
  943. }
  944. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  945. }
  946. public function export() {
  947. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  948. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  949. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  950. $obj["allowanceType"] = \StrUtil::getRequestDecodeParam($this->request, "allowanceType");
  951. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  952. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  953. $where = [];
  954. $where[] = ["ta.delete", "=", 0];
  955. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  956. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  957. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  958. }
  959. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  960. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  961. }
  962. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  963. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  964. }
  965. if (\StrUtil::isNotEmpAndNull($obj["allowanceType"])) {
  966. $where[] = ["ta.allowanceType", "=", $obj["allowanceType"]];
  967. }
  968. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  969. $where[] = ["ta.address", "=", $obj["address"]];
  970. }
  971. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  972. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  973. }
  974. $projects = [
  975. AllowanceProjectEnum::PROJECT_TAX,
  976. AllowanceProjectEnum::PROJECT_WAGES,
  977. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  978. AllowanceProjectEnum::PROJECT_SB_PENSION,
  979. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  980. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  981. ];
  982. $months = [];
  983. for ($m = 1; $m <= 12; $m++) {
  984. $months[] = $m . "月";
  985. }
  986. $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]]];
  987. $infoCols = count($columns);
  988. for ($i = 0; $i < count($projects); $i++) {
  989. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  990. }
  991. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  992. ->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")
  993. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  994. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  995. ->where($where)
  996. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  997. ->select()->toArray();
  998. $tmpList = [];
  999. $levelMap = DictApi::selectByParentCode("talent_arrange");
  1000. $streetMap = DictApi::selectByParentCode("street");
  1001. $where = [];
  1002. $where[] = ["id", "in", array_column($list, "identifyCondition")];
  1003. $icmap = \app\common\model\TalentCondition::where($where)->column("name", "id");
  1004. $where = [];
  1005. $where[] = ["id", "in", array_column($list, "enterpriseId")];
  1006. $enterpriseMap = \app\common\model\Enterprise::where($where)->column("name", "id");
  1007. foreach ($list as $item) {
  1008. //组装数据
  1009. if (!$tmpList[$item["id"]]) {
  1010. $tmpList[$item["id"]]["curEnterpriseId"] = $item["curEnterpriseId"];
  1011. $tmpList[$item["id"]]["info"] = [$item["year"], $streetMap[$item["address"]], $item["name"], $item["sex"] == 1 ? "男" : "女", $item["idCard"], $levelMap[$item["talentArrange"]],
  1012. $icmap[$item["identifyCondition"]], $item["identifyGetTime"], $item["identifyConditionName"], $item["identifyMonth"], AllowanceTypeEnum::getTypeName($item["allowanceType"]), $item["months"], $item["money"],
  1013. $item["moneyDesc"], $this->getCheckStateName($item["checkState"], $item["publicState"], $item["allowanceType"])];
  1014. }
  1015. if (!$tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]) {
  1016. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]] = [
  1017. "startTime" => $item["startTime"],
  1018. "endTime" => $item["endTime"],
  1019. "entryTime" => $item["entryTime"],
  1020. "isQuit" => $item["isQuit"]
  1021. ];
  1022. }
  1023. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]["projects"][$item["project"]] = $item["pre_months"];
  1024. }
  1025. $rows = [];
  1026. $colorset = [];
  1027. foreach ($tmpList as $id => $item) {
  1028. foreach ($item["enterprise"] as $enterpriseId => $enterprise) {
  1029. $row = $item["info"];
  1030. $row[] = $this->user["uid"] == $enterpriseId ? "本单位" : $enterpriseMap[$enterpriseId];
  1031. for ($i = 0; $i < count($projects); $i++) {
  1032. if (strpos($enterprise["projects"][$projects[$i]], "=") === false) {
  1033. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1034. for ($m = 1; $m <= 12; $m++) {
  1035. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1036. if (in_array($_month, $months)) {
  1037. $row[] = "✔";
  1038. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1039. } else {
  1040. $row[] = "";
  1041. }
  1042. }
  1043. } else {
  1044. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1045. $_months = [];
  1046. foreach ($months as $month) {
  1047. $kv = explode("=", $month);
  1048. $_months[$kv[0]] = $kv[1];
  1049. }
  1050. for ($m = 1; $m <= 12; $m++) {
  1051. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1052. $days = $_months[$_month];
  1053. if ($days && $days > 0) {
  1054. $row[] = $days . "天";
  1055. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1056. } else {
  1057. $row[] = "";
  1058. }
  1059. }
  1060. }
  1061. }
  1062. $rows[] = $row;
  1063. }
  1064. }
  1065. $cols = $infoCols + count($projects) * 12 - 1;
  1066. $settings = [
  1067. "width" => [["A", 8], ["C", 12], ["D", 6], ["E", 20], ["F", 12], ["G", 70], ["H", 12], ["I", 15], ["J", 12], ["K", 12], ["P", 30]],
  1068. "height" => [18],
  1069. "freeze" => "D3",
  1070. "color" => $colorset
  1071. ];
  1072. for ($i = 0; $i < count($projects) * 12; $i++) {
  1073. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  1074. }
  1075. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  1076. export($columns, $rows, "津补贴申报名单", $settings);
  1077. }
  1078. private function getCheckStateName($checkState, $publicState, $allowanceType) {
  1079. switch ($checkState) {
  1080. case 1:
  1081. return "待提交";
  1082. case 5:
  1083. case 13:
  1084. case 15:
  1085. case 20:
  1086. case 25:
  1087. case 35:
  1088. return "审核中";
  1089. case 10:
  1090. return "已驳回";
  1091. case - 1:
  1092. if ($publicState >= 3) {
  1093. return "审核不通过";
  1094. } else {
  1095. return "审核中";
  1096. }
  1097. break;
  1098. case 30:
  1099. if ($publicState == 1) {
  1100. return "待核查征信";
  1101. } else if ($publicState == 2) {
  1102. return "待公示";
  1103. } else if ($publicState == 3) {
  1104. return "公示中";
  1105. } else if ($publicState == 4) {
  1106. return $allowanceType != 3 ? "待兑现" : "不予兑现";
  1107. } else if ($publicState == 5) {
  1108. return "已兑现";
  1109. }
  1110. default:
  1111. return "未知状态";
  1112. }
  1113. }
  1114. }