TalentAllowance.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. /**
  23. * Description of TalentAllowance
  24. *
  25. * @author sgq
  26. */
  27. class TalentAllowance extends EnterpriseController {
  28. public function index() {
  29. $tpl = "";
  30. switch ($this->user["type"]) {
  31. case CommonConst::ENTERPRISE_JC:
  32. $tpl = "indexIC";
  33. break;
  34. }
  35. return view($tpl, ['type' => $this->user["type"]]);
  36. }
  37. public function list() {
  38. $res = TalentAllowanceApi::getList($this->request);
  39. return json($res);
  40. }
  41. /**
  42. * 申请
  43. */
  44. public function apply(\think\Request $request) {
  45. $param = $request->param();
  46. $id = isset($param["id"]) ? $param["id"] : 0;
  47. $info = null;
  48. if ($id) {
  49. $info = TalentAllowanceApi::getInfoById($id);
  50. $this->translateToChinese($info);
  51. }
  52. if ($request->isPost()) {
  53. return $this->save($info, $request);
  54. }
  55. $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  56. return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
  57. }
  58. public function batchApply() {
  59. $ids = $this->request["ids"];
  60. $ids = array_filter(explode(",", $ids));
  61. $allowanceType = $this->request["allowanceType"];
  62. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
  63. if (!$batch) {
  64. return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
  65. }
  66. for ($i = 0; $i < count($ids); $i++) {
  67. queue("app\job\TalentAllowance", ["type" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
  68. }
  69. return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
  70. }
  71. private function save($talentAllowance, \think\Request $request) {
  72. $response = new \stdClass();
  73. $response->code = 500;
  74. $param = $request->param();
  75. if (!$param) {
  76. $response->msg = "请填写信息后在提交";
  77. return $response;
  78. }
  79. if (\StrUtil::isEmpOrNull($param["talentId"])) {
  80. $response->msg = "请选择申报对象";
  81. return $response;
  82. }
  83. if (!$param["id"]) {
  84. $where = [];
  85. $where[] = ["year", "=", $param["year"]];
  86. $where[] = ["idCard", "=", $param["idCard"]];
  87. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  88. $exists = TaModel::where($where)->find();
  89. if ($exists) {
  90. $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
  91. return $response;
  92. }
  93. $user = $this->user;
  94. $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
  95. $data = [
  96. "talentId" => $param["talentId"],
  97. "enterpriseId" => $ti["enterprise_id"],
  98. "enterpriseName" => $user["name"],
  99. "year" => $param["year"],
  100. "source" => $ti["source"],
  101. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  102. "talentType" => $ti["enterpriseTag"],
  103. "address" => $ti["street"],
  104. "name" => $ti["name"],
  105. "sex" => $ti["sex"],
  106. "cardType" => $ti["card_type"],
  107. "idCard" => $ti["card_number"],
  108. "firstInJJTime" => $ti["fst_work_time"],
  109. "entryTime" => $ti["cur_entry_time"],
  110. "post" => $ti["position"],
  111. "phone" => $ti["phone"],
  112. "talentArrange" => $ti["talent_arrange"],
  113. "identifyCondition" => $ti["talent_condition"],
  114. "identifyGetTime" => $ti["identifyGetTime"],
  115. "identifyOutTime" => $ti["identifyExpireTime"],
  116. "identifyConditionName" => $ti["identifyConditionName"],
  117. "identifyMonth" => $ti["identifyMonth"],
  118. "bank" => $ti["bank"],
  119. "bankNetwork" => $ti["bank_branch_name"],
  120. "bankAccount" => $ti["bank_account"],
  121. "bankNumber" => $ti["bank_number"],
  122. "checkState" => 1,
  123. "type" => $user["type"],
  124. "provinceCode" => $ti["province"],
  125. "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
  126. "cityCode" => $ti["city"],
  127. "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
  128. "countyCode" => $ti["county"],
  129. "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
  130. "isSupple" => 2,
  131. "createTime" => date("Y-m-d H:i:s"),
  132. "createUser" => $user["uid"],
  133. "id" => getStringId(),
  134. "wage" => $param["wage"],
  135. "allowanceType" => $param["allowanceType"]
  136. ];
  137. /* * 1.获取上一年度的人才层次 */
  138. $arrangeList = $this->getLastYearTalentType($data, $ti);
  139. if (!$arrangeList) {
  140. $response->msg = "上一年度暂无有效的人才层次";
  141. return $response;
  142. }
  143. /* * 2.获取上一年度所在单位* */
  144. $contractDetailList = $this->getConcatList($ti, $data, $param["year"]); //保存上一年度的工作单位
  145. if (!$contractDetailList) {
  146. $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
  147. return $response;
  148. }
  149. TaModel::insert($data);
  150. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  151. /**
  152. * 4.添加津补贴核查项目
  153. */
  154. //核查项目详情表
  155. $this->createAllowanceProject($data, $contractDetailList);
  156. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  157. //添加日志
  158. TalentChecklog::create([
  159. 'id' => getStringId(),
  160. 'mainId' => $data['id'],
  161. 'type' => intval(ProjectState::JBT),
  162. 'typeFileId' => null,
  163. 'active' => 1,
  164. 'state' => 1,
  165. 'step' => 0,
  166. 'stateChange' => "保存未提交",
  167. 'description' => "添加津补贴申报",
  168. 'createTime' => date("Y-m-d H:i:s", time()),
  169. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  170. ]);
  171. $response->msg = "保存成功";
  172. $response->code = 200;
  173. $response->obj = $data;
  174. return $response;
  175. } else {
  176. TaModel::update($param);
  177. $response->msg = "修改成功";
  178. $response->code = 200;
  179. return $response;
  180. }
  181. }
  182. public function getInfoByIdAndYear($id, $year) {
  183. $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
  184. $data = [
  185. "talentId" => $id,
  186. "year" => $year,
  187. "idCard" => $ti["card_number"],
  188. "id" => getStringId()
  189. ];
  190. /* * 1.获取上一年度的人才层次 */
  191. $arrangeList = $this->getLastYearTalentType($data, $ti);
  192. if (!$arrangeList) {
  193. return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
  194. }
  195. /* * 2.获取上一年度所在单位* */
  196. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  197. if (!$contractDetailList) {
  198. return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
  199. }
  200. return new Response(Response::SUCCESS, "", $ti);
  201. }
  202. /**
  203. * 删除优秀人才津补贴
  204. */
  205. public function delete() {
  206. $id = $this->request["id"];
  207. $response = new \stdClass();
  208. $response->code = 500;
  209. $info = TalentAllowanceApi::getInfoById($id);
  210. if ($info["checkState"] != 1) {
  211. $response->msg = "删除失败!此数据已提交审核,无法删除!";
  212. return $response;
  213. }
  214. Db::startTrans();
  215. try {
  216. //删除核查项目表
  217. Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
  218. //删除合同情况表
  219. Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
  220. //删除人才层次变更表
  221. Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
  222. //删除日志
  223. $where[] = ["mainId", "=", $id];
  224. $where[] = ["type", "=", ProjectState::JBT];
  225. Db::table("new_talent_checklog")->where($where)->delete();
  226. //删除主表
  227. Db::table("un_talent_allowance_info")->delete($id);
  228. Db::commit();
  229. $response->code = 200;
  230. $response->msg = "删除成功";
  231. return $response;
  232. } catch (think\db\exception\DbException $e) {
  233. Db::rollback();
  234. $response->msg = $e->getMessage();
  235. return $response;
  236. }
  237. }
  238. public function detail(\think\Request $request) {
  239. $param = $request->param();
  240. $id = $param["id"];
  241. $info = TalentAllowanceApi::getInfoById($id);
  242. $this->translateToChinese($info);
  243. return view("", ["row" => $info]);
  244. }
  245. private function translateToChinese(&$obj) {
  246. if (\StrUtil::isNotEmpAndNull($obj["address"])) {
  247. $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
  248. }
  249. if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
  250. $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
  251. }
  252. if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
  253. $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
  254. }
  255. if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
  256. $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
  257. }
  258. if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
  259. $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
  260. }
  261. }
  262. /* * 获取上一年度的人才层次变更信息 */
  263. private function getLastYearTalentType($info, $talentInfo) {
  264. $arrangeList = [];
  265. /* * * 添加人才层次记录 */
  266. $where = [];
  267. $where[] = ["idCard", "=", $info["idCard"]];
  268. $where[] = ["checkState", "=", MainState::PASS];
  269. $where[] = ["isPublic", ">=", 5];
  270. $where[] = ["oldIdentifyMonth", "<=", $info["year"] . "-12-31"];
  271. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth")->order("createTime desc")->select()->toArray();
  272. $typeList[] = [
  273. "oldTalentArrange" => $talentInfo["talent_arrange"],
  274. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  275. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  276. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  277. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  278. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  279. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  280. "newIdentifyMonth" => $info["year"] . "-12-31"
  281. ];
  282. $totalMonth = \DateUtil::getMonthBetweenDates($info["year"] . "-01-01", $info["year"] . "-12-31");
  283. /* * 获取上一年度有效的人才层次 */
  284. usort($typeList, function($a, $b) {
  285. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  286. });
  287. $commonMonth = [];
  288. foreach ($typeList as $talentTypeChange) {
  289. $startTime = $talentTypeChange["oldIdentifyMonth"];
  290. $endTime = $talentTypeChange["newIdentifyMonth"];
  291. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  292. if ($monthList) {
  293. $monthList = array_intersect($monthList, $totalMonth);
  294. }
  295. if ($monthList) {
  296. $months = implode(",", $monthList);
  297. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  298. return !in_array($value, $commonMonth);
  299. });
  300. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  301. if (count($monthList) > 0) {
  302. $arrange = [
  303. "id" => getStringId(),
  304. "mainId" => $info["id"],
  305. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  306. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  307. "startTime" => $startTime,
  308. "endTime" => $endTime,
  309. "prepareMonths" => null,
  310. "description" => "申报年度有效月份:" . $months,
  311. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  312. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  313. ];
  314. $sb = '';
  315. foreach ($monthList as $month) {
  316. $sb .= substr($month, 5, 2) . ",";
  317. }
  318. $arrange["prepareMonths"] = rtrim($sb, ",");
  319. $arrangeList[] = $arrange;
  320. }
  321. }
  322. }
  323. return $arrangeList;
  324. }
  325. /**
  326. * @param
  327. * @returns void
  328. * @author Liu
  329. * @date 2020/4/26
  330. * @description 获取上一年度所在单位
  331. * */
  332. private function getConcatList($talentInfo, $info, $year) {
  333. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  334. /** 添加申报人才上一年度工作单位记录 */
  335. $where = [];
  336. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  337. $where[] = ["checkState", "=", 3];
  338. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  339. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  340. if ($talentInfo["active"] == 1) {
  341. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  342. $starttime = $labor_contract_rangetime[0];
  343. $endtime = $labor_contract_rangetime[1];
  344. $quitList[] = [
  345. "enterpriseId" => $talentInfo["enterprise_id"],
  346. "enterpriseName" => $talentInfo["enterpriseName"],
  347. "talentType" => $talentInfo["enterpriseTag"],
  348. "identifyGetTime" => $talentInfo["identifyGetTime"],
  349. "starttime" => $starttime,
  350. "endtime" => $endtime,
  351. "entryTime" => $talentInfo["cur_entry_time"],
  352. "quitTime" => null,
  353. "post" => $talentInfo["position"]
  354. ];
  355. }
  356. $list = [];
  357. foreach ($quitList as $quit) {
  358. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  359. $monthList = array_intersect($monthList, $totalMonth);
  360. if ($monthList) {
  361. $sb = '';
  362. foreach ($monthList as $month) {
  363. $sb .= substr($month, 5, 2) . ",";
  364. }
  365. $list[] = [
  366. "id" => getStringId(),
  367. "mainId" => $info["id"],
  368. "enterpriseId" => $quit["enterpriseId"],
  369. "talentType" => $quit["talentType"],
  370. "startTime" => $quit["starttime"],
  371. "endTime" => $quit["endtime"],
  372. "entryTime" => $quit["entryTime"],
  373. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  374. "letterTime" => $quit["letterTime"],
  375. "gygb" => $quit["gygb"],
  376. "identifyGetTime" => $quit["identifyGetTime"],
  377. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  378. "post" => $quit["post"],
  379. "months" => rtrim($sb, ",")
  380. ];
  381. }
  382. }
  383. return $list;
  384. }
  385. private function createAllowanceProject($info, $contractList) {
  386. foreach ($contractList as $detail) {
  387. $projects = [
  388. //AllowanceProjectEnum::PROJECT_CONTRACT,
  389. AllowanceProjectEnum::PROJECT_TAX,
  390. AllowanceProjectEnum::PROJECT_WAGES,
  391. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  392. AllowanceProjectEnum::PROJECT_SB_PENSION,
  393. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  394. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  395. //AllowanceProjectEnum::PROJECT_WORKDAY,
  396. ];
  397. $list = [];
  398. foreach ($projects as $project) {
  399. $list[] = [
  400. "mainId" => $info["id"],
  401. "baseId" => $detail["id"],
  402. "enterpriseId" => $detail["enterpriseId"],
  403. "project" => $project,
  404. "isLock" => 1,
  405. "createTime" => date("Y-m-d H:i:s")
  406. ];
  407. }
  408. \app\common\model\TalentAllowanceProject::insertAll($list);
  409. }
  410. }
  411. /**
  412. * 查询工作单位
  413. */
  414. public function findAllowanceContractDetail() {
  415. $mainId = $this->request["mainId"];
  416. $offset = $this->request["offset"] ?: 0;
  417. $limit = $this->request["limit"] ?: 1000;
  418. $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
  419. $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
  420. $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
  421. foreach ($list as &$row) {
  422. $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
  423. }unset($row);
  424. return json(["rows" => $list, "total" => $count]);
  425. }
  426. /**
  427. * 查询核查项目情况
  428. */
  429. public function findAllowanceProject() {
  430. $mainId = $this->request["mainId"];
  431. $baseId = $this->request["baseId"];
  432. $offset = $this->request["offset"] ?: 0;
  433. $limit = $this->request["limit"] ?: 1000;
  434. $where = [];
  435. $where[] = ["mainId", "=", $mainId];
  436. $where[] = ["baseId", "=", $baseId];
  437. $count = \app\common\model\TalentAllowanceProject::where($where)->count();
  438. $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
  439. $info = TalentAllowanceApi::getInfoById($mainId);
  440. foreach ($list as &$project) {
  441. $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
  442. if ($info["checkState"] == 1) {
  443. $project["isEdit"] = in_array($project["project"], [
  444. //AllowanceProjectEnum::PROJECT_CONTRACT,
  445. AllowanceProjectEnum::PROJECT_TAX,
  446. AllowanceProjectEnum::PROJECT_WAGES,
  447. AllowanceProjectEnum::PROJECT_ATTENDANCE,
  448. AllowanceProjectEnum::PROJECT_SB_PENSION,
  449. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
  450. AllowanceProjectEnum::PROJECT_SB_MEDICA,
  451. //AllowanceProjectEnum::PROJECT_WORKDAY
  452. ]) ? 1 : 2;
  453. } else if ($info["checkState"] == 10) {
  454. $projects = explode(",", $info["projects"]);
  455. if (in_array($project["id"], $projects)) {
  456. $project["isEdit"] = 1;
  457. } else {
  458. $project["isEdit"] = 2;
  459. }
  460. } else {
  461. $project["isEdit"] = 2;
  462. }
  463. }unset($project);
  464. return json(["rows" => $list, "total" => $count]);
  465. }
  466. /**
  467. * 查询人才层次变更记录
  468. */
  469. public function findAllowanceArrange() {
  470. $mainId = $this->request["mainId"];
  471. $offset = $this->request["offset"] ?: 0;
  472. $limit = $this->request["limit"] ?: 1000;
  473. $where = [];
  474. $where[] = ["mainId", "=", $mainId];
  475. $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
  476. $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
  477. foreach ($list as &$arrange) {
  478. $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
  479. $arrange["identifyConditionText"] = $condition["name"];
  480. $arrange["talentArrangeName"] = app\common\state\CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
  481. }unset($arrange);
  482. return json(["rows" => $list, "total" => $count]);
  483. }
  484. /**
  485. * 修改合同起止时间
  486. */
  487. public function editContract() {
  488. $response = new \stdClass();
  489. $response->code = 500;
  490. $param = $this->request->param();
  491. if (!$param["id"]) {
  492. $response->msg = "系统错误,请联系管理员";
  493. return $response;
  494. }
  495. $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
  496. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  497. if (\StrUtil::isEmpOrNull($param["startTime"])) {
  498. $response->msg = "请选择合同起始时间";
  499. return $response;
  500. }
  501. if (\StrUtil::isEmpOrNull($param["endTime"])) {
  502. $response->msg = "请选择合同截止时间";
  503. return $response;
  504. }
  505. \app\common\model\TalentAllowancecontractDetail::update($param);
  506. //添加日志
  507. TalentChecklog::create([
  508. 'id' => getStringId(),
  509. 'mainId' => $info['id'],
  510. 'type' => intval(ProjectState::JBT),
  511. 'typeFileId' => $param["id"],
  512. 'active' => 1,
  513. 'state' => null,
  514. 'step' => 0,
  515. 'stateChange' => null,
  516. 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
  517. 'createTime' => date("Y-m-d H:i:s", time()),
  518. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  519. ]);
  520. $response->msg = "修改成功";
  521. $response->code = 200;
  522. return $response;
  523. }
  524. /**
  525. * 修改项目
  526. */
  527. public function editProject() {
  528. $response = new \stdClass();
  529. $response->code = 500;
  530. $param = $this->request->param();
  531. if (!$param["id"]) {
  532. $response->msg = "系统错误,请联系管理员";
  533. return $response;
  534. }
  535. $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
  536. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  537. \app\common\model\TalentAllowanceProject::update($param);
  538. //添加日志
  539. TalentChecklog::create([
  540. 'id' => getStringId(),
  541. 'mainId' => $info['id'],
  542. 'type' => intval(ProjectState::JBT),
  543. 'typeFileId' => $param["id"],
  544. 'active' => 1,
  545. 'state' => null,
  546. 'step' => 0,
  547. 'stateChange' => null,
  548. 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
  549. 'createTime' => date("Y-m-d H:i:s", time()),
  550. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  551. ]);
  552. $response->msg = "修改成功";
  553. $response->code = 200;
  554. return $response;
  555. }
  556. /**
  557. * 判断是否可以修改
  558. */
  559. public function validateIsEdit() {
  560. $id = $this->request["id"];
  561. $type = $this->request["type"];
  562. $info = null;
  563. if ($type == 1) { //编辑合同
  564. $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
  565. } else if ($type == 2) { //编辑项目
  566. $detail = \app\common\model\TalentAllowanceProject::find($id);
  567. }
  568. $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
  569. if ($info["checkState"] != 1 && $info["checkState"] != 10) {
  570. if ($info["checkState"] == -1) {
  571. return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
  572. } else if ($info["checkState"] == 30) {
  573. return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
  574. } else {
  575. return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
  576. }
  577. }
  578. return new Response(Response::SUCCESS, "");
  579. }
  580. /**
  581. * 提交审核
  582. */
  583. public function submitToCheck() {
  584. $data = $this->request->param();
  585. $response = new \stdClass();
  586. $response->code = 500;
  587. if (!$data || !$data["id"]) {
  588. $response->msg = "提交审核失败,请先填写基础信息";
  589. return $response;
  590. }
  591. $old = TalentAllowanceApi::getInfoById($data["id"]);
  592. $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
  593. if ($batch["code"] != 200) {
  594. $response->msg = $batch["msg"];
  595. return $response;
  596. }
  597. if ($old["checkState"] != 1 && $old["checkState"] != 10) {
  598. $response->msg = "不能重复提交审核";
  599. return $response;
  600. }
  601. $where = [];
  602. $where[] = ["type", "=", $old["type"]];
  603. $where[] = ["project", "=", ProjectState::JBT];
  604. $where[] = ["isConditionFile", "in", [0, $old["allowanceType"]]];
  605. $where[] = ["active", "=", 1];
  606. $where[] = ["delete", "=", 0];
  607. $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
  608. $sb = [];
  609. $sb[] = "以下为必传附件:";
  610. foreach ($filetypes as $filetype) {
  611. if ($filetype["must"] == 1) {
  612. $where = [];
  613. $where[] = ["mainId", "=", $data["id"]];
  614. $where[] = ["typeId", "=", $filetype["id"]];
  615. $count = Db::table("new_talent_file")->where($where)->count();
  616. if ($count == 0) {
  617. $sb[] = $filetype["name"] . ";";
  618. }
  619. }
  620. }
  621. if (count($sb) > 1) {
  622. $response->msg = implode("<br>", $sb);
  623. return $response;
  624. }
  625. /**
  626. * 初步判断合同是否满两年
  627. */
  628. $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
  629. foreach ($detailList as $detail) {
  630. if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
  631. $response->msg = "合同起止时间不能为空";
  632. return $response;
  633. }
  634. }
  635. foreach ($detailList as $detail) {
  636. $contractEndTime = strtotime($detail["endTime"]);
  637. $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
  638. $where = [];
  639. $where[] = ["mainId", "=", $data["id"]];
  640. $where[] = ["baseId", "=", $detail["id"]];
  641. $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
  642. $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
  643. \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
  644. }
  645. $data["checkMsg"] = "";
  646. $data["checkState"] = 5;
  647. $data["files"] = "";
  648. $data["projects"] = "";
  649. $data["concats"] = "";
  650. $data["fields"] = "";
  651. $data["toDep"] = "";
  652. $data["process"] = null;
  653. if (!$old["firstSubmitTime"]) {
  654. $data["firstSubmitTime"] = date("Y-m-d H:i:s");
  655. }
  656. $data["newSubmitTime"] = date("Y-m-d H:i:s");
  657. TaModel::update($data);
  658. //添加日志
  659. TalentChecklog::create([
  660. 'id' => getStringId(),
  661. 'mainId' => $data['id'],
  662. 'type' => intval(ProjectState::JBT),
  663. 'typeFileId' => null,
  664. 'active' => 1,
  665. 'state' => 1,
  666. 'step' => 0,
  667. 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
  668. 'description' => "确认提交审核",
  669. 'createTime' => date("Y-m-d H:i:s", time()),
  670. 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
  671. ]);
  672. $response->msg = "提交审核成功";
  673. $response->code = 200;
  674. $response->obj = 5;
  675. return $response;
  676. }
  677. public function updateSuppleState() {
  678. $id = $this->request["id"];
  679. $response = new \stdClass();
  680. $response->code = 500;
  681. if (\StrUtil::isEmpOrNull($id)) {
  682. $response->msg = "系统错误,请联系管理员";
  683. return $response;
  684. }
  685. $data["id"] = $id;
  686. $data["isSupple"] = 1;
  687. TaModel::update($data);
  688. $response->msg = "状态更新成功";
  689. $response->code = 200;
  690. return $response;
  691. }
  692. public function uploadCommonFile() {
  693. $batchId = $this->request["batch"];
  694. if (!$batchId) {
  695. return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
  696. }
  697. $batchInfo = BatchApi::getOne($batchId);
  698. if (!$batchInfo) {
  699. return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
  700. }
  701. if (!$this->request->file()) {
  702. return json(new Response(Response::ERROR, "没有上传任何材料"));
  703. }
  704. $file = $this->request->file("file");
  705. $upload = new UploadApi();
  706. $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
  707. if ($result->code != 200) {
  708. return json(new Response(Response::ERROR, $result->msg));
  709. }
  710. $data["id"] = getStringId();
  711. $data["enterpriseId"] = $this->user["uid"];
  712. $data["batchId"] = $batchId;
  713. $data["batch"] = $batchInfo["batch"];
  714. $data["url"] = $result->filepath;
  715. $data["originalName"] = $file->getOriginalName();
  716. $data["createTime"] = date("Y-m-d H:i:s");
  717. $data["createUser"] = $this->user["uid"];
  718. $res = Db::table("un_talent_allowance_common_file")->insert($data);
  719. return json(new Response(Response::SUCCESS, "上传成功"));
  720. }
  721. public function listCommonFile() {
  722. $param = $this->request->param();
  723. $batchId = $param["batch"];
  724. $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
  725. $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
  726. foreach ($list as $key => $item) {
  727. $list[$key]["ext"] = pathinfo($item["url"])["extension"];
  728. $list[$key]["url"] = getStoragePath($item["url"]);
  729. }
  730. return json(["rows" => $list]);
  731. }
  732. public function deleteCommonFile() {
  733. $id = $this->request["id"];
  734. $where = [];
  735. $where[] = ["id", "=", $id];
  736. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  737. $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
  738. if (!$file) {
  739. return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
  740. }
  741. if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
  742. if (!empty($file["url"])) {
  743. $filepath = "storage/" . $file["url"];
  744. if (file_exists($filepath)) {
  745. unlink($filepath);
  746. }
  747. }
  748. return json(new Response(Response::SUCCESS, "删除成功"));
  749. }
  750. }
  751. public function findTalentAllowance() {
  752. $res = [];
  753. $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
  754. $year = $batch["batch"];
  755. if ($year) {
  756. $ids = null;
  757. //根据申报年度查询当前企业已申报的人才
  758. $where = [];
  759. $where[] = ["year", "=", $year];
  760. $where[] = ["enterpriseId", "=", $this->user["uid"]];
  761. $talentAllowances = TaModel::where($where)->select()->toArray();
  762. $ids = array_unique(array_column($talentAllowances, "talentId"));
  763. $whr = [];
  764. $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
  765. $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
  766. $whr[] = ["e.type", "=", $this->user["type"]];
  767. $whr[] = ["ti.id", "not in", $ids];
  768. $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")->where($whr)->select()->toArray();
  769. foreach ($list as $info) {
  770. if (strtotime($year . "-12-31") >= strtotime($info["identifyMonth"])) {
  771. $res[] = $info;
  772. } else {
  773. $whereTypeChange = [];
  774. $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
  775. $whereTypeChange[] = ["checkState", "=", MainState::PASS];
  776. $whereTypeChange[] = ["isPublic", "=", 6];
  777. $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
  778. foreach ($typeChanges as $typeChange) {
  779. if (strtotime($year . "-12-31") >= strtotime($typeChange["oldIdentifyMonth"])) {
  780. $res[] = $info;
  781. break;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
  788. }
  789. }