TalentAllowance.php 28 KB

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