TalentAllowance.php 58 KB

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