TalentAllowance.php 34 KB

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