TalentAllowance.php 56 KB

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