TalentAllowance.php 54 KB

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