TalentAllowance.php 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716
  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. $templateFile = "gjjbtbiao.xlsx";
  40. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ) {
  41. $need_extra_project = getJsonConfig("../sys_config.json", "talent_allowance_need_extra_project");
  42. if ($need_extra_project[$this->user["uid"]]) {
  43. if ($need_extra_project[$this->user["uid"]][1] == AllowanceProjectEnum::PROJECT_TRAINING_PROGRAM) {
  44. $templateFile = "gjjbtbiao_2.xlsx";
  45. } else {
  46. $templateFile = "gjjbtbiao_1.xlsx";
  47. }
  48. }
  49. }
  50. return view($tpl, ['type' => $this->user["type"], "templateFile" => $templateFile]);
  51. }
  52. public function list() {
  53. $res = TalentAllowanceApi::getList($this->request);
  54. return json($res);
  55. }
  56. public function calculator($id) {
  57. $cal = TalentAllowanceApi::validateAllowanceType($id);
  58. return json($cal);
  59. }
  60. /**
  61. * 申请
  62. */
  63. public function apply(\think\Request $request) {
  64. $param = $request->param();
  65. $id = isset($param["id"]) ? $param["id"] : 0;
  66. $info = null;
  67. if ($id) {
  68. $info = TalentAllowanceApi::getInfoById($id);
  69. $this->translateToChinese($info);
  70. }
  71. if ($request->isPost()) {
  72. return $this->save($info, $request);
  73. }
  74. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  75. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ) {
  76. $need_choose_post_type = getJsonConfig("../sys_config.json", "talent_allowance_need_choose_post_type");
  77. $need_choose_institution = getJsonConfig("../sys_config.json", "talent_allowance_need_choose_institution");
  78. if ($need_choose_post_type[$this->user["uid"]]) {
  79. $postTypes = DictApi::findChildDictByCode("PostType");
  80. foreach ($postTypes as $key => $pt) {
  81. if (!in_array($pt["code"], $need_choose_post_type[$this->user["uid"]])) {
  82. unset($postTypes[$key]);
  83. }
  84. }
  85. }
  86. if (in_array($this->user["uid"], $need_choose_institution)) {
  87. $institutions = DictApi::findChildDictByCode("institution");
  88. }
  89. }
  90. return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info, "postTypes" => $postTypes, "institutions" => $institutions]);
  91. }
  92. /**
  93. * 批量提交申请
  94. * @return Response
  95. */
  96. public function batchApply() {
  97. $ids = $this->request["ids"];
  98. $ids = array_filter(explode(",", $ids));
  99. $allowanceType = $this->request["allowanceType"];
  100. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  101. if (!$batch) {
  102. return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
  103. }
  104. for ($i = 0; $i < count($ids); $i++) {
  105. queue("app\job\TalentAllowance", ["type" => 1, "method" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
  106. }
  107. return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
  108. }
  109. /**
  110. * 批量导入申请
  111. * @return Response
  112. */
  113. public function batchImportApply() {
  114. $maxFileSize = 10; //mb
  115. $tmp = $this->request->file("file");
  116. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  117. if (!$batch) {
  118. return \StrUtil::back(new Response(Response::ERROR, "当前并无有效的申报批次进行中"), "TalentAllowanceInfo.importCallBack");
  119. }
  120. if (!$tmp) {
  121. return \StrUtil::back(new Response(Response::ERROR, "没有上传批量申请文档"), "TalentAllowanceInfo.importCallBack");
  122. }
  123. if (!isExcelFile($tmp->getMime())) {
  124. return \StrUtil::back(new Response(Response::ERROR, "只能识别Excel文档"), "TalentAllowanceInfo.importCallBack");
  125. }
  126. if (round($tmp->getSize() / 1024 / 1024, 2) > $maxFileSize) {
  127. return \StrUtil::back(new Response(Response::ERROR, "文档大小不能超过10MB"), "TalentAllowanceInfo.importCallBack");
  128. }
  129. $filepath = $tmp->getPathname();
  130. try {
  131. $rows = getExcelDatas($filepath);
  132. } catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
  133. return \StrUtil::back(new Response(Response::ERROR, "文件识别错误!"), "TalentAllowanceInfo.importCallBack");
  134. }
  135. array_shift($rows); //去标题行
  136. //检查excel文件有没有问题
  137. $checkMonths = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
  138. $need_extra_project = getJsonConfig("../sys_config.json", "talent_allowance_need_extra_project");
  139. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ) {
  140. $titles = ["姓名", "身份证", "申请补贴类型", "个税缴纳月份", "工资发放月份", "考勤情况", "养老保险"];
  141. if ($need_extra_project[$this->user["uid"]]) {
  142. for ($i = 0; $i < count($need_extra_project[$this->user["uid"]]); $i++) {
  143. $titles[] = AllowanceProjectEnum::getProjectName($need_extra_project[$this->user["uid"]][$i]);
  144. }
  145. }
  146. } else {
  147. $titles = ["姓名", "身份证", "申请补贴类型", "个税缴纳月份", "工资发放月份", "考勤情况", "养老保险", "失业保险", "医疗保险"];
  148. }
  149. $allowanceTypes = ["工作津贴", "一次性交通补贴"];
  150. $idCards = [];
  151. foreach ($rows as $key => $row) {
  152. $no = $key + 2;
  153. $idCard = trim($row[1]);
  154. $allowanceType = trim($row[2]);
  155. if (!$idCard) {
  156. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证不能放空,请仔细检查内容完整后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  157. }
  158. if (in_array($idCard, $idCards)) {
  159. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行身份证存在重复,请请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  160. } else {
  161. $idCards[] = $idCard;
  162. }
  163. if (!in_array($allowanceType, $allowanceTypes)) {
  164. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行申请补贴类型错误,请仔细检查内容无误后再重新提交", $no)), "TalentAllowanceInfo.importCallBack");
  165. }
  166. if ($allowanceType == "工作津贴") {
  167. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($this->user["type"], $this->user["uid"]);
  168. for ($i = 3; $i < 9; $i++) {
  169. $project = 1;
  170. switch ($i) {
  171. case 3:
  172. $project = AllowanceProjectEnum::PROJECT_TAX;
  173. break;
  174. case 4:
  175. $project = AllowanceProjectEnum::PROJECT_WAGES;
  176. break;
  177. case 5:
  178. $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
  179. break;
  180. case 6:
  181. $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
  182. break;
  183. case 7:
  184. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ && $need_extra_project[$this->user["uid"]]) {
  185. $project = $need_extra_project[$this->user["uid"]][0];
  186. } else {
  187. $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
  188. }
  189. break;
  190. case 8:
  191. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ && $need_extra_project[$this->user["uid"]]) {
  192. $project = $need_extra_project[$this->user["uid"]][1];
  193. } else {
  194. $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
  195. }
  196. break;
  197. }
  198. if (!in_array($project, $projects))
  199. continue;
  200. $monthstr = str_replace([" ", ","], ",", trim($row[$i]));
  201. $months = array_filter(explode(",", $monthstr));
  202. if (!$months)
  203. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
  204. if (array_diff($months, $checkMonths))
  205. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[$i])), "TalentAllowanceInfo.importCallBack");
  206. }
  207. } else {
  208. $monthstr = str_replace([" ", ","], ",", trim($row[5]));
  209. $monthstr = str_replace(":", ":", $monthstr);
  210. $months = array_filter(explode(",", $monthstr));
  211. if (!$months)
  212. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s不能为空,请仔细检查内容完整后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
  213. foreach ($months as $m) {
  214. list($a, $b) = explode(":", $m);
  215. if (!in_array($a, $checkMonths) || !is_numeric($b) || $b > 31 || $b < 0)
  216. return \StrUtil::back(new Response(Response::ERROR, sprintf("第%d行%s错误,请查看模板文档对应列说明修改后再重新提交", $no, $titles[5])), "TalentAllowanceInfo.importCallBack");
  217. }
  218. }
  219. }
  220. for ($i = 0; $i < count($rows); $i++) {
  221. queue("app\job\TalentAllowance", ["type" => 1, "method" => 2, "data" => $rows[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => trim($rows[$i][2]) == "工作津贴" ? 1 : 2]);
  222. }
  223. return \StrUtil::back(new Response(Response::SUCCESS, count($rows) . "行数据已经成功添加到计划任务,请稍候查看申报列表进行确认"), "TalentAllowanceInfo.importCallBack");
  224. }
  225. private function save($talentAllowance, \think\Request $request) {
  226. $response = new \stdClass();
  227. $response->code = 500;
  228. $param = $request->param();
  229. if (!$param) {
  230. $response->msg = "请填写信息后在提交";
  231. return $response;
  232. }
  233. if (\StrUtil::isEmpOrNull($param["talentId"])) {
  234. $response->msg = "请选择申报对象";
  235. return $response;
  236. }
  237. if (!$param["id"]) {
  238. $where = [];
  239. $where[] = ["year", "like", substr($param["year"], 0, 4) . "%"];
  240. $where[] = ["idCard", "=", $param["idCard"]];
  241. $where[] = ["delete", "=", 0];
  242. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  243. $exists = TaModel::where($where)->find();
  244. if ($exists) {
  245. $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
  246. return $response;
  247. }
  248. $user = $this->user;
  249. $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
  250. if ($ti["talent_type"] == 1 && $ti["enterpriseType"] == CommonConst::ENTERPRISE_WJ && $param["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  251. $response->msg = "现有人才暂时不能申请一次性交通贴补";
  252. return $response;
  253. }
  254. $data = [
  255. "talentId" => $param["talentId"],
  256. "enterpriseId" => $ti["enterprise_id"],
  257. "enterpriseName" => $user["name"],
  258. "year" => $param["year"],
  259. "source" => $ti["source"],
  260. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  261. "talentType" => $ti["enterpriseTag"],
  262. "address" => $ti["street"],
  263. "name" => $ti["name"],
  264. "sex" => $ti["sex"],
  265. "cardType" => $ti["card_type"],
  266. "idCard" => $ti["card_number"],
  267. "firstInJJTime" => $ti["fst_work_time"],
  268. "entryTime" => $ti["cur_entry_time"],
  269. "post" => $ti["position"],
  270. "phone" => $ti["phone"],
  271. "talentArrange" => $ti["talent_arrange"],
  272. "identifyCondition" => $ti["talent_condition"],
  273. "identifyGetTime" => $ti["identifyGetTime"],
  274. "identifyOutTime" => $ti["identifyExpireTime"],
  275. "identifyConditionName" => $ti["identifyConditionName"],
  276. "identifyMonth" => $ti["identifyMonth"],
  277. "bank" => $ti["bank"],
  278. "bankNetwork" => $ti["bank_branch_name"],
  279. "bankAccount" => $ti["bank_account"],
  280. "bankNumber" => $ti["bank_number"],
  281. "checkState" => 1,
  282. "type" => $user["type"],
  283. "provinceCode" => $ti["province"],
  284. "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
  285. "cityCode" => $ti["city"],
  286. "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
  287. "countyCode" => $ti["county"],
  288. "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
  289. "isSupple" => 2,
  290. "createTime" => date("Y-m-d H:i:s"),
  291. "createUser" => $user["uid"],
  292. "id" => getStringId(),
  293. "wage" => $param["wage"],
  294. "allowanceType" => $param["allowanceType"],
  295. "postType" => $param["postType"] ?: 0,
  296. "institution" => $param["institution"] ?: 0
  297. ];
  298. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  299. $identifyYear = date("Y", strtotime($submitTime));
  300. $year = substr($param["year"], 0, 4);
  301. if ((($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  302. $response->msg = "该人员的人才认定时间晚于申报津补贴的年份,不符合申报条件";
  303. return $response;
  304. }
  305. /* * 1.获取上一年度的人才层次 */
  306. $arrangeList = $this->getLastYearTalentType($data, $ti);
  307. if (!$arrangeList) {
  308. if ($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) {
  309. $batchYear = substr($data["year"], 0, 4);
  310. $identifyYear = substr($data["identifyMonth"], 0, 4);
  311. if (!$batchYear || !$identifyYear || $identifyYear > $batchYear) {
  312. $response->msg = "上一年度暂无有效的人才层次";
  313. return $response;
  314. }
  315. } else {
  316. $response->msg = "上一年度暂无有效的人才层次";
  317. return $response;
  318. }
  319. }
  320. /* * 2.获取上一年度所在单位* */
  321. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  322. if (!$contractDetailList) {
  323. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  324. return $response;
  325. }
  326. TaModel::insert($data);
  327. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  328. /**
  329. * 4.添加津补贴核查项目
  330. */
  331. //核查项目详情表
  332. $this->createAllowanceProject($data, $contractDetailList);
  333. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  334. //添加日志
  335. TalentChecklog::create([
  336. 'id' => getStringId(),
  337. 'mainId' => $data['id'],
  338. 'type' => intval(ProjectState::JBT),
  339. 'typeFileId' => null,
  340. 'active' => 1,
  341. 'state' => 1,
  342. 'step' => 0,
  343. 'stateChange' => "保存未提交",
  344. 'description' => "添加津补贴申报",
  345. 'createTime' => date("Y-m-d H:i:s", time()),
  346. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  347. ]);
  348. $response->msg = "保存成功";
  349. $response->code = 200;
  350. $response->obj = $data;
  351. return $response;
  352. } else {
  353. TaModel::update($param);
  354. $response->msg = "修改成功";
  355. $response->code = 200;
  356. return $response;
  357. }
  358. }
  359. public function getInfoByIdAndYear($id, $year) {
  360. $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
  361. $data = [
  362. "talentId" => $id,
  363. "year" => $year,
  364. "idCard" => $ti["card_number"],
  365. "id" => getStringId(),
  366. "type" => $ti["enterpriseType"]
  367. ];
  368. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  369. $identifyYear = date("Y", strtotime($submitTime));
  370. $year = substr($year, 0, 4);
  371. if ((($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [CommonConst::ENTERPRISE_WJ, CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  372. return new Response(Response::ERROR, "该人员的人才认定时间晚于申报津补贴的年份,不符合申报条件");
  373. }
  374. /* * 1.获取上一年度的人才层次 */
  375. $arrangeList = $this->getLastYearTalentType($data, $ti);
  376. if (!$arrangeList) {
  377. if ($ti["enterpriseType"] == CommonConst::ENTERPRISE_JC) {
  378. $identifyYear = substr($ti["identifyMonth"], 0, 4);
  379. if (!$year || !$identifyYear || $identifyYear > $year) {
  380. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  381. }
  382. } else {
  383. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  384. }
  385. }
  386. /* * 2.获取上一年度所在单位* */
  387. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  388. if (!$contractDetailList) {
  389. return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
  390. }
  391. return new Response(Response::SUCCESS, "", $ti);
  392. }
  393. /**
  394. * 删除优秀人才津补贴
  395. */
  396. public function delete() {
  397. $id = $this->request["id"];
  398. $info = TalentAllowanceApi::getInfoById($id);
  399. if ($info["checkState"] != 1 && $info["checkState"] != -1) {
  400. return new Response(Response::ERROR, "删除失败!此数据已提交审核,无法删除!");
  401. }
  402. Db::startTrans();
  403. try {
  404. /* 硬删
  405. //删除核查项目表
  406. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  407. //删除合同情况表
  408. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  409. //删除人才层次变更表
  410. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  411. //删除日志
  412. $where[] = ["mainId", "=", $id];
  413. $where[] = ["type", "=", ProjectState::JBT];
  414. Db::table("new_talent_checklog")->where($where)->delete();
  415. //删除主表
  416. Db::table("un_talent_allowance_info")->delete($id);
  417. *
  418. */
  419. $data["id"] = $id;
  420. $data["delete"] = 1;
  421. $data["deleteUser"] = $this->user["uid"];
  422. $data["deleteTime"] = date("Y-m-d H:i:s");
  423. Db::table("un_talent_allowance_info")->update($data);
  424. Db::commit();
  425. return new Response(Response::SUCCESS, "删除成功");
  426. } catch (think\db\exception\DbException $e) {
  427. Db::rollback();
  428. return new Response(Response::ERROR, $e->getMessage());
  429. }
  430. }
  431. public function detail(\think\Request $request) {
  432. $param = $request->param();
  433. $id = $param["id"];
  434. $info = TalentAllowanceApi::getInfoById($id);
  435. $this->translateToChinese($info);
  436. if ($this->user["type"] == CommonConst::ENTERPRISE_GJ) {
  437. $need_choose_post_type = getJsonConfig("../sys_config.json", "talent_allowance_need_choose_post_type");
  438. $need_choose_institution = getJsonConfig("../sys_config.json", "talent_allowance_need_choose_institution");
  439. if ($need_choose_post_type[$this->user["uid"]]) {
  440. $postTypes = DictApi::findChildDictByCode("PostType");
  441. foreach ($postTypes as $key => $pt) {
  442. if (!in_array($pt["code"], $need_choose_post_type[$this->user["uid"]])) {
  443. unset($postTypes[$key]);
  444. }
  445. }
  446. }
  447. if (in_array($this->user["uid"], $need_choose_institution)) {
  448. $institutions = DictApi::findChildDictByCode("institution");
  449. }
  450. }
  451. return view("", ["row" => $info, "postTypes" => $postTypes, "institutions" => $institutions]);
  452. }
  453. private function translateToChinese(&$obj) {
  454. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  455. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  456. }
  457. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  458. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  459. }
  460. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  461. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  462. }
  463. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  464. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  465. }
  466. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  467. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  468. }
  469. }
  470. /* * 获取上一年度的人才层次变更信息 */
  471. private function getLastYearTalentType($info, $talentInfo) {
  472. $year = substr($info["year"], 0, 4);
  473. $arrangeList = [];
  474. /* * * 添加人才层次记录 */
  475. $oldStartTimeField = "oldIdentifyMonth";
  476. $newStartTimeField = "newIdentifyMonth";
  477. if ($info["type"] == CommonConst::ENTERPRISE_JC) {
  478. $oldStartTimeField = "oldIdentifyGetTime";
  479. $newStartTimeField = "newIdentifyGetTime";
  480. }
  481. if (in_array($info["type"], [CommonConst::ENTERPRISE_WJ]) && date("Y", strtotime($talentInfo["identifyMonth"])) == "2023") {
  482. $talentInfo["identifyMonth"] = "2022-12-01"; //让卫健包含2023全年
  483. }
  484. $specialPersonsBy2024 = \app\common\api\VerifyApi::getSpecialPersonsBy2024();
  485. if (in_array($talentInfo['card_number'],$specialPersonsBy2024)) {
  486. $talentInfo["identifyMonth"] = "2024-01-01"; //让卫健特殊人员包含2024全年
  487. }
  488. $where = [];
  489. $where[] = ["idCard", "=", $info["idCard"]];
  490. $where[] = ["checkState", "=", MainState::PASS];
  491. $where[] = ["isPublic", "=", 6];
  492. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  493. $where[] = ["createTime", ">=", "2022-10-01 00:00:00"];
  494. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  495. $typeList[] = [
  496. "oldTalentArrange" => $talentInfo["talent_arrange"],
  497. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  498. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  499. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  500. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  501. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  502. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  503. "newIdentifyMonth" => $year . "-12-31",
  504. "newIdentifyGetTime" => $year . "-12-31"
  505. ];
  506. if (in_array($info["idCard"], \app\common\api\VerifyApi::getTwiceIdentifyPersons())) {
  507. $whr = [];
  508. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  509. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  510. $whr[] = ["e.type", "=", $this->user["type"]];
  511. $whr[] = ["ti.id", "<>", $talentInfo["id"]];
  512. $whr[] = ["card_number", "=", $info["idCard"]];
  513. $otherChangeList = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.*,e.`type` as eType")->order("identifyMonth desc")->where($whr)->select()->toArray();
  514. foreach ($otherChangeList as $k => $oc) {
  515. if ($k == 0) {
  516. $newIdentifyMonth = $talentInfo["identifyMonth"];
  517. $newIdentifyGetTime = $talentInfo["identifyGetTime"];
  518. } else {
  519. $newIdentifyMonth = $oc[$k - 1]["identifyMonth"];
  520. $newIdentifyGetTime = $oc[$k - 1]["identifyGetTime"];
  521. }
  522. $typeList[] = [
  523. "oldTalentArrange" => $oc["talent_arrange"],
  524. "oldIdentifyCondition" => $oc["talent_condition"],
  525. "oldIdentifyGetTime" => $oc["identifyGetTime"],
  526. "oldIdentifyOutTime" => $oc["identifyExpireTime"],
  527. "oldIdentifyMonth" => $oc["identifyMonth"],
  528. "oldCertificateStartTime" => $oc["certificateGetTime"],
  529. "oldCertificateOutTime" => $oc["certificateExpireTime"],
  530. "newIdentifyMonth" => $newIdentifyMonth,
  531. "newIdentifyGetTime" => $newIdentifyGetTime
  532. ];
  533. }
  534. }
  535. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  536. /* * 获取上一年度有效的人才层次 */
  537. usort($typeList, function ($a, $b) {
  538. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  539. });
  540. $commonMonth = [];
  541. foreach ($typeList as $talentTypeChange) {
  542. $startTime = $talentTypeChange[$oldStartTimeField];
  543. $endTime = $talentTypeChange[$newStartTimeField];
  544. if (in_array($info["type"], [CommonConst::ENTERPRISE_GJ])) {
  545. $monthList = \DateUtil::getMonthBetweenDatesNotEnd($startTime, $endTime);
  546. if ($endTime == $year . "-12-31") {
  547. $monthList[] = $year . "-12";
  548. }
  549. } else {
  550. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  551. }
  552. if ($monthList) {
  553. $monthList = array_intersect($monthList, $totalMonth);
  554. }
  555. if ($monthList) {
  556. $months = implode(",", $monthList);
  557. $monthList = array_filter($monthList, function ($value) use ($commonMonth) {
  558. return !in_array($value, $commonMonth);
  559. });
  560. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  561. if (count($monthList) > 0) {
  562. $arrange = [
  563. "id" => getStringId(),
  564. "mainId" => $info["id"],
  565. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  566. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  567. "startTime" => $startTime,
  568. "endTime" => $endTime,
  569. "prepareMonths" => null,
  570. "description" => "申报年度有效月份:" . $months,
  571. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  572. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  573. ];
  574. $sb = '';
  575. foreach ($monthList as $month) {
  576. $sb .= substr($month, 5, 2) . ",";
  577. }
  578. $arrange["prepareMonths"] = rtrim($sb, ",");
  579. $arrangeList[] = $arrange;
  580. }
  581. }
  582. }
  583. return $arrangeList;
  584. }
  585. /**
  586. * @param
  587. * @returns void
  588. * @author Liu
  589. * @date 2020/4/26
  590. * @description 获取上一年度所在单位
  591. * */
  592. private function getConcatList($talentInfo, $info, $year) {
  593. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  594. /** 添加申报人才上一年度工作单位记录 */
  595. $where = [];
  596. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  597. $where[] = ["checkState", "=", 3];
  598. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  599. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  600. if ($talentInfo["active"] == 1) {
  601. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  602. $starttime = $labor_contract_rangetime[0];
  603. $endtime = $labor_contract_rangetime[1];
  604. $quitList[] = [
  605. "enterpriseId" => $talentInfo["enterprise_id"],
  606. "enterpriseName" => $talentInfo["enterpriseName"],
  607. "talentType" => $talentInfo["enterpriseTag"],
  608. "identifyGetTime" => $talentInfo["identifyGetTime"],
  609. "starttime" => $starttime,
  610. "endtime" => $endtime,
  611. "entryTime" => $talentInfo["cur_entry_time"],
  612. "quitTime" => null,
  613. "post" => $talentInfo["position"]
  614. ];
  615. }
  616. $list = [];
  617. foreach ($quitList as $quit) {
  618. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  619. $monthList = array_intersect($monthList, $totalMonth);
  620. if ($monthList) {
  621. $sb = '';
  622. foreach ($monthList as $month) {
  623. $sb .= substr($month, 5, 2) . ",";
  624. }
  625. $list[] = [
  626. "id" => getStringId(),
  627. "mainId" => $info["id"],
  628. "enterpriseId" => $quit["enterpriseId"],
  629. "talentType" => $quit["talentType"],
  630. "startTime" => $quit["starttime"],
  631. "endTime" => $quit["endtime"],
  632. "entryTime" => $quit["entryTime"],
  633. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  634. "letterTime" => $quit["letterTime"],
  635. "gygb" => $quit["gygb"],
  636. "identifyGetTime" => $quit["identifyGetTime"],
  637. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  638. "post" => $quit["post"],
  639. "months" => rtrim($sb, ",")
  640. ];
  641. }
  642. }
  643. return $list;
  644. }
  645. private function createAllowanceProject($info, $contractList) {
  646. $count = 0;
  647. foreach ($contractList as $detail) {
  648. $count++;
  649. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"], $info["enterpriseId"]);
  650. $list = [];
  651. foreach ($projects as $project) {
  652. $months = "";
  653. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  654. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  655. $list[] = [
  656. "mainId" => $info["id"],
  657. "baseId" => $detail["id"],
  658. "enterpriseId" => $detail["enterpriseId"],
  659. "project" => $project,
  660. "months" => $months,
  661. "isLock" => 1,
  662. "createTime" => date("Y-m-d H:i:s")
  663. ];
  664. }
  665. \app\common\model\TalentAllowanceProject::insertAll($list);
  666. }
  667. }
  668. /**
  669. * 查询工作单位
  670. */
  671. public function findAllowanceContractDetail() {
  672. $mainId = $this->request["mainId"];
  673. $offset = $this->request["offset"] ?: 0;
  674. $limit = $this->request["limit"] ?: 1000;
  675. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  676. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  677. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  678. foreach ($list as &$row) {
  679. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  680. }unset($row);
  681. return json(["rows" => $list, "total" => $count]);
  682. }
  683. /**
  684. * 查询核查项目情况
  685. */
  686. public function findAllowanceProject() {
  687. $mainId = $this->request["mainId"];
  688. $baseId = $this->request["baseId"];
  689. $offset = $this->request["offset"] ?: 0;
  690. $limit = $this->request["limit"] ?: 1000;
  691. $where = [];
  692. $where[] = ["mainId", "=", $mainId];
  693. $where[] = ["baseId", "=", $baseId];
  694. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  695. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  696. $info = TalentAllowanceApi::getInfoById($mainId);
  697. foreach ($list as &$project) {
  698. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  699. if ($info["checkState"] == 1) {
  700. $project["isEdit"] = in_array($project["project"], [
  701. //AllowanceProjectEnum::PROJECT_CONTRACT,
  702. AllowanceProjectEnum::PROJECT_TAX,
  703. AllowanceProjectEnum::PROJECT_WAGES,
  704. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  705. AllowanceProjectEnum::PROJECT_SB_PENSION,
  706. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  707. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  708. AllowanceProjectEnum::PROJECT_TEACHING,
  709. AllowanceProjectEnum::PROJECT_LESSON,
  710. AllowanceProjectEnum::PROJECT_TRAINING_PROGRAM,
  711. //AllowanceProjectEnum::PROJECT_WORKDAY
  712. ]) ? 1 : 2;
  713. } else if ($info["checkState"] == 10 || $info["checkState"] == 8) {
  714. $projects = explode(",", $info["projects"]);
  715. if (in_array($project["id"], $projects)) {
  716. $project["isEdit"] = 1;
  717. } else {
  718. $project["isEdit"] = 2;
  719. }
  720. } else {
  721. $project["isEdit"] = 2;
  722. }
  723. }unset($project);
  724. return json(["rows" => $list, "total" => $count]);
  725. }
  726. /**
  727. * 查询人才层次变更记录
  728. */
  729. public function findAllowanceArrange() {
  730. $mainId = $this->request["mainId"];
  731. $offset = $this->request["offset"] ?: 0;
  732. $limit = $this->request["limit"] ?: 1000;
  733. $where = [];
  734. $where[] = ["mainId", "=", $mainId];
  735. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  736. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  737. foreach ($list as &$arrange) {
  738. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  739. $arrange["identifyConditionText"] = $condition["name"];
  740. $arrange["talentArrangeName"] = CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  741. }unset($arrange);
  742. return json(["rows" => $list, "total" => $count]);
  743. }
  744. /**
  745. * 修改合同起止时间
  746. */
  747. public function editContract() {
  748. $response = new \stdClass();
  749. $response->code = 500;
  750. $param = $this->request->param();
  751. if (!$param["id"]) {
  752. $response->msg = "系统错误,请联系管理员";
  753. return $response;
  754. }
  755. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  756. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  757. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  758. $response->msg = "请选择合同起始时间";
  759. return $response;
  760. }
  761. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  762. $response->msg = "请选择合同截止时间";
  763. return $response;
  764. }
  765. \app\common\model\TalentAllowancecontractDetail::update($param);
  766. //添加日志
  767. TalentChecklog::create([
  768. 'id' => getStringId(),
  769. 'mainId' => $info['id'],
  770. 'type' => intval(ProjectState::JBT),
  771. 'typeFileId' => $param["id"],
  772. 'active' => 1,
  773. 'state' => null,
  774. 'step' => 0,
  775. 'stateChange' => null,
  776. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  777. 'createTime' => date("Y-m-d H:i:s", time()),
  778. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  779. ]);
  780. $response->msg = "修改成功";
  781. $response->code = 200;
  782. return $response;
  783. }
  784. /**
  785. * 修改项目
  786. */
  787. public function editProject() {
  788. $response = new \stdClass();
  789. $response->code = 500;
  790. $param = $this->request->param();
  791. if (!$param["id"]) {
  792. $response->msg = "系统错误,请联系管理员";
  793. return $response;
  794. }
  795. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  796. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  797. \app\common\model\TalentAllowanceProject::update($param);
  798. //添加日志
  799. TalentChecklog::create([
  800. 'id' => getStringId(),
  801. 'mainId' => $info['id'],
  802. 'type' => intval(ProjectState::JBT),
  803. 'typeFileId' => $param["id"],
  804. 'active' => 1,
  805. 'state' => null,
  806. 'step' => 0,
  807. 'stateChange' => null,
  808. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  809. 'createTime' => date("Y-m-d H:i:s", time()),
  810. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  811. ]);
  812. $response->msg = "修改成功";
  813. $response->code = 200;
  814. return $response;
  815. }
  816. /**
  817. * 判断是否可以修改
  818. */
  819. public function validateIsEdit() {
  820. $id = $this->request["id"];
  821. $type = $this->request["type"];
  822. $info = null;
  823. if ($type == 1) { //编辑合同
  824. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  825. } else if ($type == 2) { //编辑项目
  826. $detail = \app\common\model\TalentAllowanceProject::find($id);
  827. }
  828. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  829. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  830. if ($info["checkState"] == -1) {
  831. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  832. } else if ($info["checkState"] == 30) {
  833. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  834. } else {
  835. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  836. }
  837. }
  838. return new Response(Response::SUCCESS, "");
  839. }
  840. /**
  841. * 提交审核
  842. */
  843. public function submitToCheck() {
  844. $data = $this->request->param();
  845. $response = new \stdClass();
  846. $response->code = 500;
  847. if (!$data || !$data["id"]) {
  848. $response->msg = "提交审核失败,请先填写基础信息";
  849. return $response;
  850. }
  851. $old = TalentAllowanceApi::getInfoById($data["id"]);
  852. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  853. if ($batch["code"] != 200) {
  854. $response->msg = $batch["msg"];
  855. return $response;
  856. }
  857. if ($old["checkState"] != 1 && $old["checkState"] != 10 && $old["checkState"] != 8) {
  858. $response->msg = "不能重复提交审核";
  859. return $response;
  860. }
  861. if (!$old["allowanceType"]) {
  862. $response->msg = "没有明确津贴类型";
  863. return $response;
  864. }
  865. //因为工作津贴和交通补贴两者的考勤分别记录的是月份和天数,如果没有手动修改值会导致数据不对口,如修改类型却未修改考勤记录,则手动改为空。
  866. $where = [];
  867. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_ATTENDANCE];
  868. $where[] = ["mainId", "=", $data["id"]];
  869. $attendanceList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  870. if ($old["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  871. //因为天数保存格式为 月份=天数 如 01=31,02=20,03=15,月份保存格式为01,02,03,所以可以从有没有=号判断是否有进行考勤的修改保存操作
  872. foreach ($attendanceList as $a) {
  873. //$a["months"]有值但是没有包含=号则一般可认为是类型修改为交通补贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  874. if ($a["months"] && strpos($a["months"], "=") === false) {
  875. $_updProject["id"] = $a["id"];
  876. $_updProject["months"] = "";
  877. \app\common\model\TalentAllowanceProject::update($_updProject);
  878. }
  879. }
  880. } else {
  881. foreach ($attendanceList as $a) {
  882. //$a["months"]有值但是包含了=号则一般可认为是类型修改为工作津贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  883. if ($a["months"] && strpos($a["months"], "=") !== false) {
  884. $_updProject["id"] = $a["id"];
  885. $_updProject["months"] = "";
  886. \app\common\model\TalentAllowanceProject::update($_updProject);
  887. }
  888. }
  889. }
  890. $where = [];
  891. $where[] = ["type", "=", $old["type"]];
  892. $where[] = ["project", "=", ProjectState::JBT];
  893. $where[] = ["isConditionFile", "=", $old["allowanceType"]];
  894. $where[] = ["active", "=", 1];
  895. $where[] = ["delete", "=", 0];
  896. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  897. $where = [];
  898. $where[] = ["enterpriseId", "=", $old["enterpriseId"]];
  899. $where[] = ["batch", "=", $old["year"]];
  900. $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();
  901. $relationIds = [];
  902. foreach ($commonFiles as $key => $row) {
  903. $_relationIds = array_filter(explode(",", $row["relationIds"]));
  904. $relationIds = array_merge($relationIds, $_relationIds);
  905. }
  906. foreach ($filetypes as $key => $filetype) {
  907. if (in_array($filetype["id"], $relationIds)) {
  908. $filetypes[$key]["must"] = 2;
  909. }
  910. }
  911. $sb = [];
  912. $sb[] = "以下为必传附件:";
  913. foreach ($filetypes as $filetype) {
  914. if ($filetype["must"] == 1) {
  915. $where = [];
  916. $where[] = ["mainId", "=", $data["id"]];
  917. $where[] = ["typeId", "=", $filetype["id"]];
  918. $count = Db::table("new_talent_file")->where($where)->count();
  919. if ($count == 0) {
  920. $sb[] = $filetype["name"] . ";";
  921. }
  922. }
  923. }
  924. if (count($sb) > 1 && $old["postType"] != 8) {
  925. $response->msg = implode("<br>", $sb);
  926. return $response;
  927. }
  928. /**
  929. * 初步判断合同是否满两年
  930. */
  931. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  932. foreach ($detailList as $detail) {
  933. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  934. $response->msg = "合同起止时间不能为空";
  935. return $response;
  936. }
  937. }
  938. foreach ($detailList as $detail) {
  939. $contractEndTime = strtotime($detail["endTime"]);
  940. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  941. $where = [];
  942. $where[] = ["mainId", "=", $data["id"]];
  943. $where[] = ["baseId", "=", $detail["id"]];
  944. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  945. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  946. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  947. }
  948. $data["checkMsg"] = "";
  949. $data["checkState"] = AllowanceStateEnum::NEED_CHECK;
  950. $afterState = 7; //待初审
  951. /* $ep = \app\common\api\EnterpriseApi::getOne($this->user["uid"]);
  952. if ($ep->isGeneral == 2 && \app\common\api\Nhc::hasGeneralHospital($ep->medicalCommunityId)) {
  953. $data["checkState"] = AllowanceStateEnum::NEED_GENERAL_CHECK; //分院并且有总院
  954. $afterState = 3; //待审核
  955. } */
  956. $data["files"] = "";
  957. $data["projects"] = "";
  958. $data["concats"] = "";
  959. $data["fields"] = "";
  960. $data["toDep"] = "";
  961. $data["process"] = null;
  962. if (!$old["firstSubmitTime"]) {
  963. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  964. }
  965. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  966. TaModel::update($data);
  967. //添加日志
  968. TalentChecklog::create([
  969. 'id' => getStringId(),
  970. 'mainId' => $data['id'],
  971. 'type' => intval(ProjectState::JBT),
  972. 'typeFileId' => null,
  973. 'active' => 1,
  974. 'state' => 1,
  975. 'step' => 0,
  976. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc($afterState)),
  977. 'description' => "确认提交审核",
  978. 'createTime' => date("Y-m-d H:i:s", time()),
  979. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  980. ]);
  981. $response->msg = "提交审核成功";
  982. $response->code = 200;
  983. $response->obj = 5;
  984. return $response;
  985. }
  986. public function updateSuppleState() {
  987. $id = $this->request["id"];
  988. $response = new \stdClass();
  989. $response->code = 500;
  990. if (\StrUtil::isEmpOrNull($id)) {
  991. $response->msg = "系统错误,请联系管理员";
  992. return $response;
  993. }
  994. $data["id"] = $id;
  995. $data["isSupple"] = 1;
  996. TaModel::update($data);
  997. $response->msg = "状态更新成功";
  998. $response->code = 200;
  999. return $response;
  1000. }
  1001. public function uploadCommonFile() {
  1002. $batchId = $this->request["batch"];
  1003. if (!$batchId) {
  1004. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  1005. }
  1006. $batchInfo = BatchApi::getOne($batchId);
  1007. if (!$batchInfo) {
  1008. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  1009. }
  1010. if (!$this->request->file()) {
  1011. return json(new Response(Response::ERROR, "没有上传任何材料"));
  1012. }
  1013. $file = $this->request->file("file");
  1014. $upload = new UploadApi();
  1015. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  1016. if ($result->code != 200) {
  1017. return json(new Response(Response::ERROR, $result->msg));
  1018. }
  1019. $data["id"] = getStringId();
  1020. $data["enterpriseId"] = $this->user["uid"];
  1021. $data["batchId"] = $batchId;
  1022. $data["batch"] = $batchInfo["batch"];
  1023. $data["url"] = $result->filepath;
  1024. $data["originalName"] = $file->getOriginalName();
  1025. $data["createTime"] = date("Y-m-d H:i:s");
  1026. $data["createUser"] = $this->user["uid"];
  1027. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  1028. return json(new Response(Response::SUCCESS, "上传成功"));
  1029. }
  1030. public function listCommonFile() {
  1031. $param = $this->request->param();
  1032. $batchId = $param["batch"];
  1033. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  1034. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  1035. $whr[] = ["type", "=", $this->user["type"]];
  1036. $whr[] = ["project", "=", ProjectState::JBT];
  1037. $whr[] = ["isConditionFile", "=", 0];
  1038. $whr[] = ["delete", "=", 0];
  1039. if ($this->user["type"] == CommonConst::ENTERPRISE_JC) {
  1040. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->whereRaw("find_in_set(:enterpriseId,enterpriseIds)", ["enterpriseId" => $this->user["uid"]])->select()->toArray();
  1041. } else {
  1042. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->select()->toArray();
  1043. }
  1044. foreach ($list as $key => $item) {
  1045. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  1046. $list[$key]["url"] = getStoragePath($item["url"]);
  1047. $list[$key]["fileTypes"] = $commonFileTypes;
  1048. }
  1049. return json(["rows" => $list]);
  1050. }
  1051. public function bindCommonFileWithFileType() {
  1052. $params = $this->request->param();
  1053. $fileId = $params["fileId"];
  1054. $fileTypeId = $params["fileTypeId"];
  1055. $upd["id"] = $fileId;
  1056. $upd["fileTypeId"] = $fileTypeId ?: 0;
  1057. $upd["updateTime"] = date("Y-m-d H:i:s");
  1058. $upd["updateUser"] = $this->user["uid"];
  1059. try {
  1060. Db::table("un_talent_allowance_common_file")->update($upd);
  1061. if ($fileTypeId > 0) {
  1062. $msg = "关联成功";
  1063. } else {
  1064. $msg = "取消关联成功";
  1065. }
  1066. return json(new Response(Response::SUCCESS, $msg));
  1067. } catch (\think\db\exception\DbException $e) {
  1068. return json(new Response(Response::ERROR, $e->getMessage()));
  1069. }
  1070. }
  1071. public function deleteCommonFile() {
  1072. $id = $this->request["id"];
  1073. $where = [];
  1074. $where[] = ["id", "=", $id];
  1075. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1076. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  1077. if (!$file) {
  1078. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  1079. }
  1080. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  1081. if (!empty($file["url"])) {
  1082. $filepath = "storage/" . $file["url"];
  1083. if (file_exists($filepath)) {
  1084. //unlink($filepath);
  1085. }
  1086. }
  1087. return json(new Response(Response::SUCCESS, "删除成功"));
  1088. }
  1089. }
  1090. public function findTalentAllowance() {
  1091. $res = [];
  1092. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  1093. $year = $batch["batch"];
  1094. if ($year) {
  1095. $year = substr($year, 0, 4);
  1096. $ids = null;
  1097. //根据申报年度查询当前企业已申报的人才
  1098. $where = [];
  1099. $where[] = ["year", "like", $year . "%"];
  1100. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1101. $talentAllowances = TaModel::where($where)->select()->toArray();
  1102. $ids = array_unique(array_column($talentAllowances, "talentId"));
  1103. $whr = [];
  1104. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  1105. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  1106. $whr[] = ["e.type", "=", $this->user["type"]];
  1107. $whr[] = ["ti.id", "not in", $ids];
  1108. $twiceIdentifyPersons = \app\common\api\VerifyApi::getTwiceIdentifyPersons();
  1109. if ($twiceIdentifyPersons) {
  1110. $_whr = $whr;
  1111. $whr[] = ["card_number", "not in", $twiceIdentifyPersons];
  1112. $_whr[] = ["card_number", "in", $twiceIdentifyPersons];
  1113. $tmpList = \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();
  1114. $twiceIdentifyPersonList = [];
  1115. $otherTypeChangeList = [];
  1116. foreach ($tmpList as $person) {
  1117. if (!$twiceIdentifyPersonList[$person["idCard"]]) {
  1118. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1119. } else {
  1120. if ($person["talent_arrange"] < $twiceIdentifyPersonList[$person["idCard"]]["talent_arrange"]) {
  1121. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $twiceIdentifyPersonList[$person["idCard"]]["identifyMonth"], "oldIdentifyGetTime" => $twiceIdentifyPersonList[$person["idCard"]]["identifyGetTime"]];
  1122. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1123. } else {
  1124. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $person["identifyMonth"], "oldIdentifyGetTime" => $person["identifyGetTime"]];
  1125. }
  1126. }
  1127. }
  1128. sort($twiceIdentifyPersonList);
  1129. }
  1130. $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();
  1131. if ($twiceIdentifyPersonList) {
  1132. $list = array_merge((array) $list, $twiceIdentifyPersonList);
  1133. }
  1134. foreach ($list as $info) {
  1135. $identifyTime = $info["identifyMonth"];
  1136. if ($info["eType"] == CommonConst::ENTERPRISE_JC) {
  1137. $identifyTime = $info["identifyGetTime"] ?: $info["identifyMonth"];
  1138. }
  1139. if (strtotime($year . "-12-31") >= strtotime($identifyTime)) {
  1140. $res[] = $info;
  1141. } else {
  1142. $whereTypeChange = [];
  1143. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  1144. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  1145. $whereTypeChange[] = ["isPublic", "=", 6];
  1146. $whereTypeChange[] = ["createTime", ">=", "2022-10-01 00:00:00"];
  1147. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  1148. if ($otherTypeChangeList[$info["idCard"]]) {
  1149. $typeChanges = array_merge($otherTypeChangeList[$info["idCard"]], (array) $typeChanges);
  1150. }
  1151. foreach ($typeChanges as $typeChange) {
  1152. $oldIdentifyTime = $typeChange["oldIdentifyMonth"];
  1153. if ($typeChange["type"] == CommonConst::ENTERPRISE_JC) {
  1154. $oldIdentifyTime = $typeChange["oldIdentifyGetTime"] ?: $typeChange["oldIdentifyMonth"];
  1155. }
  1156. if (strtotime($year . "-12-31") >= strtotime($oldIdentifyTime)) {
  1157. $res[] = $info;
  1158. break;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }
  1164. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  1165. }
  1166. public function export() {
  1167. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  1168. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  1169. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  1170. $obj["allowanceType"] = \StrUtil::getRequestDecodeParam($this->request, "allowanceType");
  1171. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  1172. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  1173. $where = [];
  1174. $where[] = ["ta.delete", "=", 0];
  1175. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  1176. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  1177. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  1178. }
  1179. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  1180. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  1181. }
  1182. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  1183. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  1184. }
  1185. if (\StrUtil::isNotEmpAndNull($obj["allowanceType"])) {
  1186. $where[] = ["ta.allowanceType", "=", $obj["allowanceType"]];
  1187. }
  1188. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  1189. $where[] = ["ta.address", "=", $obj["address"]];
  1190. }
  1191. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  1192. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  1193. }
  1194. $projects = [
  1195. AllowanceProjectEnum::PROJECT_TAX,
  1196. AllowanceProjectEnum::PROJECT_WAGES,
  1197. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  1198. AllowanceProjectEnum::PROJECT_SB_PENSION,
  1199. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  1200. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  1201. ];
  1202. $months = [];
  1203. for ($m = 1; $m <= 12; $m++) {
  1204. $months[] = $m . "月";
  1205. }
  1206. $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]]];
  1207. $infoCols = count($columns);
  1208. for ($i = 0; $i < count($projects); $i++) {
  1209. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  1210. }
  1211. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  1212. ->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")
  1213. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  1214. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  1215. ->where($where)
  1216. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  1217. ->select()->toArray();
  1218. $tmpList = [];
  1219. $levelMap = DictApi::selectByParentCode("talent_arrange");
  1220. $streetMap = DictApi::selectByParentCode("street");
  1221. $where = [];
  1222. $where[] = ["id", "in", array_column($list, "identifyCondition")];
  1223. $icmap = \app\common\model\TalentCondition::where($where)->column("name", "id");
  1224. $where = [];
  1225. $where[] = ["id", "in", array_column($list, "enterpriseId")];
  1226. $enterpriseMap = \app\common\model\Enterprise::where($where)->column("name", "id");
  1227. foreach ($list as $item) {
  1228. //组装数据
  1229. if (!$tmpList[$item["id"]]) {
  1230. $tmpList[$item["id"]]["curEnterpriseId"] = $item["curEnterpriseId"];
  1231. $tmpList[$item["id"]]["info"] = [$item["year"], $streetMap[$item["address"]], $item["name"], $item["sex"] == 1 ? "男" : "女", $item["idCard"], $levelMap[$item["talentArrange"]],
  1232. $icmap[$item["identifyCondition"]], $item["identifyGetTime"], $item["identifyConditionName"], $item["identifyMonth"], AllowanceTypeEnum::getTypeName($item["allowanceType"]), $item["virtualAmount"], $item["months"], $item["money"],
  1233. $item["moneyDesc"], $this->getCheckStateName($item["checkState"], $item["publicState"], $item["allowanceType"])];
  1234. }
  1235. if (!$tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]) {
  1236. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]] = [
  1237. "startTime" => $item["startTime"],
  1238. "endTime" => $item["endTime"],
  1239. "entryTime" => $item["entryTime"],
  1240. "isQuit" => $item["isQuit"]
  1241. ];
  1242. }
  1243. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]["projects"][$item["project"]] = $item["pre_months"];
  1244. }
  1245. $rows = [];
  1246. $colorset = [];
  1247. foreach ($tmpList as $id => $item) {
  1248. foreach ($item["enterprise"] as $enterpriseId => $enterprise) {
  1249. $row = $item["info"];
  1250. $row[] = $this->user["uid"] == $enterpriseId ? "本单位" : $enterpriseMap[$enterpriseId];
  1251. for ($i = 0; $i < count($projects); $i++) {
  1252. if (strpos($enterprise["projects"][$projects[$i]], "=") === false) {
  1253. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1254. for ($m = 1; $m <= 12; $m++) {
  1255. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1256. if (in_array($_month, $months)) {
  1257. $row[] = "✔";
  1258. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1259. } else {
  1260. $row[] = "";
  1261. }
  1262. }
  1263. } else {
  1264. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1265. $_months = [];
  1266. foreach ($months as $month) {
  1267. $kv = explode("=", $month);
  1268. $_months[$kv[0]] = $kv[1];
  1269. }
  1270. for ($m = 1; $m <= 12; $m++) {
  1271. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1272. $days = $_months[$_month];
  1273. if ($days && $days > 0) {
  1274. $row[] = $days . "天";
  1275. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1276. } else {
  1277. $row[] = "";
  1278. }
  1279. }
  1280. }
  1281. }
  1282. $rows[] = $row;
  1283. }
  1284. }
  1285. $cols = $infoCols + count($projects) * 12 - 1;
  1286. $settings = [
  1287. "width" => [["A", 8], ["C", 12], ["D", 6], ["E", 20], ["F", 12], ["G", 70], ["H", 12], ["I", 15], ["J", 12], ["K", 12], ["P", 30]],
  1288. "height" => [18],
  1289. "freeze" => "D3",
  1290. "color" => $colorset
  1291. ];
  1292. for ($i = 0; $i < count($projects) * 12; $i++) {
  1293. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  1294. }
  1295. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  1296. export($columns, $rows, "津补贴申报名单", $settings);
  1297. }
  1298. /**
  1299. * 审核列表页
  1300. */
  1301. public function examineCenter() {
  1302. $tpl = "";
  1303. switch ($this->user["type"]) {
  1304. case CommonConst::ENTERPRISE_WJ:
  1305. $tpl = "/talent_allowance/examine_center"; //卫健医院
  1306. break;
  1307. }
  1308. return view($tpl);
  1309. }
  1310. /**
  1311. * 审核列表页
  1312. */
  1313. public function examineList() {
  1314. $res = TalentAllowanceApi::getHospitalExamineList($this->request);
  1315. return json($res);
  1316. }
  1317. /**
  1318. * 审核页面
  1319. * @return type
  1320. */
  1321. public function toCheckPage() {
  1322. $id = $this->request["id"];
  1323. $process = $this->request["process"];
  1324. $obj = TalentAllowanceApi::getInfoById($id);
  1325. $this->translateToChinese($obj);
  1326. return view("check", ["row" => $obj, "process" => $process]);
  1327. }
  1328. /**
  1329. * 查看详情
  1330. * @return type
  1331. */
  1332. public function toSelectPage() {
  1333. $id = $this->request["id"];
  1334. $process = $this->request["process"];
  1335. $obj = TalentAllowanceApi::getInfoById($id);
  1336. $this->translateToChinese($obj);
  1337. return view("check", ["row" => $obj, "process" => $process]);
  1338. }
  1339. /**
  1340. * 审核保存
  1341. */
  1342. public function check() {
  1343. $obj = $this->request->param();
  1344. if (!$obj["checkState"]) {
  1345. return new Response(Response::ERROR, "请选择审核状态");
  1346. }
  1347. $oldObj = TalentAllowanceApi::getInfoById($obj["id"]);
  1348. if (!$oldObj) {
  1349. return new Response(Response::ERROR, "审核对象不存在");
  1350. }
  1351. $ep = \app\common\api\EnterpriseApi::getOne($oldObj["enterpriseId"]);
  1352. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1353. return new Response(Response::ERROR, "不在审核范围内");
  1354. }
  1355. if ($oldObj["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $oldObj["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1356. return new Response(Response::ERROR, "不在审核范围内");
  1357. }
  1358. $newObj = [];
  1359. $newObj["id"] = $obj["id"];
  1360. $projectList = [];
  1361. $fileList = [];
  1362. if (\StrUtil::isNotEmpAndNull($obj["projects"])) {
  1363. $projectList = array_filter(explode(",", $obj["projects"]));
  1364. $newObj["projects"] = implode(",", $projectList);
  1365. }
  1366. if (\StrUtil::isNotEmpAndNull($obj["files"])) {
  1367. $fileList = array_filter(explode(",", $obj["files"]));
  1368. $newObj["files"] = implode(",", $fileList);
  1369. }
  1370. $newObj["concats"] = $obj["concats"];
  1371. $newObj["fields"] = $obj["fields"];
  1372. //}
  1373. TaModel::update($newObj);
  1374. //添加日志
  1375. TalentChecklog::create([
  1376. 'id' => getStringId(),
  1377. 'mainId' => $obj['id'],
  1378. 'type' => intval(ProjectState::JBT),
  1379. 'typeFileId' => null,
  1380. 'active' => 2,
  1381. 'state' => $obj["checkState"],
  1382. 'step' => -2,
  1383. 'stateChange' => null,
  1384. 'description' => $obj["checkMsg"],
  1385. 'createTime' => date("Y-m-d H:i:s", time()),
  1386. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1387. ]);
  1388. return new Response(Response::SUCCESS, "审核成功");
  1389. }
  1390. /**
  1391. * 提交审核
  1392. * @return Response
  1393. */
  1394. public function submitCheck() {
  1395. $id = $this->request["id"];
  1396. $process = -2;
  1397. $old = TalentAllowanceApi::getInfoById($id);
  1398. if (!$old) {
  1399. return new Response(Response::ERROR, "审核对象不存在");
  1400. }
  1401. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1402. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1403. return new Response(Response::ERROR, "不在审核范围内");
  1404. }
  1405. if ($old["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $old["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1406. return new Response(Response::ERROR, "不在审核范围内");
  1407. }
  1408. $updCheck = [];
  1409. $updCheck["id"] = $id;
  1410. $updCheck["type"] = $old["type"];
  1411. /* * 查询审核日志 */
  1412. $log = \app\common\api\TalentLogApi::getLastLogByStep($id, ProjectState::JBT, $process);
  1413. if (!$log) {
  1414. return new Response(Response::ERROR, "请先审核后再提交");
  1415. }
  1416. $updCheck["checkMsg"] = $log["description"];
  1417. /* * 判断到达的最高流程 */
  1418. $updCheck["highProcess"] = !$old["highProcess"] || $old["highProcess"] < $process ? $process : $old["highProcess"];
  1419. switch ($log["state"]) {
  1420. case 3:
  1421. $updCheck["precheckPassTime"] = $old["precheckPassTime"];
  1422. if (!$old["precheckPassTime"]) {
  1423. $updCheck["precheckPassTime"] = date("Y-m-d H:i:s");
  1424. }
  1425. $updCheck["submitTime"] = date("Y-m-d H:i:s");
  1426. $updCheck["checkState"] = AllowanceStateEnum::NEED_CHECK;
  1427. break;
  1428. case 2:
  1429. $updCheck["checkState"] = AllowanceStateEnum::GENERAL_REJECT;
  1430. break;
  1431. case -1:
  1432. $updCheck["checkState"] = AllowanceStateEnum::NOTPASS;
  1433. $updCheck["recommendAllowanceType"] = 3;
  1434. $updCheck["recommendMoney"] = 0;
  1435. $updCheck["recommendAllowanceMsg"] = "审核不通过,不予兑现";
  1436. break;
  1437. default:
  1438. return new Response(Response::ERROR, "未知的审核状态");
  1439. }
  1440. //添加日志
  1441. TalentChecklog::create([
  1442. 'id' => getStringId(),
  1443. 'mainId' => $id,
  1444. 'type' => intval(ProjectState::JBT),
  1445. 'typeFileId' => null,
  1446. 'active' => 1,
  1447. 'state' => $log["state"],
  1448. 'step' => $process,
  1449. 'stateChange' => AllowanceStateEnum::getStateName($old["checkState"]) . "->" . AllowanceStateEnum::getStateName($updCheck["checkState"]),
  1450. 'description' => $log["description"],
  1451. 'createTime' => date("Y-m-d H:i:s", time()),
  1452. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1453. ]);
  1454. TalentChecklog::where("id", $log["id"])->delete();
  1455. TaModel::update($updCheck);
  1456. return new Response(Response::SUCCESS, "提交审核成功");
  1457. }
  1458. /**
  1459. * 校验是否在审核范围内
  1460. */
  1461. public function validateIsCheck() {
  1462. $id = $this->request["id"];
  1463. $type = $this->request["type"];
  1464. $info = null;
  1465. switch ($type) {
  1466. case 1: //编辑合同
  1467. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  1468. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  1469. break;
  1470. case 2: //编辑项目
  1471. $project = \app\common\model\TalentAllowanceProject::find($id);
  1472. $info = TalentAllowanceApi::getInfoById($project["mainId"]);
  1473. break;
  1474. case 3:
  1475. $info = TalentAllowanceApi::getInfoById($id);
  1476. break;
  1477. }
  1478. if (!$info) {
  1479. return new Response(Response::ERROR, "校验不通过,无法操作");
  1480. }
  1481. $ep = \app\common\api\EnterpriseApi::getOne($info["enterpriseId"]);
  1482. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1483. return new Response(Response::ERROR, "不在审核范围内");
  1484. }
  1485. $where = [];
  1486. $where[] = ["mainId", "=", $info["id"]];
  1487. $where[] = ["step", "=", -2];
  1488. $where[] = ["active", "=", 2];
  1489. $log = null;
  1490. if ($info["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $info["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1491. return new Response(Response::ERROR, "不在审核范围内");
  1492. }
  1493. $log = TalentChecklog::where($where)->order("createTime desc")->find();
  1494. if ($log != null) {
  1495. $info["checkState"] = $log["state"];
  1496. $info["checkMsg"] = $log["description"];
  1497. } else {
  1498. $info["checkState"] = null;
  1499. $info["checkMsg"] = "";
  1500. }
  1501. $res = [];
  1502. $res["info"] = $info;
  1503. if ($type == 3) {
  1504. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1505. $where = [];
  1506. $where[] = ["mainId", "=", $id];
  1507. $where[] = ["isLock", "=", 1];
  1508. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1509. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1510. $detailMap = array_reduce($detailList, function ($result, $item) {
  1511. $key = $item["id"];
  1512. $result[$key] = $item;
  1513. return $result;
  1514. }, []);
  1515. foreach ($detailList as &$detail) {
  1516. $detail["enterpriseName"] = sprintf("%s(%s至%s)", $enterpriseMap[$detail["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1517. }unset($detail);
  1518. foreach ($projectList as &$project) {
  1519. $detail = $detailMap[$project["baseId"]];
  1520. $project["projectName"] = sprintf("%s(%s(%s至%s))", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1521. }
  1522. $where = [];
  1523. $where[] = ["type", "=", $info["type"]];
  1524. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1525. $where[] = ["active", "=", 1];
  1526. $where[] = ["delete", "=", 0];
  1527. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1528. $res["files"] = $filetypes;
  1529. $res["projects"] = $projectList;
  1530. $res["concats"] = $detailList;
  1531. }
  1532. return new Response(Response::SUCCESS, "不在审核范围内", $res);
  1533. }
  1534. /**
  1535. * 初始化可修改的项目/附件/合同
  1536. * */
  1537. public function findFieldsAndFiles() {
  1538. $id = $this->request["id"];
  1539. if (\StrUtil::isEmpOrNull($id)) {
  1540. return new Response(Response::ERROR, "请选择需要修改的对象");
  1541. }
  1542. $info = TalentAllowanceApi::getInfoById($id);
  1543. if (!$info) {
  1544. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1545. }
  1546. if ($info["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1547. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1548. }
  1549. $res = [];
  1550. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1551. $where = [];
  1552. $where[] = ["mainId", "=", $id];
  1553. $where[] = ["isLock", "=", 1];
  1554. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1555. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1556. foreach ($detailList as &$detail) {
  1557. $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
  1558. }unset($detail);
  1559. foreach ($projectList as &$project) {
  1560. $detail = $detailMap[$project["baseId"]];
  1561. $project["projectName"] = sprintf("%s(%s)", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]]);
  1562. }unset($project);
  1563. $where = [];
  1564. $where[] = ["type", "=", $info["type"]];
  1565. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1566. $where[] = ["active", "=", 1];
  1567. $where[] = ["delete", "=", 0];
  1568. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1569. $res["files"] = $filetypes;
  1570. $res["projects"] = $projectList;
  1571. $res["concats"] = $detailList;
  1572. $res["info"] = $info;
  1573. return new Response(Response::SUCCESS, "", $res);
  1574. }
  1575. /**
  1576. * 修改驳回项目/附件/合同
  1577. * */
  1578. public function updateFieldsAndFiles() {
  1579. $data = $this->request->param();
  1580. if (!$data["id"]) {
  1581. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1582. }
  1583. $old = TalentAllowanceApi::getInfoById($data["id"]);
  1584. if (!$old) {
  1585. return new Response(Response::ERROR, "审核对象不存在");
  1586. }
  1587. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1588. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1589. return new Response(Response::ERROR, "不在审核范围内");
  1590. }
  1591. if ($old["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1592. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1593. }
  1594. TaModel::update($data);
  1595. return new Response(Response::SUCCESS, "修改成功");
  1596. }
  1597. private function checkExaminePriv($isGeneral, $medicalCommunityId) {
  1598. if ($this->user["medicalCommunityId"] == $medicalCommunityId && $this->user["isGeneral"] == 1 && $isGeneral == 2) {
  1599. return true;
  1600. }
  1601. return false;
  1602. }
  1603. private function getCheckStateName($checkState, $publicState, $allowanceType) {
  1604. switch ($checkState) {
  1605. case 1:
  1606. return "待提交";
  1607. case 3:
  1608. case 5:
  1609. case 13:
  1610. case 15:
  1611. case 20:
  1612. case 25:
  1613. case 35:
  1614. return "审核中";
  1615. case 8:
  1616. return "总院驳回";
  1617. case 9:
  1618. case 10:
  1619. return "已驳回";
  1620. case - 1:
  1621. if ($publicState >= 3) {
  1622. return "审核不通过";
  1623. } else {
  1624. return "审核中";
  1625. }
  1626. break;
  1627. case 30:
  1628. if ($publicState == 1) {
  1629. return "待核查征信";
  1630. } else if ($publicState == 2) {
  1631. return "待公示";
  1632. } else if ($publicState == 3) {
  1633. return "公示中";
  1634. } else if ($publicState == 4) {
  1635. return $allowanceType != 3 ? "待兑现" : "不予兑现";
  1636. } else if ($publicState == 5) {
  1637. return "已兑现";
  1638. }
  1639. default:
  1640. return "未知状态";
  1641. }
  1642. }
  1643. }