TalentAllowance.php 51 KB

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