TalentAllowance.php 29 KB

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