TalentAllowance.php 80 KB

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