TalentAllowance.php 70 KB

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