TalentAllowance.php 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713
  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, "已经成功添加到计划任务,请稍候查看申报列表进行确认"), "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) {
  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. $where = [];
  485. $where[] = ["idCard", "=", $info["idCard"]];
  486. $where[] = ["checkState", "=", MainState::PASS];
  487. $where[] = ["isPublic", "=", 6];
  488. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  489. $where[] = ["createTime", ">=", "2022-10-01 00:00:00"];
  490. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  491. $typeList[] = [
  492. "oldTalentArrange" => $talentInfo["talent_arrange"],
  493. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  494. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  495. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  496. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  497. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  498. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  499. "newIdentifyMonth" => $year . "-12-31",
  500. "newIdentifyGetTime" => $year . "-12-31"
  501. ];
  502. if (in_array($info["idCard"], \app\common\api\VerifyApi::getTwiceIdentifyPersons())) {
  503. $whr = [];
  504. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  505. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  506. $whr[] = ["e.type", "=", $this->user["type"]];
  507. $whr[] = ["ti.id", "<>", $talentInfo["id"]];
  508. $whr[] = ["card_number", "=", $info["idCard"]];
  509. $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();
  510. foreach ($otherChangeList as $k => $oc) {
  511. if ($k == 0) {
  512. $newIdentifyMonth = $talentInfo["identifyMonth"];
  513. $newIdentifyGetTime = $talentInfo["identifyGetTime"];
  514. } else {
  515. $newIdentifyMonth = $oc[$k - 1]["identifyMonth"];
  516. $newIdentifyGetTime = $oc[$k - 1]["identifyGetTime"];
  517. }
  518. $typeList[] = [
  519. "oldTalentArrange" => $oc["talent_arrange"],
  520. "oldIdentifyCondition" => $oc["talent_condition"],
  521. "oldIdentifyGetTime" => $oc["identifyGetTime"],
  522. "oldIdentifyOutTime" => $oc["identifyExpireTime"],
  523. "oldIdentifyMonth" => $oc["identifyMonth"],
  524. "oldCertificateStartTime" => $oc["certificateGetTime"],
  525. "oldCertificateOutTime" => $oc["certificateExpireTime"],
  526. "newIdentifyMonth" => $newIdentifyMonth,
  527. "newIdentifyGetTime" => $newIdentifyGetTime
  528. ];
  529. }
  530. }
  531. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  532. /* * 获取上一年度有效的人才层次 */
  533. usort($typeList, function($a, $b) {
  534. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  535. });
  536. $commonMonth = [];
  537. foreach ($typeList as $talentTypeChange) {
  538. $startTime = $talentTypeChange[$oldStartTimeField];
  539. $endTime = $talentTypeChange[$newStartTimeField];
  540. if (in_array($info["type"], [CommonConst::ENTERPRISE_GJ])) {
  541. $monthList = \DateUtil::getMonthBetweenDatesNotEnd($startTime, $endTime);
  542. if ($endTime == $year . "-12-31") {
  543. $monthList[] = $year . "-12";
  544. }
  545. } else {
  546. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  547. }
  548. if ($monthList) {
  549. $monthList = array_intersect($monthList, $totalMonth);
  550. }
  551. if ($monthList) {
  552. $months = implode(",", $monthList);
  553. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  554. return !in_array($value, $commonMonth);
  555. });
  556. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  557. if (count($monthList) > 0) {
  558. $arrange = [
  559. "id" => getStringId(),
  560. "mainId" => $info["id"],
  561. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  562. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  563. "startTime" => $startTime,
  564. "endTime" => $endTime,
  565. "prepareMonths" => null,
  566. "description" => "申报年度有效月份:" . $months,
  567. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  568. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  569. ];
  570. $sb = '';
  571. foreach ($monthList as $month) {
  572. $sb .= substr($month, 5, 2) . ",";
  573. }
  574. $arrange["prepareMonths"] = rtrim($sb, ",");
  575. $arrangeList[] = $arrange;
  576. }
  577. }
  578. }
  579. return $arrangeList;
  580. }
  581. /**
  582. * @param
  583. * @returns void
  584. * @author Liu
  585. * @date 2020/4/26
  586. * @description 获取上一年度所在单位
  587. * */
  588. private function getConcatList($talentInfo, $info, $year) {
  589. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  590. /** 添加申报人才上一年度工作单位记录 */
  591. $where = [];
  592. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  593. $where[] = ["checkState", "=", 3];
  594. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  595. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  596. if ($talentInfo["active"] == 1) {
  597. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  598. $starttime = $labor_contract_rangetime[0];
  599. $endtime = $labor_contract_rangetime[1];
  600. $quitList[] = [
  601. "enterpriseId" => $talentInfo["enterprise_id"],
  602. "enterpriseName" => $talentInfo["enterpriseName"],
  603. "talentType" => $talentInfo["enterpriseTag"],
  604. "identifyGetTime" => $talentInfo["identifyGetTime"],
  605. "starttime" => $starttime,
  606. "endtime" => $endtime,
  607. "entryTime" => $talentInfo["cur_entry_time"],
  608. "quitTime" => null,
  609. "post" => $talentInfo["position"]
  610. ];
  611. }
  612. $list = [];
  613. foreach ($quitList as $quit) {
  614. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  615. $monthList = array_intersect($monthList, $totalMonth);
  616. if ($monthList) {
  617. $sb = '';
  618. foreach ($monthList as $month) {
  619. $sb .= substr($month, 5, 2) . ",";
  620. }
  621. $list[] = [
  622. "id" => getStringId(),
  623. "mainId" => $info["id"],
  624. "enterpriseId" => $quit["enterpriseId"],
  625. "talentType" => $quit["talentType"],
  626. "startTime" => $quit["starttime"],
  627. "endTime" => $quit["endtime"],
  628. "entryTime" => $quit["entryTime"],
  629. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  630. "letterTime" => $quit["letterTime"],
  631. "gygb" => $quit["gygb"],
  632. "identifyGetTime" => $quit["identifyGetTime"],
  633. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  634. "post" => $quit["post"],
  635. "months" => rtrim($sb, ",")
  636. ];
  637. }
  638. }
  639. return $list;
  640. }
  641. private function createAllowanceProject($info, $contractList) {
  642. $count = 0;
  643. foreach ($contractList as $detail) {
  644. $count++;
  645. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"], $info["enterpriseId"]);
  646. $list = [];
  647. foreach ($projects as $project) {
  648. $months = "";
  649. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  650. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  651. $list[] = [
  652. "mainId" => $info["id"],
  653. "baseId" => $detail["id"],
  654. "enterpriseId" => $detail["enterpriseId"],
  655. "project" => $project,
  656. "months" => $months,
  657. "isLock" => 1,
  658. "createTime" => date("Y-m-d H:i:s")
  659. ];
  660. }
  661. \app\common\model\TalentAllowanceProject::insertAll($list);
  662. }
  663. }
  664. /**
  665. * 查询工作单位
  666. */
  667. public function findAllowanceContractDetail() {
  668. $mainId = $this->request["mainId"];
  669. $offset = $this->request["offset"] ?: 0;
  670. $limit = $this->request["limit"] ?: 1000;
  671. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  672. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  673. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  674. foreach ($list as &$row) {
  675. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  676. }unset($row);
  677. return json(["rows" => $list, "total" => $count]);
  678. }
  679. /**
  680. * 查询核查项目情况
  681. */
  682. public function findAllowanceProject() {
  683. $mainId = $this->request["mainId"];
  684. $baseId = $this->request["baseId"];
  685. $offset = $this->request["offset"] ?: 0;
  686. $limit = $this->request["limit"] ?: 1000;
  687. $where = [];
  688. $where[] = ["mainId", "=", $mainId];
  689. $where[] = ["baseId", "=", $baseId];
  690. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  691. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  692. $info = TalentAllowanceApi::getInfoById($mainId);
  693. foreach ($list as &$project) {
  694. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  695. if ($info["checkState"] == 1) {
  696. $project["isEdit"] = in_array($project["project"], [
  697. //AllowanceProjectEnum::PROJECT_CONTRACT,
  698. AllowanceProjectEnum::PROJECT_TAX,
  699. AllowanceProjectEnum::PROJECT_WAGES,
  700. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  701. AllowanceProjectEnum::PROJECT_SB_PENSION,
  702. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  703. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  704. AllowanceProjectEnum::PROJECT_TEACHING,
  705. AllowanceProjectEnum::PROJECT_LESSON,
  706. AllowanceProjectEnum::PROJECT_TRAINING_PROGRAM,
  707. //AllowanceProjectEnum::PROJECT_WORKDAY
  708. ]) ? 1 : 2;
  709. } else if ($info["checkState"] == 10 || $info["checkState"] == 8) {
  710. $projects = explode(",", $info["projects"]);
  711. if (in_array($project["id"], $projects)) {
  712. $project["isEdit"] = 1;
  713. } else {
  714. $project["isEdit"] = 2;
  715. }
  716. } else {
  717. $project["isEdit"] = 2;
  718. }
  719. }unset($project);
  720. return json(["rows" => $list, "total" => $count]);
  721. }
  722. /**
  723. * 查询人才层次变更记录
  724. */
  725. public function findAllowanceArrange() {
  726. $mainId = $this->request["mainId"];
  727. $offset = $this->request["offset"] ?: 0;
  728. $limit = $this->request["limit"] ?: 1000;
  729. $where = [];
  730. $where[] = ["mainId", "=", $mainId];
  731. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  732. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  733. foreach ($list as &$arrange) {
  734. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  735. $arrange["identifyConditionText"] = $condition["name"];
  736. $arrange["talentArrangeName"] = CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  737. }unset($arrange);
  738. return json(["rows" => $list, "total" => $count]);
  739. }
  740. /**
  741. * 修改合同起止时间
  742. */
  743. public function editContract() {
  744. $response = new \stdClass();
  745. $response->code = 500;
  746. $param = $this->request->param();
  747. if (!$param["id"]) {
  748. $response->msg = "系统错误,请联系管理员";
  749. return $response;
  750. }
  751. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  752. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  753. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  754. $response->msg = "请选择合同起始时间";
  755. return $response;
  756. }
  757. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  758. $response->msg = "请选择合同截止时间";
  759. return $response;
  760. }
  761. \app\common\model\TalentAllowancecontractDetail::update($param);
  762. //添加日志
  763. TalentChecklog::create([
  764. 'id' => getStringId(),
  765. 'mainId' => $info['id'],
  766. 'type' => intval(ProjectState::JBT),
  767. 'typeFileId' => $param["id"],
  768. 'active' => 1,
  769. 'state' => null,
  770. 'step' => 0,
  771. 'stateChange' => null,
  772. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  773. 'createTime' => date("Y-m-d H:i:s", time()),
  774. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  775. ]);
  776. $response->msg = "修改成功";
  777. $response->code = 200;
  778. return $response;
  779. }
  780. /**
  781. * 修改项目
  782. */
  783. public function editProject() {
  784. $response = new \stdClass();
  785. $response->code = 500;
  786. $param = $this->request->param();
  787. if (!$param["id"]) {
  788. $response->msg = "系统错误,请联系管理员";
  789. return $response;
  790. }
  791. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  792. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  793. \app\common\model\TalentAllowanceProject::update($param);
  794. //添加日志
  795. TalentChecklog::create([
  796. 'id' => getStringId(),
  797. 'mainId' => $info['id'],
  798. 'type' => intval(ProjectState::JBT),
  799. 'typeFileId' => $param["id"],
  800. 'active' => 1,
  801. 'state' => null,
  802. 'step' => 0,
  803. 'stateChange' => null,
  804. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  805. 'createTime' => date("Y-m-d H:i:s", time()),
  806. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  807. ]);
  808. $response->msg = "修改成功";
  809. $response->code = 200;
  810. return $response;
  811. }
  812. /**
  813. * 判断是否可以修改
  814. */
  815. public function validateIsEdit() {
  816. $id = $this->request["id"];
  817. $type = $this->request["type"];
  818. $info = null;
  819. if ($type == 1) { //编辑合同
  820. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  821. } else if ($type == 2) { //编辑项目
  822. $detail = \app\common\model\TalentAllowanceProject::find($id);
  823. }
  824. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  825. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  826. if ($info["checkState"] == -1) {
  827. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  828. } else if ($info["checkState"] == 30) {
  829. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  830. } else {
  831. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  832. }
  833. }
  834. return new Response(Response::SUCCESS, "");
  835. }
  836. /**
  837. * 提交审核
  838. */
  839. public function submitToCheck() {
  840. $data = $this->request->param();
  841. $response = new \stdClass();
  842. $response->code = 500;
  843. if (!$data || !$data["id"]) {
  844. $response->msg = "提交审核失败,请先填写基础信息";
  845. return $response;
  846. }
  847. $old = TalentAllowanceApi::getInfoById($data["id"]);
  848. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  849. if ($batch["code"] != 200) {
  850. $response->msg = $batch["msg"];
  851. return $response;
  852. }
  853. if ($old["checkState"] != 1 && $old["checkState"] != 10 && $old["checkState"] != 8) {
  854. $response->msg = "不能重复提交审核";
  855. return $response;
  856. }
  857. if (!$old["allowanceType"]) {
  858. $response->msg = "没有明确津贴类型";
  859. return $response;
  860. }
  861. //因为工作津贴和交通补贴两者的考勤分别记录的是月份和天数,如果没有手动修改值会导致数据不对口,如修改类型却未修改考勤记录,则手动改为空。
  862. $where = [];
  863. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_ATTENDANCE];
  864. $where[] = ["mainId", "=", $data["id"]];
  865. $attendanceList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  866. if ($old["allowanceType"] == AllowanceTypeEnum::JBT_JT) {
  867. //因为天数保存格式为 月份=天数 如 01=31,02=20,03=15,月份保存格式为01,02,03,所以可以从有没有=号判断是否有进行考勤的修改保存操作
  868. foreach ($attendanceList as $a) {
  869. //$a["months"]有值但是没有包含=号则一般可认为是类型修改为交通补贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  870. if ($a["months"] && strpos($a["months"], "=") === false) {
  871. $_updProject["id"] = $a["id"];
  872. $_updProject["months"] = "";
  873. \app\common\model\TalentAllowanceProject::update($_updProject);
  874. }
  875. }
  876. } else {
  877. foreach ($attendanceList as $a) {
  878. //$a["months"]有值但是包含了=号则一般可认为是类型修改为工作津贴而未修改考勤,此时的months字段数据是错误的,修改为空。
  879. if ($a["months"] && strpos($a["months"], "=") !== false) {
  880. $_updProject["id"] = $a["id"];
  881. $_updProject["months"] = "";
  882. \app\common\model\TalentAllowanceProject::update($_updProject);
  883. }
  884. }
  885. }
  886. $where = [];
  887. $where[] = ["type", "=", $old["type"]];
  888. $where[] = ["project", "=", ProjectState::JBT];
  889. $where[] = ["isConditionFile", "=", $old["allowanceType"]];
  890. $where[] = ["active", "=", 1];
  891. $where[] = ["delete", "=", 0];
  892. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  893. $where = [];
  894. $where[] = ["enterpriseId", "=", $old["enterpriseId"]];
  895. $where[] = ["batch", "=", $old["year"]];
  896. $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();
  897. $relationIds = [];
  898. foreach ($commonFiles as $key => $row) {
  899. $_relationIds = array_filter(explode(",", $row["relationIds"]));
  900. $relationIds = array_merge($relationIds, $_relationIds);
  901. }
  902. foreach ($filetypes as $key => $filetype) {
  903. if (in_array($filetype["id"], $relationIds)) {
  904. $filetypes[$key]["must"] = 2;
  905. }
  906. }
  907. $sb = [];
  908. $sb[] = "以下为必传附件:";
  909. foreach ($filetypes as $filetype) {
  910. if ($filetype["must"] == 1) {
  911. $where = [];
  912. $where[] = ["mainId", "=", $data["id"]];
  913. $where[] = ["typeId", "=", $filetype["id"]];
  914. $count = Db::table("new_talent_file")->where($where)->count();
  915. if ($count == 0) {
  916. $sb[] = $filetype["name"] . ";";
  917. }
  918. }
  919. }
  920. if (count($sb) > 1) {
  921. $response->msg = implode("<br>", $sb);
  922. return $response;
  923. }
  924. /**
  925. * 初步判断合同是否满两年
  926. */
  927. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  928. foreach ($detailList as $detail) {
  929. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  930. $response->msg = "合同起止时间不能为空";
  931. return $response;
  932. }
  933. }
  934. foreach ($detailList as $detail) {
  935. $contractEndTime = strtotime($detail["endTime"]);
  936. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  937. $where = [];
  938. $where[] = ["mainId", "=", $data["id"]];
  939. $where[] = ["baseId", "=", $detail["id"]];
  940. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  941. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  942. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  943. }
  944. $data["checkMsg"] = "";
  945. $data["checkState"] = AllowanceStateEnum::NEED_CHECK;
  946. $afterState = 7; //待初审
  947. /* $ep = \app\common\api\EnterpriseApi::getOne($this->user["uid"]);
  948. if ($ep->isGeneral == 2 && \app\common\api\Nhc::hasGeneralHospital($ep->medicalCommunityId)) {
  949. $data["checkState"] = AllowanceStateEnum::NEED_GENERAL_CHECK; //分院并且有总院
  950. $afterState = 3; //待审核
  951. } */
  952. $data["files"] = "";
  953. $data["projects"] = "";
  954. $data["concats"] = "";
  955. $data["fields"] = "";
  956. $data["toDep"] = "";
  957. $data["process"] = null;
  958. if (!$old["firstSubmitTime"]) {
  959. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  960. }
  961. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  962. TaModel::update($data);
  963. //添加日志
  964. TalentChecklog::create([
  965. 'id' => getStringId(),
  966. 'mainId' => $data['id'],
  967. 'type' => intval(ProjectState::JBT),
  968. 'typeFileId' => null,
  969. 'active' => 1,
  970. 'state' => 1,
  971. 'step' => 0,
  972. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc($afterState)),
  973. 'description' => "确认提交审核",
  974. 'createTime' => date("Y-m-d H:i:s", time()),
  975. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  976. ]);
  977. $response->msg = "提交审核成功";
  978. $response->code = 200;
  979. $response->obj = 5;
  980. return $response;
  981. }
  982. public function updateSuppleState() {
  983. $id = $this->request["id"];
  984. $response = new \stdClass();
  985. $response->code = 500;
  986. if (\StrUtil::isEmpOrNull($id)) {
  987. $response->msg = "系统错误,请联系管理员";
  988. return $response;
  989. }
  990. $data["id"] = $id;
  991. $data["isSupple"] = 1;
  992. TaModel::update($data);
  993. $response->msg = "状态更新成功";
  994. $response->code = 200;
  995. return $response;
  996. }
  997. public function uploadCommonFile() {
  998. $batchId = $this->request["batch"];
  999. if (!$batchId) {
  1000. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  1001. }
  1002. $batchInfo = BatchApi::getOne($batchId);
  1003. if (!$batchInfo) {
  1004. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  1005. }
  1006. if (!$this->request->file()) {
  1007. return json(new Response(Response::ERROR, "没有上传任何材料"));
  1008. }
  1009. $file = $this->request->file("file");
  1010. $upload = new UploadApi();
  1011. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  1012. if ($result->code != 200) {
  1013. return json(new Response(Response::ERROR, $result->msg));
  1014. }
  1015. $data["id"] = getStringId();
  1016. $data["enterpriseId"] = $this->user["uid"];
  1017. $data["batchId"] = $batchId;
  1018. $data["batch"] = $batchInfo["batch"];
  1019. $data["url"] = $result->filepath;
  1020. $data["originalName"] = $file->getOriginalName();
  1021. $data["createTime"] = date("Y-m-d H:i:s");
  1022. $data["createUser"] = $this->user["uid"];
  1023. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  1024. return json(new Response(Response::SUCCESS, "上传成功"));
  1025. }
  1026. public function listCommonFile() {
  1027. $param = $this->request->param();
  1028. $batchId = $param["batch"];
  1029. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  1030. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  1031. $whr[] = ["type", "=", $this->user["type"]];
  1032. $whr[] = ["project", "=", ProjectState::JBT];
  1033. $whr[] = ["isConditionFile", "=", 0];
  1034. $whr[] = ["delete", "=", 0];
  1035. if ($this->user["type"] == CommonConst::ENTERPRISE_JC) {
  1036. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->whereRaw("find_in_set(:enterpriseId,enterpriseIds)", ["enterpriseId" => $this->user["uid"]])->select()->toArray();
  1037. } else {
  1038. $commonFileTypes = Db::table("new_common_filetype")->where($whr)->select()->toArray();
  1039. }
  1040. foreach ($list as $key => $item) {
  1041. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  1042. $list[$key]["url"] = getStoragePath($item["url"]);
  1043. $list[$key]["fileTypes"] = $commonFileTypes;
  1044. }
  1045. return json(["rows" => $list]);
  1046. }
  1047. public function bindCommonFileWithFileType() {
  1048. $params = $this->request->param();
  1049. $fileId = $params["fileId"];
  1050. $fileTypeId = $params["fileTypeId"];
  1051. $upd["id"] = $fileId;
  1052. $upd["fileTypeId"] = $fileTypeId ?: 0;
  1053. $upd["updateTime"] = date("Y-m-d H:i:s");
  1054. $upd["updateUser"] = $this->user["uid"];
  1055. try {
  1056. Db::table("un_talent_allowance_common_file")->update($upd);
  1057. if ($fileTypeId > 0) {
  1058. $msg = "关联成功";
  1059. } else {
  1060. $msg = "取消关联成功";
  1061. }
  1062. return json(new Response(Response::SUCCESS, $msg));
  1063. } catch (\think\db\exception\DbException $e) {
  1064. return json(new Response(Response::ERROR, $e->getMessage()));
  1065. }
  1066. }
  1067. public function deleteCommonFile() {
  1068. $id = $this->request["id"];
  1069. $where = [];
  1070. $where[] = ["id", "=", $id];
  1071. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1072. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  1073. if (!$file) {
  1074. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  1075. }
  1076. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  1077. if (!empty($file["url"])) {
  1078. $filepath = "storage/" . $file["url"];
  1079. if (file_exists($filepath)) {
  1080. unlink($filepath);
  1081. }
  1082. }
  1083. return json(new Response(Response::SUCCESS, "删除成功"));
  1084. }
  1085. }
  1086. public function findTalentAllowance() {
  1087. $res = [];
  1088. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  1089. $year = $batch["batch"];
  1090. if ($year) {
  1091. $year = substr($year, 0, 4);
  1092. $ids = null;
  1093. //根据申报年度查询当前企业已申报的人才
  1094. $where = [];
  1095. $where[] = ["year", "like", $year . "%"];
  1096. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  1097. $talentAllowances = TaModel::where($where)->select()->toArray();
  1098. $ids = array_unique(array_column($talentAllowances, "talentId"));
  1099. $whr = [];
  1100. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  1101. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  1102. $whr[] = ["e.type", "=", $this->user["type"]];
  1103. $whr[] = ["ti.id", "not in", $ids];
  1104. $twiceIdentifyPersons = \app\common\api\VerifyApi::getTwiceIdentifyPersons();
  1105. if ($twiceIdentifyPersons) {
  1106. $_whr = $whr;
  1107. $whr[] = ["card_number", "not in", $twiceIdentifyPersons];
  1108. $_whr[] = ["card_number", "in", $twiceIdentifyPersons];
  1109. $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();
  1110. $twiceIdentifyPersonList = [];
  1111. $otherTypeChangeList = [];
  1112. foreach ($tmpList as $person) {
  1113. if (!$twiceIdentifyPersonList[$person["idCard"]]) {
  1114. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1115. } else {
  1116. if ($person["talent_arrange"] < $twiceIdentifyPersonList[$person["idCard"]]["talent_arrange"]) {
  1117. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $twiceIdentifyPersonList[$person["idCard"]]["identifyMonth"], "oldIdentifyGetTime" => $twiceIdentifyPersonList[$person["idCard"]]["identifyGetTime"]];
  1118. $twiceIdentifyPersonList[$person["idCard"]] = $person;
  1119. } else {
  1120. $otherTypeChangeList[$person["idCard"]][] = ["oldIdentifyMonth" => $person["identifyMonth"], "oldIdentifyGetTime" => $person["identifyGetTime"]];
  1121. }
  1122. }
  1123. }
  1124. sort($twiceIdentifyPersonList);
  1125. }
  1126. $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();
  1127. if ($twiceIdentifyPersonList) {
  1128. $list = array_merge((array) $list, $twiceIdentifyPersonList);
  1129. }
  1130. foreach ($list as $info) {
  1131. $identifyTime = $info["identifyMonth"];
  1132. if ($info["eType"] == CommonConst::ENTERPRISE_JC) {
  1133. $identifyTime = $info["identifyGetTime"] ?: $info["identifyMonth"];
  1134. }
  1135. if (strtotime($year . "-12-31") >= strtotime($identifyTime)) {
  1136. $res[] = $info;
  1137. } else {
  1138. $whereTypeChange = [];
  1139. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  1140. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  1141. $whereTypeChange[] = ["isPublic", "=", 6];
  1142. $whereTypeChange[] = ["createTime", ">=", "2022-10-01 00:00:00"];
  1143. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  1144. if ($otherTypeChangeList[$info["idCard"]]) {
  1145. $typeChanges = array_merge($otherTypeChangeList[$info["idCard"]], (array) $typeChanges);
  1146. }
  1147. foreach ($typeChanges as $typeChange) {
  1148. $oldIdentifyTime = $typeChange["oldIdentifyMonth"];
  1149. if ($typeChange["type"] == CommonConst::ENTERPRISE_JC) {
  1150. $oldIdentifyTime = $typeChange["oldIdentifyGetTime"] ?: $typeChange["oldIdentifyMonth"];
  1151. }
  1152. if (strtotime($year . "-12-31") >= strtotime($oldIdentifyTime)) {
  1153. $res[] = $info;
  1154. break;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  1161. }
  1162. public function export() {
  1163. $obj["year"] = \StrUtil::getRequestDecodeParam($this->request, "year");
  1164. $obj["name"] = \StrUtil::getRequestDecodeParam($this->request, "name");
  1165. $obj["talentArrange"] = \StrUtil::getRequestDecodeParam($this->request, "talentArrange");
  1166. $obj["allowanceType"] = \StrUtil::getRequestDecodeParam($this->request, "allowanceType");
  1167. $obj["address"] = \StrUtil::getRequestDecodeParam($this->request, "address");
  1168. $obj["identifyCondition"] = \StrUtil::getRequestDecodeParam($this->request, "identifyCondition");
  1169. $where = [];
  1170. $where[] = ["ta.delete", "=", 0];
  1171. $where[] = ["ta.enterpriseId", "=", $this->user["uid"]];
  1172. if (\StrUtil::isNotEmpAndNull($obj["year"])) {
  1173. $where[] = ["ta.year", "like", "%" . $obj["year"] . "%"];
  1174. }
  1175. if (\StrUtil::isNotEmpAndNull($obj["name"])) {
  1176. $where[] = ["ta.name", "like", "%" . $obj["name"] . "%"];
  1177. }
  1178. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  1179. $where[] = ["ta.talentArrange", "=", $obj["talentArrange"]];
  1180. }
  1181. if (\StrUtil::isNotEmpAndNull($obj["allowanceType"])) {
  1182. $where[] = ["ta.allowanceType", "=", $obj["allowanceType"]];
  1183. }
  1184. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  1185. $where[] = ["ta.address", "=", $obj["address"]];
  1186. }
  1187. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  1188. $where[] = ["ta.identifyCondition", "=", $obj["identifyCondition"]];
  1189. }
  1190. $projects = [
  1191. AllowanceProjectEnum::PROJECT_TAX,
  1192. AllowanceProjectEnum::PROJECT_WAGES,
  1193. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  1194. AllowanceProjectEnum::PROJECT_SB_PENSION,
  1195. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  1196. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  1197. ];
  1198. $months = [];
  1199. for ($m = 1; $m <= 12; $m++) {
  1200. $months[] = $m . "月";
  1201. }
  1202. $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]]];
  1203. $infoCols = count($columns);
  1204. for ($i = 0; $i < count($projects); $i++) {
  1205. $columns[] = [AllowanceProjectEnum::getProjectName($projects[$i]), $months];
  1206. }
  1207. $list = \app\common\model\TalentAllowanceProject::alias("pro")
  1208. ->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")
  1209. ->leftJoin("un_talent_allowance_info ta", "ta.id=pro.mainId")
  1210. ->leftJoin("un_talent_allowancecontract_detail con", "pro.baseId=con.id")
  1211. ->where($where)
  1212. ->order("ta.year desc,ta.createTime desc,pro.project asc")
  1213. ->select()->toArray();
  1214. $tmpList = [];
  1215. $levelMap = DictApi::selectByParentCode("talent_arrange");
  1216. $streetMap = DictApi::selectByParentCode("street");
  1217. $where = [];
  1218. $where[] = ["id", "in", array_column($list, "identifyCondition")];
  1219. $icmap = \app\common\model\TalentCondition::where($where)->column("name", "id");
  1220. $where = [];
  1221. $where[] = ["id", "in", array_column($list, "enterpriseId")];
  1222. $enterpriseMap = \app\common\model\Enterprise::where($where)->column("name", "id");
  1223. foreach ($list as $item) {
  1224. //组装数据
  1225. if (!$tmpList[$item["id"]]) {
  1226. $tmpList[$item["id"]]["curEnterpriseId"] = $item["curEnterpriseId"];
  1227. $tmpList[$item["id"]]["info"] = [$item["year"], $streetMap[$item["address"]], $item["name"], $item["sex"] == 1 ? "男" : "女", $item["idCard"], $levelMap[$item["talentArrange"]],
  1228. $icmap[$item["identifyCondition"]], $item["identifyGetTime"], $item["identifyConditionName"], $item["identifyMonth"], AllowanceTypeEnum::getTypeName($item["allowanceType"]), $item["virtualAmount"], $item["months"], $item["money"],
  1229. $item["moneyDesc"], $this->getCheckStateName($item["checkState"], $item["publicState"], $item["allowanceType"])];
  1230. }
  1231. if (!$tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]) {
  1232. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]] = [
  1233. "startTime" => $item["startTime"],
  1234. "endTime" => $item["endTime"],
  1235. "entryTime" => $item["entryTime"],
  1236. "isQuit" => $item["isQuit"]
  1237. ];
  1238. }
  1239. $tmpList[$item["id"]]["enterprise"][$item["enterpriseId"]]["projects"][$item["project"]] = $item["pre_months"];
  1240. }
  1241. $rows = [];
  1242. $colorset = [];
  1243. foreach ($tmpList as $id => $item) {
  1244. foreach ($item["enterprise"] as $enterpriseId => $enterprise) {
  1245. $row = $item["info"];
  1246. $row[] = $this->user["uid"] == $enterpriseId ? "本单位" : $enterpriseMap[$enterpriseId];
  1247. for ($i = 0; $i < count($projects); $i++) {
  1248. if (strpos($enterprise["projects"][$projects[$i]], "=") === false) {
  1249. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1250. for ($m = 1; $m <= 12; $m++) {
  1251. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1252. if (in_array($_month, $months)) {
  1253. $row[] = "✔";
  1254. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1255. } else {
  1256. $row[] = "";
  1257. }
  1258. }
  1259. } else {
  1260. $months = array_filter(explode(",", $enterprise["projects"][$projects[$i]]));
  1261. $_months = [];
  1262. foreach ($months as $month) {
  1263. $kv = explode("=", $month);
  1264. $_months[$kv[0]] = $kv[1];
  1265. }
  1266. for ($m = 1; $m <= 12; $m++) {
  1267. $_month = str_pad($m, 2, "0", STR_PAD_LEFT);
  1268. $days = $_months[$_month];
  1269. if ($days && $days > 0) {
  1270. $row[] = $days . "天";
  1271. $colorset[] = [sprintf("%s%d", getExcelColumnByIndex($infoCols + $i * 12 + $m - 1), count($rows) + 3), "29dd23"];
  1272. } else {
  1273. $row[] = "";
  1274. }
  1275. }
  1276. }
  1277. }
  1278. $rows[] = $row;
  1279. }
  1280. }
  1281. $cols = $infoCols + count($projects) * 12 - 1;
  1282. $settings = [
  1283. "width" => [["A", 8], ["C", 12], ["D", 6], ["E", 20], ["F", 12], ["G", 70], ["H", 12], ["I", 15], ["J", 12], ["K", 12], ["P", 30]],
  1284. "height" => [18],
  1285. "freeze" => "D3",
  1286. "color" => $colorset
  1287. ];
  1288. for ($i = 0; $i < count($projects) * 12; $i++) {
  1289. $settings["width"][] = [getExcelColumnByIndex($infoCols + $i), 6]; //批设置项目的宽度
  1290. }
  1291. $settings["background-color"][] = [sprintf("%s2:%s2", getExcelColumnByIndex($infoCols), getExcelColumnByIndex($cols)), "E1F1DE"];
  1292. export($columns, $rows, "津补贴申报名单", $settings);
  1293. }
  1294. /**
  1295. * 审核列表页
  1296. */
  1297. public function examineCenter() {
  1298. $tpl = "";
  1299. switch ($this->user["type"]) {
  1300. case CommonConst::ENTERPRISE_WJ:
  1301. $tpl = "/talent_allowance/examine_center"; //卫健医院
  1302. break;
  1303. }
  1304. return view($tpl);
  1305. }
  1306. /**
  1307. * 审核列表页
  1308. */
  1309. public function examineList() {
  1310. $res = TalentAllowanceApi::getHospitalExamineList($this->request);
  1311. return json($res);
  1312. }
  1313. /**
  1314. * 审核页面
  1315. * @return type
  1316. */
  1317. public function toCheckPage() {
  1318. $id = $this->request["id"];
  1319. $process = $this->request["process"];
  1320. $obj = TalentAllowanceApi::getInfoById($id);
  1321. $this->translateToChinese($obj);
  1322. return view("check", ["row" => $obj, "process" => $process]);
  1323. }
  1324. /**
  1325. * 查看详情
  1326. * @return type
  1327. */
  1328. public function toSelectPage() {
  1329. $id = $this->request["id"];
  1330. $process = $this->request["process"];
  1331. $obj = TalentAllowanceApi::getInfoById($id);
  1332. $this->translateToChinese($obj);
  1333. return view("check", ["row" => $obj, "process" => $process]);
  1334. }
  1335. /**
  1336. * 审核保存
  1337. */
  1338. public function check() {
  1339. $obj = $this->request->param();
  1340. if (!$obj["checkState"]) {
  1341. return new Response(Response::ERROR, "请选择审核状态");
  1342. }
  1343. $oldObj = TalentAllowanceApi::getInfoById($obj["id"]);
  1344. if (!$oldObj) {
  1345. return new Response(Response::ERROR, "审核对象不存在");
  1346. }
  1347. $ep = \app\common\api\EnterpriseApi::getOne($oldObj["enterpriseId"]);
  1348. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1349. return new Response(Response::ERROR, "不在审核范围内");
  1350. }
  1351. if ($oldObj["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $oldObj["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1352. return new Response(Response::ERROR, "不在审核范围内");
  1353. }
  1354. $newObj = [];
  1355. $newObj["id"] = $obj["id"];
  1356. $projectList = [];
  1357. $fileList = [];
  1358. if (\StrUtil::isNotEmpAndNull($obj["projects"])) {
  1359. $projectList = array_filter(explode(",", $obj["projects"]));
  1360. $newObj["projects"] = implode(",", $projectList);
  1361. }
  1362. if (\StrUtil::isNotEmpAndNull($obj["files"])) {
  1363. $fileList = array_filter(explode(",", $obj["files"]));
  1364. $newObj["files"] = implode(",", $fileList);
  1365. }
  1366. $newObj["concats"] = $obj["concats"];
  1367. $newObj["fields"] = $obj["fields"];
  1368. //}
  1369. TaModel::update($newObj);
  1370. //添加日志
  1371. TalentChecklog::create([
  1372. 'id' => getStringId(),
  1373. 'mainId' => $obj['id'],
  1374. 'type' => intval(ProjectState::JBT),
  1375. 'typeFileId' => null,
  1376. 'active' => 2,
  1377. 'state' => $obj["checkState"],
  1378. 'step' => -2,
  1379. 'stateChange' => null,
  1380. 'description' => $obj["checkMsg"],
  1381. 'createTime' => date("Y-m-d H:i:s", time()),
  1382. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1383. ]);
  1384. return new Response(Response::SUCCESS, "审核成功");
  1385. }
  1386. /**
  1387. * 提交审核
  1388. * @return Response
  1389. */
  1390. public function submitCheck() {
  1391. $id = $this->request["id"];
  1392. $process = -2;
  1393. $old = TalentAllowanceApi::getInfoById($id);
  1394. if (!$old) {
  1395. return new Response(Response::ERROR, "审核对象不存在");
  1396. }
  1397. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1398. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1399. return new Response(Response::ERROR, "不在审核范围内");
  1400. }
  1401. if ($old["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $old["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1402. return new Response(Response::ERROR, "不在审核范围内");
  1403. }
  1404. $updCheck = [];
  1405. $updCheck["id"] = $id;
  1406. $updCheck["type"] = $old["type"];
  1407. /* * 查询审核日志 */
  1408. $log = \app\common\api\TalentLogApi::getLastLogByStep($id, ProjectState::JBT, $process);
  1409. if (!$log) {
  1410. return new Response(Response::ERROR, "请先审核后再提交");
  1411. }
  1412. $updCheck["checkMsg"] = $log["description"];
  1413. /* * 判断到达的最高流程 */
  1414. $updCheck["highProcess"] = !$old["highProcess"] || $old["highProcess"] < $process ? $process : $old["highProcess"];
  1415. switch ($log["state"]) {
  1416. case 3:
  1417. $updCheck["precheckPassTime"] = $old["precheckPassTime"];
  1418. if (!$old["precheckPassTime"]) {
  1419. $updCheck["precheckPassTime"] = date("Y-m-d H:i:s");
  1420. }
  1421. $updCheck["submitTime"] = date("Y-m-d H:i:s");
  1422. $updCheck["checkState"] = AllowanceStateEnum::NEED_CHECK;
  1423. break;
  1424. case 2:
  1425. $updCheck["checkState"] = AllowanceStateEnum::GENERAL_REJECT;
  1426. break;
  1427. case -1:
  1428. $updCheck["checkState"] = AllowanceStateEnum::NOTPASS;
  1429. $updCheck["recommendAllowanceType"] = 3;
  1430. $updCheck["recommendMoney"] = 0;
  1431. $updCheck["recommendAllowanceMsg"] = "审核不通过,不予兑现";
  1432. break;
  1433. default:
  1434. return new Response(Response::ERROR, "未知的审核状态");
  1435. }
  1436. //添加日志
  1437. TalentChecklog::create([
  1438. 'id' => getStringId(),
  1439. 'mainId' => $id,
  1440. 'type' => intval(ProjectState::JBT),
  1441. 'typeFileId' => null,
  1442. 'active' => 1,
  1443. 'state' => $log["state"],
  1444. 'step' => $process,
  1445. 'stateChange' => AllowanceStateEnum::getStateName($old["checkState"]) . "->" . AllowanceStateEnum::getStateName($updCheck["checkState"]),
  1446. 'description' => $log["description"],
  1447. 'createTime' => date("Y-m-d H:i:s", time()),
  1448. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  1449. ]);
  1450. TalentChecklog::where("id", $log["id"])->delete();
  1451. TaModel::update($updCheck);
  1452. return new Response(Response::SUCCESS, "提交审核成功");
  1453. }
  1454. /**
  1455. * 校验是否在审核范围内
  1456. */
  1457. public function validateIsCheck() {
  1458. $id = $this->request["id"];
  1459. $type = $this->request["type"];
  1460. $info = null;
  1461. switch ($type) {
  1462. case 1: //编辑合同
  1463. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  1464. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  1465. break;
  1466. case 2: //编辑项目
  1467. $project = \app\common\model\TalentAllowanceProject::find($id);
  1468. $info = TalentAllowanceApi::getInfoById($project["mainId"]);
  1469. break;
  1470. case 3:
  1471. $info = TalentAllowanceApi::getInfoById($id);
  1472. break;
  1473. }
  1474. if (!$info) {
  1475. return new Response(Response::ERROR, "校验不通过,无法操作");
  1476. }
  1477. $ep = \app\common\api\EnterpriseApi::getOne($info["enterpriseId"]);
  1478. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1479. return new Response(Response::ERROR, "不在审核范围内");
  1480. }
  1481. $where = [];
  1482. $where[] = ["mainId", "=", $info["id"]];
  1483. $where[] = ["step", "=", -2];
  1484. $where[] = ["active", "=", 2];
  1485. $log = null;
  1486. if ($info["checkState"] != AllowanceStateEnum::NEED_GENERAL_CHECK && $info["checkState"] != AllowanceStateEnum::FIRST_REJECT) {
  1487. return new Response(Response::ERROR, "不在审核范围内");
  1488. }
  1489. $log = TalentChecklog::where($where)->order("createTime desc")->find();
  1490. if ($log != null) {
  1491. $info["checkState"] = $log["state"];
  1492. $info["checkMsg"] = $log["description"];
  1493. } else {
  1494. $info["checkState"] = null;
  1495. $info["checkMsg"] = "";
  1496. }
  1497. $res = [];
  1498. $res["info"] = $info;
  1499. if ($type == 3) {
  1500. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1501. $where = [];
  1502. $where[] = ["mainId", "=", $id];
  1503. $where[] = ["isLock", "=", 1];
  1504. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1505. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1506. $detailMap = array_reduce($detailList, function ($result, $item) {
  1507. $key = $item["id"];
  1508. $result[$key] = $item;
  1509. return $result;
  1510. }, []);
  1511. foreach ($detailList as &$detail) {
  1512. $detail["enterpriseName"] = sprintf("%s(%s至%s)", $enterpriseMap[$detail["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1513. }unset($detail);
  1514. foreach ($projectList as &$project) {
  1515. $detail = $detailMap[$project["baseId"]];
  1516. $project["projectName"] = sprintf("%s(%s(%s至%s))", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]], $detail["startTime"], $detail["endTime"]);
  1517. }
  1518. $where = [];
  1519. $where[] = ["type", "=", $info["type"]];
  1520. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1521. $where[] = ["active", "=", 1];
  1522. $where[] = ["delete", "=", 0];
  1523. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1524. $res["files"] = $filetypes;
  1525. $res["projects"] = $projectList;
  1526. $res["concats"] = $detailList;
  1527. }
  1528. return new Response(Response::SUCCESS, "不在审核范围内", $res);
  1529. }
  1530. /**
  1531. * 初始化可修改的项目/附件/合同
  1532. * */
  1533. public function findFieldsAndFiles() {
  1534. $id = $this->request["id"];
  1535. if (\StrUtil::isEmpOrNull($id)) {
  1536. return new Response(Response::ERROR, "请选择需要修改的对象");
  1537. }
  1538. $info = TalentAllowanceApi::getInfoById($id);
  1539. if (!$info) {
  1540. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1541. }
  1542. if ($info["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1543. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1544. }
  1545. $res = [];
  1546. $enterpriseMap = \app\common\model\Enterprise::where("type", $this->user["type"])->column("name", "id");
  1547. $where = [];
  1548. $where[] = ["mainId", "=", $id];
  1549. $where[] = ["isLock", "=", 1];
  1550. $projectList = \app\common\model\TalentAllowanceProject::where($where)->select()->toArray();
  1551. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $id)->select()->toArray();
  1552. foreach ($detailList as &$detail) {
  1553. $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
  1554. }unset($detail);
  1555. foreach ($projectList as &$project) {
  1556. $detail = $detailMap[$project["baseId"]];
  1557. $project["projectName"] = sprintf("%s(%s)", AllowanceProjectEnum::getProjectName($project["project"]), $enterpriseMap[$project["enterpriseId"]]);
  1558. }unset($project);
  1559. $where = [];
  1560. $where[] = ["type", "=", $info["type"]];
  1561. $where[] = ["project", "=", \app\common\state\ProjectState::JBT];
  1562. $where[] = ["active", "=", 1];
  1563. $where[] = ["delete", "=", 0];
  1564. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  1565. $res["files"] = $filetypes;
  1566. $res["projects"] = $projectList;
  1567. $res["concats"] = $detailList;
  1568. $res["info"] = $info;
  1569. return new Response(Response::SUCCESS, "", $res);
  1570. }
  1571. /**
  1572. * 修改驳回项目/附件/合同
  1573. * */
  1574. public function updateFieldsAndFiles() {
  1575. $data = $this->request->param();
  1576. if (!$data["id"]) {
  1577. return new Response(Response::ERROR, "系统错误,请联系管理员");
  1578. }
  1579. $old = TalentAllowanceApi::getInfoById($data["id"]);
  1580. if (!$old) {
  1581. return new Response(Response::ERROR, "审核对象不存在");
  1582. }
  1583. $ep = \app\common\api\EnterpriseApi::getOne($old["enterpriseId"]);
  1584. if (!$this->checkExaminePriv($ep->isGeneral, $ep->medicalCommunityId)) {
  1585. return new Response(Response::ERROR, "不在审核范围内");
  1586. }
  1587. if ($old["checkState"] != AllowanceStateEnum::GENERAL_REJECT) {
  1588. return new Response(Response::ERROR, "只能修改总院驳回的数据");
  1589. }
  1590. TaModel::update($data);
  1591. return new Response(Response::SUCCESS, "修改成功");
  1592. }
  1593. private function checkExaminePriv($isGeneral, $medicalCommunityId) {
  1594. if ($this->user["medicalCommunityId"] == $medicalCommunityId && $this->user["isGeneral"] == 1 && $isGeneral == 2) {
  1595. return true;
  1596. }
  1597. return false;
  1598. }
  1599. private function getCheckStateName($checkState, $publicState, $allowanceType) {
  1600. switch ($checkState) {
  1601. case 1:
  1602. return "待提交";
  1603. case 3:
  1604. case 5:
  1605. case 13:
  1606. case 15:
  1607. case 20:
  1608. case 25:
  1609. case 35:
  1610. return "审核中";
  1611. case 8:
  1612. return "总院驳回";
  1613. case 9:
  1614. case 10:
  1615. return "已驳回";
  1616. case - 1:
  1617. if ($publicState >= 3) {
  1618. return "审核不通过";
  1619. } else {
  1620. return "审核中";
  1621. }
  1622. break;
  1623. case 30:
  1624. if ($publicState == 1) {
  1625. return "待核查征信";
  1626. } else if ($publicState == 2) {
  1627. return "待公示";
  1628. } else if ($publicState == 3) {
  1629. return "公示中";
  1630. } else if ($publicState == 4) {
  1631. return $allowanceType != 3 ? "待兑现" : "不予兑现";
  1632. } else if ($publicState == 5) {
  1633. return "已兑现";
  1634. }
  1635. default:
  1636. return "未知状态";
  1637. }
  1638. }
  1639. }