TalentAllowance.php 56 KB

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